00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "kicondialog.h"
00015
00016 #include <kio/kio_export.h>
00017
00018 #include <kbuttongroup.h>
00019 #include <kcombobox.h>
00020 #include <klistwidgetsearchline.h>
00021 #include <kapplication.h>
00022 #include <klocale.h>
00023 #include <kstandarddirs.h>
00024 #include <kiconloader.h>
00025 #include <kfiledialog.h>
00026 #include <kimagefilepreview.h>
00027 #include <ksvgrenderer.h>
00028
00029 #include <QtGui/QLayout>
00030 #include <QtGui/QLabel>
00031 #include <QtCore/QTimer>
00032 #include <QtGui/QRadioButton>
00033 #include <QtCore/QFileInfo>
00034 #include <QtGui/QProgressBar>
00035 #include <QtGui/QPainter>
00036
00037 class KIconCanvas::KIconCanvasPrivate
00038 {
00039 public:
00040 KIconCanvasPrivate(KIconCanvas *qq) { q = qq; m_bLoading = false; }
00041 ~KIconCanvasPrivate() {}
00042 KIconCanvas *q;
00043 bool m_bLoading;
00044 QStringList mFiles;
00045 QTimer *mpTimer;
00046
00047
00048 void _k_slotLoadFiles();
00049 void _k_slotCurrentChanged(QListWidgetItem *item);
00050 };
00051
00055 class IconPath : public QString
00056 {
00057 protected:
00058 QString m_iconName;
00059
00060 public:
00061 IconPath(const QString &ip) : QString (ip)
00062 {
00063 int n = lastIndexOf('/');
00064 m_iconName = (n==-1) ? static_cast<QString>(*this) : mid(n+1);
00065 }
00066
00067
00068 IconPath() : QString ()
00069 { }
00070
00071 bool operator== (const IconPath &ip) const
00072 { return m_iconName == ip.m_iconName; }
00073
00074 bool operator< (const IconPath &ip) const
00075 { return m_iconName < ip.m_iconName; }
00076
00077 };
00078
00079
00080
00081
00082
00083 KIconCanvas::KIconCanvas(QWidget *parent)
00084 : KListWidget(parent), d(new KIconCanvasPrivate(this))
00085 {
00086 setViewMode(IconMode);
00087 setUniformItemSizes(true);
00088 setMovement(Static);
00089 setIconSize(QSize(60, 60));
00090 d->mpTimer = new QTimer(this);
00091 connect(d->mpTimer, SIGNAL(timeout()), this, SLOT(_k_slotLoadFiles()));
00092 connect(this, SIGNAL( currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
00093 this, SLOT(_k_slotCurrentChanged(QListWidgetItem *)));
00094 setGridSize(QSize(80,80));
00095 }
00096
00097 KIconCanvas::~KIconCanvas()
00098 {
00099 delete d->mpTimer;
00100 delete d;
00101 }
00102
00103 void KIconCanvas::loadFiles(const QStringList& files)
00104 {
00105 clear();
00106 d->mFiles = files;
00107 emit startLoading(d->mFiles.count());
00108 d->mpTimer->setSingleShot(true);
00109 d->mpTimer->start(10);
00110 d->m_bLoading = false;
00111 }
00112
00113 void KIconCanvas::KIconCanvasPrivate::_k_slotLoadFiles()
00114 {
00115 q->setResizeMode(QListWidget::Fixed);
00116 QApplication::setOverrideCursor(Qt::WaitCursor);
00117
00118
00119 q->setUpdatesEnabled(false);
00120
00121 m_bLoading = true;
00122 int i;
00123 QStringList::ConstIterator it;
00124 uint emitProgress = 10;
00125 QStringList::ConstIterator end(mFiles.end());
00126 for (it=mFiles.begin(), i=0; it!=end; ++it, i++)
00127 {
00128 if ( emitProgress >= 10 ) {
00129 emit q->progress(i);
00130 emitProgress = 0;
00131 }
00132
00133 emitProgress++;
00134
00135 if (!m_bLoading) {
00136 break;
00137 }
00138 QImage img;
00139
00140
00141 QString path= *it;
00142 QString ext = path.right(3).toUpper();
00143
00144 if (ext != "SVG" && ext != "VGZ")
00145 img.load(*it);
00146 else {
00147
00148 img = QImage(60, 60, QImage::Format_ARGB32_Premultiplied);
00149 img.fill(0);
00150 KSvgRenderer renderer(*it);
00151 if (renderer.isValid()) {
00152 QPainter p(&img);
00153 renderer.render(&p);
00154 }
00155 }
00156
00157 if (img.isNull())
00158 continue;
00159 if (img.width() > 60 || img.height() > 60)
00160 {
00161 if (img.width() > img.height())
00162 {
00163 int height = (int) ((60.0 / img.width()) * img.height());
00164 img = img.scaled(60, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
00165 } else
00166 {
00167 int width = (int) ((60.0 / img.height()) * img.width());
00168 img = img.scaled(width, 60, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
00169 }
00170 }
00171 QPixmap pm = QPixmap::fromImage(img);
00172 QFileInfo fi(*it);
00173 QListWidgetItem *item = new QListWidgetItem(pm, fi.completeBaseName(), q);
00174 item->setData(Qt::UserRole, *it);
00175 item->setToolTip(fi.completeBaseName());
00176 }
00177
00178
00179 q->setUpdatesEnabled(true);
00180
00181 QApplication::restoreOverrideCursor();
00182 m_bLoading = false;
00183 emit q->finished();
00184 q->setResizeMode(QListWidget::Adjust);
00185 }
00186
00187 QString KIconCanvas::getCurrent() const
00188 {
00189 if (!currentItem())
00190 return QString();
00191 return currentItem()->data(Qt::UserRole).toString();
00192 }
00193
00194 void KIconCanvas::stopLoading()
00195 {
00196 d->m_bLoading = false;
00197 }
00198
00199 void KIconCanvas::KIconCanvasPrivate::_k_slotCurrentChanged(QListWidgetItem *item)
00200 {
00201 emit q->nameChanged((item != 0L) ? item->text() : QString());
00202 }
00203
00204 class KIconDialog::KIconDialogPrivate
00205 {
00206 public:
00207 KIconDialogPrivate(KIconDialog *qq) {
00208 q = qq;
00209 m_bStrictIconSize = true;
00210 m_bLockUser = false;
00211 m_bLockCustomDir = false;
00212 searchLine = 0;
00213 mNumOfSteps = 1;
00214 }
00215 ~KIconDialogPrivate() {}
00216
00217 void init();
00218 void showIcons();
00219 void setContext( KIconLoader::Context context );
00220
00221
00222 void _k_slotContext(int);
00223 void _k_slotStartLoading(int);
00224 void _k_slotProgress(int);
00225 void _k_slotFinished();
00226 void _k_slotAcceptIcons();
00227 void _k_slotBrowse();
00228 void _k_slotOtherIconClicked();
00229 void _k_slotSystemIconClicked();
00230
00231 KIconDialog *q;
00232
00233 int mGroupOrSize;
00234 KIconLoader::Context mContext;
00235
00236 QStringList mFileList;
00237 KComboBox *mpCombo;
00238 QPushButton *mpBrowseBut;
00239 QRadioButton *mpSystemIcons, *mpOtherIcons;
00240 QProgressBar *mpProgress;
00241 int mNumOfSteps;
00242 KIconLoader *mpLoader;
00243 KIconCanvas *mpCanvas;
00244 int mNumContext;
00245 KIconLoader::Context mContextMap[ 12 ];
00246
00247 bool m_bStrictIconSize, m_bLockUser, m_bLockCustomDir;
00248 QString custom;
00249 QString customLocation;
00250 KListWidgetSearchLine *searchLine;
00251 };
00252
00253
00254
00255
00256
00257
00258 KIconDialog::KIconDialog(QWidget *parent)
00259 : KDialog(parent), d(new KIconDialogPrivate(this))
00260 {
00261 setModal( true );
00262 setCaption( i18n("Select Icon") );
00263 setButtons( Ok | Cancel );
00264 setDefaultButton( Ok );
00265
00266 d->mpLoader = KIconLoader::global();
00267 d->init();
00268 }
00269
00270 KIconDialog::KIconDialog(KIconLoader *loader, QWidget *parent)
00271 : KDialog(parent), d(new KIconDialogPrivate(this))
00272 {
00273 setModal( true );
00274 setCaption( i18n("Select Icon") );
00275 setButtons( Ok | Cancel );
00276 setDefaultButton( Ok );
00277
00278 d->mpLoader = loader;
00279 d->init();
00280 }
00281
00282 void KIconDialog::KIconDialogPrivate::init()
00283 {
00284 mGroupOrSize = KIconLoader::Desktop;
00285 mContext = KIconLoader::Any;
00286 mFileList = KGlobal::dirs()->findAllResources("appicon", QLatin1String("*.png"));
00287
00288 QWidget *main = new QWidget(q);
00289 q->setMainWidget(main);
00290
00291 QVBoxLayout *top = new QVBoxLayout(main);
00292 top->setMargin(0);
00293
00294 QGroupBox *bgroup = new QGroupBox(main);
00295 bgroup->setTitle(i18n("Icon Source"));
00296
00297 QVBoxLayout *vbox = new QVBoxLayout;
00298 bgroup->setLayout( vbox );
00299 top->addWidget(bgroup);
00300
00301 QGridLayout *grid = new QGridLayout();
00302 grid->setSpacing(KDialog::spacingHint());
00303 bgroup->layout()->addItem(grid);
00304
00305 mpSystemIcons = new QRadioButton(i18n("S&ystem icons:"), bgroup);
00306 connect(mpSystemIcons, SIGNAL(clicked()), q, SLOT(_k_slotSystemIconClicked()));
00307 grid->addWidget(mpSystemIcons, 1, 0);
00308 mpCombo = new KComboBox(bgroup);
00309 connect(mpCombo, SIGNAL(activated(int)), q, SLOT(_k_slotContext(int)));
00310 grid->addWidget(mpCombo, 1, 1);
00311 mpOtherIcons = new QRadioButton(i18n("O&ther icons:"), bgroup);
00312 connect(mpOtherIcons, SIGNAL(clicked()), q, SLOT(_k_slotOtherIconClicked()));
00313 grid->addWidget(mpOtherIcons, 2, 0);
00314 mpBrowseBut = new QPushButton(i18n("&Browse..."), bgroup);
00315 connect(mpBrowseBut, SIGNAL(clicked()), q, SLOT(_k_slotBrowse()));
00316 grid->addWidget(mpBrowseBut, 2, 1);
00317
00318
00319
00320
00321 QHBoxLayout *searchLayout = new QHBoxLayout();
00322 searchLayout->setMargin(0);
00323 searchLayout->setSpacing(KDialog::spacingHint());
00324 top->addLayout(searchLayout);
00325
00326 QLabel *searchLabel = new QLabel(i18n("&Search:"), main);
00327 searchLayout->addWidget(searchLabel);
00328
00329 searchLine = new KListWidgetSearchLine(main);
00330 searchLayout->addWidget(searchLine);
00331 searchLabel->setBuddy(searchLine);
00332
00333 QString wtstr = i18n("Search interactively for icon names (e.g. folder).");
00334 searchLabel->setWhatsThis(wtstr);
00335 searchLine->setWhatsThis(wtstr);
00336
00337
00338 mpCanvas = new KIconCanvas(main);
00339 connect(mpCanvas, SIGNAL(itemActivated(QListWidgetItem *)), q, SLOT(_k_slotAcceptIcons()));
00340 mpCanvas->setMinimumSize(400, 125);
00341 top->addWidget(mpCanvas);
00342 searchLine->setListWidget(mpCanvas);
00343
00344 mpProgress = new QProgressBar(main);
00345 top->addWidget(mpProgress);
00346 connect(mpCanvas, SIGNAL(startLoading(int)), q, SLOT(_k_slotStartLoading(int)));
00347 connect(mpCanvas, SIGNAL(progress(int)), q, SLOT(_k_slotProgress(int)));
00348 connect(mpCanvas, SIGNAL(finished()), q, SLOT(_k_slotFinished()));
00349
00350
00351 connect(q, SIGNAL(hidden()), mpCanvas, SLOT(stopLoading()));
00352
00353 static const char* const context_text[] = {
00354 I18N_NOOP( "Actions" ),
00355 I18N_NOOP( "Animations" ),
00356 I18N_NOOP( "Applications" ),
00357 I18N_NOOP( "Categories" ),
00358 I18N_NOOP( "Devices" ),
00359 I18N_NOOP( "Emblems" ),
00360 I18N_NOOP( "Emotes" ),
00361 I18N_NOOP( "Filesystems" ),
00362 I18N_NOOP( "International" ),
00363 I18N_NOOP( "Mimetypes" ),
00364 I18N_NOOP( "Places" ),
00365 I18N_NOOP( "Status" ) };
00366 static const KIconLoader::Context context_id[] = {
00367 KIconLoader::Action,
00368 KIconLoader::Animation,
00369 KIconLoader::Application,
00370 KIconLoader::Category,
00371 KIconLoader::Device,
00372 KIconLoader::Emblem,
00373 KIconLoader::Emote,
00374 KIconLoader::FileSystem,
00375 KIconLoader::International,
00376 KIconLoader::MimeType,
00377 KIconLoader::Place,
00378 KIconLoader::StatusIcon };
00379 mNumContext = 0;
00380 int cnt = sizeof( context_text ) / sizeof( context_text[ 0 ] );
00381
00382 Q_ASSERT( cnt == sizeof( context_id ) / sizeof( context_id[ 0 ] )
00383 && cnt == sizeof( mContextMap ) / sizeof( mContextMap[ 0 ] ));
00384 for( int i = 0;
00385 i < cnt;
00386 ++i )
00387 {
00388 if( mpLoader->hasContext( context_id[ i ] ))
00389 {
00390 mpCombo->addItem(i18n( context_text[ i ] ));
00391 mContextMap[ mNumContext++ ] = context_id[ i ];
00392 }
00393 }
00394 mpCombo->setFixedSize(mpCombo->sizeHint());
00395
00396 mpBrowseBut->setFixedWidth(mpCombo->width());
00397
00398
00399 q->incrementInitialSize(QSize(0,100));
00400 connect(q, SIGNAL(okClicked()), q, SLOT(slotOk()));
00401 }
00402
00403
00404 KIconDialog::~KIconDialog()
00405 {
00406 delete d;
00407 }
00408
00409 void KIconDialog::KIconDialogPrivate::_k_slotAcceptIcons()
00410 {
00411 custom.clear();
00412 q->slotOk();
00413 }
00414
00415 void KIconDialog::KIconDialogPrivate::showIcons()
00416 {
00417 mpCanvas->clear();
00418 QStringList filelist;
00419 if (mpSystemIcons->isChecked())
00420 if (m_bStrictIconSize)
00421 filelist=mpLoader->queryIcons(mGroupOrSize, mContext);
00422 else
00423 filelist=mpLoader->queryIconsByContext(mGroupOrSize, mContext);
00424 else if (!customLocation.isNull()) {
00425 filelist = mpLoader->queryIconsByDir(customLocation);
00426 }
00427 else
00428 filelist=mFileList;
00429
00430 QList<IconPath> iconlist;
00431 QStringList::Iterator it;
00432 foreach (const QString &it, filelist) {
00433 iconlist.append(IconPath(it));
00434 }
00435
00436 qSort(iconlist);
00437 filelist.clear();
00438
00439 foreach (const IconPath &ip, iconlist) {
00440 filelist.append(ip);
00441 }
00442
00443 searchLine->clear();
00444 mpCanvas->loadFiles(filelist);
00445 }
00446
00447 void KIconDialog::setStrictIconSize(bool b)
00448 {
00449 d->m_bStrictIconSize=b;
00450 }
00451
00452 bool KIconDialog::strictIconSize() const
00453 {
00454 return d->m_bStrictIconSize;
00455 }
00456
00457 void KIconDialog::setIconSize( int size )
00458 {
00459
00460 if (size == 0) {
00461 d->mGroupOrSize = KIconLoader::Desktop;
00462 } else {
00463 d->mGroupOrSize = -size;
00464 }
00465 }
00466
00467 int KIconDialog::iconSize() const
00468 {
00469
00470 return (d->mGroupOrSize < 0) ? -d->mGroupOrSize : 0;
00471 }
00472
00473 void KIconDialog::setup(KIconLoader::Group group, KIconLoader::Context context,
00474 bool strictIconSize, int iconSize, bool user,
00475 bool lockUser, bool lockCustomDir )
00476 {
00477 d->m_bStrictIconSize = strictIconSize;
00478 d->m_bLockUser = lockUser;
00479 d->m_bLockCustomDir = lockCustomDir;
00480 d->mGroupOrSize = (iconSize == 0) ? group : -iconSize;
00481 d->mpSystemIcons->setChecked(!user);
00482 d->mpSystemIcons->setEnabled(!lockUser || !user);
00483 d->mpOtherIcons->setChecked(user);
00484 d->mpOtherIcons->setEnabled(!lockUser || user);
00485 d->mpCombo->setEnabled(!user);
00486 d->mpBrowseBut->setEnabled(user && !lockCustomDir);
00487 d->setContext(context);
00488 }
00489
00490 void KIconDialog::KIconDialogPrivate::setContext(KIconLoader::Context context)
00491 {
00492 mContext = context;
00493 for( int i = 0;
00494 i < mNumContext;
00495 ++i )
00496 if( mContextMap[ i ] == context )
00497 {
00498 mpCombo->setCurrentIndex( i );
00499 return;
00500 }
00501 }
00502
00503 void KIconDialog::setCustomLocation( const QString& location )
00504 {
00505 d->customLocation = location;
00506 }
00507
00508 QString KIconDialog::openDialog()
00509 {
00510 d->showIcons();
00511
00512 if ( exec() == Accepted )
00513 {
00514 if (!d->custom.isNull())
00515 return d->custom;
00516 QString name = d->mpCanvas->getCurrent();
00517 if (name.isEmpty() || d->mpOtherIcons->isChecked()) {
00518 return name;
00519 }
00520 QFileInfo fi(name);
00521 return fi.baseName();
00522 }
00523 return QString();
00524 }
00525
00526 void KIconDialog::showDialog()
00527 {
00528 setModal(false);
00529 d->showIcons();
00530 show();
00531 }
00532
00533 void KIconDialog::slotOk()
00534 {
00535 QString name;
00536 if (!d->custom.isNull())
00537 {
00538 name = d->custom;
00539 }
00540 else
00541 {
00542 name = d->mpCanvas->getCurrent();
00543 if (!name.isEmpty() && d->mpSystemIcons->isChecked()) {
00544 QFileInfo fi(name);
00545 name = fi.baseName();
00546 }
00547 }
00548
00549 emit newIconName(name);
00550 KDialog::accept();
00551 }
00552
00553 QString KIconDialog::getIcon(KIconLoader::Group group, KIconLoader::Context context,
00554 bool strictIconSize, int iconSize, bool user,
00555 QWidget *parent, const QString &caption)
00556 {
00557 KIconDialog dlg(parent);
00558 dlg.setup( group, context, strictIconSize, iconSize, user );
00559 if (!caption.isNull())
00560 dlg.setCaption(caption);
00561
00562 return dlg.openDialog();
00563 }
00564
00565 void KIconDialog::KIconDialogPrivate::_k_slotBrowse()
00566 {
00567
00568
00569
00570 KUrl emptyUrl;
00571 KFileDialog dlg(emptyUrl, i18n("*.png *.xpm *.svg *.svgz|Icon Files (*.png *.xpm *.svg *.svgz)"), q);
00572 dlg.setOperationMode( KFileDialog::Opening );
00573 dlg.setCaption( i18n("Open") );
00574 dlg.setMode( KFile::File );
00575
00576 KImageFilePreview *ip = new KImageFilePreview( &dlg );
00577 dlg.setPreviewWidget( ip );
00578 dlg.exec();
00579
00580 QString file = dlg.selectedFile();
00581 if (!file.isEmpty())
00582 {
00583 custom = file;
00584 if (mpSystemIcons->isChecked()) {
00585 customLocation = QFileInfo(file).absolutePath();
00586 }
00587 q->slotOk();
00588 }
00589 }
00590
00591 void KIconDialog::KIconDialogPrivate::_k_slotSystemIconClicked()
00592 {
00593 mpBrowseBut->setEnabled(false);
00594 mpCombo->setEnabled(true);
00595 showIcons();
00596 }
00597
00598 void KIconDialog::KIconDialogPrivate::_k_slotOtherIconClicked()
00599 {
00600 mpBrowseBut->setEnabled(!m_bLockCustomDir);
00601 mpCombo->setEnabled(false);
00602 showIcons();
00603 }
00604
00605 void KIconDialog::KIconDialogPrivate::_k_slotContext(int id)
00606 {
00607 mContext = static_cast<KIconLoader::Context>( mContextMap[ id ] );
00608 showIcons();
00609 }
00610
00611 void KIconDialog::KIconDialogPrivate::_k_slotStartLoading(int steps)
00612 {
00613 if (steps < 10)
00614 mpProgress->hide();
00615 else
00616 {
00617 mNumOfSteps = steps;
00618 mpProgress->setValue(0);
00619 mpProgress->show();
00620 }
00621 }
00622
00623 void KIconDialog::KIconDialogPrivate::_k_slotProgress(int p)
00624 {
00625 mpProgress->setValue(static_cast<int>(100.0 * (double)p / (double)mNumOfSteps));
00626 }
00627
00628 void KIconDialog::KIconDialogPrivate::_k_slotFinished()
00629 {
00630 mNumOfSteps = 1;
00631 mpProgress->hide();
00632 }
00633
00634 class KIconButton::KIconButtonPrivate
00635 {
00636 public:
00637 KIconButtonPrivate(KIconButton *qq, KIconLoader *loader);
00638 ~KIconButtonPrivate();
00639
00640
00641 void _k_slotChangeIcon();
00642 void _k_newIconName(const QString&);
00643
00644 KIconButton *q;
00645
00646 int iconSize;
00647 int buttonIconSize;
00648 bool m_bStrictIconSize;
00649
00650 bool mbUser;
00651 KIconLoader::Group mGroup;
00652 KIconLoader::Context mContext;
00653
00654 QString mIcon;
00655 KIconDialog *mpDialog;
00656 KIconLoader *mpLoader;
00657 };
00658
00659
00660
00661
00662
00663
00664 KIconButton::KIconButton(QWidget *parent)
00665 : QPushButton(parent), d(new KIconButtonPrivate(this, KIconLoader::global()))
00666 {
00667 QPushButton::setIconSize(QSize(48, 48));
00668 }
00669
00670 KIconButton::KIconButton(KIconLoader *loader, QWidget *parent)
00671 : QPushButton(parent), d(new KIconButtonPrivate(this, loader))
00672 {
00673 QPushButton::setIconSize(QSize(48, 48));
00674 }
00675
00676 KIconButton::KIconButtonPrivate::KIconButtonPrivate(KIconButton *qq, KIconLoader *loader)
00677 : q(qq)
00678 {
00679 m_bStrictIconSize = false;
00680 iconSize = 0;
00681 buttonIconSize = -1;
00682
00683 mGroup = KIconLoader::Desktop;
00684 mContext = KIconLoader::Application;
00685 mbUser = false;
00686
00687 mpLoader = loader;
00688 mpDialog = 0L;
00689 connect(q, SIGNAL(clicked()), q, SLOT(_k_slotChangeIcon()));
00690 }
00691
00692 KIconButton::KIconButtonPrivate::~KIconButtonPrivate()
00693 {
00694 delete mpDialog;
00695 }
00696
00697 KIconButton::~KIconButton()
00698 {
00699 delete d;
00700 }
00701
00702 void KIconButton::setStrictIconSize(bool b)
00703 {
00704 d->m_bStrictIconSize=b;
00705 }
00706
00707 bool KIconButton::strictIconSize() const
00708 {
00709 return d->m_bStrictIconSize;
00710 }
00711
00712 void KIconButton::setIconSize( int size )
00713 {
00714 if (d->buttonIconSize == -1) {
00715 QPushButton::setIconSize(QSize(size, size));
00716 }
00717
00718 d->iconSize = size;
00719 }
00720
00721 int KIconButton::iconSize() const
00722 {
00723 return d->iconSize;
00724 }
00725
00726 void KIconButton::setButtonIconSize( int size )
00727 {
00728 QPushButton::setIconSize(QSize(size, size));
00729 d->buttonIconSize = size;
00730 }
00731
00732 int KIconButton::buttonIconSize() const
00733 {
00734 return QPushButton::iconSize().height();
00735 }
00736
00737 void KIconButton::setIconType(KIconLoader::Group group, KIconLoader::Context context, bool user)
00738 {
00739 d->mGroup = group;
00740 d->mContext = context;
00741 d->mbUser = user;
00742 }
00743
00744 void KIconButton::setIcon(const QString& icon)
00745 {
00746 d->mIcon = icon;
00747 setIcon(KIcon(d->mIcon));
00748
00749 if (!d->mpDialog) {
00750 d->mpDialog = new KIconDialog(d->mpLoader, this);
00751 connect(d->mpDialog, SIGNAL(newIconName(const QString&)), this, SLOT(_k_newIconName(const QString&)));
00752 }
00753
00754 if (d->mbUser) {
00755 d->mpDialog->setCustomLocation(QFileInfo(d->mpLoader->iconPath(d->mIcon, d->mGroup, true) ).absolutePath());
00756 }
00757 }
00758
00759 void KIconButton::setIcon(const QIcon& icon)
00760 {
00761 QPushButton::setIcon(icon);
00762 }
00763
00764 void KIconButton::resetIcon()
00765 {
00766 d->mIcon.clear();
00767 setIcon(QIcon());
00768 }
00769
00770 const QString &KIconButton::icon() const
00771 {
00772 return d->mIcon;
00773 }
00774
00775 void KIconButton::KIconButtonPrivate::_k_slotChangeIcon()
00776 {
00777 if (!mpDialog)
00778 {
00779 mpDialog = new KIconDialog(mpLoader, q);
00780 connect(mpDialog, SIGNAL(newIconName(const QString&)), q, SLOT(_k_newIconName(const QString&)));
00781 }
00782
00783 mpDialog->setup(mGroup, mContext, m_bStrictIconSize, iconSize, mbUser);
00784 mpDialog->showDialog();
00785 }
00786
00787 void KIconButton::KIconButtonPrivate::_k_newIconName(const QString& name)
00788 {
00789 if (name.isEmpty())
00790 return;
00791
00792 q->setIcon(KIcon(name));
00793 mIcon = name;
00794
00795 if (mbUser) {
00796 mpDialog->setCustomLocation(QFileInfo(mpLoader->iconPath(mIcon, mGroup, true)).absolutePath());
00797 }
00798
00799 emit q->iconChanged(name);
00800 }
00801
00802 #include "kicondialog.moc"