summaryrefslogtreecommitdiffstats
path: root/krusader/Konfigurator/konfiguratorpage.cpp
blob: 2cd7f7b2d27a0a8e5623a8105070249e47871030 (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
331
332
333
334
/* **************************************************************************
                      konfiguratorpage.cpp  -  description
                             -------------------
    copyright            : (C) 2003 by Csaba Karai
    e-mail               : krusader@users.sourceforge.net
    web site             : http://krusader.sourceforge.net
 ---------------------------------------------------------------------------
  Description
 ***************************************************************************

  A

     db   dD d8888b. db    db .d8888.  .d8b.  d8888b. d88888b d8888b.
     88 ,8P' 88  `8D 88    88 88'  YP d8' `8b 88  `8D 88'     88  `8D
     88,8P   88oobY' 88    88 `8bo.   88ooo88 88   88 88ooooo 88oobY'
     88`8b   88`8b   88    88   `Y8b. 88~~~88 88   88 88~~~~~ 88`8b
     88 `88. 88 `88. 88b  d88 db   8D 88   88 88  .8D 88.     88 `88.
     YP   YD 88   YD ~Y8888P' `8888Y' YP   YP Y8888D' Y88888P 88   YD

                                                     S o u r c e    F i l e

 ***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "konfiguratorpage.h"
#include <tqlayout.h>
#include "../krusader.h"
#include <tqwhatsthis.h>

KonfiguratorPage::KonfiguratorPage( bool firstTime, TQWidget* tqparent,  const char* name ) :
  TQFrame( tqparent, name ), firstCall( firstTime )
{
}

bool KonfiguratorPage::apply()
{
  bool restartNeeded = false;

  KonfiguratorExtension *item = itemList.first();

  while( item )
  {
    restartNeeded = item->apply() || restartNeeded;
    item = itemList.next();
  }

  krConfig->sync();  
  return restartNeeded;
}

void KonfiguratorPage::setDefaults()
{
  KonfiguratorExtension *item = itemList.first();
  int activePage = activeSubPage();

  while( item )
  {
    if( item->subPage() == activePage )
      item->setDefaults();
    item = itemList.next();
  }
}

void KonfiguratorPage::loadInitialValues()
{
  KonfiguratorExtension *item = itemList.first();

  while( item )
  {
    item->loadInitialValue();
    item = itemList.next();
  }
}

bool KonfiguratorPage::isChanged()
{
  KonfiguratorExtension *currentItem = itemList.current();  /* save the current pointer */
  bool isChanged = false;

  KonfiguratorExtension *item = itemList.first();

  while( item )
  {
    isChanged = isChanged || item->isChanged();
    item = itemList.next();
  }

  itemList.tqfind( currentItem );  /* restore the current pointer */
  return isChanged;
}

KonfiguratorCheckBox* KonfiguratorPage::createCheckBox( TQString cls, TQString name,
    bool dflt, TQString text, TQWidget *tqparent, bool rst, TQString toolTip, int pg )
{
  KonfiguratorCheckBox *checkBox = new KonfiguratorCheckBox( cls, name, dflt, text,
                                 tqparent, TQString(cls + "/" + name).ascii(), rst, pg );
  if( !toolTip.isEmpty() )
    TQWhatsThis::add( checkBox, toolTip );
  
  registerObject( checkBox->extension() );
  return checkBox;
}

KonfiguratorSpinBox* KonfiguratorPage::createSpinBox(  TQString cls, TQString name,
    int dflt, int min, int max, TQWidget *tqparent, bool rst, int pg )
{
  KonfiguratorSpinBox *spinBox = new KonfiguratorSpinBox( cls, name, dflt, min, max,
                                 tqparent, TQString(cls + "/" + name).ascii(), rst, pg );

  registerObject( spinBox->extension() );
  return spinBox;
}

KonfiguratorEditBox* KonfiguratorPage::createEditBox(  TQString cls, TQString name,
    TQString dflt, TQWidget *tqparent, bool rst, int pg )
{
  KonfiguratorEditBox *editBox = new KonfiguratorEditBox( cls, name, dflt, tqparent,
                                        TQString(cls + "/" + name).ascii(), rst, pg );

  registerObject( editBox->extension() );
  return editBox;
}

