rewrite ActivateWindow

This commit is contained in:
arm64v8a
2023-07-10 11:53:51 +09:00
parent 071b593f0d
commit db3c26671b
4 changed files with 21 additions and 23 deletions

View File

@@ -1,9 +1,5 @@
#pragma once
#ifdef Q_OS_WIN
#include "sys/windows/guihelper.h"
#endif
// Dialogs
#define Dialog_DialogBasicSettings "DialogBasicSettings"
@@ -80,23 +76,7 @@
if (result.isEmpty()) CACHE.a = ""; \
editor->deleteLater();
// System
#define _ACTIVE_THIS_WINDOW_COMMON \
hide(); \
showMinimized(); \
showNormal(); \
activateWindow(); \
setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive); \
raise();
#ifdef Q_OS_WIN
#define ACTIVE_THIS_WINDOW \
_ACTIVE_THIS_WINDOW_COMMON \
Windows_QWidget_SetForegroundWindow(this);
#else
#define ACTIVE_THIS_WINDOW _ACTIVE_THIS_WINDOW_COMMON
#endif
//
#define ADD_ASTERISK(parent) \
for (auto label: parent->findChildren<QLabel *>()) { \

View File

@@ -18,6 +18,10 @@
#include <QDateTime>
#include <QLocale>
#ifdef Q_OS_WIN
#include "sys/windows/guihelper.h"
#endif
QStringList SplitLines(const QString &_string) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
return _string.split(QRegularExpression("[\r\n]"), Qt::SplitBehaviorFlags::SkipEmptyParts);
@@ -211,6 +215,16 @@ int MessageBoxInfo(const QString &title, const QString &text) {
return QMessageBox::information(GetMessageBoxParent(), title, text);
}
void ActivateWindow(QWidget *w) {
w->setWindowState(w->windowState() & ~Qt::WindowMinimized);
w->setVisible(true);
#ifdef Q_OS_WIN
Windows_QWidget_SetForegroundWindow(w);
#endif
w->raise();
w->activateWindow();
}
void runOnUiThread(const std::function<void()> &callback, QObject *parent) {
// any thread
auto *timer = new QTimer();

View File

@@ -147,6 +147,10 @@ int MessageBoxWarning(const QString &title, const QString &text);
int MessageBoxInfo(const QString &title, const QString &text);
void ActivateWindow(QWidget *w);
//
void runOnUiThread(const std::function<void()> &callback, QObject *parent = nullptr);
void runOnNewThread(const std::function<void()> &callback);

View File

@@ -251,7 +251,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
if (this->isVisible()) {
hide();
} else {
ACTIVE_THIS_WINDOW
ActivateWindow(this);
}
}
});
@@ -554,7 +554,7 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info)
this->exit_reason = 2;
on_menu_exit_triggered();
} else if (info == "Raise") {
ACTIVE_THIS_WINDOW
ActivateWindow(this);
} else if (info == "ClearConnectionList") {
refresh_connection_list({});
}