Commit 20febd11 authored by Wolthera van Hövell's avatar Wolthera van Hövell 🛍

Add KoColorSetWidget, and KoColorPatches for current/previous color

Also rearranged the widget a lot. The KoColorSetWidget is automatically filled with the first palette in the list(which is, as always, concept cookie), and the palette is saved... right now on leave and accept events, which might not be the most intuitive, but at the least it is saved and loaded correctly.

Neither widget has the color management from the displayrenderer, as that would require me editing those directly.

I would like an eye on said save/load code.
Auditors: rempt
parent d9fc35c3
......@@ -23,6 +23,9 @@
#include <QPointer>
#include "KoColorSpaceRegistry.h"
#include <KoColorSet.h>
#include <KoResourceServerProvider.h>
#include <KoResourceServer.h>
#include "kis_signal_compressor.h"
#include "KisViewManager.h"
......@@ -32,11 +35,13 @@
#include "kis_internal_color_selector.h"
#include "ui_wdgdlginternalcolorselector.h"
#include "kis_config.h"
struct KisInternalColorSelector::Private
{
bool allowUpdates = true;
KoColor currentColor;
KoColor previousColor;
const KoColorSpace *currentColorSpace;
bool chooseAlpha = false;
KisSignalCompressor *compressColorChanges;
......@@ -68,6 +73,23 @@ KisInternalColorSelector::KisInternalColorSelector(QWidget *parent, KoColor colo
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. Might be not necessary...?
KisConfig cfg;
QString paletteName = cfg.readEntry("internal_selector_active_color_set", QString());
KoResourceServer<KoColorSet>* rServer = KoResourceServerProvider::instance()->paletteServer(false);
KoColorSet *savedPal = rServer->resourceByName(paletteName);
if (savedPal) {
m_ui->paletteBox->setColorSet(savedPal);
} else {
savedPal = rServer->resources().first();
if (savedPal) {
m_ui->paletteBox->setColorSet(savedPal);
}
}
connect(m_ui->paletteBox, SIGNAL(colorChanged(KoColor,bool)), this, SLOT(slotColorUpdated(KoColor)));
m_ui->currentColor->setColor(m_d->currentColor);
m_ui->previousColor->setColor(m_d->currentColor);
connect(this, SIGNAL(accepted()), this, SLOT(setPreviousColor()));
connect(this, SIGNAL(signalForegroundColorChosen(KoColor)), this, SLOT(slotLockSelector()));
m_d->compressColorChanges = new KisSignalCompressor(100 /* ms */, KisSignalCompressor::POSTPONE, this);
......@@ -87,7 +109,6 @@ void KisInternalColorSelector::slotColorUpdated(KoColor newColor)
{
//if the update did not come from this selector...
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(QObject::sender());
}
......@@ -143,6 +164,15 @@ void KisInternalColorSelector::slotLockSelector()
m_d->allowUpdates = false;
}
void KisInternalColorSelector::setPreviousColor()
{
m_d->previousColor = m_d->currentColor;
KisConfig cfg;
if (m_ui->paletteBox->colorSet()) {
cfg.writeEntry("internal_selector_active_color_set", m_ui->paletteBox->colorSet()->name());
}
}
void KisInternalColorSelector::updateAllElements(QObject *source)
{
//update everything!!!
......@@ -153,6 +183,10 @@ void KisInternalColorSelector::updateAllElements(QObject *source)
m_ui->visualSelector->slotSetColor(m_d->currentColor);
}
m_ui->previousColor->setColor(m_d->previousColor);
m_ui->currentColor->setColor(m_d->currentColor);
if (source != this->parent()) {
emit(signalForegroundColorChosen(m_d->currentColor));
m_d->compressColorChanges->start();
......@@ -164,3 +198,9 @@ void KisInternalColorSelector::endUpdateWithNewColor()
{
m_d->allowUpdates = true;
}
void KisInternalColorSelector::leaveEvent(QEvent *)
{
setPreviousColor();
}
......@@ -107,6 +107,12 @@ private Q_SLOTS:
void endUpdateWithNewColor();
/**
* @brief setPreviousColor
* triggered when the dialog is either accepted or hidden.
*/
void setPreviousColor();
private:
Ui_WdgDlgInternalColorSelector *m_ui; //the UI
struct Private; //The private struct
......@@ -118,6 +124,8 @@ private:
* a signal out that there's a new color.
*/
void updateAllElements(QObject *source);
virtual void leaveEvent(QEvent *);
};
#endif // KISINTERNALCOLORSELECTOR_H
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>418</width>
<width>430</width>
<height>483</height>
</rect>
</property>
......@@ -15,33 +15,123 @@
</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>250</width>
<height>250</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="KisSpinboxColorSelector" name="spinboxselector" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="KisScreenColorPicker" name="screenColorPicker" native="true"/>
<layout class="QHBoxLayout" name="horizontal">
<item>
<layout class="QVBoxLayout" name="rightPane">
<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>250</width>
<height>250</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="KisSpinboxColorSelector" name="spinboxselector" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="leftPane">
<item>
<widget class="KoColorSetWidget" name="paletteBox">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>220</width>
<height>50</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="KisScreenColorPicker" name="screenColorPicker" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="nextprevlayout">
<item>
<widget class="KoColorPatch" name="currentColor" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="KoColorPatch" name="previousColor" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
......@@ -74,6 +164,18 @@
<header>kis_visual_color_selector.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KoColorPatch</class>
<extends>QWidget</extends>
<header>KoColorPatch.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KoColorSetWidget</class>
<extends>QFrame</extends>
<header>KoColorSetWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
......
......@@ -88,12 +88,12 @@ void KisVisualColorSelector::slotsetColorSpace(const KoColorSpace *cs)
} else if (m_d->currentCS->colorChannelCount() == 3) {
KisVisualRectangleSelectorShape *bar = new KisVisualRectangleSelectorShape(this,
KisVisualRectangleSelectorShape::onedimensional,
KisVisualColorSelectorShape::HSV,
cs, 2, 2,
KisVisualColorSelectorShape::HSL,
cs, 0, 0,
m_d->displayRenderer);
KisVisualRectangleSelectorShape *block = new KisVisualRectangleSelectorShape(this, KisVisualRectangleSelectorShape::twodimensional,
KisVisualColorSelectorShape::HSV,
cs, 0, 1,
KisVisualColorSelectorShape::HSL,
cs, 1, 2,
m_d->displayRenderer);
bar->setMaximumWidth(width()*0.1);
bar->setMaximumHeight(height());
......
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