Skip to content

Commit

Permalink
Mobile|Widgets: Rudimentary key/touch event handling via Qt Quick
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed May 14, 2017
1 parent 58d60bd commit ed281f2
Show file tree
Hide file tree
Showing 13 changed files with 493 additions and 13 deletions.
62 changes: 58 additions & 4 deletions doomsday/apps/client/res/qml/main.qml
Original file line number Diff line number Diff line change
@@ -1,21 +1,54 @@
import QtQuick 2.0
import QtQuick 2.7
import Doomsday 1.0

Item {
width: 320
height: 480

ClientWindow {
anchors.fill: parent
id: mainWin
x: 0
y: 0
width: parent.width
height: parent.height
focus: true
/*SequentialAnimation on t {
NumberAnimation { to: 1; duration: 2500; easing.type: Easing.InQuad }
NumberAnimation { to: 0; duration: 2500; easing.type: Easing.OutQuad }
loops: Animation.Infinite
running: true
}*/
onTextEntryRequest: {
console.log("text entry requested");
keyInput.focus = true;
}
onTextEntryDismiss: {
console.log("text entry dismissed");
keyInput.focus = false;
mainWin.focus = true;
}

Connections {
target: Qt.inputMethod
onVisibleChanged: {
if (Qt.inputMethod.visible) {
mainWin.height = parent.height - Qt.inputMethod.keyboardRectangle.height;
console.log("update dimensions:", mainWin.height);
mainWin.dimensionsChanged();
}
else {
console.log("inputMethod visibility:", Qt.inputMethod.visible);
mainWin.userFinishedTextEntry();
keyInput.focus = false;
mainWin.focus = true;
mainWin.height = parent.height;
mainWin.dimensionsChanged();
}
}
}
}

Rectangle {
/*Rectangle {
color: Qt.rgba(1, 1, 1, 0.7)
radius: 10
border.width: 1
Expand All @@ -28,10 +61,31 @@ Item {
id: label
color: "black"
wrapMode: Text.WordWrap
text: "The background here is a squircle rendered with raw OpenGL using the 'beforeRender()' signal in QQuickWindow. This text label and its border is rendered using QML"
text: mainWin.activeFocus? "I have active focus!" : "I do not have active focus"
anchors.right: parent.right
anchors.left: parent.left
anchors.bottom: parent.bottom
anchors.margins: 20
}*/

MultiPointTouchArea {
anchors.fill: parent
onPressed: mainWin.onTouchPressed(touchPoints)
onUpdated: mainWin.onTouchUpdated(touchPoints)
onReleased: mainWin.onTouchReleased(touchPoints)
}

TextInput {
id: keyInput
visible: false
onTextChanged: {
mainWin.userEnteredText(text);
}
// onFocusChanged: {
// if (!focus) {
// mainWin.height = parent.height;
// mainWin.dimensionsChanged();
// }
// }
}
}
14 changes: 14 additions & 0 deletions doomsday/apps/client/src/ui/clientwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,14 @@ ClientWindow::ClientWindow(String const &id)
#endif

d->setupUI();

#if defined (DENG_MOBILE)
// Stay out from under the virtual keyboard.
connect(this, &GLWindow::rootDimensionsChanged, [this] (QRect rect)
{
d->root.setViewSize(Vector2ui(rect.width(), rect.height()));
});
#endif
}

ClientRootWidget &ClientWindow::root()
Expand Down Expand Up @@ -919,6 +927,12 @@ Vector2f ClientWindow::windowContentSize() const

