CuteLogger
Fast and simple logging solution for Qt based applications
colordialog.h
1/*
2 * Copyright (c) 2023 Meltytech, LLC
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef COLORDIALOG_H
19#define COLORDIALOG_H
20
21#include <QColor>
22#include <QObject>
23
24class ColorDialog : public QObject
25{
26 Q_OBJECT
27 Q_PROPERTY(
28 QColor selectedColor READ selectedColor WRITE setSelectedColor NOTIFY selectedColorChanged)
29 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
30 Q_PROPERTY(bool showAlpha READ showAlpha WRITE setShowAlpha NOTIFY showAlphaChanged)
31
32public:
33 explicit ColorDialog(QObject *parent = nullptr);
34
35 Q_INVOKABLE void open();
36
37 // Static convenience method for non-QML usage
38 static QColor getColor(const QColor &initial = Qt::white,
39 QWidget *parent = nullptr,
40 const QString &title = QString(),
41 bool showAlpha = true);
42
43signals:
44 void selectedColorChanged(const QColor &color);
45 void accepted();
46 void titleChanged();
47 void showAlphaChanged();
48
49private:
50 QColor m_color;
51 QString m_title;
52 bool m_showAlpha = true;
53
54 QColor selectedColor() const { return m_color; }
55 void setSelectedColor(const QColor &color);
56 QString title() const { return m_title; }
57 void setTitle(const QString &title);
58 bool showAlpha() const { return m_showAlpha; }
59 void setShowAlpha(bool show);
60};
61
62#endif // COLORDIALOG_H