Commit 31931e3a authored by Wolthera van Hövell's avatar Wolthera van Hövell 🛍

Add visual selector shapes.

These now work fully for the channels. They give nice squares.
I made a base class that only deals with the events and the classes, and added a rectangular subclass. This way we can make our circles and wheels and whatever easily.

Ref T2337
Ref T2438
parent e3f78b79
......@@ -256,6 +256,7 @@ set(kritaui_LIB_SRCS
widgets/kis_elided_label.cpp
widgets/kis_spinbox_color_selector.cpp
widgets/kis_screen_color_picker.cpp
widgets/kis_visual_color_selector.cpp
widgets/KoDualColorButton.cpp
input/kis_input_manager.cpp
input/kis_input_manager_p.cpp
......
......@@ -60,8 +60,10 @@ KisInternalColorSelector::KisInternalColorSelector(QWidget *parent, KoColor colo
m_ui->spinboxselector->slotSetColor(color);
connect(m_ui->spinboxselector, SIGNAL(sigNewColor(KoColor)), this, SLOT(slotColorUpdated(KoColor)));
m_ui->visualSelector->slotSetColor(color);
connect(m_ui->visualSelector, SIGNAL(sigNewColor(KoColor)), this, SLOT(slotColorUpdated(KoColor)));
connect(m_ui->screenColorPicker, SIGNAL(sigNewColorPicked(KoColor)),this, SLOT(slotColorUpdated(KoColor)));
//TODO: Add disable signal as well.
//TODO: Add disable signal as well. Might be not necessary...?
connect(this, SIGNAL(signalForegroundColorChosen(KoColor)), this, SLOT(slotLockSelector()));
m_d->compressColorChanges = new KisSignalCompressor(100 /* ms */, KisSignalCompressor::POSTPONE, this);
......@@ -133,6 +135,9 @@ void KisInternalColorSelector::updateAllElements(QObject *source)
if (source != m_ui->spinboxselector) {
m_ui->spinboxselector->slotSetColor(m_d->currentColor);
}
if (source != m_ui->visualSelector) {
m_ui->visualSelector->slotSetColor(m_d->currentColor);
}
if (source != this->parent()) {
emit(signalForegroundColorChosen(m_d->currentColor));
......
......@@ -14,6 +14,22 @@
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="KisVisualColorSelector" name="visualSelector" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>400</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="KisSpinboxColorSelector" name="spinboxselector" native="true">
<property name="sizePolicy">
......@@ -52,6 +68,12 @@
<header>kis_screen_color_picker.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KisVisualColorSelector</class>
<extends>QWidget</extends>
<header>kis_visual_color_selector.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
......
This diff is collapsed.
/*
* Copyright (C) Wolthera van Hovell tot Westerflier <griffinvalley@gmail.com>, (C) 2016
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KISVISUALCOLORSELECTOR_H
#define KISVISUALCOLORSELECTOR_H
#include <QWidget>
#include <QScopedPointer>
#include <QPixmap>
#include <QRegion>
#include <QMouseEvent>
#include <KoColor.h>
#include <KoColorSpace.h>
#include "kritaui_export.h"
/**
* @brief The KisVisualColorSelector class
* this gives a color selector box that draws gradients and everything.
* Unlike other color selectors, this one draws the full gamut of the given colorspace.
*/
class KRITAUI_EXPORT KisVisualColorSelector : public QWidget
{
Q_OBJECT
public:
explicit KisVisualColorSelector(QWidget *parent = 0);
~KisVisualColorSelector();
Q_SIGNALS:
void sigNewColor(KoColor c);
public Q_SLOTS:
void slotSetColor(KoColor c);
void slotsetColorSpace(const KoColorSpace *cs);
private Q_SLOTS:
void updateFromWidgets(KoColor c);
private:
struct Private;
const QScopedPointer<Private> m_d;
void updateSelectorElements();
void drawGradients();
};
//kis_visual_color_selector_shape
class KisVisualColorSelectorShape : public QWidget
{
Q_OBJECT
public:
/**
* @brief The Dimensions enum
* Wether or not the shape is single or two dimensional.
* A 2d widget can represent at maximum 2 coordinates.
*/
enum Dimensions{onedimensional, twodimensional};
enum ColorModel{Channel, HSV, HSL, HSI, HSY, YUV};
explicit KisVisualColorSelectorShape(QWidget *parent,
KisVisualColorSelectorShape::Dimensions dimension,
KisVisualColorSelectorShape::ColorModel model,
const KoColorSpace *cs,
int channel1, int channel2);
~KisVisualColorSelectorShape();
QPointF getShapeCoordinates();
Dimensions getDimensions();
ColorModel getColorModel();
QPixmap getPixmap();
void setFullImage(QPixmap full);
KoColor getCurrentColor();
Q_SIGNALS:
void sigNewColor(KoColor col);
public Q_SLOTS:
void setColor(KoColor c);
void slotSetActiveChannels(int channel1, int channel2);
protected:
void mousePressEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *);
void paintEvent(QPaintEvent*);
void resizeEvent(QResizeEvent *);
private:
struct Private;
const QScopedPointer<Private> m_d;
/**
* @brief convertShapeCoordinateToWidgetCoordinate
* @return take the position in the shape and convert it to screen coordinates.
*/
virtual QPointF convertShapeCoordinateToWidgetCoordinate(QPointF) = 0;
/**
* @brief convertWidgetCoordinateToShapeCoordinate
* Convert a coordinate in the widget's height width to a shape coordinate.
* @param coordinate the position your wish to have the shape coordinates of.
*/
virtual QPointF convertWidgetCoordinateToShapeCoordinate(QPoint coordinate) = 0;
QPointF convertKoColorToShapeCoordinate(KoColor c);
KoColor convertShapeCoordinateToKoColor(QPointF coordinates);
/**
* @brief getPixmap
* @return the pixmap of this shape.
*/
virtual QRegion getMaskMap() = 0;
virtual void drawCursor() = 0;
};
class KisVisualRectangleSelectorShape : public KisVisualColorSelectorShape
{
Q_OBJECT
public:
enum singelDTypes{vertical, horizontal, border};
explicit KisVisualRectangleSelectorShape(QWidget *parent,
Dimensions dimension,
ColorModel model,
const KoColorSpace *cs,
int channel1, int channel2,
KisVisualRectangleSelectorShape::singelDTypes d = KisVisualRectangleSelectorShape::vertical);
~KisVisualRectangleSelectorShape();
void setBarWidth();
private:
virtual QPointF convertShapeCoordinateToWidgetCoordinate(QPointF coordinate);
virtual QPointF convertWidgetCoordinateToShapeCoordinate(QPoint coordinate);
singelDTypes m_type;
QRegion getMaskMap();
void drawCursor();
};
#endif // KISVISUALCOLORSELECTOR_H
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment