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
|
/*
KDE Draw - a small graphics drawing program for the KDE
Copyright (C) 1998 Thomas Tanghus (tanghus@kde.org)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program 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
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.
*/
#include <tqlayout.h>
#include <tqpainter.h>
#include <tqbuttongroup.h>
#include <tqradiobutton.h>
#include <tqpushbutton.h>
#include <kconfig.h>
#include <klocale.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <kdebug.h>
#include <kapplication.h>
#include "knew.h"
KIconTemplateContainer* KIconTemplateContainer::instance = 0;
void createStandardTemplates(KIconTemplateContainer *list)
{
KIconLoader *kil = TDEGlobal::iconLoader();
KIconTemplate it;
it.path = kil->iconPath("standard", KIcon::User);
it.title = i18n("Standard File");
list->append(it);
it.path = kil->iconPath("source", KIcon::User);
it.title = i18n("Source File");
list->append(it);
it.path = kil->iconPath("compressed", KIcon::User);
it.title = i18n("Compressed File");
list->append(it);
it.path = kil->iconPath("folder", KIcon::User);
it.title = i18n("Standard Folder");
list->append(it);
it.path = kil->iconPath("package", KIcon::User);
it.title = i18n("Standard Package");
list->append(it);
it.path = kil->iconPath("mini-folder", KIcon::User);
it.title = i18n("Mini Folder");
list->append(it);
it.path = kil->iconPath("mini-package", KIcon::User);
it.title = i18n("Mini Package");
list->append(it);
}
void KIconTemplateContainer::save()
{
TDEConfig *k = kapp->config();
k->setGroup("Templates");
TQStringList names;
for (TQValueListIterator<KIconTemplate> iter = begin(); iter != end(); iter++)
{
names.append((*iter).title);
}
k->writeEntry("Names", names);
for(unsigned int i = 0; i < names.count(); i++)
{
k->writePathEntry(names[i], (*this)[i].path);
}
}
KIconTemplateContainer::KIconTemplateContainer() : TQValueList<KIconTemplate>()
{
TQStrList names;
TDEConfig *k = kapp->config();
k->setGroup("Templates");
k->readListEntry("Names", names);
for(int i = 0; i < (int)names.count(); i++)
{
KIconTemplate it;
it.path = k->readPathEntry(names.at(i));
it.title = names.at(i);
//kdDebug(4640) << "Template: " << names.at(i) << "\n" << path.data() << endl;
append(it);
}
if(count() == 0)
{
createStandardTemplates(this);
}
}
KIconTemplateContainer::~KIconTemplateContainer()
{
clear();
}
KIconListBoxItem::KIconListBoxItem( KIconTemplate t )
: TQListBoxItem(), icontemplate(t)
{
//kdDebug(4640) << "KIconListBoxItem - " << t->path.data() << ", " << t->title.data() << endl;
pm.load(t.path);
setText( t.title );
}
void KIconListBoxItem::reloadIcon()
{
pm.load(icontemplate.path);
setText( icontemplate.title );
}
void KIconListBoxItem::paint( TQPainter *p )
{
p->drawPixmap( 3, 0, pm );
TQFontMetrics fm = p->fontMetrics();
int yPos; // vertical text position
if ( pm.height() < fm.height() )
yPos = fm.ascent() + fm.leading()/2;
else
yPos = pm.height()/2 - fm.height()/2 + fm.ascent();
p->drawText( pm.width() + 5, yPos, text() );
}
int KIconListBoxItem::height(const TQListBox *lb ) const
{
return TQMAX( pm.height(), lb->fontMetrics().lineSpacing() + 1 );
}
int KIconListBoxItem::width(const TQListBox *lb ) const
{
return pm.width() + lb->fontMetrics().width( text() ) + 6;
}
NewSelect::NewSelect(TQWidget *parent) : TQWidget( parent )
{
wiz = (KWizard*) parent;
grp = new TQButtonGroup( this );
connect( grp, TQT_SIGNAL( clicked( int ) ), TQT_SLOT( buttonClicked( int ) ) );
grp->setExclusive( true );
TQVBoxLayout* ml = new TQVBoxLayout( this );
ml->addWidget( grp, 1 );
//ml->addWidget(grp, 10, AlignLeft);
TQVBoxLayout* l = new TQVBoxLayout( grp, 10 );
rbscratch = new TQRadioButton( i18n( "Create from scratch" ), grp );
l->addWidget( rbscratch, 1 );
//l->addWidget(rbscratch, 5, AlignLeft);
rbtempl = new TQRadioButton( i18n( "Create from template" ), grp );
l->addWidget( rbtempl, 1 );
//l->addWidget(rbtempl, 5, AlignLeft);
//grp->setMinimumSize(grp->childrenRect().size());
grp->setButton( 0 );
}
NewSelect::~NewSelect()
{
}
void NewSelect::buttonClicked(int id)
{
//kdDebug(4640) << "Button: " << id << endl;
emit iconopenstyle(id);
}
NewFromTemplate::NewFromTemplate( TQWidget* parent )
: TQWidget( parent )
{
wiz = (KWizard*) parent;
TQVBoxLayout* ml = new TQVBoxLayout(this);
grp = new TQGroupBox( i18n( "Templates" ), this );
ml->addWidget( grp, 1 );
//ml->addWidget(grp, 10, AlignLeft);
TQHBoxLayout* l = new TQHBoxLayout( grp, 15 );
templates = new KIconListBox( grp );
connect( templates, TQT_SIGNAL( highlighted( int ) ), TQT_SLOT( checkSelection( int ) ) );
l->addWidget( templates );
for( int i = 0; i < (int) KIconTemplateContainer::self()->count(); i++ )
templates->insertItem( new KIconListBoxItem( *KIconTemplateContainer::self()->at( i ) ) );
}
NewFromTemplate::~NewFromTemplate()
{
}
void NewFromTemplate::checkSelection( int )
{
//kdDebug(4640) << "checkSelection(int) " << templates->currentItem() << endl;
if( templates->currentItem() != -1 )
wiz->finishButton()->setEnabled( true );
else
wiz->finishButton()->setEnabled( false );
}
KNewIcon::KNewIcon( TQWidget* parent )
: KWizard( parent, 0, true )
{
//kdDebug(4640) << "KNewIcon" << endl;
setCaption( i18n( "Create New Icon" ) );
resize( 400, 250 );
openstyle = 0;
finishButton()->setEnabled( true );
cancelButton()->setEnabled( true );
nextButton()->setEnabled( false );
select = new NewSelect( this );
connect( select, TQT_SIGNAL( iconopenstyle( int ) ), TQT_SLOT( iconOpenStyle( int ) ) );
scratch = new KResizeWidget( this, 0, TQSize( 32, 32 ) );
// this doesn't accept default valid size, besides spin buttons won't allow
// an invalid size to be set by the user - forces user to change valid default
// size to create the new icon object -
connect( scratch, TQT_SIGNAL( validSize( bool ) ), TQT_SLOT( checkPage( bool ) ) );
connect(this, TQT_SIGNAL(selected(const TQString &)), this, TQT_SLOT(checkPage(const TQString &)));
templ = new NewFromTemplate(this);
templ->hide();
addPage(select, i18n("Select Icon Type"));
addPage(scratch, i18n("Create From Scratch"));
act = scratch;
//addPage(templ, i18n("Create From Template"));
}
KNewIcon::~KNewIcon()
{
delete select;
delete scratch;
delete templ;
}
void KNewIcon::okClicked()
{
if(openstyle == Blank)
emit newicon(scratch->getSize());
else
emit newicon(templ->path());
hide();
setResult(1);
accept();
}
void KNewIcon::cancelClicked()
{
hide();
setResult(0);
reject();
}
void KNewIcon::iconOpenStyle(int style)
{
openstyle = style;
if( act )
removePage( act );
if(openstyle == Blank)
{
act = scratch;
setNextEnabled( act, true );
addPage( scratch, i18n( "Create From Scratch" ) );
}
else if( openstyle == Template )
{
act = templ;
setNextEnabled( act, true );
addPage( templ, i18n( "Create From Template" ) );
}
}
void KNewIcon::checkPage( bool b)
{
//kdDebug(4640) << "checkPage(int) " << openstyle << " " << p << endl;
if(openstyle == Blank)
finishButton()->setEnabled(true);
else if( !b )
finishButton()->setEnabled(false);
else
templ->checkSelection(0);
}
void KNewIcon::checkPage(const TQString &)
{
if(currentPage() == select || openstyle == Blank)
finishButton()->setEnabled(true);
else
finishButton()->setEnabled(false);
}
#include "knew.moc"
|