forked from Ivasoft/DSView
update: protocol search ui
This commit is contained in:
@@ -248,6 +248,7 @@ set(DSView_SOURCES
|
||||
pv/minizip/ioapi.c
|
||||
pv/dialogs/applicationpardlg.cpp
|
||||
pv/dock/keywordlineedit.cpp
|
||||
pv/dock/searchcombobox.cpp
|
||||
)
|
||||
|
||||
set(DSView_HEADERS
|
||||
@@ -332,6 +333,7 @@ set(DSView_HEADERS
|
||||
pv/minizip/ioapi.h
|
||||
pv/dialogs/applicationpardlg.h
|
||||
pv/dock/keywordlineedit.h
|
||||
pv/dock/searchcombobox.h
|
||||
)
|
||||
|
||||
set(DSView_FORMS
|
||||
|
||||
@@ -21,28 +21,24 @@
|
||||
|
||||
#include "keywordlineedit.h"
|
||||
|
||||
KeywordLineEdit::KeywordLineEdit(QComboBox *comboBox)
|
||||
:QLineEdit()
|
||||
{
|
||||
assert(comboBox);
|
||||
_comboBox = comboBox;
|
||||
#define PROTOCOL_FIND_TITLE "Protocol search..."
|
||||
|
||||
KeywordLineEdit::KeywordLineEdit(QWidget *parent, IKeywordActive *active)
|
||||
:QLineEdit(parent)
|
||||
{
|
||||
_active = active;
|
||||
this->setText(PROTOCOL_FIND_TITLE);
|
||||
}
|
||||
|
||||
|
||||
void KeywordLineEdit::focusInEvent(QFocusEvent *e)
|
||||
void KeywordLineEdit::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
QLineEdit::focusInEvent(e);
|
||||
QString key(PROTOCOL_FIND_TITLE);
|
||||
if (this->text() == key){
|
||||
this->setText("");
|
||||
}
|
||||
if (e->button() == Qt::LeftButton && _active != NULL){
|
||||
_active->BeginEditKeyword();
|
||||
}
|
||||
QLineEdit::mousePressEvent(e);
|
||||
}
|
||||
|
||||
void KeywordLineEdit::focusOutEvent(QFocusEvent *e)
|
||||
void KeywordLineEdit::ResetText()
|
||||
{
|
||||
QLineEdit::focusOutEvent(e);
|
||||
|
||||
if (this->text() == ""){
|
||||
this->setText(PROTOCOL_FIND_TITLE);
|
||||
}
|
||||
this->setText(PROTOCOL_FIND_TITLE);
|
||||
}
|
||||
@@ -23,25 +23,29 @@
|
||||
#define KEY_WORD_LINE_EDIT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QLineEdit>
|
||||
#include <QComboBox>
|
||||
#include <QFocusEvent>
|
||||
#include <QLineEdit>
|
||||
#include <QMouseEvent>
|
||||
#include <QWidget>
|
||||
|
||||
#define PROTOCOL_FIND_TITLE "Protocol search..."
|
||||
class IKeywordActive{
|
||||
public:
|
||||
virtual void BeginEditKeyword()=0;
|
||||
};
|
||||
|
||||
class KeywordLineEdit : public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
KeywordLineEdit(QComboBox *comboBox);
|
||||
KeywordLineEdit(QWidget *parent, IKeywordActive *active);
|
||||
|
||||
void ResetText();
|
||||
|
||||
protected:
|
||||
void focusInEvent(QFocusEvent *e) override;
|
||||
void focusOutEvent(QFocusEvent *e) override;
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
|
||||
private:
|
||||
QComboBox *_comboBox;
|
||||
IKeywordActive *_active;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include <assert.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <QToolButton>
|
||||
|
||||
#include <algorithm>
|
||||
#include "../ui/msgbox.h"
|
||||
@@ -53,6 +54,7 @@
|
||||
#include "../data/decode/decoderstatus.h"
|
||||
#include "../data/decode/decoder.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
@@ -65,10 +67,7 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio
|
||||
{
|
||||
_session = session;
|
||||
_cur_search_index = -1;
|
||||
_search_edited = false;
|
||||
_searching = false;
|
||||
_add_silent = false;
|
||||
_bSettingList = false;
|
||||
_search_edited = false;
|
||||
|
||||
_up_widget = new QWidget(this);
|
||||
|
||||
@@ -78,12 +77,8 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio
|
||||
_del_all_button->setFlat(true);
|
||||
_del_all_button->setCheckable(true);
|
||||
|
||||
_protocol_combobox = new DsComboBox(_up_widget);
|
||||
_protocol_combobox->setEditable(true);
|
||||
_protocol_combobox->setLineEdit(new KeywordLineEdit(_protocol_combobox));
|
||||
_protocol_combobox->setCompleter(NULL);
|
||||
|
||||
//GSList *l = g_slist_sort(g_slist_copy((GSList*)srd_decoder_list()), decoder_name_cmp);
|
||||
_keyword_edit = new KeywordLineEdit(_up_widget, this);
|
||||
_keyword_edit->setReadOnly(true);
|
||||
|
||||
GSList *l = const_cast<GSList*>(srd_decoder_list());
|
||||
|
||||
@@ -93,13 +88,12 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio
|
||||
for(; l; l = l->next)
|
||||
{
|
||||
const srd_decoder *const d = (srd_decoder*)l->data;
|
||||
assert(d);
|
||||
// const bool have_probes = (d->channels || d->opt_channels) != 0;
|
||||
assert(d);
|
||||
|
||||
if (true) {
|
||||
DecoderInfoItem *info = new DecoderInfoItem();
|
||||
srd_decoder *dec = (srd_decoder *)(l->data);
|
||||
info->ObjectHandle = dec;
|
||||
info->_data_handle = dec;
|
||||
_decoderInfoList.push_back(info);
|
||||
|
||||
std::string prokey(dec->id);
|
||||
@@ -117,34 +111,23 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio
|
||||
|
||||
//sort protocol list
|
||||
sort(_decoderInfoList.begin(), _decoderInfoList.end(), ProtocolDock::protocol_sort_callback);
|
||||
|
||||
_bSettingList = true;
|
||||
int protocol_index = 0;
|
||||
for (auto info : _decoderInfoList){
|
||||
info->Index = protocol_index;
|
||||
protocol_index++;
|
||||
srd_decoder *dec = (srd_decoder *)(info->ObjectHandle);
|
||||
_protocol_combobox->addItem(QString::fromUtf8(dec->name), QVariant::fromValue(info->Index));
|
||||
}
|
||||
|
||||
_protocol_combobox->setCurrentIndex(-1);
|
||||
_protocol_combobox->lineEdit()->setText(PROTOCOL_FIND_TITLE);
|
||||
_bSettingList = false;
|
||||
|
||||
|
||||
if (repeatNammes != ""){
|
||||
QString err = "Any protocol have repeated id or name: ";
|
||||
err += repeatNammes;
|
||||
MsgBox::Show("error", err.toUtf8().data());
|
||||
}
|
||||
|
||||
_up_layout = new QVBoxLayout();
|
||||
|
||||
_arrow = new QToolButton(_up_widget);
|
||||
|
||||
QHBoxLayout *hori_layout = new QHBoxLayout();
|
||||
hori_layout->addWidget(_add_button);
|
||||
hori_layout->addWidget(_del_all_button);
|
||||
hori_layout->addWidget(_protocol_combobox);
|
||||
hori_layout->addWidget(_keyword_edit);
|
||||
hori_layout->addWidget(_arrow);
|
||||
hori_layout->addStretch(1);
|
||||
|
||||
_up_layout = new QVBoxLayout();
|
||||
_up_layout->addLayout(hori_layout);
|
||||
_up_layout->addStretch(1);
|
||||
|
||||
@@ -228,12 +211,6 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio
|
||||
|
||||
retranslateUi();
|
||||
|
||||
_key_find_timer.SetCallback(std::bind(&ProtocolDock::show_protocol_list_panel, this));
|
||||
//when porotocol list panel was showPopup statu, receive key press event
|
||||
QWidget *popup1 = _protocol_combobox->findChild<QFrame*>();
|
||||
QWidget *wid1 = popup1->findChild<QWidget*>();
|
||||
wid1->installEventFilter(this);
|
||||
|
||||
connect(_dn_nav_button, SIGNAL(clicked()),this, SLOT(nav_table_view()));
|
||||
connect(_dn_save_button, SIGNAL(clicked()),this, SLOT(export_table_view()));
|
||||
connect(_dn_set_button, SIGNAL(clicked()),this, SLOT(set_model()));
|
||||
@@ -250,10 +227,7 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio
|
||||
|
||||
connect(_search_edit, SIGNAL(editingFinished()), this, SLOT(search_changed()));
|
||||
|
||||
connect(_protocol_combobox->lineEdit(), SIGNAL(textEdited(const QString &)),
|
||||
this, SLOT(on_decoder_name_edited(const QString &)));
|
||||
|
||||
connect(_protocol_combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_new_decoder_selected(int)));
|
||||
connect(_arrow, SIGNAL(clicked()), this, SLOT(show_protocol_select()));
|
||||
}
|
||||
|
||||
ProtocolDock::~ProtocolDock()
|
||||
@@ -268,15 +242,6 @@ ProtocolDock::~ProtocolDock()
|
||||
RELEASE_ARRAY(_decoderInfoList);
|
||||
}
|
||||
|
||||
void ProtocolDock::changeEvent(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::LanguageChange)
|
||||
retranslateUi();
|
||||
else if (event->type() == QEvent::StyleChange)
|
||||
reStyle();
|
||||
QScrollArea::changeEvent(event);
|
||||
}
|
||||
|
||||
void ProtocolDock::retranslateUi()
|
||||
{
|
||||
_search_edit->setPlaceholderText(tr("search"));
|
||||
@@ -296,16 +261,24 @@ void ProtocolDock::reStyle()
|
||||
_pre_button->setIcon(QIcon(iconPath+"/pre.svg"));
|
||||
_nxt_button->setIcon(QIcon(iconPath+"/next.svg"));
|
||||
_search_button->setIcon(QIcon(iconPath+"/search.svg"));
|
||||
_arrow->setIcon(QIcon(iconPath + "/search.svg"));
|
||||
|
||||
for (auto it = _protocol_lay_items.begin(); it != _protocol_lay_items.end(); it++){
|
||||
(*it)->ResetStyle();
|
||||
}
|
||||
}
|
||||
|
||||
void ProtocolDock::paintEvent(QPaintEvent *)
|
||||
{
|
||||
void ProtocolDock::changeEvent(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::LanguageChange)
|
||||
retranslateUi();
|
||||
else if (event->type() == QEvent::StyleChange)
|
||||
reStyle();
|
||||
QScrollArea::changeEvent(event);
|
||||
}
|
||||
|
||||
//void ProtocolDock::paintEvent(QPaintEvent *){}
|
||||
|
||||
void ProtocolDock::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
int width = this->visibleRegion().boundingRect().width();
|
||||
@@ -332,7 +305,7 @@ int ProtocolDock::get_protocol_index_by_id(QString id)
|
||||
{
|
||||
int dex = 0;
|
||||
for (auto info : _decoderInfoList){
|
||||
srd_decoder *dec = (srd_decoder *)(info->ObjectHandle);
|
||||
srd_decoder *dec = (srd_decoder *)(info->_data_handle);
|
||||
QString proid(dec->id);
|
||||
if (id == proid){
|
||||
return dex;
|
||||
@@ -340,23 +313,24 @@ int ProtocolDock::get_protocol_index_by_id(QString id)
|
||||
++dex;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void ProtocolDock::on_add_protocol()
|
||||
{
|
||||
if (_decoderInfoList.size() == 0){
|
||||
if (_decoderInfoList.size() == 0){
|
||||
MsgBox::Show(NULL, "Protocol list is empty!");
|
||||
return;
|
||||
}
|
||||
if (_protocol_combobox->currentIndex() == -1){
|
||||
if (_selected_protocol_id == ""){
|
||||
MsgBox::Show(NULL, "Please select a protocol!");
|
||||
return;
|
||||
}
|
||||
|
||||
int dex = _protocol_combobox->itemData(_protocol_combobox->currentIndex()).toInt();
|
||||
int dex = this->get_protocol_index_by_id(_selected_protocol_id);
|
||||
assert(dex >= 0);
|
||||
|
||||
//check the base protocol
|
||||
srd_decoder *const dec = (srd_decoder *)(_decoderInfoList[dex]->ObjectHandle);
|
||||
srd_decoder *const dec = (srd_decoder *)(_decoderInfoList[dex]->_data_handle);
|
||||
QString pro_id(dec->id);
|
||||
std::list<data::decode::Decoder*> sub_decoders;
|
||||
|
||||
@@ -373,7 +347,7 @@ void ProtocolDock::on_add_protocol()
|
||||
|
||||
while (base_dex != -1)
|
||||
{
|
||||
srd_decoder *base_dec = (srd_decoder *)(_decoderInfoList[base_dex]->ObjectHandle);
|
||||
srd_decoder *base_dec = (srd_decoder *)(_decoderInfoList[base_dex]->_data_handle);
|
||||
pro_id = QString(base_dec->id); //change base protocol
|
||||
|
||||
assert(base_dec->inputs);
|
||||
@@ -418,7 +392,7 @@ bool ProtocolDock::add_protocol_by_id(QString id, bool silent, std::list<pv::dat
|
||||
return false;
|
||||
}
|
||||
|
||||
srd_decoder *const decoder = (srd_decoder *)(_decoderInfoList[dex]->ObjectHandle);
|
||||
srd_decoder *const decoder = (srd_decoder *)(_decoderInfoList[dex]->_data_handle);
|
||||
DecoderStatus *dstatus = new DecoderStatus();
|
||||
dstatus->m_format = (int)DecoderDataFormat::hex;
|
||||
|
||||
@@ -924,54 +898,12 @@ void ProtocolDock::OnProtocolFormatChanged(QString format, void *handle){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProtocolDock::on_decoder_name_edited(const QString &value)
|
||||
{
|
||||
_bSettingList = true;
|
||||
|
||||
while (_protocol_combobox->count())
|
||||
{
|
||||
_protocol_combobox->removeItem(0);
|
||||
}
|
||||
|
||||
for (auto info: _decoderInfoList){
|
||||
srd_decoder *dec = (srd_decoder *)(info->ObjectHandle);
|
||||
QString name(dec->name);
|
||||
QString id(dec->id);
|
||||
|
||||
if (value == ""
|
||||
|| name.indexOf(value, 0, Qt::CaseInsensitive) != -1
|
||||
|| id.indexOf(value, 0, Qt::CaseInsensitive) != -1 ){
|
||||
_protocol_combobox->addItem(QString::fromUtf8(dec->name), QVariant::fromValue(info->Index));
|
||||
}
|
||||
}
|
||||
|
||||
_protocol_combobox->setCurrentIndex(-1);
|
||||
_protocol_combobox->lineEdit()->setText(value);
|
||||
_bSettingList = false;
|
||||
|
||||
if (_key_find_timer.IsActived() == false){
|
||||
//check input keep time
|
||||
_key_find_timer.Start(100);
|
||||
}
|
||||
else{
|
||||
_key_find_timer.ResetActiveTime();
|
||||
}
|
||||
}
|
||||
|
||||
void ProtocolDock::show_protocol_list_panel()
|
||||
{
|
||||
//press key end, to popup list panel
|
||||
if (_key_find_timer.GetActiveTimeLong() >= 1000){
|
||||
_key_find_timer.Stop();
|
||||
_protocol_combobox->showPopup();
|
||||
}
|
||||
}
|
||||
|
||||
bool ProtocolDock::protocol_sort_callback(const DecoderInfoItem *o1, const DecoderInfoItem *o2)
|
||||
{
|
||||
srd_decoder *dec1 = (srd_decoder *)(o1->ObjectHandle);
|
||||
srd_decoder *dec2 = (srd_decoder *)(o2->ObjectHandle);
|
||||
srd_decoder *dec1 = (srd_decoder *)(o1->_data_handle);
|
||||
srd_decoder *dec2 = (srd_decoder *)(o2->_data_handle);
|
||||
const char *s1 = dec1->name;
|
||||
const char *s2 = dec2->name;
|
||||
char c1 = 0;
|
||||
@@ -1002,24 +934,6 @@ bool ProtocolDock::protocol_sort_callback(const DecoderInfoItem *o1, const Decod
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProtocolDock::eventFilter(QObject *object, QEvent *event)
|
||||
{
|
||||
if ( event->type() == QEvent::KeyPress )
|
||||
{
|
||||
if (_protocol_combobox->IsPopup()){
|
||||
_protocol_combobox->hidePopup();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ProtocolDock::on_new_decoder_selected(int index)
|
||||
{
|
||||
if (index >= 0 && _bSettingList == false){
|
||||
on_add_protocol();
|
||||
}
|
||||
}
|
||||
|
||||
QString ProtocolDock::parse_protocol_id(const char *id)
|
||||
{
|
||||
if (id == NULL || *id == 0){
|
||||
@@ -1056,7 +970,7 @@ bool ProtocolDock::eventFilter(QObject *object, QEvent *event)
|
||||
|
||||
for (auto info : _decoderInfoList)
|
||||
{
|
||||
srd_decoder *dec = (srd_decoder *)(info->ObjectHandle);
|
||||
srd_decoder *dec = (srd_decoder *)(info->_data_handle);
|
||||
if (dec->outputs)
|
||||
{
|
||||
QString output_id = parse_protocol_id((char*)dec->outputs->data);
|
||||
@@ -1074,10 +988,35 @@ bool ProtocolDock::eventFilter(QObject *object, QEvent *event)
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------
|
||||
void ProtocolDock::BeginEditKeyword()
|
||||
{
|
||||
show_protocol_select();
|
||||
}
|
||||
|
||||
void ProtocolDock::show_protocol_select()
|
||||
{
|
||||
SearchComboBox *panel = new SearchComboBox(this);
|
||||
|
||||
for (auto info : _decoderInfoList)
|
||||
{
|
||||
srd_decoder *dec = (srd_decoder *)(info->_data_handle);
|
||||
panel->AddDataItem(QString(dec->id), QString(dec->name), info);
|
||||
}
|
||||
panel->SetItemClickHandle(this);
|
||||
panel->ShowDlg(_keyword_edit);
|
||||
}
|
||||
|
||||
void ProtocolDock::OnItemClick(void *sender, void *data_handle)
|
||||
{
|
||||
if (data_handle != NULL){
|
||||
DecoderInfoItem *info = (DecoderInfoItem*)data_handle;
|
||||
srd_decoder *dec = (srd_decoder *)(info->_data_handle);
|
||||
this->_keyword_edit->setText( QString(dec->name));
|
||||
_selected_protocol_id = QString(dec->id);
|
||||
this->on_add_protocol();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace dock
|
||||
} // namespace pv
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <QTableView>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QLineEdit>
|
||||
#include <QToolButton>
|
||||
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
@@ -42,13 +43,11 @@
|
||||
|
||||
#include "../data/decodermodel.h"
|
||||
#include "protocolitemlayer.h"
|
||||
#include "../ui/dscombobox.h"
|
||||
#include "../dstimer.h"
|
||||
#include "keywordlineedit.h"
|
||||
#include "searchcombobox.h"
|
||||
|
||||
struct DecoderInfoItem{
|
||||
int Index;
|
||||
void *ObjectHandle; //srd_decoder* type
|
||||
void *_data_handle; //srd_decoder* type
|
||||
};
|
||||
|
||||
namespace pv {
|
||||
@@ -68,7 +67,10 @@ class View;
|
||||
|
||||
namespace dock {
|
||||
|
||||
class ProtocolDock : public QScrollArea, public IProtocolItemLayerCallback
|
||||
class ProtocolDock : public QScrollArea,
|
||||
public IProtocolItemLayerCallback,
|
||||
public IKeywordActive,
|
||||
public ISearchItemClick
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -88,7 +90,7 @@ private:
|
||||
void reStyle();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
//void paintEvent(QPaintEvent *);
|
||||
void resizeEvent(QResizeEvent *);
|
||||
|
||||
int get_protocol_index_by_id(QString id);
|
||||
@@ -101,6 +103,12 @@ private:
|
||||
void OnProtocolDelete(void *handle);
|
||||
void OnProtocolFormatChanged(QString format, void *handle);
|
||||
|
||||
//IKeywordActive
|
||||
void BeginEditKeyword();
|
||||
|
||||
//ISearchItemClick
|
||||
void OnItemClick(void *sender, void *data_handle);
|
||||
|
||||
signals:
|
||||
void protocol_updated();
|
||||
|
||||
@@ -121,15 +129,12 @@ private slots:
|
||||
void search_done();
|
||||
void search_changed();
|
||||
void search_update();
|
||||
void on_decoder_name_edited(const QString &value);
|
||||
void on_new_decoder_selected(int index);
|
||||
void show_protocol_select();
|
||||
|
||||
private:
|
||||
private:
|
||||
static int decoder_name_cmp(const void *a, const void *b);
|
||||
void resize_table_view(data::DecoderModel *decoder_model);
|
||||
static bool protocol_sort_callback(const DecoderInfoItem *o1, const DecoderInfoItem *o2);
|
||||
void show_protocol_list_panel();
|
||||
bool eventFilter(QObject *object, QEvent *event);
|
||||
|
||||
private:
|
||||
SigSession *_session;
|
||||
@@ -152,8 +157,7 @@ private:
|
||||
QLabel *_dn_title_label;
|
||||
|
||||
QPushButton *_add_button;
|
||||
QPushButton *_del_all_button;
|
||||
DsComboBox *_protocol_combobox;
|
||||
QPushButton *_del_all_button;
|
||||
QVBoxLayout *_up_layout;
|
||||
std::vector <ProtocolItemLayer*> _protocol_lay_items; //protocol item layers
|
||||
|
||||
@@ -162,14 +166,12 @@ private:
|
||||
QPushButton *_dn_nav_button;
|
||||
QPushButton *_search_button;
|
||||
std::vector<DecoderInfoItem*> _decoderInfoList;
|
||||
KeywordLineEdit *_keyword_edit;
|
||||
QString _selected_protocol_id;
|
||||
QToolButton *_arrow;
|
||||
|
||||
mutable std::mutex _search_mutex;
|
||||
bool _search_edited;
|
||||
bool _searching;
|
||||
|
||||
bool _add_silent;
|
||||
DsTimer _key_find_timer;
|
||||
bool _bSettingList;
|
||||
bool _search_edited;
|
||||
};
|
||||
|
||||
} // namespace dock
|
||||
|
||||
171
DSView/pv/dock/searchcombobox.cpp
Normal file
171
DSView/pv/dock/searchcombobox.cpp
Normal file
@@ -0,0 +1,171 @@
|
||||
#include "searchcombobox.h"
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QPoint>
|
||||
#include <QLineEdit>
|
||||
#include <QScrollBar>
|
||||
|
||||
|
||||
//----------------------ComboButtonItem
|
||||
|
||||
ComboButtonItem::ComboButtonItem(QWidget *parent, ISearchItemClick *click, void *data_handle)
|
||||
:QPushButton(parent)
|
||||
{
|
||||
_click = click;
|
||||
_data_handle = data_handle;
|
||||
}
|
||||
|
||||
void ComboButtonItem::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
if (_click != NULL){
|
||||
_click->OnItemClick(this, _data_handle);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------SearchComboBox
|
||||
|
||||
SearchComboBox::SearchComboBox(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
_bShow = false;
|
||||
_item_click = NULL;
|
||||
|
||||
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
|
||||
// setAttribute(Qt::WA_TranslucentBackground);
|
||||
}
|
||||
|
||||
SearchComboBox::~SearchComboBox(){
|
||||
//release resource
|
||||
for (auto o : _items){
|
||||
delete o;
|
||||
}
|
||||
_items.clear();
|
||||
}
|
||||
|
||||
void SearchComboBox::ShowDlg(QWidget *editline)
|
||||
{
|
||||
if (_bShow)
|
||||
return;
|
||||
|
||||
_bShow = true;
|
||||
|
||||
int w = 350;
|
||||
int h = 450;
|
||||
|
||||
if (editline != NULL){
|
||||
w = editline->width() + 7;
|
||||
}
|
||||
|
||||
this->setMinimumSize(w, h);
|
||||
this->setMaximumSize(w, h);
|
||||
|
||||
QVBoxLayout *grid = new QVBoxLayout(this);
|
||||
this->setLayout(grid);
|
||||
grid->setContentsMargins(0,0,0,0);
|
||||
grid->setAlignment(Qt::AlignTop);
|
||||
grid->setSpacing(2);
|
||||
|
||||
QLineEdit *edit = new QLineEdit(this);
|
||||
edit->setMaximumWidth(this->width());
|
||||
grid->addWidget(edit);
|
||||
|
||||
QWidget *panel = new QWidget(this);
|
||||
grid->addWidget(panel);
|
||||
|
||||
panel->setContentsMargins(0,0,0,0);
|
||||
panel->setMinimumSize(w, h - edit->height() - 5);
|
||||
panel->setMaximumSize(w, h - edit->height() - 5);
|
||||
|
||||
QWidget *listPanel = new QWidget(panel);
|
||||
listPanel->setMinimumSize(w-2, panel->height());
|
||||
listPanel->setMaximumWidth(w-2);
|
||||
|
||||
QVBoxLayout *listLay = new QVBoxLayout(listPanel);
|
||||
listLay->setContentsMargins(2, 2, 20, 2);
|
||||
listLay->setSpacing(0);
|
||||
listLay->setAlignment(Qt::AlignTop);
|
||||
|
||||
for(auto o : _items)
|
||||
{
|
||||
ComboButtonItem *bt = new ComboButtonItem(panel, this, o);
|
||||
bt->setText(o->_name);
|
||||
bt->setObjectName("flat");
|
||||
bt->setMaximumWidth(w - 20);
|
||||
bt->setMinimumWidth(w - 20);
|
||||
o->_control = bt;
|
||||
listLay->addWidget(bt);
|
||||
}
|
||||
|
||||
_scroll = new QScrollArea(panel);
|
||||
_scroll->setWidget(listPanel);
|
||||
// pScrollArea->setStyleSheet("QScrollArea{border:none; background:red;}");
|
||||
_scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
||||
if (editline != NULL)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
edit->setFocus();
|
||||
this->show();
|
||||
|
||||
|
||||
connect(edit, SIGNAL(textEdited(const QString &)),
|
||||
this, SLOT(on_keyword_changed(const QString &)));
|
||||
}
|
||||
|
||||
void SearchComboBox::AddDataItem(QString id, QString name, void *data_handle)
|
||||
{
|
||||
SearchDataItem *item = new SearchDataItem();
|
||||
item->_id = id;
|
||||
item->_name = name;
|
||||
item->_data_handle = data_handle;
|
||||
this->_items.push_back(item);
|
||||
}
|
||||
|
||||
void SearchComboBox::changeEvent(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::ActivationChange){
|
||||
if (this->isActiveWindow() == false){
|
||||
this->close();
|
||||
this->deleteLater();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QWidget::changeEvent(event);
|
||||
}
|
||||
|
||||
void SearchComboBox::OnItemClick(void *sender, void *data_handle)
|
||||
{
|
||||
if (data_handle != NULL && _item_click){
|
||||
SearchDataItem *item = (SearchDataItem*)data_handle;
|
||||
this->close();
|
||||
ISearchItemClick *click = _item_click;
|
||||
this->deleteLater();
|
||||
click->OnItemClick(this, item->_data_handle);
|
||||
}
|
||||
}
|
||||
|
||||
void SearchComboBox::on_keyword_changed(const QString &value)
|
||||
{
|
||||
for(auto o : _items)
|
||||
{
|
||||
if (value == ""
|
||||
|| o->_name.indexOf(value, 0, Qt::CaseInsensitive) >= 0
|
||||
|| o->_id.indexOf(value, 0, Qt::CaseInsensitive) >= 0){
|
||||
if (o->_control->isHidden()){
|
||||
o->_control->show();
|
||||
}
|
||||
}
|
||||
else if (o->_control->isHidden() == false){
|
||||
o->_control->hide();
|
||||
}
|
||||
}
|
||||
|
||||
_scroll->verticalScrollBar()->setValue(0);
|
||||
}
|
||||
79
DSView/pv/dock/searchcombobox.h
Normal file
79
DSView/pv/dock/searchcombobox.h
Normal file
@@ -0,0 +1,79 @@
|
||||
#ifndef SEARCHCOMBOBOX_H
|
||||
#define SEARCHCOMBOBOX_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDialog>
|
||||
#include <QWidget>
|
||||
#include <QMouseEvent>
|
||||
#include <QPushButton>
|
||||
#include <QString>
|
||||
#include <vector>
|
||||
#include <QEvent>
|
||||
#include <QScrollArea>
|
||||
|
||||
class ISearchItemClick{
|
||||
public:
|
||||
virtual void OnItemClick(void *sender, void *data_handle)=0;
|
||||
};
|
||||
|
||||
//----------------------ComboButtonItem
|
||||
class ComboButtonItem : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ComboButtonItem(QWidget *parent, ISearchItemClick *click, void *data_handle);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
|
||||
private:
|
||||
void *_data_handle;
|
||||
ISearchItemClick *_click;
|
||||
};
|
||||
|
||||
//----------------------SearchDataItem
|
||||
|
||||
class SearchDataItem{
|
||||
public:
|
||||
QString _id;
|
||||
QString _name;
|
||||
void *_data_handle;
|
||||
QWidget *_control;
|
||||
};
|
||||
|
||||
//----------------------SearchComboBox
|
||||
|
||||
class SearchComboBox : public QDialog, ISearchItemClick
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SearchComboBox(QWidget *parent = nullptr);
|
||||
|
||||
~SearchComboBox();
|
||||
|
||||
void ShowDlg(QWidget *editline);
|
||||
|
||||
void AddDataItem(QString id, QString name, void *data_handle);
|
||||
|
||||
inline void SetItemClickHandle(ISearchItemClick *click){
|
||||
_item_click = click;
|
||||
}
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent *event);
|
||||
|
||||
private slots:
|
||||
void on_keyword_changed(const QString &value);
|
||||
|
||||
private:
|
||||
//ISearchItemClick
|
||||
void OnItemClick(void *sender, void *data_handle);
|
||||
|
||||
private:
|
||||
bool _bShow;
|
||||
std::vector<SearchDataItem*> _items;
|
||||
ISearchItemClick *_item_click;
|
||||
QScrollArea *_scroll;
|
||||
};
|
||||
|
||||
#endif // SEARCHCOMBOBOX_H
|
||||
@@ -55,6 +55,7 @@
|
||||
#include "../dsvdef.h"
|
||||
#include "../ui/dscombobox.h"
|
||||
#include "../ui/msgbox.h"
|
||||
#include "../appcontrol.h"
|
||||
#include <QDebug>
|
||||
|
||||
using namespace boost;
|
||||
@@ -357,7 +358,8 @@ bool DecodeTrace::create_popup()
|
||||
_form_base_height = 0;
|
||||
_decoder_container = NULL;
|
||||
|
||||
dialogs::DSDialog dlg;
|
||||
QWidget *topWindow = AppControl::Instance()->GetTopWindow();
|
||||
dialogs::DSDialog dlg(topWindow);
|
||||
//dlg.setMinimumSize(500,600);
|
||||
create_popup_form(&dlg);
|
||||
|
||||
|
||||
@@ -62,6 +62,18 @@ QWidget:item:selected
|
||||
}
|
||||
*/
|
||||
|
||||
QPushButton#flat{
|
||||
text-align:left;
|
||||
border:none;
|
||||
font-size:14px;
|
||||
}
|
||||
|
||||
QPushButton#flat:hover
|
||||
{
|
||||
background-color: #177cb0;
|
||||
color: #801dae;
|
||||
}
|
||||
|
||||
QCheckBox
|
||||
{
|
||||
spacing: 0px;
|
||||
|
||||
@@ -59,6 +59,18 @@ QWidget:item:selected
|
||||
}
|
||||
*/
|
||||
|
||||
QPushButton#flat{
|
||||
text-align:left;
|
||||
border:none;
|
||||
font-size:14px;
|
||||
}
|
||||
|
||||
QPushButton#flat:hover
|
||||
{
|
||||
background-color: #44cef6;
|
||||
color: #801dae;
|
||||
}
|
||||
|
||||
QCheckBox
|
||||
{
|
||||
spacing: 0px;
|
||||
|
||||
Reference in New Issue
Block a user