~ubuntu-branches/ubuntu/vivid/krusader/vivid-proposed

« back to all changes in this revision

Viewing changes to krusader/Konfigurator/konfiguratorpage.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-05-05 22:26:37 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505222637-ydv3cwjwy365on2r
Tags: 1:2.1.0~beta1-1ubuntu1
* Merge from Debian Unstable.  Remaining changes:
  - Retain Kubuntu doc path

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 ***************************************************************************/
30
30
 
31
31
#include "konfiguratorpage.h"
32
 
#include <qlayout.h>
 
32
#include <QtGui/QLayout>
33
33
#include <QHBoxLayout>
34
34
#include <QGridLayout>
35
35
#include <QScrollArea>
36
36
#include <QLabel>
37
37
#include "../krusader.h"
38
38
 
39
 
KonfiguratorPage::KonfiguratorPage( bool firstTime, QWidget* parent ) :
40
 
  QScrollArea( parent ), firstCall( firstTime )
 
39
KonfiguratorPage::KonfiguratorPage(bool firstTime, QWidget* parent) :
 
40
        QScrollArea(parent), firstCall(firstTime)
41
41
{
42
 
  setFrameStyle( QFrame::NoFrame );
 
42
    setFrameStyle(QFrame::NoFrame);
43
43
}
44
44
 
45
45
bool KonfiguratorPage::apply()
46
46
{
47
 
  bool restartNeeded = false;
48
 
 
49
 
  for( QList<KonfiguratorExtension *>::iterator item = itemList.begin(); item != itemList.end(); item ++ )
50
 
    restartNeeded = (*item)->apply() || restartNeeded;
51
 
 
52
 
  krConfig->sync();
53
 
  return restartNeeded;
 
47
    bool restartNeeded = false;
 
48
 
 
49
    for (QList<KonfiguratorExtension *>::iterator item = itemList.begin(); item != itemList.end(); item ++)
 
50
        restartNeeded = (*item)->apply() || restartNeeded;
 
51
 
 
52
    krConfig->sync();
 
53
    return restartNeeded;
54
54
}
55
55
 
56
56
void KonfiguratorPage::setDefaults()
57
57
{
58
 
  int activePage = activeSubPage();
 
58
    int activePage = activeSubPage();
59
59
 
60
 
  for( QList<KonfiguratorExtension *>::iterator item = itemList.begin(); item != itemList.end(); item ++ )
61
 
  {
62
 
    if( (*item)->subPage() == activePage )
63
 
      (*item)->setDefaults();
64
 
  }
 
60
    for (QList<KonfiguratorExtension *>::iterator item = itemList.begin(); item != itemList.end(); item ++) {
 
61
        if ((*item)->subPage() == activePage)
 
62
            (*item)->setDefaults();
 
63
    }
65
64
}
66
65
 
67
66
void KonfiguratorPage::loadInitialValues()
68
67
{
69
 
  for( QList<KonfiguratorExtension *>::iterator item = itemList.begin(); item != itemList.end(); item ++ )
70
 
    (*item)->loadInitialValue();
 
68
    for (QList<KonfiguratorExtension *>::iterator item = itemList.begin(); item != itemList.end(); item ++)
 
69
        (*item)->loadInitialValue();
71
70
}
72
71
 
73
72
bool KonfiguratorPage::isChanged()
74
73
{
75
 
  bool isChanged = false;
76
 
 
77
 
  for( QList<KonfiguratorExtension *>::iterator item = itemList.begin(); item != itemList.end(); item ++ )
78
 
    isChanged = isChanged || (*item)->isChanged();
79
 
 
80
 
  return isChanged;
81
 
}
82
 
 
83
 
KonfiguratorCheckBox* KonfiguratorPage::createCheckBox( QString cls, QString name,
84
 
    bool dflt, QString text, QWidget *parent, bool rst, QString toolTip, int pg )
85
 
