Back to index

scribus-ng  1.3.4.dfsg+svn20071115
colorlistbox.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 #include "colorlistbox.h"
00008 #include "colorlistbox.moc"
00009 #include <qpainter.h>
00010 #include <qpixmap.h>
00011 #include <qbitmap.h>
00012 #include <cstdlib>
00013 
00014 #include "scconfig.h"
00015 #include "commonstrings.h"
00016 #include "scribusdoc.h"
00017 #include "colorutil.h"
00018 #include "util.h"
00019 #include "sccolorengine.h"
00020 
00021 ColorSmallPixmapItem::ColorSmallPixmapItem( const ScColor& col, ScribusDoc* doc, const QString colName ) 
00022                                    : ScListBoxPixmap<15,15>()
00023 {
00024        m_color = col;
00025        m_doc = (doc) ? doc->guardedPtr() : NULL;
00026        setText(colName);
00027 }
00028 
00029 void ColorSmallPixmapItem::redraw(void)
00030 {
00031        QPixmap* pPixmap = ScListBoxPixmap<15,15>::pmap.get();
00032        QColor rgb = ScColorEngine::getDisplayColor(m_color, m_doc);
00033        pPixmap->fill(rgb);
00034        QPainter painter(pPixmap);
00035        painter.setBrush(Qt::NoBrush);
00036        QPen b(Qt::black, 1);
00037        painter.setPen(b);
00038        painter.drawRect(0, 0, 15, 15);
00039        painter.end();
00040 }
00041 
00042 ColorWidePixmapItem::ColorWidePixmapItem( const ScColor& col, ScribusDoc* doc, const QString colName ) 
00043                                    : ScListBoxPixmap<30,15>()
00044 {
00045        m_color = col;
00046        m_doc = (doc) ? doc->guardedPtr() : NULL;
00047        setText(colName);
00048 }
00049 
00050 void ColorWidePixmapItem::redraw(void)
00051 {
00052        QColor rgb = ScColorEngine::getDisplayColor(m_color, m_doc);
00053        ScListBoxPixmap<30,15>::pmap->fill(rgb);
00054 }
00055 
00056 ColorFancyPixmapItem::ColorFancyPixmapItem( const ScColor& col, ScribusDoc* doc, const QString colName ) 
00057                                    : ScListBoxPixmap<60,15>()
00058 {
00059        m_color = col;
00060        m_doc = (doc) ? doc->guardedPtr() : NULL;
00061        setText(colName);
00062 }
00063 
00064 void ColorFancyPixmapItem::redraw(void)
00065 {
00066        static QPixmap smallPix(15, 15);
00067        static QPixmap alertIcon;
00068        static QPixmap cmykIcon;
00069        static QPixmap rgbIcon;
00070        static QPixmap spotIcon;
00071        static QPixmap regIcon;
00072        static bool iconsInitialized = false;
00073 
00074        if ( !iconsInitialized ) {
00075               alertIcon = loadIcon("alert.png");
00076               cmykIcon = loadIcon("cmyk.png");
00077               rgbIcon = loadIcon("rgb.png");
00078               spotIcon = loadIcon("spot.png");
00079               regIcon = loadIcon("register.png");
00080               iconsInitialized = true;
00081        }
00082 
00083        QColor rgb = ScColorEngine::getDisplayColor(m_color, m_doc);
00084        smallPix.fill(rgb);
00085        QPainter painter(&smallPix);
00086        painter.setBrush(Qt::NoBrush);
00087        QPen b(Qt::black, 1);
00088        painter.setPen(b);
00089        painter.drawRect(0, 0, 15, 15);
00090        painter.end();
00091 
00092        QPixmap* pPixmap = ScListBoxPixmap<60,15>::pmap.get();
00093        pPixmap->fill(Qt::color0);
00094        paintAlert(smallPix, *pPixmap, 0, 0);
00095        bool isOutOfGamut = ScColorEngine::isOutOfGamut(m_color, m_doc);
00096        if (isOutOfGamut)
00097               paintAlert(alertIcon, *pPixmap, 15, 0);
00098        if ((m_color.getColorModel() == colorModelCMYK) || (m_color.isSpotColor()))
00099               paintAlert(cmykIcon, *pPixmap, 30, 0);
00100        else
00101               paintAlert(rgbIcon, *pPixmap, 30, 0);
00102        if (m_color.isSpotColor())
00103               paintAlert(spotIcon, *pPixmap, 45, 0);
00104        if (m_color.isRegistrationColor())
00105               paintAlert(regIcon, *pPixmap, 46, 0);
00106        if (pPixmap->mask() && ((!m_color.isSpotColor() && !m_color.isRegistrationColor()) || !isOutOfGamut))
00107        {
00108               QPainter alpha; // transparency handling
00109               alpha.begin(pPixmap->mask());
00110               alpha.setBrush(Qt::color0);
00111               alpha.setPen(Qt::color0);
00112               if (!m_color.isSpotColor() && !m_color.isRegistrationColor())
00113                      alpha.drawRect(45, 0, 15, 15);
00114               if (!isOutOfGamut)
00115                      alpha.drawRect(15, 0, 15, 15);
00116               alpha.end();
00117        }
00118 }
00119 
00120 ColorListBox::ColorListBox(QWidget * parent, const char * name, WFlags f)
00121        : QListBox(parent, name, f)
00122 {
00123        if (!name || strlen(name) == 0)
00124               setName("ColorListBox");
00125 }
00126 
00127 void ColorListBox::updateBox(ColorList& list, ColorListBox::PixmapType type)
00128 {
00129        clear();
00130        insertItems(list, type);
00131 }
00132 
00133 void ColorListBox::insertItems(ColorList& list, ColorListBox::PixmapType type)
00134 {
00135        if (type == ColorListBox::fancyPixmap)
00136               insertFancyPixmapItems( list );
00137        else if (type == ColorListBox::widePixmap)
00138               insertWidePixmapItems( list );
00139        else if (type == ColorListBox::smallPixmap)
00140               insertSmallPixmapItems( list );
00141 }
00142 
00143 void ColorListBox::insertSmallPixmapItems(ColorList& list)
00144 {
00145        ColorList::Iterator it;
00146        ScribusDoc* doc = list.document();
00147        for (it = list.begin(); it != list.end(); ++it)
00148        {
00149               if (it.key() == CommonStrings::None || it.key() == CommonStrings::tr_NoneColor)
00150                      continue;
00151               insertItem( new ColorSmallPixmapItem(it.data(), doc, it.key()) );
00152        }
00153 }
00154 
00155 void ColorListBox::insertWidePixmapItems(ColorList& list)
00156 {
00157        ColorList::Iterator it;
00158        ScribusDoc* doc = list.document();
00159        for (it = list.begin(); it != list.end(); ++it)
00160        {
00161               if (it.key() == CommonStrings::None || it.key() == CommonStrings::tr_NoneColor)
00162                      continue;
00163               insertItem( new ColorWidePixmapItem(it.data(), doc, it.key()) );
00164        }
00165 }
00166 
00167 void ColorListBox::insertFancyPixmapItems(ColorList& list)
00168 {
00169        ColorList::Iterator it;
00170        ScribusDoc* doc = list.document();
00171        for (it = list.begin(); it != list.end(); ++it)
00172        {
00173               if (it.key() == CommonStrings::None || it.key() == CommonStrings::tr_NoneColor)
00174                      continue;
00175               insertItem( new ColorFancyPixmapItem(it.data(), doc, it.key()) );
00176        }
00177 }