titlebar able process window move

This commit is contained in:
dreamsourcelabTAI 2021-10-22 18:12:41 +08:00
parent 3de6eb1ada
commit dd2630c4fb
26 changed files with 576 additions and 391 deletions

View File

@ -36,7 +36,7 @@ ZipMaker::ZipMaker() :
m_zDoc(NULL)
{
m_error[0] = 0;
m_opt_compress_level = Z_DEFAULT_COMPRESSION;
m_opt_compress_level = Z_BEST_SPEED;
m_zi = NULL;
}

View File

@ -0,0 +1,53 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2015 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 "applicationpardlg.h"
#include "dsdialog.h"
namespace pv
{
namespace dialogs
{
ApplicationParamDlg::ApplicationParamDlg()
{
m_ret = false;
}
ApplicationParamDlg::~ApplicationParamDlg()
{
}
bool ApplicationParamDlg::ShowDlg(QWidget *parent)
{
DSDialog dlg(parent, true, true);
dlg.exec();
return m_ret;
}
//------------IDlgCallback
void ApplicationParamDlg::OnDlgResult(bool bYes){
m_ret = bYes;
}
} //
}//

View File

@ -0,0 +1,52 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2015 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
*/
#pragma once
#include <QObject>
#include <QWidget>
#include "../interface/uicallback.h"
namespace pv
{
namespace dialogs
{
class ApplicationParamDlg : private IDlgCallback
{
// Q_OBJECT
public:
ApplicationParamDlg();
~ApplicationParamDlg();
bool ShowDlg(QWidget *parent);
//IDlgCallback
private:
void OnDlgResult(bool bYes);
private:
bool m_ret;
};
}//
}//

View File

