File indexing completed on 2024-04-28 16:44:34

0001 /*
0002  * SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005  */
0006 #pragma once
0007 
0008 #include "decorationbutton.h"
0009 #include <kdecoration2/kdecoration2_export.h>
0010 
0011 #include <QFontMetricsF>
0012 #include <QObject>
0013 
0014 #include <memory>
0015 
0016 namespace KDecoration2
0017 {
0018 class DecorationBridge;
0019 class DecorationSettingsPrivate;
0020 
0021 /**
0022  * @brief Common settings for the Decoration.
0023  *
0024  * This class gets injected into the Decoration and provides recommendations for the
0025  * Decoration. The Decoration is suggested to honor the settings, but may decide that some
0026  * settings don't fit the design and ignore them.
0027  *
0028  * @see Decoration
0029  **/
0030 class KDECORATIONS2_EXPORT DecorationSettings : public QObject
0031 {
0032     Q_OBJECT
0033     /**
0034      * Whether the feature to put a DecoratedClient on all desktops is available.
0035      *
0036      * If this feature is not available a Decoration might decide to not show the
0037      * DecorationButtonType::OnAllDesktops.
0038      **/
0039     Q_PROPERTY(bool onAllDesktopsAvailable READ isOnAllDesktopsAvailable NOTIFY onAllDesktopsAvailableChanged)
0040     /**
0041      * Whether the Decoration will be rendered with an alpha channel.
0042      *
0043      * If no alpha channel is available a Decoration should not use round borders.
0044      **/
0045     Q_PROPERTY(bool alphaChannelSupported READ isAlphaChannelSupported NOTIFY alphaChannelSupportedChanged)
0046     /**
0047      * Whether the Decoration should close the DecoratedClient when double clicking on the
0048      * DecorationButtonType::Menu.
0049      **/
0050     Q_PROPERTY(bool closeOnDoubleClickOnMenu READ isCloseOnDoubleClickOnMenu NOTIFY closeOnDoubleClickOnMenuChanged)
0051     /**
0052      * The suggested ordering of the decoration buttons on the left.
0053      **/
0054     Q_PROPERTY(QVector<KDecoration2::DecorationButtonType> decorationButtonsLeft READ decorationButtonsLeft NOTIFY decorationButtonsLeftChanged)
0055     /**
0056      * The suggested ordering of the decoration buttons on the right.
0057      **/
0058     Q_PROPERTY(QVector<KDecoration2::DecorationButtonType> decorationButtonsRight READ decorationButtonsRight NOTIFY decorationButtonsRightChanged)
0059     /**
0060      * The suggested border size.
0061      **/
0062     Q_PROPERTY(KDecoration2::BorderSize borderSize READ borderSize NOTIFY borderSizeChanged)
0063     /**
0064      * The fundamental unit of space that should be used for sizes, expressed in pixels.
0065      * Given the screen has an accurate DPI settings, it corresponds to a millimeter
0066      */
0067     Q_PROPERTY(int gridUnit READ gridUnit NOTIFY gridUnitChanged)
0068     /**
0069      * The recommended font for the Decoration's caption.
0070      **/
0071     Q_PROPERTY(QFont font READ font NOTIFY fontChanged)
0072     /**
0073      * smallSpacing is the amount of spacing that should be used around smaller UI elements,
0074      * for example as spacing in Columns. Internally, this size depends on the size of
0075      * the default font as rendered on the screen, so it takes user-configured font size and DPI
0076      * into account.
0077      */
0078     Q_PROPERTY(int smallSpacing READ smallSpacing NOTIFY spacingChanged)
0079 
0080     /**
0081      * largeSpacing is the amount of spacing that should be used inside bigger UI elements,
0082      * for example between an icon and the corresponding text. Internally, this size depends on
0083      * the size of the default font as rendered on the screen, so it takes user-configured font
0084      * size and DPI into account.
0085      */
0086     Q_PROPERTY(int largeSpacing READ largeSpacing NOTIFY spacingChanged)
0087 public:
0088     explicit DecorationSettings(DecorationBridge *bridge, QObject *parent = nullptr);
0089     ~DecorationSettings() override;
0090     bool isOnAllDesktopsAvailable() const;
0091     bool isAlphaChannelSupported() const;
0092     bool isCloseOnDoubleClickOnMenu() const;
0093     QVector<DecorationButtonType> decorationButtonsLeft() const;
0094     QVector<DecorationButtonType> decorationButtonsRight() const;
0095     BorderSize borderSize() const;
0096 
0097     QFont font() const;
0098     /**
0099      * The fontMetrics for the recommended font.
0100      * @see font
0101      **/
0102     QFontMetricsF fontMetrics() const;
0103 
0104     int gridUnit() const;
0105     int smallSpacing() const;
0106     int largeSpacing() const;
0107 
0108 Q_SIGNALS:
0109     void onAllDesktopsAvailableChanged(bool);
0110     void alphaChannelSupportedChanged(bool);
0111     void closeOnDoubleClickOnMenuChanged(bool);
0112     void decorationButtonsLeftChanged(const QVector<KDecoration2::DecorationButtonType> &);
0113     void decorationButtonsRightChanged(const QVector<KDecoration2::DecorationButtonType> &);
0114     void borderSizeChanged(KDecoration2::BorderSize size);
0115     void fontChanged(const QFont &font);
0116     void gridUnitChanged(int);
0117     void spacingChanged();
0118 
0119     /**
0120      * This signal is emitted when the backend got reconfigured.
0121      * If the plugin uses custom settings, it is recommended to re-read
0122      * them after this signal got emitted.
0123      **/
0124     void reconfigured();
0125 
0126 private:
0127     const std::unique_ptr<DecorationSettingsPrivate> d;
0128 };
0129 
0130 }
0131 
0132 Q_DECLARE_METATYPE(KDecoration2::BorderSize)