Commit b99b332e authored by eekkelund's avatar eekkelund

[Keyboard] Make Keyboard to hide when clicked outside of TextField.(This must...

[Keyboard] Make Keyboard to hide when clicked outside of TextField.(This must be made to all Input components)
parent b03a72d2
...@@ -26,7 +26,8 @@ QML_FILES += \ ...@@ -26,7 +26,8 @@ QML_FILES += \
qml/IconButton.qml \ qml/IconButton.qml \
qml/DatePicker.qml \ qml/DatePicker.qml \
qml/ScrollDecorator.qml \ qml/ScrollDecorator.qml \
qml/dialogs/QueryDialog.qml qml/dialogs/QueryDialog.qml \
qml/TextField.qml
OTHER_FILES += qmldir \ OTHER_FILES += qmldir \
$$QML_FILES $$QML_FILES
...@@ -41,7 +42,9 @@ HEADERS += \ ...@@ -41,7 +42,9 @@ HEADERS += \
themedaemon/mlocalthemedaemonclient.h \ themedaemon/mlocalthemedaemonclient.h \
themedaemon/mabstractthemedaemonclient.h \ themedaemon/mabstractthemedaemonclient.h \
sizing.h \ sizing.h \
theme.h theme.h \
editfilter.h \
nemofocussingleton.h
SOURCES += \ SOURCES += \
qquicknemocontrolsextensionplugin.cpp \ qquicknemocontrolsextensionplugin.cpp \
...@@ -53,7 +56,9 @@ SOURCES += \ ...@@ -53,7 +56,9 @@ SOURCES += \
themedaemon/mlocalthemedaemonclient.cpp \ themedaemon/mlocalthemedaemonclient.cpp \
themedaemon/mabstractthemedaemonclient.cpp \ themedaemon/mabstractthemedaemonclient.cpp \
sizing.cpp \ sizing.cpp \
theme.cpp theme.cpp \
editfilter.cpp \
nemofocussingleton.cpp
target.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH target.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH
......
/*
* Copyright (C) 2017 Eetu Kahelin
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "editfilter.h"
EditFilter::EditFilter(QObject *parent) : QObject(parent)
{
}
bool EditFilter::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::TouchBegin) {
NemoFocusSingleton *nemoFocus = NemoFocusSingleton::instance();
if(nemoFocus->edit() != NULL) {
nemoFocus->edit()->setProperty("focus",QVariant(false));
return false;
}
} else {
return QObject::eventFilter(obj, event);
}
}
/*
* Copyright (C) 2017 Eetu Kahelin
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef EDITFILTER_H
#define EDITFILTER_H
#include <QObject>
#include <QEvent>
#include <QString>
#include "nemofocussingleton.h"
class EditFilter : public QObject
{
Q_OBJECT
public:
explicit EditFilter(QObject *parent = 0);
protected:
bool eventFilter(QObject *obj, QEvent *event);
};
#endif // EDITFILTER_H
/*
* Copyright (C) 2017 Eetu Kahelin
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "nemofocussingleton.h"
void NemoFocusSingleton::nemoregister(QObject *edit)
{
m_edit = edit;
}
NemoFocusSingleton *NemoFocusSingleton::instance() {
static NemoFocusSingleton * _instance = 0;
if ( _instance == 0 ) {
_instance = new NemoFocusSingleton();
}
return _instance;
}
QObject *NemoFocusSingleton::edit() const
{
return m_edit;
}
/*
* Copyright (C) 2017 Eetu Kahelin
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef NEMOFOCUSSINGLETON_H
#define NEMOFOCUSSINGLETON_H
#include <QObject>
class NemoFocusSingleton: public QObject
{
Q_OBJECT
Q_DISABLE_COPY(NemoFocusSingleton)
public:
Q_INVOKABLE void nemoregister(QObject *edit) ;
QObject *edit() const;
static NemoFocusSingleton* instance();
private:
QObject *m_edit = nullptr;
NemoFocusSingleton(QObject* parent = nullptr) {}
};
#endif // NEMOFOCUSSINGLETON_H
...@@ -26,6 +26,8 @@ NemoWindow::NemoWindow(QWindow *parent) : ...@@ -26,6 +26,8 @@ NemoWindow::NemoWindow(QWindow *parent) :
m_defaultAllowedOrientations(Qt::PortraitOrientation | Qt::LandscapeOrientation) m_defaultAllowedOrientations(Qt::PortraitOrientation | Qt::LandscapeOrientation)
{ {
m_allowedOrientations = m_defaultAllowedOrientations; m_allowedOrientations = m_defaultAllowedOrientations;
m_filter = new EditFilter();
this->installEventFilter(m_filter);
} }
Qt::ScreenOrientations NemoWindow::allowedOrientations() const Qt::ScreenOrientations NemoWindow::allowedOrientations() const
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include <QQuickWindow> #include <QQuickWindow>
#include <QtCore/qnamespace.h> #include <QtCore/qnamespace.h>
#include "editfilter.h"
class NemoWindow : public QQuickWindow class NemoWindow : public QQuickWindow
{ {
Q_OBJECT Q_OBJECT
...@@ -48,6 +50,9 @@ private: ...@@ -48,6 +50,9 @@ private:
Qt::ScreenOrientations m_allowedOrientations; Qt::ScreenOrientations m_allowedOrientations;
Qt::ScreenOrientations m_defaultAllowedOrientations; Qt::ScreenOrientations m_defaultAllowedOrientations;
EditFilter *m_filter;
}; };
#endif // NEMOWINDOW_H #endif // NEMOWINDOW_H
...@@ -73,7 +73,7 @@ NemoPage { ...@@ -73,7 +73,7 @@ NemoPage {
color: Theme.backgroundColor color: Theme.backgroundColor
} }
Item { MouseArea {
id: content id: content
anchors.fill: parent anchors.fill: parent
} }
......
/****************************************************************************************
**
** Copyright (c) 2017, Eetu Kahelin
** All rights reserved.
**
** You may use this file under the terms of BSD license as follows:
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** * Neither the name of the author nor the
** names of its contributors may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
****************************************************************************************/
import QtQuick 2.6
import QtQuick.Controls 1.0
import QtQuick.Controls.Nemo 1.0
import QtQuick.Controls.Styles.Nemo 1.0
TextField {
onActiveFocusChanged: {
if(activeFocus) NemoFocus.nemoregister(this)
else NemoFocus.nemoregister(null)
}
style: TextFieldStyle { }
}
...@@ -27,6 +27,7 @@ InverseMouseArea 1.0 InverseMouseArea.qml ...@@ -27,6 +27,7 @@ InverseMouseArea 1.0 InverseMouseArea.qml
IconButton 1.0 IconButton.qml IconButton 1.0 IconButton.qml
DatePicker 1.0 DatePicker.qml DatePicker 1.0 DatePicker.qml
ScrollDecorator 1.0 ScrollDecorator.qml ScrollDecorator 1.0 ScrollDecorator.qml
TextField 1.0 TextField.qml
# MIRRORED CONTROLS: # MIRRORED CONTROLS:
# These are the controls that we take directly from official QQC. # These are the controls that we take directly from official QQC.
...@@ -56,6 +57,5 @@ TabView 1.0 ../TabView.qml ...@@ -56,6 +57,5 @@ TabView 1.0 ../TabView.qml
TableView 1.0 ../TableView.qml TableView 1.0 ../TableView.qml
TableViewColumn 1.0 ../TableViewColumn.qml TableViewColumn 1.0 ../TableViewColumn.qml
TextArea 1.0 ../TextArea.qml TextArea 1.0 ../TextArea.qml
TextField 1.0 ../TextField.qml
ToolBar 1.0 ../ToolBar.qml ToolBar 1.0 ../ToolBar.qml
ToolButton 1.0 ../ToolButton.qml ToolButton 1.0 ../ToolButton.qml
/* /*
* Copyright (C) 2013 Tomasz Olszak <olszak.tomasz@gmail.com> * Copyright (C) 2013 Tomasz Olszak <olszak.tomasz@gmail.com>
* Copyright (C) 2013 Andrea Bernabei <and.bernabei@gmail.com> * Copyright (C) 2013 Andrea Bernabei <and.bernabei@gmail.com>
* Copyright (C) 2017 Eetu Kahelin
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
...@@ -27,6 +28,7 @@ ...@@ -27,6 +28,7 @@
#include "nemoimageprovider.h" #include "nemoimageprovider.h"
#include "sizing.h" #include "sizing.h"
#include "theme.h" #include "theme.h"
#include "nemofocussingleton.h"
QQuickNemoControlsExtensionPlugin::QQuickNemoControlsExtensionPlugin(QObject *parent) : QQuickNemoControlsExtensionPlugin::QQuickNemoControlsExtensionPlugin(QObject *parent) :
QQmlExtensionPlugin(parent) QQmlExtensionPlugin(parent)
...@@ -38,10 +40,18 @@ static QObject *nemo_hacks_singletontype_provider(QQmlEngine *engine, QJSEngine ...@@ -38,10 +40,18 @@ static QObject *nemo_hacks_singletontype_provider(QQmlEngine *engine, QJSEngine
QObject *ret = new Hacks(engine); QObject *ret = new Hacks(engine);
return ret; return ret;
} }
QObject *getNemoFocus(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return NemoFocusSingleton::instance();
}
void QQuickNemoControlsExtensionPlugin::registerTypes(const char *uri) void QQuickNemoControlsExtensionPlugin::registerTypes(const char *uri)
{ {
Q_ASSERT(uri == QLatin1String("QtQuick.Controls.Nemo")); Q_ASSERT(uri == QLatin1String("QtQuick.Controls.Nemo"));
qmlRegisterSingletonType<QObject>(uri, 1, 0, "NemoFocus", getNemoFocus);
qmlRegisterSingletonType<QObject>(uri, 1, 0, "NemoHacks", nemo_hacks_singletontype_provider); qmlRegisterSingletonType<QObject>(uri, 1, 0, "NemoHacks", nemo_hacks_singletontype_provider);
qmlRegisterType<NemoWindow>(uri, 1, 0, "NemoWindow"); qmlRegisterType<NemoWindow>(uri, 1, 0, "NemoWindow");
qmlRegisterType<NemoPage>(uri, 1, 0, "NemoPage"); qmlRegisterType<NemoPage>(uri, 1, 0, "NemoPage");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment