1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 Thorben Kroeger <thorbenkroeger@gmail.com>.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25
26 #pragma once
27
28 #include "../utils_global.h"
29
30 #include <QBrush> // QGradientStops
31 #include <QObject>
32
33 QT_FORWARD_DECLARE_CLASS(QSettings)
QT_FORWARD_DECLARE_CLASS(QPalette)34 QT_FORWARD_DECLARE_CLASS(QPalette)
35
36 namespace Utils {
37
38 class ThemePrivate;
39
40 class QTCREATOR_UTILS_EXPORT Theme : public QObject
41 {
42 Q_OBJECT
43 public:
44 Theme(const QString &id, QObject *parent = nullptr);
45 ~Theme() override;
46
47 enum Color {
48 BackgroundColorAlternate,
49 BackgroundColorDark,
50 BackgroundColorHover,
51 BackgroundColorNormal,
52 BackgroundColorSelected,
53 BackgroundColorDisabled,
54 BadgeLabelBackgroundColorChecked,
55 BadgeLabelBackgroundColorUnchecked,
56 BadgeLabelTextColorChecked,
57 BadgeLabelTextColorUnchecked,
58 CanceledSearchTextColor,
59 ComboBoxArrowColor,
60 ComboBoxArrowColorDisabled,
61 ComboBoxTextColor,
62 DetailsButtonBackgroundColorHover,
63 DetailsWidgetBackgroundColor,
64 DockWidgetResizeHandleColor,
65 DoubleTabWidget1stSeparatorColor,
66 DoubleTabWidget1stTabActiveTextColor,
67 DoubleTabWidget1stTabBackgroundColor,
68 DoubleTabWidget1stTabInactiveTextColor,
69 DoubleTabWidget2ndSeparatorColor,
70 DoubleTabWidget2ndTabActiveTextColor,
71 DoubleTabWidget2ndTabBackgroundColor,
72 DoubleTabWidget2ndTabInactiveTextColor,
73 EditorPlaceholderColor,
74 FancyToolBarSeparatorColor,
75 FancyTabBarBackgroundColor,
76 FancyTabBarSelectedBackgroundColor,
77 FancyTabWidgetDisabledSelectedTextColor,
78 FancyTabWidgetDisabledUnselectedTextColor,
79 FancyTabWidgetEnabledSelectedTextColor,
80 FancyTabWidgetEnabledUnselectedTextColor,
81 FancyToolButtonHoverColor,
82 FancyToolButtonSelectedColor,
83 FutureProgressBackgroundColor,
84 InfoBarBackground,
85 InfoBarText, // TODO: Deprecate. Unused.
86 MenuBarEmptyAreaBackgroundColor,
87 MenuBarItemBackgroundColor,
88 MenuBarItemTextColorDisabled,
89 MenuBarItemTextColorNormal,
90 MenuItemTextColorDisabled,
91 MenuItemTextColorNormal,
92 MiniProjectTargetSelectorBackgroundColor, // TODO: Deprecate. -> Utils::StyleHelper().baseColor()
93 MiniProjectTargetSelectorBorderColor,
94 MiniProjectTargetSelectorSummaryBackgroundColor, // TODO: Deprecate. -> Utils::StyleHelper().baseColor()
95 MiniProjectTargetSelectorTextColor,
96 OutputPaneButtonFlashColor,
97 OutputPaneToggleButtonTextColorChecked,
98 OutputPaneToggleButtonTextColorUnchecked,
99 PanelStatusBarBackgroundColor,
100 PanelsWidgetSeparatorLineColor, // TODO: Deprecate. Unused.
101 PanelTextColorDark,
102 PanelTextColorMid,
103 PanelTextColorLight,
104 ProgressBarColorError,
105 ProgressBarColorFinished,
106 ProgressBarColorNormal,
107 ProgressBarTitleColor,
108 ProgressBarBackgroundColor,
109 SplitterColor,
110 TextColorDisabled,
111 TextColorError,
112 TextColorHighlight,
113 TextColorHighlightBackground,
114 TextColorLink,
115 TextColorLinkVisited,
116 TextColorNormal,
117 ToggleButtonBackgroundColor,
118 ToolBarBackgroundColor,
119 TreeViewArrowColorNormal,
120 TreeViewArrowColorSelected,
121
122 /* Palette for QPalette */
123
124 PaletteWindow,
125 PaletteWindowText,
126 PaletteBase,
127 PaletteAlternateBase,
128 PaletteToolTipBase,
129 PaletteToolTipText,
130 PaletteText,
131 PaletteButton,
132 PaletteButtonText,
133 PaletteBrightText,
134 PaletteHighlight,
135 PaletteHighlightedText,
136 PaletteLink,
137 PaletteLinkVisited,
138
139 PaletteLight,
140 PaletteMidlight,
141 PaletteDark,
142 PaletteMid,
143 PaletteShadow,
144
145 PaletteWindowDisabled,
146 PaletteWindowTextDisabled,
147 PaletteBaseDisabled,
148 PaletteAlternateBaseDisabled,
149 PaletteToolTipBaseDisabled,
150 PaletteToolTipTextDisabled,
151 PaletteTextDisabled,
152 PaletteButtonDisabled,
153 PaletteButtonTextDisabled,
154 PaletteBrightTextDisabled,
155 PaletteHighlightDisabled,
156 PaletteHighlightedTextDisabled,
157 PaletteLinkDisabled,
158 PaletteLinkVisitedDisabled,
159
160 PaletteLightDisabled,
161 PaletteMidlightDisabled,
162 PaletteDarkDisabled,
163 PaletteMidDisabled,
164 PaletteShadowDisabled,
165
166 /* Icons */
167
168 IconsBaseColor,
169 IconsDisabledColor,
170 IconsInfoColor,
171 IconsInfoToolBarColor,
172 IconsWarningColor,
173 IconsWarningToolBarColor,
174 IconsErrorColor,
175 IconsErrorToolBarColor,
176 IconsRunColor,
177 IconsRunToolBarColor,
178 IconsStopColor,
179 IconsStopToolBarColor,
180 IconsInterruptColor,
181 IconsInterruptToolBarColor,
182 IconsDebugColor,
183 IconsNavigationArrowsColor,
184 IconsBuildHammerHandleColor,
185 IconsBuildHammerHeadColor,
186 IconsModeWelcomeActiveColor,
187 IconsModeEditActiveColor,
188 IconsModeDesignActiveColor,
189 IconsModeDebugActiveColor,
190 IconsModeProjectActiveColor,
191 IconsModeAnalyzeActiveColor,
192 IconsModeHelpActiveColor,
193
194 /* Code model Icons */
195
196 IconsCodeModelKeywordColor,
197 IconsCodeModelClassColor,
198 IconsCodeModelStructColor,
199 IconsCodeModelFunctionColor,
200 IconsCodeModelVariableColor,
201 IconsCodeModelEnumColor,
202 IconsCodeModelMacroColor,
203 IconsCodeModelAttributeColor,
204 IconsCodeModelUniformColor,
205 IconsCodeModelVaryingColor,
206 IconsCodeModelOverlayBackgroundColor,
207 IconsCodeModelOverlayForegroundColor,
208
209 /* Code model text marks */
210
211 CodeModel_Error_TextMarkColor,
212 CodeModel_Warning_TextMarkColor,
213
214 /* Output panes */
215
216 OutputPanes_DebugTextColor,
217 OutputPanes_ErrorMessageTextColor,
218 OutputPanes_MessageOutput,
219 OutputPanes_NormalMessageTextColor,
220 OutputPanes_StdErrTextColor,
221 OutputPanes_StdOutTextColor,
222 OutputPanes_WarningMessageTextColor,
223 OutputPanes_TestPassTextColor,
224 OutputPanes_TestFailTextColor,
225 OutputPanes_TestXFailTextColor,
226 OutputPanes_TestXPassTextColor,
227 OutputPanes_TestSkipTextColor,
228 OutputPanes_TestWarnTextColor,
229 OutputPanes_TestFatalTextColor,
230 OutputPanes_TestDebugTextColor,
231
232 /* Debugger Log Window */
233
234 Debugger_LogWindow_LogInput,
235 Debugger_LogWindow_LogStatus,
236 Debugger_LogWindow_LogTime,
237
238 /* Debugger Watch Item */
239
240 Debugger_WatchItem_ValueNormal,
241 Debugger_WatchItem_ValueInvalid,
242 Debugger_WatchItem_ValueChanged,
243
244 /* Welcome Plugin */
245
246 Welcome_TextColor,
247 Welcome_ForegroundPrimaryColor,
248 Welcome_ForegroundSecondaryColor,
249 Welcome_BackgroundColor,
250 Welcome_ButtonBackgroundColor,
251 Welcome_DividerColor,
252 Welcome_LinkColor,
253 Welcome_HoverColor,
254 Welcome_DisabledLinkColor,
255
256 /* Timeline Library */
257 Timeline_TextColor,
258 Timeline_BackgroundColor1,
259 Timeline_BackgroundColor2,
260 Timeline_DividerColor,
261 Timeline_HighlightColor,
262 Timeline_PanelBackgroundColor,
263 Timeline_PanelHeaderColor,
264 Timeline_HandleColor,
265 Timeline_RangeColor,
266
267 /* VcsBase Plugin */
268 VcsBase_FileStatusUnknown_TextColor,
269 VcsBase_FileAdded_TextColor,
270 VcsBase_FileModified_TextColor,
271 VcsBase_FileDeleted_TextColor,
272 VcsBase_FileRenamed_TextColor,
273 VcsBase_FileUnmerged_TextColor,
274
275 /* Bookmarks Plugin */
276 Bookmarks_TextMarkColor,
277
278 /* TextEditor Plugin */
279 TextEditor_SearchResult_ScrollBarColor,
280 TextEditor_CurrentLine_ScrollBarColor,
281
282 /* Debugger Plugin */
283 Debugger_Breakpoint_TextMarkColor,
284
285 /* ProjectExplorer Plugin */
286 ProjectExplorer_TaskError_TextMarkColor,
287 ProjectExplorer_TaskWarn_TextMarkColor,
288
289 /* QmlDesigner Plugin */
290 QmlDesigner_BackgroundColor,
291 QmlDesigner_HighlightColor,
292 QmlDesigner_FormEditorSelectionColor,
293 QmlDesigner_FormEditorForegroundColor,
294 QmlDesigner_BackgroundColorDarker,
295 QmlDesigner_BackgroundColorDarkAlternate,
296 QmlDesigner_TabLight,
297 QmlDesigner_TabDark,
298 QmlDesigner_ButtonColor,
299 QmlDesigner_BorderColor,
300 QmlDesigner_FormeditorBackgroundColor,
301 QmlDesigner_AlternateBackgroundColor,
302 QmlDesigner_ScrollBarHandleColor,
303
304 /* Palette for DS Controls */
305
306 DSpanelBackground,
307 DSinteraction,
308 DSerrorColor,
309 DSdisabledColor,
310 DScontrolBackground,
311 DScontrolBackgroundInteraction,
312 DScontrolBackgroundDisabled,
313 DScontrolBackgroundGlobalHover,
314 DScontrolBackgroundHover,
315 DScontrolOutline,
316 DScontrolOutlineInteraction,
317 DScontrolOutlineDisabled,
318 DStextColor,
319 DStextColorDisabled,
320 DStextSelectionColor,
321 DStextSelectedTextColor,
322
323 DSplaceholderTextColor,
324 DSplaceholderTextColorInteraction,
325
326 DSiconColor,
327 DSiconColorHover,
328 DSiconColorInteraction,
329 DSiconColorDisabled,
330 DSiconColorSelected,
331 DSlinkIndicatorColor,
332 DSlinkIndicatorColorHover,
333 DSlinkIndicatorColorInteraction,
334 DSlinkIndicatorColorDisabled,
335 DSpopupBackground,
336 DSpopupOverlayColor,
337 DSsliderActiveTrack,
338 DSsliderActiveTrackHover,
339 DSsliderActiveTrackFocus,
340 DSsliderInactiveTrack,
341 DSsliderInactiveTrackHover,
342 DSsliderInactiveTrackFocus,
343 DSsliderHandle,
344 DSsliderHandleHover,
345 DSsliderHandleFocus,
346 DSsliderHandleInteraction,
347 DSscrollBarTrack,
348 DSscrollBarHandle,
349 DSsectionHeadBackground,
350 DSstateDefaultHighlight,
351 DSstateSeparatorColor,
352 DSstateBackgroundColor,
353 DSstatePreviewOutline,
354 DSchangedStateText,
355 DS3DAxisXColor,
356 DS3DAxisYColor,
357 DS3DAxisZColor,
358 DSactionBinding,
359 DSactionAlias,
360 DSactionKeyframe,
361 DSactionJIT,
362
363 DStableHeaderBackground,
364 DStableHeaderText,
365
366 DSdockContainerBackground,
367 DSdockContainerSplitter,
368 DSdockAreaBackground,
369
370 DSdockWidgetBackground,
371 DSdockWidgetSplitter,
372 DSdockWidgetTitleBar,
373
374 DStitleBarText,
375 DStitleBarIcon,
376 DStitleBarButtonHover,
377 DStitleBarButtonPress,
378
379 DStabContainerBackground,
380 DStabSplitter,
381
382 DStabInactiveBackground,
383 DStabInactiveText,
384 DStabInactiveIcon,
385 DStabInactiveButtonHover,
386 DStabInactiveButtonPress,
387
388 DStabActiveBackground,
389 DStabActiveText,
390 DStabActiveIcon,
391 DStabActiveButtonHover,
392 DStabActiveButtonPress,
393
394 DStabFocusBackground,
395 DStabFocusText,
396 DStabFocusIcon,
397 DStabFocusButtonHover,
398 DStabFocusButtonPress,
399
400 DSnavigatorBranch,
401 DSnavigatorBranchIndicator,
402 DSnavigatorItemBackground,
403 DSnavigatorItemBackgroundHover,
404 DSnavigatorItemBackgroundSelected,
405 DSnavigatorText,
406 DSnavigatorTextHover,
407 DSnavigatorTextSelected,
408 DSnavigatorIcon,
409 DSnavigatorIconHover,
410 DSnavigatorIconSelected,
411 DSnavigatorAliasIconChecked,
412 DSnavigatorDropIndicatorBackground,
413 DSnavigatorDropIndicatorOutline,
414
415 DSheaderViewBackground,
416 DStableViewAlternateBackground,
417
418 DStoolTipBackground,
419 DStoolTipOutline,
420 DStoolTipText,
421
422 DSUnimportedModuleColor
423 };
424
425 enum Gradient {
426 DetailsWidgetHeaderGradient,
427 };
428
429 enum ImageFile {
430 IconOverlayCSource,
431 IconOverlayCppHeader,
432 IconOverlayCppSource,
433 IconOverlayPri,
434 IconOverlayPrf,
435 IconOverlayPro,
436 StandardPixmapFileIcon,
437 StandardPixmapDirIcon
438 };
439
440 enum Flag {
441 DrawTargetSelectorBottom,
442 DrawSearchResultWidgetFrame,
443 DrawIndicatorBranch,
444 DrawToolBarHighlights,
445 DrawToolBarBorders,
446 ComboBoxDrawTextShadow,
447 DerivePaletteFromTheme,
448 ApplyThemePaletteGlobally,
449 FlatToolBars,
450 FlatSideBarIcons,
451 FlatProjectsMode,
452 FlatMenuBar,
453 ToolBarIconShadow,
454 WindowColorAsBase,
455 DarkUserInterface
456 };
457
458 Q_ENUM(Color)
459 Q_ENUM(ImageFile)
460 Q_ENUM(Gradient)
461 Q_ENUM(Flag)
462
463 Q_INVOKABLE bool flag(Flag f) const;
464 Q_INVOKABLE QColor color(Color role) const;
465 QString imageFile(ImageFile imageFile, const QString &fallBack) const;
466 QGradientStops gradient(Gradient role) const;
467 QPalette palette() const;
468 QStringList preferredStyles() const;
469 QString defaultTextEditorColorScheme() const;
470
471 QString id() const;
472 QString filePath() const;
473 QString displayName() const;
474 void setDisplayName(const QString &displayName);
475
476 void readSettings(QSettings &settings);
477
478 static bool systemUsesDarkMode();
479 static QPalette initialPalette();
480
481 protected:
482 Theme(Theme *originTheme, QObject *parent = nullptr);
483 ThemePrivate *d;
484
485 private:
486 friend QTCREATOR_UTILS_EXPORT Theme *creatorTheme();
487 friend QTCREATOR_UTILS_EXPORT Theme *proxyTheme();
488 QPair<QColor, QString> readNamedColor(const QString &color) const;
489 };
490
491 QTCREATOR_UTILS_EXPORT Theme *creatorTheme();
492 QTCREATOR_UTILS_EXPORT Theme *proxyTheme();
493
494 } // namespace Utils
495