feat: add setDotsPerInch/dotsPerInch functions for DPlatformTheme

This commit is contained in:
zccrs 2019-12-19 23:04:15 +08:00
parent 9e57aa6736
commit cca21c5e51
2 changed files with 58 additions and 0 deletions

View File

@ -45,6 +45,25 @@ void DPlatformThemePrivate::_q_onThemePropertyChanged(const QByteArray &name, co
return;
}
if (name.startsWith("Qt/DPI/")) {
const QString &screen_name = QString::fromLocal8Bit(name.mid(7));
if (!screen_name.isEmpty()) {
bool ok = false;
int dpi = value.toInt(&ok);
Q_EMIT q->dotsPerInchChanged(screen_name, ok ? dpi : -1);
}
return;
}
if (QByteArrayLiteral("Xft/DPI") == name) {
bool ok = false;
int dpi = value.toInt(&ok);
Q_EMIT q->dotsPerInchChanged(QString(), ok ? dpi : -1);
}
const QByteArrayList &list = name.split('/');
if (list.count() != 2)
@ -313,6 +332,12 @@ void DPlatformTheme::setPalette(const DPalette &palette)
if (d->fallbackProperty && !value.isValid() && d->parent) \
return d->parent->Function(); \
#define FETCH_PROPERTY_WITH_ARGS(Name, Function, Args) \
D_DC(DPlatformTheme); \
QVariant value = d->theme->getSetting(Name); \
if (d->fallbackProperty && !value.isValid() && d->parent) \
return d->parent->Function(Args); \
int DPlatformTheme::cursorBlinkTime() const
{
FETCH_PROPERTY("Net/CursorBlinkTime", cursorBlinkTime)
@ -553,6 +578,23 @@ QColor DPlatformTheme::frameBorder() const
return GET_COLOR(frameBorder);
}
int DPlatformTheme::dotsPerInch(const QString &screenName) const
{
bool ok = false;
if (!screenName.isEmpty()) {
FETCH_PROPERTY_WITH_ARGS("Qt/DPI/" + screenName.toLocal8Bit(), dotsPerInch, screenName);
int dpi = value.toInt(&ok);
if (ok)
return dpi;
}
FETCH_PROPERTY_WITH_ARGS("Xft/DPI", dotsPerInch, screenName);
int dpi = value.toInt(&ok);
return ok ? dpi : -1;
}
void DPlatformTheme::setCursorBlinkTime(int cursorBlinkTime)
{
D_D(DPlatformTheme);
@ -788,6 +830,17 @@ void DPlatformTheme::setFrameBorder(const QColor &frameBorder)
SET_COLOR(frameBorder);
}
void DPlatformTheme::setDotsPerInch(const QString &screenName, int dpi)
{
D_D(DPlatformTheme);
if (screenName.isEmpty()) {
d->theme->setSetting("Xft/DPI", dpi);
} else {
d->theme->setSetting("Qt/DPI/" + screenName.toLocal8Bit(), dpi);
}
}
DGUI_END_NAMESPACE
#include "moc_dplatformtheme.cpp"

View File

@ -140,6 +140,8 @@ public:
QColor darkLively() const;
QColor frameBorder() const;
int dotsPerInch(const QString &screenName = QString()) const;
public Q_SLOTS:
void setCursorBlinkTime(int cursorBlinkTime);
void setCursorBlinkTimeout(int cursorBlinkTimeout);
@ -183,6 +185,8 @@ public Q_SLOTS:
void setDarkLively(const QColor &darkLively);
void setFrameBorder(const QColor &frameBorder);
void setDotsPerInch(const QString &screenName, int dpi);
Q_SIGNALS:
void cursorBlinkTimeChanged(int cursorBlinkTime);
void cursorBlinkTimeoutChanged(int cursorBlinkTimeout);
@ -226,6 +230,7 @@ Q_SIGNALS:
void lightLivelyChanged(QColor lightLively);
void darkLivelyChanged(QColor darkLively);
void frameBorderChanged(QColor frameBorder);
void dotsPerInchChanged(const QString &screen, int dpi);
private:
friend class DPlatformThemePrivate;