summaryrefslogtreecommitdiffstats
path: root/client/config/polyesterconfig.cpp
blob: 4075c22d90fffe1eb2e1697ea1920a138431b301 (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
//////////////////////////////////////////////////////////////////////////////
// polyesterconfig.cc
// -------------------
// Config module for Polyester window decoration
// -------------------
// Copyright (c) 2005 Marco Martin
// -------------------
// derived from Smooth Blend
// Copyright (c) 2005 Ryan Nickell
// Please see the header file for copyright and license information.
//////////////////////////////////////////////////////////////////////////////

#include <tdeconfig.h>
#include <tdelocale.h>
#include <tdeglobal.h>
#include <tqbuttongroup.h>
#include <tqgroupbox.h>
#include <tqradiobutton.h>
#include <tqcheckbox.h>
#include <tqspinbox.h>
#include <tqwhatsthis.h>
#include <tqcombobox.h>

#include "polyesterconfig.h"
#include "configdialog.h"

//////////////////////////////////////////////////////////////////////////////
// polyesterConfig()
// -------------
// Constructor

polyesterConfig::polyesterConfig(TDEConfig* config, TQWidget* parent)
        : TQObject(parent), config_(0), dialog_(0) {
    // create the configuration object
    config_ = new TDEConfig("twinpolyesterrc");
    TDEGlobal::locale()->insertCatalogue("polyester");

    // create and show the configuration dialog
    dialog_ = new ConfigDialog(parent);

    dialog_->show();
    // load the configuration
    load(config_);

    // setup the connections for title align
    connect(dialog_->titlealign, TQ_SIGNAL(clicked(int)),this, TQ_SLOT(selectionChanged(int)));
    // setup the connections for corner rounding
    connect(dialog_->roundCorners, TQ_SIGNAL(stateChanged(int)),this,TQ_SLOT(selectionChanged(int)));
    connect(dialog_->titleBarStyle, TQ_SIGNAL(activated(int)),this,TQ_SLOT(selectionChanged(int)));
    connect(dialog_->buttonStyle, TQ_SIGNAL(activated(int)),this,TQ_SLOT(selectionChanged(int)));
    // setup title shadow
    connect(dialog_->titleshadow, TQ_SIGNAL(stateChanged(int)),this,TQ_SLOT(selectionChanged(int)));
    // setup button actions
    connect(dialog_->animatebuttons, TQ_SIGNAL(stateChanged(int)),this,TQ_SLOT(selectionChanged(int)));
    connect(dialog_->nomodalbuttons, TQ_SIGNAL(stateChanged(int)),this,TQ_SLOT(selectionChanged(int)));
    connect(dialog_->btnComboBox, TQ_SIGNAL(activated(int)),this,TQ_SLOT(selectionChanged(int)));
    connect(dialog_->lightBorder, TQ_SIGNAL(stateChanged(int)),this,TQ_SLOT(selectionChanged(int)));
    // setup the connections for spin boxes
    connect(dialog_->titlesize, TQ_SIGNAL(valueChanged(int)),this,TQ_SLOT(selectionChanged(int)));
    connect(dialog_->buttonsize, TQ_SIGNAL(valueChanged(int)),this,TQ_SLOT(selectionChanged(int)));
    connect(dialog_->framesize, TQ_SIGNAL(valueChanged(int)),this,TQ_SLOT(selectionChanged(int)));
    connect(dialog_->squareButton, TQ_SIGNAL(stateChanged(int)),this,TQ_SLOT(selectionChanged(int)));
    // double click the menu 
    connect(dialog_->menuClose, TQ_SIGNAL(stateChanged(int)),this, TQ_SLOT(selectionChanged(int)));
}

//////////////////////////////////////////////////////////////////////////////
// ~polyesterConfig()
// --------------
// Destructor

polyesterConfig::~polyesterConfig() {
    if (dialog_)
    {
        delete dialog_;
    }
    if (config_)
    {
        delete config_;
    }
}

//////////////////////////////////////////////////////////////////////////////
// selectionChanged()
// ------------------
// Selection has changed

void polyesterConfig::selectionChanged(int) {

    if(dialog_->buttonsize->value() + dialog_->framesize->value() > dialog_->titlesize->value())
    {
        dialog_->buttonsize->setValue(dialog_->titlesize->value()- dialog_->framesize->value());
    }
    // setting the framesize to less than 2 will lose the top gradient and look flat
   /* if(dialog_->framesize->value() < 2)
    {
        dialog_->framesize->setValue(2);
    }*/
    emit changed();
}

//////////////////////////////////////////////////////////////////////////////
// load()
// ------
// Load configuration data

void polyesterConfig::load(TDEConfig*) {
    config_->setGroup("General");

    TQString value = config_->readEntry("TitleAlignment", "AlignHCenter");
    TQRadioButton *button = (TQRadioButton*)dialog_->titlealign->child(value.local8Bit());
    if (button)
    {
        button->setChecked(true);
    }

    dialog_->titlesize->setValue( config_->readNumEntry("TitleSize",20 ) );
    dialog_->buttonsize->setValue( config_->readNumEntry("ButtonSize",18 ) );
    dialog_->squareButton->setChecked( config_->readBoolEntry("SquareButton", false ) );
    dialog_->framesize->setValue( config_->readNumEntry("FrameSize",2 ) );

    bool cornersFlag = config_->readBoolEntry("RoundCorners", true);
    dialog_->roundCorners->setChecked( cornersFlag );
    bool titleshadow = config_->readBoolEntry("TitleShadow", true);
    dialog_->titleshadow->setChecked(titleshadow);
    bool animatebuttons = config_->readBoolEntry("AnimateButtons", true);
    dialog_->animatebuttons->setChecked(animatebuttons);
    bool lightBorder = config_->readBoolEntry("LightBorder", true);
    dialog_->lightBorder->setChecked(lightBorder);
    dialog_->titleBarStyle->setCurrentItem(config_->readNumEntry("TitleBarStyle",0));
    dialog_->buttonStyle->setCurrentItem(config_->readNumEntry("ButtonStyle",1));
    bool nomodalbuttons = config_->readBoolEntry("NoModalButtons", false);
    dialog_->nomodalbuttons->setChecked(nomodalbuttons);
    dialog_->btnComboBox->setCurrentItem(config_->readNumEntry("ButtonComboBox",0));
    bool menuClose = config_->readBoolEntry("CloseOnMenuDoubleClick");
    dialog_->menuClose->setChecked(menuClose);
}

//////////////////////////////////////////////////////////////////////////////
// save()
// ------
// Save configuration data

void polyesterConfig::save(TDEConfig*) {
    config_->setGroup("General");

    TQRadioButton *button = (TQRadioButton*)dialog_->titlealign->selected();
    if (button)
    {
        config_->writeEntry("TitleAlignment", TQString(button->name()));
    }
    config_->writeEntry("RoundCorners", dialog_->roundCorners->isChecked() );
    config_->writeEntry("TitleSize", dialog_->titlesize->value() );
    config_->writeEntry("ButtonSize", dialog_->buttonsize->value() );
    config_->writeEntry("SquareButton", dialog_->squareButton->isChecked() );
    config_->writeEntry("FrameSize", dialog_->framesize->value() );
    config_->writeEntry("TitleShadow", dialog_->titleshadow->isChecked() );
    config_->writeEntry("TitleBarStyle", dialog_->titleBarStyle->currentItem());
    config_->writeEntry("ButtonStyle", dialog_->buttonStyle->currentItem());
    config_->writeEntry("AnimateButtons", dialog_->animatebuttons->isChecked() );
    config_->writeEntry("LightBorder", dialog_->lightBorder->isChecked() );
    config_->writeEntry("NoModalButtons", dialog_->nomodalbuttons->isChecked() );
    config_->writeEntry("ButtonComboBox", dialog_->btnComboBox->currentItem());
    config_->writeEntry("CloseOnMenuDoubleClick", dialog_->menuClose->isChecked() );

    config_->sync();
}

//////////////////////////////////////////////////////////////////////////////
// defaults()
// ----------
// Set configuration defaults

void polyesterConfig::defaults() {
    TQRadioButton *button = (TQRadioButton*)dialog_->titlealign->child("AlignHCenter");
    if (button)
    {
        button->setChecked(true);
    }
    dialog_->roundCorners->setChecked( true );
    dialog_->titlesize->setValue( 20 );
    dialog_->squareButton->setChecked( false );
    dialog_->buttonsize->setValue( 18 );
    dialog_->framesize->setValue( 2 );
    dialog_->titleBarStyle->setCurrentItem( 0 );
    dialog_->buttonStyle->setCurrentItem( 1 );
    dialog_->titleshadow->setChecked( true );
    dialog_->animatebuttons->setChecked( true );
    dialog_->nomodalbuttons->setChecked( true );
    dialog_->lightBorder->setChecked( true );
    dialog_->btnComboBox->setCurrentItem( 0 );
    dialog_->menuClose->setChecked( false );
}

//////////////////////////////////////////////////////////////////////////////
// Plugin Stuff                                                             //
//////////////////////////////////////////////////////////////////////////////

extern "C" {
    TDE_EXPORT TQObject* allocate_config(TDEConfig* config, TQWidget* parent) {
        return (new polyesterConfig(config, parent));
    }
}

#include "polyesterconfig.moc"