Back to index

scribus-ng  1.3.4.dfsg+svn20071115
colorchart.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008                           colorchart.cpp  -  description
00009                              -------------------
00010     begin                : Sat Sep 15 2001
00011     copyright            : (C) 2001 by Franz Schmid
00012     email                : Franz.Schmid@altmuehlnet.de
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 
00024 #include "colorchart.h"
00025 #include "colorchart.moc"
00026 #include <qpixmap.h>
00027 #include <qimage.h>
00028 #include <qpainter.h>
00029 #include "colorutil.h"
00030 #include "scribusdoc.h"
00031 
00032 ColorChart::ColorChart(QWidget *parent, ScribusDoc* doc) : QLabel(parent), m_doc(doc)
00033 {
00034        setScaledContents( true );
00035        setAlignment( static_cast<int>( QLabel::AlignCenter ) );
00036        Xp = 0;
00037        Yp = 0;
00038        setBackgroundMode(NoBackground);
00039        drawPalette(255);
00040 }
00041 
00042 void ColorChart::mouseMoveEvent(QMouseEvent *m)
00043 {
00044        drawMark(m->x(), m->y());
00045        emit ColorVal(m->x() * 359 / width(), m->y() * 255 / height(), true);
00046 }
00047 
00048 void ColorChart::mousePressEvent(QMouseEvent *m)
00049 {
00050        drawMark(m->x(), m->y());
00051        emit ColorVal(m->x() * 359 / width(), m->y() * 255 / height(), true);
00052 }
00053 
00054 void ColorChart::mouseReleaseEvent(QMouseEvent *m)
00055 {
00056        drawMark(m->x(), m->y());
00057        emit ColorVal(m->x() * 359 / width(), m->y() * 255 / height(), true);
00058 }
00059 
00060 void ColorChart::paintEvent(QPaintEvent *e)
00061 {
00062        QPainter p;
00063        p.begin(this);
00064        p.setClipRect(e->rect());
00065        p.drawPixmap(0, 0, pmx);
00066        drawMark(Xp, Yp);
00067        p.end();
00068 }
00069 
00070 void ColorChart::drawMark(int x, int y)
00071 {
00072        QPainter p;
00073        p.begin(this);
00074        p.setRasterOp(XorROP);
00075        p.setPen(QPen(QColor(white), 1, SolidLine, FlatCap, MiterJoin));
00076        p.drawLine(Xp-5, Yp-5, Xp-1, Yp-1);
00077        p.drawLine(Xp-5, Yp+5, Xp-1, Yp+1);
00078        p.drawLine(Xp+2, Yp+2, Xp+6, Yp+6);
00079        p.drawLine(Xp+2, Yp-2, Xp+6, Yp-6);
00080        if (!((Xp == x) && (Yp == y)))
00081        {
00082               Xp = x;
00083               Yp = y;
00084               p.drawLine(Xp-5, Yp-5, Xp-1, Yp-1);
00085               p.drawLine(Xp-5, Yp+5, Xp-1, Yp+1);
00086               p.drawLine(Xp+2, Yp+2, Xp+6, Yp+6);
00087               p.drawLine(Xp+2, Yp-2, Xp+6, Yp-6);
00088        }
00089        p.end();
00090 }
00091 
00092 void ColorChart::setMark(int h, int s)
00093 {
00094        drawMark(h * width() / 359, (255-s) * height() / 255);
00095 }
00096 
00097 void ColorChart::drawPalette(int val)
00098 {
00099        int xSize = width();
00100        int ySize = height();
00101        QImage image(xSize, ySize, 32);
00102        QColor color;
00103        int x;
00104        int y;
00105        for (y = 0; y < ySize; ++y)
00106        {
00107               unsigned int* p = reinterpret_cast<unsigned int*>(image.scanLine(y));
00108               for(x = 0; x < xSize; ++x)
00109               {
00110                      color.setHsv(360*x/xSize, 256*( ySize - 1 - y )/ySize, val);
00111                      *p = color.rgb();
00112                      ++p;
00113               }
00114        }
00115        pmx.convertFromImage(ProofImage(&image, m_doc));
00116        setPixmap(pmx);
00117 }