fix: The toolbar submenu is displayed on the secondary screen and not on the main screen

This commit is contained in:
dreamsourcelabTAI 2024-02-26 14:13:51 +08:00
parent 38ee5f1e23
commit b2e9de826a
24 changed files with 158 additions and 75 deletions

View File

@ -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

View File

@ -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<pv::view::DsoSignal*>(dsoSig);
for (int i=DSO_MS_BEGIN+1; i<DSO_MS_END; i++) {
QToolButton *button = new QToolButton(this);
XToolButton *button = new XToolButton(this);
button->setProperty("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<QToolButton*>(sender());
auto sc = dynamic_cast<QToolButton*>(sender());
if(sc != NULL) {
QVariant id = sc->property("id");
enum DSO_MEASURE_TYPE ms_type = DSO_MEASURE_TYPE(id.toInt());

View File

@ -24,7 +24,6 @@
#define DSVIEW_PV_DSOMEASURE_H
#include <QVBoxLayout>
#include <QToolButton>
#include <QDialogButtonBox>
#include <QTabWidget>

View File

@ -24,7 +24,6 @@
#define DSVIEW_PV_LISSAJOUSOPTIONS_H
#include <QGridLayout>
#include <QToolButton>
#include <QDialogButtonBox>
#include <QTabWidget>
#include <QGroupBox>

View File

@ -24,7 +24,6 @@
#define DSVIEW_PV_MATHOPTIONS_H
#include <QGridLayout>
#include <QToolButton>
#include <QDialogButtonBox>
#include <QTabWidget>
#include <QGroupBox>

View File

@ -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<QToolButton *>(sender());
auto src = dynamic_cast<QToolButton *>(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<QToolButton *>(sender());
auto *src = qobject_cast<QToolButton *>(sender());
assert(src);
Cursor* cursor = NULL;

View File

@ -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;

View File

@ -44,7 +44,6 @@
#include <assert.h>
#include <map>
#include <string>
#include <QToolButton>
#include <algorithm>
#include <QTableWidgetItem>
#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);

View File

@ -35,7 +35,6 @@
#include <QTableView>
#include <QSortFilterProxyModel>
#include <QLineEdit>
#include <QToolButton>
#include <vector>
#include <mutex>
@ -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<DecoderInfoItem*> _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;

View File

@ -284,6 +284,9 @@ void MainFrame::MoveBegin()
void MainFrame::MoveEnd()
{
saveNormalRegion();
#ifdef _WIN32
if (_parentNativeWidget != NULL){
auto scr = _parentNativeWidget->GetPointScreen();
@ -448,13 +451,6 @@ 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();

View File

@ -33,6 +33,7 @@
#include "../log.h"
#include "../ui/fn.h"
namespace pv {
namespace toolbars {

View File

@ -24,12 +24,12 @@
#define DSVIEW_PV_TOOLBARS_FILEBAR_H
#include <QToolBar>
#include <QToolButton>
#include <QAction>
#include <QMenu>
#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;

View File

@ -24,7 +24,6 @@
#define DSVIEW_PV_TOOLBARS_LOGOBAR_H
#include <QToolBar>
#include <QToolButton>
#include <QAction>
#include <QMenu>
#include <libsigrok.h>
@ -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;

View File

@ -29,12 +29,12 @@
#include <map>
#include <QToolBar>
#include <QToolButton>
#include <QAction>
#include <QMenu>
#include "../ui/dscombobox.h"
#include "../interface/icallbacks.h"
#include <QDialog>
#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;

View File

@ -22,7 +22,6 @@
#include "titlebar.h"
#include <QStyle>
#include <QLabel>
#include <QToolButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QEvent>
@ -32,6 +31,7 @@
#include <assert.h>
#include <QTimer>
#ifdef _WIN32
#include <windows.h>
#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()));

View File

@ -23,9 +23,10 @@
#define DSVIEW_PV_TOOLBARS_TITLEBAR_H
#include <QWidget>
#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;

View File

@ -24,10 +24,10 @@
#define DSVIEW_PV_TOOLBARS_TRIGBAR_H
#include <QToolBar>
#include <QToolButton>
#include <QAction>
#include <QMenu>
#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;

View File

@ -22,7 +22,6 @@
#include "fn.h"
#include <assert.h>
#include <QPushButton>
#include <QToolButton>
#include <QComboBox>
#include <QLabel>
#include <QAction>
@ -36,6 +35,7 @@
#include <QCheckBox>
#include "../config/appconfig.h"
#include "../ui/xtoolbutton.h"
namespace ui
{

View File

@ -0,0 +1,46 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2024 DreamSourceLab <support@dreamsourcelab.com>
*
* 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 <QMenu>
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);
}

View File

@ -0,0 +1,40 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2024 DreamSourceLab <support@dreamsourcelab.com>
*
* 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 <QWidget>
#include <QToolButton>
#include <QMouseEvent>
class XToolButton : public QToolButton
{
public:
XToolButton(QWidget *parent = nullptr);
protected:
void mousePressEvent(QMouseEvent *event);// override;
};
#endif

View File

@ -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);

View File

@ -30,11 +30,11 @@
#include <QWidget>
#include <QPushButton>
#include <QVector>
#include <QToolButton>
#include <QLabel>
#include <libsigrok.h>
#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 <QAction *, const sr_dev_mode *> _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;

View File

@ -26,7 +26,6 @@
#include <QLabel>
#include <QDateTime>
#include <QPushButton>
#include <QToolButton>
#include <libsigrok.h>
namespace pv {