File indexing completed on 2022-09-27 12:31:08

0001 /*
0002     SPDX-FileCopyrightText: 2003-2008 Cies Breijs <cies AT kde DOT nl>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef _COLORPICKER_H_
0008 #define _COLORPICKER_H_
0009 
0010 #include <QFrame>
0011 #include <QPainter>
0012 #include <QPaintEvent>
0013 #include <QDialog>
0014 
0015 class QLineEdit;
0016 class QSlider;
0017 class QSpinBox;
0018 
0019 
0020 class ColorPatch : public QFrame
0021 {
0022     Q_OBJECT
0023 
0024     public:
0025         explicit ColorPatch(QWidget *parent) : QFrame(parent) {
0026             setFrameStyle(QFrame::Panel|QFrame::Sunken);
0027         }
0028         void setColor(const QColor &c) { col = c; }
0029 
0030     protected:
0031         void paintEvent(QPaintEvent *e) override {
0032             QPainter p(this);
0033             drawFrame(&p);
0034             p.fillRect(contentsRect()&e->rect(), col);
0035         }
0036     
0037     private:
0038         QColor col;
0039 };
0040 
0041 
0042 
0043 
0044 class ColorPicker : public QDialog
0045 {
0046     Q_OBJECT
0047 
0048     public:
0049         explicit ColorPicker(QWidget* parent = nullptr);
0050 
0051     Q_SIGNALS:
0052         void pasteText(const QString&);
0053 
0054     private Q_SLOTS:
0055         void updateResult(int r, int g, int b);
0056         void redChanged(int);
0057         void greenChanged(int);
0058         void blueChanged(int);
0059         void copyProxy();
0060         void pasteProxy();
0061 
0062     private:
0063         ColorPatch *colorPatch;
0064         QLineEdit  *resultBox;
0065 
0066         QSlider *redSlider;
0067         QSlider *greenSlider;
0068         QSlider *blueSlider;
0069 
0070         QSpinBox *redSpin;
0071         QSpinBox *greenSpin;
0072         QSpinBox *blueSpin;
0073 };
0074 
0075 #endif  // _COLORPICKER_H_