Skip to content

Commit

Permalink
Format all code
Browse files Browse the repository at this point in the history
  • Loading branch information
plfiorini committed Feb 8, 2024
1 parent 8c99ab3 commit e9d255f
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 66 deletions.
49 changes: 29 additions & 20 deletions src/plugins/decorations/material/materialdecoration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ QMargins QWaylandMaterialDecoration::margins(MarginsType marginsType) const
// Title bar is 32dp plus borders
if (window() && window()->type() == Qt::Popup)
return QMargins(0, 0, 0, 0);
if (window() && ((window()->windowStates() & Qt::WindowMaximized) || (window()->windowStates() & Qt::WindowFullScreen)))
if (window()
&& ((window()->windowStates() & Qt::WindowMaximized)
|| (window()->windowStates() & Qt::WindowFullScreen)))
return QMargins(0, TITLE_BAR_HEIGHT, 0, 0);
return QMargins(WINDOW_BORDER, TITLE_BAR_HEIGHT, WINDOW_BORDER, WINDOW_BORDER);
}
Expand Down Expand Up @@ -145,15 +147,18 @@ void QWaylandMaterialDecoration::paint(QPaintDevice *device)
int radius = window()->windowStates() & Qt::WindowMaximized ? 0 : dp(3);
QPainterPath roundedRect;
roundedRect.addRoundedRect(margins().left(), margins().top() - TITLE_BAR_HEIGHT,
frameGeometry.width() - margins().left() - margins().right(), TITLE_BAR_HEIGHT + radius * 2,
radius, radius);
frameGeometry.width() - margins().left() - margins().right(),
TITLE_BAR_HEIGHT + radius * 2, radius, radius);
p.fillPath(roundedRect.simplified(), m_backgroundColor);

// Borders (transparent so the border is not noticeable)
QPainterPath borderPath;
borderPath.addRect(0, margins().top(), margins().left(), frameGeometry.height() - margins().top());
borderPath.addRect(0, frameGeometry.height() - margins().bottom(), frameGeometry.width(), margins().bottom());
borderPath.addRect(frameGeometry.width() - margins().right(), margins().top(), margins().right(), frameGeometry.height() - margins().bottom());
borderPath.addRect(0, margins().top(), margins().left(),
frameGeometry.height() - margins().top());
borderPath.addRect(0, frameGeometry.height() - margins().bottom(), frameGeometry.width(),
margins().bottom());
borderPath.addRect(frameGeometry.width() - margins().right(), margins().top(),
margins().right(), frameGeometry.height() - margins().bottom());
p.fillPath(borderPath, Qt::transparent);

