Subversion Repositories Scribus

Rev

Rev 23450 | 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
 *  Created by Andreas Vox on 01.10.05.
9
 *  Copyright 2005 under GPL2. All rights reserved.
10
 *
11
 */
12
 
13
#include "colorcombo.h"
21855 jghali 14
#include "colorlistmodel.h"
4729 subik 15
#include "commonstrings.h"
11645 fschmid 16
// #include "qdebug.h"
4690 mrdocs 17
 
20173 jghali 18
ColorCombo::ColorCombo(QWidget* parent) : QComboBox(parent)
4690 mrdocs 19
{
10469 cbradney 20
        setEditable(false);
21
        ColorListBox* lb = new ColorListBox(this);
9874 avox 22
        setModel( lb->model() );
23
        setItemDelegate( lb->itemDelegate() );
24
        setView( lb );
4690 mrdocs 25
}
26
 
22368 jghali 27
ColorCombo::ColorCombo(ColorCombo::PixmapType type, QWidget* parent) : QComboBox(parent)
21664 jghali 28
{
29
        setEditable(false);
30
        ColorListBox::PixmapType clbType = ColorListBox::smallPixmap;
31
        if (type == ColorCombo::widePixmaps)
32
                clbType = ColorListBox::widePixmap;
33
        else if (type == ColorCombo::fancyPixmaps)
34
                clbType = ColorListBox::fancyPixmap;
35
        ColorListBox* lb = new ColorListBox(clbType, this);
36
        setModel( lb->model() );
37
        setItemDelegate( lb->itemDelegate() );
38
        setView( lb );
39
}
40
 
20173 jghali 41
ColorCombo::ColorCombo(bool rw, QWidget* parent) : QComboBox(parent)
4690 mrdocs 42
{
10469 cbradney 43
        setEditable(rw);
44
        ColorListBox* lb = new ColorListBox(this);
9874 avox 45
        setModel( lb->model() );
46
        setItemDelegate( lb->itemDelegate() );
47
        setView( lb );
4690 mrdocs 48
}
49
 
9874 avox 50
 
51
QString ColorCombo::currentColor() const
52
{
22603 craig 53
        QString colorName(currentText());
21045 jghali 54
        if (colorName == CommonStrings::tr_NoneColor)
55
                colorName = CommonStrings::None;
56
        return colorName;
9874 avox 57
}
58
 
21855 jghali 59
void ColorCombo::setColors(ColorList& list, bool insertNone)
4690 mrdocs 60
{
24137 craig 61
        ColorListBox* clb = qobject_cast<ColorListBox*>(view());
19398 jghali 62
        if (!clb)
63
                return;
64
 
24137 craig 65
        ColorListModel* clm = qobject_cast<ColorListModel*>(clb->model());
21855 jghali 66
        if (!clm)
21664 jghali 67
                return;
68
 
21855 jghali 69
        clm->setColorList(list, insertNone);
4690 mrdocs 70
}
71
 
23450 jghali 72
void ColorCombo::setCurrentColor(QString colorName)
73
{
74
        if (colorName == CommonStrings::None)
75
                colorName = CommonStrings::tr_NoneColor;
76
 
77
        int index = findText(colorName);
78
        if (index >= 0)
79
                this->setCurrentIndex(index);
80
}
81
 
21855 jghali 82
void ColorCombo::setPixmapType(ColorCombo::PixmapType type)
7850 jghali 83
{
24137 craig 84
        ColorListBox* clb = qobject_cast<ColorListBox*>(view());
19398 jghali 85
        if (!clb)
86
                return;
87
 
21855 jghali 88
        if (type == ColorCombo::smallPixmaps)
89
                clb->setPixmapType(ColorListBox::smallPixmap);
90
        else if (type == ColorCombo::widePixmaps)
91
                clb->setPixmapType(ColorListBox::widePixmap);
92
        else if (type == ColorCombo::fancyPixmaps)
93
                clb->setPixmapType(ColorListBox::fancyPixmap);
7850 jghali 94
}
95
 
22603 craig 96
void ColorCombo::initColorList(ColorList *colorList, ScribusDoc *doc, const QString& colorValue)
14389 cbradney 97
{
98
        clear();
21664 jghali 99
        setPixmapType(ColorCombo::fancyPixmaps);
21855 jghali 100
        setColors(*colorList, true);
101
 
14389 cbradney 102
        if (colorValue == CommonStrings::None)
21855 jghali 103
        {
104
                setCurrentIndex(0);
105
                return;
106
        }
107
 
108
        int index = 0;
14389 cbradney 109
        ColorList::Iterator endOfColorList(colorList->end());
110
        for (ColorList::Iterator itc = colorList->begin(); itc != endOfColorList; ++itc)
111
        {
21855 jghali 112
                ++index;
14389 cbradney 113
                if (itc.key() == colorValue)
21855 jghali 114
                {
115
                        setCurrentIndex(index);
116
                        break;
117
                }
14389 cbradney 118
        }
119
}