{
86
 
  KonfiguratorCheckBox *checkBox = new KonfiguratorCheckBox( cls, name, dflt, text,
87
 
                                 parent, rst, pg );
88
 
  if( !toolTip.isEmpty() )
89
 
    checkBox->setWhatsThis( toolTip );
90
 
  
91
 
  registerObject( checkBox->extension() );
92
 
  return checkBox;
93
 
}
94
 
 
95
 
KonfiguratorSpinBox* KonfiguratorPage::createSpinBox(  QString cls, QString name,
96
 
    int dflt, int min, int max, QWidget *parent, bool rst, int pg )
97
 
{
98
 
  KonfiguratorSpinBox *spinBox = new KonfiguratorSpinBox( cls, name, dflt, min, max,
99
 
                                 parent, rst, pg );
100
 
 
101
 
  registerObject( spinBox->extension() );
102
 
  return spinBox;
103
 
}
104
 
 
105
 
KonfiguratorEditBox* KonfiguratorPage::createEditBox(  QString cls, QString name,
106
 
    QString dflt, QWidget *parent, bool rst, int pg )
107
 
{
108
 
  KonfiguratorEditBox *editBox = new KonfiguratorEditBox( cls, name, dflt, parent,
109
 
                                        rst, pg );
110
 
 
111
 
  registerObject( editBox->extension() );
112
 
  return editBox;
113
 
}
114
 
 
115
 
KonfiguratorListBox* KonfiguratorPage::createListBox(  QString cls, QString name,
116
 
    QStringList dflt, QWidget *parent, bool rst, int pg )
117
 
{
118
 
  KonfiguratorListBox *listBox = new KonfiguratorListBox( cls, name, dflt, parent,
119
 
                                        rst, pg );
120
 
 
121
 
  registerObject( listBox->extension() );
122
 
  return listBox;
123
 
}
124
 
 
125
 
KonfiguratorURLRequester* KonfiguratorPage::createURLRequester(  QString cls, QString name,
126
 
    QString dflt, QWidget *parent, bool rst, int pg )
127
 
{
128
 
  KonfiguratorURLRequester *urlRequester = new KonfiguratorURLRequester( cls, name, dflt,
129
 
                                        parent, rst, pg );
130
 
 
131
 
  registerObject( urlRequester->extension() );
132
 
  return urlRequester;
133
 
}
134
 
 
135
 
QGroupBox* KonfiguratorPage::createFrame( QString text, QWidget *parent )
136
 
{
137
 
  QGroupBox *groupBox = new QGroupBox( parent );
138
 
  if( !text.isNull() )
139
 
    groupBox->setTitle( text );
140
 
  return groupBox;
141
 
}
142
 
 
143
 
QGridLayout* KonfiguratorPage::createGridLayout( QWidget *parent )
144
 
{
145
 
  QGridLayout *gridLayout = new QGridLayout( parent );
146
 
  gridLayout->setAlignment( Qt::AlignTop );
147
 
  gridLayout->setSpacing( 6 );
148
 
  gridLayout->setContentsMargins( 11, 11, 11, 11 );
149
 
  return gridLayout;
150
 
}
151
 
 
152
 
QLabel* KonfiguratorPage::addLabel( QGridLayout *layout, int x, int y, QString label,
153
 
                                    QWidget *parent )
154
 
{
155
 
  QLabel *lbl = new QLabel( label, parent );
156
 
  layout->addWidget( lbl, x, y );
157
 
  return lbl;
158
 
}
159
 
 
160
 
QWidget* KonfiguratorPage::createSpacer( QWidget *parent )
161
 
{
162
 
  QWidget *widget = new QWidget( parent );
163
 
  QHBoxLayout *hboxlayout = new QHBoxLayout( widget );
164
 
  QSpacerItem* spacer = new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
165
 
  hboxlayout->addItem( spacer );
166
 
  return widget;
167
 
}
168
 
 
169
 
KonfiguratorCheckBoxGroup* KonfiguratorPage::createCheckBoxGroup( int sizex, int sizey,
170
 
    KONFIGURATOR_CHECKBOX_PARAM *params, int paramNum, QWidget *parent,
171
 
    int pg )
172
 
