Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+8
@@ -0,0 +1,8 @@
|
||||
#
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
#
|
||||
|
||||
ADD_SUBDIRECTORY(VirtualKeyboard)
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
# Created by Patric Karwat, SLSE, 2018-01-17
|
||||
#
|
||||
|
||||
SET(vbk_SRCS
|
||||
vkb_gui_plugin.cpp
|
||||
vkb_gui_plugin.h
|
||||
)
|
||||
|
||||
|
||||
NGL_ADD_LIBRARY(WS VkbPlugin MODULE ${vbk_SRCS})
|
||||
NGL_TARGET_LINK_LIBRARIES(VkbPlugin
|
||||
NGLLogger
|
||||
LtsSession
|
||||
LtsSessionData
|
||||
LtsWidgets
|
||||
LtsVirtualKeyboard
|
||||
VbkGuiPluginInterface
|
||||
Qt5::Widgets
|
||||
)
|
||||
|
||||
NGL_INSTALL_TARGET(VkbPlugin)
|
||||
@@ -0,0 +1,223 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Gui Plugin for Virtual Keyboard
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2018-06-07
|
||||
*/
|
||||
|
||||
#include "vkb_gui_plugin.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <LtsSession/lts_session_data.h>
|
||||
#include <LtsVirtualKeyboard/LtsVirtualKeyboard.h>
|
||||
#include <LtsVirtualKeyboard/LtsKeyPushButton.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QLineEdit>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QScrollArea>
|
||||
#include <QSpinBox>
|
||||
#include <QTextEdit>
|
||||
#include <QComboBox>
|
||||
#ifdef Q_OS_WIN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace VirtualKeyboard
|
||||
{
|
||||
|
||||
bool isHardwareKeyboardAvailable()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
UINT numDevices = 0;
|
||||
int count = 0;
|
||||
int maxCount = 0;
|
||||
if (strcmp(PROJECTBUILD, "demotablet") == 0) //somehow the other tablet has an internal keyboard so we need to skipt the first one =_=
|
||||
maxCount = 1;
|
||||
if (GetRawInputDeviceList(nullptr, &numDevices, sizeof(RAWINPUTDEVICELIST)) != 0)
|
||||
return false;
|
||||
std::vector<RAWINPUTDEVICELIST> devices(numDevices);
|
||||
if (GetRawInputDeviceList(&devices[0], &numDevices, sizeof(RAWINPUTDEVICELIST)) == (UINT)-1)
|
||||
return false;
|
||||
RID_DEVICE_INFO rdi;
|
||||
UINT len = sizeof(rdi);
|
||||
for (const RAWINPUTDEVICELIST &device : devices)
|
||||
{
|
||||
if (device.dwType != RIM_TYPEKEYBOARD)
|
||||
continue;
|
||||
GetRawInputDeviceInfo(device.hDevice, RIDI_DEVICEINFO, &rdi, &len);
|
||||
if (rdi.dwType != RIM_TYPEKEYBOARD)
|
||||
continue;
|
||||
if (rdi.keyboard.dwType == 81) // no documentation about this, try'n'error... :(
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count > maxCount)
|
||||
return true;
|
||||
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
std::shared_ptr<GuiPluginBase::Interface> GuiPlugin::createGuiInterface(LtsSession::LtsSession *session)
|
||||
{
|
||||
return std::make_shared<InterfaceImpl>(session);
|
||||
}
|
||||
|
||||
|
||||
InterfaceImpl::InterfaceImpl(LtsSession::LtsSession *session)
|
||||
: GuiPluginBase::Interface(session, NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Plugins.Gui.Vkb"))
|
||||
{}
|
||||
|
||||
|
||||
InterfaceImpl::~InterfaceImpl()
|
||||
{
|
||||
if (m_keyboard)
|
||||
m_keyboard->cleanupLtsVirtualKeyboard();
|
||||
}
|
||||
|
||||
|
||||
bool InterfaceImpl::fetchInterfaces()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void InterfaceImpl::clearInterfaces()
|
||||
{}
|
||||
|
||||
QString InterfaceImpl::menuGroup() const
|
||||
{
|
||||
return QStringLiteral("VirtualKeyboard");
|
||||
}
|
||||
|
||||
|
||||
void InterfaceImpl::init()
|
||||
{
|
||||
onShowKey(nullptr);
|
||||
|
||||
m_hasInit = false; // HACK: saves 5 lines of code, do not use this elsewhere! - MW
|
||||
}
|
||||
|
||||
|
||||
QVector<LtsWidgets::PluginData> InterfaceImpl::getActions()
|
||||
{
|
||||
QVector<LtsWidgets::PluginData> ret;
|
||||
LtsWidgets::PluginData plData;
|
||||
// Action 'Keyboard'
|
||||
plData.menuText = menuGroup();
|
||||
plData.identifier = QStringLiteral("vkm2");
|
||||
plData.layoutArea = LtsWidgets::LayoutArea::eMainTab;
|
||||
plData.menuIcon = QIcon(QLatin1String("icon:presets.svg"));
|
||||
plData.menuGroup = QStringLiteral("vkm");
|
||||
plData.operatorRight = 0;
|
||||
plData.closable = false;
|
||||
plData.createInstant = LtsWidgets::CreateInstantType::CreateInstantAndDiscardAction;
|
||||
plData.createWidgetFunc = [this](QWidget * parent)
|
||||
{
|
||||
return onShowKey(parent);
|
||||
};
|
||||
ret.append(plData);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
LtsWidgets::LtsDialog *InterfaceImpl::onShowKey(QWidget *)
|
||||
{
|
||||
// if (appId() == static_cast<int>(LtsSession::LtsSession::App::OC) ||
|
||||
// appId() == static_cast<int>(LtsSession::LtsSession::App::Login))
|
||||
|
||||
if (LtsSessionData::LtsSessionData::getInstance()->isTablet())
|
||||
connect(qApp, &QApplication::focusChanged, this, &InterfaceImpl::onFocusChanged);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool InterfaceImpl::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched != m_activeEventFilter)
|
||||
{
|
||||
if (watched)
|
||||
watched->removeEventFilter(this);
|
||||
return false;
|
||||
}
|
||||
if (event->type() == QEvent::MouseButtonPress)
|
||||
onFocusChanged(nullptr, m_activeEventFilter);
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool isEditable(const QWidget *w)
|
||||
{
|
||||
auto myWidget = qobject_cast<const T *>(w);
|
||||
return myWidget && !myWidget->isReadOnly();
|
||||
}
|
||||
|
||||
void InterfaceImpl::onFocusChanged(QWidget *old, QWidget *now)
|
||||
{
|
||||
Q_UNUSED(old)
|
||||
if (!now)
|
||||
return;
|
||||
|
||||
if (qobject_cast<LtsVirtualKeyboard::LtsVirtualKeyboard *>(now)
|
||||
|| (now->objectName() == QLatin1String("internalLE"))
|
||||
|| qobject_cast<QScrollArea *>(now))
|
||||
return;
|
||||
|
||||
if (isHardwareKeyboardAvailable())
|
||||
{
|
||||
if (m_keyboard)
|
||||
m_keyboard->hide(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_activeEventFilter)
|
||||
{
|
||||
m_activeEventFilter->removeEventFilter(this);
|
||||
m_activeEventFilter = nullptr;
|
||||
}
|
||||
|
||||
auto cbx = qobject_cast<const QComboBox *>(now);
|
||||
if (cbx && cbx->isEditable() && cbx->lineEdit())
|
||||
{
|
||||
m_activeEventFilter = cbx->lineEdit();
|
||||
m_activeEventFilter->installEventFilter(this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEditable<QLineEdit>(now) ||
|
||||
isEditable<QTextEdit>(now) ||
|
||||
isEditable<QPlainTextEdit>(now) ||
|
||||
isEditable<QSpinBox>(now) ||
|
||||
isEditable<QDoubleSpinBox>(now))
|
||||
{
|
||||
bool isSb = (now->inherits("QSpinBox") || now->inherits("QDoubleSpinBox"));
|
||||
//isSb = false;
|
||||
if (!m_keyboard || m_oldParent != now->parentWidget() || m_keyboard->isNumericPad() != isSb)
|
||||
{
|
||||
m_oldParent = now->parentWidget();
|
||||
m_keyboard = LtsVirtualKeyboard::LtsVirtualKeyboard::getInstance(m_session, m_oldParent /* must not be 0ptr ! */, isSb);
|
||||
}
|
||||
|
||||
if (!m_keyboard)
|
||||
return;
|
||||
|
||||
if (!m_keyboard->isVisible())
|
||||
m_keyboard->show(now, true);
|
||||
|
||||
m_keyboard->focusThis(now, isSb);
|
||||
|
||||
//m_keyboard-> move((qApp->desktop()->availableGeometry().width()-m_keyboard->width())/2, qApp->desktop()->availableGeometry().height()-m_keyboard->height()-10);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_keyboard && m_keyboard->isVisible())
|
||||
m_keyboard->hide(true);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace VirtualKeyboard
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Gui Plugin for Virtual Keyboard
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2018-06-07
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <PluginInterfaces/gui_plugin_interface.h>
|
||||
|
||||
#include <Plugins/VirtualKeyboard/vkb_gui_plugin_interface.h>
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
#include <QPointer>
|
||||
|
||||
namespace LtsVirtualKeyboard
|
||||
{
|
||||
class LtsVirtualKeyboard;
|
||||
}
|
||||
|
||||
|
||||
namespace VirtualKeyboard
|
||||
{
|
||||
|
||||
class GuiPlugin final : public QObject, public GuiPluginBase::Plugin
|
||||
{
|
||||
Q_PLUGIN_METADATA(IID "gui:3:vkb")
|
||||
Q_INTERFACES(GuiPluginBase::Plugin)
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
GuiPlugin() = default;
|
||||
~GuiPlugin() = default;
|
||||
|
||||
QString pluginName() override { return QStringLiteral("VirtualKeyboard"); }
|
||||
std::shared_ptr<GuiPluginBase::Interface> createGuiInterface(LtsSession::LtsSession *session) override;
|
||||
bool availableInPartition(IDL::PartitionType partition) const override
|
||||
{
|
||||
return partition == IDL::PartitionType::Exercise ||
|
||||
partition == IDL::PartitionType::Global ||
|
||||
partition == IDL::PartitionType::Replay;
|
||||
}
|
||||
};
|
||||
|
||||
class InterfaceImpl final : public QObject, public ForeignGuiInterface, public GuiPluginBase::Interface
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit InterfaceImpl(LtsSession::LtsSession *session);
|
||||
~InterfaceImpl();
|
||||
|
||||
bool fetchInterfaces() override;
|
||||
void clearInterfaces() override;
|
||||
QString menuGroup() const override;
|
||||
void init() override;
|
||||
|
||||
QVector<LtsWidgets::PluginData> getActions() override;
|
||||
bool availableInPartition(IDL::PartitionType partition) const override
|
||||
{
|
||||
return partition == IDL::PartitionType::Exercise ||
|
||||
partition == IDL::PartitionType::Global ||
|
||||
partition == IDL::PartitionType::Replay;
|
||||
}
|
||||
|
||||
private:
|
||||
LtsWidgets::LtsDialog *onShowKey(QWidget *parent);
|
||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void onFocusChanged(QWidget *old, QWidget *now);
|
||||
|
||||
private:
|
||||
LtsVirtualKeyboard::LtsVirtualKeyboard *m_keyboard = nullptr;
|
||||
QPointer<QWidget> m_activeEventFilter;
|
||||
QWidget *m_oldParent = nullptr;
|
||||
};
|
||||
|
||||
} // namespace VirtualKeyboard
|
||||
Reference in new issue
Block a user