diff --git a/CMakeLists.txt b/CMakeLists.txt index e5d3c876..0c962402 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -348,6 +348,7 @@ set(DSView_SOURCES DSView/pv/deviceagent.cpp DSView/pv/ui/langresource.cpp DSView/pv/ui/fn.cpp + DSView/pv/ui/xtoolbutton.cpp ) set(DSView_HEADERS diff --git a/DSView/pv/dialogs/dsomeasure.cpp b/DSView/pv/dialogs/dsomeasure.cpp index 09f88119..34dedb44 100644 --- a/DSView/pv/dialogs/dsomeasure.cpp +++ b/DSView/pv/dialogs/dsomeasure.cpp @@ -32,6 +32,7 @@ #include "../dsvdef.h" #include "../ui/langresource.h" +#include "../ui/xtoolbutton.h" using namespace std; using namespace pv::view; @@ -95,7 +96,7 @@ void DsoMeasure::add_measure(QWidget *widget, const view::DsoSignal *dsoSig) pv::view::DsoSignal *psig = const_cast(dsoSig); for (int i=DSO_MS_BEGIN+1; isetProperty("id", QVariant(i)); button->setIconSize(QSize(48, 48)); QPixmap msPix(get_ms_icon(i)); @@ -155,7 +156,7 @@ void DsoMeasure::accept() { using namespace Qt; - QToolButton* sc = dynamic_cast(sender()); + auto sc = dynamic_cast(sender()); if(sc != NULL) { QVariant id = sc->property("id"); enum DSO_MEASURE_TYPE ms_type = DSO_MEASURE_TYPE(id.toInt()); diff --git a/DSView/pv/dialogs/dsomeasure.h b/DSView/pv/dialogs/dsomeasure.h index ca541ef1..72e8192f 100644 --- a/DSView/pv/dialogs/dsomeasure.h +++ b/DSView/pv/dialogs/dsomeasure.h @@ -24,7 +24,6 @@ #define DSVIEW_PV_DSOMEASURE_H #include -#include #include #include diff --git a/DSView/pv/dialogs/lissajousoptions.h b/DSView/pv/dialogs/lissajousoptions.h index edb6ce68..5561f4e5 100644 --- a/DSView/pv/dialogs/lissajousoptions.h +++ b/DSView/pv/dialogs/lissajousoptions.h @@ -23,8 +23,7 @@ #ifndef DSVIEW_PV_LISSAJOUSOPTIONS_H #define DSVIEW_PV_LISSAJOUSOPTIONS_H -#include -#include +#include #include #include #include diff --git a/DSView/pv/dialogs/mathoptions.h b/DSView/pv/dialogs/mathoptions.h index ed6aa2fb..fd155158 100644 --- a/DSView/pv/dialogs/mathoptions.h +++ b/DSView/pv/dialogs/mathoptions.h @@ -23,8 +23,7 @@ #ifndef DSVIEW_PV_MATHOPTIONS_H #define DSVIEW_PV_MATHOPTIONS_H -#include -#include +#include #include #include #include diff --git a/DSView/pv/dock/measuredock.cpp b/DSView/pv/dock/measuredock.cpp index f4a8671b..e1b2841c 100644 --- a/DSView/pv/dock/measuredock.cpp +++ b/DSView/pv/dock/measuredock.cpp @@ -41,6 +41,7 @@ #include "../appcontrol.h" #include "../ui/fn.h" #include "../log.h" +#include "../ui/xtoolbutton.h" using namespace boost; @@ -91,7 +92,7 @@ MeasureDock::MeasureDock(QWidget *parent, View &view, SigSession *session) : /* cursor distance group */ _dist_groupBox = new QGroupBox(_widget); _dist_groupBox->setMinimumWidth(300); - _dist_add_btn = new QToolButton(_widget); + _dist_add_btn = new XToolButton(_widget); _dist_layout = new QGridLayout(_widget); _dist_layout->setVerticalSpacing(5); @@ -107,7 +108,7 @@ MeasureDock::MeasureDock(QWidget *parent, View &view, SigSession *session) : /* cursor edges group */ _edge_groupBox = new QGroupBox(_widget); _edge_groupBox->setMinimumWidth(300); - _edge_add_btn = new QToolButton(_widget); + _edge_add_btn = new XToolButton(_widget); _channel_label = new QLabel(_widget); _edge_label = new QLabel(_widget); @@ -269,7 +270,7 @@ void MeasureDock::build_dist_pannel() row_widget->setLayout(row_layout); QString iconPath = GetIconPath(); - QToolButton *del_btn = new QToolButton(row_widget); + XToolButton *del_btn = new XToolButton(row_widget); del_btn->setIcon(QIcon(iconPath+"/del.svg")); del_btn->setCheckable(true); //tr @@ -346,7 +347,7 @@ void MeasureDock::add_dist_measure() void MeasureDock::del_dist_measure() { - QToolButton* src = dynamic_cast(sender()); + auto src = dynamic_cast(sender()); assert(src); for (auto it =_dist_row_list.begin(); it != _dist_row_list.end(); it++) @@ -392,7 +393,7 @@ void MeasureDock::build_edge_pannel() row_widget->setLayout(row_layout); QString iconPath = GetIconPath(); - QToolButton *del_btn = new QToolButton(row_widget); + XToolButton *del_btn = new XToolButton(row_widget); del_btn->setIcon(QIcon(iconPath+"/del.svg")); del_btn->setCheckable(true); //tr @@ -775,7 +776,7 @@ void MeasureDock::cursor_update() auto &cursor_list = _view.get_cursorList(); for(auto it = cursor_list.begin(); it != cursor_list.end(); it++) { - QToolButton *del_btn = new QToolButton(_widget); + XToolButton *del_btn = new XToolButton(_widget); del_btn->setIcon(QIcon(iconPath+"/del.svg")); del_btn->setCheckable(true); QPushButton *cursor_pushButton = new QPushButton(QString::number(index), _widget); @@ -805,7 +806,7 @@ void MeasureDock::cursor_update() void MeasureDock::del_cursor() { - QToolButton *src = qobject_cast(sender()); + auto *src = qobject_cast(sender()); assert(src); Cursor* cursor = NULL; diff --git a/DSView/pv/dock/measuredock.h b/DSView/pv/dock/measuredock.h index 04442dbf..55d559f4 100644 --- a/DSView/pv/dock/measuredock.h +++ b/DSView/pv/dock/measuredock.h @@ -41,6 +41,7 @@ #include "../ui/dscombobox.h" #include "../interface/icallbacks.h" +#include "../ui/xtoolbutton.h" namespace pv { @@ -55,7 +56,7 @@ namespace dock { struct cursor_row_info { - QToolButton *del_bt; + XToolButton *del_bt; QPushButton *start_bt; QPushButton *end_bt; QLabel *r_label; @@ -66,7 +67,7 @@ struct cursor_row_info struct cursor_opt_info { - QToolButton *del_bt; + XToolButton *del_bt; QPushButton *goto_bt; QLabel *info_label; view::Cursor *cursor; @@ -135,10 +136,10 @@ private: QLabel *_add_dec_label; QGridLayout *_dist_layout; QGroupBox *_dist_groupBox; - QToolButton *_dist_add_btn; + XToolButton *_dist_add_btn; QGridLayout *_edge_layout; QGroupBox *_edge_groupBox; - QToolButton *_edge_add_btn; + XToolButton *_edge_add_btn; QPushButton *_sel_btn; QWidget *_dist_pannel; QWidget *_edge_pannel; diff --git a/DSView/pv/dock/protocoldock.cpp b/DSView/pv/dock/protocoldock.cpp index eeb58903..69d5b920 100644 --- a/DSView/pv/dock/protocoldock.cpp +++ b/DSView/pv/dock/protocoldock.cpp @@ -43,8 +43,7 @@ #include #include #include -#include -#include +#include #include #include #include "../ui/msgbox.h" @@ -122,7 +121,7 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio _pro_keyword_edit = new KeywordLineEdit(top_panel, this); _pro_keyword_edit->setReadOnly(true); - _pro_search_button = new QToolButton(top_panel); + _pro_search_button = new XToolButton(top_panel); QHBoxLayout *pro_search_lay = new QHBoxLayout(); pro_search_lay->setSpacing(2); pro_search_lay->addWidget(_pro_add_button); diff --git a/DSView/pv/dock/protocoldock.h b/DSView/pv/dock/protocoldock.h index adbaa233..21628a55 100644 --- a/DSView/pv/dock/protocoldock.h +++ b/DSView/pv/dock/protocoldock.h @@ -34,8 +34,7 @@ #include #include #include -#include -#include +#include #include #include @@ -46,6 +45,7 @@ #include "keywordlineedit.h" #include "searchcombobox.h" #include "../interface/icallbacks.h" +#include "../ui/xtoolbutton.h" struct DecoderInfoItem{ void *_data_handle; //srd_decoder* type @@ -169,7 +169,7 @@ private: std::vector _decoderInfoList; KeywordLineEdit *_pro_keyword_edit; QString _selected_protocol_id; - QToolButton *_pro_search_button; + XToolButton *_pro_search_button; mutable std::mutex _search_mutex; bool _search_edited; diff --git a/DSView/pv/mainframe.cpp b/DSView/pv/mainframe.cpp index b941ae22..1570173c 100644 --- a/DSView/pv/mainframe.cpp +++ b/DSView/pv/mainframe.cpp @@ -283,7 +283,10 @@ void MainFrame::MoveBegin() } void MainFrame::MoveEnd() -{ +{ + + saveNormalRegion(); + #ifdef _WIN32 if (_parentNativeWidget != NULL){ auto scr = _parentNativeWidget->GetPointScreen(); @@ -447,14 +450,7 @@ void MainFrame::moveToWinNaitiveNormal() } bool MainFrame::eventFilter(QObject *object, QEvent *event) -{ - if (event->type() == QEvent::Move && _is_resize_ready){ - if (_is_max_status == false && _titleBar->IsMoving()){ - saveNormalRegion(); - } - return QFrame::eventFilter(object, event); - } - +{ const QEvent::Type type = event->type(); const QMouseEvent *const mouse_event = (QMouseEvent*)event; int newWidth = 0; @@ -517,7 +513,7 @@ bool MainFrame::eventFilter(QObject *object, QEvent *event) pt.setX(p.x); pt.setY(p.y); #else - pt = event->globalPos(); + pt = mouse_event->globalPos(); #endif int datX = pt.x() - _clickPos.x(); int datY = pt.y() - _clickPos.y(); @@ -622,7 +618,7 @@ bool MainFrame::eventFilter(QObject *object, QEvent *event) _clickPos.setX(p.x); _clickPos.setY(p.y); #else - _clickPos = event->globalPos(); + _clickPos = mouse_event->globalPos(); #endif _dragStartRegion = GetFormRegion(); diff --git a/DSView/pv/toolbars/filebar.cpp b/DSView/pv/toolbars/filebar.cpp index a8b9bdf1..9dc4e0d6 100644 --- a/DSView/pv/toolbars/filebar.cpp +++ b/DSView/pv/toolbars/filebar.cpp @@ -33,6 +33,7 @@ #include "../log.h" #include "../ui/fn.h" + namespace pv { namespace toolbars { diff --git a/DSView/pv/toolbars/filebar.h b/DSView/pv/toolbars/filebar.h index 6982ec1f..47be6461 100644 --- a/DSView/pv/toolbars/filebar.h +++ b/DSView/pv/toolbars/filebar.h @@ -24,12 +24,12 @@ #define DSVIEW_PV_TOOLBARS_FILEBAR_H #include -#include #include #include #include "../sigsession.h" #include "../interface/icallbacks.h" +#include "../ui/xtoolbutton.h" namespace pv { namespace toolbars { @@ -73,7 +73,7 @@ private slots: private: SigSession* _session; - QToolButton _file_button; + XToolButton _file_button; QMenu *_menu; QMenu *_menu_session; //when the hardware device is connected,it will be enable QAction *_action_load; diff --git a/DSView/pv/toolbars/logobar.h b/DSView/pv/toolbars/logobar.h index 8d3f2d08..acadc266 100644 --- a/DSView/pv/toolbars/logobar.h +++ b/DSView/pv/toolbars/logobar.h @@ -23,8 +23,7 @@ #ifndef DSVIEW_PV_TOOLBARS_LOGOBAR_H #define DSVIEW_PV_TOOLBARS_LOGOBAR_H -#include -#include +#include #include #include #include @@ -32,6 +31,7 @@ #include "../sigsession.h" #include "../interface/icallbacks.h" +#include "../ui/xtoolbutton.h" namespace pv { namespace toolbars { @@ -82,7 +82,7 @@ private: bool _connected; SigSession* _session; - QToolButton _logo_button; + XToolButton _logo_button; QMenu *_menu; diff --git a/DSView/pv/toolbars/samplingbar.h b/DSView/pv/toolbars/samplingbar.h index e8aa63f4..d16a95f5 100644 --- a/DSView/pv/toolbars/samplingbar.h +++ b/DSView/pv/toolbars/samplingbar.h @@ -28,13 +28,13 @@ #include #include -#include -#include +#include #include #include #include "../ui/dscombobox.h" #include "../interface/icallbacks.h" #include +#include "../ui/xtoolbutton.h" struct st_dev_inst; class QAction; @@ -141,14 +141,14 @@ namespace pv private: SigSession *_session; - QToolButton _device_type; + XToolButton _device_type; DsComboBox _device_selector; - QToolButton _configure_button; + XToolButton _configure_button; DsComboBox _sample_count; DsComboBox _sample_rate; - QToolButton _run_stop_button; - QToolButton _instant_button; - QToolButton _mode_button; + XToolButton _run_stop_button; + XToolButton _instant_button; + XToolButton _mode_button; QAction *_run_stop_action; QAction *_instant_action; diff --git a/DSView/pv/toolbars/titlebar.cpp b/DSView/pv/toolbars/titlebar.cpp index 13b0644b..8e9a80ec 100644 --- a/DSView/pv/toolbars/titlebar.cpp +++ b/DSView/pv/toolbars/titlebar.cpp @@ -21,8 +21,7 @@ #include "titlebar.h" #include -#include -#include +#include #include #include #include @@ -32,6 +31,7 @@ #include #include + #ifdef _WIN32 #include #endif @@ -72,9 +72,9 @@ TitleBar::TitleBar(bool top, QWidget *parent, ITitleParent *titleParent, bool ha lay1->addWidget(_title); if (_isTop) { - _minimizeButton = new QToolButton(this); + _minimizeButton = new XToolButton(this); _minimizeButton->setObjectName("MinimizeButton"); - _maximizeButton = new QToolButton(this); + _maximizeButton = new XToolButton(this); _maximizeButton->setObjectName("MaximizeButton"); lay1->addWidget(_minimizeButton); @@ -87,7 +87,7 @@ TitleBar::TitleBar(bool top, QWidget *parent, ITitleParent *titleParent, bool ha } if (_isTop || _hasClose) { - _closeButton= new QToolButton(this); + _closeButton= new XToolButton(this); _closeButton->setObjectName("CloseButton"); lay1->addWidget(_closeButton); connect(_closeButton, SIGNAL( clicked()), parent, SLOT(close())); diff --git a/DSView/pv/toolbars/titlebar.h b/DSView/pv/toolbars/titlebar.h index 73bb1b77..fac30af4 100644 --- a/DSView/pv/toolbars/titlebar.h +++ b/DSView/pv/toolbars/titlebar.h @@ -23,9 +23,10 @@ #define DSVIEW_PV_TOOLBARS_TITLEBAR_H #include - #include "../interface/icallbacks.h" +#include "../interface/icallbacks.h" +#include "../ui/xtoolbutton.h" + -class QToolButton; class QHBoxLayout; class QLabel; @@ -84,9 +85,9 @@ protected: void mouseDoubleClickEvent(QMouseEvent *event); - QToolButton *_minimizeButton; - QToolButton *_maximizeButton; - QToolButton *_closeButton; + XToolButton *_minimizeButton; + XToolButton *_maximizeButton; + XToolButton *_closeButton; QLabel *_title; bool _moving; diff --git a/DSView/pv/toolbars/trigbar.h b/DSView/pv/toolbars/trigbar.h index 53c913fa..bffe83f3 100644 --- a/DSView/pv/toolbars/trigbar.h +++ b/DSView/pv/toolbars/trigbar.h @@ -23,11 +23,11 @@ #ifndef DSVIEW_PV_TOOLBARS_TRIGBAR_H #define DSVIEW_PV_TOOLBARS_TRIGBAR_H -#include -#include +#include #include #include #include "../interface/icallbacks.h" +#include "../ui/xtoolbutton.h" class DockOptions; @@ -83,12 +83,12 @@ public slots: private: SigSession *_session; bool _enable; - QToolButton _trig_button; - QToolButton _protocol_button; - QToolButton _measure_button; - QToolButton _search_button; - QToolButton _function_button; - QToolButton _setting_button; + XToolButton _trig_button; + XToolButton _protocol_button; + XToolButton _measure_button; + XToolButton _search_button; + XToolButton _function_button; + XToolButton _setting_button; QAction *_trig_action; QAction *_protocol_action; QAction *_measure_action; diff --git a/DSView/pv/ui/dscombobox.h b/DSView/pv/ui/dscombobox.h index 0b4acb51..96ed5219 100644 --- a/DSView/pv/ui/dscombobox.h +++ b/DSView/pv/ui/dscombobox.h @@ -26,7 +26,7 @@ #include class DsComboBox : public QComboBox -{ +{ public: explicit DsComboBox(QWidget *parent = nullptr); }; diff --git a/DSView/pv/ui/fn.cpp b/DSView/pv/ui/fn.cpp index 3dda6890..66fdc207 100644 --- a/DSView/pv/ui/fn.cpp +++ b/DSView/pv/ui/fn.cpp @@ -22,7 +22,6 @@ #include "fn.h" #include #include -#include #include #include #include @@ -36,6 +35,7 @@ #include #include "../config/appconfig.h" +#include "../ui/xtoolbutton.h" namespace ui { diff --git a/DSView/pv/ui/xtoolbutton.cpp b/DSView/pv/ui/xtoolbutton.cpp new file mode 100644 index 00000000..dd655279 --- /dev/null +++ b/DSView/pv/ui/xtoolbutton.cpp @@ -0,0 +1,46 @@ +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2024 DreamSourceLab + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "xtoolbutton.h" +#include + + +XToolButton::XToolButton(QWidget *parent) + :QToolButton(parent) +{ + +} + +void XToolButton::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { + QMenu* menu = this->menu(); + if (menu) + { + QPoint pt = mapToGlobal(rect().bottomLeft()); + menu->exec(pt); + return; + } + } + + QToolButton::mousePressEvent(event); +} \ No newline at end of file diff --git a/DSView/pv/ui/xtoolbutton.h b/DSView/pv/ui/xtoolbutton.h new file mode 100644 index 00000000..df0ec868 --- /dev/null +++ b/DSView/pv/ui/xtoolbutton.h @@ -0,0 +1,40 @@ +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2024 DreamSourceLab + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef XTOOLBUTTON_H +#define XTOOLBUTTON_H + +#include +#include +#include + + +class XToolButton : public QToolButton +{ +public: + XToolButton(QWidget *parent = nullptr); + +protected: + void mousePressEvent(QMouseEvent *event);// override; +}; + + +#endif \ No newline at end of file diff --git a/DSView/pv/view/devmode.cpp b/DSView/pv/view/devmode.cpp index 015936f3..cb9858dc 100644 --- a/DSView/pv/view/devmode.cpp +++ b/DSView/pv/view/devmode.cpp @@ -61,7 +61,7 @@ DevMode::DevMode(QWidget *parent, SigSession *session) : layout->setSpacing(0); layout->setContentsMargins(2, 0, 0, 0); - _close_button = new QToolButton(); + _close_button = new XToolButton(); _close_button->setObjectName("FileCloseButton"); _close_button->setContentsMargins(0, 0, 0, 0); _close_button->setFixedWidth(10); @@ -70,7 +70,7 @@ DevMode::DevMode(QWidget *parent, SigSession *session) : _close_button->setToolButtonStyle(Qt::ToolButtonIconOnly); _close_button->setMinimumWidth(10); - _mode_btn = new QToolButton(); + _mode_btn = new XToolButton(); _mode_btn->setObjectName("ModeButton"); _mode_btn->setIconSize(QSize(height() * 1.5, height())); _mode_btn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); diff --git a/DSView/pv/view/devmode.h b/DSView/pv/view/devmode.h index 319fceef..50658887 100644 --- a/DSView/pv/view/devmode.h +++ b/DSView/pv/view/devmode.h @@ -29,12 +29,12 @@ #include #include #include -#include -#include +#include #include #include #include "../interface/icallbacks.h" +#include "../ui/xtoolbutton.h" struct dev_mode_name{ int _mode; @@ -86,10 +86,10 @@ private slots: private: SigSession *_session; std::map _mode_list; - QToolButton *_mode_btn; + XToolButton *_mode_btn; QMenu *_pop_menu; QPoint _mouse_point; - QToolButton *_close_button; + XToolButton *_close_button; bool _bFile; DeviceAgent *_device_agent; diff --git a/DSView/pv/view/viewstatus.h b/DSView/pv/view/viewstatus.h index 87ea2a6f..1d32bd2e 100644 --- a/DSView/pv/view/viewstatus.h +++ b/DSView/pv/view/viewstatus.h @@ -25,8 +25,7 @@ #include #include #include -#include -#include +#include #include namespace pv {