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