2
0
forked from Ivasoft/DSView

The custom spinbox for window on trigger pannel

This commit is contained in:
dreamsourcelabTAI
2024-04-22 19:52:04 +08:00
parent ea956d83e1
commit 446badc69c
4 changed files with 231 additions and 19 deletions

View File

@@ -21,8 +21,14 @@
#include "keywordlineedit.h"
#include <QHBoxLayout>
#include <QTimer>
#include "../config/appconfig.h"
#include "../ui/langresource.h"
#include "../log.h"
namespace{
QTimer *move_timer = NULL;
}
KeywordLineEdit::KeywordLineEdit(QWidget *parent, IKeywordActive *active)
:QLineEdit(parent)
@@ -60,6 +66,7 @@ PopupLineEditInput::PopupLineEditInput(QWidget *parent)
:QDialog(parent)
{
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
_line = NULL;
QHBoxLayout *lay = new QHBoxLayout();
lay->setContentsMargins(0,0,0,0);
@@ -93,11 +100,33 @@ void PopupLineEditInput::InputRelease()
sig_inputEnd(_textInput->text());
this->close();
this->deleteLater();
if (move_timer != NULL){
move_timer->stop();
delete move_timer;
move_timer = NULL;
}
}
void PopupLineEditInput::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 PopupLineEditInput::Popup(QWidget *editline)
{
assert(editline);
_line = editline;
_textInput->setFixedSize(editline->size());
this->setFixedSize(editline->size());
@@ -112,10 +141,21 @@ void PopupLineEditInput::Popup(QWidget *editline)
_textInput->setFocus();
_textInput->setCursorPosition(_textInput->text().length());
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();
}
//---------PopupLineEdit
PopupLineEdit::PopupLineEdit(QWidget *parent)
:PopupLineEdit("", parent)
@@ -126,7 +166,7 @@ void PopupLineEditInput::Popup(QWidget *editline)
PopupLineEdit::PopupLineEdit(const QString &text, QWidget *parent)
:QLineEdit(text, parent)
{
_is_catch_keypress = true;
}
void PopupLineEdit::mousePressEvent(QMouseEvent *event)
@@ -135,14 +175,6 @@ void PopupLineEdit::mousePressEvent(QMouseEvent *event)
QLineEdit::mousePressEvent(event);
}
void PopupLineEdit::keyPressEvent(QKeyEvent *event)
{
if (_is_catch_keypress){
showPupopInput();
}
QLineEdit::keyPressEvent(event);
}
void PopupLineEdit::showPupopInput()
{
#ifdef _WIN32
@@ -180,3 +212,135 @@ void PopupLineEdit::onPopupInputEditEnd(QString text)
}
}
//---------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)
{
if (event->type() == QEvent::ActivationChange){
if (this->isActiveWindow() == false){
InputRelease();
return;
}
}
QWidget::changeEvent(event);
}
void PopupSpinBoxInput::InputRelease()
{
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);
}
}

View File

@@ -27,6 +27,7 @@
#include <QMouseEvent>
#include <QWidget>
#include <QDialog>
#include <QSpinBox>
class IKeywordActive{
public:
@@ -69,13 +70,16 @@ public:
signals:
void sig_inputEnd(QString text);
private slots:
void onCheckPostion();
protected:
void changeEvent(QEvent *event) override;
void InputRelease();
private:
QLineEdit *_textInput;
QWidget *_line;
};
//---------PopupLineEdit
@@ -87,13 +91,8 @@ public:
explicit PopupLineEdit(QWidget *parent = nullptr);
explicit PopupLineEdit(const QString &, QWidget *parent = nullptr);
inline void EnableCatchKeyPress(bool enabled){
_is_catch_keypress = enabled;
}
protected:
void mousePressEvent(QMouseEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
private slots:
void onPopupInputEditEnd(QString text);
@@ -102,8 +101,58 @@ private:
void showPupopInput();
private:
bool _is_catch_keypress;
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;
};
#endif

View File

@@ -158,7 +158,6 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio
_ann_search_button = new QPushButton(bot_panel); //search icon
_nxt_button = new QPushButton(bot_panel);
_ann_search_edit = new PopupLineEdit(bot_panel);
_ann_search_edit->EnableCatchKeyPress(true);
_ann_search_button->setFixedWidth(_ann_search_button->height());
_ann_search_button->setDisabled(true);

View File

@@ -591,7 +591,7 @@ 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 QSpinBox(_stage_tabWidget);
QSpinBox *_count_spinBox = new PopupSpinBox(_stage_tabWidget);
_count_spinBox->setRange(1, INT32_MAX);
_count_spinBox->setButtonSymbols(QAbstractSpinBox::NoButtons);
_count_spinBox_list.push_back(_count_spinBox);