@ -40,8 +40,7 @@ namespace dialogs {
DeviceOptions::DeviceOptions(QWidget *parent, boost::shared_ptr<pv::device::DevInst> dev_inst) :
DSDialog(parent),
_dev_inst(dev_inst),
_button_box(QDialogButtonBox::Ok,
Qt::Horizontal, this),
_button_box(QDialogButtonBox::Ok, Qt::Horizontal, this),
_device_options_binding(_dev_inst->dev_inst())
{
_props_box = new QGroupBox(tr("Mode"), this);

View File

@ -28,118 +28,121 @@
#include <QMouseEvent>
#include <QVBoxLayout>
#include <QAbstractButton>
#include "../dsvdef.h"
namespace pv {
namespace dialogs {
DSDialog::DSDialog(QWidget *parent, bool hasClose) :
QDialog(parent),
_moving(false)
DSDialog::DSDialog() : DSDialog(NULL, false, false)
{
}
DSDialog::DSDialog(QWidget *parent): DSDialog(parent, false, false)
{
}
DSDialog::DSDialog(QWidget *parent, bool hasClose): DSDialog(parent, hasClose, false)
{
}
DSDialog::DSDialog(QWidget *parent, bool hasClose, bool bBaseButton) :
QDialog(NULL), //must be null, otherwise window can not able to move
m_bBaseButton(bBaseButton)
{
(void)parent;
_base_layout = NULL;
_main_layout = NULL;
_main_widget = NULL;
_titlebar = NULL;
_shadow = NULL;
_base_button = NULL;
m_callback = NULL;
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
setAttribute(Qt::WA_TranslucentBackground);
build_main(hasClose);
build_base(hasClose);
}
_layout = new QVBoxLayout(this);
_layout->addWidget(_main);
setLayout(_layout);
DSDialog::~DSDialog()
{
DESTROY_QT_OBJECT(_base_layout);
DESTROY_QT_OBJECT(_main_layout);
DESTROY_QT_OBJECT(_main_widget);
DESTROY_QT_OBJECT(_titlebar);
DESTROY_QT_OBJECT(_shadow);
DESTROY_QT_OBJECT(_base_button);
}
void DSDialog::accept()
{
using namespace Qt;
if (m_callback){
m_callback->OnDlgResult(true);
}
QDialog::accept();
}
void DSDialog::reject()
{
using namespace Qt;
if (m_callback){
m_callback->OnDlgResult(false);
}
QDialog::reject();
}
bool DSDialog::eventFilter(QObject *object, QEvent *event)
{
(void)object;
const QEvent::Type type = event->type();
const QMouseEvent *const mouse_event = (QMouseEvent*)event;
if (type == QEvent::MouseMove) {
if (_moving && mouse_event->buttons().testFlag(Qt::LeftButton)) {
move(mouse_event->globalPos() - _startPos);
}
return true;
} else if (type == QEvent::MouseButtonPress) {
if (mouse_event->buttons().testFlag(Qt::LeftButton)) {
_moving = true;
#ifndef _WIN32
_startPos = mouse_event->pos() +
QPoint(_layout->margin(), _layout->margin()) +
QPoint(_layout->spacing(), _layout->spacing()) +
QPoint(_mlayout->margin(), _mlayout->margin()) +
QPoint(_mlayout->spacing(), _mlayout->spacing());
#else
_startPos = mouse_event->pos() +
QPoint(_layout->margin(), _layout->margin()) +
QPoint(_layout->spacing(), _layout->spacing());
#endif
}
} else if (type == QEvent::MouseButtonRelease) {
if (mouse_event->buttons().testFlag(Qt::LeftButton)) {
_moving = false;
}
}
return false;
}
QVBoxLayout* DSDialog::layout()
{
return _mlayout;
}
QWidget* DSDialog::mainWidget()
{
return _main;
}
void DSDialog::setTitle(QString title)
{
_titlebar->setTitle(title);
if (_titlebar){
_titlebar->setTitle(title);
}
}
void DSDialog::reload(bool hasClose)
void DSDialog::reload()
{
QString title;
if (_titlebar)
title = _titlebar->title();
if (_main)
delete _main;
build_main(hasClose);
_titlebar->setTitle(title);
_layout->addWidget(_main);
show();
}
void DSDialog::build_main(bool hasClose)
{
_main = new QWidget(this);
_mlayout = new QVBoxLayout(_main);
_main->setLayout(_mlayout);
//_mlayout->setMargin(5);
//_mlayout->setSpacing(5);
int DSDialog::exec()
{
//ok,cancel
if (m_bBaseButton){
_base_button = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,Qt::Horizontal, this);
_main_layout->addWidget(_base_button);//, 5, 1, 1, 1, Qt::AlignHCenter | Qt::AlignBottom);
connect(_base_button, SIGNAL(rejected()), this, SLOT(reject()));
connect(_base_button, SIGNAL(accepted()), this, SLOT(accept()));
}
return QDialog::exec();
}
Shadow *bodyShadow = new Shadow(_main);
bodyShadow->setBlurRadius(10.0);
bodyShadow->setDistance(3.0);
bodyShadow->setColor(QColor(0, 0, 0, 80));
_main->setAutoFillBackground(true);
_main->setGraphicsEffect(bodyShadow);
void DSDialog::build_base(bool hasClose)
{
_main_widget = new QWidget(this);
_main_layout = new QVBoxLayout(_main_widget);
_titlebar = new toolbars::TitleBar(false, this, hasClose);
_titlebar->installEventFilter(this);
_mlayout->addWidget(_titlebar);
}
_base_layout = new QVBoxLayout(this);
_main_widget->setLayout(_main_layout);
_main_widget->setAutoFillBackground(true);
_shadow = new Shadow(_main_widget);
_shadow->setBlurRadius(10.0);
_shadow->setDistance(3.0);
_shadow->setColor(QColor(0, 0, 0, 80));
_main_widget->setGraphicsEffect(_shadow);
_main_layout->addWidget(_titlebar);
_base_layout->addWidget(_main_widget);
setLayout(_base_layout);
}
} // namespace dialogs
} // namespace pv

View File

@ -26,40 +26,56 @@
#include <QDialog>
#include <QWidget>
#include <QVBoxLayout>
#include <QDialogButtonBox>
#include "../toolbars/titlebar.h"
#include "../interface/uicallback.h"
class QDialogButtonBox;
namespace pv {
namespace dialogs {
class Shadow;
//DSView any dialog base class
class DSDialog : public QDialog
{
Q_OBJECT
public:
DSDialog(QWidget *parent = 0, bool hasClose = false);
QVBoxLayout *layout();
QWidget *mainWidget();
DSDialog();
DSDialog(QWidget *parent);
DSDialog(QWidget *parent, bool hasClose);
DSDialog(QWidget *parent, bool hasClose, bool bBaseButton);
~DSDialog();
inline void SetCallback(IDlgCallback *callback){m_callback = callback;}
inline QVBoxLayout *layout(){return _main_layout;}
void setTitle(QString title);
void reload(bool hasClose);
void reload();
int exec();
protected:
void accept();
void reject();
//void mousePressEvent(QMouseEvent *event);
//void mouseReleaseEvent(QMouseEvent *event);
bool eventFilter(QObject *object, QEvent *event);
private:
void build_main(bool hasClose);
private:
QVBoxLayout *_layout;
QVBoxLayout *_mlayout;
QWidget *_main;
toolbars::TitleBar *_titlebar;
bool _moving;
QPoint _startPos;
void build_base(bool hasClose);
private:
QVBoxLayout *_base_layout;
QWidget *_main_widget;
QVBoxLayout *_main_layout;
toolbars::TitleBar *_titlebar;
Shadow *_shadow;
QDialogButtonBox *_base_button;
QPoint _startPos;
bool m_bBaseButton;
IDlgCallback *m_callback;
};
} // namespace dialogs

View File

@ -28,32 +28,42 @@
#include <QMouseEvent>
#include <QVBoxLayout>
#include <QAbstractButton>
#include "../dsvdef.h"
namespace pv {
namespace dialogs {
DSMessageBox::DSMessageBox(QWidget *parent,const char *title) :
QDialog(parent),
_moving(false),
_clickType(0)
QDialog(NULL) //must be null, otherwise window can not able to move
{
_layout = NULL;
_main_widget = NULL;
_msg = NULL;
_titlebar = NULL;
_shadow = NULL;
_main_layout = NULL;
_bClickYes = false;
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
setAttribute(Qt::WA_TranslucentBackground);
_main = new QWidget(this);
QVBoxLayout *mlayout = new QVBoxLayout(_main);
_main->setLayout(mlayout);
Shadow *bodyShadow = new Shadow();
bodyShadow->setBlurRadius(10.0);
bodyShadow->setDistance(3.0);
bodyShadow->setColor(QColor(0, 0, 0, 80));
_main->setAutoFillBackground(true);
_main->setGraphicsEffect(bodyShadow);
_main_widget = new QWidget(this);
_main_layout = new QVBoxLayout(_main_widget);
_main_widget->setLayout(_main_layout);
_shadow = new Shadow();
_msg = new QMessageBox(this);
_msg->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
_titlebar = new toolbars::TitleBar(false, this);
_layout = new QVBoxLayout(this);
_shadow->setBlurRadius(10.0);
_shadow->setDistance(3.0);
_shadow->setColor(QColor(0, 0, 0, 80));
_main_widget->setAutoFillBackground(true);
_main_widget->setGraphicsEffect(_shadow);
_msg->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
if (title){
_titlebar->setTitle(QString(title));
@ -61,20 +71,27 @@ DSMessageBox::DSMessageBox(QWidget *parent,const char *title) :
else{
_titlebar->setTitle(tr("Message"));
}
_titlebar->installEventFilter(this);
_main_layout->addWidget(_titlebar);
_main_layout->addWidget(_msg);
_layout->addWidget(_main_widget);
mlayout->addWidget(_titlebar);
mlayout->addWidget(_msg);
_layout = new QVBoxLayout(this);
_layout->addWidget(_main);
setLayout(_layout);
//connect(_msg, SIGNAL(finished(int)), this, SLOT(accept()));
connect(_msg, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(on_button(QAbstractButton*)));
}
DSMessageBox::~DSMessageBox()
{
DESTROY_QT_OBJECT(_layout);
DESTROY_QT_OBJECT(_main_widget);
DESTROY_QT_OBJECT(_msg);
DESTROY_QT_OBJECT(_titlebar);
DESTROY_QT_OBJECT(_shadow);
DESTROY_QT_OBJECT(_main_layout);
}
void DSMessageBox::accept()
{
using namespace Qt;
@ -88,50 +105,20 @@ void DSMessageBox::reject()
QDialog::reject();
}
bool DSMessageBox::eventFilter(QObject *object, QEvent *event)
{
(void)object;
const QEvent::Type type = event->type();
const QMouseEvent *const mouse_event = (QMouseEvent*)event;
if (type == QEvent::MouseMove) {
if (_moving && mouse_event->buttons().testFlag(Qt::LeftButton)) {
move(mouse_event->globalPos() - _startPos);
}
return true;
} else if (type == QEvent::MouseButtonPress) {
if (mouse_event->buttons().testFlag(Qt::LeftButton)) {
_moving = true;
_startPos = mouse_event->pos() +
QPoint(_layout->margin(), _layout->margin()) +
QPoint(_layout->spacing(), _layout->spacing());
}
} else if (type == QEvent::MouseButtonRelease) {
if (mouse_event->buttons().testFlag(Qt::LeftButton)) {
_moving = false;
}
}
return false;
}
QMessageBox* DSMessageBox::mBox()
{
return _msg;
}
int DSMessageBox::exec()
{
//_msg->show();
return QDialog::exec();
}
void DSMessageBox::on_button(QAbstractButton *btn)
{
QMessageBox::ButtonRole role = _msg->buttonRole(btn);
_clickType = (int)role;
if (role == QMessageBox::AcceptRole)
accept();
if (role == QMessageBox::AcceptRole || role == QMessageBox::YesRole){
_bClickYes = true;
accept();
}
else
reject();
}

View File

@ -33,6 +33,8 @@
namespace pv {
namespace dialogs {
class Shadow;
class DSMessageBox : public QDialog
{
Q_OBJECT
@ -40,30 +42,29 @@ class DSMessageBox : public QDialog
public:
DSMessageBox(QWidget *parent, const char *title=0);
QMessageBox *mBox();
~DSMessageBox();
int exec();
QMessageBox *mBox();
inline int GetLastClick(){return _clickType;}
inline int IsYes(){return _bClickYes;}
protected:
void accept();
void reject();
//void mousePressEvent(QMouseEvent *event);
//void mouseReleaseEvent(QMouseEvent *event);
bool eventFilter(QObject *object, QEvent *event);
void reject();
private slots:
void on_button(QAbstractButton* btn);
private:
QVBoxLayout *_layout;
QWidget *_main;
QMessageBox *_msg;
toolbars::TitleBar *_titlebar;
bool _moving;
QPoint _startPos;
int _clickType;
QVBoxLayout *_layout;
QVBoxLayout *_main_layout;
QWidget *_main_widget;
QMessageBox *_msg;
toolbars::TitleBar *_titlebar;
Shadow *_shadow;
QPoint _startPos;
bool _bClickYes;
};
} // namespace dialogs

View File

@ -210,10 +210,10 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession &sessio
ProtocolDock::~ProtocolDock()
{
//destroy protocol item layers
for (auto it = _protocolItems.begin(); it != _protocolItems.end(); it++){
delete (*it);
for (auto it = _protocol_items.begin(); it != _protocol_items.end(); it++){
DESTROY_QT_LATER(*it);
}
_protocolItems.clear();
_protocol_items.clear();
}
void ProtocolDock::changeEvent(QEvent *event)
@ -245,7 +245,7 @@ void ProtocolDock::reStyle()
_nxt_button->setIcon(QIcon(iconPath+"/next.svg"));
_search_button->setIcon(QIcon(iconPath+"/search.svg"));
for (auto it = _protocolItems.begin(); it != _protocolItems.end(); it++){
for (auto it = _protocol_items.begin(); it != _protocol_items.end(); it++){
(*it)->ResetStyle();
}
}
@ -321,8 +321,8 @@ void ProtocolDock::add_protocol(bool silent)
//crate item layer
QString protocolName = _protocol_combobox->currentText();
ProtocolItemLayer *layer = new ProtocolItemLayer(_up_widget, protocolName, this);
_protocolItems.push_back(layer);
_up_layout->insertLayout(_protocolItems.size(), layer);
_protocol_items.push_back(layer);
_up_layout->insertLayout(_protocol_items.size(), layer);
layer->m_decoderStatus = dstatus;
//set current protocol format
@ -342,7 +342,7 @@ void ProtocolDock::add_protocol(bool silent)
}
void ProtocolDock::on_del_all_protocol(){
if (_protocolItems.size() == 0){
if (_protocol_items.size() == 0){
MsgBox::Show(NULL, "No Protocol Analyzer to delete!", this);
return;
}
@ -355,15 +355,14 @@ void ProtocolDock::add_protocol(bool silent)
void ProtocolDock::del_all_protocol()
{
if (_protocolItems.size() > 0)
if (_protocol_items.size() > 0)
{
for (auto it = _protocolItems.begin(); it != _protocolItems.end(); it++)
for (auto it = _protocol_items.begin(); it != _protocol_items.end(); it++)
{
_up_layout->removeItem((*it));
delete (*it); //destory control
DESTROY_QT_LATER((*it)); //destory control
_session.remove_decode_signal(0);
}
_protocolItems.clear();
_protocol_items.clear();
protocol_updated();
}
}
@ -383,9 +382,9 @@ void ProtocolDock::decoded_progress(int progress)
if (d->decoder()->out_of_memory())
err = tr("(Out of Memory)");
if (index < _protocolItems.size())
if (index < _protocol_items.size())
{
ProtocolItemLayer &lay = *(_protocolItems.at(index));
ProtocolItemLayer &lay = *(_protocol_items.at(index));
lay.SetProgress(pg, err);
//when decode complete, check data format
@ -745,7 +744,7 @@ void ProtocolDock::search_update()
//-------------------IProtocolItemLayerCallback
void ProtocolDock::OnProtocolSetting(void *handle){
int dex = 0;
for (auto it = _protocolItems.begin(); it != _protocolItems.end(); it++){
for (auto it = _protocol_items.begin(); it != _protocol_items.end(); it++){
if ((*it) == handle){
_session.rst_decoder(dex);
protocol_updated();
@ -761,13 +760,12 @@ void ProtocolDock::OnProtocolDelete(void *handle){
}
int dex = 0;
for (auto it = _protocolItems.begin(); it != _protocolItems.end(); it++){
for (auto it = _protocol_items.begin(); it != _protocol_items.end(); it++){
if ((*it) == handle){
delete (*it);
_up_layout->removeItem((*it)); //remove child control
_protocolItems.remove(dex);
DESTROY_QT_LATER(*it);
_protocol_items.remove(dex);
_session.remove_decode_signal(dex);
protocol_updated();
protocol_updated();
break;
}
dex++;
@ -775,7 +773,7 @@ void ProtocolDock::OnProtocolDelete(void *handle){
}
void ProtocolDock::OnProtocolFormatChanged(QString format, void *handle){
for (auto it = _protocolItems.begin(); it != _protocolItems.end(); it++){
for (auto it = _protocol_items.begin(); it != _protocol_items.end(); it++){
if ((*it) == handle){
QString &name = (*it)->GetProtocolName();
AppConfig::Instance().SetProtocolFormat(name.toStdString(), format.toStdString());

View File

@ -133,7 +133,7 @@ private:
QComboBox *_protocol_combobox;
QVector <int > _protocol_index_list;
QVBoxLayout *_up_layout;
QVector <ProtocolItemLayer*> _protocolItems; //protocol item layers
QVector <ProtocolItemLayer*> _protocol_items; //protocol item layers
QPushButton *_dn_set_button;
QPushButton *_dn_save_button;

View File

@ -22,11 +22,11 @@
#include "protocolitemlayer.h"
#include "../dsvdef.h"
#include <QtCore>
#include <assert.h>
#include <assert.h>
namespace pv {
namespace dock {
ProtocolItemLayer::ProtocolItemLayer(QWidget *parent, QString protocolName, IProtocolItemLayerCallback *callback){
assert(parent);
assert(callback);
@ -58,7 +58,7 @@ ProtocolItemLayer::ProtocolItemLayer(QWidget *parent, QString protocolName, IPro
hori_layout->addWidget(_del_button);
hori_layout->addWidget(_format_combox);
hori_layout->addWidget(_protocol_label);
hori_layout->addWidget(_progress_label);
hori_layout->addWidget(_progress_label);
hori_layout->addStretch(1);
@ -69,13 +69,14 @@ ProtocolItemLayer::ProtocolItemLayer(QWidget *parent, QString protocolName, IPro
connect(_format_combox, SIGNAL(currentIndexChanged(int)),this, SLOT(on_format_select_changed(int)));
}
ProtocolItemLayer::~ProtocolItemLayer(){
DESTROY_OBJECT(_set_button);
DESTROY_OBJECT(_del_button);
DESTROY_OBJECT(_protocol_label);
DESTROY_OBJECT(_progress_label);
DESTROY_OBJECT(_format_combox);
ProtocolItemLayer::~ProtocolItemLayer(){
DESTROY_QT_OBJECT(_progress_label);
DESTROY_QT_OBJECT(_protocol_label);
DESTROY_QT_OBJECT(_set_button);
DESTROY_QT_OBJECT(_del_button);
DESTROY_QT_OBJECT(_format_combox);
}
//-------------control event
void ProtocolItemLayer::on_set_protocol()

View File

@ -54,7 +54,7 @@ public:
void LoadFormatSelect(bool bSingle);
inline QString &GetProtocolName(){return _protocolName;}
void SetProtocolFormat(const char *format);
private slots:
void on_set_protocol();
void on_del_protocol();

View File

@ -44,3 +44,24 @@ namespace DecoderDataFormat
return (int)ascii;
}
}
namespace app
{
QWidget* get_app_window_instance(QWidget *ins, bool bSet){
static QWidget *g_ins = NULL;
if (bSet){
g_ins = ins;
}
return g_ins;
}
bool is_app_top_window(QWidget* w){
QWidget *top =get_app_window_instance(NULL, NULL);
if (top && top == w){
return true;
}
return false;
}
}

View File

@ -21,8 +21,12 @@
*/
#pragma once
#define DESTROY_OBJECT(p) if ((p)){delete (p); p = NULL;}
class QWidget;
#define DESTROY_OBJECT(p) if((p)){delete (p); p = NULL;}
#define DESTROY_QT_OBJECT(p) if((p)){((p))->deleteLater(); p = NULL;}
#define DESTROY_QT_LATER(p) ((p))->deleteLater();
namespace DecoderDataFormat
{
@ -37,3 +41,10 @@ namespace DecoderDataFormat
int Parse(const char *name);
}
namespace app
{
QWidget* get_app_window_instance(QWidget *ins, bool bSet);
bool is_app_top_window(QWidget* w);
}

View File

@ -0,0 +1,8 @@
#pragma once
class IDlgCallback
{
public:
virtual void OnDlgResult(bool bYes)=0;
};

View File

@ -42,6 +42,7 @@
#include <QMessageBox>
#include <QApplication>
#include <QScreen>
#include "dsvdef.h"
#include <algorithm>
@ -68,15 +69,15 @@ MainFrame::MainFrame(DeviceManager &device_manager,
QSize(), QIcon::Normal, QIcon::Off);
setWindowIcon(icon);
_moving = false;
_draging = false;
_startPos = None;
app::get_app_window_instance(this, true);
_bDraging = false;
_hit_border = None;
_freezing = false;
_minimized = false;
// Title
_titleBar = new toolbars::TitleBar(true, this);
_titleBar->installEventFilter(this);
// MainWindow
_mainWindow = new MainWindow(device_manager, open_file_name, this);
@ -223,41 +224,55 @@ bool MainFrame::eventFilter(QObject *object, QEvent *event)
int newLeft;
int newTop;
if (type == QEvent::MouseMove && !isMaximized()) {
if (!(mouse_event->buttons() || Qt::NoButton)) {
if (object == _top_left) {
_startPos = TopLeft;
if (type != QEvent::MouseMove
&& type != QEvent::MouseButtonPress
&& type != QEvent::MouseButtonRelease
&& type != QEvent::Leave){
return QFrame::eventFilter(object, event);
}
//when window is maximized, or is moving, call return
if (isMaximized() || _titleBar->IsMoving()){
return QFrame::eventFilter(object, event);
}
if (!_bDraging && type == QEvent::MouseMove && (!(mouse_event->buttons() || Qt::NoButton))){
if (object == _top_left) {
_hit_border = TopLeft;
setCursor(Qt::SizeFDiagCursor);
} else if (object == _bottom_right) {
_startPos = BottomRight;
_hit_border = BottomRight;
setCursor(Qt::SizeFDiagCursor);
} else if (object == _top_right) {
_startPos = TopRight;
_hit_border = TopRight;
setCursor(Qt::SizeBDiagCursor);
} else if (object == _bottom_left) {
_startPos = BottomLeft;
_hit_border = BottomLeft;
setCursor(Qt::SizeBDiagCursor);
} else if (object == _left) {
_startPos = Left;
_hit_border = Left;
setCursor(Qt::SizeHorCursor);
} else if (object == _right) {
_startPos = Right;
_hit_border = Right;
setCursor(Qt::SizeHorCursor);
} else if (object == _bottom) {
_startPos = Bottom;
_hit_border = Bottom;
setCursor(Qt::SizeVerCursor);
} else if (object == _top) {
_startPos = Top;
_hit_border = Top;
setCursor(Qt::SizeVerCursor);
} else {
_startPos = None;
_hit_border = None;
setCursor(Qt::ArrowCursor);
}
} else if(mouse_event->buttons().testFlag(Qt::LeftButton)) {
if (_moving) {
this->move(mouse_event->globalPos() - _lastMousePosition);
} else if (!_freezing) {
switch (_startPos) {
return QFrame::eventFilter(object, event);
}
if (type == QEvent::MouseMove) {
if(mouse_event->buttons().testFlag(Qt::LeftButton)) {
if (!_freezing) {
switch (_hit_border) {
case TopLeft:
newWidth = std::max(_dragStartGeometry.right() - mouse_event->globalX(), minimumWidth());
newHeight = std::max(_dragStartGeometry.bottom() - mouse_event->globalY(), minimumHeight());
@ -325,31 +340,27 @@ bool MainFrame::eventFilter(QObject *object, QEvent *event)
}
return true;
}
} else if (type == QEvent::MouseButtonPress) {
if (mouse_event->button() == Qt::LeftButton)
if (_titleBar->rect().contains(mouse_event->pos()) &&
_startPos == None) {
_moving = true;
_lastMousePosition = mouse_event->pos() +
//QPoint(Margin, Margin) +
QPoint(geometry().left() - frameGeometry().left(), frameGeometry().right() - geometry().right());
}
if (_startPos != None)
_draging = true;
}
else if (type == QEvent::MouseButtonPress) {
if (mouse_event->button() == Qt::LeftButton)
if (_hit_border != None)
_bDraging = true;
_timer.start(50);
_dragStartGeometry = geometry();
} else if (type == QEvent::MouseButtonRelease) {
}
else if (type == QEvent::MouseButtonRelease) {
if (mouse_event->button() == Qt::LeftButton) {
_moving = false;
_draging = false;
_bDraging = false;
_timer.stop();
}
} else if (!_draging && type == QEvent::Leave) {
_startPos = None;
} else if (!_bDraging && type == QEvent::Leave) {
_hit_border = None;
setCursor(Qt::ArrowCursor);
}
return QObject::eventFilter(object, event);
}
return QFrame::eventFilter(object, event);
}
void MainFrame::writeSettings()
@ -406,7 +417,7 @@ void MainFrame::show_doc()
const QString DOC_KEY("ShowDocuments");
QSettings settings(QApplication::organizationName(), QApplication::applicationName());
if (!settings.contains(DOC_KEY)) {
dialogs::DSDialog dlg(this);
dialogs::DSDialog dlg(this, true);
dlg.setTitle(tr("Document"));
QLabel tipsLabel;

View File

@ -104,15 +104,13 @@ private:
widgets::Border *_top_right;
widgets::Border *_bottom_left;
widgets::Border *_bottom_right;
bool _moving;
bool _draging;
QPoint _lastMousePosition;
QRect _dragStartGeometry;
int _startPos;
QTimer _timer;
bool _freezing;
bool _minimized;
bool _bDraging;
QRect _dragStartGeometry;
int _hit_border;
QTimer _timer;
bool _freezing;
bool _minimized;
};
} // namespace pv

View File

@ -28,8 +28,8 @@
#include <QApplication>
#include "filebar.h"
#include "../device/devinst.h"
#include "../dialogs/dsmessagebox.h"
#include "../device/devinst.h"
#include "../ui/msgbox.h"
#include <deque>
@ -107,7 +107,7 @@ void FileBar::changeEvent(QEvent *event)
void FileBar::retranslateUi()
{
_file_button.setText(tr("File"));
_menu_session->setTitle(tr("Settings"));
_menu_session->setTitle(tr("Con&fig..."));
_action_load->setText(tr("&Load..."));
_action_store->setText(tr("S&tore..."));
_action_default->setText(tr("&Default..."));
@ -157,13 +157,8 @@ void FileBar::session_error(
void FileBar::show_session_error(
const QString text, const QString info_text)
{
dialogs::DSMessageBox msg(this);
msg.mBox()->setText(text);
msg.mBox()->setInformativeText(info_text);
msg.mBox()->setStandardButtons(QMessageBox::Ok);
msg.mBox()->setIcon(QMessageBox::Warning);
msg.exec();
{
MsgBox::Show(NULL, info_text.toStdString().c_str(), this);
}
void FileBar::on_actionLoad_triggered()
@ -189,14 +184,9 @@ void FileBar::on_actionDefault_triggered()
QDir dir(QCoreApplication::applicationDirPath());
assert(dir.cd("res"));
#endif
if (!dir.exists()) {
dialogs::DSMessageBox msg(this);
msg.mBox()->setText(tr("Session Load"));
msg.mBox()->setInformativeText(tr("Cannot find default session file for this device!"));
msg.mBox()->setStandardButtons(QMessageBox::Ok);
msg.mBox()->setIcon(QMessageBox::Warning);
msg.exec();
return;
if (!dir.exists()) {
MsgBox::Show(NULL, "Cannot find default session file for this device!", this);
return;
}
QString driver_name = _session.get_device()->name();

View File

@ -30,24 +30,35 @@
#include <QApplication>
#include <QPainter>
#include <QStyleOption>
#include <assert.h>
#include "../dsvdef.h"
namespace pv {
namespace toolbars {
TitleBar::TitleBar(bool top, QWidget *parent, bool hasClose) :
QWidget(parent),
_parent(parent),
_moving(false),
_isTop(top),
_hasClose(hasClose)
{
_title = NULL;
_minimizeButton = NULL;
_maximizeButton = NULL;
_closeButton = NULL;
_lay = NULL;
assert(parent);
setObjectName("TitleBar");
setContentsMargins(0,0,0,0);
setFixedHeight(32);
_title = new QLabel(this);
QHBoxLayout *hbox = new QHBoxLayout(this);
hbox->addWidget(_title);
_lay = new QHBoxLayout(this);
_lay->addWidget(_title);
if (_isTop) {
_minimizeButton = new QToolButton(this);
@ -55,8 +66,8 @@ TitleBar::TitleBar(bool top, QWidget *parent, bool hasClose) :
_maximizeButton = new QToolButton(this);
_maximizeButton->setObjectName("MaximizeButton");
hbox->addWidget(_minimizeButton);
hbox->addWidget(_maximizeButton);
_lay->addWidget(_minimizeButton);
_lay->addWidget(_maximizeButton);
connect(this, SIGNAL( normalShow() ), parent, SLOT(showNormal() ) );
connect(this, SIGNAL( maximizedShow() ), parent, SLOT(showMaximized() ) );
@ -67,17 +78,26 @@ TitleBar::TitleBar(bool top, QWidget *parent, bool hasClose) :
if (_isTop || _hasClose) {
_closeButton= new QToolButton(this);
_closeButton->setObjectName("CloseButton");
hbox->addWidget(_closeButton);
_lay->addWidget(_closeButton);
connect(_closeButton, SIGNAL( clicked() ), parent, SLOT(close() ) );
}
hbox->insertStretch(0, 500);
hbox->insertStretch(2, 500);
hbox->setMargin(0);
hbox->setSpacing(0);
_lay->insertStretch(0, 500);
_lay->insertStretch(2, 500);
_lay->setMargin(0);
_lay->setSpacing(0);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
}
TitleBar::~TitleBar(){
DESTROY_QT_OBJECT(_title);
DESTROY_QT_OBJECT(_minimizeButton);
DESTROY_QT_OBJECT(_maximizeButton);
DESTROY_QT_OBJECT(_closeButton);
DESTROY_QT_OBJECT(_lay);
}
void TitleBar::changeEvent(QEvent *event)
{
if (event->type() == QEvent::StyleChange)
@ -101,7 +121,8 @@ void TitleBar::reStyle()
}
void TitleBar::paintEvent(QPaintEvent *event)
{
{
//draw logo icon
QStyleOption o;
o.initFrom(this);
QPainter p(this);
@ -109,7 +130,6 @@ void TitleBar::paintEvent(QPaintEvent *event)
p.setRenderHint(QPainter::Antialiasing, true);
//To draw product logo
const int xgap = 2;
const int xstart = 10;
p.setPen(QPen(QColor(213, 15, 37, 255), 2, Qt::SolidLine));
@ -139,12 +159,7 @@ void TitleBar::setTitle(QString title)
{
_title->setText(title);
}
QPoint TitleBar::get_startPos() const
{
return _startPos;
}
QString TitleBar::title() const
{
return _title->text();
@ -171,35 +186,49 @@ void TitleBar::setRestoreButton(bool max)
_maximizeButton->setIcon(QIcon(iconPath+"/restore.svg"));
}
}
void TitleBar::mousePressEvent(QMouseEvent* event)
{
{
if(event->button() == Qt::LeftButton && !parentWidget()->isMaximized()) {
_moving = true;
_startPos = mapToParent(event->pos());
}
int x = event->pos().x();
int y = event->pos().y();
bool bTopWidow = app::is_app_top_window(_parent);
bool bClick = (x >= 6 && y >= 5 && x <= width() - 6); //top window need resize hit check
if (!bTopWidow || bClick ){
_moving = true;
_startPos = event->globalPos() - _parent->frameGeometry().topLeft();
event->accept();
return;
}
}
QWidget::mousePressEvent(event);
}
void TitleBar::mouseMoveEvent(QMouseEvent *event)
{
if(_moving && event->buttons().testFlag(Qt::LeftButton)) {
parentWidget()->move(event->globalPos() - _startPos);
}
{
if(_moving){
_parent->move(event->globalPos() - _startPos);
event->accept();
return;
}
QWidget::mouseMoveEvent(event);
}
void TitleBar::mouseReleaseEvent(QMouseEvent* event)
{
if(event->button() == Qt::LeftButton) {
_moving = false;
}
_moving = false;
QWidget::mouseReleaseEvent(event);
}
void TitleBar::mouseDoubleClickEvent(QMouseEvent *event)
{
if (_isTop)
showMaxRestore();
if (_isTop){
showMaxRestore();
}
QWidget::mouseDoubleClickEvent(event);
}
} // namespace toolbars
} // namespace pv

View File

@ -25,56 +25,56 @@
#include <QWidget>
class QLabel;
class QToolButton;
class QHBoxLayout;
namespace pv
namespace pv {
namespace toolbars {
class TitleBar : public QWidget
{
namespace toolbars
{
Q_OBJECT
//Window's titlebar, referenced by MainFrame,
//The title area above the main screen,
//Display logo and maximize \ minimize button
class TitleBar : public QWidget
{
Q_OBJECT
public:
TitleBar(bool top, QWidget *parent, bool hasClose = false);
~TitleBar();
void setTitle(QString title);
QString title() const;
public:
TitleBar(bool top, QWidget *parent, bool hasClose = false);
void setTitle(QString title);
QPoint get_startPos() const;
QString title() const;
private:
void changeEvent(QEvent *event);
void reStyle();
private:
void changeEvent(QEvent *event);
void reStyle();
signals:
void normalShow();
void maximizedShow();
signals:
void normalShow();
void maximizedShow();
public slots:
void showMaxRestore();
void setRestoreButton(bool max);
inline bool IsMoving(){return _moving;}
public slots:
void showMaxRestore();
void setRestoreButton(bool max);
protected:
void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseDoubleClickEvent(QMouseEvent *event);
QLabel *_title;
QToolButton *_minimizeButton;
QToolButton *_maximizeButton;
QToolButton *_closeButton;
QHBoxLayout *_lay;
protected:
void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseDoubleClickEvent(QMouseEvent *event);
bool _moving;
bool _isTop;
bool _hasClose;
QPoint _startPos;
QWidget *_parent;
};
QLabel *_title;
QToolButton *_minimizeButton;
QToolButton *_maximizeButton;
QToolButton *_closeButton;
bool _moving;
bool _isTop;
bool _hasClose;
QPoint _startPos;
};
} // namespace toolbars
} // namespace toolbars
} // namespace pv
#endif // DSVIEW_PV_TOOLBARS_TITLEBAR_H

View File

@ -30,6 +30,7 @@
#include <QApplication>
#include <QBitmap>
#include <QPainter>
#include "../dialogs/applicationpardlg.h"
namespace pv {
namespace toolbars {
@ -50,16 +51,7 @@ TrigBar::TrigBar(SigSession &session, QWidget *parent) :
{
setMovable(false);
setContentsMargins(0,0,0,0);
connect(&_trig_button, SIGNAL(clicked()),
this, SLOT(trigger_clicked()));
connect(&_protocol_button, SIGNAL(clicked()),
this, SLOT(protocol_clicked()));
connect(&_measure_button, SIGNAL(clicked()),
this, SLOT(measure_clicked()));
connect(&_search_button, SIGNAL(clicked()),
this, SLOT(search_clicked()));
_trig_button.setCheckable(true);
#ifdef ENABLE_DECODE
_protocol_button.setCheckable(true);
@ -69,12 +61,10 @@ TrigBar::TrigBar(SigSession &session, QWidget *parent) :
_action_fft = new QAction(this);
_action_fft->setObjectName(QString::fromUtf8("actionFft"));
connect(_action_fft, SIGNAL(triggered()), this, SLOT(on_actionFft_triggered()));
_action_math = new QAction(this);
_action_math->setObjectName(QString::fromUtf8("actionMath"));
connect(_action_math, SIGNAL(triggered()), this, SLOT(on_actionMath_triggered()));
_function_menu = new QMenu(this);
_function_menu->setContentsMargins(0,0,0,0);
_function_menu->addAction(_action_fft);
@ -84,25 +74,27 @@ TrigBar::TrigBar(SigSession &session, QWidget *parent) :
_action_lissajous = new QAction(this);
_action_lissajous->setObjectName(QString::fromUtf8("actionLissajous"));
connect(_action_lissajous, SIGNAL(triggered()), this, SLOT(on_actionLissajous_triggered()));
_dark_style = new QAction(this);
_dark_style->setObjectName(QString::fromUtf8("actionDark"));
connect(_dark_style, SIGNAL(triggered()), this, SLOT(on_actionDark_triggered()));
_light_style = new QAction(this);
_light_style->setObjectName(QString::fromUtf8("actionLight"));
connect(_light_style, SIGNAL(triggered()), this, SLOT(on_actionLight_triggered()));
_themes = new QMenu(this);
_themes->setObjectName(QString::fromUtf8("menuThemes"));
_themes->addAction(_light_style);
_themes->addAction(_dark_style);
_appParam_action = new QAction(this);
_display_menu = new QMenu(this);
_display_menu->setContentsMargins(0,0,0,0);
_display_menu->addAction(_appParam_action);
_display_menu->addAction(_action_lissajous);
_display_menu->addMenu(_themes);
_display_menu->addAction(_action_lissajous);
_display_button.setPopupMode(QToolButton::InstantPopup);
_display_button.setMenu(_display_menu);
@ -119,10 +111,22 @@ TrigBar::TrigBar(SigSession &session, QWidget *parent) :
_protocol_action = addWidget(&_protocol_button);
_measure_action = addWidget(&_measure_button);
_search_action = addWidget(&_search_button);
_function_action = addWidget(&_function_button);
_display_action = addWidget(&_display_button);
_function_action = addWidget(&_function_button);
_display_action = addWidget(&_display_button); //must be created
retranslateUi();
connect(&_trig_button, SIGNAL(clicked()),this, SLOT(trigger_clicked()));
connect(&_protocol_button, SIGNAL(clicked()),this, SLOT(protocol_clicked()));
connect(&_measure_button, SIGNAL(clicked()),this, SLOT(measure_clicked()));
connect(&_search_button, SIGNAL(clicked()), this, SLOT(search_clicked()));
connect(_action_fft, SIGNAL(triggered()), this, SLOT(on_actionFft_triggered()));
connect(_action_math, SIGNAL(triggered()), this, SLOT(on_actionMath_triggered()));
connect(_action_lissajous, SIGNAL(triggered()), this, SLOT(on_actionLissajous_triggered()));
connect(_dark_style, SIGNAL(triggered()), this, SLOT(on_actionDark_triggered()));
connect(_light_style, SIGNAL(triggered()), this, SLOT(on_actionLight_triggered()));
connect(_appParam_action, SIGNAL(triggered()), this, SLOT(on_application_param()));
}
void TrigBar::changeEvent(QEvent *event)
@ -141,14 +145,18 @@ void TrigBar::retranslateUi()
_measure_button.setText(tr("Measure"));
_search_button.setText(tr("Search"));
_function_button.setText(tr("Function"));
_display_button.setText(tr("Display"));
_display_button.setText(tr("Setting"));
_action_lissajous->setText(tr("&Lissajous"));
_themes->setTitle(tr("Themes"));
_dark_style->setText(tr("Dark"));
_light_style->setText(tr("Light"));
_action_lissajous->setText(tr("&Lissajous"));
_action_fft->setText(tr("FFT"));
_action_math->setText(tr("Math"));
_appParam_action->setText(tr("Application"));
}
void TrigBar::reStyle()
@ -167,6 +175,9 @@ void TrigBar::reStyle()
_action_lissajous->setIcon(QIcon(iconPath+"/lissajous.svg"));
_dark_style->setIcon(QIcon(iconPath+"/dark.svg"));
_light_style->setIcon(QIcon(iconPath+"/light.svg"));
_appParam_action->setIcon(QIcon(iconPath+"/params.svg"));
_themes->setIcon(QIcon(iconPath+"/"+qApp->property("Style").toString()+".svg"));
}
@ -304,5 +315,13 @@ void TrigBar::on_actionLissajous_triggered()
lissajous_dlg.exec();
}
void TrigBar::on_application_param(){
pv::dialogs::MathOptions math_dlg(_session, this);
math_dlg.exec();
return;
pv::dialogs::ApplicationParamDlg dlg;
dlg.ShowDlg(this);
}
} // namespace toolbars
} // namespace pv

View File

@ -83,6 +83,7 @@ public slots:
void on_actionFft_triggered();
void on_actionMath_triggered();
void on_application_param();
private:
SigSession& _session;
@ -97,7 +98,7 @@ private:
QAction* _protocol_action;
QAction* _measure_action;
QAction* _search_action;
QAction* _function_action;
QAction* _function_action;
QAction* _display_action;
QMenu* _function_menu;
@ -106,6 +107,7 @@ private:
QMenu* _display_menu;
QMenu *_themes;
QAction *_appParam_action;
QAction *_dark_style;
QAction *_light_style;
QAction* _action_lissajous;

View File

@ -51,6 +51,5 @@ bool MsgBox::Confirm(const char *text, QWidget *parent)
msg.mBox()->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msg.mBox()->setIcon(QMessageBox::Question);
msg.exec();
int click = msg.GetLastClick();
return (click == (int)QMessageBox::YesRole);
return msg.IsYes();
}

View File

@ -146,14 +146,7 @@ DecodeTrace::DecodeTrace(pv::SigSession &session,
}
DecodeTrace::~DecodeTrace()
{
DESTROY_OBJECT(_start_comboBox);
DESTROY_OBJECT(_end_comboBox);
DESTROY_OBJECT(_pub_input_layer);
DESTROY_OBJECT(_popup_form);
DESTROY_OBJECT(_popup);
_cur_row_headings.clear();
{ _cur_row_headings.clear();
_decoder_forms.clear();
_probe_selectors.clear();
_bindings.clear();
@ -371,13 +364,7 @@ bool DecodeTrace::create_popup()
}
}
//destroy object
DESTROY_OBJECT(_start_comboBox);
DESTROY_OBJECT(_end_comboBox);
DESTROY_OBJECT(_pub_input_layer);
DESTROY_OBJECT(_popup_form);
DESTROY_OBJECT(_popup);
//destroy object
return ret;
}
@ -389,7 +376,7 @@ void DecodeTrace::create_popup_form()
// which then goes out of scope destroying the layout and all the child
// widgets.
if (_popup_form)
_popup->reload(false);
_popup->reload();
_popup_form = new QFormLayout();
_popup_form->setVerticalSpacing(5);

View File

@ -501,7 +501,7 @@ void Viewport::paintProgress(QPainter &p, QColor fore, QColor back)
void Viewport::mousePressEvent(QMouseEvent *event)
{
assert(event);
_mouse_down_point = event->pos();
_mouse_down_offset = _view.offset();
_drag_strength = 0;

View File

@ -168,8 +168,8 @@ static const struct DEMO_profile supported_Demo[] = {
(1 << DEMO_LOGIC100x16) |
(1 << DEMO_ANALOG10x2) |
(1 << DEMO_DSO200x2),
SR_Mn(100),
// SR_Gn(16),
//SR_Mn(100),
SR_Gn(16),
SR_Kn(20),
0,
vdivs10to2000,