2
0
forked from Ivasoft/DSView

The text input class for window

This commit is contained in:
dreamsourcelabTAI
2024-04-22 15:41:58 +08:00
parent 3866eb3315
commit 879a4b8193
11 changed files with 145 additions and 129 deletions

View File

@@ -55,30 +55,8 @@ void KeywordLineEdit::SetInputText(QString text)
this->setText(text);
}
//----------------SimpleKeywordLineEdit
SimpleKeywordLineEdit::SimpleKeywordLineEdit(QWidget *parent)
:QLineEdit(parent)
{
_is_catch_keypress = false;
}
void SimpleKeywordLineEdit::mousePressEvent(QMouseEvent *e)
{
sig_click();
QLineEdit::mousePressEvent(e);
}
void SimpleKeywordLineEdit::keyPressEvent(QKeyEvent *e)
{
if (_is_catch_keypress){
sig_click();
}
QLineEdit::keyPressEvent(e);
}
//----------------------DecoderSearchInput
DecoderSearchInput::DecoderSearchInput(QWidget *parent)
//---------PopupLineEditInput
PopupLineEditInput::PopupLineEditInput(QWidget *parent)
:QDialog(parent)
{
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
@@ -98,17 +76,7 @@ DecoderSearchInput::DecoderSearchInput(QWidget *parent)
});
}
QString DecoderSearchInput::GetText()
{
return _textInput->text();
}
void DecoderSearchInput::SetText(QString text)
{
_textInput->setText(text);
}
void DecoderSearchInput::changeEvent(QEvent *event)
void PopupLineEditInput::changeEvent(QEvent *event)
{
if (event->type() == QEvent::ActivationChange){
if (this->isActiveWindow() == false){
@@ -120,14 +88,14 @@ void DecoderSearchInput::changeEvent(QEvent *event)
QWidget::changeEvent(event);
}
void DecoderSearchInput::InputRelease()
void PopupLineEditInput::InputRelease()
{
sig_inputEnd(_textInput->text());
this->close();
this->deleteLater();
}
void DecoderSearchInput::Popup(QWidget *editline)
void PopupLineEditInput::Popup(QWidget *editline)
{
assert(editline);
@@ -146,3 +114,68 @@ void DecoderSearchInput::Popup(QWidget *editline)
_textInput->setCursorPosition(_textInput->text().length());
this->show();
}
//---------PopupLineEdit
PopupLineEdit::PopupLineEdit(QWidget *parent)
:PopupLineEdit("", parent)
{
}
PopupLineEdit::PopupLineEdit(const QString &text, QWidget *parent)
:QLineEdit(text, parent)
{
_is_catch_keypress = true;
}
void PopupLineEdit::mousePressEvent(QMouseEvent *event)
{
showPupopInput();
QLineEdit::mousePressEvent(event);
}
void PopupLineEdit::keyPressEvent(QKeyEvent *event)
{
if (_is_catch_keypress){
showPupopInput();
}
QLineEdit::keyPressEvent(event);
}
void PopupLineEdit::showPupopInput()
{
#ifdef _WIN32
PopupLineEditInput *input = new PopupLineEditInput(this);
QString mask = this->inputMask();
if (mask != ""){
input->GetInput()->setInputMask(mask);
}
auto regular = this->validator();
if (regular != NULL){
input->GetInput()->setValidator(regular);
}
input->GetInput()->setMaxLength(this->maxLength());
input->GetInput()->setText(this->text());
_old_text = this->text();
connect(input, SIGNAL(sig_inputEnd(QString)), this, SLOT(onPopupInputEditEnd(QString)));
input->Popup(this);
#endif
}
void PopupLineEdit::onPopupInputEditEnd(QString text)
{
this->setText(text);
this->setFocus();
this->setCursorPosition(this->text().length());
if (text != _old_text){
editingFinished();
}
}

View File

@@ -52,42 +52,20 @@ private:
bool _bText;
};
//--------------SimpleKeywordLineEdit
class SimpleKeywordLineEdit : public QLineEdit
{
Q_OBJECT
public:
SimpleKeywordLineEdit(QWidget *parent);
inline void EnableCatchKeyPress(bool enabled){
_is_catch_keypress = enabled;
}
signals:
void sig_click();
protected:
void mousePressEvent(QMouseEvent *e);
void keyPressEvent(QKeyEvent *e) override;
private:
bool _is_catch_keypress;
};
//--DecoderSearchInput
class DecoderSearchInput : public QDialog
//---------PopupLineEditInput
class PopupLineEditInput : public QDialog
{
Q_OBJECT
public:
explicit DecoderSearchInput(QWidget *parent = nullptr);
QString GetText();
void SetText(QString text);
explicit PopupLineEditInput(QWidget *parent = nullptr);
void Popup(QWidget *editline);
inline QLineEdit* GetInput(){
return _textInput;
}
signals:
void sig_inputEnd(QString text);
@@ -97,6 +75,35 @@ protected:
void InputRelease();
private:
QLineEdit *_textInput;};
QLineEdit *_textInput;
};
//---------PopupLineEdit
class PopupLineEdit : public QLineEdit
{
Q_OBJECT
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);
private:
void showPupopInput();
private:
bool _is_catch_keypress;
QString _old_text;
};
#endif