{
173
 
  KonfiguratorCheckBoxGroup *groupWidget = new KonfiguratorCheckBoxGroup( parent );
174
 
  QGridLayout *layout = new QGridLayout( groupWidget );
175
 
  layout->setSpacing( 6 );
176
 
  layout->setContentsMargins( 0, 0, 0, 0 );
177
 
  
178
 
  int x = 0, y = 0;
179
 
  
180
 
  for( int i=0; i != paramNum; i++ )
181
 
  {
182
 
    KonfiguratorCheckBox *checkBox = createCheckBox( params[i].configClass,
183
 
      params[i].configName, params[i].defaultValue, params[i].text, groupWidget,
184
 
      params[i].restart, params[i].toolTip, pg );
185
 
 
186
 
    groupWidget->add( checkBox );
187
 
    layout->addWidget( checkBox, y, x );
188
 
 
189
 
    if( sizex )
190
 
    {
191
 
      if( ++x == sizex )
192
 
        x = 0, y++;
193
 
    }
194
 
    else
195
 
    {
196
 
      if( ++y == sizey )
197
 
        y = 0, x++;
198
 
    }
199
 
  }
200
 
  
201
 
  return groupWidget;
202
 
}
203
 
 
204
 
KonfiguratorRadioButtons* KonfiguratorPage::createRadioButtonGroup( QString cls,
205
 
    QString name, QString dflt, int sizex, int sizey, KONFIGURATOR_NAME_VALUE_TIP *params,
206
 
    int paramNum, QWidget *parent, bool rst, int pg )
207
 
{
208
 
  KonfiguratorRadioButtons *radioWidget = new KonfiguratorRadioButtons( cls, name, dflt, parent, rst, pg );
209
 
 
210
 
  QGridLayout *layout = new QGridLayout( radioWidget );
211
 
  layout->setAlignment( Qt::AlignTop );
212
 
  layout->setSpacing( 6 );
213
 
  layout->setContentsMargins( 0, 0, 0, 0 );
214
 
 
215
 
  int x = 0, y = 0;
216
 
 
217
 
  for( int i=0; i != paramNum; i++ )
218
 
  {
219
 
    QRadioButton *radBtn = new QRadioButton( params[i].text, radioWidget );
220
 
 
221
 
    if( !params[i].tooltip.isEmpty() )
222
 
      radBtn->setWhatsThis( params[i].tooltip );
223
 
 
224
 
    layout->addWidget( radBtn, y, x );
225
 
 
226
 
    radioWidget->addRadioButton( radBtn, params[i].text, params[i].value );
227
 
 
228
 
    if( sizex )
229
 
    {
230
 
      if( ++x == sizex )
231
 
        x = 0, y++;
232
 
    }
233
 
    else
234
 
    {
235
 
      if( ++y == sizey )
236
 
        y = 0, x++;
237
 
    }
238
 
  }
239
 
 
240
 
  radioWidget->loadInitialValue();
241
 
  registerObject( radioWidget->extension() );  
242
 
  return radioWidget;
243
 
}
244
 
 
245
 
KonfiguratorFontChooser *KonfiguratorPage::createFontChooser( QString cls, QString name,
246
 
  QFont *dflt, QWidget *parent, bool rst, int pg )
247
 
{
248
 
  KonfiguratorFontChooser *fontChooser = new KonfiguratorFontChooser( cls, name, dflt, parent,
249
 
                                        rst, pg );
250
 
 
251
 
  registerObject( fontChooser->extension() );
252
 
  return fontChooser;
253
 
}
254
 
 
255
 
KonfiguratorComboBox *KonfiguratorPage::createComboBox(  QString cls, QString name, QString dflt,
256
 
    KONFIGURATOR_NAME_VALUE_PAIR *params, int paramNum, QWidget *parent, bool rst, bool editable, int pg )
257
 
{
258
 
  KonfiguratorComboBox *comboBox = new KonfiguratorComboBox( cls, name, dflt, params,
259
 
                                        paramNum, parent, rst, editable, pg );
260
 
 
261
 
  registerObject( comboBox->extension() );
262
 
  return comboBox;
263
 
}
264
 
 
265
 
