Commit 55350f02 authored by Wolthera van Hövell's avatar Wolthera van Hövell 🛍

Move KoDualColorButton, attach internal color selector.

It doesn't crash, it updates, gets updated, can select colors, wide gamut colors, changes configuration based
on selected color's color space... It still needs to be cleaned up and have fluid updating. Also 90% of the rest of
the selector, but I first want to get this updating slot signal mess clean.

Can I keep using QObject::sender()? It's making my life very easy.

Auditors: rempt
Ref T2337, T2438
parent 6d336838
......@@ -248,6 +248,7 @@ set(kritaui_LIB_SRCS
widgets/kis_color_label_selector_widget.cpp
widgets/kis_color_filter_combo.cpp
widgets/kis_spinbox_color_selector.cpp
widgets/KoDualColorButton.cpp
input/kis_input_manager.cpp
input/kis_input_manager_p.cpp
input/kis_extended_modifiers_mapper.cpp
......
......@@ -25,6 +25,7 @@
#include "kis_signal_compressor.h"
#include "kis_canvas_resource_provider.h"
#include "KisViewManager.h"
#include "KoColorDisplayRendererInterface.h"
#include "kis_display_color_converter.h"
#include "kis_spinbox_color_selector.h"
......@@ -37,29 +38,30 @@ struct KisInternalColorSelector::Private
KoColor currentColor;
const KoColorSpace *currentColorSpace;
KisCanvas2 *canvas;
KisSpinboxColorSelector *spinBoxSelector;
KisSignalCompressor *compressColorChanges;
};
KisInternalColorSelector::KisInternalColorSelector(QWidget *parent, const QString &caption)
KisInternalColorSelector::KisInternalColorSelector(QWidget *parent, KoColor color, const QString &caption)
: QDialog(parent)
,m_d(new Private)
{
setModal(false);
setWindowTitle(caption);
this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
m_d->currentColor = KoColor();
m_d->currentColor = color;
m_d->currentColorSpace = m_d->currentColor.colorSpace();
m_d->spinBoxSelector = new KisSpinboxColorSelector;
m_d->spinBoxSelector->slotSetColorSpace(m_d->currentColorSpace);
ui->base->addWidget(m_d->spinBoxSelector);
m_d->spinBoxSelector = new KisSpinboxColorSelector(this, m_d->currentColor);
if (m_d->spinBoxSelector) {qDebug()<<"valid";}
//ui->base->addWidget(m_d->spinBoxSelector);
//ui->verticalLayout->addWidget(m_d->spinBoxSelector);
connect(m_d->spinBoxSelector, SIGNAL(sigNewColor(KoColor)), this, SLOT(slotColorUpdated(KoColor)));
connect(this, SIGNAL(signalForegroundColorChosen(KoColor)), this, SLOT(slotLockSelector()));
m_d->compressColorChanges = new KisSignalCompressor(500 /* ms */, KisSignalCompressor::POSTPONE, this);
connect(m_d->compressColorChanges, SIGNAL(timeout()), this, SLOT(sentUpdateWithNewColor()));
connect(m_d->compressColorChanges, SIGNAL(timeout()), this, SLOT(endUpdateWithNewColor()));
}
KisInternalColorSelector::~KisInternalColorSelector()
......@@ -68,37 +70,13 @@ KisInternalColorSelector::~KisInternalColorSelector()
//TODO: Does the scoped pointer also need to be deleted???
}
void KisInternalColorSelector::setCanvas(KisCanvas2 *canvas)
{
if (m_d->canvas) {
m_d->canvas->disconnectCanvasObserver(this);
}
m_d->canvas = canvas;
if (m_d->canvas) {
//basics//
connect(m_d->canvas->imageView()->resourceProvider(), SIGNAL(sigFGColorChanged(KoColor)), this, SLOT(slotColorUpdated(KoColor)));
connect(this, SIGNAL(signalForegroundColorChosen(KoColor)), m_d->canvas->imageView()->resourceProvider(), SLOT(slotSetFGColor(KoColor)));
//display color converter//
connect(m_d->canvas->displayColorConverter(), SIGNAL(displayConfigurationChanged()), this, SLOT(slotConfigurationChanged()));
}
}
void KisInternalColorSelector::unsetCanvas()
{
setEnabled(false);
m_d->canvas = 0;
}
void KisInternalColorSelector::slotColorUpdated(KoColor newColor)
{
//if the update did not come from this selector...
if (m_d->allowUpdates) {
if (m_d->allowUpdates || QObject::sender() == this->parent()) {
qDebug()<<"Color as received by the internal color selector" << KoColor::toQString(newColor);
m_d->currentColor = newColor;
updateAllElements();
} else {
emit(signalForegroundColorChosen(m_d->currentColor));
m_d->compressColorChanges->start();
updateAllElements(QObject::sender());
}
}
......@@ -116,9 +94,6 @@ void KisInternalColorSelector::slotColorSpaceChanged(const KoColorSpace *cs)
void KisInternalColorSelector::slotConfigurationChanged()
{
if (!m_d->canvas) {
return;
}
//m_d->canvas->displayColorConverter()->
//slotColorSpaceChanged(m_d->canvas->image()->colorSpace());
}
......@@ -128,10 +103,17 @@ void KisInternalColorSelector::slotLockSelector()
m_d->allowUpdates = false;
}
void KisInternalColorSelector::updateAllElements()
void KisInternalColorSelector::updateAllElements(QObject *source)
{
//update everything!!!
m_d->spinBoxSelector->slotSetColor(m_d->currentColor);
if (source != m_d->spinBoxSelector) {
m_d->spinBoxSelector->slotSetColor(m_d->currentColor);
}
if (source != this->parent()) {
emit(signalForegroundColorChosen(m_d->currentColor));
m_d->compressColorChanges->start();
}
}
void KisInternalColorSelector::endUpdateWithNewColor()
......
......@@ -20,7 +20,6 @@
#define KISINTERNALCOLORSELECTOR_H
#include "kritaui_export.h"
#include "kis_mainwindow_observer.h"
#include "kis_canvas2.h"
#include "KoColor.h"
#include "KoColorSpace.h"
......@@ -33,23 +32,18 @@
*
* A non-modal color selector dialog that is not a plugin and can thus be used for filters.
*/
class KRITAUI_EXPORT KisInternalColorSelector : public QDialog, public KisMainwindowObserver
class KRITAUI_EXPORT KisInternalColorSelector : public QDialog
{
Q_OBJECT
public:
KisInternalColorSelector(QWidget* parent, const QString &caption);
KisInternalColorSelector(QWidget* parent, KoColor color, const QString &caption);
~KisInternalColorSelector();
/**
* @brief setCanvas
* reimplemented from the canvasobserver class.
* @param canvas
*/
virtual void setCanvas(KisCanvas2 *canvas);
/**
* @brief unsetCanvas
* reimplemented from the canvas observer class.
* @brief slotColorSpaceChanged
* Color space has changed.
*/
virtual void unsetCanvas();
void slotColorSpaceChanged(const KoColorSpace *cs);
Q_SIGNALS:
/**
......@@ -79,11 +73,6 @@ private Q_SLOTS:
*/
void slotLockSelector();
/**
* @brief slotColorSpaceChanged
* Color space has changed.
*/
void slotColorSpaceChanged(const KoColorSpace *cs);
/**
* @brief slotConfigurationChanged
* Wrapper slot for changes to the colorspace.
......@@ -102,7 +91,7 @@ private:
* Updates each widget with the new element, and if it's responsible for the update sents
* a signal out that there's a new color.
*/
void updateAllElements();
void updateAllElements(QObject *source);
};
#endif // KISINTERNALCOLORSELECTOR_H
......@@ -25,6 +25,7 @@
#include "dcolorreset.xpm"
#include <QColorDialog>
#include "dialogs/kis_internal_color_selector.h"
#include <QBrush>
#include <QDrag>
......@@ -80,6 +81,7 @@ class Q_DECL_HIDDEN KoDualColorButton::Private
bool dragFlag, miniCtlFlag;
KoColor foregroundColor;
KoColor backgroundColor;
KisInternalColorSelector *colorSelectorDialog;
QPoint dragPosition;
Selection tmpSelection;
bool popDialog;
......@@ -94,6 +96,10 @@ void KoDualColorButton::Private::init(KoDualColorButton *q)
q->setMinimumSize( q->sizeHint() );
q->setAcceptDrops( true );
QString caption = "Select a color";
colorSelectorDialog = new KisInternalColorSelector(q, foregroundColor, caption);
connect(colorSelectorDialog, SIGNAL(signalForegroundColorChosen(KoColor)), q, SLOT(slotSetForeGroundColorFromDialog(KoColor)));
connect(q, SIGNAL(foregroundColorChanged(KoColor)), colorSelectorDialog, SLOT(slotColorUpdated(KoColor)));
}
KoDualColorButton::KoDualColorButton(const KoColor &foregroundColor, const KoColor &backgroundColor, QWidget *parent, QWidget* dialogParent )
......@@ -144,6 +150,7 @@ QSize KoDualColorButton::sizeHint() const
void KoDualColorButton::setForegroundColor( const KoColor &color )
{
d->foregroundColor = color;
d->colorSelectorDialog->slotColorUpdated(color);
repaint();
}
......@@ -213,6 +220,14 @@ void KoDualColorButton::dropEvent( QDropEvent *event )
*/
}
void KoDualColorButton::slotSetForeGroundColorFromDialog(const KoColor color)
{
d->foregroundColor = color;
repaint();
qDebug()<<"Color as sent by the dual color button: "<<KoColor::toQString(color);
emit foregroundColorChanged(d->foregroundColor);
}
void KoDualColorButton::mousePressEvent( QMouseEvent *event )
{
QRect foregroundRect;
......@@ -287,12 +302,13 @@ void KoDualColorButton::mouseReleaseEvent( QMouseEvent *event )
if ( foregroundRect.contains( event->pos() )) {
if(d->tmpSelection == Foreground ) {
if( d->popDialog) {
QColor c = d->displayRenderer->toQColor(d->foregroundColor);
c = QColorDialog::getColor(c, this) ;
if (c.isValid()) {
d->foregroundColor = d->displayRenderer->approximateFromRenderedQColor(c);
emit foregroundColorChanged(d->foregroundColor);
}
d->colorSelectorDialog->show();
//QColor c = d->displayRenderer->toQColor(d->foregroundColor);
//c = QColorDialog::getColor(c, this) ;
//if (c.isValid()) {
// d->foregroundColor = d->displayRenderer->approximateFromRenderedQColor(c);
// emit foregroundColorChanged(d->foregroundColor);
//}
}
else
emit pleasePopDialog( d->foregroundColor);
......
......@@ -115,6 +115,8 @@ class KRITAWIDGETS_EXPORT KoDualColorButton : public QWidget
*/
void setBackgroundColor( const KoColor &color );
void slotSetForeGroundColorFromDialog (const KoColor color);
/**
* Sets if a dialog with a color chooser should be popped up when clicking
* If you set this to false then you could connect to the pleasePopDialog signal
......
......@@ -37,12 +37,15 @@ struct KisSpinboxColorSelector::Private
KisSignalCompressor *compressUpdates;
};
KisSpinboxColorSelector::KisSpinboxColorSelector(QWidget *parent) : QWidget(parent) , m_d(new Private)
KisSpinboxColorSelector::KisSpinboxColorSelector(QWidget *parent, KoColor color) : QWidget(parent) , m_d(new Private)
{
QFormLayout *layout = new QFormLayout();
QFormLayout *layout = new QFormLayout(this);
this->setLayout(layout);
m_d->color = color;
slotSetColorSpace(m_d->color.colorSpace());
m_d->compressUpdates = new KisSignalCompressor(500 /* ms */, KisSignalCompressor::POSTPONE, this);
connect(m_d->compressUpdates, SIGNAL(timeout()), this, SLOT(slotFinishUpdate()));
}
......@@ -54,6 +57,12 @@ KisSpinboxColorSelector::~KisSpinboxColorSelector()
void KisSpinboxColorSelector::slotSetColor(KoColor color)
{
m_d->color = color;
if (m_d->color.colorSpace() != m_d->cs) {
slotSetColorSpace(m_d->color.colorSpace());
}
if (m_d->allowUpdates || QObject::sender() != this) {
updateSpinboxesWithNewValues();
}
}
void KisSpinboxColorSelector::slotSetColorSpace(const KoColorSpace *cs)
......@@ -87,7 +96,7 @@ void KisSpinboxColorSelector::slotSetColorSpace(const KoColorSpace *cs)
m_d->spinBoxList.append(input);
this->layout()->addWidget(input);
if (input) {
connect(input, SIGNAL(updated()), this, SLOT(updateFromSpinBoxes()));
connect(input, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateFromSpinBoxes()));
}
}
break;
......@@ -98,7 +107,7 @@ void KisSpinboxColorSelector::slotSetColorSpace(const KoColorSpace *cs)
m_d->spinBoxList.append(input);
this->layout()->addWidget(input);
if (input) {
connect(input, SIGNAL(updated()), this, SLOT(updateFromSpinBoxes()));
connect(input, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateFromSpinBoxes()));
}
}
break;
......@@ -109,7 +118,7 @@ void KisSpinboxColorSelector::slotSetColorSpace(const KoColorSpace *cs)
m_d->spinBoxList.append(input);
this->layout()->addWidget(input);
if (input) {
connect(input, SIGNAL(updated()), this, SLOT(updateFromSpinBoxes()));
connect(input, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateFromSpinBoxes()));
}
}
break;
......@@ -121,7 +130,7 @@ void KisSpinboxColorSelector::slotSetColorSpace(const KoColorSpace *cs)
m_d->doubleSpinBoxList.append(input);
this->layout()->addWidget(input);
if (input) {
connect(input, SIGNAL(updated()), this, SLOT(updateFromSpinBoxes()));
connect(input, SIGNAL(valueChanged(double)), this, SLOT(slotUpdateFromSpinBoxes()));
}
}
break;
......@@ -137,15 +146,16 @@ void KisSpinboxColorSelector::createColorFromSpinboxValues()
{
KoColor newColor;
int channelcount = m_d->cs->channelCount();
quint8 *data;
quint8 *data = new quint8[m_d->cs->pixelSize()];
QVector <float> channelValues(channelcount);
channelValues.fill(1.0);
QList<KoChannelInfo *> channels = KoChannelInfo::displayOrderSorted(m_d->cs->channels());
for (int i=0; i<channelcount; i++) {
for (int i=0; i<qMin(channelcount, m_d->spinBoxList.size()); i++) {
if (m_d->spinBoxList.at(i)) {
if (channels.at(i)->channelValueType()==KoChannelInfo::UINT8){
channelValues[i] = KoColorSpaceMaths<quint8,float>::scaleToA(m_d->spinBoxList.at(i)->value());
int value = m_d->spinBoxList.at(i)->value();
channelValues[i] = KoColorSpaceMaths<quint8,float>::scaleToA(value);
} else if (channels.at(i)->channelValueType()==KoChannelInfo::UINT16){
channelValues[i] = KoColorSpaceMaths<quint16,float>::scaleToA(m_d->spinBoxList.at(i)->value());
}
......@@ -182,10 +192,11 @@ void KisSpinboxColorSelector::updateSpinboxesWithNewValues()
m_d->cs->normalisedChannelsValue(m_d->color.data(), channelValues);
QList<KoChannelInfo *> channels = KoChannelInfo::displayOrderSorted(m_d->cs->channels());
for (int i=0; i<channelcount; i++) {
for (int i=0; i<qMin(channelcount, m_d->spinBoxList.size()); i++) {
if (m_d->spinBoxList.at(i)) {
if (channels.at(i)->channelValueType() == KoChannelInfo::UINT8) {
m_d->spinBoxList.at(i)->setValue(KoColorSpaceMaths<float, quint8>::scaleToA(channelValues[i]));
int value = KoColorSpaceMaths<float, quint8>::scaleToA(channelValues[i]);
m_d->spinBoxList.at(i)->setValue(value);
} else if (channels.at(i)->channelValueType() == KoChannelInfo::UINT16) {
m_d->spinBoxList.at(i)->setValue(KoColorSpaceMaths<float, quint16>::scaleToA(channelValues[i]));
}
......
......@@ -34,7 +34,7 @@ class KRITAUI_EXPORT KisSpinboxColorSelector : public QWidget
{
Q_OBJECT
public:
explicit KisSpinboxColorSelector(QWidget *parent = 0);
explicit KisSpinboxColorSelector(QWidget *parent, KoColor color);
~KisSpinboxColorSelector();
Q_SIGNALS:
......
......@@ -33,7 +33,6 @@ set(kritawidgets_LIB_SRCS
KoColorPopupAction.cpp
KoColorSetWidget.cpp
KoColorSlider.cpp
KoDualColorButton.cpp
KoEditColorSetDialog.cpp
KoTriangleColorSelector.cpp
KoResourcePopupAction.cpp
......
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