KonfiguratorListBox* KonfiguratorPage::createListBox(  TQString cls, TQString name,
    TQStringList dflt, TQWidget *tqparent, bool rst, int pg )
{
  KonfiguratorListBox *listBox = new KonfiguratorListBox( cls, name, dflt, tqparent,
                                        TQString(cls + "/" + name).ascii(), rst, pg );

  registerObject( listBox->extension() );
  return listBox;
}

KonfiguratorURLRequester* KonfiguratorPage::createURLRequester(  TQString cls, TQString name,
    TQString dflt, TQWidget *tqparent, bool rst, int pg )
{
  KonfiguratorURLRequester *urlRequester = new KonfiguratorURLRequester( cls, name, dflt,
                                        tqparent, TQString(cls + "/" + name).ascii(), rst, pg );

  registerObject( urlRequester->extension() );
  return urlRequester;
}

TQGroupBox* KonfiguratorPage::createFrame( TQString text, TQWidget *tqparent,
                                          const char *widgetName )
{
  TQGroupBox *groupBox = new TQGroupBox( tqparent, widgetName );
  groupBox->setFrameShape( TQGroupBox::Box );
  groupBox->setFrameShadow( TQGroupBox::Sunken );
  if( !text.isNull() )
    groupBox->setTitle( text );
  groupBox->setColumnLayout(0, Qt::Vertical );
  groupBox->tqlayout()->setSpacing( 0 );
  groupBox->tqlayout()->setMargin( 0 );
  return groupBox;
}                                          

TQGridLayout* KonfiguratorPage::createGridLayout( TQLayout *tqparent )
{
  TQGridLayout *gridLayout = new TQGridLayout( tqparent );
  gridLayout->tqsetAlignment( TQt::AlignTop );
  gridLayout->setSpacing( 6 );
  gridLayout->setMargin( 11 );
  return gridLayout;
}

TQLabel* KonfiguratorPage::addLabel( TQGridLayout *tqlayout, int x, int y, TQString label,
                                    TQWidget *tqparent, const char *widgetName )
{
  TQLabel *lbl = new TQLabel( label, tqparent, widgetName );
  tqlayout->addWidget( lbl, x, y );
  return lbl;
}

