Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
4690 mrdocs 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
*/
7
/*
8
 *  sccombobox.h
9
 *  ScribusCVS
10
 *
11
 *  Created by Andreas Vox on 01.10.05.
12
 *  Copyright 2005 under GPL2. All rights reserved.
13
 *
14
 */
15
 
16
#include "colorcombo.h"
4729 subik 17
#include "commonstrings.h"
11645 fschmid 18
// #include "qdebug.h"
4690 mrdocs 19
 
10469 cbradney 20
ColorCombo::ColorCombo( QWidget* parent ) : QComboBox(parent)
4690 mrdocs 21
{
18204 fschmid 22
#ifdef Q_OS_MAC
9797 avox 23
//      setStyle( new ColorCombo::ScMacStyle() );
4690 mrdocs 24
#endif
10469 cbradney 25
        setEditable(false);
26
        ColorListBox* lb = new ColorListBox(this);
9874 avox 27
        setModel( lb->model() );
28
        setItemDelegate( lb->itemDelegate() );
29
        setView( lb );
4690 mrdocs 30
}
31
 
10469 cbradney 32
ColorCombo::ColorCombo( bool rw, QWidget* parent ) : QComboBox(parent)
4690 mrdocs 33
{
18204 fschmid 34
#ifdef Q_OS_MAC
9797 avox 35
//      setStyle( new ColorCombo::ScMacStyle() );
4690 mrdocs 36
#endif
10469 cbradney 37
        setEditable(rw);
38
        ColorListBox* lb = new ColorListBox(this);
9874 avox 39
        setModel( lb->model() );
40
        setItemDelegate( lb->itemDelegate() );
41
        setView( lb );
4690 mrdocs 42
}
43
 
9874 avox 44
 
45
QString ColorCombo::currentColor() const
46
{
47
                return currentText();
48
}
49
 
4690 mrdocs 50
void ColorCombo::updateBox(ColorList& list, ColorCombo::PixmapType pixType , bool insertNone)
51
{
9874 avox 52
        ColorListBox* clb = dynamic_cast<ColorListBox*>(view());
4690 mrdocs 53
        if ( clb )
54
        {
55
                clb->clear();
56
                if ( insertNone )
16861 jghali 57
                {
9874 avox 58
                        clb->addItem(CommonStrings::tr_NoneColor);
16861 jghali 59
                        clb->item(0)->setData(Qt::UserRole, CommonStrings::None);
60
                }
4690 mrdocs 61
                if ( pixType == ColorCombo::fancyPixmaps )
7850 jghali 62
                        clb->insertItems(list, ColorListBox::fancyPixmap);
4690 mrdocs 63
                else if ( pixType == ColorCombo::widePixmaps )
7850 jghali 64
                        clb->insertItems(list, ColorListBox::widePixmap);
4690 mrdocs 65
                else if ( pixType == ColorCombo::smallPixmaps )
7850 jghali 66
                        clb->insertItems(list, ColorListBox::smallPixmap);
4690 mrdocs 67
        }
68
}
69
 
7850 jghali 70
void ColorCombo::insertItems(ColorList& list, ColorCombo::PixmapType pixType)
71
{
9874 avox 72
        ColorListBox* clb = dynamic_cast<ColorListBox*>(view());
7850 jghali 73
        if ( clb )
74
        {
75
                if ( pixType == ColorCombo::fancyPixmaps )
76
                        clb->insertItems(list, ColorListBox::fancyPixmap);
77
                else if ( pixType == ColorCombo::widePixmaps )
78
                        clb->insertItems(list, ColorListBox::widePixmap);
79
                else if ( pixType == ColorCombo::smallPixmaps )
80
                        clb->insertItems(list, ColorListBox::smallPixmap);
81
        }
82
}
83
 
7478 jghali 84
void ColorCombo::insertSmallItem( const ScColor& col, ScribusDoc* doc, const QString& colName )
4690 mrdocs 85
{
9874 avox 86
        ColorListBox* clb = dynamic_cast<ColorListBox*>(view());
4690 mrdocs 87
        if ( clb )
13047 fschmid 88
                clb->addItem( new ColorPixmapItem(ColorPixmapValue(col, doc, colName)), ColorListBox::smallPixmap );
4690 mrdocs 89
}
90
 
7478 jghali 91
void ColorCombo::insertWideItem ( const ScColor& col, ScribusDoc* doc, const QString& colName )
4690 mrdocs 92
{
9874 avox 93
        ColorListBox* clb = dynamic_cast<ColorListBox*>(view());
4690 mrdocs 94
        if ( clb )
13047 fschmid 95
                clb->addItem( new ColorPixmapItem(ColorPixmapValue(col, doc, colName)), ColorListBox::widePixmap );
4690 mrdocs 96
}
97
 
7478 jghali 98
void ColorCombo::insertFancyItem( const ScColor& col, ScribusDoc* doc, const QString& colName )
4690 mrdocs 99
{
9874 avox 100
        ColorListBox* clb = dynamic_cast<ColorListBox*>(view());
4690 mrdocs 101
        if ( clb )
13047 fschmid 102
                clb->addItem( new ColorPixmapItem(ColorPixmapValue(col, doc, colName)), ColorListBox::fancyPixmap );
4690 mrdocs 103
}
104
 
14389 cbradney 105
void ColorCombo::initColorList(ColorList *colorList, ScribusDoc *doc, QString colorValue)
106
{
107
        clear();
16861 jghali 108
        addItem(CommonStrings::tr_NoneColor, CommonStrings::None);
14389 cbradney 109
        if (colorValue == CommonStrings::None)
110
                setCurrentIndex(count()-1);
111
        ColorList::Iterator endOfColorList(colorList->end());
112
        for (ColorList::Iterator itc = colorList->begin(); itc != endOfColorList; ++itc)
113
        {
114
                insertFancyItem( itc.value(), doc, itc.key() );
115
                if (itc.key() == colorValue)
116
                        setCurrentIndex(count()-1);
117
        }
118
}