Ref T220, renamed some main window / widget functions

Make clearer if dealing with a window or widget
This commit is contained in:
Klaus Basan
2018-01-10 03:20:04 +01:00
parent d3480c41b3
commit b74652c94a
16 changed files with 77 additions and 56 deletions

View File

@@ -75,7 +75,7 @@ namespace BlackGui
CEnableForFramelessWindow *CEnableForDockWidgetInfoArea::mainApplicationWindow() const CEnableForFramelessWindow *CEnableForDockWidgetInfoArea::mainApplicationWindow() const
{ {
CEnableForFramelessWindow *mw = CGuiUtility::mainFramelessEnabledApplicationWindow(); CEnableForFramelessWindow *mw = CGuiUtility::mainFramelessEnabledWindow();
return mw; return mw;
} }

View File

@@ -247,8 +247,8 @@ namespace BlackGui
void CInfoBarStatusComponent::updateSpacing() void CInfoBarStatusComponent::updateSpacing()
{ {
if (!sGui || !sGui->mainApplicationWindow()) { return; } if (!sGui || !sGui->mainApplicationWidget()) { return; }
const int w = sGui->mainApplicationWindow()->width(); const int w = sGui->mainApplicationWidget()->width();
const int s = (w >= 400) ? 6 : 2; const int s = (w >= 400) ? 6 : 2;
this->setSpacing(s); this->setSpacing(s);
} }

View File