// Window title
Expand Down Expand Up @@ -195,7 +200,8 @@ void QWaylandMaterialDecoration::paint(QPaintDevice *device)
rect = closeButtonRect();
qreal crossSize = rect.height() / 2.3;
QPointF crossCenter(rect.center());
QRectF crossRect(crossCenter.x() - crossSize / 2, crossCenter.y() - crossSize / 2, crossSize, crossSize);
QRectF crossRect(crossCenter.x() - crossSize / 2, crossCenter.y() - crossSize / 2,
crossSize, crossSize);
pen.setWidth(2);
p.setPen(pen);
p.drawLine(crossRect.topLeft(), crossRect.bottomRight());
Expand Down Expand Up @@ -229,7 +235,8 @@ void QWaylandMaterialDecoration::paint(QPaintDevice *device)
lines.append(QLineF(rect.left(), rect.top() + 2, rect.left(), rect.bottom() - 2));
lines.append(QLineF(rect.right(), rect.top() + 2, rect.right(), rect.bottom() - 2));
lines.append(QLineF(rect.bottomLeft(), rect.bottomRight()));
lines.append(QLineF(rect.left() + 2, rect.top() + 2, rect.right() - 2, rect.top() + 2));
lines.append(
QLineF(rect.left() + 2, rect.top() + 2, rect.right() - 2, rect.top() + 2));
p.drawLines(lines);
}
p.restore();
Expand Down Expand Up @@ -277,8 +284,9 @@ bool QWaylandMaterialDecoration::handleMouse(QWaylandInputDevice *inputDevice, c
QWindowSystemInterface::handleCloseEvent(window());
} else if (isMaximizeable() && maximizeButtonRect().contains(local)) {
if (clickButton(b, Maximize))
window()->setWindowState(window()->windowStates() & Qt::WindowMaximized ? Qt::WindowNoState
: Qt::WindowMaximized);
window()->setWindowState(window()->windowStates() & Qt::WindowMaximized
? Qt::WindowNoState
: Qt::WindowMaximized);
} else if (minimizeButtonRect().contains(local)) {
if (clickButton(b, Minimize))
window()->setWindowState(Qt::WindowMinimized);
Expand All @@ -300,7 +308,9 @@ bool QWaylandMaterialDecoration::handleMouse(QWaylandInputDevice *inputDevice, c
return true;
}

bool QWaylandMaterialDecoration::handleTouch(QWaylandInputDevice *inputDevice, const QPointF &local, const QPointF &global, QEventPoint::State state, Qt::KeyboardModifiers mods)
bool QWaylandMaterialDecoration::handleTouch(QWaylandInputDevice *inputDevice, const QPointF &local,
const QPointF &global, QEventPoint::State state,
Qt::KeyboardModifiers mods)
{
Q_UNUSED(inputDevice);
Q_UNUSED(global);
Expand All @@ -311,8 +321,9 @@ bool QWaylandMaterialDecoration::handleTouch(QWaylandInputDevice *inputDevice, c
if (closeButtonRect().contains(local))
QWindowSystemInterface::handleCloseEvent(window());
else if (isMaximizeable() && maximizeButtonRect().contains(local))
window()->setWindowState(window()->windowStates() & Qt::WindowMaximized ? Qt::WindowNoState
: Qt::WindowMaximized);
window()->setWindowState(window()->windowStates() & Qt::WindowMaximized
? Qt::WindowNoState
: Qt::WindowMaximized);
else if (minimizeButtonRect().contains(local))
window()->setWindowState(Qt::WindowMinimized);
else if (local.y() <= margins().top())
Expand Down Expand Up @@ -430,18 +441,16 @@ int QWaylandMaterialDecoration::dp(int dp) const

bool QWaylandMaterialDecoration::isMinimizeable() const
{
return window()->flags() & Qt::WindowMinimizeButtonHint ||
window()->isTopLevel();
return window()->flags() & Qt::WindowMinimizeButtonHint || window()->isTopLevel();
}

bool QWaylandMaterialDecoration::isMaximizeable() const
{
return window()->flags() & Qt::WindowMaximizeButtonHint || (
(window()->maximumSize().width() > window()->minimumSize().width()) &&
(window()->maximumSize().height() > window()->minimumSize().height())
);
return window()->flags() & Qt::WindowMaximizeButtonHint
|| ((window()->maximumSize().width() > window()->minimumSize().width())
&& (window()->maximumSize().height() > window()->minimumSize().height()));
}

}
} // namespace QtWaylandClient

QT_END_NAMESPACE
11 changes: 5 additions & 6 deletions src/plugins/decorations/material/materialdecoration.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@

QT_BEGIN_NAMESPACE

namespace QtWaylandClient
{
namespace QtWaylandClient {

enum Button
{
enum Button {
None,
Close,
Maximize,
Expand All @@ -34,7 +32,8 @@ enum Button
class Q_WAYLANDCLIENT_EXPORT QWaylandMaterialDecoration : public QWaylandAbstractDecoration
{
Q_OBJECT
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY
backgroundColorChanged)
Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor NOTIFY textColorChanged)
Q_PROPERTY(QColor iconColor READ iconColor WRITE setIconColor NOTIFY iconColorChanged)
public:
Expand Down Expand Up @@ -90,4 +89,4 @@ class Q_WAYLANDCLIENT_EXPORT QWaylandMaterialDecoration : public QWaylandAbstrac
QColor m_textColor;
QStaticText m_windowTitle;
};
}
} // namespace QtWaylandClient
45 changes: 22 additions & 23 deletions src/plugins/platformtheme/hintssettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,12 @@ HintsSettings::HintsSettings(QObject *parent)

// Change only the few hints involved, for some of these settings
// we need to take actions to refresh applications
connect(m_settings, &QtGSettings::QGSettings::settingChanged, this,
[this](const QString &key) {
connect(m_settings, &QtGSettings::QGSettings::settingChanged, this, [this](const QString &key) {
if (key == QStringLiteral("cursorBlinkTime"))
qtSettingsChanged();
else if (key == QStringLiteral("toolButtonStyle"))
toolButtonStyleChanged();
else if (key == QStringLiteral("iconTheme") ||
key == QStringLiteral("toolbarIconsSize"))
else if (key == QStringLiteral("iconTheme") || key == QStringLiteral("toolbarIconsSize"))
iconChanged();
else if (key == QStringLiteral("widgetsStyle"))
styleChanged();
Expand Down Expand Up @@ -139,33 +137,29 @@ void HintsSettings::collectHints()
m_hints.insert(QPlatformTheme::UseFullScreenForPopupMenu, true);
// TODO: Use the Mac keyboard scheme only if an Apple keyboard is detected
// int(MacKeyboardScheme);
m_hints.insert(QPlatformTheme::KeyboardScheme,
int(QPlatformTheme::GnomeKeyboardScheme));
m_hints.insert(QPlatformTheme::UiEffects,
QPlatformTheme::AnimateMenuUiEffect |
QPlatformTheme::FadeMenuUiEffect |
QPlatformTheme::AnimateComboUiEffect |
QPlatformTheme::AnimateTooltipUiEffect |
QPlatformTheme::FadeTooltipUiEffect |
QPlatformTheme::AnimateToolBoxUiEffect);
m_hints.insert(QPlatformTheme::KeyboardScheme, int(QPlatformTheme::GnomeKeyboardScheme));
m_hints.insert(
QPlatformTheme::UiEffects,
QPlatformTheme::AnimateMenuUiEffect | QPlatformTheme::FadeMenuUiEffect
| QPlatformTheme::AnimateComboUiEffect | QPlatformTheme::AnimateTooltipUiEffect
| QPlatformTheme::FadeTooltipUiEffect | QPlatformTheme::AnimateToolBoxUiEffect);
m_hints.insert(QPlatformTheme::SpellCheckUnderlineStyle,
int(QTextCharFormat::SpellCheckUnderline));
m_hints.insert(QPlatformTheme::TabFocusBehavior, int(Qt::TabFocusAllControls));
m_hints.insert(QPlatformTheme::MouseCursorTheme, m_settings->value("cursorTheme"_L1));
m_hints.insert(QPlatformTheme::MouseCursorSize, m_settings->value("cursorSize"_L1));
QList<int> pixmapSizes;
pixmapSizes
<< 512 << 256 << 128 << 96 << 64 << 48
<< 32 << 24 << 22 << 16;
pixmapSizes << 512 << 256 << 128 << 96 << 64 << 48 << 32 << 24 << 22 << 16;
m_hints.insert(QPlatformTheme::IconPixmapSizes, QVariant::fromValue(pixmapSizes));
}

void HintsSettings::refreshPalette()
{
// Locate color scheme
QString scheme = m_settings->value(QStringLiteral("colorScheme")).toString();
QString schemeFileName = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
QStringLiteral("color-schemes/%1.colors").arg(scheme));
QString schemeFileName =
QStandardPaths::locate(QStandardPaths::GenericDataLocation,
QStringLiteral("color-schemes/%1.colors").arg(scheme));

// Palette
QPalette systemPalette = QPalette();
Expand All @@ -189,25 +183,29 @@ void HintsSettings::refreshFonts()
if (QFont *systemFont = readFont(fontFamily, fontSize))
m_resources.fonts[QPlatformTheme::SystemFont] = systemFont;
else
m_resources.fonts[QPlatformTheme::SystemFont] = new QFont(QLatin1String(defaultSystemFontName), defaultSystemFontSize);
m_resources.fonts[QPlatformTheme::SystemFont] =
new QFont(QLatin1String(defaultSystemFontName), defaultSystemFontSize);

// Monospace font
if (QFont *monospaceFont = readFont(monospaceFontFamily, monospaceFontSize))
m_resources.fonts[QPlatformTheme::FixedFont] = monospaceFont;
else
m_resources.fonts[QPlatformTheme::FixedFont] = new QFont(QLatin1String(defaultMonospaceFontName), defaultMonospaceFontSize);
m_resources.fonts[QPlatformTheme::FixedFont] =
new QFont(QLatin1String(defaultMonospaceFontName), defaultMonospaceFontSize);

// Small font
if (QFont *smallFont = readFont(smallFontFamily, smallFontSize))
m_resources.fonts[QPlatformTheme::SmallFont] = smallFont;
else
m_resources.fonts[QPlatformTheme::SmallFont] = new QFont(QLatin1String(defaultSystemFontName), defaultSystemFontSize);
m_resources.fonts[QPlatformTheme::SmallFont] =
new QFont(QLatin1String(defaultSystemFontName), defaultSystemFontSize);

// Mini font
if (QFont *miniFont = readFont(miniFontFamily, miniFontSize))
m_resources.fonts[QPlatformTheme::MiniFont] = miniFont;
else
m_resources.fonts[QPlatformTheme::MiniFont] = new QFont(QLatin1String(defaultSystemFontName), defaultSystemFontSize);
m_resources.fonts[QPlatformTheme::MiniFont] =
new QFont(QLatin1String(defaultSystemFontName), defaultSystemFontSize);

// Other fonts
QList<QPlatformTheme::Font> fonts;
Expand All @@ -217,7 +215,8 @@ void HintsSettings::refreshFonts()
if (QFont *systemFont = readFont(fontFamily, fontSize))
m_resources.fonts[font] = systemFont;
else
m_resources.fonts[font] = new QFont(QLatin1String(defaultSystemFontName), defaultSystemFontSize);
m_resources.fonts[font] =
new QFont(QLatin1String(defaultSystemFontName), defaultSystemFontSize);
m_resources.fonts[font]->setBold(true);
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/plugins/platformtheme/hintssettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ class HintsSettings : public QObject
explicit HintsSettings(QObject *parent = nullptr);
~HintsSettings();

inline QVariant themeHint(QPlatformTheme::ThemeHint hint) const {
inline QVariant themeHint(QPlatformTheme::ThemeHint hint) const
{
if (m_hints.contains(hint))
return m_hints[hint];
return QVariant();
}

inline QPalette *palette(QPlatformTheme::Palette type) const {
inline QPalette *palette(QPlatformTheme::Palette type) const
{
return m_resources.palettes[type];
}

inline QFont *font(QPlatformTheme::Font type) const {
inline QFont *font(QPlatformTheme::Font type) const
{
return m_resources.fonts[type];
}

Expand Down
3 changes: 2 additions & 1 deletion src/plugins/platformtheme/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
class LiriThemePlugin : public QPlatformThemePlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QPA.QPlatformThemeFactoryInterface.5.1" FILE "liritheme.json")
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QPA.QPlatformThemeFactoryInterface.5.1" FILE
"liritheme.json")
public:
explicit LiriThemePlugin(QObject *parent = 0);

Expand Down
36 changes: 24 additions & 12 deletions src/plugins/platformtheme/resourcehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,38 @@ void ResourceHelper::readPalette(const QString &fileName, QPalette *pal)
{
QSettings colorScheme(fileName, QSettings::IniFormat);

if (!readColor(pal, QPalette::Button, colorScheme.value(QStringLiteral("Colors:Button/BackgroundNormal")))) {
if (!readColor(pal, QPalette::Button,
colorScheme.value(QStringLiteral("Colors:Button/BackgroundNormal")))) {
// kcolorscheme.cpp: SetDefaultColors
const QColor defaultWindowBackground(214, 210, 208);
const QColor defaultButtonBackground(223, 220, 217);
*pal = QPalette(defaultButtonBackground, defaultWindowBackground);
return;
}

readColor(pal, QPalette::Window, colorScheme.value(QStringLiteral("Colors:Window/BackgroundNormal")));
readColor(pal, QPalette::Text, colorScheme.value(QStringLiteral("Colors:View/ForegroundNormal")));
readColor(pal, QPalette::WindowText, colorScheme.value(QStringLiteral("Colors:Window/ForegroundNormal")));
readColor(pal, QPalette::Base, colorScheme.value(QStringLiteral("Colors:View/BackgroundNormal")));
readColor(pal, QPalette::Highlight, colorScheme.value(QStringLiteral("Colors:Selection/BackgroundNormal")));
readColor(pal, QPalette::HighlightedText, colorScheme.value(QStringLiteral("Colors:Selection/ForegroundNormal")));
readColor(pal, QPalette::AlternateBase, colorScheme.value(QStringLiteral("Colors:View/BackgroundAlternate")));
readColor(pal, QPalette::ButtonText, colorScheme.value(QStringLiteral("Colors:Button/ForegroundNormal")));
readColor(pal, QPalette::Window,
colorScheme.value(QStringLiteral("Colors:Window/BackgroundNormal")));
readColor(pal, QPalette::Text,
colorScheme.value(QStringLiteral("Colors:View/ForegroundNormal")));
readColor(pal, QPalette::WindowText,
colorScheme.value(QStringLiteral("Colors:Window/ForegroundNormal")));
readColor(pal, QPalette::Base,
colorScheme.value(QStringLiteral("Colors:View/BackgroundNormal")));
readColor(pal, QPalette::Highlight,
colorScheme.value(QStringLiteral("Colors:Selection/BackgroundNormal")));
readColor(pal, QPalette::HighlightedText,
colorScheme.value(QStringLiteral("Colors:Selection/ForegroundNormal")));
readColor(pal, QPalette::AlternateBase,
colorScheme.value(QStringLiteral("Colors:View/BackgroundAlternate")));
readColor(pal, QPalette::ButtonText,
colorScheme.value(QStringLiteral("Colors:Button/ForegroundNormal")));
readColor(pal, QPalette::Link, colorScheme.value(QStringLiteral("Colors:View/ForegroundLink")));
readColor(pal, QPalette::LinkVisited, colorScheme.value(QStringLiteral("Colors:View/ForegroundVisited")));
readColor(pal, QPalette::ToolTipBase, colorScheme.value(QStringLiteral("Colors:Tooltip/BackgroundNormal")));
readColor(pal, QPalette::ToolTipText, colorScheme.value(QStringLiteral("Colors:Tooltip/ForegroundNormal")));
readColor(pal, QPalette::LinkVisited,
colorScheme.value(QStringLiteral("Colors:View/ForegroundVisited")));
readColor(pal, QPalette::ToolTipBase,
colorScheme.value(QStringLiteral("Colors:Tooltip/BackgroundNormal")));
readColor(pal, QPalette::ToolTipText,
colorScheme.value(QStringLiteral("Colors:Tooltip/ForegroundNormal")));

// Set all color roles to "normal" colors, but calculate disabled colors
const QColor button = pal->color(QPalette::Button);
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/platformtheme/resourcehelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class ResourceHelper
{
public:
explicit ResourceHelper();
~ResourceHelper() { clear(); }
~ResourceHelper()
{
clear();
}

void clear();

Expand Down

0 comments on commit e9d255f

Please sign in to comment.