Commit aed9a2c9 authored by Halla Rempt's avatar Halla Rempt
Browse files

Make the color selector in the popup palette configurable

I haven't managed to find time to optimize the performance
more, so give people a choice which version to use. The
config key is

popuppalette/usevisualcolorselector

If it's set to true, the new color selector is used.
parent dd95f238
...@@ -48,7 +48,48 @@ ...@@ -48,7 +48,48 @@
#include "brushhud/kis_round_hud_button.h" #include "brushhud/kis_round_hud_button.h"
#include <kis_action.h> #include <kis_action.h>
class PopupColorTriangle : public KoTriangleColorSelector
{
public:
PopupColorTriangle(const KoColorDisplayRendererInterface *displayRenderer, QWidget* parent)
: KoTriangleColorSelector(displayRenderer, parent)
, m_dragging(false) {
}
~PopupColorTriangle() override {}
void tabletEvent(QTabletEvent* event) override {
event->accept();
QMouseEvent* mouseEvent = 0;
switch (event->type()) {
case QEvent::TabletPress:
mouseEvent = new QMouseEvent(QEvent::MouseButtonPress, event->pos(),
Qt::LeftButton, Qt::LeftButton, event->modifiers());
m_dragging = true;
mousePressEvent(mouseEvent);
break;
case QEvent::TabletMove:
mouseEvent = new QMouseEvent(QEvent::MouseMove, event->pos(),
(m_dragging) ? Qt::LeftButton : Qt::NoButton,
(m_dragging) ? Qt::LeftButton : Qt::NoButton, event->modifiers());
mouseMoveEvent(mouseEvent);
break;
case QEvent::TabletRelease:
mouseEvent = new QMouseEvent(QEvent::MouseButtonRelease, event->pos(),
Qt::LeftButton,
Qt::LeftButton,
event->modifiers());
m_dragging = false;
mouseReleaseEvent(mouseEvent);
break;
default: break;
}
delete mouseEvent;
}
private:
bool m_dragging;
};
KisPopupPalette::KisPopupPalette(KisViewManager* viewManager, KisCoordinatesConverter* coordinatesConverter ,KisFavoriteResourceManager* manager, KisPopupPalette::KisPopupPalette(KisViewManager* viewManager, KisCoordinatesConverter* coordinatesConverter ,KisFavoriteResourceManager* manager,
const KoColorDisplayRendererInterface *displayRenderer, KisCanvasResourceProvider *provider, QWidget *parent) const KoColorDisplayRendererInterface *displayRenderer, KisCanvasResourceProvider *provider, QWidget *parent)
...@@ -74,7 +115,12 @@ KisPopupPalette::KisPopupPalette(KisViewManager* viewManager, KisCoordinatesConv ...@@ -74,7 +115,12 @@ KisPopupPalette::KisPopupPalette(KisViewManager* viewManager, KisCoordinatesConv
const int borderWidth = 3; const int borderWidth = 3;
m_triangleColorSelector = new KisVisualColorSelector(this); if (KisConfig().readEntry<bool>("popuppalette/usevisualcolorselector", false)) {
m_triangleColorSelector = new KisVisualColorSelector(this);
}
else {
m_triangleColorSelector = new PopupColorTriangle(displayRenderer, this);
}
m_triangleColorSelector->setDisplayRenderer(displayRenderer); m_triangleColorSelector->setDisplayRenderer(displayRenderer);
m_triangleColorSelector->setConfig(true,false); m_triangleColorSelector->setConfig(true,false);
m_triangleColorSelector->move(m_popupPaletteSize/2-m_colorHistoryInnerRadius+borderWidth, m_popupPaletteSize/2-m_colorHistoryInnerRadius+borderWidth); m_triangleColorSelector->move(m_popupPaletteSize/2-m_colorHistoryInnerRadius+borderWidth, m_popupPaletteSize/2-m_colorHistoryInnerRadius+borderWidth);
...@@ -91,7 +137,7 @@ KisPopupPalette::KisPopupPalette(KisViewManager* viewManager, KisCoordinatesConv ...@@ -91,7 +137,7 @@ KisPopupPalette::KisPopupPalette(KisViewManager* viewManager, KisCoordinatesConv
//setAttribute(Qt::WA_TranslucentBackground, true); //setAttribute(Qt::WA_TranslucentBackground, true);
connect(m_triangleColorSelector, SIGNAL(sigNewColor(KoColor)), connect(m_triangleColorSelector, SIGNAL(sigNewColor(const KoColor &)),
m_colorChangeCompressor.data(), SLOT(start())); m_colorChangeCompressor.data(), SLOT(start()));
connect(m_colorChangeCompressor.data(), SIGNAL(timeout()), connect(m_colorChangeCompressor.data(), SIGNAL(timeout()),
SLOT(slotEmitColorChanged())); SLOT(slotEmitColorChanged()));
...@@ -205,7 +251,6 @@ KisPopupPalette::KisPopupPalette(KisViewManager* viewManager, KisCoordinatesConv ...@@ -205,7 +251,6 @@ KisPopupPalette::KisPopupPalette(KisViewManager* viewManager, KisCoordinatesConv
void KisPopupPalette::slotExternalFgColorChanged(const KoColor &color) void KisPopupPalette::slotExternalFgColorChanged(const KoColor &color)
{ {
//m_triangleColorSelector->setRealColor(color);
//hack to get around cmyk for now. //hack to get around cmyk for now.
if (color.colorSpace()->colorChannelCount()>3) { if (color.colorSpace()->colorChannelCount()>3) {
KoColor c(KoColorSpaceRegistry::instance()->rgb8()); KoColor c(KoColorSpaceRegistry::instance()->rgb8());
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "kis_coordinates_converter.h" #include "kis_coordinates_converter.h"
#include "kis_tool_button.h" #include "kis_tool_button.h"
#include "kis_highlighted_button.h" #include "kis_highlighted_button.h"
#include <KisColorSelectorInterface.h>
class KisFavoriteResourceManager; class KisFavoriteResourceManager;
class QWidget; class QWidget;
...@@ -115,7 +115,7 @@ private: ...@@ -115,7 +115,7 @@ private:
KisActionManager* m_actionManager; KisActionManager* m_actionManager;
KisFavoriteResourceManager* m_resourceManager; KisFavoriteResourceManager* m_resourceManager;
KisVisualColorSelector* m_triangleColorSelector; KisColorSelectorInterface* m_triangleColorSelector {0};
const KoColorDisplayRendererInterface *m_displayRenderer; const KoColorDisplayRendererInterface *m_displayRenderer;
QScopedPointer<KisSignalCompressor> m_colorChangeCompressor; QScopedPointer<KisSignalCompressor> m_colorChangeCompressor;
KActionCollection* m_actionCollection; KActionCollection* m_actionCollection;
......
...@@ -59,7 +59,7 @@ struct KisVisualColorSelector::Private ...@@ -59,7 +59,7 @@ struct KisVisualColorSelector::Private
}; };
KisVisualColorSelector::KisVisualColorSelector(QWidget *parent) KisVisualColorSelector::KisVisualColorSelector(QWidget *parent)
: QWidget(parent) : KisColorSelectorInterface(parent)
, m_d(new Private) , m_d(new Private)
{ {
this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
...@@ -77,7 +77,7 @@ KisVisualColorSelector::~KisVisualColorSelector() ...@@ -77,7 +77,7 @@ KisVisualColorSelector::~KisVisualColorSelector()
delete m_d->updateTimer; delete m_d->updateTimer;
} }
void KisVisualColorSelector::slotSetColor(KoColor c) void KisVisualColorSelector::slotSetColor(const KoColor &c)
{ {
if (m_d->updateSelf == false) { if (m_d->updateSelf == false) {
m_d->currentcolor = c; m_d->currentcolor = c;
...@@ -102,7 +102,7 @@ void KisVisualColorSelector::setConfig(bool forceCircular, bool forceSelfUpdate) ...@@ -102,7 +102,7 @@ void KisVisualColorSelector::setConfig(bool forceCircular, bool forceSelfUpdate)
m_d->updateLonesome = forceSelfUpdate; m_d->updateLonesome = forceSelfUpdate;
} }
KoColor KisVisualColorSelector::getCurrentColor() KoColor KisVisualColorSelector::getCurrentColor() const
{ {
return m_d->currentcolor; return m_d->currentcolor;
} }
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "KoColorDisplayRendererInterface.h" #include "KoColorDisplayRendererInterface.h"
#include "KisColorSelectorConfiguration.h" #include "KisColorSelectorConfiguration.h"
#include "KisColorSelectorInterface.h"
#include "kritaui_export.h" #include "kritaui_export.h"
/** /**
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
* Unlike other color selectors, this one draws the full gamut of the given * Unlike other color selectors, this one draws the full gamut of the given
* colorspace. * colorspace.
*/ */
class KRITAUI_EXPORT KisVisualColorSelector : public QWidget class KRITAUI_EXPORT KisVisualColorSelector : public KisColorSelectorInterface
{ {
Q_OBJECT Q_OBJECT
public: public:
...@@ -56,24 +56,24 @@ public: ...@@ -56,24 +56,24 @@ public:
* force self-update is for making it update itself when using a modal dialog. * force self-update is for making it update itself when using a modal dialog.
*/ */
void setConfig(bool forceCircular, bool forceSelfUpdate); void setConfig(bool forceCircular, bool forceSelfUpdate);
KoColor getCurrentColor(); KoColor getCurrentColor() const;
Q_SIGNALS:
void sigNewColor(KoColor c);
public Q_SLOTS: public Q_SLOTS:
void slotSetColor(KoColor c); void slotSetColor(const KoColor &c);
void slotsetColorSpace(const KoColorSpace *cs); void slotsetColorSpace(const KoColorSpace *cs);
void slotRebuildSelectors(); void slotRebuildSelectors();
void configurationChanged(); void configurationChanged();
void setDisplayRenderer (const KoColorDisplayRendererInterface *displayRenderer); void setDisplayRenderer (const KoColorDisplayRendererInterface *displayRenderer);
private Q_SLOTS: private Q_SLOTS:
void updateFromWidgets(KoColor c); void updateFromWidgets(KoColor c);
void HSXwrangler(); void HSXwrangler();
protected: protected:
void leaveEvent(QEvent *); void leaveEvent(QEvent *);
void resizeEvent(QResizeEvent *); void resizeEvent(QResizeEvent *);
private: private:
struct Private; struct Private;
const QScopedPointer<Private> m_d; const QScopedPointer<Private> m_d;
......
...@@ -83,6 +83,8 @@ set(kritawidgets_LIB_SRCS ...@@ -83,6 +83,8 @@ set(kritawidgets_LIB_SRCS
kis_double_parse_spin_box.cpp kis_double_parse_spin_box.cpp
kis_double_parse_unit_spin_box.cpp kis_double_parse_unit_spin_box.cpp
kis_int_parse_spin_box.cpp kis_int_parse_spin_box.cpp
KisColorSelectorInterface.cpp
) )
ki18n_wrap_ui( kritawidgets_LIB_SRCS ki18n_wrap_ui( kritawidgets_LIB_SRCS
......
/*
* Copyright (C) 2016 Boudewijn Rempt <boud@valdyas.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <KisColorSelectorInterface.h>
/*
* Copyright (C) 2016 Boudewijn Rempt <boud@valdyas.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KISCOLORSELECTORINTERFACE_H
#define KISCOLORSELECTORINTERFACE_H
#include "kritawidgets_export.h"
#include <QWidget>
#include <KoColor.h>
class KoColorDisplayRendererInterface;
class KRITAWIDGETS_EXPORT KisColorSelectorInterface : public QWidget {
Q_OBJECT
public:
KisColorSelectorInterface(QWidget *parent = 0)
: QWidget(parent)
{}
virtual ~KisColorSelectorInterface() {}
virtual void setConfig(bool forceCircular, bool forceSelfUpdate)
{
Q_UNUSED(forceCircular);
Q_UNUSED(forceSelfUpdate);
}
virtual void setDisplayRenderer (const KoColorDisplayRendererInterface *displayRenderer)
{
Q_UNUSED(displayRenderer);
}
virtual KoColor getCurrentColor() const = 0;
Q_SIGNALS:
void sigNewColor(const KoColor &c);
public Q_SLOTS:
virtual void slotSetColor(const KoColor &c) = 0;
};
#endif // KISCOLORSELECTORINTERFACE_H
...@@ -118,7 +118,7 @@ KoColorPopupAction::~KoColorPopupAction() ...@@ -118,7 +118,7 @@ KoColorPopupAction::~KoColorPopupAction()
void KoColorPopupAction::setCurrentColor( const KoColor &color ) void KoColorPopupAction::setCurrentColor( const KoColor &color )
{ {
d->colorChooser->setRealColor( color ); d->colorChooser->slotSetColor( color );
KoColor minColor( color ); KoColor minColor( color );
d->currentColor = minColor; d->currentColor = minColor;
......
...@@ -90,14 +90,14 @@ void KoTriangleColorSelector::Private::init() ...@@ -90,14 +90,14 @@ void KoTriangleColorSelector::Private::init()
} }
KoTriangleColorSelector::KoTriangleColorSelector(QWidget* parent) KoTriangleColorSelector::KoTriangleColorSelector(QWidget* parent)
: QWidget(parent), : KisColorSelectorInterface(parent),
d(new Private(this, KoDumbColorDisplayRenderer::instance())) d(new Private(this, KoDumbColorDisplayRenderer::instance()))
{ {
d->init(); d->init();
} }
KoTriangleColorSelector::KoTriangleColorSelector(const KoColorDisplayRendererInterface *displayRenderer, QWidget *parent) KoTriangleColorSelector::KoTriangleColorSelector(const KoColorDisplayRendererInterface *displayRenderer, QWidget *parent)
: QWidget(parent), : KisColorSelectorInterface(parent),
d(new Private(this, displayRenderer)) d(new Private(this, displayRenderer))
{ {
d->init(); d->init();
...@@ -160,7 +160,7 @@ void KoTriangleColorSelector::paintEvent( QPaintEvent * event ) ...@@ -160,7 +160,7 @@ void KoTriangleColorSelector::paintEvent( QPaintEvent * event )
p.save(); p.save();
p.setPen( QPen( Qt::white, 1.0) ); p.setPen( QPen( Qt::white, 1.0) );
QColor currentColor = d->displayRenderer->toQColor(realColor()); QColor currentColor = d->displayRenderer->toQColor(getCurrentColor());
p.setBrush(currentColor); p.setBrush(currentColor);
p.rotate( hue() + 150 ); p.rotate( hue() + 150 );
...@@ -240,14 +240,14 @@ void KoTriangleColorSelector::setHSV(int h, int s, int v) ...@@ -240,14 +240,14 @@ void KoTriangleColorSelector::setHSV(int h, int s, int v)
setSaturation(s); setSaturation(s);
} }
KoColor KoTriangleColorSelector::realColor() const KoColor KoTriangleColorSelector::getCurrentColor() const
{ {
return d->displayRenderer->fromHsv(hue(), saturation(), value()); return d->displayRenderer->fromHsv(hue(), saturation(), value());
} }
void KoTriangleColorSelector::setRealColor(const KoColor & color) void KoTriangleColorSelector::slotSetColor(const KoColor & color)
{ {
if ( realColor() == color) if ( getCurrentColor() == color)
return; return;
//displayrenderer->getHsv is what sets the foreground color in the application //displayrenderer->getHsv is what sets the foreground color in the application
...@@ -266,7 +266,7 @@ void KoTriangleColorSelector::setRealColor(const KoColor & color) ...@@ -266,7 +266,7 @@ void KoTriangleColorSelector::setRealColor(const KoColor & color)
QColor KoTriangleColorSelector::color() const QColor KoTriangleColorSelector::color() const
{ {
return realColor().toQColor(); return getCurrentColor().toQColor();
} }
void KoTriangleColorSelector::resizeEvent( QResizeEvent * event ) void KoTriangleColorSelector::resizeEvent( QResizeEvent * event )
...@@ -285,8 +285,8 @@ inline qreal pow2(qreal v) ...@@ -285,8 +285,8 @@ inline qreal pow2(qreal v)
void KoTriangleColorSelector::tellColorChanged() void KoTriangleColorSelector::tellColorChanged()
{ {
d->updateAllowed = false; d->updateAllowed = false;
emit(realColorChanged(realColor())); emit(sigNewColor(getCurrentColor()));
emit(colorChanged(realColor().toQColor())); emit(colorChanged(getCurrentColor().toQColor()));
d->updateAllowed = true; d->updateAllowed = true;
} }
...@@ -295,7 +295,7 @@ void KoTriangleColorSelector::generateTriangle() ...@@ -295,7 +295,7 @@ void KoTriangleColorSelector::generateTriangle()
QImage image(d->sizeColorSelector, d->sizeColorSelector, QImage::Format_ARGB32); QImage image(d->sizeColorSelector, d->sizeColorSelector, QImage::Format_ARGB32);
// Length of triangle // Length of triangle
int hue_ = hue(); int hue_ = hue();
for(int y = 0; y < d->sizeColorSelector; ++y) for(int y = 0; y < d->sizeColorSelector; ++y)
{ {
qreal ynormalize = ( d->triangleTop - y ) / ( d->triangleTop - d->triangleBottom ); qreal ynormalize = ( d->triangleTop - y ) / ( d->triangleTop - d->triangleBottom );
...@@ -324,7 +324,7 @@ void KoTriangleColorSelector::generateTriangle() ...@@ -324,7 +324,7 @@ void KoTriangleColorSelector::generateTriangle()
} }
} }
} }
d->trianglePixmap = QPixmap::fromImage(image); d->trianglePixmap = QPixmap::fromImage(image);
d->invalidTriangle = false; d->invalidTriangle = false;
} }
...@@ -395,14 +395,14 @@ void KoTriangleColorSelector::mouseMoveEvent( QMouseEvent * event ) ...@@ -395,14 +395,14 @@ void KoTriangleColorSelector::mouseMoveEvent( QMouseEvent * event )
void KoTriangleColorSelector::selectColorAt(int _x, int _y, bool checkInWheel) void KoTriangleColorSelector::selectColorAt(int _x, int _y, bool checkInWheel)
{ {
Q_UNUSED( checkInWheel ); Q_UNUSED( checkInWheel );
if (d->lastX == _x && d->lastY == _y) if (d->lastX == _x && d->lastY == _y)
{ {
return; return;
} }
d->lastX = _x; d->lastX = _x;
d->lastY = _y; d->lastY = _y;
qreal x = _x - 0.5*width(); qreal x = _x - 0.5*width();
qreal y = _y - 0.5*height(); qreal y = _y - 0.5*height();
// Check if the click is inside the wheel // Check if the click is inside the wheel
......
...@@ -23,11 +23,13 @@ ...@@ -23,11 +23,13 @@
#include "kritawidgets_export.h" #include "kritawidgets_export.h"
#include <KisColorSelectorInterface.h>
class KoColor; class KoColor;
class KoColorDisplayRendererInterface; class KoColorDisplayRendererInterface;
class KRITAWIDGETS_EXPORT KoTriangleColorSelector : public QWidget { class KRITAWIDGETS_EXPORT KoTriangleColorSelector : public KisColorSelectorInterface {
Q_OBJECT Q_OBJECT
public: public:
explicit KoTriangleColorSelector(QWidget *parent); explicit KoTriangleColorSelector(QWidget *parent);
...@@ -43,7 +45,7 @@ class KRITAWIDGETS_EXPORT KoTriangleColorSelector : public QWidget { ...@@ -43,7 +45,7 @@ class KRITAWIDGETS_EXPORT KoTriangleColorSelector : public QWidget {
int hue() const; int hue() const;
int value() const; int value() const;
int saturation() const; int saturation() const;
KoColor realColor() const; KoColor getCurrentColor() const;
// please use realColor() instead! // please use realColor() instead!
Q_DECL_DEPRECATED QColor color() const; Q_DECL_DEPRECATED QColor color() const;
...@@ -53,10 +55,9 @@ class KRITAWIDGETS_EXPORT KoTriangleColorSelector : public QWidget { ...@@ -53,10 +55,9 @@ class KRITAWIDGETS_EXPORT KoTriangleColorSelector : public QWidget {
void setValue(int v); void setValue(int v);
void setSaturation(int s); void setSaturation(int s);
void setHSV(int h, int s, int v); void setHSV(int h, int s, int v);
void setRealColor(const KoColor& ); void slotSetColor(const KoColor& );
Q_SIGNALS: Q_SIGNALS:
void colorChanged(const QColor& ); void colorChanged(const QColor& );
void realColorChanged(const KoColor& );
private Q_SLOTS: private Q_SLOTS:
void configurationChanged(); void configurationChanged();
private: private:
......
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