Files
QT_wuhan_YT/widgets/numpaddialog.h
T
2026-10-14 09:59:42 +08:00

64 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef NUMPADDIALOG_H
#define NUMPADDIALOG_H
#include <QDialog>
#include <QVector>
class QLineEdit;
class QPushButton;
class QGridLayout;
class QVBoxLayout;
// ===================== 数字键盘弹窗(模态) =====================
// 半透明遮罩 + 键盘面板:顶部输入回显,数字键 1-9、0,退格、清除,确认/取消
// 两种尺寸:默认大字版(密码页用)、紧凑版(参数输入用,setCompact(true))
class NumPadDialog : public QDialog
{
Q_OBJECT
public:
explicit NumPadDialog(QWidget* parent = nullptr);
void setMaxLen(int n) { m_maxLen = n; }
void setValue(const QString& v);
QString value() const { return m_value; }
void clear();
void setOpacity(qreal opacity); // 整体不透明度(默认 1.0)
void setAnchorWidget(QWidget* ref, int gap = 20); // 面板贴参照控件左侧弹出
// 参数输入模式:回显显示实际数字(不掩码),并把“清除”键换成“小数点”
void setParamMode(bool on);
// 紧凑尺寸(按键/面板更小);默认 false = 大字版
void setCompact(bool on);
private slots:
void onDigit(const QString& d);
void onBackspace();
void onClear();
void onDot();
private:
void refreshEcho();
void placePanel();
void applySizes();
QWidget* m_panel = nullptr;
QWidget* m_anchor = nullptr; // 定位参照控件(如参数输入框)
QGridLayout* m_grid = nullptr;
QVBoxLayout* m_panelLay = nullptr;
QLineEdit* m_echo = nullptr;
QVector<QPushButton*> m_digits; // 数字键 0-9
QPushButton* m_backKey = nullptr;
QPushButton* m_clearKey = nullptr;
QPushButton* m_okKey = nullptr;
QPushButton* m_cancelKey = nullptr;
QString m_value;
int m_maxLen = 4;
int m_gap = 20;
bool m_paramMode = false;
bool m_compact = false;
};
#endif // NUMPADDIALOG_H