2
0
forked from Ivasoft/DSView

Keyword input for decoded data search in windows

This commit is contained in:
dreamsourcelabTAI
2024-04-19 21:53:19 +08:00
parent a3c65cc388
commit 4d7a3a0743
5 changed files with 188 additions and 33 deletions

View File

@@ -20,8 +20,8 @@
*/
#include "keywordlineedit.h"
#include <QHBoxLayout>
#include "../config/appconfig.h"
#include "../ui/langresource.h"
KeywordLineEdit::KeywordLineEdit(QWidget *parent, IKeywordActive *active)
@@ -32,26 +32,117 @@ KeywordLineEdit::KeywordLineEdit(QWidget *parent, IKeywordActive *active)
this->ResetText();
}
void KeywordLineEdit::mousePressEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton && _active != NULL){
_active->BeginEditKeyword();
}
QLineEdit::mousePressEvent(e);
}
void KeywordLineEdit::mousePressEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton && _active != NULL){
_active->BeginEditKeyword();
}
QLineEdit::mousePressEvent(e);
}
void KeywordLineEdit::ResetText()
{
if (_bText){
return;
}
void KeywordLineEdit::ResetText()
{
if (_bText){
return;
}
//tr
this->setText(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_KEY_DECODER_SEARCH), "Decoder search..."));
}
this->setText(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_KEY_DECODER_SEARCH), "Decoder s_ann_search_editearch..."));
}
void KeywordLineEdit::SetInputText(QString text)
{
_bText = true;
this->setText(text);
}
void KeywordLineEdit::SetInputText(QString text)
{
_bText = true;
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)
:QDialog(parent)
{
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
QHBoxLayout *lay = new QHBoxLayout();
lay->setContentsMargins(0,0,0,0);
_textInput = new QLineEdit(this);
lay->addWidget(_textInput);
this->setLayout(lay);
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);
_textInput->setFont(font);
connect(_textInput, &QLineEdit::returnPressed, [=]() {
InputRelease();
});
}
QString DecoderSearchInput::GetText()
{
return _textInput->text();
}
void DecoderSearchInput::SetText(QString text)
{
_textInput->setText(text);
}
void DecoderSearchInput::changeEvent(QEvent *event)
{
if (event->type() == QEvent::ActivationChange){
if (this->isActiveWindow() == false){
InputRelease();
return;
}
}
QWidget::changeEvent(event);
}
void DecoderSearchInput::InputRelease()
{
sig_inputEnd(_textInput->text());
this->close();
this->deleteLater();
}
void DecoderSearchInput::Popup(QWidget *editline)
{
assert(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();
_textInput->setCursorPosition(_textInput->text().length());
this->show();
}

View File

@@ -26,6 +26,7 @@
#include <QLineEdit>
#include <QMouseEvent>
#include <QWidget>
#include <QDialog>
class IKeywordActive{
public:
@@ -51,5 +52,51 @@ 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
{
Q_OBJECT
public:
explicit DecoderSearchInput(QWidget *parent = nullptr);
QString GetText();
void SetText(QString text);
void Popup(QWidget *editline);
signals:
void sig_inputEnd(QString text);
protected:
void changeEvent(QEvent *event) override;
void InputRelease();
private:
QLineEdit *_textInput;};
#endif

View File

@@ -61,6 +61,8 @@ using namespace std;
namespace pv {
namespace dock {
//-----------ProtocolDock
ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *session) :
QScrollArea(parent),
@@ -155,20 +157,17 @@ 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 QLineEdit(bot_panel);
_ann_search_edit = new SimpleKeywordLineEdit(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);
QHBoxLayout *ann_edit_layout = new QHBoxLayout();
ann_edit_layout->addWidget(_ann_search_button);
ann_edit_layout->addStretch(1);
ann_edit_layout->setContentsMargins(0, 0, 0, 0);
_ann_search_edit->setLayout(ann_edit_layout);
_ann_search_edit->setTextMargins(_ann_search_button->width() + 1, 0, 0, 0);
QHBoxLayout *ann_search_layout = new QHBoxLayout();
ann_search_layout->setSpacing(2);
ann_search_layout->addWidget(_pre_button);
ann_search_layout->addWidget(_ann_search_button);
ann_search_layout->addWidget(_ann_search_edit, 1);
ann_search_layout->addWidget(_nxt_button);
@@ -219,10 +218,10 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio
connect(_table_view->horizontalHeader(), SIGNAL(sectionResized(int,int,int)),
this, SLOT(column_resize(int, int, int)));
connect(_ann_search_edit, SIGNAL(editingFinished()), this, SLOT(search_changed()));
connect(_pro_search_button, SIGNAL(clicked()), this, SLOT(show_protocol_select()));
connect(_ann_search_edit, SIGNAL(sig_click()), this, SLOT(on_show_ann_keyinput()));
ADD_UI(this);
}
@@ -1112,5 +1111,21 @@ void ProtocolDock::UpdateFont()
_top_panel->setFixedHeight(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

@@ -144,6 +144,8 @@ private slots:
void search_changed();
void search_update();
void show_protocol_select();
void on_show_ann_keyinput();
void on_ann_search_changed(QString text);
private:
SigSession *_session;
@@ -156,7 +158,7 @@ private:
QTableView *_table_view;
QPushButton *_pre_button;
QPushButton *_nxt_button;
QLineEdit *_ann_search_edit;
SimpleKeywordLineEdit *_ann_search_edit;
QLabel *_matchs_label;
QLabel *_matchs_title_label;
QLabel *_bot_title_label;

View File

@@ -760,7 +760,7 @@ void MainFrame::AttachNativeWindow()
setWindowFlags(Qt::FramelessWindowHint);
SetWindowLong((HWND)winId(), GWL_STYLE, WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
SetWindowLong((HWND)winId(), GWL_STYLE, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
SetParent((HWND)winId(), nativeWindow->Handle());
setVisible(true);