Commit 6f18c4c3 authored by Wolthera van Hövell's avatar Wolthera van Hövell 🛍

Make internal color selector dialog possible to do modal mode.

So right now, KoDualColorButton has Non-modal mode on the foreground color and modal mode on the background color.

Also contains a lot of cleanup, the UI files for example now working
properly.

Ref T2337 T2438
parent fbdce997
......@@ -24,49 +24,54 @@
#include "KoColorSpaceRegistry.h"
#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"
#include "kis_internal_color_selector.h"
#include "ui_wdgdlginternalcolorselector.h"
struct KisInternalColorSelector::Private
{
bool allowUpdates = true;
KoColor currentColor;
const KoColorSpace *currentColorSpace;
KisSpinboxColorSelector *spinBoxSelector;
bool chooseAlpha = false;
//KisSpinboxColorSelector *spinBoxSelector;
KisSignalCompressor *compressColorChanges;
};
KisInternalColorSelector::KisInternalColorSelector(QWidget *parent, KoColor color, const QString &caption)
KisInternalColorSelector::KisInternalColorSelector(QWidget *parent, KoColor color, bool modal, const QString &caption)
: QDialog(parent)
,m_d(new Private)
{
setModal(false);
setModal(modal);
m_ui = new Ui_WdgDlgInternalColorSelector();
m_ui->setupUi(this);
if (!modal) {
m_ui->buttonBox->hide();
}
setWindowTitle(caption);
this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
m_d->currentColor = color;
m_d->currentColorSpace = m_d->currentColor.colorSpace();
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)));
m_ui->spinboxselector->slotSetColor(color);
connect(m_ui->spinboxselector, SIGNAL(sigNewColor(KoColor)), this, SLOT(slotColorUpdated(KoColor)));
connect(this, SIGNAL(signalForegroundColorChosen(KoColor)), this, SLOT(slotLockSelector()));
m_d->compressColorChanges = new KisSignalCompressor(100 /* ms */, KisSignalCompressor::POSTPONE, this);
connect(m_d->compressColorChanges, SIGNAL(timeout()), this, SLOT(endUpdateWithNewColor()));
connect(m_ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(m_ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
}
KisInternalColorSelector::~KisInternalColorSelector()
{
delete ui;
delete m_ui;
//TODO: Does the scoped pointer also need to be deleted???
}
......@@ -80,7 +85,7 @@ void KisInternalColorSelector::slotColorUpdated(KoColor newColor)
}
}
void KisInternalColorSelector::slotColorSpaceChanged(const KoColorSpace *cs)
void KisInternalColorSelector::colorSpaceChanged(const KoColorSpace *cs)
{
if (cs == m_d->currentColorSpace) {
return;
......@@ -88,10 +93,34 @@ void KisInternalColorSelector::slotColorSpaceChanged(const KoColorSpace *cs)
m_d->currentColorSpace = KoColorSpaceRegistry::instance()->colorSpace(cs->colorModelId().id(), cs->colorDepthId().id(), cs->profile());
//Empty the layout.
m_d->spinBoxSelector->slotSetColorSpace(m_d->currentColorSpace);
m_ui->spinboxselector->slotSetColorSpace(m_d->currentColorSpace);
}
KoColor KisInternalColorSelector::getModalColorDialog(const KoColor color, bool chooseAlpha, QWidget* parent, QString caption)
{
KisInternalColorSelector dialog(parent, color, true, caption);
dialog.chooseAlpha(chooseAlpha);
dialog.exec();
return dialog.getCurrentColor();
}
KoColor KisInternalColorSelector::getCurrentColor()
{
return m_d->currentColor;
}
void KisInternalColorSelector::chooseAlpha(bool chooseAlpha)
{
m_d->chooseAlpha = chooseAlpha;
}
void KisInternalColorSelector::setDialogModal(bool modal)
{
m_ui->buttonBox->show();
setModal(true);
}
void KisInternalColorSelector::slotConfigurationChanged()
{
//m_d->canvas->displayColorConverter()->
......@@ -106,8 +135,8 @@ void KisInternalColorSelector::slotLockSelector()
void KisInternalColorSelector::updateAllElements(QObject *source)
{
//update everything!!!
if (source != m_d->spinBoxSelector) {
m_d->spinBoxSelector->slotSetColor(m_d->currentColor);
if (source != m_ui->spinboxselector) {
m_ui->spinboxselector->slotSetColor(m_d->currentColor);
}
if (source != this->parent()) {
......@@ -116,6 +145,7 @@ void KisInternalColorSelector::updateAllElements(QObject *source)
}
}
void KisInternalColorSelector::endUpdateWithNewColor()
{
m_d->allowUpdates = true;
......
......@@ -20,7 +20,6 @@
#define KISINTERNALCOLORSELECTOR_H
#include "kritaui_export.h"
#include "kis_canvas2.h"
#include "KoColor.h"
#include "KoColorSpace.h"
#include <QScopedPointer>
......@@ -36,14 +35,33 @@ class KRITAUI_EXPORT KisInternalColorSelector : public QDialog
{
Q_OBJECT
public:
KisInternalColorSelector(QWidget* parent, KoColor color, const QString &caption);
KisInternalColorSelector(QWidget* parent, KoColor color, bool modal, const QString &caption);
~KisInternalColorSelector();
/**
* @brief slotColorSpaceChanged
* Color space has changed.
* Color space has changed, use this dialog to change the colorspace.
*/
void slotColorSpaceChanged(const KoColorSpace *cs);
void colorSpaceChanged(const KoColorSpace *cs);
/**
* @brief getModalColorDialog
* Excecute this dialog modally. The function returns
* the KoColor you want.
* @param color - The current color. Make sure this is in the color space you want your
* end color to be in.
* @param chooseAlpha - Whether or not the alpha-choosing functionality should be used.
*/
static KoColor getModalColorDialog(const KoColor color, bool chooseAlpha = false, QWidget* parent = Q_NULLPTR, QString caption = QString());
/**
* @brief getCurrentColor
* @return gives currently active color;
*/
KoColor getCurrentColor();
void chooseAlpha(bool chooseAlpha);
void setDialogModal(bool modal);
Q_SIGNALS:
/**
......@@ -82,7 +100,7 @@ private Q_SLOTS:
void endUpdateWithNewColor();
private:
Ui::WdgDlgInternalColorSelector *ui; //the UI
Ui_WdgDlgInternalColorSelector *m_ui; //the UI
struct Private; //The private struct
const QScopedPointer<Private> m_d; //the private pointer
......
......@@ -15,7 +15,14 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QVBoxLayout" name="base"/>
<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="QDialogButtonBox" name="buttonBox">
......@@ -29,6 +36,14 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KisSpinboxColorSelector</class>
<extends>QWidget</extends>
<header>kis_spinbox_color_selector.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
......
......@@ -97,7 +97,7 @@ void KoDualColorButton::Private::init(KoDualColorButton *q)
q->setAcceptDrops( true );
QString caption = "Select a color";
colorSelectorDialog = new KisInternalColorSelector(q, foregroundColor, caption);
colorSelectorDialog = new KisInternalColorSelector(q, foregroundColor, false, caption);
connect(colorSelectorDialog, SIGNAL(signalForegroundColorChosen(KoColor)), q, SLOT(slotSetForeGroundColorFromDialog(KoColor)));
connect(q, SIGNAL(foregroundColorChanged(KoColor)), colorSelectorDialog, SLOT(slotColorUpdated(KoColor)));
}
......@@ -303,8 +303,10 @@ void KoDualColorButton::mouseReleaseEvent( QMouseEvent *event )
if(d->tmpSelection == Foreground ) {
if( d->popDialog) {
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);
......@@ -320,12 +322,16 @@ void KoDualColorButton::mouseReleaseEvent( QMouseEvent *event )
} else if ( backgroundRect.contains( event->pos() )) {
if(d->tmpSelection == Background ) {
if( d->popDialog) {
QColor c = d->displayRenderer->toQColor(d->backgroundColor);
KoColor c = d->backgroundColor;
c = KisInternalColorSelector::getModalColorDialog(c, false, this);
d->backgroundColor = c;
emit backgroundColorChanged(d->backgroundColor);
/*QColor c = d->displayRenderer->toQColor(d->backgroundColor);
c = QColorDialog::getColor(c, this);
if (c.isValid()) {
d->backgroundColor = d->displayRenderer->approximateFromRenderedQColor(c);
emit backgroundColorChanged(d->backgroundColor);
}
}*/
}
else
emit pleasePopDialog( d->backgroundColor);
......
......@@ -35,12 +35,13 @@ struct KisSpinboxColorSelector::Private
const KoColorSpace *cs;
};
KisSpinboxColorSelector::KisSpinboxColorSelector(QWidget *parent, KoColor color) : QWidget(parent) , m_d(new Private)
KisSpinboxColorSelector::KisSpinboxColorSelector(QWidget *parent) : QWidget(parent) , m_d(new Private)
{
QFormLayout *layout = new QFormLayout(this);
this->setLayout(layout);
this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
KoColor color = KoColor();
m_d->color = color;
slotSetColorSpace(m_d->color.colorSpace());
}
......
......@@ -34,7 +34,7 @@ class KRITAUI_EXPORT KisSpinboxColorSelector : public QWidget
{
Q_OBJECT
public:
explicit KisSpinboxColorSelector(QWidget *parent, KoColor color);
explicit KisSpinboxColorSelector(QWidget *parent);
~KisSpinboxColorSelector();
Q_SIGNALS:
......
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