Add Keyboard.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "KeyboardManager.h"
|
||||
|
||||
#include "KeyboardPanel.h"
|
||||
#include "Keyboard.h"
|
||||
|
||||
KeyboardManager* KeyboardManager::getInstance()
|
||||
{
|
||||
@@ -9,15 +9,66 @@ KeyboardManager* KeyboardManager::getInstance()
|
||||
}
|
||||
|
||||
KeyboardManager::KeyboardManager()
|
||||
: mKeyboardPanel(new KeyboardPanel())
|
||||
: mKeyboard(new Keyboard())
|
||||
{
|
||||
connect(mKeyboard, &Keyboard::keyboardHided, this, &KeyboardManager::restoreInputWidget);
|
||||
}
|
||||
|
||||
KeyboardManager::~KeyboardManager()
|
||||
{
|
||||
mKeyboard->deleteLater();
|
||||
}
|
||||
|
||||
void KeyboardManager::showKeyboardPanel(QWidget* aInputWidget)
|
||||
void KeyboardManager::showKeyboard(QWidget* aInputWidget)
|
||||
{
|
||||
mKeyboardPanel->showPanel(aInputWidget);
|
||||
if (nullptr == aInputWidget)
|
||||
{
|
||||
return;
|
||||
}
|
||||
mKeyboard->setEdit(aInputWidget);
|
||||
//QPoint position = aInputWidget->mapToGlobal(QPoint(0, 0));
|
||||
//mKeyboard->move(position.x(), position.y() + aInputWidget->height());
|
||||
moveInputWidget(aInputWidget);
|
||||
mKeyboard->show();
|
||||
}
|
||||
|
||||
void KeyboardManager::hideKeyboard()
|
||||
{
|
||||
mKeyboard->hideKeyboard();
|
||||
}
|
||||
|
||||
void KeyboardManager::moveInputWidget(QWidget* aInputWidget)
|
||||
{
|
||||
if (nullptr == aInputWidget)
|
||||
{
|
||||
return;
|
||||
}
|
||||
QPoint pos = aInputWidget->mapToGlobal(QPoint(0, 0));
|
||||
int distance = pos.y() + aInputWidget->height() - 1080 + mKeyboard->height();
|
||||
if (distance > 0)
|
||||
{
|
||||
while (nullptr != aInputWidget)
|
||||
{
|
||||
aInputWidget = aInputWidget->parentWidget();
|
||||
if (aInputWidget->inherits("QDialog"))
|
||||
{
|
||||
pos = aInputWidget->mapToGlobal(QPoint(0, 0));
|
||||
mMovedDistance = distance + 5;
|
||||
mMovedWidget = QPointer<QWidget>(aInputWidget);
|
||||
aInputWidget->move(pos.x(), pos.y() - mMovedDistance);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KeyboardManager::restoreInputWidget()
|
||||
{
|
||||
if (mMovedWidget)
|
||||
{
|
||||
QPoint pos = mMovedWidget->mapToGlobal(QPoint(0, 0));
|
||||
mMovedWidget->move(pos.x(), pos.y() + mMovedDistance);
|
||||
}
|
||||
mMovedWidget.clear();
|
||||
mMovedDistance = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user