diff --git a/kio/kfile/kicondialog.cpp b/kio/kfile/kicondialog.cpp index 7eb2bc5689..cdbee93302 100644 --- a/kio/kfile/kicondialog.cpp +++ b/kio/kfile/kicondialog.cpp @@ -1,786 +1,802 @@ /* vi: ts=8 sts=4 sw=4 * * This file is part of the KDE project, module kfile. * Copyright (C) 2000 Geert Jansen * (C) 2000 Kurt Granroth * (C) 1997 Christoph Neerfeld * (C) 2002 Carsten Pfeiffer * * This is free software; it comes under the GNU Library General * Public License, version 2. See the file "COPYING.LIB" for the * exact licensing terms. */ #include "kicondialog.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class KIconCanvas::KIconCanvasPrivate { public: KIconCanvasPrivate(KIconCanvas *qq) { q = qq; m_bLoading = false; } ~KIconCanvasPrivate() {} KIconCanvas *q; bool m_bLoading; QStringList mFiles; QTimer *mpTimer; // slots void _k_slotLoadFiles(); void _k_slotCurrentChanged(QListWidgetItem *item); }; /** * Helper class for sorting icon paths by icon name */ class IconPath : public QString { protected: QString m_iconName; public: IconPath(const QString &ip) : QString (ip) { int n = lastIndexOf('/'); m_iconName = (n==-1) ? static_cast(*this) : mid(n+1); } IconPath() : QString () { } bool operator== (const IconPath &ip) const { return m_iconName == ip.m_iconName; } bool operator< (const IconPath &ip) const { return m_iconName < ip.m_iconName; } }; /* * KIconCanvas: Iconview for the iconloader dialog. */ KIconCanvas::KIconCanvas(QWidget *parent) : KListWidget(parent), d(new KIconCanvasPrivate(this)) { setViewMode(IconMode); setUniformItemSizes(true); setMovement(Static); setIconSize(QSize(60, 60)); d->mpTimer = new QTimer(this); connect(d->mpTimer, SIGNAL(timeout()), this, SLOT(_k_slotLoadFiles())); connect(this, SIGNAL( currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(_k_slotCurrentChanged(QListWidgetItem *))); setGridSize(QSize(80,80)); } KIconCanvas::~KIconCanvas() { delete d->mpTimer; delete d; } void KIconCanvas::loadFiles(const QStringList& files) { clear(); d->mFiles = files; emit startLoading(d->mFiles.count()); d->mpTimer->setSingleShot(true); d->mpTimer->start(10); d->m_bLoading = false; } void KIconCanvas::KIconCanvasPrivate::_k_slotLoadFiles() { q->setResizeMode(QListWidget::Fixed); QApplication::setOverrideCursor(Qt::WaitCursor); // disable updates to not trigger paint events when adding child items q->setUpdatesEnabled(false); m_bLoading = true; int i; QStringList::ConstIterator it; uint emitProgress = 10; // so we will emit it once in the beginning QStringList::ConstIterator end(mFiles.end()); for (it=mFiles.begin(), i=0; it!=end; ++it, i++) { if ( emitProgress >= 10 ) { emit q->progress(i); emitProgress = 0; } emitProgress++; if (!m_bLoading) { // user clicked on a button that will load another set of icons break; } QImage img; // Use the extension as the format. Works for XPM and PNG, but not for SVG QString path= *it; QString ext = path.right(3).toUpper(); if (ext != "SVG" && ext != "VGZ") img.load(*it); else { // Special stuff for SVG icons img = QImage(60, 60, QImage::Format_ARGB32_Premultiplied); img.fill(0); KSvgRenderer renderer(*it); if (renderer.isValid()) { QPainter p(&img); renderer.render(&p); } } if (img.isNull()) continue; if (img.width() > 60 || img.height() > 60) { if (img.width() > img.height()) { int height = (int) ((60.0 / img.width()) * img.height()); img = img.scaled(60, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); } else { int width = (int) ((60.0 / img.height()) * img.width()); img = img.scaled(width, 60, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); } } QPixmap pm = QPixmap::fromImage(img); QFileInfo fi(*it); QListWidgetItem *item = new QListWidgetItem(pm, fi.completeBaseName(), q); item->setData(Qt::UserRole, *it); item->setToolTip(fi.completeBaseName()); } // enable updates since we have to draw the whole view now q->setUpdatesEnabled(true); QApplication::restoreOverrideCursor(); m_bLoading = false; emit q->finished(); q->setResizeMode(QListWidget::Adjust); } QString KIconCanvas::getCurrent() const { if (!currentItem()) return QString(); return currentItem()->data(Qt::UserRole).toString(); } void KIconCanvas::stopLoading() { d->m_bLoading = false; } void KIconCanvas::KIconCanvasPrivate::_k_slotCurrentChanged(QListWidgetItem *item) { emit q->nameChanged((item != 0L) ? item->text() : QString()); } class KIconDialog::KIconDialogPrivate { public: KIconDialogPrivate(KIconDialog *qq) { q = qq; m_bStrictIconSize = true; m_bLockUser = false; m_bLockCustomDir = false; searchLine = 0; mNumOfSteps = 1; } ~KIconDialogPrivate() {} void init(); void showIcons(); void setContext( KIconLoader::Context context ); // slots void _k_slotContext(int); void _k_slotStartLoading(int); void _k_slotProgress(int); void _k_slotFinished(); void _k_slotAcceptIcons(); void _k_slotBrowse(); void _k_slotOtherIconClicked(); void _k_slotSystemIconClicked(); KIconDialog *q; int mGroupOrSize; KIconLoader::Context mContext; QStringList mFileList; QComboBox *mpCombo; QPushButton *mpBrowseBut; QRadioButton *mpSystemIcons, *mpOtherIcons; QProgressBar *mpProgress; int mNumOfSteps; KIconLoader *mpLoader; KIconCanvas *mpCanvas; int mNumContext; KIconLoader::Context mContextMap[ 12 ]; // must match KIcon::Context size, code has assert bool m_bStrictIconSize, m_bLockUser, m_bLockCustomDir; QString custom; QString customLocation; KListWidgetSearchLine *searchLine; }; /* * KIconDialog: Dialog for selecting icons. Both system and user * specified icons can be chosen. */ KIconDialog::KIconDialog(QWidget *parent) : KDialog(parent), d(new KIconDialogPrivate(this)) { setModal( true ); setCaption( i18n("Select Icon") ); setButtons( Ok | Cancel ); setDefaultButton( Ok ); d->mpLoader = KIconLoader::global(); d->init(); } KIconDialog::KIconDialog(KIconLoader *loader, QWidget *parent) : KDialog(parent), d(new KIconDialogPrivate(this)) { setModal( true ); setCaption( i18n("Select Icon") ); setButtons( Ok | Cancel ); setDefaultButton( Ok ); d->mpLoader = loader; d->init(); } void KIconDialog::KIconDialogPrivate::init() { mGroupOrSize = KIconLoader::Desktop; mContext = KIconLoader::Any; mFileList = KGlobal::dirs()->findAllResources("appicon", QLatin1String("*.png")); QWidget *main = new QWidget(q); q->setMainWidget(main); QVBoxLayout *top = new QVBoxLayout(main); top->setMargin(0); QGroupBox *bgroup = new QGroupBox(main); bgroup->setTitle(i18n("Icon Source")); QVBoxLayout *vbox = new QVBoxLayout; bgroup->setLayout( vbox ); top->addWidget(bgroup); QGridLayout *grid = new QGridLayout(); grid->setSpacing(KDialog::spacingHint()); bgroup->layout()->addItem(grid); mpSystemIcons = new QRadioButton(i18n("S&ystem icons:"), bgroup); connect(mpSystemIcons, SIGNAL(clicked()), q, SLOT(_k_slotSystemIconClicked())); grid->addWidget(mpSystemIcons, 1, 0); mpCombo = new QComboBox(bgroup); connect(mpCombo, SIGNAL(activated(int)), q, SLOT(_k_slotContext(int))); grid->addWidget(mpCombo, 1, 1); mpOtherIcons = new QRadioButton(i18n("O&ther icons:"), bgroup); connect(mpOtherIcons, SIGNAL(clicked()), q, SLOT(_k_slotOtherIconClicked())); grid->addWidget(mpOtherIcons, 2, 0); mpBrowseBut = new QPushButton(i18n("&Browse..."), bgroup); connect(mpBrowseBut, SIGNAL(clicked()), q, SLOT(_k_slotBrowse())); grid->addWidget(mpBrowseBut, 2, 1); // // ADD SEARCHLINE // QHBoxLayout *searchLayout = new QHBoxLayout(); searchLayout->setMargin(0); searchLayout->setSpacing(KDialog::spacingHint()); top->addLayout(searchLayout); QLabel *searchLabel = new QLabel(i18n("&Search:"), main); searchLayout->addWidget(searchLabel); searchLine = new KListWidgetSearchLine(main); searchLayout->addWidget(searchLine); searchLabel->setBuddy(searchLine); QString wtstr = i18n("Search interactively for icon names (e.g. folder)."); searchLabel->setWhatsThis(wtstr); searchLine->setWhatsThis(wtstr); mpCanvas = new KIconCanvas(main); connect(mpCanvas, SIGNAL(itemActivated(QListWidgetItem *)), q, SLOT(_k_slotAcceptIcons())); mpCanvas->setMinimumSize(400, 125); top->addWidget(mpCanvas); searchLine->setListWidget(mpCanvas); mpProgress = new QProgressBar(main); top->addWidget(mpProgress); connect(mpCanvas, SIGNAL(startLoading(int)), q, SLOT(_k_slotStartLoading(int))); connect(mpCanvas, SIGNAL(progress(int)), q, SLOT(_k_slotProgress(int))); connect(mpCanvas, SIGNAL(finished()), q, SLOT(_k_slotFinished())); // When pressing Ok or Cancel, stop loading icons connect(q, SIGNAL(hidden()), mpCanvas, SLOT(stopLoading())); static const char* const context_text[] = { I18N_NOOP( "Actions" ), I18N_NOOP( "Animations" ), I18N_NOOP( "Applications" ), I18N_NOOP( "Categories" ), I18N_NOOP( "Devices" ), I18N_NOOP( "Emblems" ), I18N_NOOP( "Emotes" ), I18N_NOOP( "Filesystems" ), I18N_NOOP( "International" ), I18N_NOOP( "Mimetypes" ), I18N_NOOP( "Places" ), I18N_NOOP( "Status" ) }; static const KIconLoader::Context context_id[] = { KIconLoader::Action, KIconLoader::Animation, KIconLoader::Application, KIconLoader::Category, KIconLoader::Device, KIconLoader::Emblem, KIconLoader::Emote, KIconLoader::FileSystem, KIconLoader::International, KIconLoader::MimeType, KIconLoader::Place, KIconLoader::StatusIcon }; mNumContext = 0; int cnt = sizeof( context_text ) / sizeof( context_text[ 0 ] ); // check all 3 arrays have same sizes Q_ASSERT( cnt == sizeof( context_id ) / sizeof( context_id[ 0 ] ) && cnt == sizeof( mContextMap ) / sizeof( mContextMap[ 0 ] )); for( int i = 0; i < cnt; ++i ) { if( mpLoader->hasContext( context_id[ i ] )) { mpCombo->addItem(i18n( context_text[ i ] )); mContextMap[ mNumContext++ ] = context_id[ i ]; } } mpCombo->setFixedSize(mpCombo->sizeHint()); mpBrowseBut->setFixedWidth(mpCombo->width()); // Make the dialog a little taller q->incrementInitialSize(QSize(0,100)); connect(q, SIGNAL(okClicked()), q, SLOT(slotOk())); } KIconDialog::~KIconDialog() { delete d; } void KIconDialog::KIconDialogPrivate::_k_slotAcceptIcons() { custom.clear(); q->slotOk(); } void KIconDialog::KIconDialogPrivate::showIcons() { mpCanvas->clear(); QStringList filelist; if (mpSystemIcons->isChecked()) if (m_bStrictIconSize) filelist=mpLoader->queryIcons(mGroupOrSize, mContext); else filelist=mpLoader->queryIconsByContext(mGroupOrSize, mContext); else if (!customLocation.isNull()) { filelist = mpLoader->queryIconsByDir(customLocation); } else filelist=mFileList; QList iconlist; QStringList::Iterator it; foreach (const QString &it, filelist) { iconlist.append(IconPath(it)); } qSort(iconlist); filelist.clear(); foreach (const IconPath &ip, iconlist) { filelist.append(ip); } searchLine->clear(); mpCanvas->loadFiles(filelist); } void KIconDialog::setStrictIconSize(bool b) { d->m_bStrictIconSize=b; } bool KIconDialog::strictIconSize() const { return d->m_bStrictIconSize; } void KIconDialog::setIconSize( int size ) { // see KIconLoader, if you think this is weird if (size == 0) { d->mGroupOrSize = KIconLoader::Desktop; // default Group } else { d->mGroupOrSize = -size; // yes, KIconLoader::queryIconsByContext is weird } } int KIconDialog::iconSize() const { // 0 or any other value ==> mGroupOrSize is a group, so we return 0 return (d->mGroupOrSize < 0) ? -d->mGroupOrSize : 0; } void KIconDialog::setup(KIconLoader::Group group, KIconLoader::Context context, bool strictIconSize, int iconSize, bool user, bool lockUser, bool lockCustomDir ) { d->m_bStrictIconSize = strictIconSize; d->m_bLockUser = lockUser; d->m_bLockCustomDir = lockCustomDir; d->mGroupOrSize = (iconSize == 0) ? group : -iconSize; d->mpSystemIcons->setChecked(!user); d->mpSystemIcons->setEnabled(!lockUser || !user); d->mpOtherIcons->setChecked(user); d->mpOtherIcons->setEnabled(!lockUser || user); d->mpCombo->setEnabled(!user); d->mpBrowseBut->setEnabled(user && !lockCustomDir); d->setContext(context); } void KIconDialog::KIconDialogPrivate::setContext(KIconLoader::Context context) { mContext = context; for( int i = 0; i < mNumContext; ++i ) if( mContextMap[ i ] == context ) { mpCombo->setCurrentIndex( i ); return; } } void KIconDialog::setCustomLocation( const QString& location ) { d->customLocation = location; } QString KIconDialog::openDialog() { d->showIcons(); if ( exec() == Accepted ) { if (!d->custom.isNull()) return d->custom; QString name = d->mpCanvas->getCurrent(); if (name.isEmpty() || d->mpOtherIcons->isChecked()) { return name; } QFileInfo fi(name); return fi.baseName(); } return QString(); } void KIconDialog::showDialog() { setModal(false); d->showIcons(); show(); } void KIconDialog::slotOk() { QString name; if (!d->custom.isNull()) { name = d->custom; } else { name = d->mpCanvas->getCurrent(); if (!name.isEmpty() && d->mpSystemIcons->isChecked()) { QFileInfo fi(name); name = fi.baseName(); } } emit newIconName(name); KDialog::accept(); } QString KIconDialog::getIcon(KIconLoader::Group group, KIconLoader::Context context, bool strictIconSize, int iconSize, bool user, QWidget *parent, const QString &caption) { KIconDialog dlg(parent); dlg.setup( group, context, strictIconSize, iconSize, user ); if (!caption.isNull()) dlg.setCaption(caption); return dlg.openDialog(); } void KIconDialog::KIconDialogPrivate::_k_slotBrowse() { // Create a file dialog to select a PNG, XPM or SVG file, // with the image previewer shown. // KFileDialog::getImageOpenURL doesn't allow svg. KUrl emptyUrl; KFileDialog dlg(emptyUrl, i18n("*.png *.xpm *.svg *.svgz|Icon Files (*.png *.xpm *.svg *.svgz)"), q); dlg.setOperationMode( KFileDialog::Opening ); dlg.setCaption( i18n("Open") ); dlg.setMode( KFile::File ); KImageFilePreview *ip = new KImageFilePreview( &dlg ); dlg.setPreviewWidget( ip ); dlg.exec(); QString file = dlg.selectedFile(); if (!file.isEmpty()) { custom = file; if (mpSystemIcons->isChecked()) { customLocation = QFileInfo(file).absolutePath(); } q->slotOk(); } } void KIconDialog::KIconDialogPrivate::_k_slotSystemIconClicked() { mpBrowseBut->setEnabled(false); mpCombo->setEnabled(true); showIcons(); } void KIconDialog::KIconDialogPrivate::_k_slotOtherIconClicked() { mpBrowseBut->setEnabled(!m_bLockCustomDir); mpCombo->setEnabled(false); showIcons(); } void KIconDialog::KIconDialogPrivate::_k_slotContext(int id) { mContext = static_cast( mContextMap[ id ] ); showIcons(); } void KIconDialog::KIconDialogPrivate::_k_slotStartLoading(int steps) { if (steps < 10) mpProgress->hide(); else { mNumOfSteps = steps; mpProgress->setValue(0); mpProgress->show(); } } void KIconDialog::KIconDialogPrivate::_k_slotProgress(int p) { mpProgress->setValue(static_cast(100.0 * (double)p / (double)mNumOfSteps)); } void KIconDialog::KIconDialogPrivate::_k_slotFinished() { mNumOfSteps = 1; mpProgress->hide(); } class KIconButton::KIconButtonPrivate { public: KIconButtonPrivate(KIconButton *qq, KIconLoader *loader); ~KIconButtonPrivate(); // slots void _k_slotChangeIcon(); void _k_newIconName(const QString&); KIconButton *q; int iconSize; + int buttonIconSize; bool m_bStrictIconSize; bool mbUser; KIconLoader::Group mGroup; KIconLoader::Context mContext; QString mIcon; KIconDialog *mpDialog; KIconLoader *mpLoader; }; /* * KIconButton: A "choose icon" pushbutton. */ KIconButton::KIconButton(QWidget *parent) : QPushButton(parent), d(new KIconButtonPrivate(this, KIconLoader::global())) { QPushButton::setIconSize(QSize(48, 48)); } KIconButton::KIconButton(KIconLoader *loader, QWidget *parent) : QPushButton(parent), d(new KIconButtonPrivate(this, loader)) { QPushButton::setIconSize(QSize(48, 48)); } KIconButton::KIconButtonPrivate::KIconButtonPrivate(KIconButton *qq, KIconLoader *loader) : q(qq) { m_bStrictIconSize = false; iconSize = 0; // let KIconLoader choose the default + buttonIconSize = -1; //When buttonIconSize is -1, iconSize will be used for the button mGroup = KIconLoader::Desktop; mContext = KIconLoader::Application; mbUser = false; mpLoader = loader; mpDialog = 0L; connect(q, SIGNAL(clicked()), q, SLOT(_k_slotChangeIcon())); } KIconButton::KIconButtonPrivate::~KIconButtonPrivate() { delete mpDialog; } KIconButton::~KIconButton() { delete d; } void KIconButton::setStrictIconSize(bool b) { d->m_bStrictIconSize=b; } bool KIconButton::strictIconSize() const { return d->m_bStrictIconSize; } void KIconButton::setIconSize( int size ) { - QPushButton::setIconSize(QSize(size, size)); + if (d->buttonIconSize == -1) { + QPushButton::setIconSize(QSize(size, size)); + } + d->iconSize = size; } int KIconButton::iconSize() const { return d->iconSize; } +void KIconButton::setButtonIconSize( int size ) +{ + QPushButton::setIconSize(QSize(size, size)); + d->buttonIconSize = size; +} + +int KIconButton::buttonIconSize() const +{ + return QPushButton::iconSize().height(); +} + void KIconButton::setIconType(KIconLoader::Group group, KIconLoader::Context context, bool user) { d->mGroup = group; d->mContext = context; d->mbUser = user; } void KIconButton::setIcon(const QString& icon) { d->mIcon = icon; setIcon(KIcon(d->mIcon)); if (!d->mpDialog) { d->mpDialog = new KIconDialog(d->mpLoader, this); connect(d->mpDialog, SIGNAL(newIconName(const QString&)), this, SLOT(_k_newIconName(const QString&))); } if (d->mbUser) { d->mpDialog->setCustomLocation(QFileInfo(d->mpLoader->iconPath(d->mIcon, d->mGroup, true) ).absolutePath()); } } void KIconButton::setIcon(const QIcon& icon) { QPushButton::setIcon(icon); } void KIconButton::resetIcon() { d->mIcon.clear(); setIcon(QIcon()); } const QString &KIconButton::icon() const { return d->mIcon; } void KIconButton::KIconButtonPrivate::_k_slotChangeIcon() { if (!mpDialog) { mpDialog = new KIconDialog(mpLoader, q); connect(mpDialog, SIGNAL(newIconName(const QString&)), q, SLOT(_k_newIconName(const QString&))); } mpDialog->setup(mGroup, mContext, m_bStrictIconSize, iconSize, mbUser); mpDialog->showDialog(); } void KIconButton::KIconButtonPrivate::_k_newIconName(const QString& name) { if (name.isEmpty()) return; q->setIcon(KIcon(name)); mIcon = name; if (mbUser) { mpDialog->setCustomLocation(QFileInfo(mpLoader->iconPath(mIcon, mGroup, true)).absolutePath()); } emit q->iconChanged(name); } #include "kicondialog.moc" diff --git a/kio/kfile/kicondialog.h b/kio/kfile/kicondialog.h index 0518bba8ea..6f5ce8d6b1 100644 --- a/kio/kfile/kicondialog.h +++ b/kio/kfile/kicondialog.h @@ -1,334 +1,347 @@ /* vi: ts=8 sts=4 sw=4 * * This file is part of the KDE project, module kfile. * Copyright (C) 2000 Geert Jansen * (C) 2000 Kurt Granroth * (C) 1997 Christoph Neerfeld * (C) 2002 Carsten Pfeiffer * * This is free software; it comes under the GNU Library General * Public License, version 2. See the file "COPYING.LIB" for the * exact licensing terms. */ #ifndef KICONDIALOG_H #define KICONDIALOG_H #include #include #include #include #include class KIconLoader; /** * Icon canvas for KIconDialog. */ class KIO_EXPORT KIconCanvas: public KListWidget { Q_OBJECT public: /** * Creates a new icon canvas. * * @param parent The parent widget. */ explicit KIconCanvas(QWidget *parent=0L); /** * Destroys the icon canvas. */ ~KIconCanvas(); /** * Load icons into the canvas. */ void loadFiles(const QStringList& files); /** * Returns the current icon. */ QString getCurrent() const; public Q_SLOTS: /** * Call this slot to stop the loading of the icons. */ void stopLoading(); Q_SIGNALS: /** * Emitted when the current icon has changed. */ void nameChanged(const QString&); /** * This signal is emitted when the loading of the icons * has started. * * @param count The number of icons to be loaded. */ void startLoading(int count); /** * This signal is emitted whenever an icon has been loaded. * * @param number The number of the currently loaded item. */ void progress(int number); /** * This signal is emitted when the loading of the icons * has been finished. */ void finished(); private: class KIconCanvasPrivate; KIconCanvasPrivate* const d; Q_DISABLE_COPY(KIconCanvas) Q_PRIVATE_SLOT(d, void _k_slotLoadFiles()) Q_PRIVATE_SLOT(d, void _k_slotCurrentChanged(QListWidgetItem *item)) }; /** * Dialog for interactive selection of icons. Use the function * getIcon() let the user select an icon. * * @short An icon selection dialog. */ class KIO_EXPORT KIconDialog: public KDialog { Q_OBJECT public: /** * Constructs an icon selection dialog using the global iconloader. * * @param parent The parent widget. */ explicit KIconDialog(QWidget *parent=0L); /** * Constructs an icon selection dialog using a specific iconloader. * * @param loader The icon loader to use. * @param parent The parent widget. */ explicit KIconDialog(KIconLoader *loader, QWidget *parent=0); /** * Destructs the dialog. */ ~KIconDialog(); /** * Sets a strict icon size policy for allowed icons. When true, * only icons of the specified group's size in getIcon() are shown. * When false, icons not available at the desired group's size will * also be selectable. */ void setStrictIconSize(bool b); /** * Returns true if a strict icon size policy is set. */ bool strictIconSize() const; /** * sets a custom icon directory */ void setCustomLocation( const QString& location ); /** * Sets the size of the icons to be shown / selected. * @see KIconLoader::StdSizes * @see iconSize */ void setIconSize(int size); /** * Returns the iconsize set via setIconSize() or 0, if the default * iconsize will be used. */ int iconSize() const; /** * Allows you to set the same parameters as in the class method * getIcon(), as well as two additional parameters to lock * the choice between system and user dirs and to lock the custom user * dir itself. */ void setup( KIconLoader::Group group, KIconLoader::Context context = KIconLoader::Application, bool strictIconSize = false, int iconSize = 0, bool user = false, bool lockUser = false, bool lockCustomDir = false ); /** * exec()utes this modal dialog and returns the name of the selected icon, * or QString() if the dialog was aborted. * @returns the name of the icon, suitable for loading with KIconLoader. * @see getIcon */ QString openDialog(); /** * show()es this dialog and emits a newIcon(const QString&) signal when * successful. QString() will be emitted if the dialog was aborted. */ void showDialog(); /** * Pops up the dialog an lets the user select an icon. * * @param group The icon group this icon is intended for. Providing the * group shows the icons in the dialog with the same appearance as when * used outside the dialog. * @param context The initial icon context. Initially, the icons having * this context are shown in the dialog. The user can change this. * @param strictIconSize When true, only icons of the specified group's size * are shown, otherwise icon not available in the desired group's size * will also be selectable. * @param iconSize the size of the icons -- the default of the icongroup * if set to 0 * @param user Begin with the "user icons" instead of "system icons". * @param parent The parent widget of the dialog. * @param caption The caption to use for the dialog. * @return The name of the icon, suitable for loading with KIconLoader. */ static QString getIcon(KIconLoader::Group group=KIconLoader::Desktop, KIconLoader::Context context=KIconLoader::Application, bool strictIconSize=false, int iconSize = 0, bool user=false, QWidget *parent=0, const QString &caption=QString()); Q_SIGNALS: void newIconName(const QString&); protected Q_SLOTS: void slotOk(); private: class KIconDialogPrivate; KIconDialogPrivate* const d; Q_DISABLE_COPY(KIconDialog) Q_PRIVATE_SLOT(d, void _k_slotContext(int)) Q_PRIVATE_SLOT(d, void _k_slotStartLoading(int)) Q_PRIVATE_SLOT(d, void _k_slotProgress(int)) Q_PRIVATE_SLOT(d, void _k_slotFinished()) Q_PRIVATE_SLOT(d, void _k_slotAcceptIcons()) Q_PRIVATE_SLOT(d, void _k_slotBrowse()) Q_PRIVATE_SLOT(d, void _k_slotOtherIconClicked()) Q_PRIVATE_SLOT(d, void _k_slotSystemIconClicked()) }; /** * A pushbutton for choosing an icon. Pressing on the button will open a * KIconDialog for the user to select an icon. The current icon will be * displayed on the button. * * @see KIconDialog * @short A push button that allows selection of an icon. */ class KIO_EXPORT KIconButton: public QPushButton { Q_OBJECT Q_PROPERTY( QString icon READ icon WRITE setIcon RESET resetIcon ) Q_PROPERTY( int iconSize READ iconSize WRITE setIconSize) Q_PROPERTY( bool strictIconSize READ strictIconSize WRITE setStrictIconSize ) public: /** * Constructs a KIconButton using the global iconloader. * * @param parent The parent widget. */ explicit KIconButton(QWidget *parent=0L); /** * Constructs a KIconButton using a specific KIconLoader. * * @param loader The icon loader to use. * @param parent The parent widget. */ KIconButton(KIconLoader *loader, QWidget *parent); /** * Destructs the button. */ ~KIconButton(); /** * Sets a strict icon size policy for allowed icons. When true, * only icons of the specified group's size in setIconType are allowed, * and only icons of that size will be shown in the icon dialog. */ void setStrictIconSize(bool b); /** * Returns true if a strict icon size policy is set. */ bool strictIconSize() const; /** * Sets the icon group and context. Use KIconLoader::NoGroup if you want to * allow icons for any group in the given context. */ void setIconType(KIconLoader::Group group, KIconLoader::Context context, bool user=false); /** * Sets the button's initial icon. */ void setIcon(const QString& icon); void setIcon(const QIcon& icon); /** * Resets the icon (reverts to an empty button). */ void resetIcon(); /** * Returns the name of the selected icon. */ const QString &icon() const; /** * Sets the size of the icon to be shown / selected. * @see KIconLoader::StdSizes * @see iconSize */ void setIconSize( int size ); /** * Returns the iconsize set via setIconSize() or 0, if the default * iconsize will be used. */ int iconSize() const; + /** + * Sets the size of the icon to be shown on the button + * @see KIconLoader::StdSizes + * @see buttonIconSize + */ + void setButtonIconSize( int size ); + + /** + * Returns the Button's Icon-Size + */ + int buttonIconSize() const; + + Q_SIGNALS: /** * Emitted when the icon has changed. */ void iconChanged(const QString &icon); private: class KIconButtonPrivate; KIconButtonPrivate* const d; Q_DISABLE_COPY(KIconButton) Q_PRIVATE_SLOT(d, void _k_slotChangeIcon()) Q_PRIVATE_SLOT(d, void _k_newIconName(const QString&)) }; #endif // KICONDIALOG_H