chalk

kis_palette_view.cpp
1/*
2 * Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
3 * (c) 2005 Bart Coppens <kde@bartcoppens.be>
4 *
5 * Based on already much changed code by Waldo Bastian <bastian@kde.org> from KisPaletteWidget
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22#include <stdio.h>
23#include <stdlib.h>
24
25#include <tqcheckbox.h>
26#include <tqcombobox.h>
27#include <tqdrawutil.h>
28#include <tqevent.h>
29#include <tqfile.h>
30#include <tqimage.h>
31#include <tqlabel.h>
32#include <tqlayout.h>
33#include <tqlineedit.h>
34#include <tqvalidator.h>
35#include <tqpainter.h>
36#include <tqpushbutton.h>
37#include <tqspinbox.h>
38#include <tqtimer.h>
39
40#include <tdeapplication.h>
41#include <tdeconfig.h>
42#include <tdeglobal.h>
43#include <tdeglobalsettings.h>
44#include <kiconloader.h>
45#include <tdelistbox.h>
46#include <tdelocale.h>
47#include <tdemessagebox.h>
48#include <kseparator.h>
49#include <kpalette.h>
50#include <kimageeffect.h>
51
52#include <kcolordialog.h>
53#include <kcolordrag.h>
54#include <config.h>
55#include <kdebug.h>
56
57#include <kis_meta_registry.h>
58#include <kis_color.h>
59#include <kis_factory.h>
60#include <kis_colorspace_factory_registry.h>
61#include "kis_palette_view.h"
62#include "kis_resource.h"
63#include "kis_palette.h"
64
65KisPaletteView::KisPaletteView(TQWidget *parent, const char* name, int minWidth, int cols)
66 : TQScrollView( parent, name ), mMinWidth(minWidth), mCols(cols)
67{
68 m_cells = 0;
69 m_currentPalette = 0;
70
71 TQSize cellSize = TQSize( mMinWidth, 50);
72
73 setHScrollBarMode(TQScrollView::AlwaysOff);
74 setVScrollBarMode(TQScrollView::AlwaysOn);
75
76 TQSize minSize = TQSize(verticalScrollBar()->width(), 0);
77 minSize += TQSize(frameWidth(), 0);
78 minSize += TQSize(cellSize);
79
80 setMinimumSize(minSize);
81 setSizePolicy(TQSizePolicy(TQSizePolicy::Ignored, TQSizePolicy::Ignored));
82}
83
84KisPaletteView::~KisPaletteView()
85{
86}
87
88KisPalette* KisPaletteView::palette() const
89{
90 return m_currentPalette;
91}
92
93void KisPaletteView::setPalette(KisPalette* palette)
94{
95 m_currentPalette = palette;
96 delete m_cells;
97
98 int rows = (m_currentPalette->nColors() + mCols -1 ) / mCols;
99
100 if (rows < 1) rows = 1;
101
102 m_cells = new KColorCells(viewport(), rows, mCols);
103 TQ_CHECK_PTR(m_cells);
104
105 m_cells->setShading(false);
106 m_cells->setAcceptDrags(false);
107
108 TQSize cellSize = TQSize( mMinWidth, mMinWidth * rows / mCols);
109 m_cells->setFixedSize( cellSize );
110
111 for( int i = 0; i < m_currentPalette->nColors(); i++)
112 {
113 TQColor c = m_currentPalette->getColor(i).color;
114 m_cells->setColor( i, c );
115 }
116
117 connect(m_cells, TQ_SIGNAL(colorSelected(int)),
118 TQ_SLOT(slotColorCellSelected(int)));
119
120 connect(m_cells, TQ_SIGNAL(colorDoubleClicked(int)),
121 TQ_SLOT(slotColorCellDoubleClicked(int)) );
122
123 addChild( m_cells );
124 m_cells->show();
125 updateScrollBars();
126}
127
128void KisPaletteView::slotColorCellSelected( int col )
129{
130 KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getRGB8();
131 if (!m_currentPalette || (col >= m_currentPalette->nColors()))
132 return;
133
134 m_currentEntry = m_currentPalette->getColor(col);
135 emit colorSelected(KisColor(m_currentPalette->getColor(col).color, cs));
136 emit colorSelected(m_currentPalette->getColor(col).color);
137}
138
139void KisPaletteView::slotColorCellDoubleClicked( int col )
140{
141 KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getRGB8();
142 if (!m_currentPalette || (col >= m_currentPalette->nColors()))
143 return;
144
145 emit colorDoubleClicked(KisColor(m_currentPalette->getColor(col).color, cs),
146 m_currentPalette->getColor(col).name);
147}
148
149#include "kis_palette_view.moc"
150
KisColorSpace * getRGB8()
Convenience method to get an RGB colorspace with the default lcms profile.
Open Gimp, Photoshop or RIFF palette files.
Definition kis_palette.h:50