]> cloud.milkyroute.net Git - dolphin.git/blob - src/selectionmode/backgroundcolorhelper.h
Apply 1 suggestion(s) to 1 file(s)
[dolphin.git] / src / selectionmode / backgroundcolorhelper.h
1 /*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2022 Felix Ernst <felixernst@kde.org>
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 <QObject>
13 #include <QPointer>
14
15 #include <memory>
16
17 class QWidget;
18
19 namespace SelectionMode
20 {
21
22 /**
23 * @brief A Singleton class for managing the colors of selection mode widgets.
24 */
25 class BackgroundColorHelper : public QObject
26 {
27 Q_OBJECT
28 public:
29 static BackgroundColorHelper *instance();
30
31 /**
32 * 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.
33 * The background color of @p widget will from now on be updated automatically when the palette of the application changes.
34 */
35 void controlBackgroundColor(QWidget *widget);
36
37 protected:
38 bool eventFilter(QObject *obj, QEvent *event) override;
39
40 private:
41 BackgroundColorHelper();
42
43 /**
44 * Called when the palette of the application changes.
45 * Triggers updateBackgroundColor() and the updates the background color of m_colorControlledWidgets.
46 * @see updateBackgroundColor
47 */
48 void slotPaletteChanged();
49
50 /** Calculates a new m_colorControlledWidgets based on the current color scheme of the application. */
51 void updateBackgroundColor();
52
53 private:
54 /// The widgets who have given up control over the background color to BackgroundColorHelper.
55 std::vector<QPointer<QWidget>> m_colorControlledWidgets;
56 /// The color to be used for the widgets' backgrounds.
57 QColor m_backgroundColor;
58
59 /// Singleton object
60 static BackgroundColorHelper *s_instance;
61 };
62
63 }
64
65 #endif // BACKGROUNDCOLORHELPER_H