Subversion Repositories Scribus

Rev

Rev 5880 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
3 paul 7
/***************************************************************************
8
                          colorchart.cpp  -  description
9
                             -------------------
10
    begin                : Sat Sep 15 2001
11
    copyright            : (C) 2001 by Franz Schmid
12
    email                : Franz.Schmid@altmuehlnet.de
13
 ***************************************************************************/
14
 
15
/***************************************************************************
16
 *                                                                         *
17
 *   This program is free software; you can redistribute it and/or modify  *
18
 *   it under the terms of the GNU General Public License as published by  *
19
 *   the Free Software Foundation; either version 2 of the License, or     *
20
 *   (at your option) any later version.                                   *
21
 *                                                                         *
22
 ***************************************************************************/
23
 
24
#include "colorchart.h"
25
#include "colorchart.moc"
26
#include <qpixmap.h>
27
#include <qimage.h>
28
#include <qpainter.h>
6125 cbradney 29
#include "colorutil.h"
5880 jghali 30
#include "scribusdoc.h"
3 paul 31
 
5880 jghali 32
ColorChart::ColorChart(QWidget *parent, ScribusDoc* doc) : QLabel(parent), m_doc(doc)
3 paul 33
{
161 Franz 34
        setScaledContents( true );
35
        setAlignment( static_cast<int>( QLabel::AlignCenter ) );
3 paul 36
        Xp = 0;
37
        Yp = 0;
38
        setBackgroundMode(NoBackground);
39
        drawPalette(255);
40
}
41
 
42
void ColorChart::mouseMoveEvent(QMouseEvent *m)
43
{
44
        drawMark(m->x(), m->y());
45
        emit ColorVal(m->x() * 359 / width(), m->y() * 255 / height(), false);
46
}
47
 
48
void ColorChart::mousePressEvent(QMouseEvent *m)
49
{
50
        drawMark(m->x(), m->y());
51
        emit ColorVal(m->x() * 359 / width(), m->y() * 255 / height(), false);
52
}
53
 
54
void ColorChart::mouseReleaseEvent(QMouseEvent *m)
55
{
56
        drawMark(m->x(), m->y());
57
        emit ColorVal(m->x() * 359 / width(), m->y() * 255 / height(), true);
58
}
59
 
60
void ColorChart::paintEvent(QPaintEvent *e)
61
{
62
        QPainter p;
63
        p.begin(this);
64
        p.setClipRect(e->rect());
65
        p.drawPixmap(0, 0, pmx);
66
        drawMark(Xp, Yp);
67
        p.end();
68
}
69
 
70
void ColorChart::drawMark(int x, int y)
71
{
72
        QPainter p;
73
        p.begin(this);
74
        p.setRasterOp(XorROP);
75
        p.setPen(QPen(QColor(white), 1, SolidLine, FlatCap, MiterJoin));
76
        p.drawLine(Xp-5, Yp-5, Xp-1, Yp-1);
77
        p.drawLine(Xp-5, Yp+5, Xp-1, Yp+1);
78
        p.drawLine(Xp+2, Yp+2, Xp+6, Yp+6);
79
        p.drawLine(Xp+2, Yp-2, Xp+6, Yp-6);
80
        if (!((Xp == x) && (Yp == y)))
161 Franz 81
        {
3 paul 82
                Xp = x;
83
                Yp = y;
84
                p.drawLine(Xp-5, Yp-5, Xp-1, Yp-1);
85
                p.drawLine(Xp-5, Yp+5, Xp-1, Yp+1);
86
                p.drawLine(Xp+2, Yp+2, Xp+6, Yp+6);
87
                p.drawLine(Xp+2, Yp-2, Xp+6, Yp-6);
161 Franz 88
        }
3 paul 89
        p.end();
90
}
91
 
92
void ColorChart::setMark(int h, int s)
93
{
94
        drawMark(h * width() / 359, (255-s) * height() / 255);
95
}
96
 
97
void ColorChart::drawPalette(int val)
98
{
99
        int xSize = width();
100
        int ySize = height();
101
        QImage image(xSize, ySize, 32);
102
        QColor color;
103
        int x;
104
        int y;
105
        for (y = 0; y < ySize; ++y)
161 Franz 106
        {
107
                unsigned int* p = reinterpret_cast<unsigned int*>(image.scanLine(y));
108
                for(x = 0; x < xSize; ++x)
3 paul 109
                {
110
                        color.setHsv(360*x/xSize, 256*( ySize - 1 - y )/ySize, val);
111
                        *p = color.rgb();
112
                        ++p;
113
                }
161 Franz 114
        }
5880 jghali 115
        pmx.convertFromImage(ProofImage(&image, m_doc));
3 paul 116
        setPixmap(pmx);
117
}