summaryrefslogtreecommitdiffabout
path: root/microkde/kdialogbase.cpp
blob: 22512070358b9c8e6936afad033bb114fecc87e1 (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
#include <qtabwidget.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qframe.h>


#include "klocale.h"
#include "kdebug.h"

#include "kdialogbase.h"

KDialogBase::KDialogBase()
{
}

KDialogBase::KDialogBase( QWidget *parent, const char *name, bool modal,
             const QString &caption,
             int buttonMask, ButtonCode defaultButton,
             bool separator, 
             const QString &user1,
             const QString &user2,
             const QString &user3) :
    KDialog( parent, name, modal )
{
  init( caption, buttonMask, user1, user2 );
  if (findButton( defaultButton ) )
  (findButton( defaultButton ) )->setFocus();

}

KDialogBase::KDialogBase( int dialogFace, const QString &caption, 
             int buttonMask, ButtonCode defaultButton, 
             QWidget *parent, const char *name, bool modal, 
             bool separator,
             const QString &user1,
             const QString &user2,
             const QString &user3) :
    KDialog( parent, name, modal )
{
    init( caption, buttonMask, user1, user2 );
  if (findButton( defaultButton ) )
  (findButton( defaultButton ) )->setFocus();

}

KDialogBase::~KDialogBase()
{
}

void KDialogBase::init( const QString &caption, int buttonMask,
                        const QString &user1 ,const QString &user2 )
{
  mMainWidget = 0;
  mTabWidget = 0;
  mPlainPage = 0;
  mTopLayout = 0;
  if ( !caption.isEmpty() ) {
    setCaption( caption );
  }

  if ( buttonMask & User1 ) {
    mUser1Button = new QPushButton( user1, this );
    connect( mUser1Button, SIGNAL( clicked() ), SLOT( slotUser1() ) );
  } else {
    mUser1Button = 0;
  }
  if ( buttonMask & User2 ) {
    mUser2Button = new QPushButton( user2, this );
    connect( mUser2Button, SIGNAL( clicked() ), SLOT( slotUser2() ) );
  } else {
    mUser2Button = 0;
  }

  if ( buttonMask & Ok ) {
    mOkButton = new QPushButton( i18n("Ok"), this );
    connect( mOkButton, SIGNAL( clicked() ), SLOT( slotOk() ) );
  } else {
    mOkButton = 0;
  }
  if ( buttonMask & Default ) {
     qDebug("buttonMask & Default ");
    mDefaultButton = new QPushButton( i18n("Default"), this );
    connect( mDefaultButton, SIGNAL( clicked() ), SIGNAL( defaultClicked() ) );
  } else {
    mDefaultButton = 0;
  }

  if ( buttonMask & Apply ) {
    mApplyButton = new QPushButton( i18n("Apply"), this );
    connect( mApplyButton, SIGNAL( clicked() ), SLOT( slotApply() ) );
  } else {
    mApplyButton = 0;
  }

  if ( buttonMask & Cancel ) {
    mCancelButton = new QPushButton( i18n("Cancel"), this );
    connect( mCancelButton, SIGNAL( clicked() ), SLOT( slotCancel() ) );
  } else {
    mCancelButton = 0;
  }

  if ( buttonMask & Close ) {
    mCloseButton = new QPushButton( i18n("Close"), this );
    connect( mCloseButton, SIGNAL( clicked() ), SLOT( slotClose() ) );
  } else {
    mCloseButton = 0;
  } 
}

QTabWidget *KDialogBase::tabWidget()
{
  if ( !mTabWidget ) {
    mTabWidget = new QTabWidget( this );
    setMainWidget( mTabWidget );
  }
  return mTabWidget;
}

void KDialogBase::hideButtons()
{
    if ( mUser1Button ) mUser1Button->hide() ;
    if ( mUser2Button ) mUser2Button->hide() ;
    if ( mOkButton ) mOkButton->hide()  ;
    if ( mApplyButton )  mApplyButton->hide()  ;
    if ( mDefaultButton ) mDefaultButton->hide();
    if ( mCancelButton ) mCancelButton->hide()  ;
    if ( mCloseButton ) mCloseButton->hide()  ;
  
}
void KDialogBase::initLayout()
{
 
  delete mTopLayout;
  mTopLayout = new QVBoxLayout( this );
  mTopLayout->setMargin( marginHint() );
  mTopLayout->setSpacing( spacingHint() );
  
  mTopLayout->addWidget( mMainWidget );
  
  QBoxLayout *buttonLayout = new QHBoxLayout;
  mTopLayout->addLayout( buttonLayout );
  
  if ( mUser1Button ) buttonLayout->addWidget( mUser1Button );
  if ( mUser2Button ) buttonLayout->addWidget( mUser2Button );
  if ( mOkButton ) buttonLayout->addWidget( mOkButton );
  if ( mApplyButton ) buttonLayout->addWidget( mApplyButton );
  if ( mDefaultButton ) buttonLayout->addWidget( mDefaultButton );
  if ( mCancelButton ) buttonLayout->addWidget( mCancelButton );
  if ( mCloseButton ) buttonLayout->addWidget( mCloseButton );
}

QFrame *KDialogBase::addPage( const QString &name )
{
//  kdDebug() << "KDialogBase::addPage(): " << name << endl;
  QFrame *frame = new QFrame( tabWidget() );
  tabWidget()->addTab( frame, name );
  return frame;
}

QFrame *KDialogBase::addPage( const QString &name, int, const QPixmap & )
{
  return addPage( name );
}


void KDialogBase::setMainWidget( QWidget *widget )
{
  kdDebug() << "KDialogBase::setMainWidget()" << endl;

  mMainWidget = widget;
  initLayout();
}

void KDialogBase::setButtonText( ButtonCode id, const QString &text )
{
  QPushButton *button = findButton( id );
  if ( button ) {
    button->setText( text );
  }
}

void KDialogBase::enableButton( ButtonCode id, bool state )
{
  QPushButton *button = findButton( id );
  if ( button ) {
    button->setEnabled( state );
  }
}

QPushButton *KDialogBase::findButton( ButtonCode id )
{
  QPushButton *button = 0;
  switch ( id ) {
    case Ok:
      button = mOkButton;
      break;
    case Apply:
      button = mApplyButton;
      break;
    case User1:
      button = mUser1Button;
      break;
    case User2:
      button = mUser2Button;
      break;
    case Cancel:
      button = mCancelButton;
      break;  
    case Default:
      button = mDefaultButton;
      break;
    case Close:
      button = mCloseButton;
      break;
    default:
      break;      
  }
  return button;
}

void KDialogBase::enableButtonOK( bool state )
{
  enableButton( Ok, state );
}

void KDialogBase::enableButtonApply( bool state )
{
  enableButton( Apply, state );
}

void KDialogBase::showButton( ButtonCode id, bool show )
{
  QPushButton *button = findButton( id );
  if ( button ) {
    if ( show ) button->show();
    else button->hide();
  }
}

int KDialogBase::pageIndex( QWidget *widget ) const
{
  return 0;
}


bool KDialogBase::showPage( int index )
{
    tabWidget()->setCurrentPage( index );return false;
}

QFrame *KDialogBase::plainPage()
{
  if ( !mPlainPage ) {
    mPlainPage = new QFrame( this );
    setMainWidget( mPlainPage );
  }
  return mPlainPage;
}

void KDialogBase::slotOk()
{
  emit okClicked();
  QDialog::accept();
}

void KDialogBase::slotApply()
{
  emit applyClicked();
}

void KDialogBase::slotCancel()
{
  emit cancelClicked();
  reject();
}

void KDialogBase::slotClose()
{
  emit closeClicked();
  reject();
}

void KDialogBase::slotUser1()
{
  emit user1Clicked();
}
void KDialogBase::slotUser2()
{
  emit user2Clicked();
}