karbon

vtypebuttonbox.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001, 2002, 2003 The Karbon Developers
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#if 0
21
22// 8x8 pixels
23
24static const char* const buttonnone[]={
25"8 8 7 1",
26"c c #0a0000",
27". c #0a0a0a",
28"b c #330000",
29"a c #331f1f",
30"# c #333333",
31"e c #ff0000",
32"d c #ffffff",
33".####abc",
34"#ddddeeb",
35"#dddeeea",
36"#ddeeed#",
37"#deeedd#",
38"aeeeddd#",
39"beedddd#",
40"cba####."};
41
42static const char* const buttonsolid[]={
43"8 8 1 1",
44". c #000000",
45"........",
46"........",
47"........",
48"........",
49"........",
50"........",
51"........",
52"........"};
53
54static const char* const buttongradient[]={
55"8 8 14 1",
56"f c #000000",
57"e c #040404",
58". c #0a0a0a",
59"d c #0f0f0f",
60"c c #181818",
61"b c #212121",
62"a c #292929",
63"# c #303030",
64"g c #333333",
65"l c #484848",
66"k c #787878",
67"j c #a7a7a7",
68"i c #cdcdcd",
69"h c #f1f1f1",
70".#abcdef",
71"ghijkl#f",
72"ghijkl#f",
73"ghijkl#f",
74"ghijkl#f",
75"ghijkl#f",
76"ghijkl#f",
77".#abcdef"};
78
79static const char* const buttonpattern[]={
80"8 8 4 1",
81". c #0a0a0a",
82"# c #333333",
83"a c #a0a0a0",
84"b c #ffffff",
85".######.",
86"#aabbaa#",
87"#aabbaa#",
88"#bbaabb#",
89"#bbaabb#",
90"#aabbaa#",
91"#aabbaa#",
92".######."};
93
94#else
95
96// 16x16 pixels
97
98static const char* const buttonnone[]={
99"16 16 7 1",
100"c c #0a0000",
101". c #0a0a0a",
102"b c #330000",
103"a c #331f1f",
104"# c #333333",
105"e c #ff0000",
106"d c #ffffff",
107"..########aabbcc",
108"..########aabbcc",
109"##dddddddddeeebb",
110"##ddddddddeeeebb",
111"##dddddddeeeeeaa",
112"##ddddddeeeeedaa",
113"##dddddeeeeedd##",
114"##ddddeeeeeddd##",
115"##dddeeeeedddd##",
116"##ddeeeeeddddd##",
117"aaeeeeeedddddd##",
118"aaeeeeeddddddd##",
119"bbeeeedddddddd##",
120"bbeeeddddddddd##",
121"ccbbaa########..",
122"ccbbaa########.."};
123
124static const char* const buttonsolid[]={
125"16 16 1 1",
126". c #000000",
127"................",
128"................",
129"................",
130"................",
131"................",
132"................",
133"................",
134"................",
135"................",
136"................",
137"................",
138"................",
139"................",
140"................",
141"................",
142"................"};
143
144
145// FIXME: Smoother gradient button.
146
147static const char* const buttongradient[]={
148"16 16 14 1",
149"f c #000000",
150"e c #040404",
151". c #0a0a0a",
152"d c #0f0f0f",
153"c c #181818",
154"b c #212121",
155"a c #292929",
156"# c #303030",
157"g c #333333",
158"l c #484848",
159"k c #787878",
160"j c #a7a7a7",
161"i c #cdcdcd",
162"h c #f1f1f1",
163"..##aabbccddeeff",
164"..##aabbccddeeff",
165"gghhiijjkkll##ff",
166"gghhiijjkkll##ff",
167"gghhiijjkkll##ff",
168"gghhiijjkkll##ff",
169"gghhiijjkkll##ff",
170"gghhiijjkkll##ff",
171"gghhiijjkkll##ff",
172"gghhiijjkkll##ff",
173"gghhiijjkkll##ff",
174"gghhiijjkkll##ff",
175"gghhiijjkkll##ff",
176"gghhiijjkkll##ff",
177"..##aabbccddeeff",
178"..##aabbccddeeff"};
179
180static const char* const buttonpattern[]={
181"16 16 4 1",
182". c #0a0a0a",
183"# c #333333",
184"a c #a0a0a0",
185"b c #ffffffff",
186"..############..",
187"..############..",
188"##aaaabbbbaaaa##",
189"##aaaabbbbaaaa##",
190"##aaaabbbbaaaa##",
191"##aaaabbbbaaaa##",
192"##bbbbaaaabbbb##",
193"##bbbbaaaabbbb##",
194"##bbbbaaaabbbb##",
195"##bbbbaaaabbbb##",
196"##aaaabbbbaaaa##",
197"##aaaabbbbaaaa##",
198"##aaaabbbbaaaa##",
199"##aaaabbbbaaaa##",
200"..############..",
201"..############.."};
202
203#endif
204
205
206#include <tqpixmap.h>
207#include <tqtoolbutton.h>
208#include <tqtooltip.h>
209
210#include <tdelocale.h>
211
212#include "karbon_part.h"
213#include "vfillcmd.h"
214#include "vselection.h"
215#include "vstrokecmd.h"
216
217#include "vtypebuttonbox.h"
218
219VTypeButtonBox::VTypeButtonBox( KarbonPart *part,
220 TQWidget* parent, const char* name )
221 : TQHButtonGroup( parent, name ),
222 m_part( part ), m_isStrokeManipulator( false )
223{
224 setMaximumWidth( parent->width() - 2 );
225
226 // The button for no fill
227 TQToolButton* button = new TQToolButton( this );
228 button->setPixmap( TQPixmap( (const char **) buttonnone ) );
229 button->setMaximumWidth( 14 );
230 button->setMaximumHeight( 14 );
231 TQToolTip::add( button, i18n( "None" ) );
232 insert( button, none );
233
234 // The button for solid fill
235 button = new TQToolButton( this );
236 button->setPixmap( TQPixmap( (const char **) buttonsolid ) );
237 button->setMaximumWidth( 14 );
238 button->setMaximumHeight( 14 );
239 TQToolTip::add( button, i18n( "Solid" ) );
240 insert( button, solid );
241
242 // The button for gradient fill
243 button = new TQToolButton( this );
244 button->setPixmap( TQPixmap( (const char **) buttongradient ) );
245 button->setMaximumWidth( 14 );
246 button->setMaximumHeight( 14 );
247 TQToolTip::add( button, i18n( "Gradient" ) );
248 insert( button, gradient );
249
250 // The button for pattern fill
251 button = new TQToolButton( this );
252 button->setPixmap( TQPixmap( (const char **) buttonpattern ) );
253 button->setMaximumWidth( 14 );
254 button->setMaximumHeight( 14 );
255 TQToolTip::add( button, i18n( "Pattern" ) );
256 insert( button, pattern );
257
258 setInsideMargin( 1 );
259 setInsideSpacing( 1 );
260 connect( this, TQ_SIGNAL( clicked( int ) ),
261 this, TQ_SLOT( slotButtonPressed( int ) ) );
262}
263
264void
265VTypeButtonBox::slotButtonPressed( int id )
266{
267 if( m_part && m_part->document().selection()->objects().count() > 0 ) {
268 if ( m_isStrokeManipulator )
269 manipulateStrokes( id );
270 else
271 manipulateFills( id );
272 }
273}
274
275void
276VTypeButtonBox::setStroke()
277{
278 m_isStrokeManipulator = true;
279}
280
281void
282VTypeButtonBox::setFill()
283{
284 m_isStrokeManipulator = false;
285}
286
287void
288VTypeButtonBox::manipulateFills( int id )
289{
290 VFill m_fill;
291 m_fill = *m_part->document().selection()->objects().getFirst()->fill();
292 switch( id ){
293 case none:
294 m_fill.setType( VFill::none );
295 break;
296 case solid:
297 m_fill.setType( VFill::solid );
298 break;
299 case gradient:
300 m_fill.setType( VFill::grad );
301 break;
302 case pattern:
303 m_fill.setType( VFill::patt );
304 }
305 m_part->addCommand( new VFillCmd( &m_part->document(), m_fill ), true );
306}
307
308void
309VTypeButtonBox::manipulateStrokes( int id )
310{
311 VStroke m_stroke;
312 m_stroke = *m_part->document().selection()->objects().getFirst()->stroke();
313 switch( id ){
314 case none:
315 m_stroke.setType( VStroke::none );
316 break;
317 case solid:
318 m_stroke.setType( VStroke::solid );
319 break;
320 case gradient:
321 m_stroke.setType( VStroke::grad );
322 break;
323 case pattern:
324 m_stroke.setType( VStroke::patt );
325 }
326 m_part->addCommand( new VStrokeCmd( &m_part->document(), &m_stroke ), true );
327}
328
329#include "vtypebuttonbox.moc"
330
Keeps track of visual per document properties.
Definition karbon_part.h:46
@ solid
no fill at all
Definition vfill.h:50
@ grad
solid fill
Definition vfill.h:51
@ patt
gradient fill
Definition vfill.h:52
@ patt
gradient as stroke
Definition vstroke.h:56
@ grad
solid stroke
Definition vstroke.h:55
@ solid
no stroke at all
Definition vstroke.h:54