mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 12:34:37 +03:00
rewrite ActivateWindow
This commit is contained in:
@@ -1,9 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
#include "sys/windows/guihelper.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Dialogs
|
// Dialogs
|
||||||
|
|
||||||
#define Dialog_DialogBasicSettings "DialogBasicSettings"
|
#define Dialog_DialogBasicSettings "DialogBasicSettings"
|
||||||
@@ -80,23 +76,7 @@
|
|||||||
if (result.isEmpty()) CACHE.a = ""; \
|
if (result.isEmpty()) CACHE.a = ""; \
|
||||||
editor->deleteLater();
|
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) \
|
#define ADD_ASTERISK(parent) \
|
||||||
for (auto label: parent->findChildren<QLabel *>()) { \
|
for (auto label: parent->findChildren<QLabel *>()) { \
|
||||||
|
|||||||
@@ -18,6 +18,10 @@
|
|||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
#include "sys/windows/guihelper.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
QStringList SplitLines(const QString &_string) {
|
QStringList SplitLines(const QString &_string) {
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||||
return _string.split(QRegularExpression("[\r\n]"), Qt::SplitBehaviorFlags::SkipEmptyParts);
|
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);
|
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) {
|
void runOnUiThread(const std::function<void()> &callback, QObject *parent) {
|
||||||
// any thread
|
// any thread
|
||||||
auto *timer = new QTimer();
|
auto *timer = new QTimer();
|
||||||
|
|||||||
@@ -147,6 +147,10 @@ int MessageBoxWarning(const QString &title, const QString &text);
|
|||||||
|
|
||||||
int MessageBoxInfo(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 runOnUiThread(const std::function<void()> &callback, QObject *parent = nullptr);
|
||||||
|
|
||||||
void runOnNewThread(const std::function<void()> &callback);
|
void runOnNewThread(const std::function<void()> &callback);
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
if (this->isVisible()) {
|
if (this->isVisible()) {
|
||||||
hide();
|
hide();
|
||||||
} else {
|
} 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;
|
this->exit_reason = 2;
|
||||||
on_menu_exit_triggered();
|
on_menu_exit_triggered();
|
||||||
} else if (info == "Raise") {
|
} else if (info == "Raise") {
|
||||||
ACTIVE_THIS_WINDOW
|
ActivateWindow(this);
|
||||||
} else if (info == "ClearConnectionList") {
|
} else if (info == "ClearConnectionList") {
|
||||||
refresh_connection_list({});
|
refresh_connection_list({});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user