View File

@@ -27,7 +27,6 @@
#include <QLabel>
#include <QRadioButton>
#include <QSlider>
#include <QLineEdit>
#include <QSpinBox>
#include <QGroupBox>
#include <QTableWidget>

View File

@@ -157,9 +157,8 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio
_pre_button = new QPushButton(bot_panel);
_ann_search_button = new QPushButton(bot_panel); //search icon
_nxt_button = new QPushButton(bot_panel);
_ann_search_edit = new SimpleKeywordLineEdit(bot_panel);
_ann_search_edit = new PopupLineEdit(bot_panel);
_ann_search_edit->EnableCatchKeyPress(true);
// _ann_search_edit->setReadOnly(true);
_ann_search_button->setFixedWidth(_ann_search_button->height());
_ann_search_button->setDisabled(true);
@@ -220,7 +219,8 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio
connect(_pro_search_button, SIGNAL(clicked()), this, SLOT(show_protocol_select()));
connect(_ann_search_edit, SIGNAL(sig_click()), this, SLOT(on_show_ann_keyinput()));
connect(_ann_search_edit, SIGNAL(editingFinished()), this, SLOT(search_changed()));
ADD_UI(this);
}
@@ -1111,21 +1111,5 @@ void ProtocolDock::UpdateFont()
_top_panel->setMinimumHeight(pannelHeight);
}
void ProtocolDock::on_show_ann_keyinput()
{
DecoderSearchInput *input = new DecoderSearchInput(this);
input->SetText(_ann_search_edit->text());
connect(input, SIGNAL(sig_inputEnd(QString)), this, SLOT(on_ann_search_changed(QString)));
input->Popup(_ann_search_edit);
}
void ProtocolDock::on_ann_search_changed(QString text)
{
_ann_search_edit->setText(text);
_ann_search_edit->setFocus();
_ann_search_edit->setCursorPosition(_ann_search_edit->text().length());
search_changed();
}
} // namespace dock
} // namespace pv

View File

@@ -34,12 +34,9 @@
#include <QSplitter>
#include <QTableView>
#include <QSortFilterProxyModel>
#include <QLineEdit>
#include <vector>
#include <mutex>
#include <list>
#include "../data/decodermodel.h"
#include "protocolitemlayer.h"
#include "keywordlineedit.h"
@@ -143,9 +140,7 @@ private slots:
void search_done();
void search_changed();
void search_update();
void show_protocol_select();
void on_show_ann_keyinput();
void on_ann_search_changed(QString text);
void show_protocol_select();
private:
SigSession *_session;
@@ -158,7 +153,7 @@ private:
QTableView *_table_view;
QPushButton *_pre_button;
QPushButton *_nxt_button;
SimpleKeywordLineEdit *_ann_search_edit;
PopupLineEdit *_ann_search_edit;
QLabel *_matchs_label;
QLabel *_matchs_title_label;
QLabel *_bot_title_label;

View File

