00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
#include "kdialogbase.h"
00025
#include <stdlib.h>
00026
00027
#include <qgrid.h>
00028
#include <qhbox.h>
00029
#include <qlayout.h>
00030
#include <qtooltip.h>
00031
#include <qvbox.h>
00032
#include <qwhatsthis.h>
00033
#include <qtimer.h>
00034
#include <qfocusdata.h>
00035
00036
#include <kapplication.h>
00037
#include <klocale.h>
00038
#include <kconfig.h>
00039
#include <kiconloader.h>
00040
#include <kglobal.h>
00041
#include <kglobalsettings.h>
00042
#include <kseparator.h>
00043
#include <kurllabel.h>
00044
#include <kdebug.h>
00045
00046
#include "kdialogbase_priv.h"
00047
#include "kdialogbase_priv.moc"
00048
00049
KDialogBaseTile *KDialogBase::mTile = 0;
00050
00051
int KDialogBaseButton::id()
00052 {
00053
return mKey;
00054 }
00055
00056
template class QPtrList<KDialogBaseButton>;
00057
00061
namespace
00062
{
00063
struct SButton :
public Qt
00064 {
00065 SButton()
00066 {
00067 box = 0;
00068 mask = 0;
00069 style = 0;
00070 }
00071
00072
KPushButton *append(
int key,
const KGuiItem &item );
00073
00074
void resize(
bool sameWidth,
int margin,
int spacing,
int orientation );
00075
00076
KPushButton *button(
int key );
00077
00078
QWidget *box;
00079
int mask;
00080
int style;
00081
QPtrList<KDialogBaseButton> list;
00082 };
00083 }
00084
00085
class KDialogBase::KDialogBasePrivate {
00086
public:
00087 KDialogBasePrivate() : bDetails(false), bFixed(false), bSettingDetails(false), detailsWidget(0) { }
00088
00089
bool bDetails;
00090
bool bFixed;
00091
bool bSettingDetails;
00092
QWidget *detailsWidget;
00093
QSize incSize;
00094
QSize minSize;
00095
QString detailsButton;
00096 SButton mButton;
00097 };
00098
00099 KDialogBase::KDialogBase(
QWidget *parent,
const char *name,
bool modal,
00100
const QString &caption,
int buttonMask,
00101 ButtonCode defaultButton,
bool separator,
00102
const KGuiItem &user1,
const KGuiItem &user2,
00103
const KGuiItem &user3 )
00104 :
KDialog( parent, name, modal, WStyle_DialogBorder ),
00105 mTopLayout(0), mMainWidget(0), mUrlHelp(0), mJanus(0), mActionSep(0),
00106 mIsActivated(false), mShowTile(false), mMessageBoxMode(false),
00107 mButtonOrientation(Horizontal), d(new KDialogBasePrivate)
00108 {
00109 setCaption( caption );
00110
00111 makeRelay();
00112 connect(
this, SIGNAL(
layoutHintChanged()), SLOT(
updateGeometry()) );
00113
00114
enableButtonSeparator( separator );
00115 makeButtonBox( buttonMask, defaultButton, user1, user2, user3 );
00116
00117 mIsActivated =
true;
00118 setupLayout();
00119 }
00120
00121 KDialogBase::KDialogBase(
int dialogFace,
const QString &caption,
00122
int buttonMask, ButtonCode defaultButton,
00123
QWidget *parent,
const char *name,
bool modal,
00124
bool separator,
const KGuiItem &user1,
00125
const KGuiItem &user2,
const KGuiItem &user3 )
00126 :
KDialog( parent, name, modal, WStyle_DialogBorder ),
00127 mTopLayout(0), mMainWidget(0), mUrlHelp(0), mJanus(0), mActionSep(0),
00128 mIsActivated(false), mShowTile(false), mMessageBoxMode(false),
00129 mButtonOrientation(Horizontal), d(new KDialogBasePrivate)
00130 {
00131 setCaption( caption );
00132
00133 makeRelay();
00134 connect(
this, SIGNAL(
layoutHintChanged()), SLOT(
updateGeometry()) );
00135
00136 mJanus =
new KJanusWidget(
this,
"janus", dialogFace );
00137 connect(mJanus, SIGNAL(
aboutToShowPage(
QWidget *)),
00138
this, SIGNAL(
aboutToShowPage(
QWidget *)));
00139
00140
if( !mJanus || !mJanus->
isValid() ) {
return; }
00141
00142
enableButtonSeparator( separator );
00143 makeButtonBox( buttonMask, defaultButton, user1, user2, user3 );
00144
00145 mIsActivated =
true;
00146 setupLayout();
00147 }
00148
00149 KDialogBase::KDialogBase( KDialogBase::DialogType dialogFace, WFlags f,
QWidget *parent,
const char *name,
00150
bool modal,
00151
const QString &caption,
int buttonMask,
00152 ButtonCode defaultButton,
bool separator,
00153
const KGuiItem &user1,
const KGuiItem &user2,
00154
const KGuiItem &user3 )
00155 :
KDialog( parent, name, modal, f ),
00156 mTopLayout(0), mMainWidget(0), mUrlHelp(0), mJanus(0), mActionSep(0),
00157 mIsActivated(false), mShowTile(false), mMessageBoxMode(false),
00158 mButtonOrientation(Horizontal), d(new KDialogBasePrivate)
00159 {
00160 setCaption( caption );
00161
00162 makeRelay();
00163 connect(
this, SIGNAL(
layoutHintChanged()), SLOT(
updateGeometry()) );
00164
00165 mJanus =
new KJanusWidget(
this,
"janus", dialogFace );
00166 connect(mJanus, SIGNAL(
aboutToShowPage(
QWidget *)),
00167
this, SIGNAL(
aboutToShowPage(
QWidget *)));
00168
00169
if( !mJanus || !mJanus->
isValid() ) {
return; }
00170
00171
enableButtonSeparator( separator );
00172 makeButtonBox( buttonMask, defaultButton, user1, user2, user3 );
00173
00174 mIsActivated =
true;
00175 setupLayout();
00176 }
00177
00178 KDialogBase::KDialogBase(
const QString &caption,
int buttonMask,
00179 ButtonCode defaultButton, ButtonCode escapeButton,
00180
QWidget *parent,
const char *name,
bool modal,
00181
bool separator,
const KGuiItem &yes,
00182
const KGuiItem &no,
const KGuiItem &cancel )
00183 :
KDialog( parent, name, modal, WStyle_DialogBorder ),
00184 mTopLayout(0), mMainWidget(0), mUrlHelp(0), mJanus(0), mActionSep(0),
00185 mIsActivated(false), mShowTile(false), mMessageBoxMode(true),
00186 mButtonOrientation(Horizontal),mEscapeButton(escapeButton),
00187 d(new KDialogBasePrivate)
00188 {
00189 setCaption( caption );
00190
00191 makeRelay();
00192 connect(
this, SIGNAL(
layoutHintChanged()), SLOT(
updateGeometry()) );
00193
00194
enableButtonSeparator( separator );
00195
00196 buttonMask &= Details|Yes|No|Cancel;
00197
00198 makeButtonBox( buttonMask, defaultButton,
00199 no.
text().
isEmpty() ? KStdGuiItem::no() : no,
00200 yes.
text().
isEmpty() ? KStdGuiItem::yes() : yes );
00201
00202
setButtonCancel( cancel.
text().
isEmpty() ?
00203 KStdGuiItem::cancel() : cancel );
00204
00205 mIsActivated =
true;
00206 setupLayout();
00207 }
00208
00209
00210
00211 KDialogBase::~KDialogBase()
00212 {
00213
delete d;
00214 }
00215
00216
KPushButton *SButton::append(
int key,
const KGuiItem &item )
00217 {
00218
KDialogBaseButton *p =
new KDialogBaseButton( item, key, box );
00219 list.append( p );
00220
return p;
00221 }
00222
00223
void SButton::resize(
bool sameWidth,
int margin,
00224
int spacing,
int orientation )
00225 {
00226
KDialogBaseButton *p;
00227
int h = 0;
00228
int w = 0;
00229
int t = 0;
00230
00231
for( p = list.first(); p; p = list.next() )
00232 {
00233
const QSize s( p->sizeHint() );
00234
if( s.
height() > h ) { h = s.
height(); }
00235
if( s.
width() > w ) { w = s.
width(); }
00236 }
00237
00238
if( orientation == Horizontal )
00239 {
00240
for( p = list.first(); p; p = list.next() )
00241 {
00242
QSize s( p->sizeHint() );
00243
if( sameWidth ) { s.
setWidth( w ); }
00244 p->setFixedWidth( s.
width() );
00245 t += s.
width() + spacing;
00246 }
00247
00248 box->setMinimumHeight( margin*2 + h );
00249 box->setMinimumWidth( margin*2 + t - spacing );
00250 }
00251
else
00252 {
00253
00254
for( p = list.first(); p; p = list.next() )
00255 {
00256
QSize s( p->sizeHint() );
00257 s.
setWidth( w );
00258 p->setFixedSize( s );
00259 t += s.
height() + spacing;
00260 }
00261 box->setMinimumHeight( margin*2 + t - spacing );
00262 box->setMinimumWidth( margin*2 + w );
00263 }
00264 }
00265
00266
KPushButton *SButton::button(
int key )
00267 {
00268
KDialogBaseButton *p;
00269
for( p = list.first(); p; p = list.next() )
00270 {
00271
if( p->
id() ==
key )
00272 {
00273
return p;
00274 }
00275 }
00276
return 0;
00277 }
00278
00279
void
00280 KDialogBase::delayedDestruct()
00281 {
00282
if (isVisible())
00283 hide();
00284 QTimer::singleShot( 0,
this, SLOT(
slotDelayedDestruct()));
00285 }
00286
00287
void
00288 KDialogBase::slotDelayedDestruct()
00289 {
00290
delete this;
00291 }
00292
00293
void KDialogBase::setupLayout()
00294 {
00295
if( mTopLayout )
00296 {
00297
delete mTopLayout;
00298 }
00299
00300
00301
00302
if( mButtonOrientation == Horizontal )
00303 {
00304 mTopLayout =
new QBoxLayout(
this, QBoxLayout::TopToBottom,
00305
marginHint(),
spacingHint() );
00306 }
00307
else
00308 {
00309 mTopLayout =
new QBoxLayout(
this, QBoxLayout::LeftToRight,
00310
marginHint(),
spacingHint() );
00311 }
00312
00313
if( mUrlHelp )
00314 {
00315 mTopLayout->
addWidget( mUrlHelp, 0, AlignRight );
00316 }
00317
00318
if( mJanus )
00319 {
00320 mTopLayout->
addWidget( mJanus, 10 );
00321 }
00322
else if( mMainWidget )
00323 {
00324 mTopLayout->
addWidget( mMainWidget, 10 );
00325 }
00326
00327
if ( d->detailsWidget )
00328 {
00329 mTopLayout->
addWidget( d->detailsWidget );
00330 }
00331
00332
if( mActionSep )
00333 {
00334 mTopLayout->
addWidget( mActionSep );
00335 }
00336
00337
if( d->mButton.box )
00338 {
00339 mTopLayout->
addWidget( d->mButton.box );
00340 }
00341 }
00342
00343
00344
00345 void KDialogBase::setButtonBoxOrientation(
int orientation )
00346 {
00347
if( mButtonOrientation != orientation )
00348 {
00349 mButtonOrientation = orientation;
00350
if( mActionSep )
00351 {
00352 mActionSep->
setOrientation( mButtonOrientation == Horizontal ?
00353 QFrame::HLine : QFrame::VLine );
00354 }
00355
if( mButtonOrientation == Vertical )
00356 {
00357
enableLinkedHelp(
false);
00358 }
00359 setupLayout();
00360 setButtonStyle( d->mButton.style );
00361 }
00362 }
00363
00364
00365 void KDialogBase::setEscapeButton( ButtonCode
id )
00366 {
00367 mEscapeButton =
id;
00368 }
00369
00370
00371
00372
void KDialogBase::makeRelay()
00373 {
00374
if( mTile )
00375 {
00376 connect( mTile, SIGNAL(pixmapChanged()), SLOT(
updateBackground()) );
00377
return;
00378 }
00379
00380 mTile =
new KDialogBaseTile;
00381
if( mTile )
00382 {
00383 connect( mTile, SIGNAL(pixmapChanged()), SLOT(
updateBackground()) );
00384 connect( qApp, SIGNAL(aboutToQuit()), mTile, SLOT(cleanup()) );
00385 }
00386 }
00387
00388
00389 void KDialogBase::enableButtonSeparator(
bool state )
00390 {
00391
if( state )
00392 {
00393
if( mActionSep )
00394 {
00395
return;
00396 }
00397 mActionSep =
new KSeparator(
this );
00398 mActionSep->setFocusPolicy(QWidget::NoFocus);
00399 mActionSep->
setOrientation( mButtonOrientation == Horizontal ?
00400 QFrame::HLine : QFrame::VLine );
00401 mActionSep->show();
00402 }
00403
else
00404 {
00405
if( !mActionSep )
00406 {
00407
return;
00408 }
00409
delete mActionSep; mActionSep = 0;
00410 }
00411
00412
if( mIsActivated )
00413 {
00414 setupLayout();
00415 }
00416 }
00417
00418
00419
00420 QFrame *
KDialogBase::plainPage()
00421 {
00422
return ( mJanus ? mJanus->
plainPage() : 0 );
00423 }
00424
00425
00426
00427 void KDialogBase::adjustSize()
00428 {
00429
00430
00431
if( d->bFixed )
00432 setFixedSize( sizeHint() );
00433
else
00434 resize( sizeHint() );
00435 }
00436
00437
QSize KDialogBase::sizeHint()
const
00438
{
00439
return d->minSize.expandedTo( minimumSizeHint() ) + d->incSize;
00440 }
00441
00442
QSize KDialogBase::minimumSizeHint()
const
00443
{
00444
const int m =
marginHint();
00445
const int s =
spacingHint();
00446
00447
const QSize zeroByS(0, s);
00448
00449
QSize s1(0,0);
00450
QSize s2(0,0);
00451
00452
00453
00454
00455
if( mUrlHelp )
00456 {
00457 s2 = mUrlHelp->minimumSize() + zeroByS;
00458 }
00459 s1.
rwidth() = QMAX( s1.
rwidth(), s2.
rwidth() );
00460 s1.
rheight() += s2.
rheight();
00461
00462
00463
00464
00465
if( mJanus )
00466 {
00467 s2 = mJanus->
minimumSizeHint() + zeroByS;
00468 }
00469
else if( mMainWidget )
00470 {
00471 s2 = mMainWidget->
sizeHint() + zeroByS;
00472 s2 = s2.
expandedTo( mMainWidget->
minimumSize() );
00473 s2 = s2.
expandedTo( mMainWidget->
minimumSizeHint() );
00474
if( s2.
isEmpty() )
00475 {
00476 s2 =
QSize( 100, 100+s );
00477 }
00478 }
00479
else
00480 {
00481 s2 =
QSize( 100, 100+s );
00482 }
00483 s1.
rwidth() = QMAX( s1.
rwidth(), s2.
rwidth() );
00484 s1.
rheight() += s2.
rheight();
00485
00486
if (d->detailsWidget && d->bDetails)
00487 {
00488 s2 = d->detailsWidget->sizeHint() + zeroByS;
00489 s2 = s2.
expandedTo( d->detailsWidget->minimumSize() );
00490 s2 = s2.
expandedTo( d->detailsWidget->minimumSizeHint() );
00491 s1.
rwidth() = QMAX( s1.
rwidth(), s2.
rwidth() );
00492 s1.
rheight() += s2.
rheight();
00493 }
00494
00495
00496
00497
00498
if( mActionSep )
00499 {
00500 s1.
rheight() += mActionSep->minimumSize().height() + s;
00501 }
00502
00503
00504
00505
00506
if( d->mButton.box )
00507 {
00508 s2 = d->mButton.box->minimumSize();
00509
if( mButtonOrientation == Horizontal )
00510 {
00511 s1.
rwidth() = QMAX( s1.
rwidth(), s2.
rwidth() );
00512 s1.
rheight() += s2.
rheight();
00513 }
00514
else
00515 {
00516 s1.
rwidth() += s2.
rwidth();
00517 s1.
rheight() = QMAX( s1.
rheight(), s2.
rheight() );
00518 }
00519 }
00520
00521
00522
00523
00524 s1.
rheight() += 2*m;
00525 s1.
rwidth() += 2*m;
00526
00527
return s1;
00528 }
00529
00530
00531 void KDialogBase::disableResize()
00532 {
00533 setFixedSize( sizeHint() );
00534 }
00535
00536
00537 void KDialogBase::setInitialSize(
const QSize &s,
bool noResize )
00538 {
00539 d->minSize = s;
00540 d->bFixed = noResize;
00541
adjustSize();
00542 }
00543
00544
00545 void KDialogBase::incInitialSize(
const QSize &s,
bool noResize )
00546 {
00547 d->incSize = s;
00548 d->bFixed = noResize;
00549
adjustSize();
00550 }
00551
00552
00553
void KDialogBase::makeButtonBox(
int buttonMask, ButtonCode defaultButton,
00554
const KGuiItem &user1,
const KGuiItem &user2,
00555
const KGuiItem &user3 )
00556 {
00557
if( buttonMask == 0 )
00558 {
00559 d->mButton.box = 0;
00560
return;
00561 }
00562
00563
if( buttonMask & Cancel ) { buttonMask &= ~Close; }
00564
if( buttonMask & Apply ) { buttonMask &= ~Try; }
00565
if( buttonMask & Details ) { buttonMask &= ~Default; }
00566
00567
if( !mMessageBoxMode )
00568 {
00569 mEscapeButton = (buttonMask&Cancel) ? Cancel : Close;
00570 }
00571
00572 d->mButton.box =
new QWidget(
this );
00573
00574 d->mButton.mask = buttonMask;
00575
if( d->mButton.mask & Help )
00576 {
00577
KPushButton *pb = d->mButton.append( Help, KStdGuiItem::help() );
00578
00579 connect( pb, SIGNAL(clicked()), SLOT(
slotHelp()) );
00580 }
00581
if( d->mButton.mask & Default )
00582 {
00583
KPushButton *pb = d->mButton.append( Default, KStdGuiItem::defaults() );
00584
00585 connect( pb, SIGNAL(clicked()), SLOT(
slotDefault()) );
00586 }
00587
if( d->mButton.mask & Details )
00588 {
00589
KPushButton *pb = d->mButton.append( Details, QString::null );
00590 connect( pb, SIGNAL(clicked()), SLOT(
slotDetails()) );
00591
setDetails(
false);
00592 }
00593
if( d->mButton.mask & User3 )
00594 {
00595
KPushButton *pb = d->mButton.append( User3, user3 );
00596 connect( pb, SIGNAL(clicked()), SLOT(
slotUser3()) );
00597 }
00598
if( d->mButton.mask & User2 )
00599 {
00600
KPushButton *pb = d->mButton.append( User2, user2 );
00601
if( mMessageBoxMode )
00602 {
00603 connect( pb, SIGNAL(clicked()), SLOT(
slotYes()) );
00604 }
00605
else
00606 {
00607 connect( pb, SIGNAL(clicked()),
this, SLOT(
slotUser2()) );
00608 }
00609 }
00610
if( d->mButton.mask & User1 )
00611 {
00612
KPushButton *pb = d->mButton.append( User1, user1 );
00613
if( mMessageBoxMode )
00614 {
00615 connect( pb, SIGNAL(clicked()),
this, SLOT(
slotNo()) );
00616 }
00617
else
00618 {
00619 connect( pb, SIGNAL(clicked()), SLOT(
slotUser1()) );
00620 }
00621 }
00622
if( d->mButton.mask & Ok )
00623 {
00624
KPushButton *pb = d->mButton.append( Ok, KStdGuiItem::ok() );
00625 connect( pb, SIGNAL(clicked()), SLOT(
slotOk()) );
00626 }
00627
if( d->mButton.mask & Apply )
00628 {
00629
KPushButton *pb = d->mButton.append( Apply, KStdGuiItem::apply() );
00630 connect( pb, SIGNAL(clicked()), SLOT(
slotApply()) );
00631 connect( pb, SIGNAL(clicked()), SLOT(
applyPressed()) );
00632 }
00633
if( d->mButton.mask & Try )
00634 {
00635
KPushButton *pb = d->mButton.append( Try,
00636 i18n(
"&Try" ) );
00637 connect( pb, SIGNAL(clicked()), SLOT(
slotTry()) );
00638 }
00639
if( d->mButton.mask & Cancel )
00640 {
00641
KPushButton *pb = d->mButton.append( Cancel, KStdGuiItem::cancel() );
00642 connect( pb, SIGNAL(clicked()), SLOT(
slotCancel()) );
00643 }
00644
if( d->mButton.mask & Close )
00645 {
00646
KPushButton *pb = d->mButton.append( Close, KStdGuiItem::close() );
00647 connect( pb, SIGNAL(clicked()), SLOT(
slotClose()) );
00648 }
00649
00650
if( defaultButton !=
NoDefault )
00651 {
00652
QPushButton *pb =
actionButton( defaultButton );
00653
if( pb )
00654 {
00655 setButtonFocus( pb,
true,
false );
00656 }
00657 }
00658
00659 setButtonStyle( KGlobalSettings::buttonLayout() );
00660 }
00661
00662
00663
00664
void KDialogBase::setButtonStyle(
int style )
00665 {
00666
if( !d->mButton.box )
00667 {
00668
return;
00669 }
00670
00671
if( style < 0 || style > ActionStyleMAX ) { style = ActionStyle0; }
00672 d->mButton.style = style;
00673
00674
const int *layout;
00675
int layoutMax = 0;
00676
if (mMessageBoxMode)
00677 {
00678
static const int layoutRule[5][6] =
00679 {
00680 {Details,Stretch,User2|Stretch,User1|Stretch,Cancel|Stretch, Details|Filler},
00681 {Details,Stretch,User2|Stretch,User1|Stretch,Cancel|Stretch, Details|Filler},
00682 {Details,Stretch,User2|Stretch,User1|Stretch,Cancel|Stretch, Details|Filler},
00683 {Details|Filler,Stretch,Cancel|Stretch,User2|Stretch,User1|Stretch,Details},
00684 {Details|Filler,Stretch,Cancel|Stretch,User2|Stretch,User1|Stretch,Details}
00685 };
00686 layoutMax = 6;
00687 layout = layoutRule[ d->mButton.style ];
00688 }
00689
else if (mButtonOrientation == Horizontal)
00690 {
00691
static const int layoutRule[5][10] =
00692 {
00693 {Details,Help,Default,Stretch,User3,User2,User1,Ok,Apply|Try,Cancel|Close},
00694 {Details,Help,Default,Stretch,User3,User2,User1,Cancel|Close,Apply|Try,Ok},
00695 {Details,Help,Default,Stretch,User3,User2,User1,Apply|Try,Cancel|Close,Ok},
00696 {Ok,Apply|Try,Cancel|Close,User3,User2,User1,Stretch,Default,Help,Details},
00697 {Ok,Cancel|Close,Apply|Try,User3,User2,User1,Stretch,Default,Help,Details}
00698 };
00699 layoutMax = 10;
00700 layout = layoutRule[ d->mButton.style ];
00701 }
00702
else
00703 {
00704
static const int layoutRule[5][10] =
00705 {
00706 {Ok,Apply|Try,User1,User2,User3,Stretch,Default,Cancel|Close,Help, Details},
00707
00708 {Details,Help,Default,Stretch,User3,User2,User1,Cancel|Close,Apply|Try,Ok},
00709 {Details,Help,Default,Stretch,User3,User2,User1,Apply|Try,Cancel|Close,Ok},
00710 {Ok,Apply|Try,Cancel|Close,User3,User2,User1,Stretch,Default,Help,Details},
00711 {Ok,Cancel|Close,Apply|Try,User3,User2,User1,Stretch,Default,Help,Details}
00712 };
00713 layoutMax = 10;
00714 layout = layoutRule[ d->mButton.style ];
00715 }
00716
00717
if( d->mButton.box->layout() )
00718 {
00719
delete d->mButton.box->layout();
00720 }
00721
00722 QBoxLayout *lay;
00723
if( mButtonOrientation == Horizontal )
00724 {
00725 lay =
new QBoxLayout( d->mButton.box, QBoxLayout::LeftToRight, 0,
00726
spacingHint());
00727 }
00728
else
00729 {
00730 lay =
new QBoxLayout( d->mButton.box, QBoxLayout::TopToBottom, 0,
00731
spacingHint());
00732 }
00733
00734
int numButton = 0;
00735
QPushButton *prevButton = 0;
00736
QPushButton *newButton;
00737
00738
for(
int i=0; i<layoutMax; ++i )
00739 {
00740
if(((
ButtonCode) layout[i]) == Stretch)
00741 {
00742 lay->
addStretch(1);
00743
continue;
00744 }
00745
else if (layout[i] & Filler)
00746 {
00747
if (d->mButton.mask & layout[i])
00748 {
00749 newButton =
actionButton( (ButtonCode) (layout[i] & ~(Stretch | Filler)));
00750
if (newButton)
00751 lay->
addSpacing(newButton->sizeHint().width());
00752 }
00753
continue;
00754 }
00755
else if( d->mButton.mask & Help & layout[i] )
00756 {
00757 newButton = actionButton( Help );
00758 lay->
addWidget( newButton ); ++numButton;
00759 }
00760
else if( d->mButton.mask & Default & layout[i] )
00761 {
00762 newButton = actionButton( Default );
00763 lay->
addWidget( newButton ); ++numButton;
00764 }
00765
else if( d->mButton.mask & User3 & layout[i] )
00766 {
00767 newButton = actionButton( User3 );
00768 lay->
addWidget( newButton ); ++numButton;
00769 }
00770
else if( d->mButton.mask & User2 & layout[i] )
00771 {
00772 newButton = actionButton( User2 );
00773 lay->
addWidget( newButton ); ++numButton;
00774 }
00775
else if( d->mButton.mask & User1 & layout[i] )
00776 {
00777 newButton = actionButton( User1 );
00778 lay->
addWidget( newButton ); ++numButton;
00779 }
00780
else if( d->mButton.mask & Ok & layout[i] )
00781 {
00782 newButton = actionButton( Ok );
00783 lay->
addWidget( newButton ); ++numButton;
00784 }
00785
else if( d->mButton.mask & Apply & layout[i] )
00786 {
00787 newButton = actionButton( Apply );
00788 lay->
addWidget( newButton ); ++numButton;
00789 }
00790
else if( d->mButton.mask & Try & layout[i] )
00791 {
00792 newButton = actionButton( Try );
00793 lay->
addWidget( newButton ); ++numButton;
00794 }
00795
else if( d->mButton.mask & Cancel & layout[i] )
00796 {
00797 newButton = actionButton( Cancel );
00798 lay->
addWidget( newButton ); ++numButton;
00799 }
00800
else if( d->mButton.mask & Close & layout[i] )
00801 {
00802 newButton = actionButton( Close );
00803 lay->
addWidget( newButton ); ++numButton;
00804 }
00805
else if( d->mButton.mask & Details & layout[i] )
00806 {
00807 newButton = actionButton( Details );
00808 lay->
addWidget( newButton ); ++numButton;
00809 }
00810
else
00811 {
00812
continue;
00813 }
00814
00815
00816
if(layout[i] & Stretch)
00817 {
00818 lay->
addStretch(1);
00819 }
00820
00821
if( prevButton )
00822 {
00823 setTabOrder( prevButton, newButton );
00824 }
00825 prevButton = newButton;
00826 }
00827
00828 d->mButton.resize(
false, 0,
spacingHint(), mButtonOrientation );
00829 }
00830
00831
00832 QPushButton *
KDialogBase::actionButton( ButtonCode
id )
00833 {
00834
return d->mButton.button(
id);
00835 }
00836
00837
00838 void KDialogBase::enableButton( ButtonCode
id,
bool state )
00839 {
00840
QPushButton *pb = actionButton(
id );
00841
if( pb )
00842 {
00843 pb->setEnabled( state );
00844 }
00845 }
00846
00847
00848 void KDialogBase::enableButtonOK(
bool state )
00849 {
00850
enableButton( Ok, state );
00851 }
00852
00853
00854 void KDialogBase::enableButtonApply(
bool state )
00855 {
00856
enableButton( Apply, state );
00857 }
00858
00859
00860 void KDialogBase::enableButtonCancel(
bool state )
00861 {
00862
enableButton( Cancel, state );
00863 }
00864
00865
00866 void KDialogBase::showButton( ButtonCode
id,
bool state )
00867 {
00868
QPushButton *pb = actionButton(
id );
00869
if( pb )
00870 {
00871 state ? pb->show() : pb->hide();
00872 }
00873 }
00874
00875
00876 void KDialogBase::showButtonOK(
bool state )
00877 {
00878
showButton( Ok, state );
00879 }
00880
00881
00882 void KDialogBase::showButtonApply(
bool state )
00883 {
00884
showButton( Apply, state );
00885 }
00886
00887
00888 void KDialogBase::showButtonCancel(
bool state )
00889 {
00890
showButton( Cancel, state );
00891 }
00892
00893
00894 void KDialogBase::setButtonOKText(
const QString &text,
00895
const QString &tooltip,
00896
const QString &quickhelp )
00897 {
00898
QPushButton *pb = actionButton( Ok );
00899
if( !pb )
00900 {
00901
return;
00902 }
00903
00904
const QString whatsThis = i18n(
""
00905
"If you press the <b>OK</b> button, all changes\n"
00906
"you made will be used to proceed.");
00907
00908 pb->
setText( text.
isEmpty() ? i18n(
"&OK") : text );
00909 d->mButton.resize(
false, 0,
spacingHint(), mButtonOrientation );
00910
00911 QToolTip::add( pb, tooltip.
isEmpty() ? i18n(
"Accept settings") : tooltip );
00912 QWhatsThis::add( pb, quickhelp.
isEmpty() ? whatsThis : quickhelp );
00913 }
00914
00915
00916 void KDialogBase::setButtonOK(
const KGuiItem &item )
00917 {
00918
setButtonGuiItem( Ok, item );
00919 }
00920
00921
00922 void KDialogBase::setButtonApplyText(
const QString &text,
00923
const QString &tooltip,
00924
const QString &quickhelp )
00925 {
00926
QPushButton *pb = actionButton( Apply );
00927
if( !pb )
00928 {
00929
return;
00930 }
00931
00932
const QString whatsThis = i18n(
""
00933
"When clicking <b>Apply</b>, the settings will be\n"
00934
"handed over to the program, but the dialog\n"
00935
"will not be closed. "
00936
"Use this to try different settings. ");
00937
00938 pb->
setText( text.
isEmpty() ? i18n(
"&Apply") : text );
00939 d->mButton.resize(
false, 0,
spacingHint(), mButtonOrientation );
00940
00941 QToolTip::add( pb, tooltip.
isEmpty() ? i18n(
"Apply settings") : tooltip );
00942 QWhatsThis::add( pb, quickhelp.
isEmpty() ? whatsThis : quickhelp );
00943 }
00944
00945
00946 void KDialogBase::setButtonApply(
const KGuiItem &item )
00947 {
00948
setButtonGuiItem( Apply, item );
00949 }
00950
00951
00952 void KDialogBase::setButtonCancelText(
const QString& text,
00953
const QString& tooltip,
00954
const QString& quickhelp )
00955 {
00956
QPushButton *pb = actionButton( Cancel );
00957
if( !pb )
00958 {
00959
return;
00960 }
00961
00962 pb->
setText( text.
isEmpty() ? i18n(
"&Cancel") : text );
00963 d->mButton.resize(
false, 0,
spacingHint(), mButtonOrientation );
00964
00965 QToolTip::add( pb, tooltip );
00966 QWhatsThis::add( pb, quickhelp );
00967 }
00968
00969
00970 void KDialogBase::setButtonCancel(
const KGuiItem &item )
00971 {
00972
setButtonGuiItem( Cancel, item );
00973 }
00974
00975 void KDialogBase::setButtonGuiItem( ButtonCode
id,
const KGuiItem &item )
00976 {
00977
KPushButton *pb = static_cast<KPushButton *>( actionButton(
id ) );
00978
if( !pb )
00979
return;
00980
00981 pb->
setGuiItem( item );
00982 d->mButton.resize(
false, 0,
spacingHint(), mButtonOrientation );
00983 }
00984
00985
00986 void KDialogBase::setButtonText( ButtonCode
id,
const QString &text )
00987 {
00988
if (!d->bSettingDetails && (
id == Details))
00989 {
00990 d->detailsButton = text;
00991
setDetails(d->bDetails);
00992
return;
00993 }
00994
QPushButton *pb = actionButton(
id );
00995
if( pb )
00996 {
00997 pb->
setText( text );
00998 d->mButton.resize(
false, 0,
spacingHint(), mButtonOrientation );
00999 }
01000 }
01001
01002
01003 void KDialogBase::setButtonTip( ButtonCode
id,
const QString &text )
01004 {
01005
QPushButton *pb = actionButton(
id );
01006
if( pb )
01007 {
01008
if (text.
isEmpty())
01009 QToolTip::remove( pb );
01010
else
01011 QToolTip::add( pb, text );
01012 }
01013 }
01014
01015
01016 void KDialogBase::setButtonWhatsThis( ButtonCode
id,
const QString &text )
01017 {
01018
QPushButton *pb = actionButton(
id );
01019
if( pb )
01020 {
01021
if (text.
isEmpty())
01022 QWhatsThis::remove( pb );
01023
else
01024 QWhatsThis::add( pb, text );
01025 }
01026 }
01027
01028
01029
void KDialogBase::setButtonFocus(
QPushButton *p,
bool isDefault,
bool isFocus )
01030 {
01031 p->
setDefault( isDefault );
01032
if( isFocus )
01033 p->setFocus();
01034 }
01035
01036
01037 void KDialogBase::setTreeListAutoResize(
bool state )
01038 {
01039
if( mJanus )
01040 {
01041 mJanus->
setTreeListAutoResize( state );
01042 }
01043 }
01044
01045 void KDialogBase::setShowIconsInTreeList(
bool state)
01046 {
01047
if( mJanus )
01048 {
01049 mJanus->
setShowIconsInTreeList( state );
01050 }
01051 }
01052
01053 void KDialogBase::setRootIsDecorated(
bool state )
01054 {
01055
if( mJanus )
01056 {
01057 mJanus->
setRootIsDecorated( state );
01058 }
01059 }
01060
01061 void KDialogBase::unfoldTreeList(
bool persist )
01062 {
01063
if( mJanus )
01064 mJanus->
unfoldTreeList( persist );
01065 }
01066
01067 void KDialogBase::addWidgetBelowList(
QWidget * widget )
01068 {
01069
if( mJanus )
01070 mJanus->
addWidgetBelowList( widget );
01071 }
01072
01073 void KDialogBase::addButtonBelowList(
const QString & text,
QObject * recv,
const char * slot )
01074 {
01075
if( mJanus )
01076 mJanus->
addButtonBelowList( text, recv, slot );
01077 }
01078
01079 void KDialogBase::addButtonBelowList(
const KGuiItem & item,
QObject * recv,
const char * slot )
01080 {
01081
if( mJanus )
01082 mJanus->
addButtonBelowList( item, recv, slot );
01083 }
01084
01085 void KDialogBase::setIconListAllVisible(
bool state )
01086 {
01087
if( mJanus )
01088 {
01089 mJanus->
setIconListAllVisible( state );
01090 }
01091 }
01092
01093
01094 void KDialogBase::slotHelp()
01095 {
01096 emit
helpClicked();
01097
if ( kapp )
01098 kapp->invokeHelp( mAnchor, mHelpApp );
01099 }
01100
01101
01102 void KDialogBase::slotDefault()
01103 {
01104 emit
defaultClicked();
01105 }
01106
01107 void KDialogBase::slotDetails()
01108 {
01109
setDetails(!d->bDetails);
01110 }
01111
01112 void KDialogBase::setDetailsWidget(
QWidget *detailsWidget)
01113 {
01114
delete d->detailsWidget;
01115 d->detailsWidget = detailsWidget;
01116
if (d->detailsWidget->parentWidget() !=
this)
01117 d->detailsWidget->reparent(
this,
QPoint(0,0));
01118 d->detailsWidget->hide();
01119
if( mIsActivated )
01120 {
01121 setupLayout();
01122 }
01123
if (!d->bSettingDetails)
01124
setDetails(d->bDetails);
01125 }
01126
01127 void KDialogBase::setDetails(
bool showDetails)
01128 {
01129
if (d->detailsButton.isEmpty())
01130 d->detailsButton = i18n(
"&Details");
01131 d->bSettingDetails =
true;
01132 d->bDetails = showDetails;
01133
if (d->bDetails)
01134 {
01135 emit
aboutToShowDetails();
01136
setButtonText(Details, d->detailsButton+
" <<");
01137
if (d->detailsWidget)
01138 {
01139
if (layout())
01140 layout()->setEnabled(
false);
01141
adjustSize();
01142 d->detailsWidget->show();
01143
if (layout())
01144 {
01145 layout()->activate();
01146 layout()->setEnabled(
true);
01147 }
01148 }
01149 }
01150
else
01151 {
01152
setButtonText(Details, d->detailsButton+
" >>");
01153
if (d->detailsWidget)
01154 {
01155 d->detailsWidget->hide();
01156 }
01157
if (layout())
01158 layout()->activate();
01159
adjustSize();
01160 }
01161 d->bSettingDetails =
false;
01162 }
01163
01164 void KDialogBase::slotOk()
01165 {
01166 emit
okClicked();
01167
accept();
01168 }
01169
01170
01171 void KDialogBase::slotApply()
01172 {
01173 emit
applyClicked();
01174 }
01175
01176
01177 void KDialogBase::slotTry()
01178 {
01179 emit
tryClicked();
01180 }
01181
01182
01183 void KDialogBase::slotUser3()
01184 {
01185 emit
user3Clicked();
01186 }
01187
01188
01189 void KDialogBase::slotUser2()
01190 {
01191 emit
user2Clicked();
01192 }
01193
01194
01195 void KDialogBase::slotUser1()
01196 {
01197 emit
user1Clicked();
01198 }
01199
01200
01201 void KDialogBase::slotYes()
01202 {
01203 emit
yesClicked();
01204 done( Yes );
01205 }
01206
01207
01208 void KDialogBase::slotNo()
01209 {
01210 emit
noClicked();
01211 done( No );
01212 }
01213
01214
01215 void KDialogBase::slotCancel()
01216 {
01217 emit
cancelClicked();
01218 done( mMessageBoxMode ? (
int)Cancel : (
int)Rejected );
01219 }
01220
01221
01222 void KDialogBase::slotClose()
01223 {
01224 emit
closeClicked();
01225
reject();
01226 }
01227
01228
01229 void KDialogBase::helpClickedSlot(
const QString & )
01230 {
01231
slotHelp();
01232 }
01233
01234
01235 void KDialogBase::applyPressed()
01236 {
01237 emit
apply();
01238 }
01239
01240
01241 void KDialogBase::enableLinkedHelp(
bool state )
01242 {
01243
if( state )
01244 {
01245
if( mUrlHelp )
01246 {
01247
return;
01248 }
01249
01250 mUrlHelp =
new KURLLabel(
this,
"url" );
01251 mUrlHelp->
setText(
helpLinkText() );
01252 mUrlHelp->
setFloat(
true);
01253 mUrlHelp->
setUnderline(
true);
01254
if( mShowTile && mTile->
get() )
01255 {
01256 mUrlHelp->setBackgroundPixmap(*mTile->
get());
01257 }
01258 mUrlHelp->setMinimumHeight( fontMetrics().height() +
marginHint() );
01259 connect(mUrlHelp,SIGNAL(leftClickedURL(
const QString &)),
01260 SLOT(
helpClickedSlot(
const QString &)));
01261 mUrlHelp->show();
01262 }
01263
else
01264 {
01265
if( !mUrlHelp )
01266 {
01267
return;
01268 }
01269
delete mUrlHelp; mUrlHelp = 0;
01270 }
01271
01272
if( mIsActivated )
01273 {
01274 setupLayout();
01275 }
01276 }
01277
01278
01279 void KDialogBase::setHelp(
const QString &anchor,
const QString &appname )
01280 {
01281 mAnchor = anchor;
01282 mHelpApp = appname;
01283 }
01284
01285
01286 void KDialogBase::setHelpLinkText(
const QString &text )
01287 {
01288 mHelpLinkText = text;
01289
if( mUrlHelp )
01290 {
01291 mUrlHelp->
setText(
helpLinkText() );
01292 }
01293 }
01294
01295
01296 QFrame *
KDialogBase::addPage(
const QString &itemName,
const QString &header,
01297
const QPixmap &pixmap )
01298 {
01299
return ( mJanus ? mJanus->
addPage( itemName, header, pixmap ) : 0);
01300 }
01301
01302 QFrame *
KDialogBase::addPage(
const QStringList &items,
const QString &header,
01303
const QPixmap &pixmap )
01304 {
01305
return ( mJanus ? mJanus->
addPage( items, header, pixmap ) : 0);
01306 }
01307
01308
01309 QVBox *
KDialogBase::addVBoxPage(
const QString &itemName,
01310
const QString &header,
const QPixmap &pixmap )
01311 {
01312
return ( mJanus ? mJanus->
addVBoxPage( itemName, header, pixmap) : 0);
01313 }
01314
01315 QVBox *
KDialogBase::addVBoxPage(
const QStringList &items,
01316
const QString &header,
const QPixmap &pixmap )
01317 {
01318
return ( mJanus ? mJanus->
addVBoxPage( items, header, pixmap) : 0);
01319 }
01320
01321
01322 QHBox *
KDialogBase::addHBoxPage(
const QString &itemName,
01323
const QString &header,
01324
const QPixmap &pixmap )
01325 {
01326
return ( mJanus ? mJanus->
addHBoxPage( itemName, header, pixmap ) : 0);
01327 }
01328
01329 QHBox *
KDialogBase::addHBoxPage(
const QStringList &items,
01330
const QString &header,
01331
const QPixmap &pixmap )
01332 {
01333
return ( mJanus ? mJanus->
addHBoxPage( items, header, pixmap ) : 0);
01334 }
01335
01336
01337 QGrid *
KDialogBase::addGridPage(
int n, Orientation dir,
01338
const QString &itemName,
01339
const QString &header,
const QPixmap &pixmap )
01340 {
01341
return ( mJanus ? mJanus->
addGridPage( n, dir, itemName, header, pixmap) : 0);
01342 }
01343
01344 QGrid *
KDialogBase::addGridPage(
int n, Orientation dir,
01345
const QStringList &items,
01346
const QString &header,
const QPixmap &pixmap )
01347 {
01348
return ( mJanus ? mJanus->
addGridPage( n, dir, items, header, pixmap) : 0);
01349 }
01350
01351 void KDialogBase::setFolderIcon(
const QStringList &path,
const QPixmap &pixmap)
01352 {
01353
if (!mJanus)
01354
return;
01355
01356 mJanus->
setFolderIcon(path,pixmap);
01357 }
01358
01359 QFrame *
KDialogBase::makeMainWidget()
01360 {
01361
if( mJanus || mMainWidget )
01362 {
01363 printMakeMainWidgetError();
01364
return 0;
01365 }
01366
01367
QFrame *
mainWidget =
new QFrame(
this );
01368
setMainWidget( mainWidget );
01369
return mainWidget;
01370 }
01371
01372
01373 QVBox *
KDialogBase::makeVBoxMainWidget()
01374 {
01375
if( mJanus || mMainWidget )
01376 {
01377 printMakeMainWidgetError();
01378
return 0;
01379 }
01380
01381
QVBox *
mainWidget =
new QVBox(
this );
01382 mainWidget->setSpacing(
spacingHint() );
01383
setMainWidget( mainWidget );
01384
return mainWidget;
01385 }
01386
01387
01388 QHBox *
KDialogBase::makeHBoxMainWidget()
01389 {
01390
if( mJanus || mMainWidget )
01391 {
01392 printMakeMainWidgetError();
01393
return 0;
01394 }
01395
01396
QHBox *
mainWidget =
new QHBox(
this );
01397 mainWidget->
setSpacing(
spacingHint() );
01398
setMainWidget( mainWidget );
01399
return mainWidget;
01400 }
01401
01402
01403 QGrid *
KDialogBase::makeGridMainWidget(
int n, Orientation dir )
01404 {
01405
if( mJanus || mMainWidget )
01406 {
01407 printMakeMainWidgetError();
01408
return 0;
01409 }
01410
01411
QGrid *
mainWidget =
new QGrid( n, dir,
this );
01412 mainWidget->
setSpacing(
spacingHint() );
01413
setMainWidget( mainWidget );
01414
return mainWidget;
01415 }
01416
01417
01418
void KDialogBase::printMakeMainWidgetError()
01419 {
01420
if( mJanus )
01421 {
01422
kdDebug() <<
"makeMainWidget: Illegal mode (wrong constructor)" <<
endl;
01423 }
01424
else if( mMainWidget )
01425 {
01426
kdDebug() <<
"makeMainWidget: Main widget already defined" <<
endl;
01427 }
01428 }
01429
01430
01431 void KDialogBase::setMainWidget(
QWidget *widget )
01432 {
01433
if( mJanus )
01434 {
01435
if( mJanus->
setSwallowedWidget(widget) )
01436 {
01437 mMainWidget = widget;
01438 }
01439 }
01440
else
01441 {
01442 mMainWidget = widget;
01443
if( mIsActivated )
01444 {
01445 setupLayout();
01446 }
01447 }
01448
if( mMainWidget != NULL )
01449 {
01450
QFocusData* fd = focusData();
01451
QWidget* prev = fd->
last();
01452
for(
QPtrListIterator<KDialogBaseButton> it( d->mButton.list );
01453 it != NULL;
01454 ++it )
01455 {
01456
if( prev != *it )
01457 setTabOrder( prev, *it );
01458 prev = *it;
01459 }
01460 }
01461 }
01462
01463
01464 QWidget *
KDialogBase::mainWidget()
01465 {
01466
return mMainWidget;
01467 }
01468
01469
01470 bool KDialogBase::showPage(
int index )
01471 {
01472
return ( mJanus ? mJanus->
showPage(index) :
false);
01473 }
01474
01475
01476 int KDialogBase::activePageIndex()
const
01477
{
01478
return ( mJanus ? mJanus->
activePageIndex() : -1);
01479 }
01480
01481
01482 int KDialogBase::pageIndex(
QWidget *widget )
const
01483
{
01484
return ( mJanus ? mJanus->
pageIndex( widget) : -1);
01485 }
01486
01487
01488
01489 QRect KDialogBase::getContentsRect()
const
01490
{
01491
QRect r;
01492 r.
setLeft(
marginHint() );
01493 r.
setTop(
marginHint() + (mUrlHelp ? mUrlHelp->height() : 0) );
01494 r.
setRight( width() -
marginHint() );
01495
int h = (!mActionSep ? 0 : mActionSep->minimumSize().height()+
marginHint());
01496
if( d->mButton.box )
01497 {
01498 r.
setBottom( height() - d->mButton.box->minimumSize().height() - h );
01499 }
01500
else
01501 {
01502 r.
setBottom( height() - h );
01503 }
01504
01505
return r;
01506 }
01507
01508
01509
01510 void KDialogBase::getBorderWidths(
int& ulx,
int& uly,
int& lrx,
int& lry)
const
01511
{
01512 ulx =
marginHint();
01513 uly =
marginHint();
01514
if( mUrlHelp )
01515 {
01516 uly += mUrlHelp->minimumSize().height();
01517 }
01518
01519 lrx =
marginHint();
01520 lry = d->mButton.box ? d->mButton.box->minimumSize().height() : 0;
01521
if( mActionSep )
01522 {
01523 lry += mActionSep->minimumSize().height() +
marginHint();
01524 }
01525 }
01526
01527
01528 QSize KDialogBase::calculateSize(
int w,
int h)
const
01529
{
01530
int ulx, uly, lrx, lry;
01531
getBorderWidths(ulx, uly, lrx, lry);
01532
return QSize(ulx+w+lrx,uly+h+lry);
01533 }
01534
01535
01536 QString KDialogBase::helpLinkText()
const
01537
{
01538
return ( mHelpLinkText.
isNull() ? i18n(
"Get help...") : mHelpLinkText );
01539 }
01540
01541
01542 void KDialogBase::updateGeometry()
01543 {
01544
if( mTopLayout )
01545 {
01546 mTopLayout->
setMargin(
marginHint() );
01547 mTopLayout->
setSpacing(
spacingHint() );
01548 }
01549 }
01550
01551
01552
01553 void KDialogBase::keyPressEvent(
QKeyEvent *e )
01554 {
01555
01556
01557
01558
01559
if( e->
state() == 0 )
01560 {
01561
if( e->
key() == Key_F1 )
01562 {
01563
QPushButton *pb = actionButton( Help );
01564
if( pb )
01565 {
01566 pb->animateClick();
01567 e->
accept();
01568
return;
01569 }
01570 }
01571
if( e->
key() == Key_Escape )
01572 {
01573
QPushButton *pb = actionButton( mEscapeButton );
01574
if( pb )
01575 {
01576 pb->animateClick();
01577 e->
accept();
01578
return;
01579 }
01580
01581 }
01582 }
01583
else if( e->
key() == Key_F1 && e->
state() == ShiftButton )
01584 {
01585
QWhatsThis::enterWhatsThisMode();
01586 e->
accept();
01587
return;
01588 }
01589
01590
01591
else if ( e->
state() == ControlButton &&
01592 (e->
key() == Key_Return || e->
key() == Key_Enter) )
01593 {
01594
QPushButton *pb = actionButton( Ok );
01595
if ( pb )
01596 {
01597 pb->animateClick();
01598 e->
accept();
01599
return;
01600 }
01601 }
01602
01603
01604
01605
01606 QDialog::keyPressEvent(e);
01607 }
01608
01609
01610
01611 void KDialogBase::hideEvent(
QHideEvent *ev )
01612 {
01613 emit
hidden();
01614
if (!ev->spontaneous())
01615 {
01616 emit
finished();
01617 }
01618 }
01619
01620
01621
01622 void KDialogBase::closeEvent(
QCloseEvent *e )
01623 {
01624
QPushButton *pb = actionButton( mEscapeButton );
01625
if( pb && isShown() ) {
01626 pb->animateClick();
01627 }
else {
01628 QDialog::closeEvent( e );
01629 }
01630 }
01631
01632 void KDialogBase::cancel()
01633 {
01634
switch ( mEscapeButton ) {
01635
case Ok:
01636
slotOk();
01637
break;
01638
case User1:
01639
if ( mMessageBoxMode )
01640
slotNo();
01641
else
01642
slotUser1();
01643
break;
01644
case User2:
01645
if ( mMessageBoxMode )
01646
slotYes();
01647
else
01648
slotUser2();
01649
break;
01650
case User3:
01651
slotUser3();
01652
break;
01653
case Close:
01654
slotClose();
01655
break;
01656
case Cancel:
01657
default:
01658
slotCancel();
01659 }
01660 }
01661
01662 bool KDialogBase::haveBackgroundTile()
01663 {
01664
return ( !mTile || mTile->
get() );
01665 }
01666
01667
01668 const QPixmap *
KDialogBase::getBackgroundTile() {
return backgroundTile(); }
01669
01670 const QPixmap *
KDialogBase::backgroundTile()
01671 {
01672
return ( mTile ? mTile->
get() : 0);
01673 }
01674
01675
01676 void KDialogBase::setBackgroundTile(
const QPixmap *pix )
01677 {
01678
if( mTile )
01679 {
01680 mTile->
set( pix );
01681 }
01682 }
01683
01684
01685 void KDialogBase::updateBackground()
01686 {
01687
if( !mTile || !mTile->
get() )
01688 {
01689
QPixmap nullPixmap;
01690 setBackgroundPixmap(nullPixmap);
01691
if( d->mButton.box )
01692 {
01693 d->mButton.box->setBackgroundPixmap(nullPixmap);
01694 d->mButton.box->setBackgroundMode(PaletteBackground);
01695 }
01696 setBackgroundMode(PaletteBackground);
01697 }
01698
else
01699 {
01700
const QPixmap *pix = mTile->
get();
01701 setBackgroundPixmap(*pix);
01702
if( d->mButton.box )
01703 {
01704 d->mButton.box->setBackgroundPixmap(*pix);
01705 }
01706
showTile( mShowTile );
01707 }
01708 }
01709
01710
01711 void KDialogBase::showTile(
bool state )
01712 {
01713 mShowTile = state;
01714
if( !mShowTile || !mTile || !mTile->
get() )
01715 {
01716 setBackgroundMode(PaletteBackground);
01717
if( d->mButton.box )
01718 {
01719 d->mButton.box->setBackgroundMode(PaletteBackground);
01720 }
01721
if( mUrlHelp )
01722 {
01723 mUrlHelp->setBackgroundMode(PaletteBackground);
01724 }
01725 }
01726
else
01727 {
01728
const QPixmap *pix = mTile->
get();
01729 setBackgroundPixmap(*pix);
01730
if( d->mButton.box )
01731 {
01732 d->mButton.box->setBackgroundPixmap(*pix);
01733 }
01734
if( mUrlHelp )
01735 {
01736 mUrlHelp->setBackgroundPixmap(*pix);
01737 }
01738 }
01739 }
01740
01741 QSize KDialogBase::configDialogSize(
const QString& groupName )
const
01742
{
01743
return configDialogSize( *KGlobal::config(), groupName );
01744 }
01745
01746
01747 QSize KDialogBase::configDialogSize(
KConfig& config,
01748
const QString& groupName )
const
01749
{
01750
int w, h;
01751
int scnum =
QApplication::desktop()->screenNumber(parentWidget());
01752
QRect desk =
QApplication::desktop()->screenGeometry(scnum);
01753
01754 w = sizeHint().
width();
01755 h = sizeHint().height();
01756
01757
KConfigGroupSaver cs(&config, groupName);
01758 w = config.
readNumEntry( QString::fromLatin1(
"Width %1").arg( desk.
width()), w );
01759 h = config.
readNumEntry( QString::fromLatin1(
"Height %1").arg( desk.
height()), h );
01760
01761
return QSize( w, h );
01762 }
01763
01764
01765 void KDialogBase::saveDialogSize(
const QString& groupName,
bool global )
01766 {
01767
saveDialogSize( *KGlobal::config(), groupName, global );
01768 }
01769
01770
01771 void KDialogBase::saveDialogSize(
KConfig& config,
const QString& groupName,
01772
bool global )
const
01773
{
01774
int scnum =
QApplication::desktop()->screenNumber(parentWidget());
01775
QRect desk =
QApplication::desktop()->screenGeometry(scnum);
01776
01777
KConfigGroupSaver cs(&config, groupName);
01778
QSize sizeToSave = size();
01779
01780 config.
writeEntry( QString::fromLatin1(
"Width %1").arg( desk.
width()),
01781 QString::number( sizeToSave.
width()),
true, global);
01782 config.
writeEntry( QString::fromLatin1(
"Height %1").arg( desk.
height()),
01783 QString::number( sizeToSave.
height()),
true, global);
01784 }
01785
01786
01787 KDialogBaseButton::KDialogBaseButton(
const KGuiItem &item,
int key,
01788
QWidget *parent,
const char *name )
01789 :
KPushButton( item, parent, name ), mKey(key)
01790 {
01791 }
01792
01793
01794
01795
01796 KDialogBaseTile::KDialogBaseTile(
QObject *parent,
const char *name )
01797 :
QObject( parent,
name ), mPixmap(0)
01798 {
01799 }
01800
01801
01802 KDialogBaseTile::~KDialogBaseTile()
01803 {
01804 cleanup();
01805 }
01806
01807
01808
void KDialogBaseTile::set(
const QPixmap *pix )
01809 {
01810
if( !pix )
01811 {
01812 cleanup();
01813 }
01814
else
01815 {
01816
if( !mPixmap )
01817 {
01818 mPixmap =
new QPixmap(*pix);
01819 }
01820
else
01821 {
01822 *mPixmap = *pix;
01823 }
01824 }
01825
01826 emit pixmapChanged();
01827 }
01828
01829
01830
const QPixmap *KDialogBaseTile::get()
const
01831
{
01832
return mPixmap;
01833 }
01834
01835
01836
void KDialogBaseTile::cleanup()
01837 {
01838
delete mPixmap; mPixmap = 0;
01839 }
01840
01841
void KDialogBase::virtual_hook(
int id,
void* data )
01842 { KDialog::virtual_hook(
id, data ); }
01843
01844
#include "kdialogbase.moc"