kicondialog.cpp
00001 /* vi: ts=8 sts=4 sw=4 00002 * 00003 * This file is part of the KDE project, module tdefile. 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 <tdeapplication.h> 00023 #include <tdelocale.h> 00024 #include <tdeglobal.h> 00025 #include <kstandarddirs.h> 00026 #include <kiconloader.h> 00027 #include <kprogress.h> 00028 #include <kiconview.h> 00029 #include <tdefiledialog.h> 00030 #include <kimagefilepreview.h> 00031 00032 #include <tqlayout.h> 00033 #include <tqstring.h> 00034 #include <tqstringlist.h> 00035 #include <tqsortedlist.h> 00036 #include <tqimage.h> 00037 #include <tqpixmap.h> 00038 #include <tqlabel.h> 00039 #include <tqcombobox.h> 00040 #include <tqtimer.h> 00041 #include <tqbuttongroup.h> 00042 #include <tqradiobutton.h> 00043 #include <tqfileinfo.h> 00044 #include <tqtoolbutton.h> 00045 #include <tqwhatsthis.h> 00046 00047 #ifdef HAVE_LIBART 00048 #include <svgicons/ksvgiconengine.h> 00049 #include <svgicons/ksvgiconpainter.h> 00050 #endif 00051 00052 class TDEIconCanvas::TDEIconCanvasPrivate 00053 { 00054 public: 00055 TDEIconCanvasPrivate() { m_bLoading = false; } 00056 ~TDEIconCanvasPrivate() {} 00057 bool m_bLoading; 00058 }; 00059 00063 class IconPath : public TQString 00064 { 00065 protected: 00066 TQString m_iconName; 00067 00068 public: 00069 IconPath(const TQString &ip) : TQString (ip) 00070 { 00071 int n = findRev('/'); 00072 m_iconName = (n==-1) ? static_cast<TQString>(*this) : mid(n+1); 00073 } 00074 00075 00076 IconPath() : TQString () 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 * TDEIconCanvas: Iconview for the iconloader dialog. 00089 */ 00090 00091 TDEIconCanvas::TDEIconCanvas(TQWidget *parent, const char *name) 00092 : TDEIconView(parent, name) 00093 { 00094 d = new TDEIconCanvasPrivate; 00095 mpTimer = new TQTimer(this); 00096 connect(mpTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotLoadFiles())); 00097 connect(this, TQT_SIGNAL(currentChanged(TQIconViewItem *)), 00098 TQT_SLOT(slotCurrentChanged(TQIconViewItem *))); 00099 setGridX(80); 00100 setWordWrapIconText(false); 00101 setShowToolTips(true); 00102 } 00103 00104 TDEIconCanvas::~TDEIconCanvas() 00105 { 00106 delete mpTimer; 00107 delete d; 00108 } 00109 00110 void TDEIconCanvas::loadFiles(const TQStringList& 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 TDEIconCanvas::slotLoadFiles() 00120 { 00121 setResizeMode(Fixed); 00122 TQApplication::setOverrideCursor(tqwaitCursor); 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 TQStringList::ConstIterator it; 00134 uint emitProgress = 10; // so we will emit it once in the beginning 00135 TQStringList::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 TQImage img; 00153 00154 // Use the extension as the format. Works for XPM and PNG, but not for SVG 00155 TQString path= *it; 00156 TQString 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 TQPixmap pm; 00181 pm.convertFromImage(img); 00182 TQFileInfo fi(*it); 00183 TQIconViewItem *item = new TQIconViewItem(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 TQApplication::restoreOverrideCursor(); 00197 d->m_bLoading = false; 00198 emit finished(); 00199 setResizeMode(Adjust); 00200 } 00201 00202 TQString TDEIconCanvas::getCurrent() const 00203 { 00204 if (!currentItem()) 00205 return TQString::null; 00206 return currentItem()->key(); 00207 } 00208 00209 void TDEIconCanvas::stopLoading() 00210 { 00211 d->m_bLoading = false; 00212 } 00213 00214 void TDEIconCanvas::slotCurrentChanged(TQIconViewItem *item) 00215 { 00216 emit nameChanged((item != 0L) ? item->text() : TQString::null); 00217 } 00218 00219 class TDEIconDialog::TDEIconDialogPrivate 00220 { 00221 public: 00222 TDEIconDialogPrivate() { 00223 m_bStrictIconSize = true; 00224 m_bLockUser = false; 00225 m_bLockCustomDir = false; 00226 searchLine = 0; 00227 } 00228 ~TDEIconDialogPrivate() {} 00229 bool m_bStrictIconSize, m_bLockUser, m_bLockCustomDir; 00230 TQString custom; 00231 TQString customLocation; 00232 TDEIconViewSearchLine *searchLine; 00233 }; 00234 00235 /* 00236 * TDEIconDialog: Dialog for selecting icons. Both system and user 00237 * specified icons can be chosen. 00238 */ 00239 00240 TDEIconDialog::TDEIconDialog(TQWidget *parent, const char *name) 00241 : KDialogBase(parent, name, true, i18n("Select Icon"), Ok|Cancel, Ok) 00242 { 00243 d = new TDEIconDialogPrivate; 00244 mpLoader = TDEGlobal::iconLoader(); 00245 init(); 00246 } 00247 00248 TDEIconDialog::TDEIconDialog(TDEIconLoader *loader, TQWidget *parent, 00249 const char *name) 00250 : KDialogBase(parent, name, true, i18n("Select Icon"), Ok|Cancel, Ok) 00251 { 00252 d = new TDEIconDialogPrivate; 00253 mpLoader = loader; 00254 init(); 00255 } 00256 00257 void TDEIconDialog::init() 00258 { 00259 mGroupOrSize = TDEIcon::Desktop; 00260 mContext = TDEIcon::Any; 00261 mType = 0; 00262 mFileList = TDEGlobal::dirs()->findAllResources("appicon", TQString::fromLatin1("*.png")); 00263 00264 TQWidget *main = new TQWidget( this ); 00265 setMainWidget(main); 00266 00267 TQVBoxLayout *top = new TQVBoxLayout(main); 00268 top->setSpacing( spacingHint() ); 00269 00270 TQButtonGroup *bgroup = new TQButtonGroup(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, TQT_SIGNAL(clicked(int)), TQT_SLOT(slotButtonClicked(int))); 00275 TQGridLayout *grid = new TQGridLayout(bgroup->layout(), 3, 2); 00276 mpRb1 = new TQRadioButton(i18n("S&ystem icons:"), bgroup); 00277 grid->addWidget(mpRb1, 1, 0); 00278 mpCombo = new TQComboBox(bgroup); 00279 connect(mpCombo, TQT_SIGNAL(activated(int)), TQT_SLOT(slotContext(int))); 00280 grid->addWidget(mpCombo, 1, 1); 00281 mpRb2 = new TQRadioButton(i18n("O&ther icons:"), bgroup); 00282 grid->addWidget(mpRb2, 2, 0); 00283 mpBrowseBut = new TQPushButton(i18n("&Browse..."), bgroup); 00284 grid->addWidget(mpBrowseBut, 2, 1); 00285 00286 // 00287 // ADD SEARCHLINE 00288 // 00289 TQHBoxLayout *searchLayout = new TQHBoxLayout(0, 0, KDialog::spacingHint()); 00290 top->addLayout(searchLayout); 00291 00292 TQToolButton *clearSearch = new TQToolButton(main); 00293 clearSearch->setTextLabel(i18n("Clear Search"), true); 00294 clearSearch->setIconSet(SmallIconSet(TQApplication::reverseLayout() ? "clear_left" :"locationbar_erase")); 00295 searchLayout->addWidget(clearSearch); 00296 00297 TQLabel *searchLabel = new TQLabel(i18n("&Search:"), main); 00298 searchLayout->addWidget(searchLabel); 00299 00300 d->searchLine = new TDEIconViewSearchLine(main, "searchLine"); 00301 searchLayout->addWidget(d->searchLine); 00302 searchLabel->setBuddy(d->searchLine); 00303 00304 00305 // signals and slots connections 00306 connect(clearSearch, TQT_SIGNAL(clicked()), d->searchLine, TQT_SLOT(clear())); 00307 00308 TQString wtstr = i18n("Search interactively for icon names (e.g. folder)."); 00309 TQWhatsThis::add(searchLabel, wtstr); 00310 TQWhatsThis::add(d->searchLine, wtstr); 00311 00312 00313 mpCanvas = new TDEIconCanvas(main); 00314 connect(mpCanvas, TQT_SIGNAL(executed(TQIconViewItem *)), TQT_SLOT(slotAcceptIcons())); 00315 connect(mpCanvas, TQT_SIGNAL(returnPressed(TQIconViewItem *)), TQT_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, TQT_SIGNAL(startLoading(int)), TQT_SLOT(slotStartLoading(int))); 00323 connect(mpCanvas, TQT_SIGNAL(progress(int)), TQT_SLOT(slotProgress(int))); 00324 connect(mpCanvas, TQT_SIGNAL(finished()), TQT_SLOT(slotFinished())); 00325 00326 // When pressing Ok or Cancel, stop loading icons 00327 connect(this, TQT_SIGNAL(hidden()), mpCanvas, TQT_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 TDEIcon::Context context_id[] = { 00343 TDEIcon::Action, 00344 TDEIcon::Animation, 00345 TDEIcon::Application, 00346 TDEIcon::Category, 00347 TDEIcon::Device, 00348 TDEIcon::Emblem, 00349 TDEIcon::Emote, 00350 TDEIcon::FileSystem, 00351 TDEIcon::International, 00352 TDEIcon::MimeType, 00353 TDEIcon::Place, 00354 TDEIcon::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(TQSize(0,100)); 00376 } 00377 00378 00379 TDEIconDialog::~TDEIconDialog() 00380 { 00381 delete d; 00382 } 00383 00384 void TDEIconDialog::slotAcceptIcons() 00385 { 00386 d->custom=TQString::null; 00387 slotOk(); 00388 } 00389 00390 void TDEIconDialog::showIcons() 00391 { 00392 mpCanvas->clear(); 00393 TQStringList 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 TQSortedList <IconPath>iconlist; 00405 iconlist.setAutoDelete(true); 00406 TQStringList::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 TDEIconDialog::setStrictIconSize(bool b) 00421 { 00422 d->m_bStrictIconSize=b; 00423 } 00424 00425 bool TDEIconDialog::strictIconSize() const 00426 { 00427 return d->m_bStrictIconSize; 00428 } 00429 00430 void TDEIconDialog::setIconSize( int size ) 00431 { 00432 // see TDEIconLoader, if you think this is weird 00433 if ( size == 0 ) 00434 mGroupOrSize = TDEIcon::Desktop; // default Group 00435 else 00436 mGroupOrSize = -size; // yes, TDEIconLoader::queryIconsByContext is weird 00437 } 00438 00439 int TDEIconDialog::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 TQString TDEIconDialog::selectIcon(TDEIcon::Group group, TDEIcon::Context context, bool user) 00447 { 00448 setup( group, context, false, 0, user ); 00449 return openDialog(); 00450 } 00451 #endif 00452 00453 void TDEIconDialog::setup(TDEIcon::Group group, TDEIcon::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 TDEIconDialog::setup(TDEIcon::Group group, TDEIcon::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 TDEIconDialog::setContext( TDEIcon::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 TDEIconDialog::setCustomLocation( const TQString& location ) 00498 { 00499 d->customLocation = location; 00500 } 00501 00502 TQString TDEIconDialog::openDialog() 00503 { 00504 showIcons(); 00505 00506 if ( exec() == Accepted ) 00507 { 00508 if (!d->custom.isNull()) 00509 return d->custom; 00510 TQString name = mpCanvas->getCurrent(); 00511 if (name.isEmpty() || (mType == 1)) 00512 return name; 00513 TQFileInfo fi(name); 00514 return fi.baseName(); 00515 } 00516 return TQString::null; 00517 } 00518 00519 void TDEIconDialog::showDialog() 00520 { 00521 setModal(false); 00522 showIcons(); 00523 show(); 00524 } 00525 00526 void TDEIconDialog::slotOk() 00527 { 00528 TQString 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 TQFileInfo fi(name); 00539 name = fi.baseName(); 00540 } 00541 } 00542 00543 emit newIconName(name); 00544 KDialogBase::slotOk(); 00545 } 00546 00547 TQString TDEIconDialog::getIcon(TDEIcon::Group group, TDEIcon::Context context, 00548 bool strictIconSize, int iconSize, bool user, 00549 TQWidget *parent, const TQString &caption) 00550 { 00551 TDEIconDialog 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 TDEIconDialog::slotButtonClicked(int id) 00560 { 00561 TQString 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(TQString::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 = TQFileInfo( file ).dirPath( true ); 00605 slotOk(); 00606 } 00607 } 00608 break; 00609 } 00610 } 00611 00612 void TDEIconDialog::slotContext(int id) 00613 { 00614 mContext = static_cast<TDEIcon::Context>( mContextMap[ id ] ); 00615 showIcons(); 00616 } 00617 00618 void TDEIconDialog::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 TDEIconDialog::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 TDEIconDialog::slotFinished() 00639 { 00640 mpProgress->hide(); 00641 } 00642 00643 class TDEIconButton::TDEIconButtonPrivate 00644 { 00645 public: 00646 TDEIconButtonPrivate() { 00647 m_bStrictIconSize = false; 00648 iconSize = 0; // let TDEIconLoader choose the default 00649 } 00650 ~TDEIconButtonPrivate() {} 00651 bool m_bStrictIconSize; 00652 int iconSize; 00653 }; 00654 00655 00656 /* 00657 * TDEIconButton: A "choose icon" pushbutton. 00658 */ 00659 00660 TDEIconButton::TDEIconButton(TQWidget *parent, const char *name) 00661 : TQPushButton(parent, name) 00662 { 00663 init( TDEGlobal::iconLoader() ); 00664 } 00665 00666 TDEIconButton::TDEIconButton(TDEIconLoader *loader, 00667 TQWidget *parent, const char *name) 00668 : TQPushButton(parent, name) 00669 { 00670 init( loader ); 00671 } 00672 00673 void TDEIconButton::init( TDEIconLoader *loader ) 00674 { 00675 d = new TDEIconButtonPrivate; 00676 mGroup = TDEIcon::Desktop; 00677 mContext = TDEIcon::Application; 00678 mbUser = false; 00679 00680 mpLoader = loader; 00681 mpDialog = 0L; 00682 connect(this, TQT_SIGNAL(clicked()), TQT_SLOT(slotChangeIcon())); 00683 } 00684 00685 TDEIconButton::~TDEIconButton() 00686 { 00687 delete mpDialog; 00688 delete d; 00689 } 00690 00691 void TDEIconButton::setStrictIconSize(bool b) 00692 { 00693 d->m_bStrictIconSize=b; 00694 } 00695 00696 bool TDEIconButton::strictIconSize() const 00697 { 00698 return d->m_bStrictIconSize; 00699 } 00700 00701 void TDEIconButton::setIconSize( int size ) 00702 { 00703 d->iconSize = size; 00704 } 00705 00706 int TDEIconButton::iconSize() const 00707 { 00708 return d->iconSize; 00709 } 00710 00711 void TDEIconButton::setIconType(TDEIcon::Group group, TDEIcon::Context context, bool user) 00712 { 00713 mGroup = group; 00714 mContext = context; 00715 mbUser = user; 00716 } 00717 00718 void TDEIconButton::setIcon(const TQString& icon) 00719 { 00720 mIcon = icon; 00721 setIconSet(mpLoader->loadIconSet(mIcon, mGroup, d->iconSize)); 00722 00723 if (!mpDialog) 00724 { 00725 mpDialog = new TDEIconDialog(mpLoader, this); 00726 connect(mpDialog, TQT_SIGNAL(newIconName(const TQString&)), TQT_SLOT(newIconName(const TQString&))); 00727 } 00728 00729 if ( mbUser ) 00730 mpDialog->setCustomLocation( TQFileInfo( mpLoader->iconPath(mIcon, mGroup, true) ).dirPath( true ) ); 00731 } 00732 00733 void TDEIconButton::resetIcon() 00734 { 00735 mIcon = TQString::null; 00736 setIconSet(TQIconSet()); 00737 } 00738 00739 void TDEIconButton::slotChangeIcon() 00740 { 00741 if (!mpDialog) 00742 { 00743 mpDialog = new TDEIconDialog(mpLoader, this); 00744 connect(mpDialog, TQT_SIGNAL(newIconName(const TQString&)), TQT_SLOT(newIconName(const TQString&))); 00745 } 00746 00747 mpDialog->setup( mGroup, mContext, d->m_bStrictIconSize, d->iconSize, mbUser ); 00748 mpDialog->showDialog(); 00749 } 00750 00751 void TDEIconButton::newIconName(const TQString& name) 00752 { 00753 if (name.isEmpty()) 00754 return; 00755 00756 TQIconSet iconset = mpLoader->loadIconSet(name, mGroup, d->iconSize); 00757 setIconSet(iconset); 00758 mIcon = name; 00759 00760 if ( mbUser ) 00761 mpDialog->setCustomLocation( TQFileInfo( mpLoader->iconPath(mIcon, mGroup, true) ).dirPath( true ) ); 00762 00763 emit iconChanged(name); 00764 } 00765 00766 void TDEIconCanvas::virtual_hook( int id, void* data ) 00767 { TDEIconView::virtual_hook( id, data ); } 00768 00769 void TDEIconDialog::virtual_hook( int id, void* data ) 00770 { KDialogBase::virtual_hook( id, data ); } 00771 00772 #include "kicondialog.moc"