Skip to content

Commit

Permalink
[fingerterm] Add option for keyboard to be fixed open. Contributes JB…
Browse files Browse the repository at this point in the history
…#49213

Provides a 'Fixed' option, in addition to 'Off', 'Fade' and 'Move', that
makes the keyboard open all of the time.
  • Loading branch information
llewelld authored and David Llewellyn-Jones committed Feb 5, 2021
1 parent 20fdef1 commit 4182ad7
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 38 deletions.
7 changes: 7 additions & 0 deletions fingerterm.pro
Expand Up @@ -92,3 +92,10 @@ contains(MEEGO_EDITION,nemo) {
desktopfile.files = $${TARGET}.desktop
INSTALLS += desktopfile
}

DISTFILES += \
data/* \
icons/*.png \
qml/*.qml \
rpm/fingerterm.changes \
rpm/fingerterm.spec
84 changes: 58 additions & 26 deletions qml/Main.qml
Expand Up @@ -89,6 +89,14 @@ Item {
anchors.fill: parent
color: bgcolor

Connections {
target: util
onKeyboardModeChanged: {
window.setTextRenderAttributes();
window.updateVKB();
}
}

Rectangle {
id: bellTimerRect
visible: opacity > 0
Expand Down Expand Up @@ -163,7 +171,8 @@ Item {
// - not in select mode, as it would be hard to select text
if (touchPoint.y < vkb.y && touchPoint.startY < vkb.y &&
Math.abs(touchPoint.y - touchPoint.startY) < 20 &&
util.dragMode !== Util.DragSelect) {
util.dragMode !== Util.DragSelect &&
util.keyboardMode != Util.KeyboardFixed) {
if (vkb.active) {
window.sleepVKB();
} else {
Expand Down Expand Up @@ -222,7 +231,9 @@ Item {
fontPointSize: util.fontSize
opacity: (util.keyboardMode == Util.KeyboardFade && vkb.active) ? 0.3
: 1.0
allowGestures: !vkb.active && !menu.showing && !urlWindow.show && !aboutDialog.show && !layoutWindow.show
allowGestures: (!vkb.active || util.keyboardMode == Util.KeyboardFixed)
&& !menu.showing && !urlWindow.show
&& !aboutDialog.show && !layoutWindow.show

Behavior on opacity {
NumberAnimation { duration: textrender.duration; easing.type: Easing.InOutQuad }
Expand All @@ -232,7 +243,7 @@ Item {
}

onCutAfterChanged: {
// this property is used in the paint function, so make sure that the element gets
// this property is used in the paint function, to make sure that the element gets
// painted with the updated value (might not otherwise happen because of caching)
textrender.redraw();
}
Expand All @@ -243,7 +254,9 @@ Item {

interval: util.keyboardFadeOutDelay
onTriggered: {
window.sleepVKB();
if (util.keyboardMode != Util.KeyboardFixed) {
window.sleepVKB();
}
}
}

Expand Down Expand Up @@ -338,46 +351,65 @@ Item {
fadeTimer.restart();
vkb.active = true;
setTextRenderAttributes();
// FIXME: This "duration = 0" hack prevents the animations running at
// other times (e.g. on screen rotation). It should be using States.
textrender.duration = 0;
}

function sleepVKB()
{
textrender.duration = window.fadeInTime;
vkb.active = false;
setTextRenderAttributes();
// FIXME: This "duration = 0" hack prevents the animations running at
// other times (e.g. on screen rotation). It should be using States.
textrender.duration = 0;
}

function setTextRenderAttributes()
function updateVKB()
{
if (util.keyboardMode == Util.KeyboardMove)
{
vkb.visibleSetting = true;
if(vkb.active) {
var move = textrender.cursorPixelPos().y + textrender.fontHeight/2
+ textrender.fontHeight*util.extraLinesFromCursor
if(move < vkb.y) {
textrender.y = 0;
textrender.cutAfter = vkb.y;
} else {
textrender.y = 0 - move + vkb.y
textrender.cutAfter = move;
}
} else {
textrender.cutAfter = textrender.height;
if(!vkb.visibleSetting)
return;

textrender.duration = 0;
fadeTimer.restart();
setTextRenderAttributes();
}

function _applyKeyboardOffset()
{
if(vkb.active) {
var move = textrender.cursorPixelPos().y + textrender.fontHeight/2
+ textrender.fontHeight*util.extraLinesFromCursor
if (move < vkb.y) {
textrender.y = 0;
textrender.cutAfter = vkb.y;
} else {
textrender.y = 0 - move + vkb.y
textrender.cutAfter = move;
}
} else {
textrender.y = 0;
textrender.cutAfter = textrender.height;
}
else if (util.keyboardMode == Util.KeyboardFade)
}

function setTextRenderAttributes()
{
var solidKeyboard = (util.keyboardMode === Util.KeyboardMove)
|| (util.keyboardMode === Util.KeyboardFixed)

if (solidKeyboard)
{
vkb.active |= (util.keyboardMode === Util.KeyboardFixed);
vkb.visibleSetting = true;
textrender.cutAfter = textrender.height;
textrender.y = 0;
_applyKeyboardOffset()
}
else // "off" (vkb disabled)
else
{
vkb.visibleSetting = false;
textrender.cutAfter = textrender.height;
vkb.visibleSetting = (util.keyboardMode === Util.KeyboardFade);
textrender.y = 0;
textrender.cutAfter = textrender.height;
}
}

Expand Down
23 changes: 16 additions & 7 deletions qml/MenuFingerterm.qml
Expand Up @@ -290,7 +290,7 @@ Item {
}
Rectangle {
width: window.buttonWidthLarge
height: window.buttonHeightLarge
height: window.buttonHeightLarge + window.buttonHeightSmall
radius: window.radiusSmall
color: "#606060"
border.color: "#000000"
Expand All @@ -306,37 +306,46 @@ Item {
horizontalAlignment: Text.AlignHCenter
}
Row {
Button {
text: "Fixed"
highlighted: util.keyboardMode == Util.KeyboardFixed
onClicked: {
util.keyboardMode = Util.KeyboardFixed
menuWin.showing = false;
}
width: window.buttonWidthHalf
height: window.buttonHeightSmall
}
Button {
text: "Off"
highlighted: util.keyboardMode == Util.KeyboardOff
onClicked: {
util.keyboardMode = Util.KeyboardOff
window.setTextRenderAttributes();
menuWin.showing = false;
}
width: window.buttonWidthSmall
width: window.buttonWidthHalf
height: window.buttonHeightSmall
}
}
Row {
Button {
text: "Fade"
highlighted: util.keyboardMode == Util.KeyboardFade
onClicked: {
util.keyboardMode = Util.KeyboardFade
window.setTextRenderAttributes();
menuWin.showing = false;
}
width: window.buttonWidthSmall
width: window.buttonWidthHalf
height: window.buttonHeightSmall
}
Button {
text: "Move"
highlighted: util.keyboardMode == Util.KeyboardMove
onClicked: {
util.keyboardMode = Util.KeyboardMove
window.setTextRenderAttributes();
menuWin.showing = false;
}
width: window.buttonWidthSmall
width: window.buttonWidthHalf
height: window.buttonHeightSmall
}
}
Expand Down
36 changes: 32 additions & 4 deletions util.cpp
Expand Up @@ -38,7 +38,8 @@ Util::Util(QSettings *settings, QObject *parent) :
QObject(parent),
iSettings(settings),
iWindow(0),
iTerm(0)
iTerm(0),
iKeyboardMode(KeyboardOff)
{
connect(QGuiApplication::clipboard(), SIGNAL(dataChanged()), this, SIGNAL(clipboardOrSelectionChanged()));
}
Expand All @@ -55,7 +56,7 @@ void Util::setWindow(QQuickView* win)
iWindow = win;
if(!iWindow)
qFatal("invalid main window");
connect(win, SIGNAL(contentOrientationChanged(Qt::ScreenOrientation)), this, SIGNAL(windowOrientationChanged()));
connect(win, SIGNAL(contentOrientationChanged(Qt::ScreenOrientation)), this, SLOT(contentOrientationChanged(Qt::ScreenOrientation)));
}

void Util::setWindowTitle(QString title)
Expand All @@ -80,6 +81,16 @@ void Util::setWindowOrientation(int orientation)
iWindow->reportContentOrientationChange(static_cast<Qt::ScreenOrientation>(orientation));
}

void Util::contentOrientationChanged(Qt::ScreenOrientation)
{
KeyboardMode mode = static_cast<KeyboardMode>(keyboardMode());
emit windowOrientationChanged();
if (mode != iKeyboardMode) {
iKeyboardMode = mode;
emit keyboardModeChanged();
}
}

void Util::setTerm(Terminal *term)
{
if (iTerm) {
Expand Down Expand Up @@ -221,12 +232,20 @@ void Util::setDragMode(int mode)

int Util::keyboardMode()
{
QString mode = settingsValue("ui/vkbShowMethod", "move").toString();
bool portrait = iWindow->contentOrientation() & (Qt::PortraitOrientation | Qt::InvertedPortraitOrientation);
QString mode;
if (portrait) {
mode = settingsValue("ui/vkbShowMethodPortrait", "move").toString();
} else {
mode = settingsValue("ui/vkbShowMethodLandscape", "move").toString();
}

if (mode == "fade") {
return KeyboardFade;
} else if (mode == "move") {
return KeyboardMove;
} else if (mode == "fixed" ) {
return KeyboardFixed;
} else {
return KeyboardOff;
}
Expand All @@ -246,12 +265,21 @@ void Util::setKeyboardMode(int mode)
case KeyboardMove:
modeString = "move";
break;
case KeyboardFixed:
modeString = "fixed";
break;
case KeyboardOff:
default:
modeString = "off";
}

setSettingsValue("ui/vkbShowMethod", modeString);
bool portrait = iWindow->contentOrientation() & (Qt::PortraitOrientation | Qt::InvertedPortraitOrientation);

if (portrait) {
setSettingsValue("ui/vkbShowMethodPortrait", modeString);
} else {
setSettingsValue("ui/vkbShowMethodLandscape", modeString);
}
emit keyboardModeChanged();
}

Expand Down
5 changes: 5 additions & 0 deletions util.h
Expand Up @@ -52,6 +52,7 @@ class Util : public QObject
public:
enum KeyboardMode {
KeyboardOff,
KeyboardFixed,
KeyboardFade,
KeyboardMove
};
Expand Down Expand Up @@ -140,6 +141,9 @@ class Util : public QObject
void orientationModeChanged();
void showWelcomeScreenChanged();

private slots:
void contentOrientationChanged(Qt::ScreenOrientation);

private:
Q_DISABLE_COPY(Util)

Expand All @@ -148,6 +152,7 @@ class Util : public QObject
QSettings* iSettings;
QQuickView* iWindow;
Terminal* iTerm;
KeyboardMode iKeyboardMode;
};

#endif // UTIL_H
2 changes: 1 addition & 1 deletion version.h
@@ -1,5 +1,5 @@
#ifndef VERSION_H
#define VERSION_H
const QString PROGRAM_VERSION="1.3.2";
const QString PROGRAM_VERSION="1.3.12";
#endif

0 comments on commit 4182ad7

Please sign in to comment.