@@ -239,7 +239,7 @@ void TriggerDock::widget_enable(int index)
void TriggerDock::value_changed()
{
QLineEdit* sc=dynamic_cast<QLineEdit*>(sender());
PopupLineEdit* sc=dynamic_cast<PopupLineEdit*>(sender());
if(sc != NULL) {
for (int i = 0; i < TriggerProbes*2-1; i++) {
if ((i >= sc->text().size()) || (i % 2 == 0 && sc->text().at(i) == ' ')) {
@@ -584,7 +584,7 @@ void TriggerDock::setup_adv_tab()
_logic_comboBox->setCurrentIndex(1);
_logic_comboBox_list.push_back(_logic_comboBox);
QLineEdit *_value0_lineEdit = new QLineEdit("X X X X X X X X X X X X X X X X", _stage_tabWidget);
PopupLineEdit *_value0_lineEdit = new PopupLineEdit("X X X X X X X X X X X X X X X X", _stage_tabWidget);
_value0_lineEdit->setFont(font);
_value0_lineEdit->setValidator(value_validator);
_value0_lineEdit->setMaxLength(TriggerProbes * 2 - 1);
@@ -601,7 +601,7 @@ void TriggerDock::setup_adv_tab()
_inv0_comboBox->addItem("!=");
_inv0_comboBox_list.push_back(_inv0_comboBox);
QLineEdit *_value1_lineEdit = new QLineEdit("X X X X X X X X X X X X X X X X", _stage_tabWidget);
PopupLineEdit *_value1_lineEdit = new PopupLineEdit("X X X X X X X X X X X X X X X X", _stage_tabWidget);
_value1_lineEdit->setFont(font);
_value1_lineEdit->setValidator(value_validator);
_value1_lineEdit->setMaxLength(TriggerProbes * 2 - 1);
@@ -638,7 +638,7 @@ void TriggerDock::setup_adv_tab()
row = 1;
if (_cur_ch_num == 32) {
QLineEdit *_value0_ext32_lineEdit = new QLineEdit("X X X X X X X X X X X X X X X X", _stage_tabWidget);
PopupLineEdit *_value0_ext32_lineEdit = new PopupLineEdit("X X X X X X X X X X X X X X X X", _stage_tabWidget);
_value0_ext32_lineEdit->setFont(font);
_value0_ext32_lineEdit->setValidator(value_validator);
_value0_ext32_lineEdit->setMaxLength(TriggerProbes * 2 - 1);
@@ -646,7 +646,7 @@ void TriggerDock::setup_adv_tab()
_value0_ext32_lineEdit->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
_value0_ext32_lineEdit_list.push_back(_value0_ext32_lineEdit);
QLineEdit *_value1_ext32_lineEdit = new QLineEdit("X X X X X X X X X X X X X X X X", _stage_tabWidget);
PopupLineEdit *_value1_ext32_lineEdit = new PopupLineEdit("X X X X X X X X X X X X X X X X", _stage_tabWidget);
_value1_ext32_lineEdit->setFont(font);
_value1_ext32_lineEdit->setValidator(value_validator);
_value1_ext32_lineEdit->setMaxLength(TriggerProbes * 2 - 1);
@@ -724,7 +724,7 @@ void TriggerDock::setup_adv_tab()
_serial_groupBox->setFlat(true);
_serial_start_label = new QLabel(_serial_groupBox);
_serial_start_lineEdit = new QLineEdit("X X X X X X X X X X X X X X X X", _serial_groupBox);
_serial_start_lineEdit = new PopupLineEdit("X X X X X X X X X X X X X X X X", _serial_groupBox);
_serial_start_lineEdit->setFont(font);
_serial_start_lineEdit->setValidator(value_validator);
_serial_start_lineEdit->setMaxLength(TriggerProbes * 2 - 1);
@@ -732,7 +732,7 @@ void TriggerDock::setup_adv_tab()
_serial_start_lineEdit->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
_serial_stop_label = new QLabel(_serial_groupBox);
_serial_stop_lineEdit = new QLineEdit("X X X X X X X X X X X X X X X X", _serial_groupBox);
_serial_stop_lineEdit = new PopupLineEdit("X X X X X X X X X X X X X X X X", _serial_groupBox);
_serial_stop_lineEdit->setFont(font);
_serial_stop_lineEdit->setValidator(value_validator);
_serial_stop_lineEdit->setMaxLength(TriggerProbes * 2 - 1);
@@ -740,7 +740,7 @@ void TriggerDock::setup_adv_tab()
_serial_stop_lineEdit->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
_serial_edge_label = new QLabel(_serial_groupBox);
_serial_edge_lineEdit = new QLineEdit("X X X X X X X X X X X X X X X X", _serial_groupBox);
_serial_edge_lineEdit = new PopupLineEdit("X X X X X X X X X X X X X X X X", _serial_groupBox);
_serial_edge_lineEdit->setFont(font);
_serial_edge_lineEdit->setValidator(value_validator);
_serial_edge_lineEdit->setMaxLength(TriggerProbes * 2 - 1);
@@ -755,7 +755,7 @@ void TriggerDock::setup_adv_tab()
}
_serial_value_label = new QLabel(_serial_groupBox);
_serial_value_lineEdit = new QLineEdit("X X X X X X X X X X X X X X X X", _serial_groupBox);
_serial_value_lineEdit = new PopupLineEdit("X X X X X X X X X X X X X X X X", _serial_groupBox);
_serial_value_lineEdit->setFont(font);
_serial_value_lineEdit->setMaxLength(TriggerProbes * 2 - 1);
_serial_value_lineEdit->setInputMask(mask);
@@ -766,7 +766,7 @@ void TriggerDock::setup_adv_tab()
_serial_value_lineEdit->setValidator(value_validator2);
_serial_hex_label = new QLabel(_serial_groupBox);
_serial_hex_lineEdit = new QLineEdit("", _serial_groupBox);
_serial_hex_lineEdit = new PopupLineEdit("", _serial_groupBox);
_serial_hex_lineEdit->setMaxLength(4);
QRegularExpression value_rx_hex("[0-9a-fA-F]+");
QValidator *value_validator_hex = new QRegularExpressionValidator(value_rx_hex, _stage_tabWidget);
@@ -802,21 +802,21 @@ void TriggerDock::setup_adv_tab()
row = 1;
if (_cur_ch_num == 32) {
_serial_start_ext32_lineEdit = new QLineEdit("X X X X X X X X X X X X X X X X", _serial_groupBox);
_serial_start_ext32_lineEdit = new PopupLineEdit("X X X X X X X X X X X X X X X X", _serial_groupBox);
_serial_start_ext32_lineEdit->setFont(font);
_serial_start_ext32_lineEdit->setValidator(value_validator);
_serial_start_ext32_lineEdit->setMaxLength(TriggerProbes * 2 - 1);
_serial_start_ext32_lineEdit->setInputMask(mask);
_serial_start_ext32_lineEdit->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
_serial_stop_ext32_lineEdit = new QLineEdit("X X X X X X X X X X X X X X X X", _serial_groupBox);
_serial_stop_ext32_lineEdit = new PopupLineEdit("X X X X X X X X X X X X X X X X", _serial_groupBox);
_serial_stop_ext32_lineEdit->setFont(font);
_serial_stop_ext32_lineEdit->setValidator(value_validator);
_serial_stop_ext32_lineEdit->setMaxLength(TriggerProbes * 2 - 1);
_serial_stop_ext32_lineEdit->setInputMask(mask);
_serial_stop_ext32_lineEdit->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
_serial_edge_ext32_lineEdit = new QLineEdit("X X X X X X X X X X X X X X X X", _serial_groupBox);
_serial_edge_ext32_lineEdit = new PopupLineEdit("X X X X X X X X X X X X X X X X", _serial_groupBox);
_serial_edge_ext32_lineEdit->setFont(font);
_serial_edge_ext32_lineEdit->setValidator(value_validator);
_serial_edge_ext32_lineEdit->setMaxLength(TriggerProbes * 2 - 1);
@@ -924,7 +924,7 @@ void TriggerDock::setup_adv_tab()
UpdateFont();
}
void TriggerDock::lineEdit_highlight(QLineEdit *dst) {
void TriggerDock::lineEdit_highlight(PopupLineEdit *dst) {
if (dst == NULL)
return;
@@ -1088,7 +1088,7 @@ void TriggerDock::UpdateFont()
font2.setPointSizeF(AppConfig::Instance().appOptions.fontSize);
QFontMetrics fm(font2);
auto edits = this->findChildren<QLineEdit*>();
auto edits = this->findChildren<PopupLineEdit*>();
int lineH = 30;
for(auto o : edits)

View File

@@ -28,7 +28,6 @@
#include <QLabel>
#include <QRadioButton>
#include <QSlider>
#include <QLineEdit>
#include <QSpinBox>
#include <QGroupBox>
#include <QCheckBox>
@@ -43,6 +42,7 @@
#include "../ui/dscombobox.h"
#include "../interface/icallbacks.h"
#include "../ui/uimanager.h"
#include "keywordlineedit.h"
namespace pv {
@@ -75,7 +75,7 @@ private:
void reStyle();
void setup_adv_tab();
void lineEdit_highlight(QLineEdit *dst);
void lineEdit_highlight(PopupLineEdit *dst);
/*
* commit trigger setting
@@ -119,33 +119,33 @@ private:
QVector <QGroupBox *> _stage_groupBox_list;
QVector <QLabel *> _mu_label_list;
QVector <DsComboBox *> _logic_comboBox_list;
QVector <QLineEdit *> _value0_lineEdit_list;
QVector <QLineEdit *> _value0_ext32_lineEdit_list;
QVector <PopupLineEdit *> _value0_lineEdit_list;
QVector <PopupLineEdit *> _value0_ext32_lineEdit_list;
QVector <QSpinBox *> _count_spinBox_list;
QVector <DsComboBox *> _inv0_comboBox_list;
QVector <QLineEdit *> _value1_lineEdit_list;
QVector <QLineEdit *> _value1_ext32_lineEdit_list;
QVector <PopupLineEdit *> _value1_lineEdit_list;
QVector <PopupLineEdit *> _value1_ext32_lineEdit_list;
QVector <DsComboBox *> _inv1_comboBox_list;
QVector <QCheckBox *> _contiguous_checkbox_list;
QTabWidget *_adv_tabWidget;
QGroupBox *_serial_groupBox;
QLabel *_serial_start_label;
QLineEdit *_serial_start_lineEdit;
QLineEdit *_serial_start_ext32_lineEdit;
PopupLineEdit *_serial_start_lineEdit;
PopupLineEdit *_serial_start_ext32_lineEdit;
QLabel *_serial_stop_label;
QLineEdit *_serial_stop_lineEdit;
QLineEdit *_serial_stop_ext32_lineEdit;
PopupLineEdit *_serial_stop_lineEdit;
PopupLineEdit *_serial_stop_ext32_lineEdit;
QLabel *_serial_edge_label;
QLineEdit *_serial_edge_lineEdit;
QLineEdit *_serial_edge_ext32_lineEdit;
PopupLineEdit *_serial_edge_lineEdit;
PopupLineEdit *_serial_edge_ext32_lineEdit;
QLabel *_serial_data_label;
DsComboBox *_serial_data_comboBox;
QLabel *_serial_value_label;
QLineEdit *_serial_value_lineEdit;
PopupLineEdit *_serial_value_lineEdit;
DsComboBox *_serial_bits_comboBox;
QLabel *_serial_hex_label;
QLineEdit *_serial_hex_lineEdit;
PopupLineEdit *_serial_hex_lineEdit;
QLabel *_serial_hex_ck_label;
QLabel *_serial_note_label;

View File

@@ -31,8 +31,7 @@
#include <QComboBox>
#include <QFormLayout>
#include <QWidget>
#include <QCheckBox>
#include <QLineEdit>
#include <QCheckBox>
#include <QHBoxLayout>
#include <QFile>
#include <QLabel>

View File

@@ -64,7 +64,7 @@ Header::Header(View &parent) :
_context_trace = NULL;
_mouse_is_down = false;
nameEdit = new QLineEdit(this);
nameEdit = new PopupLineEdit(this);
nameEdit->setFixedWidth(100);
nameEdit->hide();

View File

@@ -27,8 +27,8 @@
#include <list>
#include <utility>
#include <QWidget>
#include <QLineEdit>
#include "../ui/uimanager.h"
#include "../dock/keywordlineedit.h"
namespace pv {
namespace view {
@@ -97,7 +97,7 @@ private:
bool _nameFlag;
QPoint _mouse_point;
QPoint _mouse_down_point;
QLineEdit *nameEdit;
PopupLineEdit *nameEdit;
std::list<std::pair<Trace*, int> > _drag_traces;
Trace *_context_trace;
bool _mouse_is_down;

View File

@@ -24,7 +24,6 @@
#include <assert.h>
#include <math.h>
#include <QFormLayout>
#include <QLineEdit>
#include <QApplication>
#include "trace.h"