QFrame* KonfiguratorPage::createLine( QWidget *parent, bool vertical )
266
 
{
267
 
  QFrame *line = new QFrame( parent );
268
 
  line->setFrameStyle( ( vertical ? QFrame::VLine : QFrame::HLine ) | QFrame::Sunken );
269
 
  return line;
270
 
}
271
 
 
272
 
void KonfiguratorPage::registerObject( KonfiguratorExtension *item )
273
 
{
274
 
  itemList.push_back( item );
275
 
  connect( item, SIGNAL( sigChanged( bool ) ), this, SIGNAL ( sigChanged( ) ) );
276
 
}
277
 
 
278
 
void KonfiguratorPage::removeObject( KonfiguratorExtension *item )
279
 
{
280
 
    int ndx = itemList.indexOf( item );
281
 
    if( ndx != -1 )
282
 
    {
283
 
      QList<KonfiguratorExtension *>::iterator it = itemList.begin() + ndx;
284
 
      delete *it;
285
 
      itemList.erase( it );
286
 
    }
287
 
}
288
 
 
289
 
KonfiguratorColorChooser *KonfiguratorPage::createColorChooser( QString cls, QString name, QColor dflt,
290
 
                                                                QWidget *parent, bool rst,
291
 
                                                                ADDITIONAL_COLOR *addColPtr, int addColNum, int pg )
292
 
{
293
 
  KonfiguratorColorChooser *colorChooser = new KonfiguratorColorChooser( cls, name, dflt,  parent,
294
 
                                        rst, addColPtr, addColNum, pg );
295
 
 
296
 
  registerObject( colorChooser->extension() );
297
 
  return colorChooser;
 
74
    bool isChanged = false;
 
75
 
 
76
    for (QList<KonfiguratorExtension *>::iterator item = itemList.begin(); item != itemList.end(); item ++)
 
77
        isChanged = isChanged || (*item)->isChanged();
 
78
 
 
79
    return isChanged;
 
80
}
 
81
 
 
82
KonfiguratorCheckBox* KonfiguratorPage::createCheckBox(QString cls, QString name,
 
83
        bool dflt, QString text, QWidget *parent, bool rst, QString toolTip, int pg)
 
84
{
 
85
    KonfiguratorCheckBox *checkBox = new KonfiguratorCheckBox(cls, name, dflt, text,
 
86
            parent, rst, pg);
 
87
    if (!toolTip.isEmpty())
 
88
        checkBox->setWhatsThis(toolTip);
 
89
 
 
90
    registerObject(checkBox->extension());
 
91
    return checkBox;
 
92
}
 
93
 
 
94
KonfiguratorSpinBox* KonfiguratorPage::createSpinBox(QString cls, QString name,
 
95
        int dflt, int min, int max, QWidget *parent, bool rst, int pg)
 
96
{
 
97
    KonfiguratorSpinBox *spinBox = new KonfiguratorSpinBox(cls, name, dflt, min, max,
 
98
            parent, rst, pg);
 
99
 
 
100
    registerObject(spinBox->extension());
 
101
    return spinBox;
 
102
}
 
103
 
 
104
KonfiguratorEditBox* KonfiguratorPage::createEditBox(QString cls, QString name,
 
105
        QString dflt, QWidget *parent, bool rst, int pg)
 
106
{
 
107
    KonfiguratorEditBox *editBox = new KonfiguratorEditBox(cls, name, dflt, parent,
 
108
            rst, pg);
 
109
 
 
110
    registerObject(editBox->extension());
 
111
    return editBox;
 
112
}
 
113
 
 
114
KonfiguratorListBox* KonfiguratorPage::createListBox(QString cls, QString name,
 
115
        QStringList dflt, QWidget *parent, bool rst, int pg)
 
116
{
 
117
    KonfiguratorListBox *listBox = new KonfiguratorListBox(cls, name, dflt, parent,
 
118
            rst, pg);
 
119
 
 
120
    registerObject(listBox->extension());
 
121
    return listBox;
 
122
}
 
