summaryrefslogtreecommitdiffstats
path: root/karbon/widgets/vtypebuttonbox.cc
blob: 9a98a125ac7eaa872601d78cb04b62fc54e55ac7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/* This file is part of the KDE project
   Copyright (C) 2001, 2002, 2003 The Karbon Developers

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#if 0

// 8x8 pixels

static const char* const buttonnone[]={
"8 8 7 1",
"c c #0a0000",
". c #0a0a0a",
"b c #330000",
"a c #331f1f",
"# c #333333",
"e c #ff0000",
"d c #ffffff",
".####abc",
"#ddddeeb",
"#dddeeea",
"#ddeeed#",
"#deeedd#",
"aeeeddd#",
"beedddd#",
"cba####."};

static const char* const buttonsolid[]={
"8 8 1 1",
". c #000000",
"........",
"........",
"........",
"........",
"........",
"........",
"........",
"........"};

static const char* const buttongradient[]={
"8 8 14 1",
"f c #000000",
"e c #040404",
". c #0a0a0a",
"d c #0f0f0f",
"c c #181818",
"b c #212121",
"a c #292929",
"# c #303030",
"g c #333333",
"l c #484848",
"k c #787878",
"j c #a7a7a7",
"i c #cdcdcd",
"h c #f1f1f1",
".#abcdef",
"ghijkl#f",
"ghijkl#f",
"ghijkl#f",
"ghijkl#f",
"ghijkl#f",
"ghijkl#f",
".#abcdef"};

static const char* const buttonpattern[]={
"8 8 4 1",
". c #0a0a0a",
"# c #333333",
"a c #a0a0a0",
"b c #ffffff",
".######.",
"#aabbaa#",
"#aabbaa#",
"#bbaabb#",
"#bbaabb#",
"#aabbaa#",
"#aabbaa#",
".######."};

#else

// 16x16 pixels

static const char* const buttonnone[]={
"16 16 7 1",
"c c #0a0000",
". c #0a0a0a",
"b c #330000",
"a c #331f1f",
"# c #333333",
"e c #ff0000",
"d c #ffffff",
"..########aabbcc",
"..########aabbcc",
"##dddddddddeeebb",
"##ddddddddeeeebb",
"##dddddddeeeeeaa",
"##ddddddeeeeedaa",
"##dddddeeeeedd##",
"##ddddeeeeeddd##",
"##dddeeeeedddd##",
"##ddeeeeeddddd##",
"aaeeeeeedddddd##",
"aaeeeeeddddddd##",
"bbeeeedddddddd##",
"bbeeeddddddddd##",
"ccbbaa########..",
"ccbbaa########.."};

static const char* const buttonsolid[]={
"16 16 1 1",
". c #000000",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................"};


// FIXME: Smoother gradient button.

static const char* const buttongradient[]={
"16 16 14 1",
"f c #000000",
"e c #040404",
". c #0a0a0a",
"d c #0f0f0f",
"c c #181818",
"b c #212121",
"a c #292929",
"# c #303030",
"g c #333333",
"l c #484848",
"k c #787878",
"j c #a7a7a7",
"i c #cdcdcd",
"h c #f1f1f1",
"..##aabbccddeeff",
"..##aabbccddeeff",
"gghhiijjkkll##ff",
"gghhiijjkkll##ff",
"gghhiijjkkll##ff",
"gghhiijjkkll##ff",
"gghhiijjkkll##ff",
"gghhiijjkkll##ff",
"gghhiijjkkll##ff",
"gghhiijjkkll##ff",
"gghhiijjkkll##ff",
"gghhiijjkkll##ff",
"gghhiijjkkll##ff",
"gghhiijjkkll##ff",
"..##aabbccddeeff",
"..##aabbccddeeff"};

static const char* const buttonpattern[]={
"16 16 4 1",
". c #0a0a0a",
"# c #333333",
"a c #a0a0a0",
"b c #ffffffff",
"..############..",
"..############..",
"##aaaabbbbaaaa##",
"##aaaabbbbaaaa##",
"##aaaabbbbaaaa##",
"##aaaabbbbaaaa##",
"##bbbbaaaabbbb##",
"##bbbbaaaabbbb##",
"##bbbbaaaabbbb##",
"##bbbbaaaabbbb##",
"##aaaabbbbaaaa##",
"##aaaabbbbaaaa##",
"##aaaabbbbaaaa##",
"##aaaabbbbaaaa##",
"..############..",
"..############.."};

#endif


#include <tqpixmap.h>
#include <tqtoolbutton.h>
#include <tqtooltip.h>

#include <tdelocale.h>

#include "karbon_part.h"
#include "vfillcmd.h"
#include "vselection.h"
#include "vstrokecmd.h"

#include "vtypebuttonbox.h"

VTypeButtonBox::VTypeButtonBox( KarbonPart *part, 
								TQWidget* parent, const char* name )
	: TQHButtonGroup( parent, name ),
	  m_part( part ), m_isStrokeManipulator( false )
{
	setMaximumWidth( parent->width() - 2 );

	// The button for no fill
	TQToolButton* button = new TQToolButton( this );
	button->setPixmap( TQPixmap( (const char **) buttonnone ) );
	button->setMaximumWidth( 14 );
	button->setMaximumHeight( 14 );
	TQToolTip::add( button, i18n( "None" ) );
	insert( button, none );

	// The button for solid fill
	button = new TQToolButton( this );
	button->setPixmap( TQPixmap( (const char **) buttonsolid ) );
	button->setMaximumWidth( 14 );
	button->setMaximumHeight( 14 );
	TQToolTip::add( button, i18n( "Solid" ) );
	insert( button, solid );

	// The button for gradient fill
	button = new TQToolButton( this );
	button->setPixmap( TQPixmap( (const char **) buttongradient ) );
	button->setMaximumWidth( 14 );
	button->setMaximumHeight( 14 );
	TQToolTip::add( button, i18n( "Gradient" ) );
	insert( button, gradient );

	// The button for pattern fill
	button = new TQToolButton( this );
	button->setPixmap( TQPixmap( (const char **) buttonpattern ) );
	button->setMaximumWidth( 14 );
	button->setMaximumHeight( 14 );
	TQToolTip::add( button, i18n( "Pattern" ) );
	insert( button, pattern );

	setInsideMargin( 1 );
	setInsideSpacing( 1 );
	connect( this, TQT_SIGNAL( clicked( int ) ),
			 this, TQT_SLOT( slotButtonPressed( int ) ) );
}

void
VTypeButtonBox::slotButtonPressed( int id )
{
	if( m_part && m_part->document().selection()->objects().count() > 0 ) {
		if ( m_isStrokeManipulator )
			manipulateStrokes( id );
		else
			manipulateFills( id );
	}
}

void
VTypeButtonBox::setStroke()
{
	m_isStrokeManipulator = true;
}

void
VTypeButtonBox::setFill()
{
	m_isStrokeManipulator = false;
}

void
VTypeButtonBox::manipulateFills( int id )
{
	VFill m_fill;
	m_fill = *m_part->document().selection()->objects().getFirst()->fill();
	switch( id ){
	case none:
		m_fill.setType( VFill::none );
		break;
	case solid:
		m_fill.setType( VFill::solid );
		break;
	case gradient:
		m_fill.setType( VFill::grad );
		break;
	case pattern:
		m_fill.setType( VFill::patt );
	}
	m_part->addCommand( new VFillCmd( &m_part->document(), m_fill ), true );
}

void
VTypeButtonBox::manipulateStrokes( int id )
{
	VStroke m_stroke;
	m_stroke = *m_part->document().selection()->objects().getFirst()->stroke();
	switch( id ){
	case none:
		m_stroke.setType( VStroke::none );
		break;
	case solid:
		m_stroke.setType( VStroke::solid );
		break;
	case gradient:
		m_stroke.setType( VStroke::grad );
		break;
	case pattern:
		m_stroke.setType( VStroke::patt );
	}
	m_part->addCommand( new VStrokeCmd( &m_part->document(), &m_stroke ), true );
}

#include "vtypebuttonbox.moc"