kicondialog.cpp
00001 /* vi: ts=8 sts=4 sw=4 00002 * 00003 * This file is part of the KDE project, module kfile. 00004 * Copyright (C) 2000 Geert Jansen <jansen@kde.org> 00005 * (C) 2000 Kurt Granroth <granroth@kde.org> 00006 * (C) 1997 Christoph Neerfeld <chris@kde.org> 00007 * (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org> 00008 * 00009 * This is free software; it comes under the GNU Library General 00010 * Public License, version 2. See the file "COPYING.LIB" for the 00011 * exact licensing terms. 00012 */ 00013 00014 #include "kicondialog.h" 00015 00016 #include <config.h> 00017 00018 #include <assert.h> 00019 00020 #include <kiconviewsearchline.h> 00021 00022 #include <kapplication.h> 00023 #include <klocale.h> 00024 #include <kglobal.h> 00025 #include <kstandarddirs.h> 00026 #include <kiconloader.h> 00027 #include <kprogress.h> 00028 #include <kiconview.h> 00029 #include <kfiledialog.h> 00030 #include <kimagefilepreview.h> 00031 00032 #include <qlayout.h> 00033 #include <qstring.h> 00034 #include <qstringlist.h> 00035 #include <qsortedlist.h> 00036 #include <qimage.h> 00037 #include <qpixmap.h> 00038 #include <qlabel.h> 00039 #include <qcombobox.h> 00040 #include <qtimer.h> 00041 #include <qbuttongroup.h> 00042 #include <qradiobutton.h> 00043 #include <qfileinfo.h> 00044 #include <qtoolbutton.h> 00045 #include <qwhatsthis.h> 00046 00047 #ifdef HAVE_LIBART 00048 #include <svgicons/ksvgiconengine.h> 00049 #include <svgicons/ksvgiconpainter.h> 00050 #endif 00051 00052 class KIconCanvas::KIconCanvasPrivate 00053 { 00054 public: 00055 KIconCanvasPrivate() { m_bLoading = false; } 00056 ~KIconCanvasPrivate() {} 00057 bool m_bLoading; 00058 }; 00059 00063 class IconPath : public QString 00064 { 00065 protected: 00066 QString m_iconName; 00067 00068 public: 00069 IconPath(const QString &ip) : QString (ip) 00070 { 00071 int n = findRev('/'); 00072 m_iconName = (n==-1) ? static_cast<QString>(*this) : mid(n+1); 00073 } 00074 00075 00076 IconPath() : QString () 00077 { } 00078 00079 bool operator== (const IconPath &ip) const 00080 { return m_iconName == ip.m_iconName; } 00081 00082 bool operator< (const IconPath &ip) const 00083 { return m_iconName < ip.m_iconName; } 00084 00085 }; 00086 00087 /* 00088 * KIconCanvas: Iconview for the iconloader dialog. 00089 */ 00090 00091 KIconCanvas::KIconCanvas(QWidget *parent, const char *name) 00092 : KIconView(parent, name) 00093 { 00094 d = new KIconCanvasPrivate; 00095 mpTimer = new QTimer(this); 00096 connect(mpTimer, SIGNAL(timeout()), SLOT(slotLoadFiles())); 00097 connect(this, SIGNAL(currentChanged(QIconViewItem *)), 00098 SLOT(slotCurrentChanged(QIconViewItem *))); 00099 setGridX(80); 00100 setWordWrapIconText(false); 00101 setShowToolTips(true); 00102 } 00103 00104 KIconCanvas::~KIconCanvas() 00105 { 00106 delete mpTimer; 00107 delete d; 00108 } 00109 00110 void KIconCanvas::loadFiles(const QStringList& files) 00111 { 00112 clear(); 00113 mFiles = files; 00114 emit startLoading(mFiles.count()); 00115 mpTimer->start(10, true); // #86680 00116 d->m_bLoading = false; 00117 } 00118 00119 void KIconCanvas::slotLoadFiles() 00120 { 00121 setResizeMode(Fixed); 00122 QApplication::setOverrideCursor(waitCursor); 00123 00124 // disable updates to not trigger paint events when adding child items 00125 setUpdatesEnabled( false ); 00126 00127 #ifdef HAVE_LIBART 00128 KSVGIconEngine *svgEngine = new KSVGIconEngine(); 00129 #endif 00130 00131 d->m_bLoading = true; 00132 int i; 00133 QStringList::ConstIterator it; 00134 uint emitProgress = 10; // so we will emit it once in the beginning 00135 QStringList::ConstIterator end(mFiles.end()); 00136 for (it=mFiles.begin(), i=0; it!=end; ++it, i++) 00137 { 00138 // Calling kapp->processEvents() makes the iconview flicker like hell 00139 // (it's being repainted once for every new item), so we don't do this. 00140 // Instead, we directly repaint the progress bar without going through 00141 // the event-loop. We do that just once for every 10th item so that 00142 // the progress bar doesn't flicker in turn. (pfeiffer) 00143 if ( emitProgress >= 10 ) { 00144 emit progress(i); 00145 emitProgress = 0; 00146 } 00147 00148 emitProgress++; 00149 // kapp->processEvents(); 00150 if ( !d->m_bLoading ) // user clicked on a button that will load another set of icons 00151 break; 00152 QImage img; 00153 00154 // Use the extension as the format. Works for XPM and PNG, but not for SVG 00155 QString path= *it; 00156 QString ext = path.right(3).upper(); 00157 00158 if (ext != "SVG" && ext != "VGZ") 00159 img.load(*it); 00160 #ifdef HAVE_LIBART 00161 else 00162 if (svgEngine->load(60, 60, *it)) 00163 img = *svgEngine->painter()->image(); 00164 #endif 00165 00166 if (img.isNull()) 00167 continue; 00168 if (img.width() > 60 || img.height() > 60) 00169 { 00170 if (img.width() > img.height()) 00171 { 00172 int height = (int) ((60.0 / img.width()) * img.height()); 00173 img = img.smoothScale(60, height); 00174 } else 00175 { 00176 int width = (int) ((60.0 / img.height()) * img.width()); 00177 img = img.smoothScale(width, 60); 00178 } 00179 } 00180 QPixmap pm; 00181 pm.convertFromImage(img); 00182 QFileInfo fi(*it); 00183 QIconViewItem *item = new QIconViewItem(this, fi.baseName(), pm); 00184 item->setKey(*it); 00185 item->setDragEnabled(false); 00186 item->setDropEnabled(false); 00187 } 00188 00189 #ifdef HAVE_LIBART 00190 delete svgEngine; 00191 #endif 00192 00193 // enable updates since we have to draw the whole view now 00194 setUpdatesEnabled( true ); 00195 00196 QApplication::restoreOverrideCursor(); 00197 d->m_bLoading = false; 00198 emit finished(); 00199 setResizeMode(Adjust); 00200 } 00201 00202 QString KIconCanvas::getCurrent() const 00203 { 00204 if (!currentItem()) 00205 return QString::null; 00206 return currentItem()->key(); 00207 } 00208 00209 void KIconCanvas::stopLoading() 00210 { 00211 d->m_bLoading = false; 00212 } 00213 00214 void KIconCanvas::slotCurrentChanged(QIconViewItem *item) 00215 { 00216 emit nameChanged((item != 0L) ? item->text() : QString::null); 00217 } 00218 00219 class KIconDialog::KIconDialogPrivate 00220 { 00221 public: 00222 KIconDialogPrivate() { 00223 m_bStrictIconSize = true; 00224 m_bLockUser = false; 00225 m_bLockCustomDir = false; 00226 searchLine = 0; 00227 } 00228 ~KIconDialogPrivate() {} 00229 bool m_bStrictIconSize, m_bLockUser, m_bLockCustomDir; 00230 QString custom; 00231 QString customLocation; 00232 KIconViewSearchLine *searchLine; 00233 }; 00234 00235 /* 00236 * KIconDialog: Dialog for selecting icons. Both system and user 00237 * specified icons can be chosen. 00238 */ 00239 00240 KIconDialog::KIconDialog(QWidget *parent, const char *name) 00241 : KDialogBase(parent, name, true, i18n("Select Icon"), Ok|Cancel, Ok) 00242 { 00243 d = new KIconDialogPrivate; 00244 mpLoader = KGlobal::iconLoader(); 00245 init(); 00246 } 00247 00248 KIconDialog::KIconDialog(KIconLoader *loader, QWidget *parent, 00249 const char *name) 00250 : KDialogBase(parent, name, true, i18n("Select Icon"), Ok|Cancel, Ok) 00251 { 00252 d = new KIconDialogPrivate; 00253 mpLoader = loader; 00254 init(); 00255 } 00256 00257 void KIconDialog::init() 00258 { 00259 mGroupOrSize = KIcon::Desktop; 00260 mContext = KIcon::Any; 00261 mType = 0; 00262 mFileList = KGlobal::dirs()->findAllResources("appicon", QString::fromLatin1("*.png")); 00263 00264 QWidget *main = new QWidget( this ); 00265 setMainWidget(main); 00266 00267 QVBoxLayout *top = new QVBoxLayout(main); 00268 top->setSpacing( spacingHint() ); 00269 00270 QButtonGroup *bgroup = new QButtonGroup(0, Qt::Vertical, i18n("Icon Source"), main); 00271 bgroup->layout()->setSpacing(KDialog::spacingHint()); 00272 bgroup->layout()->setMargin(KDialog::marginHint()); 00273 top->addWidget(bgroup); 00274 connect(bgroup, SIGNAL(clicked(int)), SLOT(slotButtonClicked(int))); 00275 QGridLayout *grid = new QGridLayout(bgroup->layout(), 3, 2); 00276 mpRb1 = new QRadioButton(i18n("S&ystem icons:"), bgroup); 00277 grid->addWidget(mpRb1, 1, 0); 00278 mpCombo = new QComboBox(bgroup); 00279 connect(mpCombo, SIGNAL(activated(int)), SLOT(slotContext(int))); 00280 grid->addWidget(mpCombo, 1, 1); 00281 mpRb2 = new QRadioButton(i18n("O&ther icons:"), bgroup); 00282 grid->addWidget(mpRb2, 2, 0); 00283 mpBrowseBut = new QPushButton(i18n("&Browse..."), bgroup); 00284 grid->addWidget(mpBrowseBut, 2, 1); 00285 00286 // 00287 // ADD SEARCHLINE 00288 // 00289 QHBoxLayout *searchLayout = new QHBoxLayout(0, 0, KDialog::spacingHint()); 00290 top->addLayout(searchLayout); 00291 00292 QToolButton *clearSearch = new QToolButton(main); 00293 clearSearch->setTextLabel(i18n("Clear Search"), true); 00294 clearSearch->setIconSet(SmallIconSet(QApplication::reverseLayout() ? "clear_left" :"locationbar_erase")); 00295 searchLayout->addWidget(clearSearch); 00296 00297 QLabel *searchLabel = new QLabel(i18n("&Search:"), main); 00298 searchLayout->addWidget(searchLabel); 00299 00300 d->searchLine = new KIconViewSearchLine(main, "searchLine"); 00301 searchLayout->addWidget(d->searchLine); 00302 searchLabel->setBuddy(d->searchLine); 00303 00304 00305 // signals and slots connections 00306 connect(clearSearch, SIGNAL(clicked()), d->searchLine, SLOT(clear())); 00307 00308 QString wtstr = i18n("Search interactively for icon names (e.g. folder)."); 00309 QWhatsThis::add(searchLabel, wtstr); 00310 QWhatsThis::add(d->searchLine, wtstr); 00311 00312 00313 mpCanvas = new KIconCanvas(main); 00314 connect(mpCanvas, SIGNAL(executed(QIconViewItem *)), SLOT(slotAcceptIcons())); 00315 connect(mpCanvas, SIGNAL(returnPressed(QIconViewItem *)), SLOT(slotAcceptIcons())); 00316 mpCanvas->setMinimumSize(400, 125); 00317 top->addWidget(mpCanvas); 00318 d->searchLine->setIconView(mpCanvas); 00319 00320 mpProgress = new KProgress(main); 00321 top->addWidget(mpProgress); 00322 connect(mpCanvas, SIGNAL(startLoading(int)), SLOT(slotStartLoading(int))); 00323 connect(mpCanvas, SIGNAL(progress(int)), SLOT(slotProgress(int))); 00324 connect(mpCanvas, SIGNAL(finished()), SLOT(slotFinished())); 00325 00326 // When pressing Ok or Cancel, stop loading icons 00327 connect(this, SIGNAL(hidden()), mpCanvas, SLOT(stopLoading())); 00328 00329 static const char* const context_text[] = { 00330 I18N_NOOP( "Actions" ), 00331 I18N_NOOP( "Animations" ), 00332 I18N_NOOP( "Applications" ), 00333 I18N_NOOP( "Categories" ), 00334 I18N_NOOP( "Devices" ), 00335 I18N_NOOP( "Emblems" ), 00336 I18N_NOOP( "Emotes" ), 00337 I18N_NOOP( "Filesystems" ), 00338 I18N_NOOP( "International" ), 00339 I18N_NOOP( "Mimetypes" ), 00340 I18N_NOOP( "Places" ), 00341 I18N_NOOP( "Status" ) }; 00342 static const KIcon::Context context_id[] = { 00343 KIcon::Action, 00344 KIcon::Animation, 00345 KIcon::Application, 00346 KIcon::Category, 00347 KIcon::Device, 00348 KIcon::Emblem, 00349 KIcon::Emote, 00350 KIcon::FileSystem, 00351 KIcon::International, 00352 KIcon::MimeType, 00353 KIcon::Place, 00354 KIcon::StatusIcon }; 00355 mNumContext = 0; 00356 int cnt = sizeof( context_text ) / sizeof( context_text[ 0 ] ); 00357 // check all 3 arrays have same sizes 00358 assert( cnt == sizeof( context_id ) / sizeof( context_id[ 0 ] ) 00359 && cnt == sizeof( mContextMap ) / sizeof( mContextMap[ 0 ] )); 00360 for( int i = 0; 00361 i < cnt; 00362 ++i ) 00363 { 00364 if( mpLoader->hasContext( context_id[ i ] )) 00365 { 00366 mpCombo->insertItem(i18n( context_text[ i ] )); 00367 mContextMap[ mNumContext++ ] = context_id[ i ]; 00368 } 00369 } 00370 mpCombo->setFixedSize(mpCombo->sizeHint()); 00371 00372 mpBrowseBut->setFixedWidth(mpCombo->width()); 00373 00374 // Make the dialog a little taller 00375 incInitialSize(QSize(0,100)); 00376 } 00377 00378 00379 KIconDialog::~KIconDialog() 00380 { 00381 delete d; 00382 } 00383 00384 void KIconDialog::slotAcceptIcons() 00385 { 00386 d->custom=QString::null; 00387 slotOk(); 00388 } 00389 00390 void KIconDialog::showIcons() 00391 { 00392 mpCanvas->clear(); 00393 QStringList filelist; 00394 if (mType == 0) 00395 if (d->m_bStrictIconSize) 00396 filelist=mpLoader->queryIcons(mGroupOrSize, mContext); 00397 else 00398 filelist=mpLoader->queryIconsByContext(mGroupOrSize, mContext); 00399 else if ( !d->customLocation.isNull() ) 00400 filelist=mpLoader->queryIconsByDir( d->customLocation ); 00401 else 00402 filelist=mFileList; 00403 00404 QSortedList <IconPath>iconlist; 00405 iconlist.setAutoDelete(true); 00406 QStringList::Iterator it; 00407 for( it = filelist.begin(); it != filelist.end(); ++it ) 00408 iconlist.append(new IconPath(*it)); 00409 00410 iconlist.sort(); 00411 filelist.clear(); 00412 00413 for ( IconPath *ip=iconlist.first(); ip != 0; ip=iconlist.next() ) 00414 filelist.append(*ip); 00415 00416 d->searchLine->clear(); 00417 mpCanvas->loadFiles(filelist); 00418 } 00419 00420 void KIconDialog::setStrictIconSize(bool b) 00421 { 00422 d->m_bStrictIconSize=b; 00423 } 00424 00425 bool KIconDialog::strictIconSize() const 00426 { 00427 return d->m_bStrictIconSize; 00428 } 00429 00430 void KIconDialog::setIconSize( int size ) 00431 { 00432 // see KIconLoader, if you think this is weird 00433 if ( size == 0 ) 00434 mGroupOrSize = KIcon::Desktop; // default Group 00435 else 00436 mGroupOrSize = -size; // yes, KIconLoader::queryIconsByContext is weird 00437 } 00438 00439 int KIconDialog::iconSize() const 00440 { 00441 // 0 or any other value ==> mGroupOrSize is a group, so we return 0 00442 return (mGroupOrSize < 0) ? -mGroupOrSize : 0; 00443 } 00444 00445 #ifndef KDE_NO_COMPAT 00446 QString KIconDialog::selectIcon(KIcon::Group group, KIcon::Context context, bool user) 00447 { 00448 setup( group, context, false, 0, user ); 00449 return openDialog(); 00450 } 00451 #endif 00452 00453 void KIconDialog::setup(KIcon::Group group, KIcon::Context context, 00454 bool strictIconSize, int iconSize, bool user ) 00455 { 00456 d->m_bStrictIconSize = strictIconSize; 00457 mGroupOrSize = (iconSize == 0) ? group : -iconSize; 00458 mType = user ? 1 : 0; 00459 mpRb1->setChecked(!user); 00460 mpRb2->setChecked(user); 00461 mpCombo->setEnabled(!user); 00462 mpBrowseBut->setEnabled(user); 00463 setContext( context ); 00464 } 00465 00466 void KIconDialog::setup(KIcon::Group group, KIcon::Context context, 00467 bool strictIconSize, int iconSize, bool user, 00468 bool lockUser, bool lockCustomDir ) 00469 { 00470 d->m_bStrictIconSize = strictIconSize; 00471 d->m_bLockUser = lockUser; 00472 d->m_bLockCustomDir = lockCustomDir; 00473 mGroupOrSize = (iconSize == 0) ? group : -iconSize; 00474 mType = user ? 1 : 0; 00475 mpRb1->setChecked(!user); 00476 mpRb1->setEnabled( !lockUser || !user ); 00477 mpRb2->setChecked(user); 00478 mpRb2->setEnabled( !lockUser || user ); 00479 mpCombo->setEnabled(!user); 00480 mpBrowseBut->setEnabled( user && !lockCustomDir ); 00481 setContext( context ); 00482 } 00483 00484 void KIconDialog::setContext( KIcon::Context context ) 00485 { 00486 mContext = context; 00487 for( int i = 0; 00488 i < mNumContext; 00489 ++i ) 00490 if( mContextMap[ i ] == context ) 00491 { 00492 mpCombo->setCurrentItem( i ); 00493 return; 00494 } 00495 } 00496 00497 void KIconDialog::setCustomLocation( const QString& location ) 00498 { 00499 d->customLocation = location; 00500 } 00501 00502 QString KIconDialog::openDialog() 00503 { 00504 showIcons(); 00505 00506 if ( exec() == Accepted ) 00507 { 00508 if (!d->custom.isNull()) 00509 return d->custom; 00510 QString name = mpCanvas->getCurrent(); 00511 if (name.isEmpty() || (mType == 1)) 00512 return name; 00513 QFileInfo fi(name); 00514 return fi.baseName(); 00515 } 00516 return QString::null; 00517 } 00518 00519 void KIconDialog::showDialog() 00520 { 00521 setModal(false); 00522 showIcons(); 00523 show(); 00524 } 00525 00526 void KIconDialog::slotOk() 00527 { 00528 QString name; 00529 if (!d->custom.isNull()) 00530 { 00531 name = d->custom; 00532 } 00533 else 00534 { 00535 name = mpCanvas->getCurrent(); 00536 if (!name.isEmpty() && (mType != 1)) 00537 { 00538 QFileInfo fi(name); 00539 name = fi.baseName(); 00540 } 00541 } 00542 00543 emit newIconName(name); 00544 KDialogBase::slotOk(); 00545 } 00546 00547 QString KIconDialog::getIcon(KIcon::Group group, KIcon::Context context, 00548 bool strictIconSize, int iconSize, bool user, 00549 QWidget *parent, const QString &caption) 00550 { 00551 KIconDialog dlg(parent, "icon dialog"); 00552 dlg.setup( group, context, strictIconSize, iconSize, user ); 00553 if (!caption.isNull()) 00554 dlg.setCaption(caption); 00555 00556 return dlg.openDialog(); 00557 } 00558 00559 void KIconDialog::slotButtonClicked(int id) 00560 { 00561 QString file; 00562 00563 switch (id) 00564 { 00565 case 0: 00566 if(mType!=0) 00567 { 00568 mType = 0; 00569 mpBrowseBut->setEnabled(false); 00570 mpCombo->setEnabled(true); 00571 showIcons(); 00572 } 00573 break; 00574 00575 case 1: 00576 if(mType!=1) 00577 { 00578 mType = 1; 00579 mpBrowseBut->setEnabled( !d->m_bLockCustomDir ); 00580 mpCombo->setEnabled(false); 00581 showIcons(); 00582 } 00583 break; 00584 case 2: 00585 { 00586 // Create a file dialog to select a PNG, XPM or SVG file, 00587 // with the image previewer shown. 00588 // KFileDialog::getImageOpenURL doesn't allow svg. 00589 KFileDialog dlg(QString::null, i18n("*.png *.xpm *.svg *.svgz|Icon Files (*.png *.xpm *.svg *.svgz)"), 00590 this, "filedialog", true); 00591 dlg.setOperationMode( KFileDialog::Opening ); 00592 dlg.setCaption( i18n("Open") ); 00593 dlg.setMode( KFile::File ); 00594 00595 KImageFilePreview *ip = new KImageFilePreview( &dlg ); 00596 dlg.setPreviewWidget( ip ); 00597 dlg.exec(); 00598 00599 file = dlg.selectedFile(); 00600 if (!file.isEmpty()) 00601 { 00602 d->custom = file; 00603 if ( mType == 1 ) 00604 d->customLocation = QFileInfo( file ).dirPath( true ); 00605 slotOk(); 00606 } 00607 } 00608 break; 00609 } 00610 } 00611 00612 void KIconDialog::slotContext(int id) 00613 { 00614 mContext = static_cast<KIcon::Context>( mContextMap[ id ] ); 00615 showIcons(); 00616 } 00617 00618 void KIconDialog::slotStartLoading(int steps) 00619 { 00620 if (steps < 10) 00621 mpProgress->hide(); 00622 else 00623 { 00624 mpProgress->setTotalSteps(steps); 00625 mpProgress->setProgress(0); 00626 mpProgress->show(); 00627 } 00628 } 00629 00630 void KIconDialog::slotProgress(int p) 00631 { 00632 mpProgress->setProgress(p); 00633 // commented out the following since setProgress already paints ther 00634 // progress bar. ->repaint() only makes it flicker 00635 //mpProgress->repaint(); 00636 } 00637 00638 void KIconDialog::slotFinished() 00639 { 00640 mpProgress->hide(); 00641 } 00642 00643 class KIconButton::KIconButtonPrivate 00644 { 00645 public: 00646 KIconButtonPrivate() { 00647 m_bStrictIconSize = false; 00648 iconSize = 0; // let KIconLoader choose the default 00649 } 00650 ~KIconButtonPrivate() {} 00651 bool m_bStrictIconSize; 00652 int iconSize; 00653 }; 00654 00655 00656 /* 00657 * KIconButton: A "choose icon" pushbutton. 00658 */ 00659 00660 KIconButton::KIconButton(QWidget *parent, const char *name) 00661 : QPushButton(parent, name) 00662 { 00663 init( KGlobal::iconLoader() ); 00664 } 00665 00666 KIconButton::KIconButton(KIconLoader *loader, 00667 QWidget *parent, const char *name) 00668 : QPushButton(parent, name) 00669 { 00670 init( loader ); 00671 } 00672 00673 void KIconButton::init( KIconLoader *loader ) 00674 { 00675 d = new KIconButtonPrivate; 00676 mGroup = KIcon::Desktop; 00677 mContext = KIcon::Application; 00678 mbUser = false; 00679 00680 mpLoader = loader; 00681 mpDialog = 0L; 00682 connect(this, SIGNAL(clicked()), SLOT(slotChangeIcon())); 00683 } 00684 00685 KIconButton::~KIconButton() 00686 { 00687 delete mpDialog; 00688 delete d; 00689 } 00690 00691 void KIconButton::setStrictIconSize(bool b) 00692 { 00693 d->m_bStrictIconSize=b; 00694 } 00695 00696 bool KIconButton::strictIconSize() const 00697 { 00698 return d->m_bStrictIconSize; 00699 } 00700 00701 void KIconButton::setIconSize( int size ) 00702 { 00703 d->iconSize = size; 00704 } 00705 00706 int KIconButton::iconSize() const 00707 { 00708 return d->iconSize; 00709 } 00710 00711 void KIconButton::setIconType(KIcon::Group group, KIcon::Context context, bool user) 00712 { 00713 mGroup = group; 00714 mContext = context; 00715 mbUser = user; 00716 } 00717 00718 void KIconButton::setIcon(const QString& icon) 00719 { 00720 mIcon = icon; 00721 setIconSet(mpLoader->loadIconSet(mIcon, mGroup, d->iconSize)); 00722 00723 if (!mpDialog) 00724 { 00725 mpDialog = new KIconDialog(mpLoader, this); 00726 connect(mpDialog, SIGNAL(newIconName(const QString&)), SLOT(newIconName(const QString&))); 00727 } 00728 00729 if ( mbUser ) 00730 mpDialog->setCustomLocation( QFileInfo( mpLoader->iconPath(mIcon, mGroup, true) ).dirPath( true ) ); 00731 } 00732 00733 void KIconButton::resetIcon() 00734 { 00735 mIcon = QString::null; 00736 setIconSet(QIconSet()); 00737 } 00738 00739 void KIconButton::slotChangeIcon() 00740 { 00741 if (!mpDialog) 00742 { 00743 mpDialog = new KIconDialog(mpLoader, this); 00744 connect(mpDialog, SIGNAL(newIconName(const QString&)), SLOT(newIconName(const QString&))); 00745 } 00746 00747 mpDialog->setup( mGroup, mContext, d->m_bStrictIconSize, d->iconSize, mbUser ); 00748 mpDialog->showDialog(); 00749 } 00750 00751 void KIconButton::newIconName(const QString& name) 00752 { 00753 if (name.isEmpty()) 00754 return; 00755 00756 QIconSet iconset = mpLoader->loadIconSet(name, mGroup, d->iconSize); 00757 setIconSet(iconset); 00758 mIcon = name; 00759 00760 if ( mbUser ) 00761 mpDialog->setCustomLocation( QFileInfo( mpLoader->iconPath(mIcon, mGroup, true) ).dirPath( true ) ); 00762 00763 emit iconChanged(name); 00764 } 00765 00766 void KIconCanvas::virtual_hook( int id, void* data ) 00767 { KIconView::virtual_hook( id, data ); } 00768 00769 void KIconDialog::virtual_hook( int id, void* data ) 00770 { KDialogBase::virtual_hook( id, data ); } 00771 00772 #include "kicondialog.moc"