ICSAPI::parseVerbose is now used instead of VariantInfo::getVerboseMove.
[tagua.git] / src / pref_preferences.cpp
blob6495dfcf2195622c01ca183cc3dbc49436393c66
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #include <QApplication>
12 #include <QHBoxLayout>
13 #include <kicon.h>
14 #include "mastersettings.h"
15 #include "pref_board.h"
16 #include "pref_movelist.h"
17 #include "pref_theme.h"
18 #include "pref_engines.h"
19 #include "pref_preferences.h"
21 template<typename T>
22 class PrefWrapper : public PrefBase {
23 private:
24 T* m_inner;
25 QString m_variant;
26 public:
27 PrefWrapper(const QString currentVariant, QWidget *parent = 0)
28 : PrefBase(parent)
29 , m_inner(0)
30 , m_variant(currentVariant) { }
32 virtual void apply() {
33 if (m_inner)
34 m_inner->apply();
37 virtual void showEvent(QShowEvent*) {
38 if (m_inner)
39 return;
41 m_inner = new T(m_variant, this);
42 QHBoxLayout *l = new QHBoxLayout(this);
43 l->addWidget(m_inner);
44 m_inner->show();
49 Preferences::Preferences(const QString& currentVariant, QWidget *parent)
50 : QDialog(parent) {
52 setupUi(this);
53 setWindowIcon(KIcon("tagua"));
54 connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply()));
56 pagePref->hide();
57 PrefBase *b;
58 KPageWidgetItem *i;
60 b = new PrefWrapper<PrefBoard>(currentVariant, this);
61 connect(this, SIGNAL(applied()), b, SLOT(apply()));
62 i = pagePref->addPage(b, "Board");
63 i->setHeader("Board preferences:");
64 i->setIcon(KIcon("prefBoard"));
66 b = new PrefWrapper<PrefMoveList>(currentVariant, this);
67 connect(this, SIGNAL(applied()), b, SLOT(apply()));
68 i = pagePref->addPage(b, "Move list");
69 i->setHeader("Move list preferences:");
70 i->setIcon(KIcon("prefMoveList"));
72 b = new PrefWrapper<PrefTheme>(currentVariant, this);
73 connect(this, SIGNAL(applied()), b, SLOT(apply()));
74 i = pagePref->addPage(b, "Theme");
75 i->setHeader("Pieces & squares theme:");
76 i->setIcon(KIcon("prefTheme"));
77 pagePref->show();
79 b = new PrefWrapper<PrefEngines>(currentVariant, this);
80 connect(this, SIGNAL(applied()), b, SLOT(apply()));
81 i = pagePref->addPage(b, "Engines");
82 i->setHeader("Engines:");
83 i->setIcon(KIcon("brain"));
84 pagePref->show();
87 Preferences::~Preferences() {
90 void Preferences::apply() {
91 applied();
92 settings().changed();