~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to krita/plugins/extensions/painterlyframework/kis_painterlymixer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
18
 * Boston, MA 02110-1301, USA.
19
19
*/
20
 
 
21
20
#include "kis_painterlymixer.h"
22
21
 
 
22
#include <QButtonGroup>
 
23
#include <QGridLayout>
 
24
#include <QSlider>
 
25
 
 
26
#include <KoColorSpace.h>
 
27
#include <KoCanvasBase.h>
 
28
#include <KoResourceManager.h>
 
29
 
23
30
#include "colorspot.h"
24
31
#include "kis_ksf32_colorspace.h"
25
32
#include "mixercanvas.h"
26
 
#include "mixertool.h"
27
 
 
28
 
#include <kis_paintop.h>
29
 
#include <kis_canvas_resource_provider.h>
30
 
#include <kis_view2.h>
31
 
#include <KoColorSpace.h>
32
 
#include <KoToolProxy.h>
33
 
#include <QButtonGroup>
34
 
 
35
 
KisPainterlyMixer::KisPainterlyMixer(QWidget *parent, KisView2 *view)
36
 
        : QWidget(parent), m_view(view), m_resources(view->resourceProvider()), m_tool(0), m_colorspace(0)
 
33
 
 
34
KisPainterlyMixer::KisPainterlyMixer(QWidget *parent)
 
35
        : QWidget(parent)
37
36
{
38
37
    setupUi(this);
39
38
 
40
 
    QString csid = KisKSF32ColorSpace<3>::ColorSpaceId().id();
41
 
    KoColorSpaceRegistry *f = KoColorSpaceRegistry::instance();
42
 
 
43
 
    // TODO Illuminant and colorspace has to be chosen at runtime
44
 
    QList<const KoColorProfile*> profiles = f->profilesFor(csid);
45
 
    if (profiles.count()) { // don't crash if the profile is not available.
46
 
        const KoColorProfile* testp = profiles.at(0);
47
 
        m_colorspace = f->colorSpace(csid, testp);
48
 
        Q_ASSERT(m_colorspace);
49
 
    } else {
50
 
        setEnabled(false);
51
 
        return;
52
 
    }
53
 
 
54
 
    initCanvas();
55
 
    initTool();
56
39
    initSpots();
57
40
 
 
41
    // XXX: ask Enkithan for a palette-knife icon
 
42
    bnMix->setIcon(KIcon("krita_tool_knife"));
 
43
    bnPick->setIcon(KIcon("krita_tool_color_picker"));
 
44
    bnPan->setIcon(KIcon("krita_tool_move"));
58
45
    m_bErase->setIcon(KIcon("edit-delete"));
59
46
    connect(m_bErase, SIGNAL(clicked()), m_canvas, SLOT(slotClear()));
 
47
 
 
48
    //connect(sliderRadius, SIGNAL(valueChanged(int)), m_canvas->mixerTool(), SLOT(setRadius(qreal)));
60
49
}
61
50
 
62
51
KisPainterlyMixer::~KisPainterlyMixer()
63
52
{
64
 
    if (m_tool)
65
 
        delete m_tool;
66
 
}
67
 
 
68
 
void KisPainterlyMixer::initCanvas()
69
 
{
70
 
    m_canvas->setLayer(m_colorspace);
71
 
    m_canvas->setToolProxy(new KoToolProxy(m_canvas));
72
 
    m_canvas->setResources(m_resources);
73
 
}
74
 
 
75
 
void KisPainterlyMixer::initTool()
76
 
{
77
 
    Q_ASSERT(m_canvas);
78
 
    m_tool = new MixerTool(m_canvas, m_resources);
79
 
    m_canvas->toolProxy()->setActiveTool(m_tool);
80
 
    m_tool->activate();
81
53
}
82
54
 
83
55
#define ROWS 2
85
57
 
86
58
void KisPainterlyMixer::initSpots()
87
59
{
 
60
    kDebug();
88
61
    int row, col;
89
62
    QGridLayout *l = new QGridLayout(m_spotsFrame);
90
63
 
92
65
    loadColors();
93
66
 
94
67
    l->setSpacing(5);
 
68
 
95
69
    for (row = 0; row < ROWS; row++) {
96
70
        for (col = 0; col < COLS; col++) {
97
71
            int index = row * COLS + col;
98
72
            QToolButton *curr = new ColorSpot(m_spotsFrame, m_vColors[index]);
 
73
            QPalette p (curr->palette());
 
74
            p.setColor(QPalette::Button, m_vColors[index].toQColor());
 
75
            curr->setPalette(p);
 
76
            curr->setAutoFillBackground(false);
 
77
 
99
78
            l->addWidget(curr, row, col);
100
79
 
101
80
            m_bgColors->addButton(curr, index);
109
88
 
110
89
void KisPainterlyMixer::loadColors()
111
90
{
112
 
    // TODO We need to handle save/load of user-defined colors in the spots.
113
 
    const KoColorSpace *cs = m_colorspace;
 
91
    // TODO: We need to handle save/load of user-defined colors in the spots.
 
92
    //       This needs to be coordinated with the favourite resources!
 
93
    const KoColorSpace *cs = m_canvas->colorSpace();
114
94
    m_vColors.append(KoColor(QColor("#FF0000"), cs)); // Red
115
95
    m_vColors.append(KoColor(QColor("#00FF00"), cs)); // Green
116
96
    m_vColors.append(KoColor(QColor("#0000FF"), cs)); // Blue
123
103
 
124
104
void KisPainterlyMixer::slotChangeColor(int index)
125
105
{
126
 
    m_resources->setFGColor(m_vColors[index]);
 
106
    emit colorChanged(m_vColors[index]);
 
107
}
 
108
 
 
109
void KisPainterlyMixer::setColor(const KoColor& color)
 
110
{
 
111
    m_canvas->resourceManager()->setForegroundColor(color);
127
112
}
128
113
 
129
114
#include "kis_painterlymixer.moc"