]> cloud.milkyroute.net Git - dolphin.git/blob - src/selectionmode/backgroundcolorhelper.h
Not use forward and includes
[dolphin.git] / src / selectionmode / backgroundcolorhelper.h
1 /*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2022 Felix Ernst <felixernst@zohomail.eu>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7
8 #ifndef BACKGROUNDCOLORHELPER_H
9 #define BACKGROUNDCOLORHELPER_H
10
11 #include <QColor>
12 #include <QPointer>
13
14 #include <memory>
15
16 class QWidget;
17
18 namespace SelectionMode
19 {
20
21 /**
22 * @brief A Singleton class for managing the colors of selection mode widgets.
23 */
24 class BackgroundColorHelper
25 {
26 public:
27 static BackgroundColorHelper *instance();
28
29 /**
30 * Changes the background color of @p widget to a distinct color scheme matching color which makes it clear that the widget belongs to the selection mode.
31 * The background color of @p widget will from now on be updated automatically when the palette of the application changes.
32 */
33 void controlBackgroundColor(QWidget *widget);
34
35 private:
36 BackgroundColorHelper();
37
38 /**
39 * Called when the palette of the application changes.
40 * Triggers updateBackgroundColor() and the updates the background color of m_colorControlledWidgets.
41 * @see updateBackgroundColor
42 */
43 void slotPaletteChanged();
44
45 /** Calculates a new m_colorControlledWidgets based on the current colour scheme of the application. */
46 void updateBackgroundColor();
47
48 private:
49 /// The widgets who have given up control over the background color to BackgroundColorHelper.
50 std::vector<QPointer<QWidget>> m_colorControlledWidgets;
51 /// The color to be used for the widgets' backgrounds.
52 QColor m_backgroundColor;
53
54 /// Singleton object
55 static BackgroundColorHelper *s_instance;
56 };
57
58 }
59
60 #endif // BACKGROUNDCOLORHELPER_H