TQWidget* KonfiguratorPage::createSpacer( TQWidget *tqparent, const char *widgetName )
{
  TQWidget *widget = new TQWidget( tqparent, widgetName );
  TQHBoxLayout *hboxtqlayout = new TQHBoxLayout( widget );
  TQSpacerItem* spacer = new TQSpacerItem( 40, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
  hboxtqlayout->addItem( spacer );
  return widget;
}

KonfiguratorCheckBoxGroup* KonfiguratorPage::createCheckBoxGroup( int sizex, int sizey,
    KONFIGURATOR_CHECKBOX_PARAM *params, int paramNum, TQWidget *tqparent,
    const char *widgetName, int pg )
{
  KonfiguratorCheckBoxGroup *groupWidget = new KonfiguratorCheckBoxGroup( tqparent, widgetName );
  TQGridLayout *tqlayout = new TQGridLayout( groupWidget );
  tqlayout->setSpacing( 6 );
  tqlayout->setMargin( 0 );
  
  int x = 0, y = 0;
  
  for( int i=0; i != paramNum; i++ )
  {
    KonfiguratorCheckBox *checkBox = createCheckBox( params[i].configClass,
      params[i].configName, params[i].defaultValue, params[i].text, groupWidget,
      params[i].restart, params[i].toolTip, pg );

    groupWidget->add( checkBox );
    tqlayout->addWidget( checkBox, y, x );

    if( sizex )
    {
      if( ++x == sizex )
        x = 0, y++;
    }
    else
    {
      if( ++y == sizey )
        y = 0, x++;
    }
  }
  
  return groupWidget;
}

KonfiguratorRadioButtons* KonfiguratorPage::createRadioButtonGroup( TQString cls,
    TQString name, TQString dflt, int sizex, int sizey, KONFIGURATOR_NAME_VALUE_TIP *params,
    int paramNum, TQWidget *tqparent, const char *widgetName, bool rst, int pg )
{
  KonfiguratorRadioButtons *radioWidget = new KonfiguratorRadioButtons( cls, name, dflt, tqparent, widgetName, rst, pg );
  radioWidget->setFrameShape( TQButtonGroup::NoFrame );
  radioWidget->setFrameShadow( TQButtonGroup::Sunken );
  radioWidget->setTitle( "" );
  radioWidget->setExclusive( true );
  radioWidget->setRadioButtonExclusive( true );
  radioWidget->setColumnLayout(0, Qt::Vertical );

  TQGridLayout *tqlayout = new TQGridLayout( radioWidget->tqlayout() );
  tqlayout->tqsetAlignment( TQt::AlignTop );
  tqlayout->setSpacing( 6 );
  tqlayout->setMargin( 0 );

  int x = 0, y = 0;

  for( int i=0; i != paramNum; i++ )
  {
    TQRadioButton *radBtn = new TQRadioButton( params[i].text, radioWidget,
                        TQString( cls + "/" + name + "/" + params[i].value ).ascii() );

    if( !params[i].tooltip.isEmpty() )
      TQWhatsThis::add( radBtn, params[i].tooltip );

    tqlayout->addWidget( radBtn, y, x );

    radioWidget->addRadioButton( radBtn, params[i].text, params[i].value );

    if( sizex )
    {
      if( ++x == sizex )
        x = 0, y++;
    }
    else
    {
      if( ++y == sizey )
        y = 0, x++;
    }
  }

  radioWidget->loadInitialValue();
  registerObject( radioWidget->extension() );  
  return radioWidget;
}

KonfiguratorFontChooser *KonfiguratorPage::createFontChooser( TQString cls, TQString name,
  TQFont *dflt, TQWidget *tqparent, bool rst, int pg )
{
  KonfiguratorFontChooser *fontChooser = new KonfiguratorFontChooser( cls, name, dflt, tqparent,
                                        TQString(cls + "/" + name).ascii(), rst, pg );

  registerObject( fontChooser->extension() );
  return fontChooser;
}

KonfiguratorComboBox *KonfiguratorPage::createComboBox(  TQString cls, TQString name, TQString dflt,
    KONFIGURATOR_NAME_VALUE_PAIR *params, int paramNum, TQWidget *tqparent, bool rst, bool editable, int pg )
{
  KonfiguratorComboBox *comboBox = new KonfiguratorComboBox( cls, name, dflt, params,
                                        paramNum, tqparent, TQString(cls + "/" + name).ascii(),
                                        rst, editable, pg );

  registerObject( comboBox->extension() );
  return comboBox;
}

TQFrame* KonfiguratorPage::createLine( TQWidget *tqparent, const char *widgetName, bool vertical )
{
  TQFrame *line = new TQFrame( tqparent, widgetName );
  line->setFrameStyle( ( vertical ? TQFrame::VLine : TQFrame::HLine ) | TQFrame::Sunken );
  return line;
}

void KonfiguratorPage::registerObject( KonfiguratorExtension *item )
{
  KonfiguratorExtension *currentItem = itemList.current();
  
  itemList.append( item );
  connect( item, TQT_SIGNAL( sigChanged( bool ) ), this, TQT_SIGNAL ( sigChanged( ) ) );

  itemList.tqfind( currentItem );
}

void KonfiguratorPage::removeObject( KonfiguratorExtension *item )
{
  if( item == itemList.current() )
  {
    itemList.remove();
    if( itemList.current() != itemList.getFirst() )
      itemList.prev();
  }
  else
    itemList.removeRef( item );
}

KonfiguratorColorChooser *KonfiguratorPage::createColorChooser( TQString cls, TQString name, TQColor dflt,
                                                                TQWidget *tqparent, bool rst,
                                                                ADDITIONAL_COLOR *addColPtr, int addColNum, int pg )
{
  KonfiguratorColorChooser *colorChooser = new KonfiguratorColorChooser( cls, name, dflt,  tqparent,
                                        TQString(cls + "/" + name).ascii(), rst, addColPtr, addColNum, pg );

  registerObject( colorChooser->extension() );
  return colorChooser;
}

#include "konfiguratorpage.moc"