void ClientWindow::drawWindowContent()
{
#if defined (DENG_MOBILE)
{

}
#endif

DENG2_ASSERT_IN_RENDER_THREAD();
root().draw();
LIBGUI_ASSERT_GL_OK();
Expand Down
5 changes: 4 additions & 1 deletion doomsday/apps/client/src/ui/home/nogamescolumnwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ String NoGamesColumnWidget::tabHeading() const

void NoGamesColumnWidget::browseForDataFiles()
{
bool reload = false;

#if !defined (DENG_MOBILE)
// Use a native dialog to select the IWAD folder.
ClientApp::app().beginNativeUIMode();

Expand All @@ -71,14 +74,14 @@ void NoGamesColumnWidget::browseForDataFiles()
dlg.setReadOnly(true);
//dlg.setNameFilter("*.wad");
dlg.setLabelText(QFileDialog::Accept, tr("Select"));
bool reload = false;
if (dlg.exec())
{
App::config().set("resource.iwadFolder", dlg.selectedFiles().at(0));
reload = true;
}

ClientApp::app().endNativeUIMode();
#endif

// Reload packages and recheck for game availability.
if (reload)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libappfw/include/de/framework/guiwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class LIBAPPFW_PUBLIC GuiWidget : public QObject, public Widget

MouseClickStatus handleMouseClick(Event const &event,
MouseEvent::Button button = MouseEvent::Left);

/**
* Requests the widget to refresh its geometry, if it has any static
* geometry. Normally this does not need to be called. It is provided
Expand Down
6 changes: 6 additions & 0 deletions doomsday/sdk/libappfw/include/de/widgets/lineeditwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ class LIBAPPFW_PUBLIC LineEditWidget : public GuiWidget, public shell::AbstractL
public:
static KeyModifiers modifiersFromKeyEvent(KeyEvent::Modifiers const &keyMods);

#if defined (DENG_MOBILE)
protected slots:
void userEnteredText(QString);
void userFinishedTextEntry();
#endif

signals:
void enterPressed(QString text);
void editorContentChanged();
Expand Down
8 changes: 8 additions & 0 deletions doomsday/sdk/libappfw/src/guirootwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ void GuiRootWidget::update()

void GuiRootWidget::draw()
{
DENG2_GUARD(this);

DENG2_ASSERT_IN_RENDER_THREAD();

d->focusIndicator->initialize();

if (d->noFramesDrawnYet)
Expand Down Expand Up @@ -459,6 +463,10 @@ void GuiRootWidget::draw()

void GuiRootWidget::drawUntil(Widget &until)
{
DENG2_GUARD(this);

DENG2_ASSERT_IN_RENDER_THREAD();

d->painter.setNormalizedScissor();

NotifyArgs args = notifyArgsForDraw();
Expand Down
28 changes: 26 additions & 2 deletions doomsday/sdk/libappfw/src/widgets/lineeditwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,26 @@ void LineEditWidget::focusGained()
}

#if defined (DENG_MOBILE)
qGuiApp->inputMethod()->show();
{
auto &win = root().window();
emit win.textEntryRequest();

// Text entry happens via OS virtual keyboard.
connect(&win, &GLWindow::userEnteredText, this, &LineEditWidget::userEnteredText);
connect(&win, &GLWindow::userFinishedTextEntry, this, &LineEditWidget::userFinishedTextEntry);
}
#endif
}

void LineEditWidget::focusLost()
{
#if defined (DENG_MOBILE)
qGuiApp->inputMethod()->hide();
{
auto &win = root().window();
disconnect(&win, &GLWindow::userEnteredText, this, &LineEditWidget::userEnteredText);
disconnect(&win, &GLWindow::userFinishedTextEntry, this, &LineEditWidget::userFinishedTextEntry);
emit win.textEntryDismiss();
}
#endif

d->contentChanged(false /* don't notify */);
Expand All @@ -401,6 +413,18 @@ void LineEditWidget::focusLost()
d->hint->setOpacity(1, 1, 0.5);
}
}

#if defined (DENG_MOBILE)
void LineEditWidget::userEnteredText(QString text)
{
setText(text);
}

void LineEditWidget::userFinishedTextEntry()
{
root().popFocus();
}
#endif

void LineEditWidget::update()
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libcore/include/de/widgets/rootwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class RuleRectangle;
*
* @ingroup widgets
*/
class DENG2_PUBLIC RootWidget : public Widget
class DENG2_PUBLIC RootWidget : public Widget, public Lockable
{
public:
typedef Vector2ui Size;
Expand Down
8 changes: 7 additions & 1 deletion doomsday/sdk/libcore/src/widgets/rootwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ Rule const &RootWidget::viewHeight() const

void RootWidget::setViewSize(Size const &size)
{
DENG2_GUARD(this);

d->viewRect->setInput(Rule::Right, Constu(size.x));
d->viewRect->setInput(Rule::Bottom, Constu(size.y));

Expand Down Expand Up @@ -139,23 +141,27 @@ Widget *RootWidget::focus() const

void RootWidget::initialize()
{
DENG2_GUARD(this);
notifyTree(&Widget::initialize);
}

void RootWidget::update()
{
DENG2_GUARD(this);
notifyTree(&Widget::update);
}

void RootWidget::draw()
{
DENG2_GUARD(this);
notifyTree(notifyArgsForDraw());

Rule::markRulesValid(); // All done for this frame.
}

bool RootWidget::processEvent(Event const &event)
{
DENG2_GUARD(this);

// Focus is only for the keyboard.
if (event.isKey() && focus())
{
Expand Down
21 changes: 20 additions & 1 deletion doomsday/sdk/libgui/include/de/gui/glwindow_qml.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,18 @@ class LIBGUI_PUBLIC GLWindow : public QObject, public Asset
bool event(QEvent *) override;
*/

signals:
void textEntryRequest();
void textEntryDismiss();
void userEnteredText(QString);
void userFinishedTextEntry();
void rootDimensionsChanged(QRect);

public slots:
void paintGL();
void frameWasSwapped();

private:
DENG2_PRIVATE(d)
};
Expand All @@ -228,9 +235,21 @@ class GLQuickItem : public QQuickItem

virtual GLWindow *makeWindowRenderer() = 0;

signals:
void textEntryRequest();
void textEntryDismiss();

public slots:
void sync();
void cleanup();

void dimensionsChanged();
void userEnteredText(QString text);
void userFinishedTextEntry();

void onTouchPressed(QVariantList touchPoints);
void onTouchUpdated(QVariantList touchPoints);
void onTouchReleased(QVariantList touchPoints);

private slots:
void handleWindowChanged(QQuickWindow *win);
Expand Down
Loading

0 comments on commit ed281f2

Please sign in to comment.