From e8eee13db65768f2b277236586ab41323d2834bb Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Tue, 23 Apr 2024 10:06:59 +0800 Subject: [PATCH] The new text input class of trigger pannel for windows --- DSView/pv/dock/keywordlineedit.cpp | 149 ++++------------------------- DSView/pv/dock/keywordlineedit.h | 61 ++---------- DSView/pv/dock/triggerdock.cpp | 9 +- DSView/pv/dock/triggerdock.h | 2 +- 4 files changed, 35 insertions(+), 186 deletions(-) diff --git a/DSView/pv/dock/keywordlineedit.cpp b/DSView/pv/dock/keywordlineedit.cpp index 32b83340..40cd76f1 100644 --- a/DSView/pv/dock/keywordlineedit.cpp +++ b/DSView/pv/dock/keywordlineedit.cpp @@ -160,15 +160,20 @@ void PopupLineEditInput::Popup(QWidget *editline) PopupLineEdit::PopupLineEdit(QWidget *parent) :PopupLineEdit("", parent) { - } PopupLineEdit::PopupLineEdit(const QString &text, QWidget *parent) :QLineEdit(text, parent) { - + _is_number_mode = false; } + PopupLineEdit::PopupLineEdit(bool isNumberMode, QWidget *parent) + :QLineEdit(parent) + { + _is_number_mode = isNumberMode; + } + void PopupLineEdit::mousePressEvent(QMouseEvent *event) { showPupopInput(); @@ -194,6 +199,11 @@ void PopupLineEdit::showPupopInput() input->GetInput()->setText(this->text()); input->setFont(this->font()); + if (_is_number_mode){ + QIntValidator *validator = new QIntValidator(); + input->GetInput()->setValidator(validator); + } + _old_text = this->text(); connect(input, SIGNAL(sig_inputEnd(QString)), this, SLOT(onPopupInputEditEnd(QString))); @@ -211,136 +221,19 @@ void PopupLineEdit::onPopupInputEditEnd(QString text) editingFinished(); } } - -//---------PopupSpinBoxInput -PopupSpinBoxInput::PopupSpinBoxInput(QWidget *parent) - :QDialog(parent) -{ - setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint); - _line = NULL; - - QHBoxLayout *lay = new QHBoxLayout(); - lay->setContentsMargins(0,0,0,0); - _textInput = new QSpinBox(this); - lay->addWidget(_textInput); - this->setLayout(lay); - - QFont font = this->font(); - font.setPointSizeF(AppConfig::Instance().appOptions.fontSize); - _textInput->setFont(font); -} - -void PopupSpinBoxInput::changeEvent(QEvent *event) +int PopupLineEdit::value() { - if (event->type() == QEvent::ActivationChange){ - if (this->isActiveWindow() == false){ - InputRelease(); - return; - } + assert(_is_number_mode); + + QString text = this->text(); + if (text != ""){ + return text.toInt(); } - - QWidget::changeEvent(event); + return 0; } -void PopupSpinBoxInput::InputRelease() +void PopupLineEdit::setValue(int value) { - sig_inputEnd(_textInput->value()); - this->close(); - this->deleteLater(); - - if (move_timer != NULL){ - move_timer->stop(); - delete move_timer; - move_timer = NULL; - } -} - -void PopupSpinBoxInput::onCheckPostion() -{ - if (_line != NULL){ - QPoint p1 = _line->pos(); - QPoint p2 = _line->mapToGlobal(p1); - int x = p2.x() - p1.x(); - int y = p2.y() - p1.y(); - - QPoint p = this->pos(); - if (p.x() != x || p.y() != y){ - this->move(x, y); - } - } -} - -void PopupSpinBoxInput::Popup(QWidget *editline) -{ - assert(editline); - _line = editline; - - _textInput->setFixedSize(editline->size()); - this->setFixedSize(editline->size()); - - QPoint pt = mapToGlobal(editline->rect().bottomLeft()); - - QPoint p1 = editline->pos(); - QPoint p2 = editline->mapToGlobal(p1); - int x = p2.x() - p1.x(); - int y = p2.y() - p1.y(); - this->move(x, y); - - _textInput->setFocus(); - - if (move_timer != NULL){ - move_timer->stop(); - delete move_timer; - move_timer = NULL; - } - move_timer = new QTimer(this); - move_timer->setInterval(100); - - connect(move_timer, SIGNAL(timeout()), this, SLOT(onCheckPostion())); - move_timer->start(); - - this->show(); -} - -//---------PopupSpinBox -PopupSpinBox::PopupSpinBox(QWidget *parent) - :QSpinBox(parent) -{ - -} - -void PopupSpinBox::mousePressEvent(QMouseEvent *event) -{ - showPupopInput(); - QSpinBox::mousePressEvent(event); -} - -void PopupSpinBox::showPupopInput() -{ -#ifdef _WIN32 - PopupSpinBoxInput *input = new PopupSpinBoxInput(this); - input->GetInput()->setValue(this->value()); - input->setFont(this->font()); - input->GetInput()->setButtonSymbols(this->buttonSymbols()); - - int min = this->minimum(); - int max = this->maximum(); - input->GetInput()->setRange(min, max); - - _old_value = this->value(); - - connect(input, SIGNAL(sig_inputEnd(int)), this, SLOT(onPopupInputEditEnd(int))); - input->Popup(this); -#endif -} - -void PopupSpinBox::onPopupInputEditEnd(int value) -{ - this->setFocus(); - this->setValue(value); - - if (value != _old_value){ - valueChanged(value); - } + this->setText(QString::number(value)); } \ No newline at end of file diff --git a/DSView/pv/dock/keywordlineedit.h b/DSView/pv/dock/keywordlineedit.h index bf8784cf..61856b2f 100644 --- a/DSView/pv/dock/keywordlineedit.h +++ b/DSView/pv/dock/keywordlineedit.h @@ -90,6 +90,15 @@ class PopupLineEdit : public QLineEdit public: explicit PopupLineEdit(QWidget *parent = nullptr); explicit PopupLineEdit(const QString &, QWidget *parent = nullptr); + explicit PopupLineEdit(bool isNumberMode, QWidget *parent = nullptr); + + inline bool is_number_mode(){ + return _is_number_mode; + } + + int value(); + + void setValue(int value); protected: void mousePressEvent(QMouseEvent *event) override; @@ -102,57 +111,7 @@ private: private: QString _old_text; -}; - -//---------PopupSpinBoxInput -class PopupSpinBoxInput : public QDialog -{ - Q_OBJECT - -public: - explicit PopupSpinBoxInput(QWidget *parent = nullptr); - - void Popup(QWidget *editline); - - inline QSpinBox* GetInput(){ - return _textInput; - } - -signals: - void sig_inputEnd(int value); - -private slots: - void onCheckPostion(); - -protected: - void changeEvent(QEvent *event) override; - - void InputRelease(); - -private: - QSpinBox *_textInput; - QWidget *_line; -}; - -//---------PopupSpinBox -class PopupSpinBox : public QSpinBox -{ - Q_OBJECT - -public: - explicit PopupSpinBox(QWidget *parent = nullptr); - -protected: - void mousePressEvent(QMouseEvent *event) override; - -private slots: - void onPopupInputEditEnd(int value); - -private: - void showPupopInput(); - -private: - int _old_value; + bool _is_number_mode; }; #endif diff --git a/DSView/pv/dock/triggerdock.cpp b/DSView/pv/dock/triggerdock.cpp index e9ecda0a..e05d9399 100644 --- a/DSView/pv/dock/triggerdock.cpp +++ b/DSView/pv/dock/triggerdock.cpp @@ -410,9 +410,6 @@ bool TriggerDock::commit_trigger() void TriggerDock::update_view() { - // TRIGGERPOS - //uint16_t pos = ds_trigger_get_pos(); - //_position_slider->setValue(pos); } QJsonObject TriggerDock::get_session() @@ -591,9 +588,9 @@ void TriggerDock::setup_adv_tab() _value0_lineEdit->setInputMask(mask); _value0_lineEdit->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); _value0_lineEdit_list.push_back(_value0_lineEdit); - QSpinBox *_count_spinBox = new PopupSpinBox(_stage_tabWidget); - _count_spinBox->setRange(1, INT32_MAX); - _count_spinBox->setButtonSymbols(QAbstractSpinBox::NoButtons); + PopupLineEdit *_count_spinBox = new PopupLineEdit(true, _stage_tabWidget); + // _count_spinBox->setRange(1, INT32_MAX); + //_count_spinBox->setButtonSymbols(QAbstractSpinBox::NoButtons); _count_spinBox_list.push_back(_count_spinBox); DsComboBox *_inv0_comboBox = new DsComboBox(_stage_tabWidget); //tr diff --git a/DSView/pv/dock/triggerdock.h b/DSView/pv/dock/triggerdock.h index 3929f02d..d5480c6e 100644 --- a/DSView/pv/dock/triggerdock.h +++ b/DSView/pv/dock/triggerdock.h @@ -121,7 +121,7 @@ private: QVector _logic_comboBox_list; QVector _value0_lineEdit_list; QVector _value0_ext32_lineEdit_list; - QVector _count_spinBox_list; + QVector _count_spinBox_list; QVector _inv0_comboBox_list; QVector _value1_lineEdit_list; QVector _value1_ext32_lineEdit_list;