mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Ref T220, font metric support
* signal if font changed * character based size can be set
This commit is contained in:
@@ -90,8 +90,9 @@ namespace BlackGui
|
||||
CGuiApplication::adjustPalette();
|
||||
this->setWindowIcon(icon);
|
||||
this->settingsChanged();
|
||||
this->setCurrentFontValues(); // most likely the default font and not any stylesheet font at this time
|
||||
sGui = this;
|
||||
connect(&m_styleSheetUtility, &CStyleSheetUtility::styleSheetsChanged, this, &CGuiApplication::styleSheetsChanged);
|
||||
connect(&m_styleSheetUtility, &CStyleSheetUtility::styleSheetsChanged, this, &CGuiApplication::onStyleSheetsChanged);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +196,6 @@ namespace BlackGui
|
||||
mainWindow->setWindowIconText(name);
|
||||
CStyleSheetUtility::setQSysInfoProperties(mainWindow, true);
|
||||
CGuiUtility::registerMainApplicationWindow(mainWindow);
|
||||
|
||||
emit this->uiObjectTreeReady();
|
||||
}
|
||||
|
||||
@@ -236,11 +236,35 @@ namespace BlackGui
|
||||
void CGuiApplication::onStartUpCompleted()
|
||||
{
|
||||
CApplication::onStartUpCompleted();
|
||||
this->setCurrentFont();
|
||||
if (m_splashScreen)
|
||||
{
|
||||
m_splashScreen->close();
|
||||
m_splashScreen.reset();
|
||||
}
|
||||
|
||||
if (m_minWidthChars > 0 || m_minHeightChars > 0)
|
||||
{
|
||||
const QSize s = CGuiUtility::fontMetricsEstimateSize(m_minWidthChars, m_minHeightChars);
|
||||
QWidget *mw = CGuiUtility::mainApplicationWindow();
|
||||
if (mw)
|
||||
{
|
||||
QSize cs = mw->size();
|
||||
if (m_minWidthChars > 0) { cs.setWidth(s.width()); }
|
||||
if (m_minHeightChars > 0) { cs.setHeight(s.height()); }
|
||||
mw->resize(cs);
|
||||
}
|
||||
}
|
||||
if (m_saveMainWidgetState && !this->isSet(m_cmdWindowSizeReset))
|
||||
{
|
||||
this->restoreWindowGeometryAndState();
|
||||
}
|
||||
|
||||
if (m_splashScreen)
|
||||
{
|
||||
m_splashScreen->close(); // GUI
|
||||
m_splashScreen.reset();
|
||||
}
|
||||
}
|
||||
|
||||
QString CGuiApplication::beautifyHelpMessage(const QString &helpText)
|
||||
@@ -642,6 +666,12 @@ namespace BlackGui
|
||||
return m_styleSheetUtility.resetFont();
|
||||
}
|
||||
|
||||
void CGuiApplication::setMinimumSizeInCharacters(int widthChars, int heightChars)
|
||||
{
|
||||
m_minWidthChars = widthChars;
|
||||
m_minHeightChars = heightChars;
|
||||
}
|
||||
|
||||
bool CGuiApplication::interactivelySynchronizeSetup(int timeoutMs)
|
||||
{
|
||||
bool ok = false;
|
||||
@@ -757,6 +787,16 @@ namespace BlackGui
|
||||
if (result != QDialog::Accepted) { return; }
|
||||
}
|
||||
|
||||
QString CGuiApplication::getFontInfo() const
|
||||
{
|
||||
static const QString info("Family: '%1', average width: %2");
|
||||
const QWidget *w = this->mainApplicationWindow();
|
||||
if (!w) { return QStringLiteral("Font info not available"); }
|
||||
return info.
|
||||
arg(w->font().family()).
|
||||
arg(w->fontMetrics().averageCharWidth());
|
||||
}
|
||||
|
||||
void CGuiApplication::triggerNewVersionCheck(int delayedMs)
|
||||
{
|
||||
if (!m_updateSetting.get()) { return; }
|
||||
@@ -806,4 +846,22 @@ namespace BlackGui
|
||||
newPalette.setColor(QPalette::LinkVisited, linkColor);
|
||||
qApp->setPalette(newPalette);
|
||||
}
|
||||
|
||||
void CGuiApplication::onStyleSheetsChanged()
|
||||
{
|
||||
emit this->styleSheetsChanged();
|
||||
const QFont f = CGuiUtility::currentFont();
|
||||
if (f.pointSize() != m_fontPointSize || f.family() != m_fontFamily)
|
||||
{
|
||||
emit this->fontChanged();
|
||||
CLogMessage(this).info(this->getFontInfo());
|
||||
}
|
||||
}
|
||||
|
||||
void CGuiApplication::setCurrentFontValues()
|
||||
{
|
||||
const QFont font = CGuiUtility::currentFont();
|
||||
m_fontFamily = font.family();
|
||||
m_fontPointSize = font.pointSize();
|
||||
}
|
||||
} // ns
|
||||
|
||||
@@ -172,6 +172,9 @@ namespace BlackGui
|
||||
//! Reset the font to default
|
||||
bool resetFont();
|
||||
|
||||
//! Set minimum width/height in characters
|
||||
void setMinimumSizeInCharacters(int widthChars, int heightChars);
|
||||
|
||||
//! Wait for setup, in case it fails display a dialog how to continue
|
||||
bool interactivelySynchronizeSetup(int timeoutMs = BlackMisc::Network::CNetworkUtils::getLongTimeoutMs());
|
||||
|
||||
@@ -210,9 +213,8 @@ namespace BlackGui
|
||||
//! Object tree ready (means ui->setupUi() completed)
|
||||
void uiObjectTreeReady();
|
||||
|
||||
protected slots:
|
||||
//! Startup competed
|
||||
virtual void onStartUpCompleted() override;
|
||||
//! Font has been changed
|
||||
void fontChanged();
|
||||
|
||||
protected:
|
||||
//! \name print messages generated during parsing / cmd handling
|
||||
@@ -227,14 +229,24 @@ namespace BlackGui
|
||||
//! \copydoc BlackCore::CApplication::onCoreFacadeStarted
|
||||
virtual void onCoreFacadeStarted() override;
|
||||
|
||||
//! \copydoc BlackCore::CApplication::onStartUpCompleted
|
||||
virtual void onStartUpCompleted() override;
|
||||
|
||||
//! Check for a new version (update)
|
||||
void checkNewVersion(bool onlyIfNew);
|
||||
|
||||
//! Info about font
|
||||
QString getFontInfo() const;
|
||||
|
||||
//! Register metadata
|
||||
static void registerMetadata();
|
||||
|
||||
private:
|
||||
QPixmap m_windowIcon;
|
||||
QString m_fontFamily; //!< current font family
|
||||
int m_fontPointSize; //!< current font size
|
||||
int m_minWidthChars = -1; //!< min. width characters (based on current font metrics)
|
||||
int m_minHeightChars = -1; //!< min. height characters (based on current font metrics)
|
||||
QCommandLineOption m_cmdWindowStateMinimized { "empty" }; //!< window state (minimized)
|
||||
QCommandLineOption m_cmdWindowMode { "empty" }; //!< window mode (flags: frameless ...)
|
||||
CStyleSheetUtility m_styleSheetUtility {{}, this}; //!< style sheet utility
|
||||
@@ -256,6 +268,12 @@ namespace BlackGui
|
||||
|
||||
//! Fix the palette for better readibility
|
||||
void adjustPalette();
|
||||
|
||||
//! Style sheets have been changed
|
||||
void onStyleSheetsChanged();
|
||||
|
||||
//! Set current font values
|
||||
void setCurrentFontValues();
|
||||
};
|
||||
} // ns
|
||||
|
||||
|
||||
Reference in New Issue
Block a user