@@ -387,7 +387,7 @@ namespace BlackGui
} }
// and move // and move
QPoint mainWindowPos = BlackGui::CGuiUtility::mainWindowPosition(); QPoint mainWindowPos = BlackGui::CGuiUtility::mainWidgetPosition();
if (!mainWindowPos.isNull()) if (!mainWindowPos.isNull())
{ {
int x = mainWindowPos.x() + m_offsetWhenFloating.x(); int x = mainWindowPos.x() + m_offsetWhenFloating.x();
@@ -556,8 +556,8 @@ namespace BlackGui
void CDockWidget::forceStyleSheetUpdate() void CDockWidget::forceStyleSheetUpdate()
{ {
QString qss = this->styleSheet(); const QString qss = this->styleSheet();
this->setStyleSheet(qss.isEmpty() ? " " : ""); this->setStyleSheet(qss.isEmpty() ? QStringLiteral(" ") : QStringLiteral(""));
this->setStyleSheet(qss); this->setStyleSheet(qss);
} }

View File

@@ -82,7 +82,7 @@ namespace BlackGui
WindowMode m_windowMode = WindowNormal; //!< Window mode, \sa WindowMode WindowMode m_windowMode = WindowNormal; //!< Window mode, \sa WindowMode
WindowMode m_originalWindowMode = WindowNormal; //!< mode when initialized WindowMode m_originalWindowMode = WindowNormal; //!< mode when initialized
bool m_mainApplicationWindow = false; //!< is this the main application window (only 1)? bool m_mainApplicationWindow = false; //!< is this the main application window (only 1)?
QWidget *m_widget = nullptr; //!< corresponding widget or dock widget QWidget *m_widget = nullptr; //!< corresponding window or dock widget
QSizeGrip *m_framelessSizeGrip = nullptr; //!< size grip object QSizeGrip *m_framelessSizeGrip = nullptr; //!< size grip object
QByteArray m_framelessPropertyName; //!< property name for frameless widgets QByteArray m_framelessPropertyName; //!< property name for frameless widgets

View File

@@ -172,36 +172,41 @@ namespace BlackGui
QCoreApplication::processEvents(QEventLoop::AllEvents, 100); QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
} }
QWidget *CGuiApplication::mainApplicationWindow() QWidget *CGuiApplication::mainApplicationWidget()
{ {
return CGuiUtility::mainApplicationWindow(); return CGuiUtility::mainApplicationWidget();
}
QMainWindow *CGuiApplication::mainApplicationWindow()
{
return qobject_cast<QMainWindow *>(CGuiApplication::mainApplicationWidget());
} }
IMainWindowAccess *CGuiApplication::mainWindowAccess() IMainWindowAccess *CGuiApplication::mainWindowAccess()
{ {
IMainWindowAccess *m = qobject_cast<IMainWindowAccess *>(mainApplicationWindow()); IMainWindowAccess *m = qobject_cast<IMainWindowAccess *>(mainApplicationWidget());
return m; return m;
} }
void CGuiApplication::initMainApplicationWindow(QWidget *mainWindow) void CGuiApplication::initMainApplicationWidget(QWidget *mainWidget)
{ {
if (!mainWindow) { return; } if (!mainWidget) { return; }
if (m_uiSetupCompleted) { return; } if (m_uiSetupCompleted) { return; }
m_uiSetupCompleted = true; m_uiSetupCompleted = true;
const QString name(this->getApplicationNameVersionBetaDev()); const QString name(this->getApplicationNameVersionDetailed());
mainWindow->setObjectName(QCoreApplication::applicationName()); mainWidget->setObjectName(QCoreApplication::applicationName());
mainWindow->setWindowTitle(name); mainWidget->setWindowTitle(name);
mainWindow->setWindowIcon(m_windowIcon); mainWidget->setWindowIcon(m_windowIcon);
mainWindow->setWindowIconText(name); mainWidget->setWindowIconText(name);
CStyleSheetUtility::setQSysInfoProperties(mainWindow, true); CStyleSheetUtility::setQSysInfoProperties(mainWidget, true);
CGuiUtility::registerMainApplicationWindow(mainWindow); CGuiUtility::registerMainApplicationWidget(mainWidget);
emit this->uiObjectTreeReady(); emit this->uiObjectTreeReady();
} }
void CGuiApplication::addWindowFlags(Qt::WindowFlags flags) void CGuiApplication::addWindowFlags(Qt::WindowFlags flags)
{ {
QWidget *maw = this->mainApplicationWindow(); QWidget *maw = this->mainApplicationWidget();
if (maw) if (maw)
{ {
Qt::WindowFlags windowFlags = maw->windowFlags(); Qt::WindowFlags windowFlags = maw->windowFlags();
@@ -490,7 +495,7 @@ namespace BlackGui
c = connect(a, &QAction::triggered, this, [a, this]() c = connect(a, &QAction::triggered, this, [a, this]()
{ {
// a close event might already trigger a shutdown // a close event might already trigger a shutdown
this->mainApplicationWindow()->close(); this->mainApplicationWidget()->close();
this->gracefulShutdown(); this->gracefulShutdown();
}); });
Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed"); Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
@@ -537,7 +542,7 @@ namespace BlackGui
void CGuiApplication::addMenuWindow(QMenu &menu) void CGuiApplication::addMenuWindow(QMenu &menu)
{ {
QWidget *w = mainApplicationWindow(); QWidget *w = mainApplicationWidget();
if (!w) { return; } if (!w) { return; }
const QSize iconSize = CIcons::empty16().size(); const QSize iconSize = CIcons::empty16().size();
QPixmap icon = w->style()->standardIcon(QStyle::SP_TitleBarMaxButton).pixmap(iconSize); QPixmap icon = w->style()->standardIcon(QStyle::SP_TitleBarMaxButton).pixmap(iconSize);
@@ -582,7 +587,7 @@ namespace BlackGui
void CGuiApplication::addMenuHelp(QMenu &menu) void CGuiApplication::addMenuHelp(QMenu &menu)
{ {
QWidget *w = mainApplicationWindow(); QWidget *w = mainApplicationWidget();
if (!w) { return; } if (!w) { return; }
QAction *a = menu.addAction(w->style()->standardIcon(QStyle::SP_TitleBarContextHelpButton), "Online help"); QAction *a = menu.addAction(w->style()->standardIcon(QStyle::SP_TitleBarContextHelpButton), "Online help");
bool c = connect(a, &QAction::triggered, this, [this]() bool c = connect(a, &QAction::triggered, this, [this]()
@@ -685,7 +690,7 @@ namespace BlackGui
CStyleSheetUtility::fileNameFonts(), CStyleSheetUtility::fileNameFonts(),
CStyleSheetUtility::fileNameStandardWidget() CStyleSheetUtility::fileNameStandardWidget()
}); });
CSetupLoadingDialog dialog(msgs, this->mainApplicationWindow()); CSetupLoadingDialog dialog(msgs, this->mainApplicationWidget());
dialog.setStyleSheet(style); dialog.setStyleSheet(style);
const int r = dialog.exec(); const int r = dialog.exec();
if (r == QDialog::Rejected) if (r == QDialog::Rejected)
@@ -779,7 +784,7 @@ namespace BlackGui
if (!m_updateDialog) if (!m_updateDialog)
{ {
// without parent stylesheet is not inherited // without parent stylesheet is not inherited
m_updateDialog = new CUpdateInfoDialog(this->mainApplicationWindow()); m_updateDialog = new CUpdateInfoDialog(this->mainApplicationWidget());
} }
if (onlyIfNew && !m_updateDialog->isNewVersionAvailable()) return; if (onlyIfNew && !m_updateDialog->isNewVersionAvailable()) return;
@@ -790,7 +795,7 @@ namespace BlackGui
QString CGuiApplication::getFontInfo() const QString CGuiApplication::getFontInfo() const
{ {
static const QString info("Family: '%1', average width: %2"); static const QString info("Family: '%1', average width: %2");
const QWidget *w = this->mainApplicationWindow(); const QWidget *w = this->mainApplicationWidget();
if (!w) { return QStringLiteral("Font info not available"); } if (!w) { return QStringLiteral("Font info not available"); }
return info. return info.
arg(w->font().family()). arg(w->font().family()).

View File

@@ -109,7 +109,8 @@ namespace BlackGui
void processEventsToRefreshGui() const; void processEventsToRefreshGui() const;
//! Init the main application window based on information in this application //! Init the main application window based on information in this application
void initMainApplicationWindow(QWidget *mainWindow); //! \remark can be QDialog, QMainWindow
void initMainApplicationWidget(QWidget *mainWidget);
//! Set window flag on main application window //! Set window flag on main application window
void addWindowFlags(Qt::WindowFlags flags); void addWindowFlags(Qt::WindowFlags flags);
@@ -193,8 +194,11 @@ namespace BlackGui
//! \note Pixmap requires a valid QApplication, so it cannot be passed as constructor parameter //! \note Pixmap requires a valid QApplication, so it cannot be passed as constructor parameter
static void setWindowIcon(const QPixmap &icon); static void setWindowIcon(const QPixmap &icon);
//! \copydoc BlackGui::CGuiUtility::mainApplicationWidget
static QWidget *mainApplicationWidget();
//! Main application window //! Main application window
static QWidget *mainApplicationWindow(); static QMainWindow *mainApplicationWindow();
//! Main window access interface //! Main window access interface
static BlackGui::IMainWindowAccess *mainWindowAccess(); static BlackGui::IMainWindowAccess *mainWindowAccess();

View File

@@ -39,9 +39,9 @@ using namespace BlackMisc;
namespace BlackGui namespace BlackGui
{ {
QWidget *CGuiUtility::s_mainApplicationWindow = nullptr; QWidget *CGuiUtility::s_mainApplicationWidget = nullptr;
CEnableForFramelessWindow *CGuiUtility::mainFramelessEnabledApplicationWindow() CEnableForFramelessWindow *CGuiUtility::mainFramelessEnabledWindow()
{ {
const QWidgetList tlw = topLevelApplicationWidgetsWithName(); const QWidgetList tlw = topLevelApplicationWidgetsWithName();
for (QWidget *w : tlw) for (QWidget *w : tlw)
@@ -55,9 +55,9 @@ namespace BlackGui
namespace Private namespace Private
{ {
QWidget *mainApplicationWindowSearch() QWidget *mainApplicationWidgetSearch()
{ {
CEnableForFramelessWindow *mw = CGuiUtility::mainFramelessEnabledApplicationWindow(); CEnableForFramelessWindow *mw = CGuiUtility::mainFramelessEnabledWindow();
if (mw && mw->getWidget()) if (mw && mw->getWidget())
{ {
return mw->getWidget(); return mw->getWidget();
@@ -75,23 +75,23 @@ namespace BlackGui
} }
} // ns } // ns
void CGuiUtility::registerMainApplicationWindow(QWidget *mainWindow) void CGuiUtility::registerMainApplicationWidget(QWidget *mainWidget)
{ {
CGuiUtility::s_mainApplicationWindow = mainWindow; CGuiUtility::s_mainApplicationWidget = mainWidget;
} }
QWidget *CGuiUtility::mainApplicationWindow() QWidget *CGuiUtility::mainApplicationWidget()
{ {
if (!CGuiUtility::s_mainApplicationWindow) if (!CGuiUtility::s_mainApplicationWidget)
{ {
CGuiUtility::s_mainApplicationWindow = Private::mainApplicationWindowSearch(); CGuiUtility::s_mainApplicationWidget = Private::mainApplicationWidgetSearch();
} }
return CGuiUtility::s_mainApplicationWindow; return CGuiUtility::s_mainApplicationWidget;
} }
bool CGuiUtility::isMainWindowFrameless() bool CGuiUtility::isMainWindowFrameless()
{ {
const CEnableForFramelessWindow *mw = CGuiUtility::mainFramelessEnabledApplicationWindow(); const CEnableForFramelessWindow *mw = CGuiUtility::mainFramelessEnabledWindow();
return (mw && mw->isFrameless()); return (mw && mw->isFrameless());
} }
@@ -251,9 +251,9 @@ namespace BlackGui
return rl; return rl;
} }
QPoint CGuiUtility::mainWindowPosition() QPoint CGuiUtility::mainWidgetPosition()
{ {
CEnableForFramelessWindow *mw = mainFramelessEnabledApplicationWindow(); CEnableForFramelessWindow *mw = CGuiUtility::mainFramelessEnabledWindow();
return (mw) ? mw->getWidget()->pos() : QPoint(); return (mw) ? mw->getWidget()->pos() : QPoint();
} }
@@ -407,14 +407,19 @@ namespace BlackGui
QFontMetrics CGuiUtility::currentFontMetrics() QFontMetrics CGuiUtility::currentFontMetrics()
{ {
const QWidget *w = CGuiUtility::mainApplicationWindow(); const QWidget *w = CGuiUtility::mainApplicationWidget();
if (w) { return w->fontMetrics(); } if (w) { return w->fontMetrics(); }
return QApplication::fontMetrics(); return QApplication::fontMetrics();
} }
QFontMetricsF CGuiUtility::currentFontMetricsF()
{
return QFontMetricsF(CGuiUtility::currentFontMetrics());
}
QFont CGuiUtility::currentFont() QFont CGuiUtility::currentFont()
{ {
const QWidget *w = CGuiUtility::mainApplicationWindow(); const QWidget *w = CGuiUtility::mainApplicationWidget();
if (w) { return w->font(); } if (w) { return w->font(); }
return QApplication::font(); return QApplication::font();
} }
@@ -440,6 +445,8 @@ namespace BlackGui
QSize CGuiUtility::fontMetricsEstimateSize(int xCharacters, int yCharacters) QSize CGuiUtility::fontMetricsEstimateSize(int xCharacters, int yCharacters)
{ {
// 1920/1080: 560/16 256/16 => 530/960
// 3840/2160: 400/10 178/10 => 375/600
const QSize s1 = CGuiUtility::fontMetrics80Chars(); const QSize s1 = CGuiUtility::fontMetrics80Chars();
const QSize s2 = CGuiUtility::fontMetricsLazyDog43Chars(); const QSize s2 = CGuiUtility::fontMetricsLazyDog43Chars();
const QSize s = s1 + s2; const QSize s = s1 + s2;

View File

@@ -23,6 +23,7 @@
#include <QWidgetList> #include <QWidgetList>
#include <QFont> #include <QFont>
#include <QFontMetrics> #include <QFontMetrics>
#include <QFontMetricsF>
#include <QModelIndexList> #include <QModelIndexList>
class QCheckBox; class QCheckBox;
@@ -42,13 +43,13 @@ namespace BlackGui
{ {
public: public:
//! Main (frameless enabled) application window //! Main (frameless enabled) application window
static CEnableForFramelessWindow *mainFramelessEnabledApplicationWindow(); static CEnableForFramelessWindow *mainFramelessEnabledWindow();
//! Register main application window widget if this is known //! Register main application window widget if this is known
static void registerMainApplicationWindow(QWidget *mainWindow); static void registerMainApplicationWidget(QWidget *mainWidget);
//! Main application window widget //! Main application window widget
static QWidget *mainApplicationWindow(); static QWidget *mainApplicationWidget();
//! Is main window frameless? //! Is main window frameless?
static bool isMainWindowFrameless(); static bool isMainWindowFrameless();
@@ -56,8 +57,8 @@ namespace BlackGui
//! Top level widgets with names //! Top level widgets with names
static QWidgetList topLevelApplicationWidgetsWithName(); static QWidgetList topLevelApplicationWidgetsWithName();
//! Position of main window //! Position of main widget
static QPoint mainWindowPosition(); static QPoint mainWidgetPosition();
//! Replace count in name such as "stations (4)" //! Replace count in name such as "stations (4)"
static QString replaceTabCountValue(const QString &oldName, int count); static QString replaceTabCountValue(const QString &oldName, int count);
@@ -137,6 +138,9 @@ namespace BlackGui
//! Main window font metrics or default metrics //! Main window font metrics or default metrics
static QFontMetrics currentFontMetrics(); static QFontMetrics currentFontMetrics();
//! Main window font metrics or default metrics
static QFontMetricsF currentFontMetricsF();
//! Main window font or default font //! Main window font or default font
static QFont currentFont(); static QFont currentFont();
@@ -153,7 +157,7 @@ namespace BlackGui
//! Constructor, use static methods only //! Constructor, use static methods only
CGuiUtility() {} CGuiUtility() {}
static QWidget *s_mainApplicationWindow; static QWidget *s_mainApplicationWidget;
}; };
} // ns } // ns

View File

@@ -509,7 +509,7 @@ namespace BlackGui
m_infoAreaFloating = floating; m_infoAreaFloating = floating;
if (m_infoAreaFloating) if (m_infoAreaFloating)
{ {
QPoint p = CGuiUtility::mainWindowPosition(); QPoint p = CGuiUtility::mainWidgetPosition();
this->setWindowFlags(Qt::Dialog); this->setWindowFlags(Qt::Dialog);
this->move(p.rx() + 20, p.ry() + 20); this->move(p.rx() + 20, p.ry() + 20);
this->show(); // not working without show this->show(); // not working without show

View File

@@ -216,7 +216,7 @@ namespace BlackGui
QWidget *CViewBaseNonTemplate::mainApplicationWindowWidget() const QWidget *CViewBaseNonTemplate::mainApplicationWindowWidget() const
{ {
return CGuiUtility::mainApplicationWindow(); return CGuiUtility::mainApplicationWidget();
} }
CStatusMessage CViewBaseNonTemplate::showFileLoadDialog() CStatusMessage CViewBaseNonTemplate::showFileLoadDialog()

View File

@@ -43,7 +43,7 @@ namespace BlackSimPlugin
this->onSettingsChanged(); // init from settings this->onSettingsChanged(); // init from settings
m_myAircraft = this->getOwnAircraft(); // sync with provider m_myAircraft = this->getOwnAircraft(); // sync with provider
m_monitorWidget.reset(new CSimulatorEmulatedMonitorDialog(this, sGui->mainApplicationWindow())); m_monitorWidget.reset(new CSimulatorEmulatedMonitorDialog(this, sGui->mainApplicationWidget()));
connect(qApp, &QApplication::aboutToQuit, this, &CSimulatorEmulated::closeMonitor); connect(qApp, &QApplication::aboutToQuit, this, &CSimulatorEmulated::closeMonitor);
connect(&m_interpolatorFetchTimer, &QTimer::timeout, this, &CSimulatorEmulated::fetchFromInterpolator); connect(&m_interpolatorFetchTimer, &QTimer::timeout, this, &CSimulatorEmulated::fetchFromInterpolator);

View File

@@ -44,7 +44,7 @@ CSwiftCore::CSwiftCore(QWidget *parent) :
{ {
Q_ASSERT(sGui); Q_ASSERT(sGui);
ui->setupUi(this); ui->setupUi(this);
sGui->initMainApplicationWindow(this); sGui->initMainApplicationWidget(this);
const QString name(sGui->getApplicationNameAndVersion()); const QString name(sGui->getApplicationNameAndVersion());
setSystemTrayMode(MinimizeToTray | QuitOnClose); setSystemTrayMode(MinimizeToTray | QuitOnClose);
setSystemTrayToolTip(name); setSystemTrayToolTip(name);

View File

@@ -94,7 +94,7 @@ void CSwiftData::onStyleSheetsChanged()
void CSwiftData::init() void CSwiftData::init()
{ {
sGui->initMainApplicationWindow(this); sGui->initMainApplicationWidget(this);
this->initLogDisplay(); this->initLogDisplay();
m_mwaLogComponent = ui->comp_MainInfoArea->getLogComponent(); m_mwaLogComponent = ui->comp_MainInfoArea->getLogComponent();

View File

@@ -69,7 +69,7 @@ void SwiftGuiStd::init()
m_mwaOverlayFrame = ui->fr_CentralFrameInside; m_mwaOverlayFrame = ui->fr_CentralFrameInside;
m_mwaLogComponent = ui->comp_MainInfoArea->getLogComponent(); m_mwaLogComponent = ui->comp_MainInfoArea->getLogComponent();
sGui->initMainApplicationWindow(this); sGui->initMainApplicationWidget(this);
// log messages // log messages
m_logSubscriber.changeSubscription(CLogPattern().withSeverityAtOrAbove(CStatusMessage::SeverityInfo)); m_logSubscriber.changeSubscription(CLogPattern().withSeverityAtOrAbove(CStatusMessage::SeverityInfo));

View File

@@ -157,7 +157,7 @@ void CSwiftLauncher::mousePressEvent(QMouseEvent *event)
void CSwiftLauncher::init() void CSwiftLauncher::init()
{ {
sGui->initMainApplicationWindow(this); sGui->initMainApplicationWidget(this);
m_mwaOverlayFrame = ui->fr_SwiftLauncherMain; m_mwaOverlayFrame = ui->fr_SwiftLauncherMain;
m_mwaStatusBar = nullptr; m_mwaStatusBar = nullptr;

View File

@@ -33,6 +33,7 @@ namespace BlackGui { namespace Components { class CConfigurationWizard; }}
* \note Besides the fact the launcher makes it easy to start our applications it also pre-fetches some * \note Besides the fact the launcher makes it easy to start our applications it also pre-fetches some
* cache files, hence reducing load times in the subsequent applications. Therefor starting via the launcher * cache files, hence reducing load times in the subsequent applications. Therefor starting via the launcher
* is preferable, but not mandatory. * is preferable, but not mandatory.
* \fixme it was better if launcher was a QMainWindow, because we have to deal with main widgets QDialog and QMainWindow because of launcher
*/ */
class CSwiftLauncher : class CSwiftLauncher :
public QDialog, public QDialog,