modify
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
project(NumKeyBoard LANGUAGES CXX)
|
||||
|
||||
set(NUMKEYBOARD_SOURCES
|
||||
numkeydia.cpp
|
||||
numkeydia.ui
|
||||
NumKeyBoard.qrc
|
||||
)
|
||||
|
||||
set(NUMKEYBOARD_HEADERS
|
||||
numkeydia.h
|
||||
NumKeyBoard_global.h
|
||||
)
|
||||
|
||||
add_library(${PROJECT_NAME} SHARED
|
||||
${NUMKEYBOARD_SOURCES}
|
||||
${NUMKEYBOARD_HEADERS}
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
||||
NUMKEYBOARD_LIBRARY
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC
|
||||
Qt${QT_VERSION_MAJOR}::Core
|
||||
Qt${QT_VERSION_MAJOR}::Gui
|
||||
Qt${QT_VERSION_MAJOR}::Widgets
|
||||
)
|
||||
+7
-1
@@ -1,6 +1,8 @@
|
||||
QT += core gui widgets
|
||||
|
||||
TEMPLATE = lib
|
||||
TARGET = NumKeyBoard
|
||||
DEFINES += NUMKEYBOARD_LIBRARY
|
||||
|
||||
CONFIG += c++17
|
||||
|
||||
@@ -12,12 +14,16 @@ OBJECTS_DIR = $$PWD/Build/objs
|
||||
RCC_DIR = $$PWD/Build/resources
|
||||
UI_DIR = $$PWD/Build/ui
|
||||
|
||||
HEADERS += $$PWD/numkeydia.h
|
||||
HEADERS += \
|
||||
$$PWD/NumKeyBoard_global.h \
|
||||
$$PWD/numkeydia.h
|
||||
|
||||
SOURCES += $$PWD/numkeydia.cpp
|
||||
|
||||
FORMS += $$PWD/numkeydia.ui
|
||||
|
||||
RESOURCES += $$PWD/NumKeyBoard.qrc
|
||||
|
||||
# Default rules for deployment.
|
||||
unix {
|
||||
target.path = /usr/lib
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file alias="commonWidget.qss">../../Res/Qss/commonWidget.qss</file>
|
||||
<file alias="Images/keyboard.svg">../../Res/Images/keyboard.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef NUMKEYBOARD_GLOBAL_H
|
||||
#define NUMKEYBOARD_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(NUMKEYBOARD_LIBRARY)
|
||||
#define NUMKEYBOARD_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define NUMKEYBOARD_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // NUMKEYBOARD_GLOBAL_H
|
||||
@@ -1,66 +1,31 @@
|
||||
# 数字软键盘
|
||||
# NumKeyBoard
|
||||
|
||||
## qmake作为pri使用
|
||||
`Libs/NumKeyBoard` is the shared numeric keyboard library used by both `TGcs` and `LauncherLib`.
|
||||
|
||||
- 将文件夹复制到主工程Libs目录下
|
||||
- 主工程pro文件中加入:
|
||||
## qmake
|
||||
|
||||
Build the library from `TGcsProject.pro` or `Libs/NumKeyBoard/NumKeyBoard.pro`, then link it from consumer projects:
|
||||
|
||||
```qmake
|
||||
include($$PWD/Libs/SoftNumKeyBoard/NumKeyBoard.pri)
|
||||
unix|win32: LIBS += -L$$PWD/Build/Libs/ -lNumKeyBoard
|
||||
INCLUDEPATH += $$PWD/Libs/NumKeyBoard
|
||||
DEPENDPATH += $$PWD/Libs/NumKeyBoard
|
||||
```
|
||||
|
||||
- 主工程中重写eventFilter函数,实现点击lineedit时,调出小键盘
|
||||
## API
|
||||
|
||||
Use the shared singleton-style keyboard API:
|
||||
|
||||
```cpp
|
||||
protected:
|
||||
virtual bool eventFilter(QObject * obj, QEvent *event) override;
|
||||
```
|
||||
|
||||
```cpp
|
||||
bool SettingWidget::eventFilter(QObject *obj, QEvent * event)
|
||||
{
|
||||
auto _obj = static_cast<QLineEdit *>(obj);
|
||||
if(m_inputList.contains(_obj))
|
||||
{
|
||||
if(event->type() == QEvent::FocusIn)
|
||||
{
|
||||
if(!_keyBoard)
|
||||
{
|
||||
_keyBoard = new NumKeyDia(this);
|
||||
}
|
||||
//传入对应的QLineEdit
|
||||
_keyBoard->setPLineEdit(_obj);
|
||||
_keyBoard->exec();
|
||||
//QLineEdit取消聚焦,可以不用
|
||||
_obj->clearFocus();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return QObject::eventFilter(obj, event);
|
||||
}
|
||||
```
|
||||
|
||||
- 对应的控件安装事件过滤器
|
||||
|
||||
```cpp
|
||||
m_inputList = this->findChildren<QLineEdit *>();
|
||||
foreach (auto &i, m_inputList)
|
||||
{
|
||||
i->installEventFilter(this);
|
||||
i->setFocusPolicy(Qt::ClickFocus);
|
||||
}
|
||||
```
|
||||
|
||||
- 控件设置属性
|
||||
|
||||
```cpp
|
||||
//设置输入输出的最大值、最小值、名字和是否是数字
|
||||
ui->lineEdit_energyA->setProperty("IsNum", true);
|
||||
//double时,默认保留三位小数
|
||||
ui->lineEdit_energyA->setProperty("IsDouble", true);
|
||||
//输入的数不能超过最大值和最小值
|
||||
ui->lineEdit_energyA->setProperty("Max", 1.000);
|
||||
ui->lineEdit_energyA->setProperty("Min", 0.000);
|
||||
ui->lineEdit_energyA->setProperty("Name", tr("PressureA"));
|
||||
auto *keyboard = KeyBoard::app();
|
||||
if(!keyboard)
|
||||
{
|
||||
keyboard = new NumKeyDia;
|
||||
}
|
||||
|
||||
keyboard->setValue(lineEdit->text());
|
||||
keyboard->exec();
|
||||
lineEdit->setText(keyboard->getValue());
|
||||
```
|
||||
|
||||
The old `setPLineEdit` / range-validation API is no longer part of the shared library.
|
||||
|
||||
+155
-136
@@ -1,192 +1,135 @@
|
||||
#include "numkeydia.h"
|
||||
#include "numkeydia.h"
|
||||
#include "ui_numkeydia.h"
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMessageBox>
|
||||
#include <QFile>
|
||||
#include <QMouseEvent>
|
||||
#include <QPushButton>
|
||||
#include <QShortcut>
|
||||
#include <QTextStream>
|
||||
#include <QtGlobal>
|
||||
|
||||
namespace
|
||||
{
|
||||
void loadKeyboardStyleSheet(QWidget *widget)
|
||||
{
|
||||
if(!widget)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(QStringLiteral(":/commonWidget.qss"));
|
||||
if(!file.open(QFile::ReadOnly | QFile::Text))
|
||||
{
|
||||
qDebug() << QStringLiteral("Unable to load keyboard stylesheet");
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream stream(&file);
|
||||
widget->setStyleSheet(stream.readAll());
|
||||
}
|
||||
}
|
||||
|
||||
NumKeyDia *NumKeyDia::singleton = nullptr;
|
||||
|
||||
NumKeyDia::NumKeyDia(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::NumKeyDia)
|
||||
{
|
||||
loadKeyboardStyleSheet(this);
|
||||
if(singleton != nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
singleton = this;
|
||||
ui->setupUi(this);
|
||||
this->setWindowFlag(Qt::FramelessWindowHint);
|
||||
ui->lineEdit_input->setCursorPosition(Qt::StrongFocus);
|
||||
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
|
||||
ui->lineEdit_input->setFocusPolicy(Qt::StrongFocus);
|
||||
auto _btnInputList = ui->widget_input->findChildren<QPushButton *>();
|
||||
foreach (auto &i, _btnInputList)
|
||||
{
|
||||
connect(i, &QPushButton::clicked, this, &NumKeyDia::btn_input_clicked);
|
||||
i->setFocusPolicy(Qt::NoFocus);
|
||||
}
|
||||
|
||||
auto *returnShortcut = new QShortcut(QKeySequence(Qt::Key_Return), this);
|
||||
connect(returnShortcut, &QShortcut::activated, this, &NumKeyDia::on_btn_ok_clicked);
|
||||
|
||||
auto *enterShortcut = new QShortcut(QKeySequence(Qt::Key_Enter), this);
|
||||
connect(enterShortcut, &QShortcut::activated, this, &NumKeyDia::on_btn_ok_clicked);
|
||||
|
||||
ui->toolButton_ico->installEventFilter(this);
|
||||
ui->label_appInfo->installEventFilter(this);
|
||||
ui->btn_clear->setText(QStringLiteral("<"));
|
||||
setInputPage(InputPage::NumberPage);
|
||||
}
|
||||
|
||||
NumKeyDia::~NumKeyDia()
|
||||
{
|
||||
if(singleton == this)
|
||||
{
|
||||
singleton = nullptr;
|
||||
}
|
||||
delete ui;
|
||||
}
|
||||
|
||||
bool NumKeyDia::eventFilter(QObject *, QEvent *event)
|
||||
{
|
||||
if(event->type() == QEvent::MouseButtonDblClick)
|
||||
if(event->type() == QEvent::MouseButtonPress)
|
||||
{
|
||||
if(!m_bMaxFlag)
|
||||
{
|
||||
this->showFullScreen();
|
||||
m_bMaxFlag = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->showNormal();
|
||||
m_bMaxFlag = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(event->type() == QEvent::MouseButtonPress)
|
||||
{
|
||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
||||
auto *mouseEvent = static_cast<QMouseEvent *>(event);
|
||||
m_point = mouseEvent->globalPos() - frameGeometry().topLeft();
|
||||
//鼠标位置减去左上角的左边
|
||||
}
|
||||
else if(event->type() == QEvent::MouseMove)
|
||||
{
|
||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
||||
auto *mouseEvent = static_cast<QMouseEvent *>(event);
|
||||
move(mouseEvent->globalPos() - m_point);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QLineEdit *NumKeyDia::pLineEdit() const
|
||||
void NumKeyDia::setValue(const QString &value)
|
||||
{
|
||||
return m_pLineEdit;
|
||||
}
|
||||
|
||||
void NumKeyDia::setPLineEdit(QLineEdit *newPLineEdit)
|
||||
{
|
||||
m_pLineEdit = newPLineEdit;
|
||||
QString _text = m_pLineEdit->text();
|
||||
// int _cnt = _text.count();
|
||||
// for(int i = 0; i < _cnt; ++i)
|
||||
// {
|
||||
// if(_text.at(0) != "1" && _text.at(0) != "2" && _text.at(0) != "3" && _text.at(0) != "4" &&
|
||||
// _text.at(0) != "5" && _text.at(0) != "6" && _text.at(0) != "7" && _text.at(0) != "8" && _text.at(0) != "9")
|
||||
// {
|
||||
// _text.remove(0, 1);
|
||||
// }
|
||||
// }
|
||||
this->value = value;
|
||||
setInputPage(InputPage::NumberPage);
|
||||
ui->lineEdit_input->setFocus();
|
||||
ui->lineEdit_input->setText(_text);
|
||||
newPLineEdit->setEnabled(false);
|
||||
ui->lineEdit_input->setText(value);
|
||||
ui->lineEdit_input->setCursorPosition(ui->lineEdit_input->text().size());
|
||||
|
||||
m_firstInputFlag = true;
|
||||
|
||||
ui->label_3->setText(m_pLineEdit->property("Name").toString() + ": ");
|
||||
|
||||
//最大值和最小值显示
|
||||
m_isNum = m_pLineEdit->property("IsNum").toBool();
|
||||
if(!m_isNum)
|
||||
{
|
||||
ui->label_min->setText(tr("no limit"));
|
||||
ui->label_max->setText(tr("no limit"));
|
||||
return;
|
||||
}
|
||||
|
||||
m_minValue = m_pLineEdit->property("Min").toDouble();
|
||||
m_maxValue = m_pLineEdit->property("Max").toDouble();
|
||||
|
||||
m_isDouble = m_pLineEdit->property("IsDouble").toBool();
|
||||
|
||||
if(m_isDouble)
|
||||
QString &NumKeyDia::getValue()
|
||||
{
|
||||
m_format = m_pLineEdit->property("Format").toInt();
|
||||
m_prec = m_pLineEdit->property("Prec").toInt();
|
||||
}
|
||||
|
||||
if(m_minValue == m_maxValue)
|
||||
{
|
||||
ui->label_min->setText(tr("no limit"));
|
||||
ui->label_max->setText(tr("no limit"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(m_isDouble)
|
||||
{
|
||||
ui->label_max->setText(QString::number(m_maxValue, m_format, m_prec));
|
||||
ui->label_min->setText(QString::number(m_minValue, m_format, m_prec));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->label_max->setText(QString::number(m_maxValue, 10, 0));
|
||||
ui->label_min->setText(QString::number(m_minValue, 10, 0));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void NumKeyDia::on_btn_ok_clicked()
|
||||
{
|
||||
if(!m_pLineEdit)
|
||||
return;
|
||||
|
||||
//如果输入为空,那么设为0
|
||||
QString _res = ui->lineEdit_input->text();
|
||||
if(_res == "")
|
||||
_res = "0";
|
||||
|
||||
//不是数字,直接设置后返回
|
||||
if(!m_isNum)
|
||||
if(_res.isEmpty())
|
||||
{
|
||||
m_pLineEdit->setText(_res);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool ok;
|
||||
double _d = ui->lineEdit_input->text().toDouble(&ok);
|
||||
|
||||
if(!ok)
|
||||
{
|
||||
QMessageBox::critical(this, "error", "Input is not a number!\nPlease reInput");
|
||||
return;
|
||||
_res = QStringLiteral("0");
|
||||
}
|
||||
|
||||
bool _isNotValid = false;
|
||||
if(m_minValue < m_maxValue)
|
||||
{
|
||||
// _d = (_d < m_minValue) ? m_minValue : _d;
|
||||
// _d = (_d > m_maxValue) ? m_maxValue : _d;
|
||||
if(_d < m_minValue || _d > m_maxValue)
|
||||
_isNotValid = true;
|
||||
}
|
||||
if(_isNotValid)
|
||||
{
|
||||
QMessageBox::critical(this, "error", "Input is not valid!\nPlease reInput");
|
||||
return;
|
||||
}
|
||||
|
||||
if(m_isDouble)
|
||||
m_pLineEdit->setText(QString::number(_d, m_format, m_prec));
|
||||
else
|
||||
m_pLineEdit->setText(QString::number(_d, 10, 0));
|
||||
}
|
||||
value = _res;
|
||||
|
||||
closeKeyBoard();
|
||||
}
|
||||
|
||||
|
||||
void NumKeyDia::on_btn_cancel_clicked()
|
||||
{
|
||||
//取消,关闭数字键盘
|
||||
closeKeyBoard();
|
||||
}
|
||||
|
||||
|
||||
void NumKeyDia::on_btn_clear_clicked()
|
||||
{
|
||||
//清空
|
||||
ui->lineEdit_input->clear();
|
||||
m_firstInputFlag = false;
|
||||
const int currentPosition = ui->lineEdit_input->cursorPosition();
|
||||
ui->lineEdit_input->setCursorPosition(qMax(0, currentPosition - 1));
|
||||
ui->lineEdit_input->setFocus();
|
||||
}
|
||||
|
||||
|
||||
void NumKeyDia::on_btn_back_clicked()
|
||||
{
|
||||
m_firstInputFlag = false;
|
||||
@@ -194,51 +137,127 @@ void NumKeyDia::on_btn_back_clicked()
|
||||
int _index = ui->lineEdit_input->cursorPosition();
|
||||
QString _currentText = ui->lineEdit_input->text();
|
||||
|
||||
if(_currentText == "")
|
||||
if(_currentText.isEmpty())
|
||||
{
|
||||
ui->lineEdit_input->setFocus();
|
||||
}
|
||||
|
||||
//当前光标在最前面,不做任何处理
|
||||
if(_index != 0)
|
||||
{
|
||||
//删除前一个字符
|
||||
_currentText.remove(_index - 1, 1);
|
||||
ui->lineEdit_input->setText(_currentText);
|
||||
}
|
||||
|
||||
ui->lineEdit_input->setFocus();
|
||||
ui->lineEdit_input->setCursorPosition(_index - 1);
|
||||
ui->lineEdit_input->setCursorPosition(qMax(0, _index - 1));
|
||||
}
|
||||
|
||||
void NumKeyDia::btn_input_clicked()
|
||||
{
|
||||
auto *_btnClicked = qobject_cast<QPushButton *>(sender());
|
||||
if(!_btnClicked)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(_btnClicked->property("isModeSwitch").toBool())
|
||||
{
|
||||
const auto nextPage = (m_inputPage == InputPage::NumberPage)
|
||||
? InputPage::SymbolPage
|
||||
: InputPage::NumberPage;
|
||||
setInputPage(nextPage);
|
||||
ui->lineEdit_input->setFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
if(m_firstInputFlag)
|
||||
{
|
||||
ui->lineEdit_input->clear();
|
||||
m_firstInputFlag = false;
|
||||
}
|
||||
auto _btnClicked = qobject_cast<QPushButton *>(sender());
|
||||
QString _inputValue = _btnClicked->text();
|
||||
|
||||
const QString _inputValue = _btnClicked->property("inputValue").toString();
|
||||
if(_inputValue.isEmpty())
|
||||
{
|
||||
ui->lineEdit_input->setFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
int _index = ui->lineEdit_input->cursorPosition();
|
||||
QString _currentText = ui->lineEdit_input->text();
|
||||
|
||||
_currentText.insert(_index, _inputValue);
|
||||
ui->lineEdit_input->setText(_currentText);
|
||||
ui->lineEdit_input->setFocus();
|
||||
ui->lineEdit_input->setCursorPosition(_index + _inputValue.size());
|
||||
}
|
||||
|
||||
void NumKeyDia::closeKeyBoard()
|
||||
{
|
||||
this->close();
|
||||
m_pLineEdit->setEnabled(true);
|
||||
}
|
||||
|
||||
void NumKeyDia::setMaxValue(double newMaxValue)
|
||||
void NumKeyDia::setInputPage(InputPage page)
|
||||
{
|
||||
m_maxValue = newMaxValue;
|
||||
m_inputPage = page;
|
||||
refreshInputButtons();
|
||||
}
|
||||
|
||||
void NumKeyDia::setMinValue(double newMinValue)
|
||||
void NumKeyDia::refreshInputButtons()
|
||||
{
|
||||
m_minValue = newMinValue;
|
||||
if(m_inputPage == InputPage::NumberPage)
|
||||
{
|
||||
configureInputButton(ui->btn_1, QStringLiteral("1"), QStringLiteral("1"), true);
|
||||
configureInputButton(ui->btn_2, QStringLiteral("2"), QStringLiteral("2"), true);
|
||||
configureInputButton(ui->btn_3, QStringLiteral("3"), QStringLiteral("3"), true);
|
||||
configureInputButton(ui->btn_4, QStringLiteral("4"), QStringLiteral("4"), true);
|
||||
configureInputButton(ui->btn_5, QStringLiteral("5"), QStringLiteral("5"), true);
|
||||
configureInputButton(ui->btn_6, QStringLiteral("6"), QStringLiteral("6"), true);
|
||||
configureInputButton(ui->btn_7, QStringLiteral("7"), QStringLiteral("7"), true);
|
||||
configureInputButton(ui->btn_8, QStringLiteral("8"), QStringLiteral("8"), true);
|
||||
configureInputButton(ui->btn_9, QStringLiteral("9"), QStringLiteral("9"), true);
|
||||
configureInputButton(ui->btn_sub, QStringLiteral("#+="), QString(), true, true);
|
||||
configureInputButton(ui->btn_0, QStringLiteral("0"), QStringLiteral("0"), true);
|
||||
configureInputButton(ui->pushButton_dot, QStringLiteral("."), QStringLiteral("."), true);
|
||||
return;
|
||||
}
|
||||
|
||||
configureInputButton(ui->btn_1, QStringLiteral("/"), QStringLiteral("/"), true);
|
||||
configureInputButton(ui->btn_2, QStringLiteral("-"), QStringLiteral("-"), true);
|
||||
configureInputButton(ui->btn_3, QStringLiteral(":"), QStringLiteral(":"), true);
|
||||
const QString degreeSymbol(QChar(0x00B0));
|
||||
configureInputButton(ui->btn_4, degreeSymbol, degreeSymbol, true);
|
||||
configureInputButton(ui->btn_5, QStringLiteral("'"), QStringLiteral("'"), true);
|
||||
configureInputButton(ui->btn_6, QStringLiteral("\""), QStringLiteral("\""), true);
|
||||
configureInputButton(ui->btn_7, QStringLiteral("."), QStringLiteral("."), true);
|
||||
configureInputButton(ui->btn_8, QStringLiteral("_"), QStringLiteral("_"), true);
|
||||
configureInputButton(ui->btn_9, QStringLiteral("@"), QStringLiteral("@"), true);
|
||||
configureInputButton(ui->btn_sub, QStringLiteral("123"), QString(), true, true);
|
||||
configureInputButton(ui->btn_0, QStringLiteral("+"), QStringLiteral("+"), true);
|
||||
configureInputButton(ui->pushButton_dot, QStringLiteral(","), QStringLiteral(","), true);
|
||||
}
|
||||
|
||||
void NumKeyDia::configureInputButton(QPushButton *button,
|
||||
const QString &label,
|
||||
const QString &value,
|
||||
bool enabled,
|
||||
bool isModeSwitch)
|
||||
{
|
||||
if(!button)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
button->setText(label);
|
||||
button->setEnabled(enabled);
|
||||
button->setProperty("inputValue", value);
|
||||
button->setProperty("isModeSwitch", isModeSwitch);
|
||||
}
|
||||
|
||||
namespace KeyBoard
|
||||
{
|
||||
NumKeyDia *app()
|
||||
{
|
||||
return NumKeyDia::instance();
|
||||
};
|
||||
};
|
||||
|
||||
+32
-16
@@ -1,16 +1,18 @@
|
||||
#ifndef NUMKEYDIA_H
|
||||
#ifndef NUMKEYDIA_H
|
||||
#define NUMKEYDIA_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
#include "NumKeyBoard_global.h"
|
||||
#include <QDialog>
|
||||
#include <QLineEdit>
|
||||
|
||||
class QPushButton;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class NumKeyDia;
|
||||
}
|
||||
|
||||
class Q_DECL_EXPORT NumKeyDia : public QDialog
|
||||
class NUMKEYBOARD_EXPORT NumKeyDia : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -18,12 +20,13 @@ public:
|
||||
explicit NumKeyDia(QWidget *parent = nullptr);
|
||||
~NumKeyDia();
|
||||
|
||||
QLineEdit *pLineEdit() const;
|
||||
void setPLineEdit(QLineEdit *newPLineEdit);
|
||||
static NumKeyDia *instance()
|
||||
{
|
||||
return singleton;
|
||||
}
|
||||
|
||||
void setMinValue(double newMinValue);
|
||||
|
||||
void setMaxValue(double newMaxValue);
|
||||
void setValue(const QString &value);
|
||||
QString &getValue();
|
||||
|
||||
protected:
|
||||
virtual bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
@@ -42,22 +45,35 @@ private slots:
|
||||
void closeKeyBoard();
|
||||
|
||||
private:
|
||||
enum class InputPage
|
||||
{
|
||||
NumberPage,
|
||||
SymbolPage
|
||||
};
|
||||
|
||||
void setInputPage(InputPage page);
|
||||
void refreshInputButtons();
|
||||
void configureInputButton(QPushButton *button,
|
||||
const QString &label,
|
||||
const QString &value,
|
||||
bool enabled,
|
||||
bool isModeSwitch = false);
|
||||
|
||||
Ui::NumKeyDia *ui;
|
||||
|
||||
QLineEdit *m_pLineEdit = nullptr;
|
||||
static NumKeyDia *singleton;
|
||||
|
||||
bool m_bMaxFlag = false;
|
||||
QString value = QString();
|
||||
|
||||
QPoint m_point;
|
||||
|
||||
bool m_firstInputFlag = true;
|
||||
InputPage m_inputPage = InputPage::NumberPage;
|
||||
};
|
||||
|
||||
double m_minValue = 0.000;
|
||||
double m_maxValue = 0.000;
|
||||
bool m_isNum = false;
|
||||
bool m_isDouble = false;
|
||||
char m_format = 'f';
|
||||
int m_prec = 3;
|
||||
namespace KeyBoard
|
||||
{
|
||||
NUMKEYBOARD_EXPORT NumKeyDia *app();
|
||||
};
|
||||
|
||||
#endif // NUMKEYDIA_H
|
||||
|
||||
+48
-97
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>536</width>
|
||||
<height>430</height>
|
||||
<width>530</width>
|
||||
<height>375</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -26,40 +26,39 @@
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="2">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="3" column="1">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::MinimumExpanding</enum>
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>10</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::MinimumExpanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>10</width>
|
||||
<height>20</height>
|
||||
<height>10</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="1" rowspan="2" colspan="2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
@@ -83,7 +82,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border-image: url(:/resources/140xfd.ico);</string>
|
||||
<string notr="true">border-image: url(:/Images/keyboard.svg);</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
@@ -115,7 +114,7 @@
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Numeric Keypad</string>
|
||||
<string>数字键盘</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -132,7 +131,7 @@
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>CurrentInput:</string>
|
||||
<string>输入:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -155,81 +154,17 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>12</pointsize>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Minimum:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_min">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Times New Roman</family>
|
||||
<pointsize>12</pointsize>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>0.000</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<spacer name="verticalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>12</pointsize>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Maximum:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_max">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Times New Roman</family>
|
||||
<pointsize>12</pointsize>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>1.000</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_3" native="true">
|
||||
@@ -709,6 +644,22 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::MinimumExpanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>10</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
@@ -725,18 +676,18 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<item row="0" column="2">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::MinimumExpanding</enum>
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>10</width>
|
||||
<height>10</height>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
|
||||
Reference in New Issue
Block a user