chalk

kis_palette_widget.cpp
1/*
2 * Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#include <stdio.h>
20#include <stdlib.h>
21
22#include <tqcheckbox.h>
23#include <tqcombobox.h>
24#include <tqdrawutil.h>
25#include <tqevent.h>
26#include <tqfile.h>
27#include <tqimage.h>
28#include <tqlabel.h>
29#include <tqlayout.h>
30#include <tqlineedit.h>
31#include <tqvalidator.h>
32#include <tqpainter.h>
33#include <tqpushbutton.h>
34#include <tqspinbox.h>
35#include <tqtimer.h>
36
37#include <tdeapplication.h>
38#include <tdeconfig.h>
39#include <tdeglobal.h>
40#include <tdeglobalsettings.h>
41#include <kiconloader.h>
42#include <tdelistbox.h>
43#include <tdelocale.h>
44#include <tdemessagebox.h>
45#include <kseparator.h>
46#include <kpalette.h>
47#include <kimageeffect.h>
48
49#include <kcolordialog.h>
50#include <kcolordrag.h>
51#include <config.h>
52#include <kdebug.h>
53
54#include <kis_meta_registry.h>
55#include <kis_color.h>
56#include <kis_factory.h>
57#include <kis_colorspace_factory_registry.h>
58#include "kis_palette_widget.h"
59#include "kis_resource.h"
60#include "kis_palette.h"
61#include "kis_palette_view.h"
62
63KisPaletteWidget::KisPaletteWidget( TQWidget *parent, int minWidth, int cols)
64 : TQWidget( parent ), mMinWidth(minWidth), mCols(cols)
65{
66 init = false;
67
68 m_currentPalette = 0;
69
70 TQVBoxLayout *layout = new TQVBoxLayout( this );
71
72 combo = new TQComboBox( false, this );
73 combo->setFocusPolicy( TQWidget::ClickFocus );
74 layout->addWidget(combo);
75
76 m_view = new KisPaletteView(this, 0, minWidth, cols);
77 layout->addWidget( m_view );
78
79 //setFixedSize(sizeHint());
80
81 connect(combo, TQ_SIGNAL(activated(const TQString &)),
82 this, TQ_SLOT(slotSetPalette(const TQString &)));
83 connect(m_view, TQ_SIGNAL(colorSelected(const KisColor &)),
84 this, TQ_SIGNAL(colorSelected(const KisColor &)));
85 connect(m_view, TQ_SIGNAL(colorSelected(const TQColor &)),
86 this, TQ_SIGNAL(colorSelected(const TQColor &)));
87 connect(m_view, TQ_SIGNAL(colorDoubleClicked(const KisColor &, const TQString &)),
88 this, TQ_SIGNAL(colorDoubleClicked(const KisColor &, const TQString &)));
89}
90
91KisPaletteWidget::~KisPaletteWidget()
92{
93}
94
95TQString KisPaletteWidget::palette() const
96{
97 return combo->currentText();
98}
99
100
101// 2000-02-12 Espen Sand
102// Set the color in two steps. The setPalette() slot will not emit a signal
103// with the current color setting. The reason is that setPalette() is used
104// by the color selector dialog on startup. In the color selector dialog
105// we normally want to display a startup color which we specify
106// when the dialog is started. The slotSetPalette() slot below will
107// set the palette and then use the information to emit a signal with the
108// new color setting. It is only used by the combobox widget.
109//
110void KisPaletteWidget::slotSetPalette( const TQString &_paletteName )
111{
112 setPalette( _paletteName );
113 m_view->slotColorCellSelected(0); // FIXME: We need to save the current value!!
114}
115
116
117void KisPaletteWidget::setPalette( const TQString &_paletteName )
118{
119 TQString paletteName( _paletteName);
120
121 m_currentPalette = m_namedPaletteMap[paletteName];
122
123 if (combo->currentText() != paletteName)
124 {
125 bool found = false;
126 for(int i = 0; i < combo->count(); i++)
127 {
128 if (combo->text(i) == paletteName)
129 {
130 combo->setCurrentItem(i);
131 found = true;
132 break;
133 }
134 }
135 if (!found)
136 {
137 combo->insertItem(paletteName);
138 combo->setCurrentItem(combo->count()-1);
139 }
140 }
141
142 m_view->setPalette(m_currentPalette);
143}
144
145void KisPaletteWidget::slotAddPalette(KisResource * palette)
146{
147 KisPalette * p = dynamic_cast<KisPalette*>(palette);
148
149 m_namedPaletteMap.insert(palette->name(), p);
150
151 combo->insertItem(palette->name());
152
153 if (!init) {
154 combo->setCurrentItem(0);
155 setPalette(combo ->currentText());
156 init = true;
157 }
158}
159
160
161#include "kis_palette_widget.moc"
162
A KisColor describes a color in a certain colorspace.
Definition kis_color.h:33
A scrolling view that lists a single KisPalette.
Open Gimp, Photoshop or RIFF palette files.
Definition kis_palette.h:50
The KisResource class provides a representation of Chalk image resources.