123
 
 
124
KonfiguratorURLRequester* KonfiguratorPage::createURLRequester(QString cls, QString name,
 
125
        QString dflt, QWidget *parent, bool rst, int pg)
 
126
{
 
127
    KonfiguratorURLRequester *urlRequester = new KonfiguratorURLRequester(cls, name, dflt,
 
128
            parent, rst, pg);
 
129
 
 
130
    registerObject(urlRequester->extension());
 
131
    return urlRequester;
 
132
}
 
133
 
 
134
QGroupBox* KonfiguratorPage::createFrame(QString text, QWidget *parent)
 
135
{
 
136
    QGroupBox *groupBox = new QGroupBox(parent);
 
137
    if (!text.isNull())
 
138
        groupBox->setTitle(text);
 
139
    return groupBox;
 
140
}
 
141
 
 
142
QGridLayout* KonfiguratorPage::createGridLayout(QWidget *parent)
 
143
{
 
144
    QGridLayout *gridLayout = new QGridLayout(parent);
 
145
    gridLayout->setAlignment(Qt::AlignTop);
 
146
    gridLayout->setSpacing(6);
 
147
    gridLayout->setContentsMargins(11, 11, 11, 11);
 
148
    return gridLayout;
 
149
}
 
150
 
 
151
QLabel* KonfiguratorPage::addLabel(QGridLayout *layout, int x, int y, QString label,
 
152
                                   QWidget *parent)
 
153
{
 
154
    QLabel *lbl = new QLabel(label, parent);
 
155
    layout->addWidget(lbl, x, y);
 
156
    return lbl;
 
157
}
 
158
 
 
159
QWidget* KonfiguratorPage::createSpacer(QWidget *parent)
 
160
{
 
161
    QWidget *widget = new QWidget(parent);
 
162
    QHBoxLayout *hboxlayout = new QHBoxLayout(widget);
 
163
    QSpacerItem* spacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
 
164
    hboxlayout->addItem(spacer);
 
165
    return widget;
 
166
}
 
167
 
 
168
KonfiguratorCheckBoxGroup* KonfiguratorPage::createCheckBoxGroup(int sizex, int sizey,
 
169
        KONFIGURATOR_CHECKBOX_PARAM *params, int paramNum, QWidget *parent,
 
170
        int pg)
 
171
{
 
172
    KonfiguratorCheckBoxGroup *groupWidget = new KonfiguratorCheckBoxGroup(parent);
 
173
    QGridLayout *layout = new QGridLayout(groupWidget);
 
174
    layout->setSpacing(6);
 
175
    layout->setContentsMargins(0, 0, 0, 0);
 
176
 
 
177
    int x = 0, y = 0;
 
178
 
 
179
    for (int i = 0; i != paramNum; i++) {
 
180
        KonfiguratorCheckBox *checkBox = createCheckBox(params[i].configClass,
 
181
                                         params[i].configName, params[i].defaultValue, params[i].text, groupWidget,
 
182
                                         params[i].restart, params[i].toolTip, pg);
 
183
 
 
184
        groupWidget->add(checkBox);
 
185
        layout->addWidget(checkBox, y, x);
 
186
 
 
187
        if (sizex) {
 
188
            if (++x == sizex)
 
189
                x = 0, y++;
 
190
        } else {
 
191
            if (++y == sizey)
 
192
                y = 0, x++;
 
193
        }
 
194
    }
 
195
 
 
196
    return groupWidget;
 
197
}
 
198
 
 
199
KonfiguratorRadioButtons* KonfiguratorPage::createRadioButtonGroup(QString cls,
 
200
        QString name, QString dflt, int sizex, int sizey, KONFIGURATOR_NAME_VALUE_TIP *params,
 
201
        int paramNum, QWidget *parent, bool rst, int pg)
 
