1 /* 2 SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org> 3 4 SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 #ifndef KWIN_DECORATION_OPTIONS_H 7 #define KWIN_DECORATION_OPTIONS_H 8 9 #include <KDecoration2/Decoration> 10 11 #include <QObject> 12 #include <QColor> 13 #include <QFont> 14 #include <QPalette> 15 16 namespace KWin 17 { 18 19 // TODO: move to deco API 20 class ColorSettings 21 { 22 public: 23 ColorSettings(const QPalette &pal); 24 25 void update(const QPalette &pal); 26 titleBarColor(bool active)27 const QColor &titleBarColor(bool active) const { 28 return active ? m_activeTitleBarColor : m_inactiveTitleBarColor; 29 } activeTitleBarColor()30 const QColor &activeTitleBarColor() const { 31 return m_activeTitleBarColor; 32 } inactiveTitleBarColor()33 const QColor &inactiveTitleBarColor() const { 34 return m_inactiveTitleBarColor; 35 } activeTitleBarBlendColor()36 const QColor &activeTitleBarBlendColor() const { 37 return m_activeTitleBarBlendColor; 38 } inactiveTitleBarBlendColor()39 const QColor &inactiveTitleBarBlendColor() const { 40 return m_inactiveTitleBarBlendColor; 41 } frame(bool active)42 const QColor &frame(bool active) const { 43 return active ? m_activeFrameColor : m_inactiveFrameColor; 44 } activeFrame()45 const QColor &activeFrame() const { 46 return m_activeFrameColor; 47 } inactiveFrame()48 const QColor &inactiveFrame() const { 49 return m_inactiveFrameColor; 50 } font(bool active)51 const QColor &font(bool active) const { 52 return active ? m_activeFontColor : m_inactiveFontColor; 53 } activeFont()54 const QColor &activeFont() const { 55 return m_activeFontColor; 56 } inactiveFont()57 const QColor &inactiveFont() const { 58 return m_inactiveFontColor; 59 } activeButtonColor()60 const QColor &activeButtonColor() const { 61 return m_activeButtonColor; 62 } inactiveButtonColor()63 const QColor &inactiveButtonColor() const { 64 return m_inactiveButtonColor; 65 } activeHandle()66 const QColor &activeHandle() const { 67 return m_activeHandle; 68 } inactiveHandle()69 const QColor &inactiveHandle() const { 70 return m_inactiveHandle; 71 } palette()72 const QPalette &palette() const { 73 return m_palette; 74 } 75 private: 76 void init(const QPalette &pal); 77 QColor m_activeTitleBarColor; 78 QColor m_inactiveTitleBarColor; 79 QColor m_activeTitleBarBlendColor; 80 QColor m_inactiveTitleBarBlendColor; 81 QColor m_activeFrameColor; 82 QColor m_inactiveFrameColor; 83 QColor m_activeFontColor; 84 QColor m_inactiveFontColor; 85 QColor m_activeButtonColor; 86 QColor m_inactiveButtonColor; 87 QColor m_activeHandle; 88 QColor m_inactiveHandle; 89 QPalette m_palette; 90 }; 91 92 /** 93 * @short Common Window Decoration Options. 94 * 95 * This Class provides common window decoration options which can be used, but do not have to 96 * be used by a window decoration. The class provides properties for global settings such as 97 * color, font and decoration button position. 98 * 99 * If a window decoration wants to follow the global color scheme it should honor the values 100 * provided by the properties. 101 * 102 * In any case it makes sense to respect the font settings for the decoration as this is also 103 * an accessibility feature. 104 * 105 * In order to use the options in a QML based window decoration an instance of this object needs 106 * to be created and the as a context property available "decoration" needs to be passed to the 107 * DecorationOptions instance: 108 * 109 * @code 110 * DecorationOptions { 111 * id: options 112 * deco: decoration 113 * } 114 * @endcode 115 */ 116 class DecorationOptions : public QObject 117 { 118 Q_OBJECT 119 /** 120 * The decoration Object for which this set of options should be used. The decoration is 121 * required to get the correct colors and fonts depending on whether the decoration represents 122 * an active or inactive window. 123 * 124 * Best pass the decoration object available as a context property to this property. 125 */ 126 Q_PROPERTY(KDecoration2::Decoration *deco READ decoration WRITE setDecoration NOTIFY decorationChanged) 127 /** 128 * The color for the titlebar depending on the decoration's active state. 129 */ 130 Q_PROPERTY(QColor titleBarColor READ titleBarColor NOTIFY colorsChanged) 131 /** 132 * The blend color for the titlebar depending on the decoration's active state. 133 */ 134 Q_PROPERTY(QColor titleBarBlendColor READ titleBarBlendColor NOTIFY colorsChanged) 135 /** 136 * The titlebar text color depending on the decoration's active state. 137 */ 138 Q_PROPERTY(QColor fontColor READ fontColor NOTIFY colorsChanged) 139 /** 140 * The color to use for titlebar buttons depending on the decoration's active state. 141 */ 142 Q_PROPERTY(QColor buttonColor READ buttonColor NOTIFY colorsChanged) 143 /** 144 * The color for the window frame (border) depending on the decoration's active state. 145 */ 146 Q_PROPERTY(QColor borderColor READ borderColor NOTIFY colorsChanged) 147 /** 148 * The color for the resize handle depending on the decoration's active state. 149 */ 150 Q_PROPERTY(QColor resizeHandleColor READ resizeHandleColor NOTIFY colorsChanged) 151 /** 152 * The font to be used for the decoration caption depending on the decoration's active state. 153 */ 154 Q_PROPERTY(QFont titleFont READ titleFont NOTIFY fontChanged) 155 /** 156 * The buttons to be positioned on the left side of the titlebar from left to right. 157 */ 158 Q_PROPERTY(QList<int> titleButtonsLeft READ titleButtonsLeft NOTIFY titleButtonsChanged) 159 /** 160 * The buttons to be positioned on the right side of the titlebar from left to right. 161 */ 162 Q_PROPERTY(QList<int> titleButtonsRight READ titleButtonsRight NOTIFY titleButtonsChanged) 163 Q_PROPERTY(int mousePressAndHoldInterval READ mousePressAndHoldInterval CONSTANT) 164 public: 165 enum BorderSize { 166 BorderNone, ///< No borders except title 167 BorderNoSides, ///< No borders on sides 168 BorderTiny, ///< Minimal borders 169 BorderNormal, ///< Standard size borders, the default setting 170 BorderLarge, ///< Larger borders 171 BorderVeryLarge, ///< Very large borders 172 BorderHuge, ///< Huge borders 173 BorderVeryHuge, ///< Very huge borders 174 BorderOversized ///< Oversized borders 175 }; 176 Q_ENUM(BorderSize) 177 /** 178 * Enum values to identify the decorations buttons which should be used 179 * by the decoration. 180 * 181 */ 182 enum DecorationButton { 183 /** 184 * Invalid button value. A decoration should not create a button for 185 * this type. 186 */ 187 DecorationButtonNone, 188 DecorationButtonMenu, 189 DecorationButtonApplicationMenu, 190 DecorationButtonOnAllDesktops, 191 DecorationButtonQuickHelp, 192 DecorationButtonMinimize, 193 DecorationButtonMaximizeRestore, 194 DecorationButtonClose, 195 DecorationButtonKeepAbove, 196 DecorationButtonKeepBelow, 197 DecorationButtonShade, 198 DecorationButtonResize, 199 /** 200 * The decoration should create an empty spacer instead of a button for 201 * this type. 202 */ 203 DecorationButtonExplicitSpacer 204 }; 205 Q_ENUM(DecorationButton) 206 explicit DecorationOptions(QObject *parent = nullptr); 207 ~DecorationOptions() override; 208 209 QColor titleBarColor() const; 210 QColor titleBarBlendColor() const; 211 QColor fontColor() const; 212 QColor buttonColor() const; 213 QColor borderColor() const; 214 QColor resizeHandleColor() const; 215 QFont titleFont() const; 216 QList<int> titleButtonsLeft() const; 217 QList<int> titleButtonsRight() const; 218 KDecoration2::Decoration *decoration() const; 219 void setDecoration(KDecoration2::Decoration *decoration); 220 221 int mousePressAndHoldInterval() const; 222 223 Q_SIGNALS: 224 void colorsChanged(); 225 void fontChanged(); 226 void decorationChanged(); 227 void titleButtonsChanged(); 228 229 private Q_SLOTS: 230 void slotActiveChanged(); 231 232 private: 233 bool m_active; 234 KDecoration2::Decoration *m_decoration; 235 ColorSettings m_colors; 236 QMetaObject::Connection m_paletteConnection; 237 }; 238 239 class Borders : public QObject 240 { 241 Q_OBJECT 242 Q_PROPERTY(int left READ left WRITE setLeft NOTIFY leftChanged) 243 Q_PROPERTY(int right READ right WRITE setRight NOTIFY rightChanged) 244 Q_PROPERTY(int top READ top WRITE setTop NOTIFY topChanged) 245 Q_PROPERTY(int bottom READ bottom WRITE setBottom NOTIFY bottomChanged) 246 public: 247 Borders(QObject *parent = nullptr); 248 ~Borders() override; 249 int left() const; 250 int right() const; 251 int top() const; 252 int bottom() const; 253 254 void setLeft(int left); 255 void setRight(int right); 256 void setTop(int top); 257 void setBottom(int bottom); 258 259 operator QMargins() const; 260 261 public Q_SLOTS: 262 /** 263 * Sets all four borders to @p value. 264 */ 265 void setAllBorders(int value); 266 /** 267 * Sets all borders except the title border to @p value. 268 */ 269 void setBorders(int value); 270 /** 271 * Sets the side borders (e.g. if title is on top, the left and right borders) 272 * to @p value. 273 */ 274 void setSideBorders(int value); 275 /** 276 * Sets the title border to @p value. 277 */ 278 void setTitle(int value); 279 280 Q_SIGNALS: 281 void leftChanged(); 282 void rightChanged(); 283 void topChanged(); 284 void bottomChanged(); 285 286 private: 287 int m_left; 288 int m_right; 289 int m_top; 290 int m_bottom; 291 }; 292 293 #define GETTER( name ) \ 294 inline int Borders::name() const \ 295 { \ 296 return m_##name;\ 297 }\ 298 299 GETTER(left) 300 GETTER(right) 301 GETTER(top) 302 GETTER(bottom) 303 304 #undef GETTER 305 306 } // namespace 307 #endif // KWIN_DECORATION_OPTIONS_H 308