forked from Ivasoft/DSView
Close the popup dialog when screen count changed
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include "../dsvdef.h"
|
||||
#include "../config/appconfig.h"
|
||||
#include "../ui/fn.h"
|
||||
#include "../ui/popupdlglist.h"
|
||||
|
||||
namespace pv {
|
||||
namespace dialogs {
|
||||
@@ -81,6 +82,8 @@ DSDialog::~DSDialog()
|
||||
DESTROY_QT_OBJECT(_titlebar);
|
||||
DESTROY_QT_OBJECT(_shadow);
|
||||
DESTROY_QT_OBJECT(_base_button);
|
||||
|
||||
PopupDlgList::RemoveDlgFromList(this);
|
||||
}
|
||||
|
||||
void DSDialog::accept()
|
||||
@@ -129,6 +132,8 @@ int DSDialog::exec()
|
||||
}
|
||||
|
||||
update_font();
|
||||
|
||||
PopupDlgList::AddDlgTolist(this);
|
||||
|
||||
return QDialog::exec();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
DSDialog(QWidget *parent);
|
||||
DSDialog(QWidget *parent, bool hasClose);
|
||||
DSDialog(QWidget *parent, bool hasClose, bool bBaseButton);
|
||||
~DSDialog();
|
||||
virtual ~DSDialog();
|
||||
|
||||
inline void SetCallback(IDlgCallback *callback){m_callback = callback;}
|
||||
inline QVBoxLayout *layout(){return _main_layout;}
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "../ui/langresource.h"
|
||||
#include "../config/appconfig.h"
|
||||
#include "../ui/fn.h"
|
||||
#include "../ui/popupdlglist.h"
|
||||
|
||||
namespace pv {
|
||||
namespace dialogs {
|
||||
@@ -95,6 +96,8 @@ DSMessageBox::~DSMessageBox()
|
||||
DESTROY_QT_OBJECT(_titlebar);
|
||||
DESTROY_QT_OBJECT(_shadow);
|
||||
DESTROY_QT_OBJECT(_main_layout);
|
||||
|
||||
PopupDlgList::RemoveDlgFromList(this);
|
||||
}
|
||||
|
||||
void DSMessageBox::accept()
|
||||
@@ -138,6 +141,8 @@ int DSMessageBox::exec()
|
||||
_titlebar->update_font();
|
||||
}
|
||||
|
||||
PopupDlgList::AddDlgTolist(this);
|
||||
|
||||
return QDialog::exec();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include <QWidget>
|
||||
#include <QMessageBox>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "../toolbars/titlebar.h"
|
||||
|
||||
namespace pv {
|
||||
@@ -42,7 +41,7 @@ class DSMessageBox : public QDialog
|
||||
public:
|
||||
DSMessageBox(QWidget *parent, const QString title=0);
|
||||
|
||||
~DSMessageBox();
|
||||
virtual ~DSMessageBox();
|
||||
|
||||
QMessageBox *mBox();
|
||||
|
||||
|
||||
@@ -115,4 +115,14 @@ public:
|
||||
virtual void update_font()=0;
|
||||
};
|
||||
|
||||
enum ParentNativeEvent{
|
||||
EV_SCREEN_DPI_CHANGED = 0,
|
||||
};
|
||||
|
||||
class IParentNativeEventCallback
|
||||
{
|
||||
public:
|
||||
virtual void OnParentNativeEvent(ParentNativeEvent msg)=0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include <QFile>
|
||||
#include <QGuiApplication>
|
||||
#include <QFont>
|
||||
#include <algorithm>
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
#include <QDesktopWidget>
|
||||
@@ -55,7 +56,9 @@
|
||||
#include "appcontrol.h"
|
||||
#include "ui/langresource.h"
|
||||
#include "log.h"
|
||||
#include <algorithm>
|
||||
#include "dialogs/dsdialog.h"
|
||||
#include "ui/popupdlglist.h"
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "winnativewidget.h"
|
||||
@@ -170,6 +173,8 @@ MainFrame::MainFrame()
|
||||
|
||||
installEventFilter(this);
|
||||
|
||||
connect(this, SIGNAL(sig_ParentNativeEvent(int)), this, SLOT(OnParentNaitveWindowEvent(int)));
|
||||
|
||||
//PrintRegionProc();
|
||||
}
|
||||
|
||||
@@ -218,6 +223,7 @@ void MainFrame::AttachNativeWindow()
|
||||
_parentNativeWidget = new WinNativeWidget(x, y, w, h);
|
||||
_parentNativeWidget->setGeometry(x, y, w, h);
|
||||
_parentNativeWidget->SetChildWidget(this);
|
||||
_parentNativeWidget->SetNativeEventCallback(this);
|
||||
|
||||
if (_parentNativeWidget->Handle())
|
||||
{
|
||||
@@ -311,6 +317,27 @@ void MainFrame::MoveEnd()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainFrame::OnParentNativeEvent(ParentNativeEvent msg)
|
||||
{
|
||||
sig_ParentNativeEvent((int)msg);
|
||||
}
|
||||
|
||||
void MainFrame::OnParentNaitveWindowEvent(int msg)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (_parentNativeWidget != NULL){
|
||||
if (msg == EV_SCREEN_DPI_CHANGED){
|
||||
QTimer::singleShot(100, this, [this](){
|
||||
_parentNativeWidget->UpdateChildDpi();
|
||||
_parentNativeWidget->ResizeChild();
|
||||
|
||||
PopupDlgList::TryCloseAllByScreenChanged();
|
||||
});
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainFrame::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
|
||||
@@ -66,7 +66,10 @@ struct FormInitInfo
|
||||
bool isMaxSize;
|
||||
};
|
||||
|
||||
class MainFrame : public QFrame, public ITitleParent
|
||||
class MainFrame :
|
||||
public QFrame,
|
||||
public ITitleParent,
|
||||
public IParentNativeEventCallback
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -104,6 +107,9 @@ protected:
|
||||
|
||||
void changeEvent(QEvent *event) override;
|
||||
|
||||
signals:
|
||||
void sig_ParentNativeEvent(int msg);
|
||||
|
||||
public slots:
|
||||
void unfreezing();
|
||||
void show_doc();
|
||||
@@ -113,6 +119,7 @@ public slots:
|
||||
void showMaximized();
|
||||
void showMinimized();
|
||||
void moveToWinNaitiveNormal();
|
||||
void OnParentNaitveWindowEvent(int msg);
|
||||
|
||||
private:
|
||||
void hide_border();
|
||||
@@ -130,6 +137,9 @@ private:
|
||||
void MoveBegin() override;
|
||||
void MoveEnd() override;
|
||||
|
||||
//IParentNativeEventCallback
|
||||
void OnParentNativeEvent(ParentNativeEvent msg) override;
|
||||
|
||||
void SetFormRegion(int x, int y, int w, int h);
|
||||
QRect GetFormRegion();
|
||||
|
||||
|
||||
70
DSView/pv/ui/popupdlglist.cpp
Normal file
70
DSView/pv/ui/popupdlglist.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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 "popupdlglist.h"
|
||||
#include <QGuiApplication>
|
||||
|
||||
namespace{
|
||||
std::vector<QWidget*> g_popup_dlg_list;
|
||||
int g_screen_count = 1;
|
||||
}
|
||||
|
||||
void PopupDlgList::AddDlgTolist(QWidget *w)
|
||||
{
|
||||
if (w != nullptr){
|
||||
g_popup_dlg_list.push_back(w);
|
||||
}
|
||||
g_screen_count = QGuiApplication::screens().size();
|
||||
}
|
||||
|
||||
void PopupDlgList::RemoveDlgFromList(QWidget *w)
|
||||
{
|
||||
if (w != nullptr){
|
||||
for (auto it = g_popup_dlg_list.begin(); it != g_popup_dlg_list.end(); ++it)
|
||||
{
|
||||
if ((*it) == w){
|
||||
g_popup_dlg_list.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PopupDlgList::TryCloseAllByScreenChanged()
|
||||
{
|
||||
int screen_count = QGuiApplication::screens().size();
|
||||
|
||||
if (screen_count != g_screen_count)
|
||||
{
|
||||
int num = g_popup_dlg_list.size();
|
||||
|
||||
for (int i=0; i<num; i++)
|
||||
{
|
||||
auto it = g_popup_dlg_list.begin() + i;
|
||||
if ((*it)->isVisible()){
|
||||
(*it)->close(); //Close the dialog.
|
||||
g_popup_dlg_list.erase(it);
|
||||
--num;
|
||||
--i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
36
DSView/pv/ui/popupdlglist.h
Normal file
36
DSView/pv/ui/popupdlglist.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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 POPUP_DLG_LIST_H
|
||||
#define POPUP_DLG_LIST_H
|
||||
|
||||
#include <vector>
|
||||
#include <QWidget>
|
||||
|
||||
class PopupDlgList
|
||||
{
|
||||
public:
|
||||
static void AddDlgTolist(QWidget *w);
|
||||
static void RemoveDlgFromList(QWidget *w);
|
||||
static void TryCloseAllByScreenChanged();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -156,9 +156,15 @@ LRESULT CALLBACK WinNativeWidget::WndProc(HWND hWnd, UINT message, WPARAM wParam
|
||||
break;
|
||||
}
|
||||
case WM_DPICHANGED:
|
||||
if (self->_is_moving == false){
|
||||
self->UpdateChildDpi();
|
||||
self->ResizeChild();
|
||||
if (self->_is_moving == false){
|
||||
if (self->_event_callback != NULL){
|
||||
self->_event_callback->OnParentNativeEvent(EV_SCREEN_DPI_CHANGED);
|
||||
}
|
||||
else{
|
||||
self->UpdateChildDpi();
|
||||
self->ResizeChild();
|
||||
}
|
||||
|
||||
dsv_info("Dpi was changed.");
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <Windows.h>
|
||||
#include <Windowsx.h>
|
||||
#include <QWidget>
|
||||
#include "interface/icallbacks.h"
|
||||
|
||||
#ifndef WM_DPICHANGED
|
||||
#define WM_DPICHANGED 0x02E0
|
||||
@@ -35,12 +36,6 @@
|
||||
|
||||
namespace pv {
|
||||
|
||||
class IParentNaitveEventCallback
|
||||
{
|
||||
public:
|
||||
virtual void OnParentNativeEvent(int msg)=0;
|
||||
};
|
||||
|
||||
class WinNativeWidget
|
||||
{
|
||||
public:
|
||||
@@ -74,6 +69,10 @@ public:
|
||||
|
||||
QScreen* GetPointScreen();
|
||||
|
||||
inline void SetNativeEventCallback(IParentNativeEventCallback *callback){
|
||||
_event_callback = callback;
|
||||
}
|
||||
|
||||
private:
|
||||
QScreen* screenFromWindow(HWND hwnd);
|
||||
|
||||
@@ -81,7 +80,7 @@ private:
|
||||
QWidget* childWidget;
|
||||
HWND _childWindow;
|
||||
HWND _hWnd;
|
||||
IParentNaitveEventCallback *_event_callback;
|
||||
IParentNativeEventCallback *_event_callback;
|
||||
bool _is_moving;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user