Skip to content

Commit c53aa85

Browse files
committed
Add support for Windows virtual keyboard
Fixes #4478
1 parent a2d6b02 commit c53aa85

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

src/StelMainView.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,16 @@
5757
#include <QTimer>
5858
#include <QWidget>
5959
#include <QWindow>
60+
#include <QSpinBox>
61+
#include <QLineEdit>
6062
#include <QMessageBox>
63+
#include <QDoubleSpinBox>
6164
#include <QStandardPaths>
6265
#include <QStorageInfo>
6366
#ifdef Q_OS_WIN
6467
#include <QPinchGesture>
68+
#include <windows.h>
69+
#include <shellapi.h>
6570
#endif
6671
#include <QOpenGLShader>
6772
#include <QOpenGLShaderProgram>
@@ -80,6 +85,32 @@ Q_LOGGING_CATEGORY(mainview, "stel.MainView")
8085
# define GL_MAX_TEXTURE_MAX_ANISOTROPY 0x84FF
8186
#endif
8287

88+
namespace
89+
{
90+
#ifdef Q_OS_WIN
91+
void showTouchKeyboard(const bool show)
92+
{
93+
const auto& cfg = *StelApp::getInstance().getSettings();
94+
if (cfg.value("gui/flag_enable_touch_keyboard", false).toBool() == false)
95+
return;
96+
const auto cmd = cfg.value("gui/touch_keyboard_cmd",
97+
"osk.exe").toString().toStdString();
98+
const auto windowClass = cfg.value("gui/touch_keyboard_window_class",
99+
"OSKMainClass").toString().toStdWString();
100+
if (show)
101+
{
102+
ShellExecuteA(nullptr, "open", cmd.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
103+
}
104+
else
105+
{
106+
const auto hWnd = FindWindowW(windowClass.c_str(), nullptr);
107+
if (hWnd && IsWindowVisible(hWnd))
108+
PostMessageW(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0);
109+
}
110+
}
111+
#endif
112+
}
113+
83114
// Initialize static variables
84115
StelMainView* StelMainView::singleton = Q_NULLPTR;
85116

@@ -727,11 +758,27 @@ void StelMainView::resizeEvent(QResizeEvent* event)
727758

728759
bool StelMainView::eventFilter(QObject *obj, QEvent *event)
729760
{
730-
if(event->type() == QEvent::FileOpen)
761+
switch (event->type())
762+
{
763+
case QEvent::FileOpen:
731764
{
732765
QFileOpenEvent *openEvent = static_cast<QFileOpenEvent *>(event);
733766
//qDebug() << "load script:" << openEvent->file();
734767
qApp->setProperty("onetime_startup_script", openEvent->file());
768+
break;
769+
}
770+
#ifdef Q_OS_WIN
771+
case QEvent::FocusIn:
772+
if (qobject_cast<QLineEdit*>(obj) || qobject_cast<QSpinBox*>(obj) || qobject_cast<QDoubleSpinBox*>(obj))
773+
showTouchKeyboard(true);
774+
return false;
775+
case QEvent::FocusOut:
776+
if (qobject_cast<QLineEdit*>(obj) || qobject_cast<QSpinBox*>(obj) || qobject_cast<QDoubleSpinBox*>(obj))
777+
showTouchKeyboard(false);
778+
return false;
779+
#endif
780+
default:
781+
break;
735782
}
736783
return QGraphicsView::eventFilter(obj, event);
737784
}

0 commit comments

Comments
 (0)