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

libtdegames

  • libtdegames
kcarddialog.cpp
1/*
2 This file is part of the TDE games library
3 Copyright (C) 2000 Martin Heni (martin@heni-online.de)
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
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 $Id$
21*/
22
23#include <stdio.h>
24#include <assert.h>
25
26#include <tqgroupbox.h>
27#include <tqlabel.h>
28#include <tqcheckbox.h>
29#include <tqlayout.h>
30#include <tqtooltip.h>
31#include <tqslider.h>
32#include <tqwmatrix.h>
33
34#include <tdeapplication.h>
35#include <tdelocale.h>
36#include <kstandarddirs.h>
37#include <kiconview.h>
38#include <ksimpleconfig.h>
39
40#include "kcarddialog.h"
41#include <tqpushbutton.h>
42#include <kdebug.h>
43
44#define KCARD_DEFAULTDECK TQString::fromLatin1("deck0.png")
45#define KCARD_DEFAULTCARD TQString::fromLatin1("11.png")
46#define KCARD_DEFAULTCARDDIR TQString::fromLatin1("cards-default/")
47
48// values for the resize slider
49#define SLIDER_MIN 400
50#define SLIDER_MAX 3000
51
52// TDEConfig entries
53#define CONF_GROUP "KCardDialog"
54#define CONF_RANDOMDECK TQString::fromLatin1("RandomDeck")
55#define CONF_DECK TQString::fromLatin1("Deck")
56#define CONF_CARDDIR TQString::fromLatin1("CardDir")
57#define CONF_RANDOMCARDDIR TQString::fromLatin1("RandomCardDir")
58#define CONF_USEGLOBALDECK TQString::fromLatin1("GlobalDeck")
59#define CONF_USEGLOBALCARDDIR TQString::fromLatin1("GlobalCardDir")
60#define CONF_SCALE TQString::fromLatin1("Scale")
61
62#define CONF_GLOBAL_GROUP TQString::fromLatin1("KCardDialog Settings")
63#define CONF_GLOBAL_DECK TQString::fromLatin1("GlobalDeck")
64#define CONF_GLOBAL_CARDDIR TQString::fromLatin1("GlobalCardDir")
65#define CONF_GLOBAL_RANDOMDECK TQString::fromLatin1("GlobalRandomDeck")
66#define CONF_GLOBAL_RANDOMCARDDIR TQString::fromLatin1("GlobalRandomCardDir")
67
68
69class KCardDialogPrivate
70{
71public:
72 KCardDialogPrivate()
73 {
74 deckLabel = 0;
75 cardLabel = 0;
76 deckIconView = 0;
77 cardIconView = 0;
78 randomDeck = 0;
79 randomCardDir = 0;
80 cPreview = 0;
81 scaleSlider = 0;
82 globalDeck = 0;
83 globalCardDir = 0;
84
85 cScale = 1;
86 }
87
88 TQLabel* deckLabel;
89 TQLabel* cardLabel;
90 TDEIconView* deckIconView;
91 TDEIconView* cardIconView;
92 TQCheckBox* randomDeck;
93 TQCheckBox* randomCardDir;
94 TQCheckBox* globalDeck;
95 TQCheckBox* globalCardDir;
96
97 TQSlider* scaleSlider;
98 TQPixmap cPreviewPix;
99 TQLabel* cPreview;
100
101 TQMap<TQIconViewItem*, TQString> deckMap;
102 TQMap<TQIconViewItem*, TQString> cardMap;
103 TQMap<TQString, TQString> helpMap;
104
105 //set query variables
106 KCardDialog::CardFlags cFlags;
107 TQString cDeck;
108 TQString cCardDir;
109 double cScale;
110};
111
112int KCardDialog::getCardDeck(TQString &pDeck, TQString &pCardDir, TQWidget *pParent,
113 CardFlags pFlags, bool* pRandomDeck, bool* pRandomCardDir,
114 double* pScale, TDEConfig* pConf)
115{
116 KCardDialog dlg(pParent, "dlg", pFlags);
117
118 dlg.setDeck(pDeck);
119 dlg.setCardDir(pCardDir);
120
121 dlg.setupDialog(pScale != 0);
122 dlg.loadConfig(pConf);
123 dlg.showRandomDeckBox(pRandomDeck != 0);
124 dlg.showRandomCardDirBox(pRandomCardDir != 0);
125 int result=dlg.exec();
126 if (result==TQDialog::Accepted)
127 {
128 // TODO check for global cards/decks!!!!
129 pDeck=dlg.deck();
130 pCardDir=dlg.cardDir();
131 if (!pCardDir.isNull() && pCardDir.right(1)!=TQString::fromLatin1("/"))
132 {
133 pCardDir+=TQString::fromLatin1("/");
134 }
135 if (pRandomDeck)
136 {
137 *pRandomDeck = dlg.isRandomDeck();
138 }
139 if (pRandomCardDir)
140 {
141 *pRandomCardDir = dlg.isRandomCardDir();
142 }
143 if (pScale)
144 {
145 *pScale = dlg.cardScale();
146 }
147
148 if (dlg.isGlobalDeck())
149 {
150 kdDebug(11000) << "use global deck" << endl;
151 bool random;
152 getGlobalDeck(pDeck, random);
153 kdDebug(11000) << "use: " << pDeck<< endl;
154 if (pRandomDeck)
155 {
156 *pRandomDeck=random;
157 if (random)
158 kdDebug(11000) << "use random deck" << endl;
159 }
160 }
161 if (dlg.isGlobalCardDir())
162 {
163 kdDebug(11000) << "use global carddir" << endl;
164 bool random;
165 getGlobalCardDir(pCardDir, random);
166 kdDebug(11000) << "use: " << pCardDir << endl;
167 if (pRandomCardDir)
168 {
169 *pRandomCardDir=random;
170 if (random)
171 kdDebug(11000) << "use random carddir" << endl;
172 }
173 }
174 }
175 dlg.saveConfig(pConf);
176 return result;
177}
178
179void KCardDialog::getConfigCardDeck(TDEConfig* conf, TQString &pDeck, TQString &pCardDir, double& pScale)
180{
181// TODO check for global cards/decks!!!!
182 if (!conf) {
183 return;
184 }
185 TQString origGroup = conf->group();
186
187 conf->setGroup(CONF_GROUP);
188 if (conf->readBoolEntry(CONF_RANDOMDECK) || !conf->hasKey(CONF_DECK)) {
189 pDeck = getRandomDeck();
190 } else {
191 pDeck = conf->readEntry(CONF_DECK);
192 }
193 if (conf->readBoolEntry(CONF_RANDOMCARDDIR) || !conf->hasKey(CONF_CARDDIR)) {
194 pCardDir = getRandomCardDir();
195 } else {
196 pCardDir = conf->readPathEntry(CONF_CARDDIR);
197 }
198 pScale = conf->readDoubleNumEntry(CONF_SCALE, 1.0);
199
200 if (conf->readBoolEntry(CONF_USEGLOBALDECK, false)) {
201 bool random;
202 getGlobalDeck(pCardDir, random);
203 if (random || pDeck.isNull() ) {
204 pDeck = getRandomDeck();
205 }
206 }
207 if (conf->readBoolEntry(CONF_USEGLOBALCARDDIR, false)) {
208 bool random;
209 getGlobalCardDir(pCardDir, random);
210 if (random || pCardDir.isNull() ) {
211 pCardDir = getRandomCardDir();
212 }
213 }
214
215 conf->setGroup(origGroup);
216}
217
218TQString KCardDialog::getDefaultDeck()
219{
220 KCardDialog::init();
221 return locate("cards", TQString::fromLatin1("decks/") + KCARD_DEFAULTDECK);
222}
223
224TQString KCardDialog::getDefaultCardDir()
225{
226 KCardDialog::init();
227
228 TQString file = KCARD_DEFAULTCARDDIR + KCARD_DEFAULTCARD;
229 return TDEGlobal::dirs()->findResourceDir("cards",file) + KCARD_DEFAULTCARDDIR;
230}
231
232TQString KCardDialog::getCardPath(const TQString &carddir, int index)
233{
234 KCardDialog::init();
235
236 TQString entry = carddir + TQString::number(index);
237 if (TDEStandardDirs::exists(entry + TQString::fromLatin1(".png")))
238 return entry + TQString::fromLatin1(".png");
239
240 // rather theoretical
241 if (TDEStandardDirs::exists(entry + TQString::fromLatin1(".xpm")))
242 return entry + TQString::fromLatin1(".xpm");
243
244 return TQString();
245}
246
247const TQString& KCardDialog::deck() const { return d->cDeck; }
248void KCardDialog::setDeck(const TQString& file) { d->cDeck=file; }
249const TQString& KCardDialog::cardDir() const { return d->cCardDir; }
250void KCardDialog::setCardDir(const TQString& dir) { d->cCardDir=dir; }
251KCardDialog::CardFlags KCardDialog::flags() const { return d->cFlags; }
252double KCardDialog::cardScale() const { return d->cScale; }
253bool KCardDialog::isRandomDeck() const
254{ return (d->randomDeck ? d->randomDeck->isChecked() : false); }
255bool KCardDialog::isRandomCardDir() const
256{ return (d->randomCardDir ? d->randomCardDir->isChecked() : false); }
257bool KCardDialog::isGlobalDeck() const
258{ return (d->globalDeck ? d->globalDeck->isChecked() : false); }
259bool KCardDialog::isGlobalCardDir() const
260{ return (d->globalCardDir ? d->globalCardDir->isChecked() : false); }
261
262void KCardDialog::setupDialog(bool showResizeBox)
263{
264 TQHBoxLayout* topLayout = new TQHBoxLayout(plainPage(), spacingHint());
265 TQVBoxLayout* cardLayout = new TQVBoxLayout(topLayout);
266 TQString path, file;
267 TQWMatrix m;
268 m.scale(0.8,0.8);
269
270 setInitialSize(TQSize(600,400));
271
272 if (! (flags() & NoDeck))
273 {
274 TQHBoxLayout* layout = new TQHBoxLayout(cardLayout);
275
276 // Deck iconview
277 TQGroupBox* grp1 = new TQGroupBox(1,TQt::Horizontal, i18n("Choose Backside"), plainPage());
278 layout->addWidget(grp1);
279
280 d->deckIconView = new TDEIconView(grp1,"decks");
281 d->deckIconView->setSpacing(8);
282 /*
283 deckIconView->setGridX(-1);
284 deckIconView->setGridY(50);
285 */
286 d->deckIconView->setGridX(82);
287 d->deckIconView->setGridY(106);
288 d->deckIconView->setSelectionMode(TQIconView::Single);
289 d->deckIconView->setResizeMode(TQIconView::Adjust);
290 d->deckIconView->setMinimumWidth(360);
291 d->deckIconView->setMinimumHeight(170);
292 d->deckIconView->setWordWrapIconText(false);
293 d->deckIconView->showToolTips();
294
295 // deck select
296 TQVBoxLayout* l = new TQVBoxLayout(layout);
297 TQGroupBox* grp3 = new TQGroupBox(i18n("Backside"), plainPage());
298 grp3->setFixedSize(100, 130);
299 l->addWidget(grp3, 0, AlignTop|AlignHCenter);
300 d->deckLabel = new TQLabel(grp3);
301 d->deckLabel->setText(i18n("empty"));
302 d->deckLabel->setAlignment(AlignHCenter|AlignVCenter);
303 d->deckLabel->setGeometry(10, 20, 80, 90);
304
305 d->randomDeck = new TQCheckBox(plainPage());
306 d->randomDeck->setChecked(false);
307 connect(d->randomDeck, TQ_SIGNAL(toggled(bool)), this,
308 TQ_SLOT(slotRandomDeckToggled(bool)));
309 d->randomDeck->setText(i18n("Random backside"));
310 l->addWidget(d->randomDeck, 0, AlignTop|AlignHCenter);
311
312 d->globalDeck = new TQCheckBox(plainPage());
313 d->globalDeck->setChecked(false);
314 d->globalDeck->setText(i18n("Use global backside"));
315 l->addWidget(d->globalDeck, 0, AlignTop|AlignHCenter);
316
317 TQPushButton* b = new TQPushButton(i18n("Make Backside Global"), plainPage());
318 connect(b, TQ_SIGNAL(pressed()), this, TQ_SLOT(slotSetGlobalDeck()));
319 l->addWidget(b, 0, AlignTop|AlignHCenter);
320
321 connect(d->deckIconView,TQ_SIGNAL(clicked(TQIconViewItem *)),
322 this,TQ_SLOT(slotDeckClicked(TQIconViewItem *)));
323 }
324
325 if (! (flags() & NoCards))
326 {
327 // Cards iconview
328 TQHBoxLayout* layout = new TQHBoxLayout(cardLayout);
329 TQGroupBox* grp2 = new TQGroupBox(1,TQt::Horizontal, i18n("Choose Frontside"), plainPage());
330 layout->addWidget(grp2);
331
332 d->cardIconView =new TDEIconView(grp2,"cards");
333 /*
334 cardIconView->setGridX(36);
335 cardIconView->setGridY(50);
336 */
337 d->cardIconView->setGridX(82);
338 d->cardIconView->setGridY(106);
339 d->cardIconView->setResizeMode(TQIconView::Adjust);
340 d->cardIconView->setMinimumWidth(360);
341 d->cardIconView->setMinimumHeight(170);
342 d->cardIconView->setWordWrapIconText(false);
343 d->cardIconView->showToolTips();
344
345 // Card select
346 TQVBoxLayout* l = new TQVBoxLayout(layout);
347 TQGroupBox* grp4 = new TQGroupBox(i18n("Frontside"), plainPage());
348 grp4->setFixedSize(100, 130);
349 l->addWidget(grp4, 0, AlignTop|AlignHCenter);
350 d->cardLabel = new TQLabel(grp4);
351 d->cardLabel->setText(i18n("empty"));
352 d->cardLabel->setAlignment(AlignHCenter|AlignVCenter);
353 d->cardLabel->setGeometry(10, 20, 80, 90 );
354
355 d->randomCardDir = new TQCheckBox(plainPage());
356 d->randomCardDir->setChecked(false);
357 connect(d->randomCardDir, TQ_SIGNAL(toggled(bool)), this,
358 TQ_SLOT(slotRandomCardDirToggled(bool)));
359 d->randomCardDir->setText(i18n("Random frontside"));
360 l->addWidget(d->randomCardDir, 0, AlignTop|AlignHCenter);
361
362 d->globalCardDir = new TQCheckBox(plainPage());
363 d->globalCardDir->setChecked(false);
364 d->globalCardDir->setText(i18n("Use global frontside"));
365 l->addWidget(d->globalCardDir, 0, AlignTop|AlignHCenter);
366
367 TQPushButton* b = new TQPushButton(i18n("Make Frontside Global"), plainPage());
368 connect(b, TQ_SIGNAL(pressed()), this, TQ_SLOT(slotSetGlobalCardDir()));
369 l->addWidget(b, 0, AlignTop|AlignHCenter);
370
371 connect(d->cardIconView,TQ_SIGNAL(clicked(TQIconViewItem *)),
372 this,TQ_SLOT(slotCardClicked(TQIconViewItem *)));
373 }
374
375 // Insert deck icons
376 // First find the default or alternate path
377 if (! (flags() & NoDeck))
378 {
379 insertDeckIcons();
380 d->deckIconView->arrangeItemsInGrid();
381
382 // Set default icons if given
383 if (!deck().isNull())
384 {
385 file=deck();
386 TQPixmap pixmap(file);
387 pixmap=pixmap.xForm(m);
388 d->deckLabel->setPixmap(pixmap);
389 TQToolTip::add(d->deckLabel,d->helpMap[file]);
390 }
391 }
392
393 // Insert card icons
394 if (! (flags() & NoCards))
395 {
396 insertCardIcons();
397 d->cardIconView->arrangeItemsInGrid();
398
399 // Set default icons if given
400 if (!cardDir().isNull())
401 {
402 file = cardDir() + KCARD_DEFAULTCARD;
403 TQPixmap pixmap(file);
404 pixmap = pixmap.xForm(m);
405 d->cardLabel->setPixmap(pixmap);
406 TQToolTip::add(d->cardLabel,d->helpMap[cardDir()]);
407 }
408 }
409
410 // insert resize box
411 if (showResizeBox)
412 {
413 // this part is a little bit...tricky.
414 // i'm sure there is a cleaner way but i cannot find it.
415 // whenever the pixmap is resized (aka scaled) the box is resized, too. This
416 // leads to an always resizing dialog which is *very* ugly. i worked around
417 // this by using a TQWidget which is the only child widget of the group box.
418 // The other widget are managed inside this TQWidget - a stretch area on the
419 // right ensures that the TDEIconViews are not resized...
420
421 // note that the dialog is still resized if you you scale the pixmap very
422 // large. This is desired behaviour as i don't want to make the box even
423 // larger but i want the complete pixmap to be displayed. the dialog is not
424 // resized if you make the pixmap smaller again.
425 TQVBoxLayout* layout = new TQVBoxLayout(topLayout);
426 TQGroupBox* grp = new TQGroupBox(1,TQt::Horizontal, i18n("Resize Cards"), plainPage());
427 layout->setResizeMode(TQLayout::Fixed);
428 layout->addWidget(grp);
429 TQWidget* box = new TQWidget(grp);
430 TQHBoxLayout* hbox = new TQHBoxLayout(box, 0, spacingHint());
431 TQVBoxLayout* boxLayout = new TQVBoxLayout(hbox);
432 hbox->addStretch(0);
433
434 d->scaleSlider = new TQSlider(1, SLIDER_MAX, 1, (-1000+SLIDER_MIN+SLIDER_MAX),TQt::Horizontal, box);
435 d->scaleSlider->setMinValue(SLIDER_MIN);
436 connect(d->scaleSlider, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(slotCardResized(int)));
437 boxLayout->addWidget(d->scaleSlider, 0, AlignLeft);
438
439 TQPushButton* b = new TQPushButton(i18n("Default Size"), box);
440 connect(b, TQ_SIGNAL(pressed()), this, TQ_SLOT(slotDefaultSize()));
441 boxLayout->addWidget(b, 0, AlignLeft);
442
443 TQLabel* l = new TQLabel(i18n("Preview:"), box);
444 boxLayout->addWidget(l);
445 d->cPreviewPix.load(getDefaultDeck());
446 d->cPreview = new TQLabel(box);
447 boxLayout->addWidget(d->cPreview, 0, AlignCenter|AlignVCenter);
448
449 slotCardResized(d->scaleSlider->value());
450 }
451}
452
453void KCardDialog::insertCardIcons()
454{
455 TQStringList list = TDEGlobal::dirs()->findAllResources("cards", "card*/index.desktop", false, true);
456 // kdDebug(11000) << "insert " << list.count() << endl;
457 if (list.isEmpty())
458 return;
459
460 // We shrink the icons a little
461 //
462 TQWMatrix m;
463 m.scale(0.8,0.8);
464
465 for (TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it)
466 {
467 KSimpleConfig cfg(*it);
468 cfg.setGroup(TQString::fromLatin1("KDE Backdeck"));
469 TQString path = (*it).left((*it).findRev('/') + 1);
470 assert(path[path.length() - 1] == '/');
471 TQPixmap pixmap(path + cfg.readEntry("Preview", "12c.png"));
472
473 if (pixmap.isNull())
474 continue;
475
476 TQString name=cfg.readEntry("Name", i18n("unnamed"));
477 TQIconViewItem *item= new TQIconViewItem(d->cardIconView, name, pixmap);
478
479 item->setDragEnabled(false);
480 item->setDropEnabled(false);
481 item->setRenameEnabled(false);
482 item->setSelectable(true);
483
484 d->cardMap[item] = path;
485 d->helpMap[path] = cfg.readEntry("Comment",name);
486 }
487}
488
489void KCardDialog::insertDeckIcons()
490{
491 TQStringList list = TDEGlobal::dirs()->findAllResources("cards", "decks/*.desktop", false, true);
492 if (list.isEmpty())
493 return;
494
495 TQString label;
496
497 // We shrink the icons a little
498 TQWMatrix m;
499 m.scale(0.8,0.8);
500
501 for (TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it)
502 {
503 KSimpleConfig cfg(*it);
504 TQPixmap pixmap(getDeckName(*it));
505 if (pixmap.isNull())
506 continue;
507
508 // pixmap=pixmap.xForm(m);
509
510 cfg.setGroup(TQString::fromLatin1("KDE Cards"));
511 TQString name=cfg.readEntry("Name", i18n("unnamed"));
512 TQIconViewItem *item= new TQIconViewItem(d->deckIconView,name, pixmap);
513
514 item->setDragEnabled(false);
515 item->setDropEnabled(false);
516 item->setRenameEnabled(false);
517
518 d->deckMap[item] = getDeckName(*it);
519 d->helpMap[d->deckMap[item]] = cfg.readEntry("Comment",name);
520 }
521}
522
523
524KCardDialog::~KCardDialog()
525{
526 delete d;
527}
528
529
530// Create the dialog
531KCardDialog::KCardDialog( TQWidget *parent, const char *name, CardFlags mFlags)
532 : KDialogBase( Plain, i18n("Carddeck Selection"), Ok|Cancel, Ok, parent, name, true, true)
533{
534 KCardDialog::init();
535
536 d = new KCardDialogPrivate;
537 d->cFlags = mFlags;
538}
539
540void KCardDialog::slotDeckClicked(TQIconViewItem *item)
541{
542 if (item && item->pixmap())
543 {
544 d->deckLabel->setPixmap(* (item->pixmap()));
545 TQToolTip::remove( d->deckLabel );
546 TQToolTip::add(d->deckLabel,d->helpMap[d->deckMap[item]]);
547 setDeck(d->deckMap[item]);
548 }
549}
550void KCardDialog::slotCardClicked(TQIconViewItem *item)
551{
552 if (item && item->pixmap())
553 {
554 d->cardLabel->setPixmap(* (item->pixmap()));
555 TQString path = d->cardMap[item];
556 TQToolTip::remove( d->deckLabel );
557 TQToolTip::add(d->cardLabel,d->helpMap[path]);
558 setCardDir(path);
559 }
560}
561
562TQString KCardDialog::getDeckName(const TQString &desktop)
563{
564 TQString entry = desktop.left(desktop.length() - strlen(".desktop"));
565 if (TDEStandardDirs::exists(entry + TQString::fromLatin1(".png")))
566 return entry + TQString::fromLatin1(".png");
567
568 // rather theoretical
569 if (TDEStandardDirs::exists(entry + TQString::fromLatin1(".xpm")))
570 return entry + TQString::fromLatin1(".xpm");
571 return TQString();
572}
573
574TQString KCardDialog::getRandomDeck()
575{
576 KCardDialog::init();
577
578 TQStringList list = TDEGlobal::dirs()->findAllResources("cards", "decks/*.desktop");
579 if (list.isEmpty())
580 return TQString();
581
582 int d = TDEApplication::random() % list.count();
583 return getDeckName(*list.at(d));
584}
585
586TQString KCardDialog::getRandomCardDir()
587{
588 KCardDialog::init();
589
590 TQStringList list = TDEGlobal::dirs()->findAllResources("cards", "card*/index.desktop");
591 if (list.isEmpty())
592 return TQString();
593
594 int d = TDEApplication::random() % list.count();
595 TQString entry = *list.at(d);
596 return entry.left(entry.length() - strlen("index.desktop"));
597}
598
599void KCardDialog::showRandomDeckBox(bool s)
600{
601 if (!d->randomDeck)
602 return;
603
604 if (s)
605 d->randomDeck->show();
606 else
607 d->randomDeck->hide();
608}
609
610void KCardDialog::showRandomCardDirBox(bool s)
611{
612 if (!d->randomCardDir)
613 return;
614
615 if (s)
616 d->randomCardDir->show();
617 else
618 d->randomCardDir->hide();
619}
620
621void KCardDialog::slotRandomDeckToggled(bool on)
622{
623 if (on) {
624 d->deckLabel->setText("random");
625 setDeck(getRandomDeck());
626 } else {
627 d->deckLabel->setText("empty");
628 setDeck(0);
629 }
630}
631
632void KCardDialog::slotRandomCardDirToggled(bool on)
633{
634 if (on) {
635 d->cardLabel->setText("random");
636 setCardDir(getRandomCardDir());
637 if (cardDir().length()>0 && cardDir().right(1)!=TQString::fromLatin1("/")) {
638 setCardDir(cardDir() + TQString::fromLatin1("/"));
639 }
640 } else {
641 d->cardLabel->setText("empty");
642 setCardDir(0);
643 }
644}
645
646void KCardDialog::loadConfig(TDEConfig* conf)
647{
648 if (!conf) {
649 return;
650 }
651
652 TQString origGroup = conf->group();
653
654 conf->setGroup(CONF_GROUP);
655 if (! (flags() & NoDeck)) {
656 if (conf->hasKey(CONF_DECK)) {
657 setDeck(conf->readEntry(CONF_DECK));
658 }
659
660 bool random = conf->readBoolEntry(CONF_RANDOMDECK, false);
661 d->randomDeck->setChecked(random);
662 slotRandomDeckToggled(random);
663
664 if (conf->hasKey(CONF_USEGLOBALDECK) && conf->readBoolEntry(CONF_USEGLOBALDECK)) {
665 d->globalDeck->setChecked(true);
666 } else {
667 d->globalDeck->setChecked(false);
668 }
669 }
670 if (! (flags() & NoCards)) {
671 if (conf->hasKey(CONF_CARDDIR)) {
672 setCardDir(conf->readPathEntry(CONF_CARDDIR));
673 }
674
675 bool random = conf->readBoolEntry(CONF_RANDOMCARDDIR, false);
676 d->randomCardDir->setChecked(random);
677 slotRandomCardDirToggled(random);
678
679 if (conf->hasKey(CONF_USEGLOBALCARDDIR) && conf->readBoolEntry(CONF_USEGLOBALCARDDIR)) {
680 d->globalCardDir->setChecked(true);
681 } else {
682 d->globalCardDir->setChecked(false);
683 }
684 }
685
686 d->cScale = conf->readDoubleNumEntry(CONF_SCALE, 1.0);
687
688 conf->setGroup(origGroup);
689}
690
691void KCardDialog::slotCardResized(int s)
692{
693 if (!d->cPreview) {
694 return;
695 }
696 if (s < SLIDER_MIN || s > SLIDER_MAX) {
697 kdError(11000) << "invalid scaling value!" << endl;
698 return;
699 }
700
701 s *= -1;
702 s += (SLIDER_MIN + SLIDER_MAX);
703
704 TQWMatrix m;
705 double scale = (double)1000/s;
706 m.scale(scale, scale);
707 TQPixmap pix = d->cPreviewPix.xForm(m);
708 d->cPreview->setPixmap(pix);
709 d->cScale = scale;
710}
711
712void KCardDialog::slotDefaultSize()
713{
714 if (!d->scaleSlider) {
715 return;
716 }
717 d->scaleSlider->setValue(-1000 + SLIDER_MIN + SLIDER_MAX);
718}
719
720void KCardDialog::saveConfig(TDEConfig* conf)
721{
722 if (!conf) {
723 return;
724 }
725 TQString origGroup = conf->group();
726
727 conf->setGroup(CONF_GROUP);
728 if (! (flags() & NoDeck)) {
729 conf->writeEntry(CONF_DECK, deck());
730 conf->writeEntry(CONF_RANDOMDECK, isRandomDeck());
731 conf->writeEntry(CONF_USEGLOBALDECK, d->globalDeck->isChecked());
732 }
733 if (! (flags() & NoCards)) {
734 conf->writePathEntry(CONF_CARDDIR, cardDir());
735 conf->writeEntry(CONF_RANDOMCARDDIR, isRandomCardDir());
736 conf->writeEntry(CONF_USEGLOBALCARDDIR, d->globalCardDir->isChecked());
737 }
738 conf->writeEntry(CONF_SCALE, d->cScale);
739
740 conf->setGroup(origGroup);
741}
742
743void KCardDialog::slotSetGlobalDeck()
744{
745 KSimpleConfig* conf = new KSimpleConfig(TQString::fromLatin1("kdeglobals"), false);
746 conf->setGroup(CONF_GLOBAL_GROUP);
747
748 conf->writeEntry(CONF_GLOBAL_DECK, deck());
749 conf->writeEntry(CONF_GLOBAL_RANDOMDECK, isRandomDeck());
750
751 delete conf;
752}
753
754void KCardDialog::slotSetGlobalCardDir()
755{
756 KSimpleConfig* conf = new KSimpleConfig(TQString::fromLatin1("kdeglobals"), false);
757 conf->setGroup(CONF_GLOBAL_GROUP);
758
759 conf->writePathEntry(CONF_GLOBAL_CARDDIR, cardDir());
760 conf->writeEntry(CONF_GLOBAL_RANDOMCARDDIR, isRandomCardDir());
761
762 delete conf;
763}
764
765void KCardDialog::getGlobalDeck(TQString& deck, bool& random)
766{
767 KSimpleConfig* conf = new KSimpleConfig(TQString::fromLatin1("kdeglobals"), true);
768 conf->setGroup(CONF_GLOBAL_GROUP);
769
770 if (!conf->hasKey(CONF_GLOBAL_DECK) || conf->readBoolEntry(CONF_GLOBAL_RANDOMDECK, false)) {
771 deck = getRandomDeck();
772 random = true;
773 } else {
774 deck = conf->readEntry(CONF_GLOBAL_DECK);
775 random = conf->readBoolEntry(CONF_GLOBAL_RANDOMDECK, false);
776 }
777
778 delete conf;
779}
780
781void KCardDialog::getGlobalCardDir(TQString& dir, bool& random)
782{
783 KSimpleConfig* conf = new KSimpleConfig(TQString::fromLatin1("kdeglobals"), true);
784 conf->setGroup(CONF_GLOBAL_GROUP);
785
786 if (!conf->hasKey(CONF_GLOBAL_CARDDIR) || conf->readBoolEntry(CONF_GLOBAL_RANDOMCARDDIR, false)) {
787 dir = getRandomCardDir();
788 random = true;
789 } else {
790 dir = conf->readPathEntry(CONF_GLOBAL_CARDDIR);
791 random = conf->readBoolEntry(CONF_GLOBAL_RANDOMCARDDIR, false);
792 }
793
794 delete conf;
795}
796
797void KCardDialog::init()
798{
799 static bool _inited = false;
800 if (_inited)
801 return;
802 TDEGlobal::dirs()->addResourceType("cards", TDEStandardDirs::kde_default("data") + TQString::fromLatin1("carddecks/"));
803
804 TDEGlobal::locale()->insertCatalogue("libtdegames");
805 _inited = true;
806}
807
808#include "kcarddialog.moc"
KCardDialog
A carddeck selection dialog for card games.
Definition: kcarddialog.h:91
KCardDialog::KCardDialog
KCardDialog(TQWidget *parent=NULL, const char *name=NULL, CardFlags flags=Both)
Constructs a card deck selection dialog.
Definition: kcarddialog.cpp:531
KCardDialog::getConfigCardDeck
static void getConfigCardDeck(TDEConfig *conf, TQString &deck, TQString &cardDir, double &scale)
Read the configuration from the applications rc file and put the previously chosen deck/frontside in ...
Definition: kcarddialog.cpp:179
KCardDialog::setCardDir
void setCardDir(const TQString &dir)
Sets the default card directory.
Definition: kcarddialog.cpp:250
KCardDialog::flags
CardFlags flags() const
Definition: kcarddialog.cpp:251
KCardDialog::isRandomCardDir
bool isRandomCardDir() const
Definition: kcarddialog.cpp:255
KCardDialog::CardFlags
CardFlags
Definition: kcarddialog.h:102
KCardDialog::getDefaultCardDir
static TQString getDefaultCardDir()
Returns the default path to the card frontsides.
Definition: kcarddialog.cpp:224
KCardDialog::deck
const TQString & deck() const
Returns the chosen deck, which is a valid path to a imagefile.
Definition: kcarddialog.cpp:247
KCardDialog::saveConfig
void saveConfig(TDEConfig *conf)
Saves the KCardDialog config into a config file.
Definition: kcarddialog.cpp:720
KCardDialog::showRandomDeckBox
void showRandomDeckBox(bool s)
Show or hides the "random backside" checkbox.
Definition: kcarddialog.cpp:599
KCardDialog::setupDialog
void setupDialog(bool showResizeBox=false)
Creates the default widgets in the dialog.
Definition: kcarddialog.cpp:262
KCardDialog::getRandomCardDir
static TQString getRandomCardDir()
Returns a random directory of cards.
Definition: kcarddialog.cpp:586
KCardDialog::showRandomCardDirBox
void showRandomCardDirBox(bool s)
Show or hides the "random foreside" checkbox.
Definition: kcarddialog.cpp:610
KCardDialog::cardDir
const TQString & cardDir() const
Definition: kcarddialog.cpp:249
KCardDialog::cardScale
double cardScale() const
Definition: kcarddialog.cpp:252
KCardDialog::loadConfig
void loadConfig(TDEConfig *conf)
Load the default settings into the dialog (e.g.
Definition: kcarddialog.cpp:646
KCardDialog::getDefaultDeck
static TQString getDefaultDeck()
Returns the default path to the card deck backsides.
Definition: kcarddialog.cpp:218
KCardDialog::getCardDeck
static int getCardDeck(TQString &deck, TQString &carddir, TQWidget *parent=0, CardFlags flags=Both, bool *randomDeck=0, bool *randomCardDir=0, double *scale=0, TDEConfig *conf=0)
Creates a modal carddeck dialog, lets the user choose a deck, and returns when the dialog is closed.
Definition: kcarddialog.cpp:112
KCardDialog::getRandomDeck
static TQString getRandomDeck()
Returns a random deck in deckPath()
Definition: kcarddialog.cpp:574
KCardDialog::isRandomDeck
bool isRandomDeck() const
Definition: kcarddialog.cpp:253
KCardDialog::isGlobalDeck
bool isGlobalDeck() const
Definition: kcarddialog.cpp:257
KCardDialog::setDeck
void setDeck(const TQString &file)
Sets the default deck.
Definition: kcarddialog.cpp:248
KCardDialog::isGlobalCardDir
bool isGlobalCardDir() const
Definition: kcarddialog.cpp:259
KCardDialog::getCardPath
static TQString getCardPath(const TQString &carddir, int index)
Returns the path to the card frontside specified in dir carddir.
Definition: kcarddialog.cpp:232
KCardDialog::~KCardDialog
~KCardDialog()
Destructs a card deck selection dialog.
Definition: kcarddialog.cpp:524

libtdegames

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

libtdegames

Skip menu "libtdegames"
  • libtdegames
Generated for libtdegames by doxygen 1.9.4
This website is maintained by Timothy Pearson.