mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
Utility functions
This commit is contained in:
committed by
Mat Sutcliffe
parent
e8786f9794
commit
5e8696464f
@@ -11,6 +11,7 @@
|
||||
#include "blackgui/overlaymessagesframe.h"
|
||||
#include "blackmisc/icon.h"
|
||||
#include "blackmisc/verify.h"
|
||||
#include "guiutility.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCheckBox>
|
||||
@@ -948,4 +949,166 @@ namespace BlackGui
|
||||
if (wizard->button(QWizard::CustomButton2)) { wizard->button(QWizard::CustomButton2)->setMinimumWidth(minW); }
|
||||
if (wizard->button(QWizard::CustomButton3)) { wizard->button(QWizard::CustomButton3)->setMinimumWidth(minW); }
|
||||
}
|
||||
|
||||
QWidgetList CGuiUtility::getAllModallWidgets()
|
||||
{
|
||||
const QWidgetList widgets = QApplication::topLevelWidgets();
|
||||
QWidgetList openWidgets;
|
||||
for (QWidget *w : widgets)
|
||||
{
|
||||
if (w->isModal()) { openWidgets.push_back(w); }
|
||||
}
|
||||
return openWidgets;
|
||||
}
|
||||
|
||||
QStringList CGuiUtility::getAllWidgetTitles(const QWidgetList widgets)
|
||||
{
|
||||
QStringList titles;
|
||||
for (const QWidget *w : widgets)
|
||||
{
|
||||
if (!w) { continue; }
|
||||
if (!w->windowTitle().isEmpty())
|
||||
{
|
||||
titles.push_back(w->windowTitle());
|
||||
}
|
||||
else
|
||||
{
|
||||
titles.push_back(QStringLiteral("name: ") % w->objectName());
|
||||
}
|
||||
}
|
||||
return titles;
|
||||
}
|
||||
|
||||
QStringList CGuiUtility::getAllWidgetNames(const QWidgetList widgets)
|
||||
{
|
||||
QStringList titles;
|
||||
for (const QWidget *w : widgets)
|
||||
{
|
||||
if (!w) { continue; }
|
||||
titles.push_back(QStringLiteral("name: ") % w->objectName());
|
||||
}
|
||||
return titles;
|
||||
}
|
||||
|
||||
QList<QDockWidget *> CGuiUtility::getAllDockWidgets(QWidget *parent, bool floatingOnly)
|
||||
{
|
||||
QList<QDockWidget *> docks;
|
||||
if (parent)
|
||||
{
|
||||
const auto children = parent->findChildren<QDockWidget *>();
|
||||
for (QDockWidget *w : children)
|
||||
{
|
||||
if (!w) { continue; }
|
||||
if (!floatingOnly || w->isFloating())
|
||||
{
|
||||
docks.push_back(w);
|
||||
}
|
||||
}
|
||||
}
|
||||
return docks;
|
||||
}
|
||||
|
||||
QList<QDockWidget *> CGuiUtility::getAllDockWidgets(QWindow *parent, bool floatingOnly)
|
||||
{
|
||||
QList<QDockWidget *> docks;
|
||||
if (parent)
|
||||
{
|
||||
const auto children = parent->findChildren<QDockWidget *>();
|
||||
for (QDockWidget *w : children)
|
||||
{
|
||||
if (!w) { continue; }
|
||||
if (!floatingOnly || w->isFloating())
|
||||
{
|
||||
docks.push_back(w);
|
||||
}
|
||||
}
|
||||
}
|
||||
return docks;
|
||||
}
|
||||
|
||||
QWidgetList CGuiUtility::closeAllModalWidgets()
|
||||
{
|
||||
QWidgetList modals = getAllModallWidgets();
|
||||
for (QWidget *w : modals)
|
||||
{
|
||||
if (!w) { continue; }
|
||||
w->close();
|
||||
}
|
||||
return modals;
|
||||
}
|
||||
|
||||
QStringList CGuiUtility::closeAllModalWidgetsGetTitles()
|
||||
{
|
||||
const QWidgetList modals = getAllModallWidgets();
|
||||
QStringList titles;
|
||||
for (QWidget *w : modals)
|
||||
{
|
||||
if (!w) { continue; }
|
||||
titles << w->windowTitle();
|
||||
w->close();
|
||||
}
|
||||
return titles;
|
||||
}
|
||||
|
||||
QList<QDockWidget *> CGuiUtility::closeAllDockWidgets(QWidget *parent, bool floatingOnly)
|
||||
{
|
||||
QList<QDockWidget *> dws = getAllDockWidgets(parent, floatingOnly);
|
||||
for (QWidget *w : dws)
|
||||
{
|
||||
if (!w) { continue; }
|
||||
w->close();
|
||||
}
|
||||
return dws;
|
||||
}
|
||||
|
||||
QList<QDockWidget *> CGuiUtility::closeAllDockWidgets(QWindow *parent, bool floatingOnly)
|
||||
{
|
||||
QList<QDockWidget *> dws = getAllDockWidgets(parent, floatingOnly);
|
||||
for (QWidget *w : dws)
|
||||
{
|
||||
if (!w) { continue; }
|
||||
w->close();
|
||||
}
|
||||
return dws;
|
||||
}
|
||||
|
||||
QStringList CGuiUtility::closeAllDockWidgetsGetTitles(QWidget *parent, bool floatingOnly)
|
||||
{
|
||||
const QList<QDockWidget *> dws = getAllDockWidgets(parent, floatingOnly);
|
||||
QStringList titles;
|
||||
for (QWidget *w : dws)
|
||||
{
|
||||
if (!w) { continue; }
|
||||
titles << w->windowTitle();
|
||||
w->close();
|
||||
}
|
||||
return titles;
|
||||
}
|
||||
|
||||
QStringList CGuiUtility::closeAllDockWidgetsGetTitles(QWindow *parent, bool floatingOnly)
|
||||
{
|
||||
const QList<QDockWidget *> dws = getAllDockWidgets(parent, floatingOnly);
|
||||
QStringList titles;
|
||||
for (QWidget *w : dws)
|
||||
{
|
||||
if (!w) { continue; }
|
||||
titles << w->windowTitle();
|
||||
w->close();
|
||||
}
|
||||
return titles;
|
||||
}
|
||||
|
||||
QStringList CGuiUtility::deleteLaterAllDockWidgetsGetTitles(QWidget *parent, bool floatingOnly)
|
||||
{
|
||||
const QList<QDockWidget *> dws = getAllDockWidgets(parent, floatingOnly);
|
||||
QStringList titles;
|
||||
for (QWidget *w : dws)
|
||||
{
|
||||
if (!w) { continue; }
|
||||
titles << w->windowTitle();
|
||||
w->deleteLater(); // DANGEROUS
|
||||
}
|
||||
return titles;
|
||||
}
|
||||
|
||||
} // ns
|
||||
|
||||
@@ -18,9 +18,11 @@
|
||||
#include <QSize>
|
||||
#include <QPoint>
|
||||
#include <QString>
|
||||
#include <QWindow>
|
||||
#include <QWidget>
|
||||
#include <QWidgetList>
|
||||
#include <QFont>
|
||||
#include <QDockWidget>
|
||||
#include <QFontMetrics>
|
||||
#include <QFontMetricsF>
|
||||
#include <QModelIndexList>
|
||||
@@ -281,6 +283,43 @@ namespace BlackGui
|
||||
//! Set button widths for a wizard
|
||||
static void setWizardButtonWidths(QWizard *wizard);
|
||||
|
||||
//! All modal widgets
|
||||
static QWidgetList getAllModallWidgets();
|
||||
|
||||
//! All titles
|
||||
static QStringList getAllWidgetTitles(const QWidgetList widgets);
|
||||
|
||||
//! All names
|
||||
static QStringList getAllWidgetNames(const QWidgetList widgets);
|
||||
|
||||
//! Get all dock widgets
|
||||
static QList<QDockWidget *> getAllDockWidgets(QWidget *parent, bool floatingOnly);
|
||||
|
||||
//! Get all dock widgets
|
||||
static QList<QDockWidget *> getAllDockWidgets(QWindow *parent, bool floatingOnly);
|
||||
|
||||
//! Close all modal widgets
|
||||
static QWidgetList closeAllModalWidgets();
|
||||
|
||||
//! Close all modal widgets and get titles
|
||||
static QStringList closeAllModalWidgetsGetTitles();
|
||||
|
||||
//! Close all dock widgets
|
||||
static QList<QDockWidget *> closeAllDockWidgets(QWidget *parent, bool floatingOnly);
|
||||
|
||||
//! Close all dock widgets
|
||||
static QList<QDockWidget *> closeAllDockWidgets(QWindow *parent, bool floatingOnly);
|
||||
|
||||
//! Close all dock widgets
|
||||
static QStringList closeAllDockWidgetsGetTitles(QWidget *parent, bool floatingOnly);
|
||||
|
||||
//! close all dock widgets
|
||||
static QStringList closeAllDockWidgetsGetTitles(QWindow *parent, bool floatingOnly);
|
||||
|
||||
//! "deleteLater" all dock widgets
|
||||
//! \remark do NOT use unless you know what you are doing
|
||||
static QStringList deleteLaterAllDockWidgetsGetTitles(QWidget *parent, bool floatingOnly);
|
||||
|
||||
private:
|
||||
//! No constructor, use static functions only
|
||||
CGuiUtility() {}
|
||||
|
||||
Reference in New Issue
Block a user