• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
kcolorcombo.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 1997 Martin Jones (mjones@kde.org)
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library 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 GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19//-----------------------------------------------------------------------------
20// KDE color selection dialog.
21//
22// 1999-09-27 Espen Sand <espensa@online.no>
23// KColorDialog is now subclassed from KDialogBase. I have also extended
24// KColorDialog::getColor() so that in contains a parent argument. This
25// improves centering capability.
26//
27// layout management added Oct 1997 by Mario Weilguni
28// <mweilguni@sime.com>
29//
30
31
32#include <stdio.h>
33#include <stdlib.h>
34
35#include <tqdrawutil.h>
36#include <tqevent.h>
37#include <tqfile.h>
38#include <tqimage.h>
39#include <tqlabel.h>
40#include <tqlayout.h>
41#include <tqlineedit.h>
42#include <tqvalidator.h>
43#include <tqpainter.h>
44#include <tqpushbutton.h>
45#include <tqtimer.h>
46
47#include <tdeapplication.h>
48#include <tdeconfig.h>
49#include <tdeglobal.h>
50#include <tdeglobalsettings.h>
51#include <kiconloader.h>
52#include <tdelistbox.h>
53#include <tdelocale.h>
54#include <tdemessagebox.h>
55#include <kseparator.h>
56#include <kpalette.h>
57#include <kimageeffect.h>
58
59//#include "kcolordialog.h"
60//#include "kcolordrag.h"
61#include "kcolorcombo.h"
62
63// This is repeated from the KColorDlg, but I didn't
64// want to make it public BL.
65// We define it out when compiling with --enable-final in which case
66// we use the version defined in KColorDlg
67
68#ifndef KDE_USE_FINAL
69#define STANDARD_PAL_SIZE 17
70
71static TQColor *standardPalette = 0;
72
73static void createStandardPalette()
74{
75 if ( standardPalette )
76 return;
77
78 standardPalette = new TQColor [STANDARD_PAL_SIZE];
79
80 int i = 0;
81
82 standardPalette[i++] = TQt::red;
83 standardPalette[i++] = TQt::green;
84 standardPalette[i++] = TQt::blue;
85 standardPalette[i++] = TQt::cyan;
86 standardPalette[i++] = TQt::magenta;
87 standardPalette[i++] = TQt::yellow;
88 standardPalette[i++] = TQt::darkRed;
89 standardPalette[i++] = TQt::darkGreen;
90 standardPalette[i++] = TQt::darkBlue;
91 standardPalette[i++] = TQt::darkCyan;
92 standardPalette[i++] = TQt::darkMagenta;
93 standardPalette[i++] = TQt::darkYellow;
94 standardPalette[i++] = TQt::white;
95 standardPalette[i++] = TQt::lightGray;
96 standardPalette[i++] = TQt::gray;
97 standardPalette[i++] = TQt::darkGray;
98 standardPalette[i++] = TQt::black;
99}
100#endif
101
102class KColorCombo::KColorComboPrivate
103{
104 protected:
105 friend class KColorCombo;
106 KColorComboPrivate(){}
107 ~KColorComboPrivate(){}
108 bool showEmptyList;
109};
110
111KColorCombo::KColorCombo( TQWidget *parent, const char *name )
112 : TQComboBox( parent, name )
113{
114 d=new KColorComboPrivate();
115 d->showEmptyList=false;
116
117 customColor.setRgb( 255, 255, 255 );
118 internalcolor.setRgb( 255, 255, 255 );
119
120 createStandardPalette();
121
122 addColors();
123
124 connect( this, TQ_SIGNAL( activated(int) ), TQ_SLOT( slotActivated(int) ) );
125 connect( this, TQ_SIGNAL( highlighted(int) ), TQ_SLOT( slotHighlighted(int) ) );
126}
127
128
129KColorCombo::~KColorCombo()
130{
131 delete d;
132}
136void KColorCombo::setColor( const TQColor &col )
137{
138 internalcolor = col;
139 d->showEmptyList=false;
140 addColors();
141}
142
143
147TQColor KColorCombo::color() const {
148 return internalcolor;
149}
150
151void KColorCombo::resizeEvent( TQResizeEvent *re )
152{
153 TQComboBox::resizeEvent( re );
154
155 addColors();
156}
157
161void KColorCombo::showEmptyList()
162{
163 d->showEmptyList=true;
164 addColors();
165}
166
167void KColorCombo::slotActivated( int index )
168{
169 if ( index == 0 )
170 {
171 if ( KColorDialog::getColor( customColor, this ) == TQDialog::Accepted )
172 {
173 TQPainter painter;
174 TQPen pen;
175 TQRect rect( 0, 0, width(), TQFontMetrics(painter.font()).height()+4);
176 TQPixmap pixmap( rect.width(), rect.height() );
177
178 if ( tqGray( customColor.rgb() ) < 128 )
179 pen.setColor( white );
180 else
181 pen.setColor( black );
182
183 painter.begin( &pixmap );
184 TQBrush brush( customColor );
185 painter.fillRect( rect, brush );
186 painter.setPen( pen );
187 painter.drawText( 2, TQFontMetrics(painter.font()).ascent()+2, i18n("Custom...") );
188 painter.end();
189
190 changeItem( pixmap, 0 );
191 pixmap.detach();
192 }
193
194 internalcolor = customColor;
195 }
196 else
197 internalcolor = standardPalette[ index - 1 ];
198
199 emit activated( internalcolor );
200}
201
202void KColorCombo::slotHighlighted( int index )
203{
204 if ( index == 0 )
205 internalcolor = customColor;
206 else
207 internalcolor = standardPalette[ index - 1 ];
208
209 emit highlighted( internalcolor );
210}
211
212void KColorCombo::addColors()
213{
214 TQPainter painter;
215 TQPen pen;
216 TQRect rect( 0, 0, width(), TQFontMetrics(painter.font()).height()+4 );
217 TQPixmap pixmap( rect.width(), rect.height() );
218 int i;
219
220 clear();
221 if (d->showEmptyList) return;
222
223 createStandardPalette();
224
225 for ( i = 0; i < STANDARD_PAL_SIZE; i++ )
226 if ( standardPalette[i] == internalcolor ) break;
227
228 if ( i == STANDARD_PAL_SIZE )
229 customColor = internalcolor;
230
231 if ( tqGray( customColor.rgb() ) < 128 )
232 pen.setColor( white );
233 else
234 pen.setColor( black );
235
236 painter.begin( &pixmap );
237 TQBrush brush( customColor );
238 painter.fillRect( rect, brush );
239 painter.setPen( pen );
240 painter.drawText( 2, TQFontMetrics(painter.font()).ascent()+2, i18n("Custom...") );
241 painter.end();
242
243 insertItem( pixmap );
244 pixmap.detach();
245
246 for ( i = 0; i < STANDARD_PAL_SIZE; i++ )
247 {
248 painter.begin( &pixmap );
249 TQBrush brush( standardPalette[i] );
250 painter.fillRect( rect, brush );
251 painter.end();
252
253 insertItem( pixmap );
254 pixmap.detach();
255
256 if ( standardPalette[i] == internalcolor )
257 setCurrentItem( i + 1 );
258 }
259}
260
261void KColorCombo::virtual_hook( int, void* )
262{ /*BASE::virtual_hook( id, data );*/ }
263
264#include "kcolorcombo.moc"
KColorCombo
Combobox for colors.
Definition: kcolorcombo.h:40
KColorCombo::showEmptyList
void showEmptyList()
Clear the color list and don't show it, till the next setColor() call.
Definition: kcolorcombo.cpp:161
KColorCombo::setColor
void setColor(const TQColor &col)
Selects the color col.
Definition: kcolorcombo.cpp:136
KColorCombo::highlighted
void highlighted(const TQColor &col)
Emitted when a new item has been highlighted.
KColorCombo::KColorCombo
KColorCombo(TQWidget *parent, const char *name=0L)
Constructs a color combo box.
Definition: kcolorcombo.cpp:111
KColorCombo::color
TQColor color() const
Returns the currently selected color.
Definition: kcolorcombo.cpp:147
KColorCombo::activated
void activated(const TQColor &col)
Emitted when a new color box has been selected.
KColorDialog::getColor
static int getColor(TQColor &theColor, TQWidget *parent=0L)
Creates a modal color dialog, let the user choose a color, and returns when the dialog is closed.
Definition: kcolordialog.cpp:1298
KStdAction::clear
TDEAction * clear(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name)
Clear the content of the focus widget.
Definition: kstdaction.cpp:176
tdelocale.h

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.4
This website is maintained by Timothy Pearson.