2
* Copyright (c) 2010 Adam Celarek <kdedev at xibo dot at>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 2 of the License.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
#include "kis_minimal_shade_selector.h"
21
#include <QVBoxLayout>
25
#include <KConfigGroup>
26
#include <KComponentData>
29
#include "KoResourceManager.h"
31
#include "kis_shade_selector_line.h"
34
KisMinimalShadeSelector::KisMinimalShadeSelector(QWidget *parent) :
35
KisColorSelectorBase(parent), m_canvas(0)
39
QVBoxLayout* l = new QVBoxLayout(this);
46
void KisMinimalShadeSelector::setCanvas(KisCanvas2 *canvas)
48
KisColorSelectorBase::setCanvas(canvas);
52
void KisMinimalShadeSelector::setColor(const QColor& color)
55
for(int i=0; i<m_shadingLines.size(); i++)
56
m_shadingLines.at(i)->setColor(color);
59
void KisMinimalShadeSelector::updateSettings()
61
KisColorSelectorBase::updateSettings();
62
KConfigGroup cfg = KGlobal::config()->group("advancedColorSelector");
64
QString stri = cfg.readEntry("minimalShadeSelectorLineConfig", "0|0.2|0|0");
65
QStringList strili = stri.split(';', QString::SkipEmptyParts);
67
int lineCount = strili.size();
68
while(lineCount-m_shadingLines.size() > 0) {
69
m_shadingLines.append(new KisShadeSelectorLine(this));
70
m_shadingLines.last()->setLineNumber(m_shadingLines.size()-1);
71
layout()->addWidget(m_shadingLines.last());
73
while(lineCount-m_shadingLines.size() < 0) {
74
layout()->removeWidget(m_shadingLines.last());
75
delete m_shadingLines.takeLast();
78
for(int i=0; i<strili.size(); i++) {
79
m_shadingLines.at(i)->fromString(strili.at(i));
82
int lineHeight = cfg.readEntry("minimalShadeSelectorLineHeight", 20);
83
setMinimumHeight(lineCount*lineHeight+2*lineCount);
84
setMaximumHeight(lineCount*lineHeight+2*lineCount);
86
for(int i=0; i<m_shadingLines.size(); i++)
87
m_shadingLines.at(i)->updateSettings();
89
setPopupBehaviour(false, false);
92
void KisMinimalShadeSelector::resourceChanged(int key, const QVariant &v)
94
if(m_colorUpdateAllowed==false)
97
KConfigGroup cfg = KGlobal::config()->group("advancedColorSelector");
99
bool onForeground = cfg.readEntry("shadeSelectorUpdateOnForeground", false);
100
bool onBackground = cfg.readEntry("shadeSelectorUpdateOnBackground", true);
102
if ((key == KoCanvasResource::ForegroundColor && onForeground)
103
|| (key == KoCanvasResource::BackgroundColor && onBackground)) {
104
setColor(findGeneratingColor(v.value<KoColor>()));
108
void KisMinimalShadeSelector::paintEvent(QPaintEvent *)
110
QPainter painter(this);
111
painter.fillRect(0,0,width(), height(), QColor(128,128,128));
114
KisColorSelectorBase* KisMinimalShadeSelector::createPopup() const
116
KisMinimalShadeSelector* popup = new KisMinimalShadeSelector(0);
117
popup->setColor(m_lastColor);