~ubuntu-branches/ubuntu/oneiric/koffice/oneiric-updates

« back to all changes in this revision

Viewing changes to krita/plugins/extensions/dockers/colorselectorng/kis_minimal_shade_selector.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (c) 2010 Adam Celarek <kdedev at xibo dot at>
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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.
 
16
 */
 
17
 
 
18
#include "kis_minimal_shade_selector.h"
 
19
 
 
20
#include <QColor>
 
21
#include <QVBoxLayout>
 
22
#include <QPainter>
 
23
 
 
24
#include <KConfig>
 
25
#include <KConfigGroup>
 
26
#include <KComponentData>
 
27
#include <KGlobal>
 
28
 
 
29
#include "KoResourceManager.h"
 
30
 
 
31
#include "kis_shade_selector_line.h"
 
32
 
 
33
 
 
34
KisMinimalShadeSelector::KisMinimalShadeSelector(QWidget *parent) :
 
35
    KisColorSelectorBase(parent), m_canvas(0)
 
36
{
 
37
    setAcceptDrops(true);
 
38
 
 
39
    QVBoxLayout* l = new QVBoxLayout(this);
 
40
    l->setSpacing(0);
 
41
    l->setMargin(0);
 
42
 
 
43
    updateSettings();
 
44
}
 
45
 
 
46
void KisMinimalShadeSelector::setCanvas(KisCanvas2 *canvas)
 
47
{
 
48
    KisColorSelectorBase::setCanvas(canvas);
 
49
    m_canvas=canvas;
 
50
}
 
51
 
 
52
void KisMinimalShadeSelector::setColor(const QColor& color)
 
53
{
 
54
    m_lastColor = color;
 
55
    for(int i=0; i<m_shadingLines.size(); i++)
 
56
        m_shadingLines.at(i)->setColor(color);
 
57
}
 
58
 
 
59
void KisMinimalShadeSelector::updateSettings()
 
60
{
 
61
    KisColorSelectorBase::updateSettings();
 
62
    KConfigGroup cfg = KGlobal::config()->group("advancedColorSelector");
 
63
 
 
64
    QString stri = cfg.readEntry("minimalShadeSelectorLineConfig", "0|0.2|0|0");
 
65
    QStringList strili = stri.split(';', QString::SkipEmptyParts);
 
66
 
 
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());
 
72
    }
 
73
    while(lineCount-m_shadingLines.size() < 0) {
 
74
        layout()->removeWidget(m_shadingLines.last());
 
75
        delete m_shadingLines.takeLast();
 
76
    }
 
77
 
 
78
    for(int i=0; i<strili.size(); i++) {
 
79
        m_shadingLines.at(i)->fromString(strili.at(i));
 
80
    }
 
81
 
 
82
    int lineHeight = cfg.readEntry("minimalShadeSelectorLineHeight", 20);
 
83
    setMinimumHeight(lineCount*lineHeight+2*lineCount);
 
84
    setMaximumHeight(lineCount*lineHeight+2*lineCount);
 
85
 
 
86
    for(int i=0; i<m_shadingLines.size(); i++)
 
87
        m_shadingLines.at(i)->updateSettings();
 
88
 
 
89
    setPopupBehaviour(false, false);
 
90
}
 
91
 
 
92
void KisMinimalShadeSelector::resourceChanged(int key, const QVariant &v)
 
93
{
 
94
    if(m_colorUpdateAllowed==false)
 
95
        return;
 
96
 
 
97
    KConfigGroup cfg = KGlobal::config()->group("advancedColorSelector");
 
98
 
 
99
    bool onForeground = cfg.readEntry("shadeSelectorUpdateOnForeground", false);
 
100
    bool onBackground = cfg.readEntry("shadeSelectorUpdateOnBackground", true);
 
101
 
 
102
    if ((key == KoCanvasResource::ForegroundColor && onForeground)
 
103
        || (key == KoCanvasResource::BackgroundColor && onBackground)) {
 
104
        setColor(findGeneratingColor(v.value<KoColor>()));
 
105
    }
 
106
}
 
107
 
 
108
void KisMinimalShadeSelector::paintEvent(QPaintEvent *)
 
109
{
 
110
    QPainter painter(this);
 
111
    painter.fillRect(0,0,width(), height(), QColor(128,128,128));
 
112
}
 
113
 
 
114
KisColorSelectorBase* KisMinimalShadeSelector::createPopup() const
 
115
{
 
116
    KisMinimalShadeSelector* popup = new KisMinimalShadeSelector(0);
 
117
    popup->setColor(m_lastColor);
 
118
    return popup;
 
119
}