├── icon.ico ├── files ├── mockup.png ├── qtcolorpicker-1.png ├── qtcolorpicker-2.png └── mockup.bmml ├── Service ├── vars.cpp ├── vars.h ├── services.h ├── validator.h ├── services.cpp └── validator.cpp ├── changelog.txt ├── Views ├── pickerview.cpp ├── testdialog.h ├── testdialog.ui ├── pickerview.h ├── testwidget.h ├── testwidget.ui ├── testdialog.cpp ├── test_form.ui ├── sliderswindow.h ├── testwidget.cpp ├── mainwindow.h ├── sliderswindow.cpp ├── mainwindow.cpp └── mainwindow.ui ├── Test ├── dialog.h ├── testpaint.h ├── dialog.cpp ├── dialog.ui └── testpaint.cpp ├── tasks.txt ├── Widgets ├── ColorWidgets │ ├── colorsample.h │ ├── hselector.h │ ├── svselector.h │ ├── colorwidget.h │ ├── colorwidget.cpp │ ├── colorsample.cpp │ ├── hselector.cpp │ └── svselector.cpp ├── colortext.h ├── Sliders │ ├── RGB │ │ ├── rgbslider.h │ │ └── rgbslider.cpp │ ├── HSV │ │ ├── hsvslider.h │ │ └── hsvslider.cpp │ ├── CMYK │ │ ├── cmykslider.h │ │ └── cmykslider.cpp │ ├── colorslider.h │ └── colorslider.cpp └── colortext.cpp ├── Models ├── colorprocessor.h └── colorprocessor.cpp ├── main.cpp ├── Controllers ├── maincontroller.h ├── sliderscontroller.h ├── maincontroller.cpp └── sliderscontroller.cpp ├── QtColorPicker.pro └── README.md /icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mortalis13/Qt-Color-Picker-Qt/HEAD/icon.ico -------------------------------------------------------------------------------- /files/mockup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mortalis13/Qt-Color-Picker-Qt/HEAD/files/mockup.png -------------------------------------------------------------------------------- /Service/vars.cpp: -------------------------------------------------------------------------------- 1 | #include "vars.h" 2 | 3 | Vars::Vars(QObject *parent) : 4 | QObject(parent) 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /files/qtcolorpicker-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mortalis13/Qt-Color-Picker-Qt/HEAD/files/qtcolorpicker-1.png -------------------------------------------------------------------------------- /files/qtcolorpicker-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mortalis13/Qt-Color-Picker-Qt/HEAD/files/qtcolorpicker-2.png -------------------------------------------------------------------------------- /changelog.txt: -------------------------------------------------------------------------------- 1 | 1.0.2 2 | 3 | -F1-F6 - copy buttons 4 | -F1-F4 - focus text fields 5 | -copied text has ',' 6 | -sliders layout 7 | -paste text in various formats ('1 2 3', '1,2,3', '1, 2, 3') 8 | -inc/dec color components by scrolling 9 | -------------------------------------------------------------------------------- /Views/pickerview.cpp: -------------------------------------------------------------------------------- 1 | #include "pickerview.h" 2 | 3 | #include 4 | #include 5 | 6 | 7 | PickerView::PickerView(QWidget *parent) : 8 | QWidget(parent) 9 | { 10 | init(); 11 | } 12 | 13 | PickerView::~PickerView() { 14 | } 15 | 16 | void PickerView::init() { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Test/dialog.h: -------------------------------------------------------------------------------- 1 | #ifndef DIALOG_H 2 | #define DIALOG_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class Dialog; 8 | } 9 | 10 | class Dialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit Dialog(QWidget *parent = 0); 16 | ~Dialog(); 17 | 18 | private: 19 | Ui::Dialog *ui; 20 | }; 21 | 22 | #endif // DIALOG_H 23 | -------------------------------------------------------------------------------- /Service/vars.h: -------------------------------------------------------------------------------- 1 | #ifndef VARS_H 2 | #define VARS_H 3 | 4 | #include 5 | 6 | class Vars : public QObject 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | enum ColorType{ 12 | HSV, RGB, CMYK, Hex 13 | }; 14 | 15 | public: 16 | explicit Vars(QObject *parent = 0); 17 | 18 | signals: 19 | 20 | public slots: 21 | 22 | }; 23 | 24 | #endif // VARS_H 25 | -------------------------------------------------------------------------------- /Test/testpaint.h: -------------------------------------------------------------------------------- 1 | #ifndef TESTPAINT_H 2 | #define TESTPAINT_H 3 | 4 | #include 5 | 6 | class TestPaint : public QWidget 7 | { 8 | Q_OBJECT 9 | void smallLines(QPainter &p); 10 | void largeLines(QPainter &p); 11 | public: 12 | explicit TestPaint(QWidget *parent = 0); 13 | 14 | signals: 15 | 16 | public slots: 17 | 18 | protected: 19 | void paintEvent(QPaintEvent *event); 20 | }; 21 | 22 | #endif // TESTPAINT_H 23 | -------------------------------------------------------------------------------- /Test/dialog.cpp: -------------------------------------------------------------------------------- 1 | #include "dialog.h" 2 | #include "ui_dialog.h" 3 | 4 | #include 5 | #include "norwegianwoodstyle.h" 6 | 7 | Dialog::Dialog(QWidget *parent) : 8 | QDialog(parent), 9 | ui(new Ui::Dialog) 10 | { 11 | ui->setupUi(this); 12 | 13 | // QApplication::setStyle(QStyleFactory::create("fusion")); 14 | // ui->horizontalSlider->setStyle(new NorwegianWoodStyle); 15 | } 16 | 17 | Dialog::~Dialog() 18 | { 19 | delete ui; 20 | } 21 | -------------------------------------------------------------------------------- /Views/testdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef TESTDIALOG_H 2 | #define TESTDIALOG_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class TestDialog; 8 | } 9 | 10 | class TestDialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit TestDialog(QWidget *parent = 0); 16 | ~TestDialog(); 17 | 18 | private: 19 | Ui::TestDialog *ui; 20 | 21 | 22 | protected: 23 | void paintEvent(QPaintEvent* e); 24 | 25 | }; 26 | 27 | #endif // TESTDIALOG_H 28 | -------------------------------------------------------------------------------- /Views/testdialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | TestDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 50 10 | 50 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Views/pickerview.h: -------------------------------------------------------------------------------- 1 | #ifndef PICKERVIEW_H 2 | #define PICKERVIEW_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | class PickerView : public QWidget 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | 15 | private: 16 | 17 | public: 18 | explicit PickerView(QWidget *parent = 0); 19 | ~PickerView(); 20 | 21 | 22 | protected: 23 | 24 | 25 | private: 26 | 27 | void init(); 28 | 29 | 30 | signals: 31 | 32 | private slots: 33 | 34 | }; 35 | 36 | #endif // PICKERVIEW_H 37 | -------------------------------------------------------------------------------- /Service/services.h: -------------------------------------------------------------------------------- 1 | #ifndef SERVICES_H 2 | #define SERVICES_H 3 | 4 | #include 5 | #include 6 | 7 | class Services : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit Services(QObject *parent = 0); 12 | 13 | static void drawRoundRect(QPainter& p, QRectF sizeRect, int borderSize, int borderRadius, QColor borderColor); 14 | static void drawInnerRoundRect(QPainter& p, QRectF sizeRect, int borderSize, int borderRadius, QColor borderColor); 15 | 16 | signals: 17 | 18 | public slots: 19 | 20 | }; 21 | 22 | #endif // SERVICES_H 23 | -------------------------------------------------------------------------------- /Views/testwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef TESTWIDGET_H 2 | #define TESTWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class TestWidget; 8 | } 9 | 10 | class TestWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit TestWidget(QWidget *parent = 0); 16 | ~TestWidget(); 17 | 18 | private: 19 | Ui::TestWidget *ui; 20 | 21 | int mx, my; 22 | 23 | 24 | protected: 25 | void paintEvent(QPaintEvent* e); 26 | void mousePressEvent(QMouseEvent* e); 27 | void mouseMoveEvent(QMouseEvent* e); 28 | // void mouseReleaseEvent(QMouseEvent *e); 29 | 30 | }; 31 | 32 | #endif // TESTWIDGET_H 33 | -------------------------------------------------------------------------------- /Views/testwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | TestWidget 4 | 5 | 6 | Qt::NonModal 7 | 8 | 9 | 10 | 0 11 | 0 12 | 204 13 | 204 14 | 15 | 16 | 17 | Form 18 | 19 | 20 | false 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Test/dialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Dialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 521 10 | 320 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 40 20 | 40 21 | 42 22 | 22 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Views/testdialog.cpp: -------------------------------------------------------------------------------- 1 | #include "testdialog.h" 2 | #include "ui_testdialog.h" 3 | 4 | #include 5 | #include 6 | 7 | TestDialog::TestDialog(QWidget *parent) : 8 | QDialog(parent), 9 | ui(new Ui::TestDialog) 10 | { 11 | ui->setupUi(this); 12 | } 13 | 14 | TestDialog::~TestDialog() 15 | { 16 | delete ui; 17 | } 18 | 19 | 20 | void TestDialog::paintEvent(QPaintEvent *event) 21 | { 22 | int w = width(); 23 | int h = height(); 24 | 25 | QPainter p(this); 26 | p.setRenderHint(QPainter::Antialiasing); 27 | 28 | QPen pen; 29 | pen.setWidth(2); 30 | pen.setColor(QColor(40,40,40,255)); 31 | 32 | p.setPen(pen); 33 | p.setBrush(QBrush(QColor(0,0,0))); 34 | 35 | p.drawRect(0, 0, w, h); 36 | } 37 | 38 | -------------------------------------------------------------------------------- /Views/test_form.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 548 10 | 286 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 0 21 | 0 22 | 548 23 | 21 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /tasks.txt: -------------------------------------------------------------------------------- 1 | 2 | - press mid button on text to select all or to select group 3 | - [hex] inc/dec each hex digit (not group) 4 | - saturation/value pointers on the sides of selector 5 | - show half of hue trapezoid when in the top/bottom max position (when it is partially hidden) 6 | - trim, remove \s+ after validation (when all comps are valid) 7 | *- text fields scroll 8 | *- text with commas (process, copy) 9 | - add swatches/color combo box (list) 10 | - hint (value) on slider/selector hover 11 | *- ctrl+tab to tab on text fields 12 | 13 | # - hold mid button to move on sv selector 14 | # - copy hex on Sample click 15 | # - mouse scroll on selectors 16 | # - validate on up/down, tab/btab 17 | # - short hex 18 | # - drag by any point 19 | # - paste validation 20 | # - hex ffffff => hue -1 21 | # - ctrl+scroll to inc/dec by 10 22 | 23 | # - esc 24 | # - field shortcuts 25 | # - button shortcuts 26 | # - change background 27 | # - draw gradient on hue selector instead of lines 28 | # - startup window position -------------------------------------------------------------------------------- /Widgets/ColorWidgets/colorsample.h: -------------------------------------------------------------------------------- 1 | #ifndef COLORSAMPLE_H 2 | #define COLORSAMPLE_H 3 | 4 | #include 5 | #include 6 | 7 | #include "colorwidget.h" 8 | 9 | 10 | class ColorSample : public ColorWidget 11 | { 12 | Q_OBJECT 13 | 14 | private: 15 | bool mouseMoving; 16 | QColor borderColor; 17 | 18 | public: 19 | explicit ColorSample(QWidget *parent = 0); 20 | 21 | void reupdateColor(); 22 | 23 | 24 | signals: 25 | void colorChanged(QColor color); 26 | void samplePressedLeft(); 27 | void samplePressedRight(); 28 | void samplePressedMiddle(); 29 | 30 | public slots: 31 | void changeColor(QColor color); 32 | void mouseMovedOnWindow(); 33 | void mouseReleasedOnWindow(); 34 | 35 | protected: 36 | void paintEvent(QPaintEvent *event); 37 | void mouseReleaseEvent(QMouseEvent* e); 38 | void enterEvent(QEvent* e); 39 | void leaveEvent(QEvent *e); 40 | 41 | private: 42 | void drawBorder(QPainter& p); 43 | 44 | }; 45 | 46 | #endif // COLORSAMPLE_H 47 | -------------------------------------------------------------------------------- /Test/testpaint.cpp: -------------------------------------------------------------------------------- 1 | #include "testpaint.h" 2 | 3 | #include 4 | #include 5 | 6 | TestPaint::TestPaint(QWidget *parent) : 7 | QWidget(parent) 8 | { 9 | } 10 | 11 | void TestPaint::smallLines(QPainter& p) { 12 | p.setPen(Qt::black); 13 | int lines = 0; 14 | 15 | for (int i = 0; i <= height(); i+=4) { 16 | p.drawLine(0, i, width(), i); 17 | lines++; 18 | } 19 | 20 | qDebug() << "smallLines: " << lines; 21 | } 22 | 23 | void TestPaint::largeLines(QPainter& p) { 24 | QPen pen(QColor(0,0,0), 2); 25 | p.setPen(pen); 26 | int hlines = 0, vlines = 0; 27 | 28 | for (int i = 0; i <= height(); i+=40) { 29 | p.drawLine(0, i, width(), i); 30 | hlines++; 31 | } 32 | 33 | for (int i = 0; i <= width(); i+=40) { 34 | p.drawLine(i, 0, i, height()); 35 | vlines++; 36 | } 37 | 38 | qDebug() << QString("largeLines: %1 h, %2 v").arg(hlines).arg(vlines); 39 | } 40 | 41 | void TestPaint::paintEvent(QPaintEvent *event) 42 | { 43 | QPainter p(this); 44 | 45 | // smallLines(p); 46 | largeLines(p); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /Widgets/ColorWidgets/hselector.h: -------------------------------------------------------------------------------- 1 | #ifndef HUEBAR_H 2 | #define HUEBAR_H 3 | 4 | #include 5 | #include 6 | 7 | #include "colorwidget.h" 8 | 9 | 10 | class HSelector : public ColorWidget 11 | { 12 | Q_OBJECT 13 | 14 | private: 15 | int barHeight; 16 | // QColor color; 17 | // int h,s,v; 18 | 19 | 20 | public: 21 | explicit HSelector(QWidget *parent = 0); 22 | 23 | void setH(int h); 24 | void setH(QColor color); 25 | void setInitH(int h); 26 | 27 | void reupdateColor(); 28 | 29 | protected: 30 | void paintEvent(QPaintEvent* e); 31 | void mousePressEvent(QMouseEvent* e); 32 | void mouseMoveEvent(QMouseEvent* e); 33 | void mouseReleaseEvent(QMouseEvent *e); 34 | void wheelEvent(QWheelEvent* e); 35 | 36 | private: 37 | void updateColor(); 38 | 39 | void drawPointer(QPainter &p); 40 | void correctPointer(); 41 | void movePointer(int y); 42 | void incPointer(int val); 43 | void decPointer(int val); 44 | 45 | void drawBorder(QPainter& p); 46 | 47 | 48 | signals: 49 | void hueChanged(QColor); 50 | 51 | 52 | }; 53 | 54 | #endif // HUEBAR_H 55 | -------------------------------------------------------------------------------- /Service/validator.h: -------------------------------------------------------------------------------- 1 | #ifndef VALIDATOR_H 2 | #define VALIDATOR_H 3 | 4 | #include 5 | #include 6 | 7 | #include "vars.h" 8 | 9 | 10 | class Validator : public QObject 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit Validator(QObject *parent = 0); 16 | 17 | static bool checkColorText(QString text, Vars::ColorType colorType=Vars::HSV); 18 | 19 | static bool checkValueHSV(QString text); 20 | static bool checkValueRGB(QString text); 21 | static bool checkValueCMYK(QString text); 22 | static bool checkValueHex(QString text); 23 | 24 | static void correctHSV(QColor& color); 25 | static void correctRGB(QColor& color); 26 | static void correctCMYK(QColor& color); 27 | 28 | static QString correctColorText(QString text); 29 | 30 | static bool checkComponentVal(int val, Vars::ColorType colorType=Vars::HSV, int group=0, int hexLen=0); 31 | static bool checkValueByType(QString text, Vars::ColorType colorType=Vars::HSV); 32 | 33 | 34 | private: 35 | static int getSizeByType(Vars::ColorType colorType); 36 | 37 | signals: 38 | 39 | public slots: 40 | 41 | }; 42 | 43 | #endif // VALIDATOR_H 44 | -------------------------------------------------------------------------------- /Widgets/colortext.h: -------------------------------------------------------------------------------- 1 | #ifndef COLORTEXT_H 2 | #define COLORTEXT_H 3 | 4 | #include 5 | #include 6 | 7 | #include "Service/vars.h" 8 | 9 | class ColorText : public QLineEdit 10 | { 11 | Q_OBJECT 12 | 13 | private: 14 | Vars::ColorType colorType; 15 | QString separator; 16 | int len; 17 | 18 | public: 19 | explicit ColorText(QWidget *parent = 0); 20 | 21 | void setType(Vars::ColorType colorType); 22 | void updateText(QString text); 23 | 24 | signals: 25 | void focusNextField(); 26 | void focusPrevField(); 27 | 28 | 29 | public slots: 30 | 31 | protected: 32 | void keyPressEvent(QKeyEvent *e); 33 | void wheelEvent(QWheelEvent *e); 34 | bool event(QEvent *e); 35 | 36 | private: 37 | void changeComponentVal(int pos, bool inc); 38 | 39 | int getGroup(); 40 | 41 | void selectNextComponent(); 42 | void selectPrevComponent(); 43 | void selectComponent(bool next); 44 | QStringList getComponentsFromHex(QString hex); 45 | int getGroupNumber(int group, int groupLen, bool next); 46 | int getHexGroup(int pos, int len); 47 | bool checkValueHex(QString text); 48 | 49 | }; 50 | 51 | #endif // COLORTEXT_H 52 | -------------------------------------------------------------------------------- /Widgets/Sliders/RGB/rgbslider.h: -------------------------------------------------------------------------------- 1 | #ifndef RGBSLIDER_H 2 | #define RGBSLIDER_H 3 | 4 | #include "Widgets/Sliders/colorslider.h" 5 | 6 | class RGBSlider : public ColorSlider 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | enum SliderType{Red, Green, Blue}; 12 | 13 | private: 14 | qreal r,g,b; 15 | SliderType sliderType; 16 | 17 | 18 | public: 19 | RGBSlider(QWidget *parent = 0); 20 | 21 | void setType(SliderType type); 22 | void init(); 23 | 24 | void setR(QColor color); 25 | void setG(QColor color); 26 | void setB(QColor color); 27 | 28 | void changeRed(QColor color); 29 | void changeGreen(QColor color); 30 | void changeBlue(QColor color); 31 | 32 | 33 | protected: 34 | void paintEvent(QPaintEvent* e); 35 | void updateColor(); 36 | 37 | private: 38 | void paintComponent(); 39 | void updateSlider(); 40 | void setColorComponent(QColor color, SliderType stype); 41 | 42 | void paintRed(QLinearGradient &grad); 43 | void paintGreen(QLinearGradient &grad); 44 | void paintBlue(QLinearGradient &grad); 45 | 46 | 47 | signals: 48 | void redChanged(QColor); 49 | void greenChanged(QColor); 50 | void blueChanged(QColor); 51 | 52 | }; 53 | 54 | #endif // RGBSLIDER_H 55 | -------------------------------------------------------------------------------- /Widgets/Sliders/HSV/hsvslider.h: -------------------------------------------------------------------------------- 1 | #ifndef HSVSLIDER_H 2 | #define HSVSLIDER_H 3 | 4 | #include "Widgets/Sliders/colorslider.h" 5 | 6 | class HSVSlider : public ColorSlider 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | enum SliderType{Hue, Saturation, Value}; 12 | 13 | private: 14 | qreal h,s,v; 15 | SliderType sliderType; 16 | 17 | 18 | public: 19 | HSVSlider(QWidget *parent = 0); 20 | 21 | void setType(SliderType type); 22 | void init(); 23 | 24 | void setH(QColor color); 25 | void setS(QColor color); 26 | void setV(QColor color); 27 | 28 | void changeHue(QColor color); 29 | void changeValue(QColor color); 30 | void changeSaturation(QColor color); 31 | 32 | 33 | protected: 34 | void paintEvent(QPaintEvent* e); 35 | void updateColor(); 36 | 37 | private: 38 | void paintComponent(); 39 | void updateSlider(); 40 | void setColorComponent(QColor color, SliderType stype); 41 | 42 | void paintHue(QLinearGradient &grad); 43 | void paintSaturation(QLinearGradient &grad); 44 | void paintValue(QLinearGradient &grad); 45 | 46 | 47 | signals: 48 | void hueChanged(QColor); 49 | void saturationChanged(QColor); 50 | void valueChanged(QColor); 51 | 52 | 53 | }; 54 | 55 | #endif // HSVSLIDER_H 56 | -------------------------------------------------------------------------------- /Views/sliderswindow.h: -------------------------------------------------------------------------------- 1 | #ifndef SLIDERSWINDOW_H 2 | #define SLIDERSWINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | #include "Controllers/sliderscontroller.h" 8 | 9 | 10 | namespace Ui { 11 | class SlidersWindow; 12 | } 13 | 14 | class SlidersController; 15 | 16 | class SlidersWindow : public QMainWindow 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | Ui::SlidersWindow *ui; 22 | 23 | private: 24 | bool mouseDown; 25 | bool mouseMoved; 26 | int mx, my; 27 | 28 | SlidersController *slidersController; 29 | 30 | public: 31 | explicit SlidersWindow(SlidersController *slidersController, QWidget *parent = 0); 32 | ~SlidersWindow(); 33 | 34 | 35 | protected: 36 | void mouseMoveEvent(QMouseEvent* e); 37 | void mousePressEvent(QMouseEvent* e); 38 | void mouseReleaseEvent(QMouseEvent* e); 39 | 40 | void keyPressEvent(QKeyEvent *e); 41 | void keyReleaseEvent(QKeyEvent *e); 42 | 43 | 44 | private: 45 | void addActions(); 46 | void addKeyActions(); 47 | void addShortcuts(); 48 | void init(); 49 | 50 | 51 | signals: 52 | 53 | void ctrlPressed(); 54 | void ctrlReleased(); 55 | 56 | 57 | private slots: 58 | void sliderMiddlePressed(QMouseEvent* e); 59 | 60 | 61 | }; 62 | 63 | #endif // SLIDERS_H 64 | -------------------------------------------------------------------------------- /Models/colorprocessor.h: -------------------------------------------------------------------------------- 1 | #ifndef COLORPROCESSOR_H 2 | #define COLORPROCESSOR_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include "Widgets/ColorWidgets/hselector.h" 11 | #include "Widgets/ColorWidgets/svselector.h" 12 | 13 | #include "Service/vars.h" 14 | 15 | 16 | class ColorProcessor : public QObject 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | explicit ColorProcessor(HSelector* hSelector, SVSelector* svSelector, QObject* parent=0); 22 | 23 | QString getHSV(QColor color); 24 | QString getRGB(QColor color); 25 | QString getCMYK(QColor color); 26 | QString getHex(QColor color); 27 | 28 | QColor getColorHSV(QString HSV_Text); 29 | QColor getColorRGB(QString RGB_Text); 30 | QColor getColorCMYK(QString CMYK_Text); 31 | QColor getColorHex(QString Hex_Text); 32 | 33 | void updateColorHSV(QString HSV); 34 | void updateColorRGB(QString RGB); 35 | void updateColorCMYK(QString CMYK); 36 | void updateColorHex(QString Hex); 37 | 38 | void updateColor(QColor color); 39 | 40 | void copyText(QString text); 41 | QString pasteText(); 42 | 43 | signals: 44 | void updateFinished(); 45 | 46 | private: 47 | HSelector* hSelector; 48 | SVSelector* svSelector; 49 | QClipboard* clip; 50 | 51 | }; 52 | 53 | #endif // COLORPROCESSOR_H 54 | -------------------------------------------------------------------------------- /Widgets/ColorWidgets/svselector.h: -------------------------------------------------------------------------------- 1 | #ifndef SATVALUESELECTOR_H 2 | #define SATVALUESELECTOR_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "colorwidget.h" 9 | 10 | 11 | class SVSelector : public ColorWidget 12 | { 13 | Q_OBJECT 14 | 15 | private: 16 | // QColor color; 17 | // int h,s,v; 18 | 19 | 20 | public: 21 | explicit SVSelector(QWidget *parent = 0); 22 | 23 | void setS(QColor color); 24 | void setV(QColor color); 25 | void setSV(int s, int v); 26 | 27 | void reupdateColor(); 28 | 29 | 30 | protected: 31 | void paintEvent(QPaintEvent *e); 32 | void mousePressEvent(QMouseEvent* e); 33 | void mouseMoveEvent(QMouseEvent* e); 34 | void mouseReleaseEvent(QMouseEvent* e); 35 | void wheelEvent(QWheelEvent *e); 36 | 37 | 38 | private: 39 | void updateColor(); 40 | 41 | void drawPointer(QPainter &p); 42 | void correctPointer(); 43 | void movePointer(int x, int y); 44 | 45 | void incPointerX(int val); 46 | void decPointerX(int val); 47 | void decPointerY(int val); 48 | void incPointerY(int val); 49 | 50 | void drawBorder(QPainter& p); 51 | 52 | 53 | signals: 54 | void colorChanged(QColor); 55 | void saturationChanged(QColor); 56 | void valueChanged(QColor); 57 | 58 | public slots: 59 | void changeHue(QColor color); 60 | 61 | 62 | }; 63 | 64 | #endif // SATVALUESELECTOR_H 65 | -------------------------------------------------------------------------------- /Widgets/Sliders/CMYK/cmykslider.h: -------------------------------------------------------------------------------- 1 | #ifndef CMYKSLIDER_H 2 | #define CMYKSLIDER_H 3 | 4 | #include "Widgets/Sliders/colorslider.h" 5 | 6 | class CMYKSlider : public ColorSlider 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | enum SliderType{Cyan, Magenta, Yellow, Black}; 12 | 13 | private: 14 | qreal c,m,y,k; 15 | SliderType sliderType; 16 | 17 | 18 | public: 19 | CMYKSlider(QWidget *parent = 0); 20 | 21 | void setType(SliderType type); 22 | void init(); 23 | 24 | void setC(QColor color); 25 | void setM(QColor color); 26 | void setY(QColor color); 27 | void setK(QColor color); 28 | 29 | void changeCyan(QColor color); 30 | void changeMagenta(QColor color); 31 | void changeYellow(QColor color); 32 | void changeBlack(QColor color); 33 | 34 | 35 | protected: 36 | void paintEvent(QPaintEvent* e); 37 | void updateColor(); 38 | 39 | private: 40 | void paintComponent(); 41 | void updateSlider(); 42 | void setColorComponent(QColor color, SliderType stype); 43 | 44 | void paintCyan(QLinearGradient &grad); 45 | void paintMagenta(QLinearGradient &grad); 46 | void paintYellow(QLinearGradient &grad); 47 | void paintBlack(QLinearGradient &grad); 48 | 49 | 50 | signals: 51 | void cyanChanged(QColor); 52 | void magentaChanged(QColor); 53 | void yellowChanged(QColor); 54 | void blackChanged(QColor); 55 | 56 | }; 57 | 58 | #endif // CMYKSLIDER_H 59 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "Views/mainwindow.h" 5 | 6 | // v1.0.2 7 | 8 | void setPosition(MainWindow &view) { 9 | QDesktopWidget *w = QApplication::desktop(); 10 | int primary = w->primaryScreen(); 11 | QRect dim = w->screenGeometry(primary); 12 | 13 | int mx,my, corr = 20; 14 | 15 | mx = view.x(); 16 | mx = dim.width() - view.width() - corr; 17 | my = corr; 18 | 19 | view.move(mx, my); 20 | } 21 | 22 | int main(int argc, char *argv[]) 23 | { 24 | QApplication a(argc, argv); 25 | MainWindow view; 26 | 27 | view.show(); 28 | setPosition(view); 29 | 30 | return a.exec(); 31 | } 32 | 33 | 34 | // void saveHuesToFile() { 35 | // QFile file("hues.dat"); 36 | // if ( !file.open(QIODevice::WriteOnly) ) { 37 | // qDebug("Cannot open file"); 38 | // return; 39 | // } 40 | 41 | // QList hues; 42 | // QColor color; 43 | 44 | // int maxHue = 360; 45 | // int max = 255; 46 | 47 | // for (int h = 0;h 5 | 6 | class ColorSlider : public QWidget 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit ColorSlider(QWidget *parent = 0); 11 | 12 | void updatePaint(); 13 | 14 | protected: 15 | void mousePressEvent(QMouseEvent* e); 16 | void mouseMoveEvent(QMouseEvent* e); 17 | 18 | void mouseReleaseEvent(QMouseEvent *e); 19 | void wheelEvent(QWheelEvent* e); 20 | 21 | protected: 22 | virtual void updateColor(); 23 | 24 | qreal normalizeVal(int val); 25 | int normalizePointerX(qreal val); 26 | 27 | void drawPointer(QPainter &p); 28 | void correctPointer(); 29 | void movePointer(int x); 30 | void incPointer(int val=1); 31 | void decPointer(int val=1); 32 | 33 | void calcVars(qreal val); 34 | void drawBorder(QPainter& p); 35 | 36 | void log(QString format, int var); 37 | void log(QString format, qreal var); 38 | 39 | 40 | protected: 41 | const qreal maxF=1.0; 42 | 43 | bool sliderDrawn; 44 | QPixmap sliderPixmap; 45 | 46 | bool middlePresed; 47 | bool ctrlHeld; 48 | bool widthChanged; 49 | 50 | QColor color; 51 | 52 | int pointerX; 53 | int pointerY; 54 | 55 | int minPointerX; 56 | int maxPointerX; 57 | 58 | int sliderX; 59 | int sliderY; 60 | int sliderW; 61 | int sliderH; 62 | int prevSliderW; 63 | 64 | int sliderVal; 65 | int maxRange; 66 | 67 | 68 | signals: 69 | void middlePressedSignal(QMouseEvent* e); 70 | 71 | public slots: 72 | void ctrlPressed(); 73 | void ctrlReleased(); 74 | 75 | }; 76 | 77 | #endif // COLORSLIDER_H 78 | -------------------------------------------------------------------------------- /Widgets/ColorWidgets/colorwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef COLORWIDGET_H 2 | #define COLORWIDGET_H 3 | 4 | #include 5 | 6 | 7 | class ColorWidget : public QWidget 8 | { 9 | Q_OBJECT 10 | 11 | 12 | protected: 13 | const int maxH=360; 14 | const int maxSV=255; 15 | const qreal maxF=1.0; 16 | 17 | const qreal ratio=1.0/maxH; 18 | 19 | 20 | const int border=2; 21 | const int borderRadius=10; 22 | 23 | const int selectorX=border; 24 | const int selectorY=border; 25 | 26 | const QColor borderColor=QColor(80,80,80,200); 27 | const QColor pointerColor=QColor("#333"); 28 | 29 | 30 | // --- H --- 31 | const int barWidth=40; 32 | 33 | const int minPointerY = border; 34 | const int maxPointerY = maxH + minPointerY; 35 | 36 | const int pointerWidth=10; 37 | const int pointerDy1=1.5; 38 | const int pointerDy2=5; 39 | 40 | 41 | // --- SV --- 42 | const int selectorSize=maxSV+1; 43 | const int minPointerXY = border; 44 | const int maxPointerXY = maxSV+border; 45 | 46 | const int pointerR=5; 47 | const int pointerBorder=2; 48 | 49 | const QColor pointerBorderColor=QColor("#ddd"); 50 | 51 | 52 | protected: 53 | bool middlePresed; 54 | bool selectorDrawn; 55 | bool shiftHeld; 56 | bool ctrlHeld; 57 | 58 | QPixmap hSelectorPixmap; 59 | QImage hueLayerImage; 60 | QColor color; 61 | 62 | int h,s,v; 63 | qreal hf,sf,vf; 64 | 65 | int pointerX; 66 | int pointerY; 67 | 68 | 69 | public: 70 | explicit ColorWidget(QWidget *parent = 0); 71 | 72 | 73 | protected: 74 | void drawCircle(QPainter &p); 75 | void drawRightTrapezoid(QPainter& p); 76 | 77 | void hideCursor(QMouseEvent *e); 78 | void restoreCursor(); 79 | 80 | void log(QString format, int var); 81 | void log(QString format, qreal var); 82 | 83 | 84 | signals: 85 | void middlePressedSignal(QMouseEvent* e); 86 | 87 | 88 | public slots: 89 | void shiftPressed(); 90 | void shiftReleased(); 91 | void ctrlPressed(); 92 | void ctrlReleased(); 93 | 94 | 95 | }; 96 | 97 | #endif // COLORWIDGET_H 98 | -------------------------------------------------------------------------------- /Controllers/maincontroller.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINCONTROLLER_H 2 | #define MAINCONTROLLER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "Views/mainwindow.h" 8 | #include "Controllers/sliderscontroller.h" 9 | #include "Models/colorprocessor.h" 10 | 11 | #include "Widgets/ColorWidgets/hselector.h" 12 | #include "Widgets/ColorWidgets/svselector.h" 13 | 14 | 15 | class MainWindow; 16 | 17 | class MainController : public QObject 18 | { 19 | Q_OBJECT 20 | 21 | private: 22 | HSelector* hSelector; 23 | SVSelector* svSelector; 24 | 25 | ColorProcessor* colorProcessor; 26 | SlidersController *slidersController; 27 | 28 | MainWindow* view; 29 | 30 | 31 | public: 32 | explicit MainController(HSelector* hSelector, SVSelector* svSelector, 33 | ColorProcessor *colorProcessor, 34 | MainWindow *view, 35 | QObject* parent=0); 36 | 37 | void addSlidersController(SlidersController *slidersController); 38 | 39 | 40 | private: 41 | void changeRGB(int pos, int val); 42 | void changeCMYK(int pos, int val); 43 | 44 | void connectRGB(); 45 | void disconnectRGB(); 46 | void connectCMYK(); 47 | void disconnectCMYK(); 48 | 49 | signals: 50 | void hueChanged(QColor); 51 | void saturationChanged(QColor); 52 | void valueChanged(QColor); 53 | 54 | void redChanged(QColor); 55 | void greenChanged(QColor); 56 | void blueChanged(QColor); 57 | 58 | void cyanChanged(QColor); 59 | void magentaChanged(QColor); 60 | void yellowChanged(QColor); 61 | void blackChanged(QColor); 62 | 63 | 64 | public slots: 65 | void changeHue(QColor color); 66 | void changeSaturation(QColor color); 67 | void changeValue(QColor color); 68 | 69 | void changeRed(QColor color); 70 | void changeGreen(QColor color); 71 | void changeBlue(QColor color); 72 | 73 | void changeCyan(QColor color); 74 | void changeMagenta(QColor color); 75 | void changeYellow(QColor color); 76 | void changeBlack(QColor color); 77 | 78 | }; 79 | 80 | #endif // MAINCONTROLLER_H 81 | -------------------------------------------------------------------------------- /QtColorPicker.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2015-05-28T15:25:48 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = QtColorPicker 12 | TEMPLATE = app 13 | 14 | QMAKE_CXXFLAGS -= -Wunused-parameter 15 | CONFIG += c++11 16 | 17 | win32:RC_ICONS += icon.ico 18 | 19 | 20 | SOURCES += main.cpp\ 21 | Views/mainwindow.cpp \ 22 | Views/sliderswindow.cpp \ 23 | Views/pickerview.cpp \ 24 | \ 25 | Widgets/ColorWidgets/colorwidget.cpp \ 26 | Widgets/ColorWidgets/colorsample.cpp \ 27 | Widgets/ColorWidgets/hselector.cpp \ 28 | Widgets/ColorWidgets/svselector.cpp \ 29 | Widgets/colortext.cpp \ 30 | \ 31 | Widgets/Sliders/colorslider.cpp \ 32 | Widgets/Sliders/HSV/hsvslider.cpp \ 33 | Widgets/Sliders/RGB/rgbslider.cpp \ 34 | Widgets/Sliders/CMYK/cmykslider.cpp \ 35 | \ 36 | Service/services.cpp \ 37 | Service/validator.cpp \ 38 | Service/vars.cpp \ 39 | \ 40 | Models/colorprocessor.cpp \ 41 | \ 42 | Controllers/sliderscontroller.cpp \ 43 | Controllers/maincontroller.cpp \ 44 | Views/testwidget.cpp \ 45 | Views/testdialog.cpp 46 | 47 | 48 | HEADERS += Views/mainwindow.h \ 49 | Views/sliderswindow.h \ 50 | Views/pickerview.h \ 51 | \ 52 | Widgets/ColorWidgets/colorwidget.h \ 53 | Widgets/ColorWidgets/colorsample.h \ 54 | Widgets/ColorWidgets/hselector.h \ 55 | Widgets/ColorWidgets/svselector.h \ 56 | Widgets/colortext.h \ 57 | \ 58 | Widgets/Sliders/colorslider.h \ 59 | Widgets/Sliders/HSV/hsvslider.h \ 60 | Widgets/Sliders/RGB/rgbslider.h \ 61 | Widgets/Sliders/CMYK/cmykslider.h \ 62 | \ 63 | Service/services.h \ 64 | Service/validator.h \ 65 | Service/vars.h \ 66 | \ 67 | Models/colorprocessor.h \ 68 | \ 69 | Controllers/sliderscontroller.h \ 70 | Controllers/maincontroller.h \ 71 | Views/testwidget.h \ 72 | Views/testdialog.h 73 | 74 | 75 | FORMS += Views/mainwindow.ui \ 76 | Views/test_form.ui \ 77 | Views/sliderswindow.ui \ 78 | Views/testwidget.ui \ 79 | Views/testdialog.ui 80 | -------------------------------------------------------------------------------- /Service/services.cpp: -------------------------------------------------------------------------------- 1 | #include "services.h" 2 | 3 | Services::Services(QObject *parent) : 4 | QObject(parent) 5 | { 6 | } 7 | 8 | // outer rect (specify rect with inner coordinates, the round rect will be outer) 9 | 10 | void Services::drawRoundRect(QPainter& p, QRectF sizeRect, int borderSize, int borderRadius, QColor borderColor) { 11 | QPen pen; 12 | pen.setWidth(borderSize); 13 | pen.setColor(borderColor); 14 | pen.setJoinStyle(Qt::RoundJoin); 15 | 16 | p.setPen(pen); 17 | p.setBrush(Qt::NoBrush); 18 | 19 | QRectF rect(sizeRect.x() - borderSize/2, sizeRect.y() - borderSize/2, 20 | sizeRect.width() + borderSize, sizeRect.height() + borderSize); 21 | 22 | if (borderSize % 2 == 0) 23 | p.drawRoundedRect(rect, borderSize, borderSize); 24 | else 25 | p.drawRoundedRect(rect.translated(0.5, 0.5), borderRadius, borderRadius); 26 | } 27 | 28 | 29 | void Services::drawInnerRoundRect(QPainter& p, QRectF sizeRect, int borderSize, int borderRadius, QColor borderColor) { 30 | QPen pen; 31 | pen.setWidth(borderSize); 32 | pen.setColor(borderColor); 33 | pen.setJoinStyle(Qt::RoundJoin); 34 | 35 | p.setPen(pen); 36 | p.setBrush(Qt::NoBrush); 37 | 38 | QRectF rect(sizeRect.x() + borderSize/2, sizeRect.y() + borderSize/2, 39 | sizeRect.width() - borderSize, sizeRect.height() - borderSize); 40 | 41 | if (borderSize % 2 == 0) 42 | p.drawRoundedRect(rect, borderSize, borderSize); 43 | else 44 | p.drawRoundedRect(rect.translated(0.5, 0.5), borderRadius, borderRadius); 45 | } 46 | 47 | 48 | // ----------------- triangles for HueBar ----------------- 49 | 50 | // void Services::drawLeftTriangle(QPainter& p) { 51 | // QPen pen(Qt::NoPen); 52 | // QBrush brush(pointerColor); 53 | // pen.setCapStyle(Qt::FlatCap); 54 | // p.setBrush(brush); 55 | // p.setPen(pen); 56 | 57 | // QPolygonF triangle; 58 | 59 | // QPoint p1(border+pointerWidth, pointerY); 60 | // QPoint p2(border, pointerY - triangleDy); 61 | // QPoint p3(border, pointerY + triangleDy); 62 | 63 | // triangle << p1 << p2 << p3; 64 | // QPainterPath path; 65 | // path.addPolygon(triangle); 66 | // p.drawPath(path); 67 | // } 68 | 69 | // void Services::drawRightTriangle(QPainter& p) { 70 | // QPen pen(Qt::NoPen); 71 | // QBrush brush(pointerColor); 72 | // pen.setCapStyle(Qt::FlatCap); 73 | // p.setBrush(brush); 74 | // p.setPen(pen); 75 | 76 | // QPolygonF triangle; 77 | 78 | // QPoint p1(width()-border-pointerWidth, pointerY); 79 | // QPoint p2(width()-border, pointerY - triangleDy); 80 | // QPoint p3(width()-border, pointerY + triangleDy); 81 | 82 | // triangle << p1 << p2 << p3; 83 | // QPainterPath path; 84 | // path.addPolygon(triangle); 85 | // p.drawPath(path); 86 | // } 87 | -------------------------------------------------------------------------------- /Views/testwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "testwidget.h" 2 | #include "ui_testwidget.h" 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | TestWidget::TestWidget(QWidget *parent) : 12 | QWidget(parent), 13 | ui(new Ui::TestWidget) 14 | { 15 | ui->setupUi(this); 16 | } 17 | 18 | TestWidget::~TestWidget() 19 | { 20 | delete ui; 21 | } 22 | 23 | 24 | void TestWidget::paintEvent(QPaintEvent *event) { 25 | int w = width(); 26 | int h = height(); 27 | 28 | QPainter p(this); 29 | 30 | int b = 2; 31 | int step = 10; 32 | 33 | // -- setup 34 | QPen pen; 35 | pen.setWidth(b); 36 | pen.setColor(QColor(40,40,40)); 37 | pen.setJoinStyle(Qt::RoundJoin); 38 | 39 | // p.setRenderHint(QPainter::Antialiasing); 40 | p.setPen(pen); 41 | p.setBrush(QBrush(QColor(255,255,255))); 42 | 43 | QPen penGrid; 44 | penGrid.setWidth(1); 45 | penGrid.setColor(QColor(0,0,0)); 46 | 47 | // -- draw 48 | p.drawRect(b/2, b/2, w-b, h-b); 49 | p.setPen(penGrid); 50 | 51 | int cols = (w - 2*b) / step; 52 | int rows = (h - 2*b) / step; 53 | 54 | for (int i = 1; i < cols; i++) { 55 | int x = b/2 + i*(step+1); 56 | p.drawLine(x, b, x, h-b); 57 | } 58 | 59 | for (int i = 1; i < rows; i++) { 60 | int y = b/2 + i*(step+1); 61 | p.drawLine(b, y, w-b, y); 62 | } 63 | 64 | 65 | // -- screen pixels 66 | QPixmap pix = QPixmap(); 67 | QScreen *screen = QGuiApplication::primaryScreen(); 68 | if (screen) pix = screen->grabWindow(0); 69 | 70 | for (int row = 0; row < rows; row++) { 71 | for (int col = 0; col < cols; col++) { 72 | QRgb rgb = pix.toImage().pixel(row, col); 73 | QColor pixColor(rgb); 74 | p.setPen(QPen(pixColor)); 75 | 76 | for (int k = 0; k < step*step; k++) { 77 | int x = col * step + k % step; 78 | int y = row * step + k / step; 79 | if (x == col*step || y == row*step) continue; 80 | if (x < b || y < b) continue; 81 | if (x >= w-b || y >= h-b) continue; 82 | p.drawPoint(x, y); 83 | } 84 | } 85 | } 86 | } 87 | 88 | void TestWidget::mousePressEvent(QMouseEvent *e) 89 | { 90 | mx=e->x(); 91 | my=e->y(); 92 | } 93 | 94 | void TestWidget::mouseMoveEvent(QMouseEvent *e) { 95 | // int x = e->x(); 96 | // int y = e->y(); 97 | 98 | // int wx = x - width()/2; 99 | // int wy = y - height()/2; 100 | 101 | // // qDebug() << wx << wy; 102 | // move(wx, wy); 103 | 104 | 105 | int gx=e->globalX(); 106 | int gy=e->globalY(); 107 | 108 | int corrX=geometry().x() - x(); 109 | int corrY=geometry().y() - y(); 110 | 111 | int moveX=gx-mx-corrX; 112 | int moveY=gy-my-corrY; 113 | 114 | move(moveX, moveY); 115 | } 116 | 117 | -------------------------------------------------------------------------------- /Widgets/ColorWidgets/colorwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "colorwidget.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "Service/services.h" 8 | 9 | 10 | // ---------------------------------------------------------------------------------------------------- 11 | 12 | ColorWidget::ColorWidget(QWidget *parent) : QWidget(parent) { 13 | selectorDrawn = false; 14 | middlePresed = false; 15 | 16 | shiftHeld = false; 17 | ctrlHeld = false; 18 | 19 | pointerY = 0; 20 | 21 | h = 0; 22 | s = maxSV; 23 | v = maxSV; 24 | 25 | hf = 0; 26 | sf = maxF; 27 | vf = maxF; 28 | 29 | color.setHsv(h, s, v); 30 | } 31 | 32 | 33 | // ---------------------------------------------- service ---------------------------------------------- 34 | 35 | void ColorWidget::drawCircle(QPainter& p) { 36 | QPen pen(pointerBorderColor, pointerBorder); 37 | p.setPen(pen); 38 | p.setBrush(pointerColor); 39 | p.drawEllipse( QPoint(pointerX, pointerY), pointerR, pointerR ); 40 | } 41 | 42 | void ColorWidget::drawRightTrapezoid(QPainter& p) { 43 | QPen pen(Qt::NoPen); 44 | pen.setCapStyle(Qt::FlatCap); 45 | QBrush brush(pointerColor); 46 | p.setPen(pen); 47 | p.setBrush(brush); 48 | 49 | QPolygonF triangle; 50 | 51 | QPoint p1( width() - pointerWidth, pointerY + pointerDy1 ); 52 | QPoint p2( width() - pointerWidth, pointerY - pointerDy1 ); 53 | QPoint p3( width(), pointerY - pointerDy2 ); 54 | QPoint p4( width(), pointerY + pointerDy2 ); 55 | 56 | triangle << p1 << p2 << p3 << p4; 57 | 58 | QPainterPath path; 59 | path.addPolygon(triangle); 60 | p.drawPath(path); 61 | } 62 | 63 | void ColorWidget::hideCursor(QMouseEvent *e) { 64 | int x = e->x(); 65 | int y = e->y(); 66 | 67 | if ( ( xmaxPointerXY ) || ( ymaxPointerXY ) ) { 68 | restoreCursor(); 69 | return; 70 | } 71 | this->setCursor( QCursor(Qt::BlankCursor) ); 72 | } 73 | 74 | void ColorWidget::restoreCursor() { 75 | this->setCursor( QCursor(Qt::ArrowCursor) ); 76 | } 77 | 78 | 79 | // ---------------------------------------------- slots ---------------------------------------------- 80 | 81 | void ColorWidget::shiftPressed() { 82 | shiftHeld = true; 83 | } 84 | 85 | void ColorWidget::shiftReleased() { 86 | shiftHeld = false; 87 | } 88 | 89 | void ColorWidget::ctrlPressed() { 90 | ctrlHeld = true; 91 | } 92 | 93 | void ColorWidget::ctrlReleased() { 94 | ctrlHeld = false; 95 | } 96 | 97 | // ---------------------------------------------- other ---------------------------------------------- 98 | 99 | void ColorWidget::log(QString format, int var) { 100 | qDebug() << QString(format).arg(var); 101 | } 102 | 103 | void ColorWidget::log(QString format, qreal var) { 104 | qDebug() << QString(format).arg(var); 105 | } 106 | -------------------------------------------------------------------------------- /Views/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "Models/colorprocessor.h" 10 | 11 | #include "Controllers/sliderscontroller.h" 12 | #include "Controllers/maincontroller.h" 13 | 14 | #include "sliderswindow.h" 15 | 16 | namespace Ui { 17 | class MainWindow; 18 | } 19 | 20 | class MainController; 21 | 22 | class MainWindow : public QMainWindow 23 | { 24 | Q_OBJECT 25 | 26 | private: 27 | QSignalMapper *mapper; 28 | 29 | Ui::MainWindow *ui; 30 | 31 | SlidersController *slidersController; 32 | MainController *mainController; 33 | 34 | ColorProcessor *colorProcessor; 35 | SlidersWindow* slidersWindow; 36 | 37 | QString editingField; 38 | 39 | bool mouseDown; 40 | bool mouseMoved; 41 | int mx, my; 42 | 43 | 44 | public: 45 | explicit MainWindow(QWidget *parent = 0); 46 | ~MainWindow(); 47 | 48 | void setHSV(QString text); 49 | void setRGB(QString text); 50 | void setCMYK(QString text); 51 | void setHex(QString text); 52 | 53 | QString getHSV(); 54 | QString getRGB(); 55 | QString getCMYK(); 56 | QString getHex(); 57 | 58 | 59 | private: 60 | void addActions(); 61 | void addShortcuts(); 62 | void addSlidersActions(); 63 | void init(); 64 | 65 | void updateSliders(); 66 | void stickSliders(); 67 | void status(QString msg); 68 | 69 | void correctFields(); 70 | QString correctField(QString text); 71 | 72 | 73 | protected: 74 | void mouseMoveEvent(QMouseEvent* e); 75 | void mousePressEvent(QMouseEvent* e); 76 | void mouseReleaseEvent(QMouseEvent* e); 77 | 78 | void keyPressEvent(QKeyEvent *e); 79 | void keyReleaseEvent(QKeyEvent *e); 80 | 81 | bool eventFilter(QObject *obj, QEvent *event); 82 | 83 | signals: 84 | void mouseMovedOnWindow(); 85 | void mouseReleasedOnWindow(); 86 | void shiftPressed(); 87 | void shiftReleased(); 88 | void ctrlPressed(); 89 | void ctrlReleased(); 90 | 91 | public slots: 92 | void updateColorHSV(QString HSV); 93 | void updateColorRGB(QString RGB); 94 | void updateColorCMYK(QString CMYK); 95 | void updateColorHex(QString Hex); 96 | 97 | private slots: 98 | void selectField(QWidget* w); 99 | 100 | void updateColorText(QColor color); 101 | void updateColorFinished(); 102 | 103 | void copyHSV(); 104 | void copyRGB(); 105 | void copyCMYK(); 106 | void copyHex(); 107 | void copyHexHash(); 108 | void pasteHex(); 109 | 110 | void middleClick(QMouseEvent *e); 111 | void hsvMiddlePressed(QMouseEvent *e); 112 | 113 | void toggleSliders(); 114 | void closeSliders(); 115 | void openSliders(); 116 | 117 | void focusNextField(); 118 | void focusPrevField(); 119 | 120 | void showPickerClicked(); 121 | 122 | }; 123 | 124 | #endif // MAINWINDOW_H 125 | 126 | -------------------------------------------------------------------------------- /Widgets/ColorWidgets/colorsample.cpp: -------------------------------------------------------------------------------- 1 | #include "colorsample.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "Service/services.h" 7 | 8 | 9 | // ----------------------------------------------- consts ----------------------------------------------- 10 | 11 | const QColor defaultBorderColor = QColor(80,80,80,200); 12 | 13 | 14 | // ---------------------------------------------------------------------------------------------------- 15 | 16 | ColorSample::ColorSample(QWidget *parent) : ColorWidget(parent) 17 | { 18 | color.setHsv(0, maxSV, maxSV); 19 | borderColor = defaultBorderColor; 20 | } 21 | 22 | 23 | // --------------------------------------------- events --------------------------------------------- 24 | 25 | void ColorSample::paintEvent(QPaintEvent *event) 26 | { 27 | QPainter p(this); 28 | p.setRenderHint(QPainter::Antialiasing); 29 | 30 | p.setPen(Qt::NoPen); 31 | p.setBrush(color); 32 | p.drawRect(border, border, width()-2*border, height()-2*border); 33 | 34 | drawBorder(p); 35 | } 36 | 37 | void ColorSample::mouseReleaseEvent(QMouseEvent *e) 38 | { 39 | if (!mouseMoving) { 40 | switch ( e->button() ) { 41 | case Qt::LeftButton: 42 | emit samplePressedLeft(); 43 | break; 44 | case Qt::RightButton: 45 | emit samplePressedRight(); 46 | break; 47 | case Qt::MiddleButton: 48 | emit samplePressedMiddle(); 49 | e->accept(); 50 | return; 51 | default: 52 | return; 53 | } 54 | } 55 | 56 | if (e->button() == Qt::MiddleButton) { 57 | emit samplePressedMiddle(); 58 | e->accept(); 59 | return; 60 | } 61 | 62 | e->ignore(); 63 | mouseMoving = false; 64 | } 65 | 66 | void ColorSample::enterEvent(QEvent *e) 67 | { 68 | borderColor.setRgb(30,30,30,220); 69 | setCursor(Qt::PointingHandCursor); 70 | update(); 71 | } 72 | 73 | void ColorSample::leaveEvent(QEvent *e) 74 | { 75 | borderColor = defaultBorderColor; 76 | setCursor(Qt::ArrowCursor); 77 | update(); 78 | } 79 | 80 | 81 | // --------------------------------------------- slots --------------------------------------------- 82 | 83 | void ColorSample::mouseMovedOnWindow() { 84 | mouseMoving = true; 85 | } 86 | 87 | void ColorSample::mouseReleasedOnWindow() { 88 | mouseMoving = false; 89 | } 90 | 91 | void ColorSample::changeColor(QColor color) 92 | { 93 | this->color = color; 94 | emit colorChanged(color); 95 | update(); 96 | } 97 | 98 | void ColorSample::reupdateColor() 99 | { 100 | emit colorChanged(color); 101 | } 102 | 103 | // --------------------------------------------- service --------------------------------------------- 104 | 105 | void ColorSample::drawBorder(QPainter& p) { 106 | QRectF rectangle(0, 0, width(), height()); 107 | Services::drawInnerRoundRect(p, rectangle, border, borderRadius, borderColor); 108 | } 109 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QtColorPicker 2 | 3 | ## Main features 4 | 5 | - Hue, Saturation, Value selectors 6 | - Conversion of selected color to text represented in text fields 7 | - Buttons to copy color values and past **Hex** value 8 | - Color sliders and spinners for 3 color models (**HSV, RGB, CMYK**) 9 | 10 | 11 | ## Additional features 12 | 13 | - Main window and sliders window can be moved by dragging background window space with **left/right/middle** mouse buttons 14 | - When mouse is on color selectors or sliders the parent window can be moved with the **middle** mouse button 15 | - Windows can be closed with the **middle button** click on any element except *text fields, color sample and spinners* 16 | - Separate component values in the text fields can be *increased/decreased* with **Up/Down** keys 17 | - In text fields selection of the *next/previous* component can be performed with **Tab/Shift+Tab** keys 18 | - Mouse scrolling can be used to *increase/decrease* values by 1 and by 10 with **Ctrl** key for selectors, sliders and spinners (to change **Saturation** on the selector with scrolling **Shift** is held) 19 | - **Left/Right click** on the color sample can be used to copy **Hex** color without and with leading # respectively 20 | 21 | 22 | ## Usage 23 | 24 | - To *increase/decrease* value of a color component in text fields set text cursor near it or select it and press **Up/Down** keys or mouse scroll 25 | - To select *next/previous* color component in the same field press **Tab/Shift+Tab** 26 | - To toggle **Sliders window** click with middle mouse button on the color sample or use **Ctrl+S** 27 | - To **close** any window **middle click** somewhere on it 28 | - To **move** any window drag it with any mouse button by any part (except *selector, sliders, spinners, buttons and text fields* on which the middle button can be used) 29 | 30 | 31 | ## Shortcuts 32 | 33 | - **F1 - F5** - copy color values (HSV, RGB, CMYK, Hex, # Hex) 34 | - **F6** - paste Hex value 35 | - **Shift+F1 - Shift+F4** - focus text fields (HSV, RGB, CMYK, Hex) 36 | - **Ctrl+S** - open/close Sliders window 37 | - **Esc** or mouse wheel press - exit 38 | - mouse wheel press on the color sample - open/close Sliders window 39 | - left/right mouse click on the color sample - copy Hex value (without/with leading #) 40 | - mouse scroll on the vertical Hue selector - change the Hue value by 1 41 | - mouse scroll on the rectangular Saturation/Value selector - change Value component by 1, with **Shift** - change Saturation component 42 | - mouse scroll with **Ctrl** - change values by 10 43 | 44 | ## Download 45 | 46 | Portable packages: 47 | 48 | [All releases](https://github.com/mortalis13/Qt-Color-Picker-Qt/releases)
49 | [SourceForge](https://sourceforge.net/projects/qtcolorpicker/files)
50 | [Softpedia v1.0.0](http://www.softpedia.com/get/PORTABLE-SOFTWARE/Multimedia/Graphics/Portable-QtColorPicker.shtml) 51 | 52 | ## Build 53 | 54 | The program was created with [Qt 5.3.1](http://download.qt.io/official_releases/qt/5.3/5.3.1/) using MinGW compiler in [Qt Creator 3.1.2](http://download.qt.io/official_releases/qtcreator/3.1/3.1.2/). 55 | 56 | 57 | ## Screenshots 58 | 59 | ![QtColorPicker-main](/files/qtcolorpicker-1.png) 60 | ![QtColorPicker-sliders](/files/qtcolorpicker-2.png) 61 | -------------------------------------------------------------------------------- /Controllers/sliderscontroller.h: -------------------------------------------------------------------------------- 1 | #ifndef SLIDERSCONTROLLER_H 2 | #define SLIDERSCONTROLLER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "Views/sliderswindow.h" 8 | 9 | 10 | class SlidersWindow; 11 | 12 | class SlidersController : public QObject 13 | { 14 | Q_OBJECT 15 | 16 | private: 17 | SlidersWindow* slidersView; 18 | 19 | bool hueSpinManualEdit; 20 | bool saturationSpinManualEdit; 21 | bool valueSpinManualEdit; 22 | 23 | bool redSpinManualEdit; 24 | bool greenSpinManualEdit; 25 | bool blueSpinManualEdit; 26 | 27 | bool cyanSpinManualEdit; 28 | bool magentaSpinManualEdit; 29 | bool yellowSpinManualEdit; 30 | bool blackSpinManualEdit; 31 | 32 | 33 | public: 34 | explicit SlidersController(QObject* parent=0); 35 | 36 | void setView(SlidersWindow* slidersView); 37 | 38 | void connectRGB(); 39 | void disconnectRGB(); 40 | void connectCMYK(); 41 | void disconnectCMYK(); 42 | 43 | 44 | private: 45 | void addActions(); 46 | void init(); 47 | 48 | void updateRedValues(QColor color); 49 | void updateGreenValues(QColor color); 50 | void updateBlueValues(QColor color); 51 | 52 | void updateCyanValues(QColor color); 53 | void updateMagentaValues(QColor color); 54 | void updateYellowValues(QColor color); 55 | void updateBlackValues(QColor color); 56 | 57 | 58 | signals: 59 | void RGBChanged(QColor); 60 | void CMYKChanged(QColor); 61 | 62 | 63 | void hueChanged(int); 64 | void hueChanged(QColor); 65 | 66 | void saturationChanged(int); 67 | void saturationChanged(QColor); 68 | 69 | void valueChanged(int); 70 | void valueChanged(QColor); 71 | 72 | 73 | void redChanged(int); 74 | void redChanged(QColor); 75 | 76 | void greenChanged(int); 77 | void greenChanged(QColor); 78 | 79 | void blueChanged(int); 80 | void blueChanged(QColor); 81 | 82 | 83 | void cyanChanged(int); 84 | void cyanChanged(QColor); 85 | 86 | void magentaChanged(int); 87 | void magentaChanged(QColor); 88 | 89 | void yellowChanged(int); 90 | void yellowChanged(QColor); 91 | 92 | void blackChanged(int); 93 | void blackChanged(QColor); 94 | 95 | 96 | public slots: 97 | void changeHue(int h); 98 | void changeHue(QColor color); 99 | void changeHueFromSelector(QColor color); 100 | 101 | void changeSaturation(int s); 102 | void changeSaturation(QColor color); 103 | void changeSaturationFromSelector(QColor color); 104 | 105 | void changeValue(int s); 106 | void changeValue(QColor color); 107 | void changeValueFromSelector(QColor color); 108 | 109 | 110 | void changeRed(int r); 111 | void changeRed(QColor color); 112 | void changeRedFromSelector(QColor color); 113 | 114 | void changeGreen(int g); 115 | void changeGreen(QColor color); 116 | void changeGreenFromSelector(QColor color); 117 | 118 | void changeBlue(int b); 119 | void changeBlue(QColor color); 120 | void changeBlueFromSelector(QColor color); 121 | 122 | 123 | void changeCyan(int c); 124 | void changeCyan(QColor color); 125 | void changeCyanFromSelector(QColor color); 126 | 127 | void changeMagenta(int m); 128 | void changeMagenta(QColor color); 129 | void changeMagentaFromSelector(QColor color); 130 | 131 | void changeYellow(int y); 132 | void changeYellow(QColor color); 133 | void changeYellowFromSelector(QColor color); 134 | 135 | void changeBlack(int k); 136 | void changeBlack(QColor color); 137 | void changeBlackFromSelector(QColor color); 138 | 139 | }; 140 | 141 | #endif // SLIDERSCONTROLLER_H 142 | -------------------------------------------------------------------------------- /Controllers/maincontroller.cpp: -------------------------------------------------------------------------------- 1 | #include "maincontroller.h" 2 | 3 | 4 | MainController::MainController(HSelector *hSelector, SVSelector *svSelector, 5 | ColorProcessor *colorProcessor, 6 | MainWindow *view, 7 | QObject* parent) : QObject(parent) 8 | { 9 | this->hSelector = hSelector; 10 | this->svSelector = svSelector; 11 | this->view = view; 12 | this->colorProcessor = colorProcessor; 13 | 14 | slidersController = NULL; 15 | } 16 | 17 | void MainController::addSlidersController(SlidersController *slidersController) { 18 | this->slidersController = slidersController; 19 | } 20 | 21 | void MainController::connectRGB() { 22 | if (slidersController!=NULL) 23 | slidersController->connectRGB(); 24 | } 25 | 26 | void MainController::disconnectRGB() { 27 | if (slidersController!=NULL) 28 | slidersController->disconnectRGB(); 29 | } 30 | 31 | void MainController::connectCMYK() { 32 | if (slidersController!=NULL) 33 | slidersController->connectCMYK(); 34 | } 35 | 36 | void MainController::disconnectCMYK() { 37 | if (slidersController!=NULL) 38 | slidersController->disconnectCMYK(); 39 | } 40 | 41 | 42 | // --------------------------------------------- HSV --------------------------------------------- 43 | 44 | // ===== hue ===== 45 | void MainController::changeHue(QColor color) { 46 | hSelector->setH(color); 47 | } 48 | 49 | // ===== saturation ===== 50 | void MainController::changeSaturation(QColor color) { 51 | svSelector->setS(color); 52 | } 53 | 54 | // ===== value ===== 55 | void MainController::changeValue(QColor color) { 56 | svSelector->setV(color); 57 | } 58 | 59 | 60 | // --------------------------------------------- RGB --------------------------------------------- 61 | 62 | void MainController::changeRGB(int pos, int val) { 63 | QString RGB_Text = view->getRGB(); 64 | QColor currentColor = colorProcessor->getColorRGB(RGB_Text); 65 | 66 | switch (pos) { 67 | case 0: 68 | currentColor.setRed(val); 69 | break; 70 | case 1: 71 | currentColor.setGreen(val); 72 | break; 73 | case 2: 74 | currentColor.setBlue(val); 75 | break; 76 | } 77 | 78 | disconnectRGB(); 79 | QString RGB = colorProcessor->getRGB(currentColor); 80 | view->setRGB(RGB); 81 | view->updateColorRGB(RGB); 82 | connectRGB(); 83 | } 84 | 85 | // ===== red ===== 86 | void MainController::changeRed(QColor color) { 87 | changeRGB(0, color.red()); 88 | } 89 | 90 | // ===== green ===== 91 | void MainController::changeGreen(QColor color) { 92 | changeRGB(1, color.green()); 93 | } 94 | 95 | // ===== blue ===== 96 | void MainController::changeBlue(QColor color) { 97 | changeRGB(2, color.blue()); 98 | } 99 | 100 | 101 | // --------------------------------------------- CMYK --------------------------------------------- 102 | 103 | void MainController::changeCMYK(int pos, int val) { 104 | QString CMYK_Text = view->getCMYK(); 105 | QColor currentColor = colorProcessor->getColorCMYK(CMYK_Text); 106 | 107 | int c = currentColor.cyan(); 108 | int m = currentColor.magenta(); 109 | int y = currentColor.yellow(); 110 | int k = currentColor.black(); 111 | 112 | switch (pos) { 113 | case 0: 114 | c = val; 115 | break; 116 | case 1: 117 | m = val; 118 | break; 119 | case 2: 120 | y = val; 121 | break; 122 | case 3: 123 | k = val; 124 | break; 125 | } 126 | currentColor.setCmyk(c, m, y, k); 127 | 128 | disconnectCMYK(); 129 | QString CMYK = colorProcessor->getCMYK(currentColor); 130 | view->setCMYK(CMYK); 131 | view->updateColorCMYK(CMYK); 132 | connectCMYK(); 133 | } 134 | 135 | // ===== cyan ===== 136 | void MainController::changeCyan(QColor color) { 137 | changeCMYK(0, color.cyan()); 138 | } 139 | 140 | // ===== magenta ===== 141 | void MainController::changeMagenta(QColor color) { 142 | changeCMYK(1, color.magenta()); 143 | } 144 | 145 | // ===== yellow ===== 146 | void MainController::changeYellow(QColor color) { 147 | changeCMYK(2, color.yellow()); 148 | } 149 | 150 | // ===== black ===== 151 | void MainController::changeBlack(QColor color) { 152 | changeCMYK(3, color.black()); 153 | } 154 | -------------------------------------------------------------------------------- /Widgets/ColorWidgets/hselector.cpp: -------------------------------------------------------------------------------- 1 | #include "hselector.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "Service/services.h" 8 | 9 | 10 | // ---------------------------------------------------------------------------------------------------- 11 | 12 | HSelector::HSelector(QWidget *parent) : ColorWidget(parent) { 13 | } 14 | 15 | void HSelector::paintEvent(QPaintEvent *event) 16 | { 17 | QPainter p(this); 18 | p.setRenderHint(QPainter::Antialiasing); 19 | 20 | barHeight = height()-2*border; 21 | 22 | if (!selectorDrawn) { 23 | hSelectorPixmap = QPixmap(barWidth, barHeight); 24 | QPainter huePainter(&hSelectorPixmap); 25 | 26 | QPointF p1( 0, selectorY ); 27 | QPointF p2( 0, height()-border ); 28 | QLinearGradient grad(p1, p2); 29 | 30 | QColor color; 31 | for (qreal hs = 0; hs<1.0; hs+=ratio) { 32 | color.setHsvF(hs, sf, vf); 33 | grad.setColorAt(hs, color); 34 | } 35 | 36 | huePainter.setPen(Qt::NoPen); 37 | huePainter.setBrush( QBrush(grad) ); 38 | huePainter.drawRect(0, 0, barWidth, barHeight); 39 | 40 | selectorDrawn = true; 41 | } 42 | 43 | p.drawPixmap(selectorX, selectorY, hSelectorPixmap); 44 | 45 | drawPointer(p); 46 | drawBorder(p); 47 | } 48 | 49 | void HSelector::mousePressEvent(QMouseEvent *e) 50 | { 51 | if ( e->button() == Qt::MiddleButton ) { 52 | middlePresed = true; 53 | e->ignore(); 54 | 55 | QMouseEvent* mouseEvent = new QMouseEvent(e->type(), e->windowPos(), e->button(), e->buttons(), e->modifiers()); 56 | emit middlePressedSignal(mouseEvent); 57 | } 58 | else { 59 | middlePresed = false; 60 | movePointer(e->y()); 61 | updateColor(); 62 | } 63 | } 64 | 65 | void HSelector::mouseMoveEvent(QMouseEvent *e) 66 | { 67 | if (middlePresed) { 68 | e->ignore(); 69 | } 70 | else { 71 | movePointer(e->y()); 72 | updateColor(); 73 | } 74 | } 75 | 76 | void HSelector::mouseReleaseEvent(QMouseEvent *e) 77 | { 78 | e->ignore(); 79 | } 80 | 81 | void HSelector::wheelEvent(QWheelEvent *e) 82 | { 83 | QPoint p = e->angleDelta(); 84 | 85 | int val = 1; 86 | if (ctrlHeld) val = 10; 87 | 88 | if (p.y()<0) incPointer(val); 89 | if (p.y()>0) decPointer(val); 90 | 91 | updateColor(); 92 | e->accept(); 93 | } 94 | 95 | 96 | // ---------------------------------------------- service ---------------------------------------------- 97 | 98 | void HSelector::drawPointer(QPainter& p) { 99 | correctPointer(); 100 | drawRightTrapezoid(p); 101 | } 102 | 103 | void HSelector::correctPointer() { 104 | pointerY = h + minPointerY; // to update pointer Y on text edit 105 | pointerY = qMin(maxPointerY, qMax(minPointerY, pointerY)); 106 | } 107 | 108 | void HSelector::incPointer(int val) { 109 | movePointer(pointerY+val); 110 | } 111 | 112 | void HSelector::decPointer(int val) { 113 | movePointer(pointerY-val); 114 | } 115 | 116 | void HSelector::movePointer(int y) { 117 | pointerY = y; 118 | update(); 119 | } 120 | 121 | void HSelector::drawBorder(QPainter& p) { 122 | QRectF rectangle( selectorX, selectorX, barWidth, barHeight ); // set inner rect coordinates (the border will be outer) 123 | Services::drawRoundRect( p, rectangle, border, borderRadius, borderColor ); 124 | } 125 | 126 | void HSelector::updateColor() { 127 | h = pointerY-border; 128 | h = qMax(0, h); 129 | h = qMin(maxH, h); 130 | 131 | color.setHsv(h, s, v); 132 | emit hueChanged(color); 133 | } 134 | 135 | void HSelector::reupdateColor() { 136 | emit hueChanged(color); 137 | } 138 | 139 | // ---------------------------------------------- set/get ---------------------------------------------- 140 | 141 | void HSelector::setInitH(int h) { 142 | QColor color; 143 | color.setHsv(h, s, v); 144 | this->h = color.hue(); 145 | emit hueChanged(color); 146 | update(); 147 | } 148 | 149 | void HSelector::setH(int h) 150 | { 151 | if (this->h == 360) this->h = 0; 152 | if (this->h == h) return; 153 | 154 | QColor color; 155 | color.setHsv(h, s, v); 156 | setH(color); 157 | } 158 | 159 | void HSelector::setH(QColor color) 160 | { 161 | int h = color.hue(); 162 | if (this->h == 360) this->h = 0; 163 | if (this->h == h) { 164 | return; 165 | } 166 | 167 | this->h = color.hue(); 168 | emit hueChanged(color); 169 | update(); 170 | } 171 | -------------------------------------------------------------------------------- /Models/colorprocessor.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "colorprocessor.h" 3 | 4 | #include 5 | 6 | #include "Service/validator.h" 7 | 8 | 9 | 10 | ColorProcessor::ColorProcessor(HSelector *hSelector, SVSelector *svSelector, QObject* parent) : QObject(parent) { 11 | this->hSelector = hSelector; 12 | this->svSelector = svSelector; 13 | clip = QApplication::clipboard(); 14 | } 15 | 16 | // -------------------------------------------- color strings -------------------------------------------- 17 | 18 | QString ColorProcessor::getHSV(QColor color) { 19 | QString res; 20 | Validator::correctHSV(color); 21 | 22 | int h = color.hue(); 23 | int s = color.saturation(); 24 | int v = color.value(); 25 | 26 | res = QString("%1 %2 %3").arg(h).arg(s).arg(v); 27 | return res; 28 | } 29 | 30 | QString ColorProcessor::getRGB(QColor color) { 31 | QString res; 32 | Validator::correctRGB(color); 33 | 34 | int r = color.red(); 35 | int g = color.green(); 36 | int b = color.blue(); 37 | 38 | res = QString("%1 %2 %3").arg(r).arg(g).arg(b); 39 | return res; 40 | } 41 | 42 | QString ColorProcessor::getCMYK(QColor color) { 43 | QString res; 44 | Validator::correctCMYK(color); 45 | 46 | int c = color.cyan(); 47 | int m = color.magenta(); 48 | int y = color.yellow(); 49 | int k = color.black(); 50 | 51 | res = QString("%1 %2 %3 %4").arg(c).arg(m).arg(y).arg(k); 52 | return res; 53 | } 54 | 55 | QString ColorProcessor::getHex(QColor color) { 56 | QString res; 57 | 58 | res = color.name(); 59 | res = res.replace("#", ""); 60 | return res; 61 | } 62 | 63 | 64 | // -------------------------------------------- color objects -------------------------------------------- 65 | 66 | QColor ColorProcessor::getColorHSV(QString HSV_Text) { 67 | QStringList list; 68 | QColor color; 69 | 70 | list = HSV_Text.split(" "); 71 | int h = list[0].toInt(); 72 | int s = list[1].toInt(); 73 | int v = list[2].toInt(); 74 | 75 | color.setHsv(h, s, v); 76 | 77 | return color; 78 | } 79 | 80 | QColor ColorProcessor::getColorRGB(QString RGB_Text) { 81 | QStringList list; 82 | QColor color; 83 | 84 | list = RGB_Text.split(" "); 85 | int r = list[0].toInt(); 86 | int g = list[1].toInt(); 87 | int b = list[2].toInt(); 88 | 89 | color.setRgb(r, g, b); 90 | 91 | return color; 92 | } 93 | 94 | QColor ColorProcessor::getColorCMYK(QString CMYK_Text) { 95 | QStringList list; 96 | QColor color; 97 | 98 | list = CMYK_Text.split(" "); 99 | int c = list[0].toInt(); 100 | int m = list[1].toInt(); 101 | int y = list[2].toInt(); 102 | int k = list[3].toInt(); 103 | 104 | color.setCmyk(c, m, y, k); 105 | 106 | return color; 107 | } 108 | 109 | QColor ColorProcessor::getColorHex(QString Hex_Text) { 110 | QColor color; 111 | color.setNamedColor("#"+Hex_Text); 112 | return color; 113 | } 114 | 115 | // -------------------------------------------- update color -------------------------------------------- 116 | 117 | void ColorProcessor::updateColorHSV(QString HSV_Text) { 118 | if ( !Validator::checkColorText(HSV_Text, Vars::HSV) ) return; 119 | if ( !Validator::checkValueHSV(HSV_Text) ) return; 120 | 121 | QColor color = getColorHSV(HSV_Text); 122 | updateColor(color); 123 | } 124 | 125 | void ColorProcessor::updateColorRGB(QString RGB_Text) { 126 | if ( !Validator::checkColorText(RGB_Text, Vars::RGB) ) return; 127 | if ( !Validator::checkValueRGB(RGB_Text) ) return; 128 | 129 | QColor color = getColorRGB(RGB_Text); 130 | updateColor(color); 131 | } 132 | 133 | void ColorProcessor::updateColorCMYK(QString CMYK_Text) { 134 | if ( !Validator::checkColorText(CMYK_Text, Vars::CMYK) ) return; 135 | if ( !Validator::checkValueCMYK(CMYK_Text) ) return; 136 | 137 | QColor color = getColorCMYK(CMYK_Text); 138 | updateColor(color); 139 | } 140 | 141 | void ColorProcessor::updateColorHex(QString Hex_Text) { 142 | if ( !Validator::checkValueHex(Hex_Text) ) return; 143 | 144 | QColor color = getColorHex(Hex_Text); 145 | updateColor(color); 146 | } 147 | 148 | void ColorProcessor::updateColor(QColor color) { 149 | int h = color.hue(); 150 | int s = color.saturation(); 151 | int v = color.value(); 152 | 153 | hSelector->setH(h); 154 | svSelector->setSV(s, v); 155 | 156 | emit updateFinished(); 157 | } 158 | 159 | // -------------------------------------------- copy color text -------------------------------------------- 160 | 161 | void ColorProcessor::copyText(QString text) { 162 | clip->setText(text); 163 | } 164 | 165 | QString ColorProcessor::pasteText() { 166 | bool ok; 167 | QString text = clip->text(); 168 | text = text.replace("#", ""); 169 | 170 | int len = text.length(); 171 | if (len!=6 && len!=3) return QString(); 172 | 173 | text.toInt(&ok, 16); 174 | if (!ok) return QString(); 175 | 176 | return text; 177 | } 178 | -------------------------------------------------------------------------------- /Widgets/Sliders/RGB/rgbslider.cpp: -------------------------------------------------------------------------------- 1 | #include "rgbslider.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | // ---------------------------------------------- consts ---------------------------------------------- 9 | 10 | const int maxRGB = 255; 11 | 12 | 13 | // ---------------------------------------------------------------------------------------------------- 14 | 15 | RGBSlider::RGBSlider(QWidget *parent) : ColorSlider(parent) 16 | { 17 | sliderType = Red; 18 | 19 | r = maxF; 20 | g = 0; 21 | b = 0; 22 | 23 | color.setRgbF(r, g, b); 24 | } 25 | 26 | void RGBSlider::paintEvent(QPaintEvent *e) 27 | { 28 | QPainter p(this); 29 | p.setRenderHint(QPainter::Antialiasing); 30 | 31 | qreal val; 32 | switch (sliderType) { 33 | case Red: 34 | val = r; 35 | break; 36 | case Green: 37 | val = g; 38 | break; 39 | case Blue: 40 | val = b; 41 | break; 42 | } 43 | calcVars(val); 44 | 45 | if (!sliderDrawn || widthChanged) { 46 | paintComponent(); 47 | } 48 | p.drawPixmap(sliderX, sliderY, sliderPixmap); 49 | 50 | drawPointer(p); 51 | drawBorder(p); 52 | } 53 | 54 | void RGBSlider::paintComponent() { 55 | sliderPixmap = QPixmap(sliderW, sliderH); 56 | QPainter tempP( &sliderPixmap ); 57 | 58 | QPointF p1( sliderX, sliderH/2 ); 59 | QPointF p2( sliderX+sliderW, sliderH/2 ); 60 | QLinearGradient grad(p1, p2); 61 | 62 | switch (sliderType) { 63 | case Red: 64 | paintRed(grad); 65 | break; 66 | case Green: 67 | paintGreen(grad); 68 | break; 69 | case Blue: 70 | paintBlue(grad); 71 | break; 72 | } 73 | 74 | tempP.setPen(Qt::NoPen); 75 | tempP.setBrush( QBrush(grad) ); 76 | tempP.drawRect(0, 0, sliderW, sliderH); 77 | 78 | sliderDrawn = true; 79 | widthChanged = false; 80 | } 81 | 82 | void RGBSlider::paintRed(QLinearGradient &grad) { 83 | grad.setColorAt( 0, QColor::fromRgbF(0, g, b) ); 84 | grad.setColorAt( 1, QColor::fromRgbF(1, g, b) ); 85 | } 86 | 87 | void RGBSlider::paintGreen(QLinearGradient &grad) { 88 | grad.setColorAt( 0, QColor::fromRgbF(r, 0, b) ); 89 | grad.setColorAt( 1, QColor::fromRgbF(r, 1, b) ); 90 | } 91 | 92 | void RGBSlider::paintBlue(QLinearGradient &grad) { 93 | grad.setColorAt( 0, QColor::fromRgbF(r, g, 0) ); 94 | grad.setColorAt( 1, QColor::fromRgbF(r, g, 1) ); 95 | } 96 | 97 | void RGBSlider::updateColor() { 98 | ColorSlider::updateColor(); 99 | 100 | qreal val; 101 | val = normalizeVal( sliderVal ); 102 | val = qMax(0.0, val); 103 | val = qMin(maxF, val); 104 | 105 | switch (sliderType) { 106 | case Red: 107 | r = val; 108 | color.setRgbF(r, g, b); 109 | emit redChanged(color); 110 | break; 111 | case Green: 112 | g = val; 113 | color.setRgbF(r, g, b); 114 | emit greenChanged(color); 115 | break; 116 | case Blue: 117 | b = val; 118 | color.setRgbF(r, g, b); 119 | emit blueChanged(color); 120 | break; 121 | } 122 | } 123 | 124 | // ---------------------------------------------- set/get ---------------------------------------------- 125 | 126 | void RGBSlider::setColorComponent(QColor color, SliderType stype) { 127 | if (this->color == color) { 128 | return; 129 | } 130 | 131 | qreal val; 132 | switch (stype) { 133 | case Red: 134 | r = color.redF(); 135 | val = r; 136 | break; 137 | case Green: 138 | g = color.greenF(); 139 | val = g; 140 | break; 141 | case Blue: 142 | b = color.blueF(); 143 | val = b; 144 | break; 145 | } 146 | 147 | sliderVal = qCeil( val * maxRange ); 148 | this->color = QColor::fromRgbF(r, g, b); 149 | update(); 150 | } 151 | 152 | void RGBSlider::setR(QColor color) { 153 | setColorComponent(color, Red); 154 | } 155 | 156 | void RGBSlider::setG(QColor color) { 157 | setColorComponent(color, Green); 158 | } 159 | 160 | void RGBSlider::setB(QColor color) { 161 | setColorComponent(color, Blue); 162 | } 163 | 164 | // ---------------------------------------------- slots ---------------------------------------------- 165 | 166 | void RGBSlider::updateSlider() { 167 | this->color = QColor::fromRgbF(r, g, b); 168 | sliderDrawn = false; 169 | update(); 170 | } 171 | 172 | void RGBSlider::changeRed(QColor color) { 173 | r = color.redF(); 174 | updateSlider(); 175 | } 176 | 177 | void RGBSlider::changeGreen(QColor color) { 178 | g = color.greenF(); 179 | updateSlider(); 180 | } 181 | 182 | void RGBSlider::changeBlue(QColor color) { 183 | b = color.blueF(); 184 | updateSlider(); 185 | } 186 | 187 | // ---------------------------------------------- service ---------------------------------------------- 188 | 189 | void RGBSlider::init() { 190 | if (sliderType == Red) { 191 | sliderVal = maxRGB; 192 | } 193 | } 194 | 195 | void RGBSlider::setType(SliderType type) { 196 | sliderType = type; 197 | } 198 | -------------------------------------------------------------------------------- /Widgets/Sliders/HSV/hsvslider.cpp: -------------------------------------------------------------------------------- 1 | #include "hsvslider.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | // ---------------------------------------------- consts ---------------------------------------------- 9 | 10 | const int maxH = 360; 11 | const int maxSV = 255; 12 | const qreal ratio = 1.0/maxH; 13 | 14 | 15 | // ---------------------------------------------------------------------------------------------------- 16 | 17 | HSVSlider::HSVSlider(QWidget *parent) : ColorSlider(parent) 18 | { 19 | sliderType = Hue; 20 | 21 | h = 0; 22 | s = maxF; 23 | v = maxF; 24 | 25 | color.setHsvF(h, s, v); 26 | } 27 | 28 | void HSVSlider::paintEvent(QPaintEvent *e) 29 | { 30 | QPainter p(this); 31 | p.setRenderHint(QPainter::Antialiasing); 32 | 33 | qreal val; 34 | switch (sliderType) { 35 | case Hue: 36 | val = h; 37 | break; 38 | case Saturation: 39 | val = s; 40 | break; 41 | case Value: 42 | val = v; 43 | break; 44 | } 45 | calcVars(val); 46 | 47 | if (!sliderDrawn || widthChanged) { 48 | paintComponent(); 49 | } 50 | p.drawPixmap(sliderX, sliderY, sliderPixmap); 51 | 52 | drawPointer(p); 53 | drawBorder(p); 54 | } 55 | 56 | void HSVSlider::paintComponent() { 57 | sliderPixmap = QPixmap(sliderW, sliderH); 58 | QPainter tempP( &sliderPixmap ); 59 | 60 | QPointF p1( sliderX, 0 ); 61 | QPointF p2( sliderX+sliderW, 0 ); 62 | 63 | QLinearGradient grad(p1, p2); 64 | 65 | switch (sliderType) { 66 | case Hue: 67 | paintHue(grad); 68 | break; 69 | case Saturation: 70 | paintSaturation(grad); 71 | break; 72 | case Value: 73 | paintValue(grad); 74 | break; 75 | } 76 | 77 | tempP.setPen(Qt::NoPen); 78 | tempP.setBrush( QBrush(grad) ); 79 | tempP.drawRect(0, 0, sliderW, sliderH); 80 | 81 | sliderDrawn = true; 82 | widthChanged = false; 83 | } 84 | 85 | void HSVSlider::paintHue(QLinearGradient &grad) { 86 | QColor color; 87 | for (qreal hs = 0; hs<1.0; hs+=ratio) { 88 | color.setHsvF(hs, s, v); 89 | grad.setColorAt(hs, color); 90 | } 91 | } 92 | 93 | void HSVSlider::paintSaturation(QLinearGradient &grad) { 94 | grad.setColorAt( 0, QColor::fromHsvF(h, 0, v) ); 95 | grad.setColorAt( 1, QColor::fromHsvF(h, 1, v) ); 96 | } 97 | 98 | void HSVSlider::paintValue(QLinearGradient &grad) { 99 | grad.setColorAt( 0, QColor::fromHsvF(h, s, 0) ); 100 | grad.setColorAt( 1, QColor::fromHsvF(h, s, 1) ); 101 | } 102 | 103 | void HSVSlider::updateColor() { 104 | ColorSlider::updateColor(); 105 | 106 | qreal val; 107 | 108 | val = normalizeVal( sliderVal ); 109 | val = qMax(0.0, val); 110 | val = qMin(maxF, val); 111 | 112 | switch (sliderType) { 113 | case Hue: 114 | h = val; 115 | color.setHsvF(h, s, v); 116 | emit hueChanged(color); 117 | break; 118 | case Saturation: 119 | s = val; 120 | color.setHsvF(h, s, v); 121 | emit saturationChanged(color); 122 | break; 123 | case Value: 124 | v = val; 125 | color.setHsvF(h, s, v); 126 | emit valueChanged(color); 127 | break; 128 | } 129 | } 130 | 131 | // ---------------------------------------------- set/get ---------------------------------------------- 132 | 133 | void HSVSlider::setColorComponent(QColor color, SliderType stype) { 134 | if (this->color == color) { 135 | return; 136 | } 137 | 138 | qreal val; 139 | switch (stype) { 140 | case Hue: 141 | h = color.hueF(); 142 | val = h; 143 | break; 144 | case Saturation: 145 | s = color.saturationF(); 146 | val = s; 147 | break; 148 | case Value: 149 | v = color.valueF(); 150 | val = v; 151 | break; 152 | } 153 | 154 | sliderVal = qCeil( val * maxRange ); 155 | this->color = QColor::fromHsvF(h, s, v); 156 | update(); 157 | } 158 | 159 | void HSVSlider::setH(QColor color) { 160 | setColorComponent(color, Hue); 161 | } 162 | 163 | void HSVSlider::setS(QColor color) { 164 | setColorComponent(color, Saturation); 165 | } 166 | 167 | void HSVSlider::setV(QColor color) { 168 | setColorComponent(color, Value); 169 | } 170 | 171 | // ---------------------------------------------- slots ---------------------------------------------- 172 | 173 | void HSVSlider::updateSlider() { 174 | this->color = QColor::fromHsvF(h, s, v); 175 | sliderDrawn = false; 176 | update(); 177 | } 178 | 179 | void HSVSlider::changeHue(QColor color) { 180 | h = color.hueF(); 181 | updateSlider(); 182 | } 183 | 184 | void HSVSlider::changeSaturation(QColor color) { 185 | s = color.saturationF(); 186 | updateSlider(); 187 | } 188 | 189 | void HSVSlider::changeValue(QColor color) { 190 | v = color.valueF(); 191 | updateSlider(); 192 | } 193 | 194 | // ---------------------------------------------- service ---------------------------------------------- 195 | 196 | void HSVSlider::init() { 197 | if (sliderType == Saturation || sliderType == Value) { 198 | sliderVal = maxSV; 199 | } 200 | } 201 | 202 | void HSVSlider::setType(SliderType type) { 203 | sliderType = type; 204 | } 205 | -------------------------------------------------------------------------------- /Widgets/Sliders/colorslider.cpp: -------------------------------------------------------------------------------- 1 | #include "colorslider.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include "Service/services.h" 11 | 12 | 13 | // --------------------------------------------- consts --------------------------------------------- 14 | 15 | const int border = 2; 16 | const int borderRadius = 10; 17 | 18 | const int sliderX = border; 19 | const int sliderY = border; 20 | 21 | const int pointerR = 5; 22 | const int pointerBorder = 2; 23 | 24 | const QColor borderColor(80,80,80,200); 25 | 26 | const QColor pointerColor("#333"); 27 | const QColor pointerLineColor(80,80,80,200); 28 | const QColor pointerBorderColor("#ddd"); 29 | const QColor pointerFillColor("#333"); 30 | 31 | 32 | // ---------------------------------------------------------------------------------------------------- 33 | 34 | ColorSlider::ColorSlider(QWidget *parent) : 35 | QWidget(parent) 36 | { 37 | sliderDrawn = false; 38 | middlePresed = false; 39 | ctrlHeld = false; 40 | widthChanged = false; 41 | 42 | pointerX = 0; 43 | pointerY = 0; 44 | 45 | sliderVal = 0; 46 | } 47 | 48 | void ColorSlider::mousePressEvent(QMouseEvent *e) 49 | { 50 | if ( e->button() == Qt::MiddleButton ) { 51 | middlePresed = true; 52 | e->ignore(); 53 | } 54 | else { 55 | middlePresed = false; 56 | movePointer( e->x() ); 57 | updateColor(); 58 | } 59 | } 60 | 61 | void ColorSlider::mouseMoveEvent(QMouseEvent *e) 62 | { 63 | if (middlePresed) { 64 | e->ignore(); 65 | } 66 | else { 67 | movePointer( e->x() ); 68 | updateColor(); 69 | } 70 | } 71 | 72 | void ColorSlider::mouseReleaseEvent(QMouseEvent *e) 73 | { 74 | e->ignore(); 75 | } 76 | 77 | void ColorSlider::wheelEvent(QWheelEvent *e) 78 | { 79 | QPoint p = e->angleDelta(); 80 | 81 | int val = 1; 82 | if (ctrlHeld) val = 10; 83 | 84 | if (p.y()>0) incPointer(val); 85 | if (p.y()<0) decPointer(val); 86 | 87 | updateColor(); 88 | e->accept(); 89 | } 90 | 91 | 92 | // ---------------------------------------------- service ---------------------------------------------- 93 | 94 | void ColorSlider::calcVars(qreal val) { 95 | sliderX = border; 96 | sliderY = border; 97 | sliderW = width()-2*border; 98 | sliderH = height()-2*border; 99 | 100 | maxRange = sliderW - 1; 101 | minPointerX = sliderX; 102 | maxPointerX = minPointerX + maxRange; 103 | 104 | if (sliderW!=prevSliderW) { 105 | widthChanged = true; 106 | sliderVal = normalizePointerX(val); 107 | } 108 | prevSliderW = sliderW; 109 | } 110 | 111 | 112 | void ColorSlider::movePointer(int x) { 113 | pointerX = x; 114 | update(); 115 | } 116 | 117 | void ColorSlider::correctPointer() { 118 | pointerX = sliderVal + minPointerX; 119 | pointerX = qMax( minPointerX, pointerX ); 120 | pointerX = qMin( maxPointerX, pointerX ); 121 | } 122 | 123 | void ColorSlider::incPointer(int val) { 124 | movePointer(pointerX+val); 125 | } 126 | 127 | void ColorSlider::decPointer(int val) { 128 | movePointer(pointerX-val); 129 | } 130 | 131 | 132 | void ColorSlider::drawPointer(QPainter& p) { 133 | correctPointer(); 134 | 135 | pointerY = height()/2; 136 | 137 | QPen pen(pointerBorderColor, pointerBorder); 138 | p.setPen(pen); 139 | p.setBrush(pointerFillColor); 140 | p.drawEllipse( QPoint(pointerX, pointerY), pointerR, pointerR ); 141 | 142 | pen.setColor(pointerLineColor); 143 | pen.setCapStyle(Qt::FlatCap); 144 | p.setPen(pen); 145 | 146 | p.drawLine( QPoint(pointerX, sliderY), QPoint(pointerX, pointerY-pointerR-pointerBorder/2) ); 147 | p.drawLine( QPoint(pointerX, sliderY+sliderH), QPoint(pointerX, pointerY+pointerR+pointerBorder/2) ); 148 | } 149 | 150 | void ColorSlider::drawBorder(QPainter& p) { 151 | QRectF rectangle( sliderX, sliderY, sliderW, sliderH ); // set inner rect coordinates (the border will be outer) 152 | Services::drawRoundRect( p, rectangle, border, borderRadius, borderColor ); 153 | } 154 | 155 | 156 | void ColorSlider::updateColor() { 157 | sliderVal = pointerX - minPointerX; 158 | sliderVal = qMax(0, sliderVal); 159 | sliderVal = qMin(maxRange, sliderVal); 160 | } 161 | 162 | 163 | // ---------------------------------------------- correction ---------------------------------------------- 164 | 165 | qreal ColorSlider::normalizeVal(int val) { 166 | qreal h = (qreal)val/maxRange; 167 | return h; 168 | } 169 | 170 | int ColorSlider::normalizePointerX(qreal val) { 171 | qreal d = val*maxRange; 172 | return qCeil(d); 173 | } 174 | 175 | 176 | // ---------------------------------------------- slots ---------------------------------------------- 177 | 178 | void ColorSlider::ctrlPressed() { 179 | ctrlHeld = true; 180 | } 181 | void ColorSlider::ctrlReleased() { 182 | ctrlHeld = false; 183 | } 184 | 185 | 186 | // ---------------------------------------------- other ---------------------------------------------- 187 | 188 | void ColorSlider::updatePaint() { 189 | update(); 190 | } 191 | 192 | void ColorSlider::log(QString format, int var) { 193 | qDebug() << QString(format).arg(var); 194 | } 195 | 196 | void ColorSlider::log(QString format, qreal var) { 197 | qDebug() << QString(format).arg(var); 198 | } 199 | -------------------------------------------------------------------------------- /Widgets/ColorWidgets/svselector.cpp: -------------------------------------------------------------------------------- 1 | #include "svselector.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "Service/services.h" 8 | 9 | 10 | // ---------------------------------------------------------------------------------------------------- 11 | 12 | SVSelector::SVSelector(QWidget *parent) : ColorWidget(parent) 13 | { 14 | pointerX = maxSV; 15 | } 16 | 17 | void SVSelector::paintEvent(QPaintEvent *event) 18 | { 19 | QColor color; 20 | 21 | QPainter p(this); 22 | p.setRenderHint(QPainter::Antialiasing); 23 | 24 | if (!selectorDrawn) { 25 | hueLayerImage = QImage(maxSV+1, maxSV+1, QImage::Format_RGB32); 26 | for (int s = 0; s <= maxSV; s++) { 27 | for (int v = 0; v <= maxSV; v++) { 28 | color.setHsv(h, s, v); 29 | hueLayerImage.setPixel(s, maxSV-v, color.rgb()); 30 | } 31 | } 32 | 33 | selectorDrawn = true; 34 | } 35 | p.drawImage(border, border, hueLayerImage); 36 | 37 | drawPointer(p); 38 | drawBorder(p); 39 | } 40 | 41 | void SVSelector::mousePressEvent(QMouseEvent *e) 42 | { 43 | if ( e->button() == Qt::MiddleButton ) { 44 | middlePresed = true; 45 | e->ignore(); 46 | } 47 | else { 48 | middlePresed = false; 49 | hideCursor(e); 50 | movePointer( e->x(), e->y() ); 51 | updateColor(); 52 | } 53 | } 54 | 55 | void SVSelector::mouseMoveEvent(QMouseEvent *e) 56 | { 57 | if (middlePresed) { 58 | e->ignore(); 59 | } 60 | else { 61 | hideCursor(e); 62 | movePointer( e->x(), e->y() ); 63 | updateColor(); 64 | } 65 | } 66 | 67 | void SVSelector::mouseReleaseEvent(QMouseEvent *e) 68 | { 69 | restoreCursor(); 70 | e->ignore(); 71 | } 72 | 73 | void SVSelector::wheelEvent(QWheelEvent *e) 74 | { 75 | QPoint p = e->angleDelta(); 76 | int y = p.y(); 77 | 78 | int val = 1; 79 | if (ctrlHeld) val = 10; 80 | 81 | if (shiftHeld) { 82 | if (y>0) incPointerX(val); 83 | if (y<0) decPointerX(val); 84 | } 85 | else { 86 | if (y<0) incPointerY(val); 87 | if (y>0) decPointerY(val); 88 | } 89 | 90 | updateColor(); 91 | e->accept(); 92 | } 93 | 94 | 95 | // ---------------------------------------------- service ---------------------------------------------- 96 | 97 | void SVSelector::drawPointer(QPainter& p) { 98 | correctPointer(); 99 | drawCircle(p); 100 | } 101 | 102 | void SVSelector::incPointerX(int val) { 103 | movePointer(pointerX+val, pointerY); 104 | } 105 | 106 | void SVSelector::decPointerX(int val) { 107 | movePointer(pointerX-val, pointerY); 108 | } 109 | 110 | void SVSelector::incPointerY(int val) { 111 | movePointer(pointerX, pointerY+val); 112 | } 113 | 114 | void SVSelector::decPointerY(int val) { 115 | movePointer(pointerX, pointerY-val); 116 | } 117 | 118 | void SVSelector::correctPointer() { 119 | pointerX = s + minPointerXY; // to update pointer XY on text edit 120 | pointerY = maxPointerXY - v; 121 | 122 | pointerX = qMax( minPointerXY, pointerX ); 123 | pointerX = qMin( maxPointerXY, pointerX ); 124 | 125 | pointerY = qMax( minPointerXY, pointerY ); 126 | pointerY = qMin( maxPointerXY, pointerY ); 127 | } 128 | 129 | void SVSelector::movePointer(int x, int y) { 130 | pointerX = x; 131 | pointerY = y; 132 | 133 | update(); // if pointer doesn't move, move update() to both mousePress() and mouseMove() events 134 | // repaint(); // on repaint() here it doesn't move (it repaints before the correction) 135 | } 136 | 137 | void SVSelector::drawBorder(QPainter& p) { 138 | QRectF rectangle( selectorX, selectorY, selectorSize, selectorSize ); 139 | Services::drawRoundRect( p, rectangle, border, borderRadius, borderColor ); 140 | } 141 | 142 | void SVSelector::updateColor() { 143 | s = pointerX - border; 144 | v = maxSV - (pointerY - border); 145 | 146 | s = qMax(0, s); // s = qMin( maxSV, qMax(0, s) ); 147 | s = qMin(maxSV, s); 148 | 149 | v = qMax(0, v); 150 | v = qMin(maxSV, v); 151 | 152 | color.setHsv(h, s, v); 153 | 154 | emit colorChanged(color); 155 | emit saturationChanged(color); 156 | emit valueChanged(color); 157 | } 158 | 159 | void SVSelector::reupdateColor() 160 | { 161 | emit saturationChanged(color); 162 | emit valueChanged(color); 163 | } 164 | 165 | // ---------------------------------------------- slots ---------------------------------------------- 166 | 167 | void SVSelector::changeHue(QColor color) 168 | { 169 | selectorDrawn = false; 170 | 171 | h = color.hue(); 172 | correctPointer(); 173 | 174 | QColor newColor; 175 | newColor.setHsv(h, s, v); 176 | emit colorChanged(newColor); 177 | 178 | update(); 179 | // repaint(); 180 | } 181 | 182 | // ---------------------------------------------- set/get ---------------------------------------------- 183 | 184 | void SVSelector::setS(QColor color) 185 | { 186 | s = color.saturation(); 187 | 188 | correctPointer(); 189 | update(); 190 | 191 | updateColor(); 192 | } 193 | 194 | void SVSelector::setV(QColor color) 195 | { 196 | v = color.value(); 197 | 198 | correctPointer(); 199 | update(); 200 | 201 | updateColor(); 202 | } 203 | 204 | void SVSelector::setSV(int s, int v) { 205 | this->s = s; 206 | this->v = v; 207 | 208 | correctPointer(); 209 | update(); 210 | 211 | updateColor(); 212 | } 213 | -------------------------------------------------------------------------------- /Widgets/Sliders/CMYK/cmykslider.cpp: -------------------------------------------------------------------------------- 1 | #include "cmykslider.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | // ---------------------------------------------- consts ---------------------------------------------- 9 | 10 | const int maxCMYK = 255; 11 | 12 | 13 | // ---------------------------------------------------------------------------------------------------- 14 | 15 | CMYKSlider::CMYKSlider(QWidget *parent) : ColorSlider(parent) 16 | { 17 | sliderType = Cyan; 18 | 19 | c = 0; 20 | m = maxF; 21 | y = maxF; 22 | k = 0; 23 | 24 | color.setCmykF(c, m, y, k); 25 | } 26 | 27 | void CMYKSlider::paintEvent(QPaintEvent *e) 28 | { 29 | QPainter p(this); 30 | p.setRenderHint(QPainter::Antialiasing); 31 | 32 | qreal val; 33 | switch (sliderType) { 34 | case Cyan: 35 | val = c; 36 | break; 37 | case Magenta: 38 | val = m; 39 | break; 40 | case Yellow: 41 | val = y; 42 | break; 43 | case Black: 44 | val = k; 45 | break; 46 | } 47 | calcVars(val); 48 | 49 | if (!sliderDrawn || widthChanged) { 50 | paintComponent(); 51 | } 52 | p.drawPixmap(sliderX, sliderY, sliderPixmap); 53 | 54 | drawPointer(p); 55 | drawBorder(p); 56 | } 57 | 58 | void CMYKSlider::paintComponent() { 59 | sliderPixmap = QPixmap(sliderW, sliderH); 60 | QPainter tempP( &sliderPixmap ); 61 | 62 | QPointF p1( sliderX, sliderH/2 ); 63 | QPointF p2( sliderX+sliderW, sliderH/2 ); 64 | QLinearGradient grad(p1, p2); 65 | 66 | switch (sliderType) { 67 | case Cyan: 68 | paintCyan(grad); 69 | break; 70 | case Magenta: 71 | paintMagenta(grad); 72 | break; 73 | case Yellow: 74 | paintYellow(grad); 75 | break; 76 | case Black: 77 | paintBlack(grad); 78 | break; 79 | } 80 | 81 | tempP.setPen(Qt::NoPen); 82 | tempP.setBrush( QBrush(grad) ); 83 | tempP.drawRect(0, 0, sliderW, sliderH); 84 | 85 | sliderDrawn = true; 86 | widthChanged = false; 87 | } 88 | 89 | void CMYKSlider::paintCyan(QLinearGradient &grad) { 90 | grad.setColorAt( 0, QColor::fromCmykF(0, m, y, k) ); 91 | grad.setColorAt( 1, QColor::fromCmykF(1, m, y, k) ); 92 | } 93 | 94 | void CMYKSlider::paintMagenta(QLinearGradient &grad) { 95 | grad.setColorAt( 0, QColor::fromCmykF(c, 0, y, k) ); 96 | grad.setColorAt( 1, QColor::fromCmykF(c, 1, y, k) ); 97 | } 98 | 99 | void CMYKSlider::paintYellow(QLinearGradient &grad) { 100 | grad.setColorAt( 0, QColor::fromCmykF(c, m, 0, k) ); 101 | grad.setColorAt( 1, QColor::fromCmykF(c, m, 1, k) ); 102 | } 103 | 104 | void CMYKSlider::paintBlack(QLinearGradient &grad) { 105 | grad.setColorAt( 0, QColor::fromCmykF(c, m, y, 0) ); 106 | grad.setColorAt( 1, QColor::fromCmykF(c, m, y, 1) ); 107 | } 108 | 109 | 110 | void CMYKSlider::updateColor() { 111 | ColorSlider::updateColor(); 112 | 113 | qreal val; 114 | val = normalizeVal( sliderVal ); 115 | val = qMax(0.0, val); 116 | val = qMin(maxF, val); 117 | 118 | switch (sliderType) { 119 | case Cyan: 120 | c = val; 121 | color.setCmykF(c, m, y, k); 122 | emit cyanChanged(color); 123 | break; 124 | case Magenta: 125 | m = val; 126 | color.setCmykF(c, m, y, k); 127 | emit magentaChanged(color); 128 | break; 129 | case Yellow: 130 | y = val; 131 | color.setCmykF(c, m, y, k); 132 | emit yellowChanged(color); 133 | break; 134 | case Black: 135 | k = val; 136 | color.setCmykF(c, m, y, k); 137 | emit blackChanged(color); 138 | break; 139 | } 140 | } 141 | 142 | // ---------------------------------------------- set/get ---------------------------------------------- 143 | 144 | void CMYKSlider::setColorComponent(QColor color, SliderType stype) { 145 | if (this->color == color) { 146 | return; 147 | } 148 | 149 | qreal val; 150 | switch (stype) { 151 | case Cyan: 152 | c = color.cyanF(); 153 | val = c; 154 | break; 155 | case Magenta: 156 | m = color.magentaF(); 157 | val = m; 158 | break; 159 | case Yellow: 160 | y = color.yellowF(); 161 | val = y; 162 | break; 163 | case Black: 164 | k = color.blackF(); 165 | val = k; 166 | break; 167 | } 168 | 169 | sliderVal = qCeil( val * maxRange ); 170 | this->color = QColor::fromCmykF(c, m, y, k); 171 | update(); 172 | } 173 | 174 | void CMYKSlider::setC(QColor color) { 175 | setColorComponent(color, Cyan); 176 | } 177 | 178 | void CMYKSlider::setM(QColor color) { 179 | setColorComponent(color, Magenta); 180 | } 181 | 182 | void CMYKSlider::setY(QColor color) { 183 | setColorComponent(color, Yellow); 184 | } 185 | 186 | void CMYKSlider::setK(QColor color) { 187 | setColorComponent(color, Black); 188 | } 189 | 190 | // ---------------------------------------------- slots ---------------------------------------------- 191 | 192 | void CMYKSlider::updateSlider() { 193 | this->color = QColor::fromCmykF(c, m, y, k); 194 | sliderDrawn = false; 195 | update(); 196 | } 197 | 198 | void CMYKSlider::changeCyan(QColor color) { 199 | c = color.cyanF(); 200 | updateSlider(); 201 | } 202 | 203 | void CMYKSlider::changeMagenta(QColor color) { 204 | m = color.magentaF(); 205 | updateSlider(); 206 | } 207 | 208 | void CMYKSlider::changeYellow(QColor color) { 209 | y = color.yellowF(); 210 | updateSlider(); 211 | } 212 | 213 | void CMYKSlider::changeBlack(QColor color) { 214 | k = color.blackF(); 215 | updateSlider(); 216 | } 217 | 218 | // ---------------------------------------------- service ---------------------------------------------- 219 | 220 | void CMYKSlider::init() { 221 | if (sliderType == Magenta || sliderType == Yellow) { 222 | sliderVal = maxCMYK; 223 | } 224 | } 225 | 226 | void CMYKSlider::setType(SliderType type) { 227 | sliderType = type; 228 | } 229 | -------------------------------------------------------------------------------- /Service/validator.cpp: -------------------------------------------------------------------------------- 1 | #include "validator.h" 2 | 3 | #include 4 | 5 | 6 | // -------------------------------------------- consts -------------------------------------------- 7 | 8 | const int maxH = 359; 9 | const int maxS = 255; 10 | const int maxV = 255; 11 | 12 | const int maxRGB = 255; 13 | const int maxCMYK = 255; 14 | 15 | const int maxHex = 255; 16 | const int maxShortHex = 15; 17 | 18 | // ---------------------------------------------------------------------------------------------------- 19 | 20 | Validator::Validator(QObject *parent) : 21 | QObject(parent) 22 | { 23 | } 24 | 25 | bool Validator::checkColorText(QString text, Vars::ColorType colorType) { 26 | int size = getSizeByType(colorType); 27 | 28 | QStringList list; 29 | list = text.split(" "); 30 | if (list.size()!=size) return false; 31 | 32 | foreach(QString comp, list) { 33 | if (!comp.length()) 34 | return false; 35 | } 36 | 37 | foreach(QString comp, list) { 38 | bool ok; 39 | comp.toInt(&ok); 40 | if (!ok) return false; 41 | } 42 | 43 | return true; 44 | } 45 | 46 | bool Validator::checkValueByType(QString text, Vars::ColorType colorType) { 47 | switch (colorType) { 48 | case Vars::HSV: 49 | return checkValueHSV(text); 50 | case Vars::RGB: 51 | return checkValueRGB(text); 52 | case Vars::CMYK: 53 | return checkValueCMYK(text); 54 | case Vars::Hex: 55 | return checkValueHex(text); 56 | } 57 | return false; 58 | } 59 | 60 | bool Validator::checkValueHSV(QString text) { 61 | QStringList list; 62 | list = text.split(" "); 63 | 64 | int h = list[0].toInt(); 65 | int s = list[1].toInt(); 66 | int v = list[2].toInt(); 67 | 68 | if (h<0 || h>maxH) return false; 69 | if (s<0 || s>maxH) return false; 70 | if (v<0 || v>maxH) return false; 71 | 72 | return true; 73 | } 74 | 75 | bool Validator::checkValueRGB(QString text) { 76 | QStringList list; 77 | list = text.split(" "); 78 | 79 | int r = list[0].toInt(); 80 | int g = list[1].toInt(); 81 | int b = list[2].toInt(); 82 | 83 | if (r<0 || r>maxRGB) return false; 84 | if (g<0 || g>maxRGB) return false; 85 | if (b<0 || b>maxRGB) return false; 86 | 87 | return true; 88 | } 89 | 90 | bool Validator::checkValueCMYK(QString text) { 91 | QStringList list; 92 | list = text.split(" "); 93 | 94 | int c = list[0].toInt(); 95 | int m = list[1].toInt(); 96 | int y = list[2].toInt(); 97 | int k = list[3].toInt(); 98 | 99 | if (c<0 || c>maxCMYK) return false; 100 | if (m<0 || m>maxCMYK) return false; 101 | if (y<0 || y>maxCMYK) return false; 102 | if (k<0 || k>maxCMYK) return false; 103 | 104 | return true; 105 | } 106 | 107 | bool Validator::checkValueHex(QString text) { 108 | int len = text.length(); 109 | if ( len!=6 && len!=3 ) return false; 110 | 111 | bool ok; 112 | int factor = len/3; 113 | 114 | for (int i = 0; i<3; i++) { 115 | QString comp = text.mid(i*factor, factor); 116 | int val = comp.toInt(&ok, 16); 117 | if (!ok) return false; 118 | 119 | if (len == 3) { 120 | if (val<0 || val>maxShortHex) return false; 121 | } 122 | else { 123 | if (val<0 || val>maxHex) return false; 124 | } 125 | } 126 | 127 | return true; 128 | } 129 | 130 | bool Validator::checkComponentVal(int val, Vars::ColorType colorType, int group, int hexLen) { 131 | if (colorType == Vars::HSV) { 132 | switch (group) { 133 | case 0: 134 | return (val >= 0 && val <= maxH); 135 | case 1: 136 | return (val >= 0 && val <= maxS); 137 | case 2: 138 | return (val >= 0 && val <= maxV); 139 | } 140 | } 141 | 142 | if (colorType == Vars::RGB) { 143 | return (val >= 0 && val <= maxRGB); 144 | } 145 | 146 | if (colorType == Vars::CMYK) { 147 | switch (group) { 148 | case 0: 149 | return (val >= 0 && val <= maxCMYK); 150 | case 1: 151 | return (val >= 0 && val <= maxCMYK); 152 | case 2: 153 | return (val >= 0 && val <= maxCMYK); 154 | case 3: 155 | return (val >= 0 && val <= maxCMYK); 156 | } 157 | } 158 | 159 | if (colorType == Vars::Hex) { 160 | if (hexLen == 3) 161 | return (val >= 0 && val <= maxShortHex); 162 | else if (hexLen == 6) 163 | return (val >= 0 && val <= maxHex); 164 | } 165 | 166 | return false; 167 | } 168 | 169 | 170 | void Validator::correctHSV(QColor& color) { 171 | int h = color.hue(); 172 | int s = color.saturation(); 173 | int v = color.value(); 174 | 175 | h = qMin(maxH, qMax(0, h)); 176 | s = qMin(maxS, qMax(0, s)); 177 | v = qMin(maxV, qMax(0, v)); 178 | 179 | color.setHsv(h, s, v); 180 | } 181 | 182 | void Validator::correctRGB(QColor& color) { 183 | int r = color.red(); 184 | int g = color.green(); 185 | int b = color.blue(); 186 | 187 | r = qMin(maxRGB, qMax(0, r)); 188 | g = qMin(maxRGB, qMax(0, g)); 189 | b = qMin(maxRGB, qMax(0, b)); 190 | 191 | color.setRgb(r, g, b); 192 | } 193 | 194 | void Validator::correctCMYK(QColor& color) { 195 | int c = color.cyan(); 196 | int m = color.magenta(); 197 | int y = color.yellow(); 198 | int k = color.black(); 199 | 200 | c = qMin(maxCMYK, qMax(0, c)); 201 | m = qMin(maxCMYK, qMax(0, m)); 202 | y = qMin(maxCMYK, qMax(0, y)); 203 | k = qMin(maxCMYK, qMax(0, k)); 204 | 205 | color.setCmyk(c, m, y, k); 206 | } 207 | 208 | 209 | QString Validator::correctColorText(QString text) { 210 | if (!text.length()) return text; 211 | return text.trimmed().replace(",", " ").replace(QRegExp("\\s+"), " "); 212 | } 213 | 214 | 215 | // --------------------------------------------- service --------------------------------------------- 216 | 217 | int Validator::getSizeByType(Vars::ColorType colorType) { 218 | switch (colorType) { 219 | case Vars::HSV: 220 | return 3; 221 | case Vars::RGB: 222 | return 3; 223 | case Vars::CMYK: 224 | return 4; 225 | default: 226 | return 0; 227 | } 228 | } 229 | -------------------------------------------------------------------------------- /Widgets/colortext.cpp: -------------------------------------------------------------------------------- 1 | #include "colortext.h" 2 | 3 | #include 4 | 5 | #include "Service/validator.h" 6 | 7 | 8 | ColorText::ColorText(QWidget *parent) : QLineEdit(parent) 9 | { 10 | colorType = Vars::HSV; 11 | separator = " "; 12 | } 13 | 14 | void ColorText::setType(Vars::ColorType colorType) { 15 | this->colorType = colorType; 16 | if (colorType == Vars::Hex) 17 | separator = ""; 18 | } 19 | 20 | 21 | void ColorText::updateText(QString text) { 22 | int pos = cursorPosition(); 23 | setText(text); 24 | setCursorPosition(pos); 25 | } 26 | 27 | 28 | 29 | // --------------------------------------------- inc/dec component --------------------------------------------- 30 | 31 | void ColorText::changeComponentVal(int pos, bool inc) { 32 | int val; 33 | int group = -1; 34 | bool ok; 35 | QStringList comp; 36 | QString valText, newValText; 37 | 38 | QString colorText = text(); 39 | 40 | if (colorType == Vars::Hex) { 41 | if ( !Validator::checkValueHex(colorText) ) return; 42 | 43 | len = colorText.length(); 44 | comp = getComponentsFromHex(colorText); 45 | group = getHexGroup(pos, len); 46 | 47 | val = comp[group].toInt(&ok, 16); 48 | 49 | if (inc) val++; 50 | else val--; 51 | if ( !Validator::checkComponentVal(val, colorType, group, len) ) return; 52 | 53 | comp[group] = QString("%1").arg( val, len/3, 16, QChar('0')); 54 | } 55 | else { 56 | if ( !Validator::checkColorText(colorText, colorType) ) return; 57 | if ( !Validator::checkValueByType(colorText, colorType) ) return; 58 | 59 | comp = colorText.split(separator); 60 | QRegExp rx(" "); 61 | int idx = 0; 62 | 63 | while ( (idx = rx.indexIn(colorText, idx)) != -1 ) { 64 | group++; 65 | if (idx >= pos) break; 66 | idx+=rx.matchedLength(); 67 | } 68 | if (idx == -1) group = comp.size()-1; 69 | if (group == -1) return; 70 | 71 | valText = comp[group]; 72 | val = valText.toInt(); 73 | 74 | if (inc) val++; 75 | else val--; 76 | if ( !Validator::checkComponentVal(val, colorType, group) ) return; 77 | 78 | newValText = QString::number(val); 79 | 80 | pos = (idx == -1) ? colorText.length() : idx; 81 | if (inc) { 82 | if ( newValText.length() > valText.length() ) pos++; 83 | } 84 | else { 85 | if ( newValText.length() < valText.length() ) pos--; 86 | } 87 | 88 | comp[group] = newValText; 89 | } 90 | 91 | colorText = comp.join(separator); 92 | setText(colorText); 93 | setCursorPosition(pos); 94 | 95 | textEdited(text()); 96 | } 97 | 98 | 99 | // --------------------------------------------- select component --------------------------------------------- 100 | 101 | void ColorText::selectNextComponent() { 102 | selectComponent(true); 103 | } 104 | 105 | void ColorText::selectPrevComponent() { 106 | selectComponent(false); 107 | } 108 | 109 | void ColorText::selectComponent(bool next) { 110 | int gpos = 0, glen; 111 | int group = -1; 112 | QStringList comp; 113 | 114 | int pos = cursorPosition(); 115 | QString colorText = text(); 116 | 117 | if (colorType == Vars::Hex) { 118 | if ( !Validator::checkValueHex(colorText) ) return; 119 | 120 | len = colorText.length(); 121 | comp = getComponentsFromHex(colorText); 122 | group = getHexGroup(pos, len); 123 | group = getGroupNumber(group, comp.size(), next); 124 | 125 | glen = len/3; 126 | gpos = group*(len/3); 127 | } 128 | else { 129 | if ( !Validator::checkColorText(colorText, colorType) ) return; 130 | if ( !Validator::checkValueByType(colorText, colorType) ) return; 131 | 132 | comp = colorText.split(" "); 133 | QRegExp rx(" "); 134 | int idx = 0; 135 | 136 | while ( (idx = rx.indexIn(colorText, idx)) != -1 ) { 137 | group++; 138 | if (idx >= pos) break; 139 | idx+=rx.matchedLength(); 140 | } 141 | if (idx == -1) group = comp.size()-1; 142 | if (group == -1) return; 143 | 144 | group = getGroupNumber(group, comp.size(), next); 145 | 146 | glen = comp[group].length(); 147 | for (int i = 0; ikey(); 206 | 207 | int pos = cursorPosition(); 208 | 209 | if (key == Qt::Key_Up) { 210 | changeComponentVal(pos, true); 211 | } 212 | else if (key == Qt::Key_Down) { 213 | changeComponentVal(pos, false); 214 | } 215 | else { 216 | QLineEdit::keyPressEvent(e); 217 | } 218 | } 219 | 220 | void ColorText::wheelEvent(QWheelEvent *e) { 221 | int delta = e->delta(); 222 | int x = e->x(); 223 | int y = e->y(); 224 | 225 | int pos = cursorPositionAt(QPoint(x, y)); 226 | 227 | 228 | changeComponentVal(pos, delta > 0); 229 | 230 | // qDebug() << QString("WHEEL: %1, [%2;%3], %4").arg(delta).arg(x).arg(y).arg(pos); 231 | 232 | e->accept(); 233 | } 234 | 235 | bool ColorText::event(QEvent *e) 236 | { 237 | if (e->type() == QEvent::KeyPress) { 238 | QKeyEvent *ke = static_cast(e); 239 | 240 | if ( ke->key() == Qt::Key_Tab ) { 241 | if (ke->modifiers() == Qt::ControlModifier) { 242 | // nextInFocusChain()->setFocus(Qt::TabFocusReason); 243 | emit focusNextField(); 244 | return true; 245 | } 246 | 247 | selectNextComponent(); 248 | return true; 249 | } 250 | else if ( ke->key() == Qt::Key_Backtab ) { 251 | if (ke->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) { 252 | // previousInFocusChain()->setFocus(Qt::BacktabFocusReason); 253 | emit focusPrevField(); 254 | return true; 255 | } 256 | 257 | selectPrevComponent(); 258 | return true; 259 | } 260 | 261 | } 262 | 263 | return QLineEdit::event(e); 264 | } 265 | -------------------------------------------------------------------------------- /Views/sliderswindow.cpp: -------------------------------------------------------------------------------- 1 | #include "sliderswindow.h" 2 | #include "ui_sliderswindow.h" 3 | 4 | #include 5 | #include 6 | 7 | 8 | SlidersWindow::SlidersWindow(SlidersController *slidersController, QWidget *parent) : 9 | QMainWindow(parent), 10 | ui(new Ui::SlidersWindow) 11 | { 12 | ui->setupUi(this); 13 | 14 | this->slidersController = slidersController; 15 | 16 | addActions(); 17 | addKeyActions(); 18 | addShortcuts(); 19 | init(); 20 | } 21 | 22 | SlidersWindow::~SlidersWindow() 23 | { 24 | delete ui; 25 | } 26 | 27 | void SlidersWindow::init() { 28 | // setAttribute(Qt::WA_DeleteOnClose); 29 | 30 | ui->hSlider->setType(HSVSlider::Hue); 31 | ui->sSlider->setType(HSVSlider::Saturation); 32 | ui->vSlider->setType(HSVSlider::Value); 33 | 34 | ui->sSlider->init(); 35 | ui->vSlider->init(); 36 | 37 | 38 | ui->rSlider->setType(RGBSlider::Red); 39 | ui->gSlider->setType(RGBSlider::Green); 40 | ui->bSlider->setType(RGBSlider::Blue); 41 | 42 | ui->rSlider->init(); 43 | 44 | 45 | ui->cSlider->setType(CMYKSlider::Cyan); 46 | ui->mSlider->setType(CMYKSlider::Magenta); 47 | ui->ySlider->setType(CMYKSlider::Yellow); 48 | ui->kSlider->setType(CMYKSlider::Black); 49 | 50 | ui->mSlider->init(); 51 | ui->ySlider->init(); 52 | } 53 | 54 | void SlidersWindow::addActions() { 55 | connect( ui->hSlider, SIGNAL(hueChanged(QColor)), slidersController, SLOT(changeHue(QColor)) ); 56 | connect( ui->sSlider, SIGNAL(saturationChanged(QColor)), slidersController, SLOT(changeSaturation(QColor)) ); 57 | connect( ui->vSlider, SIGNAL(valueChanged(QColor)), slidersController, SLOT(changeValue(QColor)) ); 58 | 59 | connect( ui->rSlider, SIGNAL(redChanged(QColor)), slidersController, SLOT(changeRed(QColor)) ); 60 | connect( ui->gSlider, SIGNAL(greenChanged(QColor)), slidersController, SLOT(changeGreen(QColor)) ); 61 | connect( ui->bSlider, SIGNAL(blueChanged(QColor)), slidersController, SLOT(changeBlue(QColor)) ); 62 | 63 | connect( ui->cSlider, SIGNAL(cyanChanged(QColor)), slidersController, SLOT(changeCyan(QColor)) ); 64 | connect( ui->mSlider, SIGNAL(magentaChanged(QColor)), slidersController, SLOT(changeMagenta(QColor)) ); 65 | connect( ui->ySlider, SIGNAL(yellowChanged(QColor)), slidersController, SLOT(changeYellow(QColor)) ); 66 | connect( ui->kSlider, SIGNAL(blackChanged(QColor)), slidersController, SLOT(changeBlack(QColor)) ); 67 | 68 | 69 | connect( ui->spHue, SIGNAL(valueChanged(int)), slidersController, SLOT(changeHue(int)) ); 70 | connect( ui->spSaturation, SIGNAL(valueChanged(int)), slidersController, SLOT(changeSaturation(int)) ); 71 | connect( ui->spValue, SIGNAL(valueChanged(int)), slidersController, SLOT(changeValue(int)) ); 72 | 73 | connect( ui->spRed, SIGNAL(valueChanged(int)), slidersController, SLOT(changeRed(int)) ); 74 | connect( ui->spGreen, SIGNAL(valueChanged(int)), slidersController, SLOT(changeGreen(int)) ); 75 | connect( ui->spBlue, SIGNAL(valueChanged(int)), slidersController, SLOT(changeBlue(int)) ); 76 | 77 | connect( ui->spCyan, SIGNAL(valueChanged(int)), slidersController, SLOT(changeCyan(int)) ); 78 | connect( ui->spMagenta, SIGNAL(valueChanged(int)), slidersController, SLOT(changeMagenta(int)) ); 79 | connect( ui->spYellow, SIGNAL(valueChanged(int)), slidersController, SLOT(changeYellow(int)) ); 80 | connect( ui->spBlack, SIGNAL(valueChanged(int)), slidersController, SLOT(changeBlack(int)) ); 81 | } 82 | 83 | void SlidersWindow::addKeyActions() { 84 | connect( ui->hSlider, SIGNAL(middlePressedSignal(QMouseEvent*)), this, SLOT(sliderMiddlePressed(QMouseEvent*)) ); 85 | connect( ui->sSlider, SIGNAL(middlePressedSignal(QMouseEvent*)), this, SLOT(sliderMiddlePressed(QMouseEvent*)) ); 86 | connect( ui->vSlider, SIGNAL(middlePressedSignal(QMouseEvent*)), this, SLOT(sliderMiddlePressed(QMouseEvent*)) ); 87 | 88 | connect( ui->rSlider, SIGNAL(middlePressedSignal(QMouseEvent*)), this, SLOT(sliderMiddlePressed(QMouseEvent*)) ); 89 | connect( ui->gSlider, SIGNAL(middlePressedSignal(QMouseEvent*)), this, SLOT(sliderMiddlePressed(QMouseEvent*)) ); 90 | connect( ui->bSlider, SIGNAL(middlePressedSignal(QMouseEvent*)), this, SLOT(sliderMiddlePressed(QMouseEvent*)) ); 91 | 92 | connect( ui->cSlider, SIGNAL(middlePressedSignal(QMouseEvent*)), this, SLOT(sliderMiddlePressed(QMouseEvent*)) ); 93 | connect( ui->mSlider, SIGNAL(middlePressedSignal(QMouseEvent*)), this, SLOT(sliderMiddlePressed(QMouseEvent*)) ); 94 | connect( ui->ySlider, SIGNAL(middlePressedSignal(QMouseEvent*)), this, SLOT(sliderMiddlePressed(QMouseEvent*)) ); 95 | connect( ui->kSlider, SIGNAL(middlePressedSignal(QMouseEvent*)), this, SLOT(sliderMiddlePressed(QMouseEvent*)) ); 96 | 97 | 98 | connect( this, SIGNAL(ctrlPressed()), ui->hSlider, SLOT(ctrlPressed()) ); 99 | connect( this, SIGNAL(ctrlReleased()), ui->hSlider, SLOT(ctrlReleased()) ); 100 | connect( this, SIGNAL(ctrlPressed()), ui->sSlider, SLOT(ctrlPressed()) ); 101 | connect( this, SIGNAL(ctrlReleased()), ui->sSlider, SLOT(ctrlReleased()) ); 102 | connect( this, SIGNAL(ctrlPressed()), ui->vSlider, SLOT(ctrlPressed()) ); 103 | connect( this, SIGNAL(ctrlReleased()), ui->vSlider, SLOT(ctrlReleased()) ); 104 | 105 | connect( this, SIGNAL(ctrlPressed()), ui->rSlider, SLOT(ctrlPressed()) ); 106 | connect( this, SIGNAL(ctrlReleased()), ui->rSlider, SLOT(ctrlReleased()) ); 107 | connect( this, SIGNAL(ctrlPressed()), ui->gSlider, SLOT(ctrlPressed()) ); 108 | connect( this, SIGNAL(ctrlReleased()), ui->gSlider, SLOT(ctrlReleased()) ); 109 | connect( this, SIGNAL(ctrlPressed()), ui->bSlider, SLOT(ctrlPressed()) ); 110 | connect( this, SIGNAL(ctrlReleased()), ui->bSlider, SLOT(ctrlReleased()) ); 111 | 112 | connect( this, SIGNAL(ctrlPressed()), ui->cSlider, SLOT(ctrlPressed()) ); 113 | connect( this, SIGNAL(ctrlReleased()), ui->cSlider, SLOT(ctrlReleased()) ); 114 | connect( this, SIGNAL(ctrlPressed()), ui->mSlider, SLOT(ctrlPressed()) ); 115 | connect( this, SIGNAL(ctrlReleased()), ui->mSlider, SLOT(ctrlReleased()) ); 116 | connect( this, SIGNAL(ctrlPressed()), ui->ySlider, SLOT(ctrlPressed()) ); 117 | connect( this, SIGNAL(ctrlReleased()), ui->ySlider, SLOT(ctrlReleased()) ); 118 | connect( this, SIGNAL(ctrlPressed()), ui->kSlider, SLOT(ctrlPressed()) ); 119 | connect( this, SIGNAL(ctrlReleased()), ui->kSlider, SLOT(ctrlReleased()) ); 120 | } 121 | 122 | void SlidersWindow::addShortcuts() { 123 | QShortcut *quit = new QShortcut(QKeySequence("Esc"), this); 124 | connect( quit, SIGNAL(activated()), this, SLOT(close()) ); 125 | } 126 | 127 | 128 | // --------------------------------------------- slots --------------------------------------------- 129 | 130 | void SlidersWindow::sliderMiddlePressed(QMouseEvent* e) { 131 | mouseDown = true; 132 | mouseMoved = false; 133 | 134 | mx = e->x(); 135 | my = e->y(); 136 | } 137 | 138 | 139 | // --------------------------------------------- events --------------------------------------------- 140 | 141 | void SlidersWindow::mousePressEvent(QMouseEvent *e) 142 | { 143 | mouseDown = true; 144 | mouseMoved = false; 145 | 146 | mx = e->x(); 147 | my = e->y(); 148 | } 149 | 150 | void SlidersWindow::mouseReleaseEvent(QMouseEvent *e) 151 | { 152 | mouseDown = false; 153 | if (e->button() == Qt::MiddleButton && !mouseMoved) close(); 154 | } 155 | 156 | void SlidersWindow::mouseMoveEvent(QMouseEvent *e) 157 | { 158 | if (mouseDown) { 159 | mouseMoved = true; 160 | 161 | int gx = e->globalX(); 162 | int gy = e->globalY(); 163 | 164 | int corrX = geometry().x()-x(); 165 | int corrY = geometry().y()-y(); 166 | 167 | int moveX = gx-mx-corrX; 168 | int moveY = gy-my-corrY; 169 | 170 | move(moveX, moveY); 171 | } 172 | } 173 | 174 | void SlidersWindow::keyPressEvent(QKeyEvent *e) 175 | { 176 | int key = e->key(); 177 | if (key == Qt::Key_Control) { 178 | emit ctrlPressed(); 179 | } 180 | } 181 | 182 | void SlidersWindow::keyReleaseEvent(QKeyEvent *e) 183 | { 184 | int key = e->key(); 185 | if (key == Qt::Key_Control) { 186 | emit ctrlReleased(); 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /Controllers/sliderscontroller.cpp: -------------------------------------------------------------------------------- 1 | #include "sliderscontroller.h" 2 | #include "ui_sliderswindow.h" 3 | 4 | // ------------------------------------------------------------------------------------------------ 5 | 6 | SlidersController::SlidersController(QObject* parent) : QObject(parent) 7 | { 8 | addActions(); 9 | init(); 10 | } 11 | 12 | void SlidersController::init() { 13 | hueSpinManualEdit = true; 14 | saturationSpinManualEdit = true; 15 | valueSpinManualEdit = true; 16 | 17 | redSpinManualEdit = true; 18 | greenSpinManualEdit = true; 19 | blueSpinManualEdit = true; 20 | 21 | cyanSpinManualEdit = true; 22 | magentaSpinManualEdit = true; 23 | yellowSpinManualEdit = true; 24 | blackSpinManualEdit = true; 25 | } 26 | 27 | void SlidersController::addActions() { 28 | connectRGB(); 29 | connectCMYK(); 30 | } 31 | 32 | void SlidersController::setView(SlidersWindow* slidersView) { 33 | this->slidersView = slidersView; 34 | } 35 | 36 | 37 | void SlidersController::connectRGB() { 38 | connect( this, SIGNAL(RGBChanged(QColor)), this, SLOT(changeRedFromSelector(QColor)) ); 39 | connect( this, SIGNAL(RGBChanged(QColor)), this, SLOT(changeGreenFromSelector(QColor)) ); 40 | connect( this, SIGNAL(RGBChanged(QColor)), this, SLOT(changeBlueFromSelector(QColor)) ); 41 | } 42 | 43 | void SlidersController::disconnectRGB() { 44 | disconnect( this, SIGNAL(RGBChanged(QColor)), 0, 0 ); 45 | } 46 | 47 | void SlidersController::connectCMYK() { 48 | connect( this, SIGNAL(CMYKChanged(QColor)), this, SLOT(changeCyanFromSelector(QColor)) ); 49 | connect( this, SIGNAL(CMYKChanged(QColor)), this, SLOT(changeMagentaFromSelector(QColor)) ); 50 | connect( this, SIGNAL(CMYKChanged(QColor)), this, SLOT(changeYellowFromSelector(QColor)) ); 51 | connect( this, SIGNAL(CMYKChanged(QColor)), this, SLOT(changeBlackFromSelector(QColor)) ); 52 | } 53 | 54 | void SlidersController::disconnectCMYK() { 55 | disconnect( this, SIGNAL(CMYKChanged(QColor)), 0, 0 ); 56 | } 57 | 58 | 59 | // --------------------------------------------- HSV --------------------------------------------- 60 | 61 | // ===== hue ===== 62 | 63 | void SlidersController::changeHue(int h) { 64 | if (hueSpinManualEdit) { 65 | QColor filter = QColor::fromHsv(h, 0, 0); 66 | changeHue(filter); 67 | } 68 | hueSpinManualEdit = true; 69 | } 70 | 71 | void SlidersController::changeHue(QColor color) { 72 | emit hueChanged(color); 73 | } 74 | 75 | void SlidersController::changeHueFromSelector(QColor color) { 76 | hueSpinManualEdit = false; 77 | 78 | slidersView->ui->hSlider->setH(color); 79 | slidersView->ui->spHue->setValue(color.hue()); 80 | 81 | slidersView->ui->sSlider->changeHue(color); 82 | slidersView->ui->vSlider->changeHue(color); 83 | } 84 | 85 | // ===== saturation ===== 86 | 87 | void SlidersController::changeSaturation(int s) { 88 | if (saturationSpinManualEdit) { 89 | QColor filter = QColor::fromHsv(0, s, 0); 90 | changeSaturation(filter); 91 | } 92 | saturationSpinManualEdit = true; 93 | } 94 | 95 | void SlidersController::changeSaturation(QColor color) { 96 | emit saturationChanged(color); 97 | } 98 | 99 | void SlidersController::changeSaturationFromSelector(QColor color) { 100 | saturationSpinManualEdit = false; 101 | 102 | slidersView->ui->sSlider->setS(color); 103 | slidersView->ui->spSaturation->setValue(color.saturation()); 104 | 105 | slidersView->ui->hSlider->changeSaturation(color); 106 | slidersView->ui->vSlider->changeSaturation(color); 107 | } 108 | 109 | // ===== value ===== 110 | 111 | void SlidersController::changeValue(int v) { 112 | if (valueSpinManualEdit) { 113 | QColor filter = QColor::fromHsv(0, 0, v); 114 | changeValue(filter); 115 | } 116 | valueSpinManualEdit = true; 117 | } 118 | 119 | void SlidersController::changeValue(QColor color) { 120 | emit valueChanged(color); 121 | } 122 | 123 | void SlidersController::changeValueFromSelector(QColor color) { 124 | valueSpinManualEdit = false; 125 | 126 | slidersView->ui->vSlider->setV(color); 127 | slidersView->ui->spValue->setValue(color.value()); 128 | 129 | slidersView->ui->hSlider->changeValue(color); 130 | slidersView->ui->sSlider->changeValue(color); 131 | } 132 | 133 | 134 | // --------------------------------------------- RGB --------------------------------------------- 135 | 136 | // ===== red ===== 137 | 138 | void SlidersController::changeRed(int r) { 139 | if (redSpinManualEdit) { 140 | QColor filter(r, 0, 0); 141 | changeRed(filter); 142 | } 143 | redSpinManualEdit = true; 144 | } 145 | 146 | void SlidersController::changeRed(QColor color) { 147 | emit redChanged(color); 148 | updateRedValues(color); 149 | } 150 | 151 | void SlidersController::changeRedFromSelector(QColor color) { 152 | updateRedValues(color); 153 | } 154 | 155 | void SlidersController::updateRedValues(QColor color) { 156 | slidersView->ui->rSlider->setR(color); 157 | 158 | redSpinManualEdit = false; 159 | slidersView->ui->spRed->setValue(color.red()); 160 | 161 | slidersView->ui->gSlider->changeRed(color); 162 | slidersView->ui->bSlider->changeRed(color); 163 | } 164 | 165 | // ===== green ===== 166 | 167 | void SlidersController::changeGreen(int g) { 168 | if (greenSpinManualEdit) { 169 | QColor filter(0, g, 0); 170 | changeGreen(filter); 171 | } 172 | greenSpinManualEdit = true; 173 | } 174 | 175 | void SlidersController::changeGreen(QColor color) { 176 | emit greenChanged(color); 177 | updateGreenValues(color); 178 | } 179 | 180 | void SlidersController::changeGreenFromSelector(QColor color) { 181 | updateGreenValues(color); 182 | } 183 | 184 | void SlidersController::updateGreenValues(QColor color) { 185 | slidersView->ui->gSlider->setG(color); 186 | 187 | greenSpinManualEdit = false; 188 | slidersView->ui->spGreen->setValue(color.green()); 189 | 190 | slidersView->ui->rSlider->changeGreen(color); 191 | slidersView->ui->bSlider->changeGreen(color); 192 | } 193 | 194 | // ===== blue ===== 195 | 196 | void SlidersController::changeBlue(int b) { 197 | if (blueSpinManualEdit) { 198 | QColor filter(0, 0, b); 199 | changeBlue(filter); 200 | } 201 | blueSpinManualEdit = true; 202 | } 203 | 204 | void SlidersController::changeBlue(QColor color) { 205 | emit blueChanged(color); 206 | updateBlueValues(color); 207 | } 208 | 209 | void SlidersController::changeBlueFromSelector(QColor color) { 210 | updateBlueValues(color); 211 | } 212 | 213 | void SlidersController::updateBlueValues(QColor color) { 214 | slidersView->ui->bSlider->setB(color); 215 | 216 | blueSpinManualEdit = false; 217 | slidersView->ui->spBlue->setValue(color.blue()); 218 | 219 | slidersView->ui->rSlider->changeBlue(color); 220 | slidersView->ui->gSlider->changeBlue(color); 221 | } 222 | 223 | 224 | // --------------------------------------------- CMYK --------------------------------------------- 225 | 226 | // ===== cyan ===== 227 | 228 | void SlidersController::changeCyan(int c) { 229 | if (cyanSpinManualEdit) { 230 | QColor filter = QColor::fromCmyk(c, 0, 0, 0); 231 | changeCyan(filter); 232 | } 233 | cyanSpinManualEdit = true; 234 | } 235 | 236 | void SlidersController::changeCyan(QColor color) { 237 | emit cyanChanged(color); 238 | updateCyanValues(color); 239 | } 240 | 241 | void SlidersController::changeCyanFromSelector(QColor color) { 242 | updateCyanValues(color); 243 | } 244 | 245 | void SlidersController::updateCyanValues(QColor color) { 246 | slidersView->ui->cSlider->setC(color); 247 | 248 | cyanSpinManualEdit = false; 249 | slidersView->ui->spCyan->setValue(color.cyan()); 250 | 251 | slidersView->ui->ySlider->changeCyan(color); 252 | slidersView->ui->mSlider->changeCyan(color); 253 | slidersView->ui->kSlider->changeCyan(color); 254 | } 255 | 256 | // ===== magenta ===== 257 | 258 | void SlidersController::changeMagenta(int m) { 259 | if (magentaSpinManualEdit) { 260 | QColor filter = QColor::fromCmyk(0, m, 0, 0); 261 | changeMagenta(filter); 262 | } 263 | magentaSpinManualEdit = true; 264 | } 265 | 266 | void SlidersController::changeMagenta(QColor color) { 267 | emit magentaChanged(color); 268 | updateMagentaValues(color); 269 | } 270 | 271 | void SlidersController::changeMagentaFromSelector(QColor color) { 272 | updateMagentaValues(color); 273 | } 274 | 275 | void SlidersController::updateMagentaValues(QColor color) { 276 | slidersView->ui->mSlider->setM(color); 277 | 278 | magentaSpinManualEdit = false; 279 | slidersView->ui->spMagenta->setValue(color.magenta()); 280 | 281 | slidersView->ui->cSlider->changeMagenta(color); 282 | slidersView->ui->ySlider->changeMagenta(color); 283 | slidersView->ui->kSlider->changeMagenta(color); 284 | } 285 | 286 | // ===== yellow ===== 287 | 288 | void SlidersController::changeYellow(int y) { 289 | if (yellowSpinManualEdit) { 290 | QColor filter = QColor::fromCmyk(0, 0, y, 0); 291 | changeYellow(filter); 292 | } 293 | yellowSpinManualEdit = true; 294 | } 295 | 296 | void SlidersController::changeYellow(QColor color) { 297 | emit yellowChanged(color); 298 | updateYellowValues(color); 299 | } 300 | 301 | void SlidersController::changeYellowFromSelector(QColor color) { 302 | updateYellowValues(color); 303 | } 304 | 305 | void SlidersController::updateYellowValues(QColor color) { 306 | slidersView->ui->ySlider->setY(color); 307 | 308 | yellowSpinManualEdit = false; 309 | slidersView->ui->spYellow->setValue(color.yellow()); 310 | 311 | slidersView->ui->cSlider->changeYellow(color); 312 | slidersView->ui->mSlider->changeYellow(color); 313 | slidersView->ui->kSlider->changeYellow(color); 314 | } 315 | 316 | // ===== black ===== 317 | 318 | void SlidersController::changeBlack(int k) { 319 | if (blackSpinManualEdit) { 320 | QColor filter = QColor::fromCmyk(0, 0, 0, k); 321 | changeBlack(filter); 322 | } 323 | blackSpinManualEdit = true; 324 | } 325 | 326 | void SlidersController::changeBlack(QColor color) { 327 | emit blackChanged(color); 328 | updateBlackValues(color); 329 | } 330 | 331 | void SlidersController::changeBlackFromSelector(QColor color) { 332 | updateBlackValues(color); 333 | } 334 | 335 | void SlidersController::updateBlackValues(QColor color) { 336 | slidersView->ui->kSlider->setK(color); 337 | 338 | blackSpinManualEdit = false; 339 | slidersView->ui->spBlack->setValue(color.black()); 340 | 341 | slidersView->ui->cSlider->changeBlack(color); 342 | slidersView->ui->mSlider->changeBlack(color); 343 | slidersView->ui->ySlider->changeBlack(color); 344 | } 345 | -------------------------------------------------------------------------------- /Views/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "Widgets/ColorWidgets/hselector.h" 9 | #include "Service/validator.h" 10 | 11 | #include "pickerview.h" 12 | #include "testwidget.h" 13 | #include "testdialog.h" 14 | 15 | 16 | MainWindow::MainWindow(QWidget *parent) : 17 | QMainWindow(parent), 18 | ui(new Ui::MainWindow) 19 | { 20 | ui->setupUi(this); 21 | colorProcessor = new ColorProcessor(ui->hSelector, ui->svSelector); 22 | mainController = new MainController(ui->hSelector, ui->svSelector, colorProcessor, this); 23 | 24 | slidersWindow = NULL; 25 | 26 | addActions(); 27 | addShortcuts(); 28 | init(); 29 | } 30 | 31 | MainWindow::~MainWindow() 32 | { 33 | delete ui; 34 | } 35 | 36 | 37 | bool MainWindow::eventFilter(QObject *obj, QEvent *event) { 38 | qDebug() << "Event Filter: " << event->type(); 39 | return QObject::eventFilter(obj, event); 40 | } 41 | 42 | 43 | void MainWindow::init() { 44 | QApplication::setStyle("fusion"); 45 | 46 | mx = 0; 47 | my = 0; 48 | 49 | mouseDown = false; 50 | 51 | QMargins margins(5,0,0,0); 52 | 53 | ui->leHSV->setTextMargins(margins); 54 | ui->leRGB->setTextMargins(margins); 55 | ui->leCMYK->setTextMargins(margins); 56 | ui->leHex->setTextMargins(margins); 57 | 58 | ui->leHSV->setType(Vars::HSV); 59 | ui->leRGB->setType(Vars::RGB); 60 | ui->leCMYK->setType(Vars::CMYK); 61 | ui->leHex->setType(Vars::Hex); 62 | 63 | ui->hSelector->setInitH(0); 64 | 65 | // qApp->installEventFilter(this); 66 | } 67 | 68 | void MainWindow::addActions() { 69 | connect( ui->hSelector, SIGNAL(hueChanged(QColor)), ui->svSelector, SLOT(changeHue(QColor)) ); 70 | connect( ui->svSelector, SIGNAL(colorChanged(QColor)), ui->colorSample, SLOT(changeColor(QColor)) ); 71 | connect( ui->colorSample, SIGNAL(colorChanged(QColor)), this, SLOT(updateColorText(QColor)) ); 72 | // connect( ui->svSelector, SIGNAL(colorChanged(QColor)), this, SLOT(updateColorText(QColor)) ); 73 | 74 | connect( ui->leHSV, SIGNAL(textEdited(QString)), this, SLOT(updateColorHSV(QString)) ); 75 | connect( ui->leRGB, SIGNAL(textEdited(QString)), this, SLOT(updateColorRGB(QString)) ); 76 | connect( ui->leCMYK, SIGNAL(textEdited(QString)), this, SLOT(updateColorCMYK(QString)) ); 77 | connect( ui->leHex, SIGNAL(textEdited(QString)), this, SLOT(updateColorHex(QString)) ); 78 | 79 | connect( ui->leHSV, SIGNAL(focusNextField()), this, SLOT(focusNextField()) ); 80 | connect( ui->leRGB, SIGNAL(focusNextField()), this, SLOT(focusNextField()) ); 81 | connect( ui->leCMYK, SIGNAL(focusNextField()), this, SLOT(focusNextField()) ); 82 | connect( ui->leHex, SIGNAL(focusNextField()), this, SLOT(focusNextField()) ); 83 | 84 | connect( ui->leHSV, SIGNAL(focusPrevField()), this, SLOT(focusPrevField()) ); 85 | connect( ui->leRGB, SIGNAL(focusPrevField()), this, SLOT(focusPrevField()) ); 86 | connect( ui->leCMYK, SIGNAL(focusPrevField()), this, SLOT(focusPrevField()) ); 87 | connect( ui->leHex, SIGNAL(focusPrevField()), this, SLOT(focusPrevField()) ); 88 | 89 | connect( colorProcessor, SIGNAL(updateFinished()), this, SLOT(updateColorFinished()) ); 90 | 91 | connect( ui->bHSV, SIGNAL(clicked()), this, SLOT(copyHSV()) ); 92 | connect( ui->bRGB, SIGNAL(clicked()), this, SLOT(copyRGB()) ); 93 | connect( ui->bCMYK, SIGNAL(clicked()), this, SLOT(copyCMYK()) ); 94 | 95 | connect( ui->bHex, SIGNAL(clicked()), this, SLOT(copyHex()) ); 96 | connect( ui->bHexHash, SIGNAL(clicked()), this, SLOT(copyHexHash()) ); 97 | connect( ui->bPasteHex, SIGNAL(clicked()), this, SLOT(pasteHex()) ); 98 | 99 | connect( ui->colorSample, SIGNAL(samplePressedLeft()), this, SLOT(copyHex()) ); 100 | connect( ui->colorSample, SIGNAL(samplePressedRight()), this, SLOT(copyHexHash()) ); 101 | connect( ui->colorSample, SIGNAL(samplePressedMiddle()), this, SLOT(toggleSliders()) ); 102 | 103 | connect( ui->hSelector, SIGNAL(middlePressedSignal(QMouseEvent*)), this, SLOT(hsvMiddlePressed(QMouseEvent*)) ); 104 | connect( ui->svSelector, SIGNAL(middlePressedSignal(QMouseEvent*)), this, SLOT(hsvMiddlePressed(QMouseEvent*)) ); 105 | 106 | connect( this, SIGNAL(mouseMovedOnWindow()), ui->colorSample, SLOT(mouseMovedOnWindow()) ); 107 | connect( this, SIGNAL(mouseReleasedOnWindow()), ui->colorSample, SLOT(mouseReleasedOnWindow()) ); 108 | connect( this, SIGNAL(shiftPressed()), ui->svSelector, SLOT(shiftPressed()) ); 109 | connect( this, SIGNAL(shiftReleased()), ui->svSelector, SLOT(shiftReleased()) ); 110 | 111 | connect( this, SIGNAL(ctrlPressed()), ui->svSelector, SLOT(ctrlPressed()) ); 112 | connect( this, SIGNAL(ctrlReleased()), ui->svSelector, SLOT(ctrlReleased()) ); 113 | connect( this, SIGNAL(ctrlPressed()), ui->hSelector, SLOT(ctrlPressed()) ); 114 | connect( this, SIGNAL(ctrlReleased()), ui->hSelector, SLOT(ctrlReleased()) ); 115 | 116 | // connect( ui->bShowPicker, SIGNAL(clicked()), this, SLOT(showPickerClicked()) ); 117 | // connect( ui->bSliders, SIGNAL(clicked()), this, SLOT(openSliders()) ); 118 | } 119 | 120 | void MainWindow::addSlidersActions() { 121 | // === HSV === 122 | connect( slidersController, SIGNAL(hueChanged(QColor)), mainController, SLOT(changeHue(QColor)) ); 123 | connect( slidersController, SIGNAL(saturationChanged(QColor)), mainController, SLOT(changeSaturation(QColor)) ); 124 | connect( slidersController, SIGNAL(valueChanged(QColor)), mainController, SLOT(changeValue(QColor)) ); 125 | 126 | connect( ui->hSelector, SIGNAL(hueChanged(QColor)), slidersController, SLOT(changeHueFromSelector(QColor)) ); 127 | connect( ui->svSelector, SIGNAL(saturationChanged(QColor)), slidersController, SLOT(changeSaturationFromSelector(QColor)) ); 128 | connect( ui->svSelector, SIGNAL(valueChanged(QColor)), slidersController, SLOT(changeValueFromSelector(QColor)) ); 129 | 130 | // === RGB === 131 | connect( slidersController, SIGNAL(redChanged(QColor)), mainController, SLOT(changeRed(QColor)) ); 132 | connect( slidersController, SIGNAL(greenChanged(QColor)), mainController, SLOT(changeGreen(QColor)) ); 133 | connect( slidersController, SIGNAL(blueChanged(QColor)), mainController, SLOT(changeBlue(QColor)) ); 134 | 135 | connect( ui->colorSample, SIGNAL(colorChanged(QColor)), slidersController, SIGNAL(RGBChanged(QColor)) ); 136 | 137 | // === CMYK === 138 | connect( slidersController, SIGNAL(cyanChanged(QColor)), mainController, SLOT(changeCyan(QColor)) ); 139 | connect( slidersController, SIGNAL(magentaChanged(QColor)), mainController, SLOT(changeMagenta(QColor)) ); 140 | connect( slidersController, SIGNAL(yellowChanged(QColor)), mainController, SLOT(changeYellow(QColor)) ); 141 | connect( slidersController, SIGNAL(blackChanged(QColor)), mainController, SLOT(changeBlack(QColor)) ); 142 | 143 | connect( ui->colorSample, SIGNAL(colorChanged(QColor)), slidersController, SIGNAL(CMYKChanged(QColor)) ); 144 | } 145 | 146 | void MainWindow::addShortcuts() { 147 | QShortcut* HSV_Text = new QShortcut(QKeySequence("Shift+F1"), this); 148 | QShortcut* RGB_Text = new QShortcut(QKeySequence("Shift+F2"), this); 149 | QShortcut* CMYK_Text = new QShortcut(QKeySequence("Shift+F3"), this); 150 | QShortcut* Hex_Text = new QShortcut(QKeySequence("Shift+F4"), this); 151 | 152 | QShortcut* toggleSlider_Key = new QShortcut(QKeySequence("Ctrl+S"), this); 153 | connect( toggleSlider_Key, SIGNAL(activated()), this, SLOT(toggleSliders()) ); 154 | 155 | mapper = new QSignalMapper(this); 156 | mapper->setMapping(HSV_Text, ui->leHSV); 157 | mapper->setMapping(RGB_Text, ui->leRGB); 158 | mapper->setMapping(CMYK_Text, ui->leCMYK); 159 | mapper->setMapping(Hex_Text, ui->leHex); 160 | 161 | connect( HSV_Text, SIGNAL(activated()), mapper, SLOT(map()) ); 162 | connect( RGB_Text, SIGNAL(activated()), mapper, SLOT(map()) ); 163 | connect( CMYK_Text, SIGNAL(activated()), mapper, SLOT(map()) ); 164 | connect( Hex_Text, SIGNAL(activated()), mapper, SLOT(map()) ); 165 | connect( mapper, SIGNAL(mapped(QWidget*)), this, SLOT(selectField(QWidget*)) ); 166 | 167 | 168 | QShortcut* HSV_Button = new QShortcut(QKeySequence("F1"), this); 169 | connect( HSV_Button, SIGNAL(activated()), ui->bHSV, SLOT(click()) ); 170 | 171 | QShortcut* RGB_Button = new QShortcut(QKeySequence("F2"), this); 172 | connect( RGB_Button, SIGNAL(activated()), ui->bRGB, SLOT(click()) ); 173 | 174 | QShortcut* CMYK_Button = new QShortcut(QKeySequence("F3"), this); 175 | connect( CMYK_Button, SIGNAL(activated()), ui->bCMYK, SLOT(click()) ); 176 | 177 | QShortcut* Hex_Button = new QShortcut(QKeySequence("F4"), this); 178 | connect( Hex_Button, SIGNAL(activated()), ui->bHex, SLOT(click()) ); 179 | 180 | QShortcut* HexHash_Button = new QShortcut(QKeySequence("F5"), this); 181 | connect( HexHash_Button, SIGNAL(activated()), ui->bHexHash, SLOT(click()) ); 182 | 183 | QShortcut* PasteHex_Button = new QShortcut(QKeySequence("F6"), this); 184 | connect( PasteHex_Button, SIGNAL(activated()), ui->bPasteHex, SLOT(click()) ); 185 | 186 | 187 | QShortcut *quit = new QShortcut(QKeySequence("Esc"), this); 188 | connect( quit, SIGNAL(activated()), this, SLOT(close()) ); 189 | } 190 | 191 | void MainWindow::selectField(QWidget* w) { 192 | QLineEdit* field = (QLineEdit*) w; 193 | field->setFocus(); 194 | field->selectAll(); 195 | } 196 | 197 | 198 | // --------------------------------------------- slots --------------------------------------------- 199 | 200 | void MainWindow::hsvMiddlePressed(QMouseEvent* e) { 201 | mouseDown = true; 202 | mouseMoved = false; 203 | 204 | mx = e->x(); 205 | my = e->y(); 206 | } 207 | 208 | void MainWindow::middleClick(QMouseEvent* e) { 209 | mouseReleaseEvent(e); 210 | } 211 | 212 | void MainWindow::updateSliders() { 213 | ui->hSelector->reupdateColor(); 214 | ui->svSelector->reupdateColor(); 215 | ui->colorSample->reupdateColor(); 216 | } 217 | 218 | void MainWindow::toggleSliders() { 219 | if (slidersWindow == NULL || !slidersWindow->isVisible()) 220 | openSliders(); 221 | else 222 | closeSliders(); 223 | } 224 | 225 | void MainWindow::closeSliders() { 226 | slidersWindow->hide(); 227 | } 228 | 229 | void MainWindow::openSliders() { 230 | if (slidersWindow == NULL) { 231 | slidersController = new SlidersController(); 232 | slidersWindow = new SlidersWindow(slidersController, this); 233 | 234 | slidersController->setView(slidersWindow); 235 | mainController->addSlidersController(slidersController); 236 | 237 | addSlidersActions(); 238 | updateSliders(); 239 | } 240 | 241 | if (slidersWindow!=NULL) { 242 | stickSliders(); 243 | slidersWindow->show(); 244 | } 245 | } 246 | 247 | void MainWindow::stickSliders() { 248 | int corrX = frameGeometry().width()-width(); 249 | 250 | int sx = x(); 251 | int sy = y(); 252 | int w = slidersWindow->width()+corrX; 253 | sx-=w; 254 | 255 | // qDebug() << QString("Sliders: %1, %2").arg(sx).arg(sy); 256 | 257 | sx = qMax(0, sx); 258 | 259 | slidersWindow->move(sx, sy); 260 | } 261 | 262 | 263 | void MainWindow::focusNextField() { 264 | if (ui->leHSV->hasFocus()) { 265 | ui->leRGB->setFocus(Qt::TabFocusReason); 266 | } 267 | else if (ui->leRGB->hasFocus()) { 268 | ui->leCMYK->setFocus(Qt::TabFocusReason); 269 | } 270 | else if (ui->leCMYK->hasFocus()) { 271 | ui->leHex->setFocus(Qt::TabFocusReason); 272 | } 273 | else if (ui->leHex->hasFocus()) { 274 | ui->leHSV->setFocus(Qt::TabFocusReason); 275 | } 276 | } 277 | 278 | void MainWindow::focusPrevField() { 279 | if (ui->leHSV->hasFocus()) { 280 | ui->leHex->setFocus(Qt::BacktabFocusReason); 281 | } 282 | else if (ui->leHex->hasFocus()) { 283 | ui->leCMYK->setFocus(Qt::BacktabFocusReason); 284 | } 285 | else if (ui->leCMYK->hasFocus()) { 286 | ui->leRGB->setFocus(Qt::BacktabFocusReason); 287 | } 288 | else if (ui->leRGB->hasFocus()) { 289 | ui->leHSV->setFocus(Qt::BacktabFocusReason); 290 | } 291 | } 292 | 293 | void MainWindow::showPickerClicked() { 294 | // PickerView* w = new PickerView(this); 295 | TestWidget* w = new TestWidget(this); 296 | // TestWidget* w = new TestWidget; 297 | // TestDialog* w = new TestDialog(this); 298 | 299 | w->setWindowFlags(Qt::Window | Qt::FramelessWindowHint); 300 | 301 | QPoint pos = QCursor::pos(); 302 | int wx = pos.x() - w->width()/2; 303 | int wy = pos.y() - w->height()/2; 304 | 305 | // w->move(10, 10); 306 | w->move(wx, wy); 307 | w->show(); 308 | 309 | // w->grabMouse(); 310 | } 311 | 312 | 313 | // --------------------------------------------- buttons --------------------------------------------- 314 | 315 | void MainWindow::copyHSV() { 316 | QString text = ui->leHSV->text(); 317 | text = text.replace(" ", ", "); 318 | colorProcessor->copyText(text); 319 | status("HSV copied"); 320 | } 321 | 322 | void MainWindow::copyRGB() { 323 | QString text = ui->leRGB->text(); 324 | text = text.replace(" ", ", "); 325 | colorProcessor->copyText(text); 326 | status("RGB copied"); 327 | } 328 | 329 | void MainWindow::copyCMYK() { 330 | QString text = ui->leCMYK->text(); 331 | text = text.replace(" ", ", "); 332 | colorProcessor->copyText(text); 333 | status("CMYK copied"); 334 | } 335 | 336 | void MainWindow::copyHex() { 337 | QString text = ui->leHex->text(); 338 | colorProcessor->copyText(text); 339 | status("Hex copied"); 340 | } 341 | 342 | void MainWindow::copyHexHash() { 343 | QString text = ui->leHex->text(); 344 | colorProcessor->copyText("#"+text); 345 | status("Hex # copied"); 346 | } 347 | 348 | void MainWindow::pasteHex() { 349 | QString text = colorProcessor->pasteText(); 350 | if (!text.length()) return; 351 | 352 | ui->leHex->setText(text); 353 | ui->leHex->textEdited(text); 354 | status("Hex value pasted"); 355 | } 356 | 357 | // --------------------------------------------- update color --------------------------------------------- 358 | 359 | void MainWindow::updateColorFinished() { 360 | editingField = ""; 361 | } 362 | 363 | void MainWindow::updateColorHSV(QString text) { 364 | editingField = "HSV"; 365 | text = Validator::correctColorText(text); 366 | ui->leHSV->updateText(text); 367 | colorProcessor->updateColorHSV(text); 368 | } 369 | 370 | void MainWindow::updateColorRGB(QString text) { 371 | editingField = "RGB"; 372 | text = Validator::correctColorText(text); 373 | ui->leRGB->updateText(text); 374 | colorProcessor->updateColorRGB(text); 375 | } 376 | 377 | void MainWindow::updateColorCMYK(QString text) { 378 | editingField = "CMYK"; 379 | text = Validator::correctColorText(text); 380 | ui->leCMYK->updateText(text); 381 | colorProcessor->updateColorCMYK(text); 382 | } 383 | 384 | void MainWindow::updateColorHex(QString text) { 385 | editingField = "Hex"; 386 | text = Validator::correctColorText(text); 387 | ui->leHex->updateText(text); 388 | colorProcessor->updateColorHex(text); 389 | } 390 | 391 | // --------------------------------------------- update color text --------------------------------------------- 392 | 393 | void MainWindow::updateColorText(QColor color) { 394 | QString HSV, RGB, CMYK, Hex; 395 | 396 | HSV = colorProcessor->getHSV(color); 397 | RGB = colorProcessor->getRGB(color); 398 | CMYK = colorProcessor->getCMYK(color); 399 | Hex = colorProcessor->getHex(color); 400 | 401 | setHSV(HSV); 402 | setRGB(RGB); 403 | setCMYK(CMYK); 404 | setHex(Hex); 405 | } 406 | 407 | void MainWindow::setHSV(QString text) { 408 | if (editingField == "HSV") return; 409 | ui->leHSV->setText(text); 410 | } 411 | 412 | void MainWindow::setRGB(QString text) { 413 | if (editingField == "RGB") return; 414 | ui->leRGB->setText(text); 415 | } 416 | 417 | void MainWindow::setCMYK(QString text) { 418 | if (editingField == "CMYK") return; 419 | ui->leCMYK->setText(text); 420 | } 421 | 422 | void MainWindow::setHex(QString text) { 423 | if (editingField == "Hex") return; 424 | ui->leHex->setText(text); 425 | } 426 | 427 | 428 | QString MainWindow::getHSV() { 429 | return ui->leHSV->text(); 430 | } 431 | 432 | QString MainWindow::getRGB() { 433 | return ui->leRGB->text(); 434 | } 435 | 436 | QString MainWindow::getCMYK() { 437 | return ui->leCMYK->text(); 438 | } 439 | 440 | QString MainWindow::getHex() { 441 | return ui->leHex->text(); 442 | } 443 | 444 | // --------------------------------------------- service --------------------------------------------- 445 | 446 | void MainWindow::correctFields() { 447 | QString text; 448 | text = ui->leHSV->text(); 449 | text = correctField(text); 450 | ui->leHSV->setText(text); 451 | 452 | text = ui->leRGB->text(); 453 | text = correctField(text); 454 | ui->leRGB->setText(text); 455 | 456 | text = ui->leCMYK->text(); 457 | text = correctField(text); 458 | ui->leCMYK->setText(text); 459 | 460 | text = ui->leHex->text(); 461 | text = correctField(text); 462 | ui->leHex->setText(text); 463 | } 464 | 465 | QString MainWindow::correctField(QString text) { // +++ to Validator 466 | text = text.trimmed(); 467 | text = text.replace(QRegExp("\\s+"), " "); 468 | 469 | return text; 470 | } 471 | 472 | void MainWindow::status(QString msg) { 473 | ui->statusBar->showMessage(msg, 3000); 474 | } 475 | 476 | // --------------------------------------------- events --------------------------------------------- 477 | 478 | void MainWindow::mousePressEvent(QMouseEvent *e) 479 | { 480 | mouseDown = true; 481 | mouseMoved = false; 482 | 483 | mx = e->x(); 484 | my = e->y(); 485 | } 486 | 487 | void MainWindow::mouseReleaseEvent(QMouseEvent *e) 488 | { 489 | mouseDown = false; 490 | if (e->button() == Qt::MiddleButton && !mouseMoved) close(); 491 | emit mouseReleasedOnWindow(); 492 | } 493 | 494 | void MainWindow::mouseMoveEvent(QMouseEvent *e) 495 | { 496 | if (mouseDown) { 497 | mouseMoved = true; 498 | 499 | emit mouseMovedOnWindow(); 500 | 501 | int gx = e->globalX(); 502 | int gy = e->globalY(); 503 | 504 | int corrX = geometry().x()-x(); 505 | int corrY = geometry().y()-y(); 506 | 507 | int moveX = gx-mx-corrX; 508 | int moveY = gy-my-corrY; 509 | 510 | move(moveX, moveY); 511 | } 512 | } 513 | 514 | void MainWindow::keyPressEvent(QKeyEvent *e) 515 | { 516 | int key = e->key(); 517 | if (key == Qt::Key_Shift) { 518 | emit shiftPressed(); 519 | } 520 | if (key == Qt::Key_Control) { 521 | emit ctrlPressed(); 522 | } 523 | } 524 | 525 | void MainWindow::keyReleaseEvent(QKeyEvent *e) 526 | { 527 | int key = e->key(); 528 | if (key == Qt::Key_Shift) { 529 | emit shiftReleased(); 530 | } 531 | if (key == Qt::Key_Control) { 532 | emit ctrlReleased(); 533 | } 534 | } 535 | -------------------------------------------------------------------------------- /Views/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 636 10 | 414 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | 21 | 636 22 | 414 23 | 24 | 25 | 26 | 27 | 636 28 | 414 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 255 38 | 255 39 | 255 40 | 41 | 42 | 43 | 44 | 45 | 46 | 219 47 | 221 48 | 219 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 255 58 | 255 59 | 255 60 | 61 | 62 | 63 | 64 | 65 | 66 | 219 67 | 221 68 | 219 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 219 78 | 221 79 | 219 80 | 81 | 82 | 83 | 84 | 85 | 86 | 219 87 | 221 88 | 219 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | QtColorPicker v1.0.2 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 0 105 | 106 | 107 | 0 108 | 109 | 110 | 0 111 | 112 | 113 | 0 114 | 115 | 116 | 0 117 | 118 | 119 | 120 | 121 | Qt::Vertical 122 | 123 | 124 | QSizePolicy::MinimumExpanding 125 | 126 | 127 | 128 | 20 129 | 14 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 0 139 | 140 | 141 | 0 142 | 143 | 144 | 0 145 | 146 | 147 | 0 148 | 149 | 150 | 0 151 | 152 | 153 | 154 | 155 | Qt::Horizontal 156 | 157 | 158 | QSizePolicy::Fixed 159 | 160 | 161 | 162 | 10 163 | 20 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 0 173 | 0 174 | 175 | 176 | 177 | 178 | 0 179 | 365 180 | 181 | 182 | 183 | 184 | 16777215 185 | 365 186 | 187 | 188 | 189 | false 190 | 191 | 192 | 193 | 0 194 | 195 | 196 | 0 197 | 198 | 199 | 0 200 | 201 | 202 | 0 203 | 204 | 205 | 0 206 | 207 | 208 | 209 | 210 | 211 | 0 212 | 0 213 | 214 | 215 | 216 | 217 | 260 218 | 80 219 | 220 | 221 | 222 | border:1px solid; 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 0 231 | 0 232 | 233 | 234 | 235 | 236 | 54 237 | 365 238 | 239 | 240 | 241 | 242 | 54 243 | 16777215 244 | 245 | 246 | 247 | false 248 | 249 | 250 | border:1px solid 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 0 259 | 0 260 | 261 | 262 | 263 | 264 | 260 265 | 260 266 | 267 | 268 | 269 | border:1px solid; 270 | 271 | 272 | 273 | 274 | 275 | 276 | Qt::Vertical 277 | 278 | 279 | QSizePolicy::Fixed 280 | 281 | 282 | 283 | 20 284 | 20 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | Qt::Horizontal 293 | 294 | 295 | QSizePolicy::Fixed 296 | 297 | 298 | 299 | 10 300 | 20 301 | 302 | 303 | 304 | 305 | 306 | svSelector 307 | colorSample 308 | hSelector 309 | 310 | 311 | 312 | 313 | 314 | Qt::Horizontal 315 | 316 | 317 | QSizePolicy::Fixed 318 | 319 | 320 | 321 | 10 322 | 20 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 0 331 | 332 | 333 | 0 334 | 335 | 336 | 337 | 338 | 339 | 0 340 | 0 341 | 342 | 343 | 344 | 345 | 0 346 | 0 347 | 348 | 349 | 350 | 351 | 10 352 | 353 | 354 | 0 355 | 356 | 357 | 0 358 | 359 | 360 | 0 361 | 362 | 363 | 0 364 | 365 | 366 | 367 | 368 | 369 | 0 370 | 0 371 | 372 | 373 | 374 | 375 | 110 376 | 36 377 | 378 | 379 | 380 | 381 | Trebuchet MS 382 | 11 383 | 75 384 | false 385 | true 386 | 387 | 388 | 389 | HSV 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 0 398 | 0 399 | 400 | 401 | 402 | 403 | 160 404 | 36 405 | 406 | 407 | 408 | 409 | Consolas 410 | 12 411 | 75 412 | true 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | false 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | Qt::Vertical 433 | 434 | 435 | QSizePolicy::Fixed 436 | 437 | 438 | 439 | 20 440 | 30 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 0 450 | 0 451 | 452 | 453 | 454 | 455 | 0 456 | 0 457 | 458 | 459 | 460 | 461 | 10 462 | 463 | 464 | 0 465 | 466 | 467 | 0 468 | 469 | 470 | 0 471 | 472 | 473 | 0 474 | 475 | 476 | 477 | 478 | 479 | 0 480 | 0 481 | 482 | 483 | 484 | 485 | 110 486 | 36 487 | 488 | 489 | 490 | 491 | Trebuchet MS 492 | 11 493 | 75 494 | false 495 | true 496 | 497 | 498 | 499 | RGB 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 0 508 | 0 509 | 510 | 511 | 512 | 513 | 160 514 | 36 515 | 516 | 517 | 518 | 519 | Consolas 520 | 12 521 | 75 522 | true 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | Qt::Vertical 540 | 541 | 542 | QSizePolicy::Fixed 543 | 544 | 545 | 546 | 20 547 | 30 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 0 557 | 0 558 | 559 | 560 | 561 | 562 | 0 563 | 0 564 | 565 | 566 | 567 | 568 | 10 569 | 570 | 571 | 0 572 | 573 | 574 | 0 575 | 576 | 577 | 0 578 | 579 | 580 | 0 581 | 582 | 583 | 584 | 585 | 586 | 0 587 | 0 588 | 589 | 590 | 591 | 592 | 110 593 | 36 594 | 595 | 596 | 597 | 598 | Trebuchet MS 599 | 11 600 | 75 601 | false 602 | true 603 | 604 | 605 | 606 | CMYK 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 0 615 | 0 616 | 617 | 618 | 619 | 620 | 160 621 | 36 622 | 623 | 624 | 625 | 626 | Consolas 627 | 12 628 | 75 629 | true 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | Qt::Vertical 647 | 648 | 649 | QSizePolicy::Fixed 650 | 651 | 652 | 653 | 30 654 | 30 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 0 664 | 0 665 | 666 | 667 | 668 | 669 | 0 670 | 0 671 | 672 | 673 | 674 | 675 | 0 676 | 677 | 678 | 0 679 | 680 | 681 | 0 682 | 683 | 684 | 0 685 | 686 | 687 | 10 688 | 689 | 690 | 691 | 692 | 693 | 0 694 | 0 695 | 696 | 697 | 698 | 699 | 160 700 | 36 701 | 702 | 703 | 704 | 705 | Consolas 706 | 12 707 | 75 708 | true 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 0 724 | 36 725 | 726 | 727 | 728 | 729 | Trebuchet MS 730 | 11 731 | 75 732 | false 733 | true 734 | 735 | 736 | 737 | Paste Hex 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 0 746 | 0 747 | 748 | 749 | 750 | 751 | 110 752 | 36 753 | 754 | 755 | 756 | 757 | Trebuchet MS 758 | 11 759 | 75 760 | false 761 | true 762 | 763 | 764 | 765 | Hex 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 0 774 | 0 775 | 776 | 777 | 778 | 779 | 110 780 | 36 781 | 782 | 783 | 784 | 785 | Trebuchet MS 786 | 11 787 | 75 788 | false 789 | true 790 | 791 | 792 | 793 | Hex # 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | Qt::Vertical 804 | 805 | 806 | QSizePolicy::Expanding 807 | 808 | 809 | 810 | 20 811 | 32 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 0 821 | 0 822 | 823 | 824 | 825 | 826 | 0 827 | 50 828 | 829 | 830 | 831 | 832 | 5 833 | 834 | 835 | 0 836 | 837 | 838 | 0 839 | 840 | 841 | 0 842 | 843 | 844 | 0 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | Qt::Vertical 853 | 854 | 855 | QSizePolicy::Fixed 856 | 857 | 858 | 859 | 20 860 | 0 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | Qt::Horizontal 871 | 872 | 873 | QSizePolicy::Minimum 874 | 875 | 876 | 877 | 10 878 | 18 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | Qt::Vertical 890 | 891 | 892 | QSizePolicy::Fixed 893 | 894 | 895 | 896 | 20 897 | 0 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | Qt::Vertical 906 | 907 | 908 | QSizePolicy::MinimumExpanding 909 | 910 | 911 | 912 | 20 913 | 14 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | Lucida Sans Unicode 924 | 9 925 | 75 926 | true 927 | 928 | 929 | 930 | false 931 | 932 | 933 | border-top:1px dotted #444; 934 | 935 | 936 | false 937 | 938 | 939 | 940 | 941 | 942 | 943 | HSelector 944 | QWidget 945 |
Widgets/ColorWidgets/hselector.h
946 | 1 947 |
948 | 949 | SVSelector 950 | QWidget 951 |
Widgets/ColorWidgets/svselector.h
952 | 1 953 |
954 | 955 | ColorSample 956 | QWidget 957 |
Widgets/ColorWidgets/colorsample.h
958 | 1 959 |
960 | 961 | ColorText 962 | QLineEdit 963 |
Widgets/colortext.h
964 |
965 |
966 | 967 | bHSV 968 | bRGB 969 | bCMYK 970 | bHex 971 | bHexHash 972 | leHSV 973 | leRGB 974 | leCMYK 975 | leHex 976 | bPasteHex 977 | 978 | 979 | 980 |
981 | -------------------------------------------------------------------------------- /files/mockup.bmml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | true 8 | false 9 | true 10 | QtColorPicker 11 | false 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | HSV 30 | 31 | 32 | 33 | 34 | 14 35 | 257%2036%20185 36 | 37 | 38 | 39 | 40 | 41 | 42 | Copy 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | RGB 54 | 55 | 56 | 57 | 58 | 14 59 | 255%209%2067 60 | 61 | 62 | 63 | 64 | 65 | 66 | Copy 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | CMYK 78 | 79 | 80 | 81 | 82 | 14 83 | 98%20100%2056%2032 84 | 85 | 86 | 87 | 88 | 89 | 90 | Copy 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | Hex 102 | 103 | 104 | 105 | 106 | 1 107 | 14 108 | a86d52 109 | 110 | 111 | 112 | 113 | 114 | 115 | Copy 116 | 117 | 118 | 119 | 120 | Copy%20%23 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | true 134 | false 135 | true 136 | QtColorPicker 137 | false 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | HSV 154 | 155 | 156 | 157 | 158 | 14 159 | 257%2036%20185 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | RGB 169 | 170 | 171 | 172 | 173 | 14 174 | 255%209%2067 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | CMYK 184 | 185 | 186 | 187 | 188 | 14 189 | 98%20100%2056%2032 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | Hex 199 | 200 | 201 | 202 | 203 | 1 204 | 14 205 | a86d52 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | Copy 215 | 216 | 217 | 218 | 219 | Copy 220 | 221 | 222 | 223 | 224 | Copy 225 | 226 | 227 | 228 | 229 | Copy 230 | 231 | 232 | 233 | 234 | Copy%20%23 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | true 244 | false 245 | true 246 | QtColorPicker 247 | false 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | HSV 260 | 261 | 262 | 263 | 264 | 14 265 | 257%2036%20185 266 | 267 | 268 | 269 | 270 | RGB 271 | 272 | 273 | 274 | 275 | 14 276 | 255%209%2067 277 | 278 | 279 | 280 | 281 | CMYK 282 | 283 | 284 | 285 | 286 | 14 287 | 98%20100%2056%2032 288 | 289 | 290 | 291 | 292 | Hex 293 | 294 | 295 | 296 | 297 | 1 298 | 14 299 | a86d52 300 | 301 | 302 | 303 | 304 | Copy 305 | 306 | 307 | 308 | 309 | Copy 310 | 311 | 312 | 313 | 314 | Copy 315 | 316 | 317 | 318 | 319 | Copy 320 | 321 | 322 | 323 | 324 | Copy%20%23 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | true 334 | false 335 | true 336 | QtColorPicker 337 | false 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | HSV 350 | 351 | 352 | 353 | 354 | 14 355 | 257%2036%20185 356 | 357 | 358 | 359 | 360 | RGB 361 | 362 | 363 | 364 | 365 | 14 366 | 255%209%2067 367 | 368 | 369 | 370 | 371 | CMYK 372 | 373 | 374 | 375 | 376 | 14 377 | 98%20100%2056%2032 378 | 379 | 380 | 381 | 382 | Hex 383 | 384 | 385 | 386 | 387 | 1 388 | 14 389 | a86d52 390 | 391 | 392 | 393 | 394 | Copy 395 | 396 | 397 | 398 | 399 | Copy 400 | 401 | 402 | 403 | 404 | Copy 405 | 406 | 407 | 408 | 409 | Copy 410 | 411 | 412 | 413 | 414 | Copy%20%23 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | true 424 | false 425 | true 426 | QtColorPicker%20-%20Final 427 | false 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 14 442 | 257%2036%20185 443 | 444 | 445 | 446 | 447 | 14 448 | 255%209%2067 449 | 450 | 451 | 452 | 453 | 14 454 | 98%20100%2056%2032 455 | 456 | 457 | 458 | 459 | 1 460 | 14 461 | a86d52 462 | 463 | 464 | 465 | 466 | 467 | 468 | HSV 469 | 470 | 471 | 472 | 473 | RGB 474 | 475 | 476 | 477 | 478 | CMYK 479 | 480 | 481 | 482 | 483 | Hex 484 | 485 | 486 | 487 | 488 | Hex%20%23 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | true 498 | false 499 | true 500 | QtColorPicker 501 | false 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | HSV 514 | 515 | 516 | 517 | 518 | RGB 519 | 520 | 521 | 522 | 523 | CMYK 524 | 525 | 526 | 527 | 528 | Hex 529 | 530 | 531 | 532 | 533 | 534 | 535 | 14 536 | 257%2036%20185 537 | 538 | 539 | 540 | 541 | 14 542 | 255%209%2067 543 | 544 | 545 | 546 | 547 | 14 548 | 98%20100%2056%2032 549 | 550 | 551 | 552 | 553 | 1 554 | 14 555 | a86d52 556 | 557 | 558 | 559 | 560 | 561 | 562 | Copy 563 | 564 | 565 | 566 | 567 | Copy 568 | 569 | 570 | 571 | 572 | Copy 573 | 574 | 575 | 576 | 577 | Copy 578 | 579 | 580 | 581 | 582 | Copy%20%23 583 | 584 | 585 | 586 | 587 | 588 | --------------------------------------------------------------------------------