KDecoration2

decorationsettings.cpp
1 /*
2  * SPDX-FileCopyrightText: 2014 Martin Gräßlin <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5  */
6 #include "decorationsettings.h"
7 #include "private/decorationbridge.h"
8 #include "private/decorationsettingsprivate.h"
9 
10 #include <QFontMetrics>
11 
12 namespace KDecoration2
13 {
14 DecorationSettings::DecorationSettings(DecorationBridge *bridge, QObject *parent)
15  : QObject(parent)
16  , d(std::move(bridge->settings(this)))
17 {
18  auto updateUnits = [this] {
19  int gridUnit = QFontMetrics(font()).boundingRect(QLatin1Char('M')).height();
20  ;
21  if (gridUnit % 2 != 0) {
22  gridUnit++;
23  }
24  if (gridUnit != d->gridUnit()) {
25  d->setGridUnit(gridUnit);
26  Q_EMIT gridUnitChanged(gridUnit);
27  }
28  if (gridUnit != d->largeSpacing()) {
29  d->setSmallSpacing(qMax(2, (int)(gridUnit / 4))); // 1/4 of gridUnit, at least 2
30  d->setLargeSpacing(gridUnit); // msize.height
31  Q_EMIT spacingChanged();
32  }
33  };
34  updateUnits();
35  connect(this, &DecorationSettings::fontChanged, this, updateUnits);
36 }
37 
38 DecorationSettings::~DecorationSettings() = default;
39 
40 #define DELEGATE(type, method) \
41  type DecorationSettings::method() const \
42  { \
43  return d->method(); \
44  }
45 
46 DELEGATE(bool, isOnAllDesktopsAvailable)
47 DELEGATE(bool, isAlphaChannelSupported)
48 DELEGATE(bool, isCloseOnDoubleClickOnMenu)
49 DELEGATE(QVector<DecorationButtonType>, decorationButtonsLeft)
50 DELEGATE(QVector<DecorationButtonType>, decorationButtonsRight)
51 DELEGATE(BorderSize, borderSize)
52 DELEGATE(QFont, font)
53 DELEGATE(QFontMetricsF, fontMetrics)
54 DELEGATE(int, gridUnit)
55 DELEGATE(int, smallSpacing)
56 DELEGATE(int, largeSpacing)
57 
58 #undef DELEGATE
59 
60 }
Framework for creating window decorations.
DecorationButtonType
The DecorationButtonType is a helper type for the DecorationButton.
int height() const const
QRect boundingRect(QChar ch) const const
BorderSize
Border sizes are a combination of visual and accessibility features.
KIOCORE_EXPORT CopyJob * move(const QUrl &src, const QUrl &dest, JobFlags flags=DefaultFlags)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Jun 19 2021 23:08:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.