Commit 1afa4384 authored by Wolthera van Hövell's avatar Wolthera van Hövell 🐛

Use internal visual selector in the Pop-up palette.

This means you finally can have your shape of choice inside the pop-up palette!

Needs testing, obviously.

Ref T2438
parent 9a07179d
......@@ -26,6 +26,8 @@
#include <brushengine/kis_paintop_preset.h>
#include "kis_resource_server_provider.h"
#include <KoTriangleColorSelector.h>
#include <kis_visual_color_selector.h>
#include <kis_config_notifier.h>
#include "KoColorSpaceRegistry.h"
#include <kis_types.h>
#include <QtGui>
......@@ -106,21 +108,27 @@ KisPopupPalette::KisPopupPalette(KisFavoriteResourceManager* manager, const KoCo
{
const int borderWidth = 3;
m_triangleColorSelector = new PopupColorTriangle(displayRenderer, this);
//m_triangleColorSelector = new PopupColorTriangle(displayRenderer, this);
m_triangleColorSelector = new KisVisualColorSelector(this);
m_triangleColorSelector->setDisplayRenderer(displayRenderer);
m_triangleColorSelector->setConfig(true,false);
m_triangleColorSelector->move(widgetSize/2-colorInnerRadius+borderWidth, widgetSize/2-colorInnerRadius+borderWidth);
m_triangleColorSelector->resize(colorInnerRadius*2-borderWidth*2, colorInnerRadius*2-borderWidth*2);
m_triangleColorSelector->setVisible(true);
m_triangleColorSelector->slotSetColor(KoColor());
QRegion maskedRegion(0, 0, m_triangleColorSelector->width(), m_triangleColorSelector->height(), QRegion::Ellipse );
m_triangleColorSelector->setMask(maskedRegion);
//setAttribute(Qt::WA_TranslucentBackground, true);
connect(m_triangleColorSelector, SIGNAL(realColorChanged(KoColor)),
connect(m_triangleColorSelector, SIGNAL(sigNewColor(KoColor)),
m_colorChangeCompressor.data(), SLOT(start()));
connect(m_colorChangeCompressor.data(), SIGNAL(timeout()),
SLOT(slotEmitColorChanged()));
connect(KisConfigNotifier::instance(), SIGNAL(configChanged()), m_triangleColorSelector, SLOT(ConfigurationChanged()));
connect(m_resourceManager, SIGNAL(sigChangeFGColorSelector(KoColor)),
SLOT(slotExternalFgColorChanged(KoColor)));
connect(this, SIGNAL(sigChangefGColor(KoColor)),
......@@ -179,14 +187,23 @@ KisPopupPalette::KisPopupPalette(KisFavoriteResourceManager* manager, const KoCo
void KisPopupPalette::slotExternalFgColorChanged(const KoColor &color)
{
m_triangleColorSelector->setRealColor(color);
//m_triangleColorSelector->setRealColor(color);
//hack to get around cmyk for now.
if (color.colorSpace()->colorChannelCount()>3) {
KoColor c(KoColorSpaceRegistry::instance()->rgb8());
c.fromKoColor(color);
m_triangleColorSelector->slotSetColor(c);
} else {
m_triangleColorSelector->slotSetColor(color);
}
}
void KisPopupPalette::slotEmitColorChanged()
{
if (isVisible()) {
update();
emit sigChangefGColor(m_triangleColorSelector->realColor());
emit sigChangefGColor(m_triangleColorSelector->getCurrentColor());
}
}
......@@ -325,7 +342,7 @@ void KisPopupPalette::paintEvent(QPaintEvent* e)
//painting foreground color
QPainterPath fgColor;
fgColor.addEllipse(QPoint(-width() / 2 + 50, -height() / 2 + 32), 30, 30);
painter.fillPath(fgColor, m_displayRenderer->toQColor(m_triangleColorSelector->realColor()));
painter.fillPath(fgColor, m_displayRenderer->toQColor(m_triangleColorSelector->getCurrentColor()));
painter.drawPath(fgColor);
// create an ellipse for the background that is slightly
......
......@@ -33,6 +33,7 @@ class KisSignalCompressor;
class KisBrushHud;
class KisRoundHudButton;
class KisCanvasResourceProvider;
class KisVisualColorSelector;
class KisPopupPalette : public QWidget
{
......@@ -98,7 +99,7 @@ private:
int m_hoveredColor;
int m_selectedColor;
KisFavoriteResourceManager* m_resourceManager;
KoTriangleColorSelector* m_triangleColorSelector;
KisVisualColorSelector* m_triangleColorSelector;
QTimer* m_timer;
......
......@@ -97,6 +97,11 @@ void KisVisualColorSelector::setConfig(bool forceCircular, bool forceSelfUpdate)
m_d->circular = forceCircular;
}
KoColor KisVisualColorSelector::getCurrentColor()
{
return m_d->currentcolor;
}
void KisVisualColorSelector::ConfigurationChanged()
{
m_d->updateTimer = new KisSignalCompressor(100 /* ms */, KisSignalCompressor::POSTPONE, this);
......@@ -115,16 +120,24 @@ void KisVisualColorSelector::slotRebuildSelectors()
m_d->widgetlist.clear();
QLayout *layout = new QHBoxLayout;
//redraw all the widgets.
int sizeValue = qMin(width(), height());
int borderWidth = qMax(sizeValue*0.1, 20.0);
if (m_d->currentCS->colorChannelCount() == 1) {
KisVisualRectangleSelectorShape *bar = new KisVisualRectangleSelectorShape(this, KisVisualRectangleSelectorShape::onedimensional,KisVisualColorSelectorShape::Channel, m_d->currentCS, 0, 0);
bar->setMaximumWidth(width()*0.1);
bar->setMaximumHeight(height());
KisVisualColorSelectorShape *bar;
if (m_d->circular==false) {
bar = new KisVisualRectangleSelectorShape(this, KisVisualColorSelectorShape::onedimensional,KisVisualColorSelectorShape::Channel, m_d->currentCS, 0, 0,m_d->displayRenderer, borderWidth);
bar->setMaximumWidth(width()*0.1);
bar->setMaximumHeight(height());
} else {
bar= new KisVisualEllipticalSelectorShape(this, KisVisualColorSelectorShape::onedimensional,KisVisualColorSelectorShape::Channel, m_d->currentCS, 0, 0,m_d->displayRenderer, borderWidth, KisVisualEllipticalSelectorShape::borderMirrored);
layout->setMargin(0);
}
connect (bar, SIGNAL(sigNewColor(KoColor)), this, SLOT(updateFromWidgets(KoColor)));
layout->addWidget(bar);
m_d->widgetlist.append(bar);
} else if (m_d->currentCS->colorChannelCount() == 3) {
int sizeValue = qMin(width(), height());
int borderWidth = qMax(sizeValue*0.1, 20.0);
QRect newrect(0,0, this->geometry().width(), this->geometry().height());
......@@ -346,14 +359,19 @@ void KisVisualColorSelector::resizeEvent(QResizeEvent *) {
int sizeValue = qMin(width(), height());
int borderWidth = qMax(sizeValue*0.1, 20.0);
QRect newrect(0,0, this->geometry().width(), this->geometry().height());
if (!m_d->currentCS) {
slotsetColorSpace(m_d->currentcolor.colorSpace());
}
if (m_d->currentCS->colorChannelCount()==3) {
if (m_d->acs_config.subType==Ring) {
m_d->widgetlist.at(0)->resize(sizeValue,sizeValue);
} else if (m_d->acs_config.subType==Slider) {
} else if (m_d->acs_config.subType==Slider && m_d->circular==false) {
m_d->widgetlist.at(0)->setMaximumWidth(borderWidth);
m_d->widgetlist.at(0)->setMinimumWidth(borderWidth);
m_d->widgetlist.at(0)->setMinimumHeight(sizeValue);
m_d->widgetlist.at(0)->setMaximumHeight(sizeValue);
} else if (m_d->acs_config.subType==Slider && m_d->circular==true) {
m_d->widgetlist.at(0)->resize(sizeValue,sizeValue);
}
m_d->widgetlist.at(0)->setBorderWidth(borderWidth);
......@@ -841,7 +859,9 @@ QVector <qreal> KisVisualColorSelectorShape::getHSX(QVector<qreal> hsx, bool wra
ihsx[2] = m_d->tone;
}
} else {
ihsx[2] = m_d->tone;
if (hsx[2]>m_d->tone-0.005 && hsx[2]<m_d->tone+0.005) {
ihsx[2] = m_d->tone;
}
}
if (m_d->model==HSV){
if (hsx[2]<=0.0) {
......@@ -1376,6 +1396,7 @@ void KisVisualEllipticalSelectorShape::drawCursor()
QPainter painter;
painter.begin(&fullSelector);
painter.setRenderHint(QPainter::Antialiasing);
QRect innerRect(m_barWidth, m_barWidth, width()-(m_barWidth*2), height()-(m_barWidth*2));
painter.save();
painter.setCompositionMode(QPainter::CompositionMode_Clear);
......@@ -1384,7 +1405,8 @@ void KisVisualEllipticalSelectorShape::drawCursor()
painter.setPen(pen);
painter.drawEllipse(QRect(0,0,width(),height()));
if (getDimensions()==KisVisualColorSelectorShape::onedimensional) {
painter.drawEllipse(QRect(this->geometry().top()+m_barWidth, this->geometry().left()+m_barWidth, this->geometry().width()-(m_barWidth*2), this->geometry().height()-(m_barWidth*2)));
painter.setBrush(Qt::SolidPattern);
painter.drawEllipse(innerRect);
}
painter.restore();
......@@ -1392,7 +1414,6 @@ void KisVisualEllipticalSelectorShape::drawCursor()
fill.setStyle(Qt::SolidPattern);
int cursorwidth = 5;
QRect innerRect(m_barWidth, m_barWidth, width()-(m_barWidth*2), height()-(m_barWidth*2));
if(m_type==KisVisualEllipticalSelectorShape::borderMirrored){
painter.setPen(Qt::white);
fill.setColor(Qt::white);
......
......@@ -103,6 +103,7 @@ public:
* force self-update is for making it update itself when using a modal dialog.
*/
void setConfig(bool forceCircular, bool forceSelfUpdate);
KoColor getCurrentColor();
Q_SIGNALS:
void sigNewColor(KoColor c);
......
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