diff --git a/plugins/dockers/advancedcolorselector/kis_shade_selector_line_combo_box.cpp b/plugins/dockers/advancedcolorselector/kis_shade_selector_line_combo_box.cpp index 05ce10c446..1e2ecb2367 100644 --- a/plugins/dockers/advancedcolorselector/kis_shade_selector_line_combo_box.cpp +++ b/plugins/dockers/advancedcolorselector/kis_shade_selector_line_combo_box.cpp @@ -1,172 +1,173 @@ /* * Copyright (c) 2010 Adam Celarek * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; version 2.1 of the License. * * 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kis_shade_selector_line_combo_box.h" #include #include #include #include #include #include "kis_shade_selector_line.h" #include "kis_shade_selector_line_combo_box_popup.h" #include "kis_color_selector_base_proxy.h" #include "kis_global.h" KisShadeSelectorLineComboBox::KisShadeSelectorLineComboBox(QWidget *parent) : QComboBox(parent), m_popup(new KisShadeSelectorLineComboBoxPopup(this)), m_parentProxy(new KisColorSelectorBaseProxyNoop()), m_currentLine(new KisShadeSelectorLine(0,0,0, m_parentProxy.data(), this)) { QGridLayout* l = new QGridLayout(this); l->addWidget(m_currentLine); m_currentLine->setEnabled(false); KoColor color; color.fromQColor(QColor(190, 50, 50)); m_currentLine->setColor(color); updateSettings(); } KisShadeSelectorLineComboBox::~KisShadeSelectorLineComboBox() { } void KisShadeSelectorLineComboBox::hidePopup() { QComboBox::hidePopup(); m_popup->hide(); } void KisShadeSelectorLineComboBox::showPopup() { QComboBox::showPopup(); m_popup->show(); const int widgetMargin = 20; const QRect fitRect = kisGrowRect(QApplication::desktop()->screenGeometry(), -widgetMargin); QRect popupRect = m_popup->rect(); popupRect.moveTo(mapToGlobal(QPoint())); popupRect = kisEnsureInRect(popupRect, fitRect); m_popup->move(popupRect.topLeft()); m_popup->setConfiguration(m_currentLine->toString()); } void KisShadeSelectorLineComboBox::setConfiguration(const QString &stri) { m_currentLine->fromString(stri); + update(); } QString KisShadeSelectorLineComboBox::configuration() const { return m_currentLine->toString(); } void KisShadeSelectorLineComboBox::setLineNumber(int n) { m_currentLine->setLineNumber(n); for(int i=0; ilayout()->count(); i++) { KisShadeSelectorLine* item = dynamic_cast(m_popup->layout()->itemAt(i)->widget()); if(item!=0) { item->setLineNumber(n); } } } void KisShadeSelectorLineComboBox::resizeEvent(QResizeEvent *e) { Q_UNUSED(e); m_currentLine->setMaximumWidth(width()-30-m_popup->spacing); m_popup->setMinimumWidth(qMax(280, width())); m_popup->setMaximumWidth(qMax(280, width())); } void KisShadeSelectorLineComboBox::updateSettings() { m_currentLine->updateSettings(); for(int i=0; ilayout()->count(); i++) { KisShadeSelectorLine* item = dynamic_cast(m_popup->layout()->itemAt(i)->widget()); if(item!=0) { item->updateSettings(); item->m_lineHeight=30; item->setMaximumHeight(30); item->setMinimumHeight(30); } } setLineHeight(m_currentLine->m_lineHeight); } void KisShadeSelectorLineComboBox::setGradient(bool b) { m_currentLine->m_gradient=b; for(int i=0; ilayout()->count(); i++) { KisShadeSelectorLine* item = dynamic_cast(m_popup->layout()->itemAt(i)->widget()); if(item!=0) { item->m_gradient=b; } } update(); } void KisShadeSelectorLineComboBox::setPatches(bool b) { m_currentLine->m_gradient=!b; for(int i=0; ilayout()->count(); i++) { KisShadeSelectorLine* item = dynamic_cast(m_popup->layout()->itemAt(i)->widget()); if(item!=0) { item->m_gradient=!b; } } update(); } void KisShadeSelectorLineComboBox::setPatchCount(int count) { m_currentLine->m_patchCount=count; for(int i=0; ilayout()->count(); i++) { KisShadeSelectorLine* item = dynamic_cast(m_popup->layout()->itemAt(i)->widget()); if(item!=0) { item->m_patchCount=count; } } update(); } void KisShadeSelectorLineComboBox::setLineHeight(int height) { m_currentLine->m_lineHeight=height; m_currentLine->setMinimumHeight(height); m_currentLine->setMaximumHeight(height); setMinimumHeight(height+m_popup->spacing); setMaximumHeight(height+m_popup->spacing); update(); } diff --git a/plugins/dockers/advancedcolorselector/kis_shade_selector_line_combo_box_popup.cpp b/plugins/dockers/advancedcolorselector/kis_shade_selector_line_combo_box_popup.cpp index 5a271b11b1..5920fef600 100644 --- a/plugins/dockers/advancedcolorselector/kis_shade_selector_line_combo_box_popup.cpp +++ b/plugins/dockers/advancedcolorselector/kis_shade_selector_line_combo_box_popup.cpp @@ -1,170 +1,171 @@ /* * Copyright (c) 2010 Adam Celarek * Copyright (c) 2013 Dmitry Kazakov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kis_shade_selector_line_combo_box.h" #include "kis_shade_selector_line_combo_box_popup.h" #include #include #include #include "kis_global.h" #include "kis_shade_selector_line.h" #include "kis_shade_selector_line_editor.h" #include "kis_color_selector_base_proxy.h" KisShadeSelectorLineComboBoxPopup::KisShadeSelectorLineComboBoxPopup(QWidget* parent) : QWidget(parent, Qt::Popup), spacing(10), m_lastHighlightedItem(0), m_lastSelectedItem(0), m_lineEditor(0), m_parentProxy(new KisColorSelectorBaseProxyNoop()) { setMouseTracking(true); QVBoxLayout* layout = new QVBoxLayout(this); layout->setSpacing(spacing); layout->addWidget(new KisShadeSelectorLine(1.0, 0.0, 0.0, m_parentProxy.data(), this)); layout->addWidget(new KisShadeSelectorLine(0.1, 0.0, 0.0, m_parentProxy.data(), this)); layout->addWidget(new KisShadeSelectorLine(0.2, 0.0, 0.0, m_parentProxy.data(), this)); layout->addWidget(new KisShadeSelectorLine(0.0, 0.5, 0.0, m_parentProxy.data(), this)); layout->addWidget(new KisShadeSelectorLine(0.0, 1.0, 0.0, m_parentProxy.data(), this)); layout->addWidget(new KisShadeSelectorLine(0.0, 0.0, 0.5, m_parentProxy.data(), this)); layout->addWidget(new KisShadeSelectorLine(0.0, 0.0, 1.0, m_parentProxy.data(), this)); layout->addWidget(new KisShadeSelectorLine(0.0, 0.5, 0.5, m_parentProxy.data(), this)); layout->addWidget(new KisShadeSelectorLine(0.0, 1.0, 1.0, m_parentProxy.data(), this)); layout->addWidget(new KisShadeSelectorLine(0.0, -0.5, 0.5, m_parentProxy.data(), this)); layout->addWidget(new KisShadeSelectorLine(0.0, -1.0, 1.0, m_parentProxy.data(), this)); layout->addWidget(new KisShadeSelectorLine(0.0, 0.5, 0.5, m_parentProxy.data(), this, -0.04)); layout->addWidget(new KisShadeSelectorLine(0.0, 0.5, 0.5, m_parentProxy.data(), this, +0.04)); layout->addWidget(new KisShadeSelectorLine(0.0, -0.5, 0.5, m_parentProxy.data(), this, -0.04)); - layout->addWidget(new KisShadeSelectorLine(0.0, -0.5, 0.5, m_parentProxy.data(), this, +0.04)); - m_lineEditor = new KisShadeSelectorLineEditor(this); + KisShadeSelectorLine* preview = new KisShadeSelectorLine(0.0, -0.5, 0.5, m_parentProxy.data(), this, +0.04); + m_lineEditor = new KisShadeSelectorLineEditor(this, preview); + layout->addWidget(preview); layout->addWidget(m_lineEditor); connect(m_lineEditor, SIGNAL(requestActivateLine(QWidget*)), SLOT(activateItem(QWidget*))); for(int i=0; ilayout()->count(); i++) { KisShadeSelectorLine* item = dynamic_cast(this->layout()->itemAt(i)->widget()); if(item!=0) { item->setMouseTracking(true); item->setEnabled(false); KoColor color; color.fromQColor(QColor(190, 50, 50)); item->setColor(color); item->showHelpText(); } } } KisShadeSelectorLineComboBoxPopup::~KisShadeSelectorLineComboBoxPopup() { } void KisShadeSelectorLineComboBoxPopup::setConfiguration(const QString &string) { m_lineEditor->fromString(string); } void KisShadeSelectorLineComboBoxPopup::updateSelectedArea(const QRect &newRect) { QRect oldSelectedArea = m_selectedArea; m_selectedArea = newRect; update(oldSelectedArea); update(m_selectedArea); } void KisShadeSelectorLineComboBoxPopup::updateHighlightedArea(const QRect &newRect) { QRect oldHighlightArea = m_highlightedArea; m_highlightedArea = newRect; update(oldHighlightArea); update(m_highlightedArea); } void KisShadeSelectorLineComboBoxPopup::activateItem(QWidget *widget) { KisShadeSelectorLineBase* item = dynamic_cast(widget); KIS_ASSERT_RECOVER_RETURN(item); QRect itemRect = kisGrowRect(item->geometry(), spacing / 2 - 1); m_lastSelectedItem = item; updateSelectedArea(itemRect); } void KisShadeSelectorLineComboBoxPopup::paintEvent(QPaintEvent *) { QPainter painter(this); painter.fillRect(0,0,width(), height(), QColor(128,128,128)); painter.fillRect(m_selectedArea, palette().highlight()); painter.setPen(QPen(palette().highlight(), 2)); painter.drawRect(m_highlightedArea); } void KisShadeSelectorLineComboBoxPopup::mouseMoveEvent(QMouseEvent * e) { if(rect().contains(e->pos())) { for(int i = 0; i < layout()->count(); i++) { KisShadeSelectorLineBase* item = dynamic_cast(layout()->itemAt(i)->widget()); KIS_ASSERT_RECOVER_RETURN(item); QRect itemRect = kisGrowRect(item->geometry(), spacing / 2 - 1); if(itemRect.contains(e->pos())) { m_lastHighlightedItem = item; updateHighlightedArea(itemRect); } } } else { updateHighlightedArea(QRect()); } } void KisShadeSelectorLineComboBoxPopup::mousePressEvent(QMouseEvent* e) { if(rect().contains(e->pos())) { mouseMoveEvent(e); m_lastSelectedItem = m_lastHighlightedItem; if (m_lastSelectedItem != m_lineEditor) { m_lineEditor->blockSignals(true); m_lineEditor->fromString(m_lastSelectedItem->toString()); m_lineEditor->blockSignals(false); } - updateSelectedArea(m_highlightedArea); - } else { - if (m_lastSelectedItem) { - KisShadeSelectorLineComboBox *parent = dynamic_cast(this->parent()); - Q_ASSERT(parent); - parent->setConfiguration(m_lastSelectedItem->toString()); - } - hide(); + } + if (m_lastSelectedItem) { + KisShadeSelectorLineComboBox *parent = dynamic_cast(this->parent()); + Q_ASSERT(parent); + parent->setConfiguration(m_lastSelectedItem->toString()); } e->accept(); + + this->parentWidget()->update(); + hide(); } diff --git a/plugins/dockers/advancedcolorselector/kis_shade_selector_line_editor.cpp b/plugins/dockers/advancedcolorselector/kis_shade_selector_line_editor.cpp index d799f1e2d8..3d824c0bf2 100644 --- a/plugins/dockers/advancedcolorselector/kis_shade_selector_line_editor.cpp +++ b/plugins/dockers/advancedcolorselector/kis_shade_selector_line_editor.cpp @@ -1,102 +1,125 @@ /* * Copyright (c) 2010 Adam Celarek * Copyright (c) 2013 Dmitry Kazakov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "kis_shade_selector_line_editor.h" +#include +#include "kis_shade_selector_line_editor.h" #include "kis_double_parse_spin_box.h" +#include "kis_config.h" -KisShadeSelectorLineEditor::KisShadeSelectorLineEditor(QWidget* parent) +KisShadeSelectorLineEditor::KisShadeSelectorLineEditor(QWidget* parent, KisShadeSelectorLine* preview) : KisShadeSelectorLineBase(parent) + , m_line_preview(preview) { QVBoxLayout* layout = new QVBoxLayout(this); QHBoxLayout* lineOne = new QHBoxLayout(); layout->addLayout(lineOne); lineOne->addWidget(new QLabel(i18n("Delta: "))); m_hueDelta = new KisDoubleParseSpinBox(); lineOne->addWidget(m_hueDelta); m_saturationDelta = new KisDoubleParseSpinBox(); lineOne->addWidget(m_saturationDelta); m_valueDelta = new KisDoubleParseSpinBox(); lineOne->addWidget(m_valueDelta); QHBoxLayout* lineTwo = new QHBoxLayout(); layout->addLayout(lineTwo); lineTwo->addWidget(new QLabel(i18n("Shift: "))); m_hueShift = new KisDoubleParseSpinBox(); lineTwo->addWidget(m_hueShift); m_saturationShift = new KisDoubleParseSpinBox(); lineTwo->addWidget(m_saturationShift); m_valueShift = new KisDoubleParseSpinBox(); lineTwo->addWidget(m_valueShift); m_hueDelta->setRange(-1, 1); m_saturationDelta->setRange(-1, 1); m_valueDelta->setRange(-1, 1); m_hueShift->setRange(-1, 1); m_saturationShift->setRange(-1, 1); m_valueShift->setRange(-1, 1); m_hueDelta->setSingleStep(0.1); m_saturationDelta->setSingleStep(0.1); m_valueDelta->setSingleStep(0.1); m_hueShift->setSingleStep(0.05); m_saturationShift->setSingleStep(0.05); m_valueShift->setSingleStep(0.05); connect(m_hueDelta, SIGNAL(valueChanged(double)), SLOT(valueChanged())); connect(m_saturationDelta, SIGNAL(valueChanged(double)), SLOT(valueChanged())); connect(m_valueDelta, SIGNAL(valueChanged(double)), SLOT(valueChanged())); connect(m_hueShift, SIGNAL(valueChanged(double)), SLOT(valueChanged())); connect(m_saturationShift, SIGNAL(valueChanged(double)), SLOT(valueChanged())); connect(m_valueShift, SIGNAL(valueChanged(double)), SLOT(valueChanged())); + KConfigGroup cfg = KSharedConfig::openConfig()->group("advancedColorSelector"); + QString lineset = cfg.readEntry( + "minimalShadeSelectorLineConfig", "0|0.2|0|0|0|0|0;1|0|1|1|0|0|0;2|0|-1|1|0|0|0;").split(";").at(0); + fromString(lineset); + + updatePreview(); +} + +void KisShadeSelectorLineEditor::updatePreview(){ + m_line_preview->setParam( + m_hueDelta->value(), m_saturationDelta->value(), m_valueDelta->value(), + m_hueShift->value(), m_saturationShift->value(), m_valueShift->value() + ); + this->parentWidget()->update(m_line_preview->geometry()); } QString KisShadeSelectorLineEditor::toString() const { return QString("%1|%2|%3|%4|%5|%6|%7") .arg(m_lineNumber) .arg(m_hueDelta->value()) .arg(m_saturationDelta->value()) .arg(m_valueDelta->value()) .arg(m_hueShift->value()) .arg(m_saturationShift->value()) .arg(m_valueShift->value()); } void KisShadeSelectorLineEditor::fromString(const QString &string) { QStringList strili = string.split('|'); m_lineNumber = strili.at(0).toInt(); m_hueDelta->setValue(strili.at(1).toDouble()); m_saturationDelta->setValue(strili.at(2).toDouble()); m_valueDelta->setValue(strili.at(3).toDouble()); if(strili.size()==4) return; // don't crash, if reading old config files. m_hueShift->setValue(strili.at(4).toDouble()); m_saturationShift->setValue(strili.at(5).toDouble()); m_valueShift->setValue(strili.at(6).toDouble()); } void KisShadeSelectorLineEditor::valueChanged() { + updatePreview(); emit requestActivateLine(this); } + +void KisShadeSelectorLineEditor::mousePressEvent(QMouseEvent* e) { + e->accept(); +} + diff --git a/plugins/dockers/advancedcolorselector/kis_shade_selector_line_editor.h b/plugins/dockers/advancedcolorselector/kis_shade_selector_line_editor.h index cf4febcf6e..303516768b 100644 --- a/plugins/dockers/advancedcolorselector/kis_shade_selector_line_editor.h +++ b/plugins/dockers/advancedcolorselector/kis_shade_selector_line_editor.h @@ -1,57 +1,64 @@ /* * Copyright (c) 2010 Adam Celarek * Copyright (c) 2013 Dmitry Kazakov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __KIS_SHADE_SELECTOR_LINE_EDITOR_H #define __KIS_SHADE_SELECTOR_LINE_EDITOR_H #include #include #include #include #include #include "kis_shade_selector_line.h" class KisDoubleParseSpinBox; class KisShadeSelectorLineEditor : public KisShadeSelectorLineBase { Q_OBJECT public: - KisShadeSelectorLineEditor(QWidget* parent); + KisShadeSelectorLineEditor(QWidget* parent, KisShadeSelectorLine *preview); QString toString() const override; void fromString(const QString &string) override; + void mousePressEvent(QMouseEvent* e) override; + +private: + void updatePreview(); + private Q_SLOTS: void valueChanged(); Q_SIGNALS: void requestActivateLine(QWidget *widget); private: + KisShadeSelectorLine* m_line_preview; + KisDoubleParseSpinBox* m_hueDelta; KisDoubleParseSpinBox* m_saturationDelta; KisDoubleParseSpinBox* m_valueDelta; KisDoubleParseSpinBox* m_hueShift; KisDoubleParseSpinBox* m_saturationShift; KisDoubleParseSpinBox* m_valueShift; }; #endif /* __KIS_SHADE_SELECTOR_LINE_EDITOR_H */