202
{
 
203
    KonfiguratorRadioButtons *radioWidget = new KonfiguratorRadioButtons(cls, name, dflt, parent, rst, pg);
 
204
 
 
205
    QGridLayout *layout = new QGridLayout(radioWidget);
 
206
    layout->setAlignment(Qt::AlignTop);
 
207
    layout->setSpacing(6);
 
208
    layout->setContentsMargins(0, 0, 0, 0);
 
209
 
 
210
    int x = 0, y = 0;
 
211
 
 
212
    for (int i = 0; i != paramNum; i++) {
 
213
        QRadioButton *radBtn = new QRadioButton(params[i].text, radioWidget);
 
214
 
 
215
        if (!params[i].tooltip.isEmpty())
 
216
            radBtn->setWhatsThis(params[i].tooltip);
 
217
 
 
218
        layout->addWidget(radBtn, y, x);
 
219
 
 
220
        radioWidget->addRadioButton(radBtn, params[i].text, params[i].value);
 
221
 
 
222
        if (sizex) {
 
223
            if (++x == sizex)
 
224
                x = 0, y++;
 
225
        } else {
 
226
            if (++y == sizey)
 
227
                y = 0, x++;
 
228
        }
 
229
    }
 
230
 
 
231
    radioWidget->loadInitialValue();
 
232
    registerObject(radioWidget->extension());
 
233
    return radioWidget;
 
234
}
 
235
 
 
236
KonfiguratorFontChooser *KonfiguratorPage::createFontChooser(QString cls, QString name,
 
237
        QFont *dflt, QWidget *parent, bool rst, int pg)
 
238
{
 
239
    KonfiguratorFontChooser *fontChooser = new KonfiguratorFontChooser(cls, name, dflt, parent,
 
240
            rst, pg);
 
241
 
 
242
    registerObject(fontChooser->extension());
 
243
    return fontChooser;
 
244
}
 
245
 
 
246
KonfiguratorComboBox *KonfiguratorPage::createComboBox(QString cls, QString name, QString dflt,
 
247
        KONFIGURATOR_NAME_VALUE_PAIR *params, int paramNum, QWidget *parent, bool rst, bool editable, int pg)
 
248
{
 
249
    KonfiguratorComboBox *comboBox = new KonfiguratorComboBox(cls, name, dflt, params,
 
250
            paramNum, parent, rst, editable, pg);
 
251
 
 
252
    registerObject(comboBox->extension());
 
253
    return comboBox;
 
254
}
 
255
 
 
256
QFrame* KonfiguratorPage::createLine(QWidget *parent, bool vertical)
 
257
{
 
258
    QFrame *line = new QFrame(parent);
 
259
    line->setFrameStyle((vertical ? QFrame::VLine : QFrame::HLine) | QFrame::Sunken);
 
260
    return line;
 
261
}
 
262
 
 
263
void KonfiguratorPage::registerObject(KonfiguratorExtension *item)
 
264
{
 
265
    itemList.push_back(item);
 
266
    connect(item, SIGNAL(sigChanged(bool)), this, SIGNAL(sigChanged()));
 
267
}
 
268
 
 
269
void KonfiguratorPage::removeObject(KonfiguratorExtension *item)
 
270
{
 
271
    int ndx = itemList.indexOf(item);
 
272
    if (ndx != -1) {
 
273
        QList<KonfiguratorExtension *>::iterator it = itemList.begin() + ndx;
 
274
        delete *it;
 
275
        itemList.erase(it);
 
276
    }
 
277
}
 
278
 
 
279
KonfiguratorColorChooser *KonfiguratorPage::createColorChooser(QString cls, QString name, QColor dflt,
 
280
        QWidget *parent, bool rst,
 
281
        ADDITIONAL_COLOR *addColPtr, int addColNum, int pg)
 
282
{
 
283
    KonfiguratorColorChooser *colorChooser = new KonfiguratorColorChooser(cls, name, dflt,  parent,
 
284
            rst, addColPtr, addColNum, pg);
 
285
 
 
286
    registerObject(colorChooser->extension());
 
287
    return colorChooser;
298
288
}
299
289
 
300
290
#include "konfiguratorpage.moc"