diff --git a/core/libs/album/treeview/abstractalbumtreeview.h b/core/libs/album/treeview/abstractalbumtreeview.h index b39add8893..704c5784eb 100644 --- a/core/libs/album/treeview/abstractalbumtreeview.h +++ b/core/libs/album/treeview/abstractalbumtreeview.h @@ -1,417 +1,423 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2009-03-25 * Description : Tree View for album models * * Copyright (C) 2009-2010 by Marcel Wiesweg * Copyright (C) 2010-2011 by Andi Clemens * Copyright (C) 2009-2019 by Gilles Caulier * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #ifndef DIGIKAM_ABSTRACT_ALBUM_TREE_VIEW_H #define DIGIKAM_ABSTRACT_ALBUM_TREE_VIEW_H // Qt includes #include // Local includes #include "albummanager.h" #include "albummodel.h" #include "albumfiltermodel.h" #include "albumpointer.h" #include "statesavingobject.h" namespace Digikam { class ContextMenuHelper; class TagModificationHelper; // NOTE: This structure name can be in conflict with QAbstractItemView::State. struct State; class AbstractAlbumTreeView; /** * Base class for all tree views that display Album-based content provided by an * AbstractSpecificAlbumModel. This class enables various utility functions like * selecting albums on mouse actions or providing an infrastructure for * displaying a context menu for albums. * * Context menu handling is implemented as template methods with hook methods * that can be implemented by subclasses to provide a custom behavior. In * default mode no context menu is shown at all. It must be enabled via a call * to setEnableContextMenu. */ class AbstractAlbumTreeView : public QTreeView, public StateSavingObject { Q_OBJECT public: enum Flag { /** Create a default model. Not supported by abstract classes. Not part of default flags! */ CreateDefaultModel, + /** Create a default filter model. */ CreateDefaultFilterModel, + /** Create a delegate which paints according to settings. * If not set, the Qt default delegate of the view is used. */ CreateDefaultDelegate, + /** Show the count according to the settings. If not set, call * setShowCount() on the model yourself. */ ShowCountAccordingToSettings, DefaultFlags = CreateDefaultFilterModel | CreateDefaultDelegate | ShowCountAccordingToSettings }; Q_DECLARE_FLAGS(Flags, Flag) public: /** * Constructs an album tree view. * If you give 0 for model, call setAlbumModel afterwards. * If you supply 0 for filterModel, call setAlbumFilterModel afterwards. */ AbstractAlbumTreeView(QWidget* const parent, Flags flags); ~AbstractAlbumTreeView(); AbstractSpecificAlbumModel* albumModel() const; AlbumFilterModel* albumFilterModel() const; /// Enable expanding of tree items on single click on the item (default: off) void setExpandOnSingleClick(const bool doThat); /// Expand an item when making it the new current item void setExpandNewCurrentItem(const bool doThat); /** * Sets whether to select an album on click via the album manager or not. * * @param selectOnClick if true, a click on an item automatically sets this * item as the current album in the album manager */ void setSelectAlbumOnClick(const bool selectOnClick); /** * Determines the global decision to show a popup menu or not. More detailed * decision at which position a menu can be shown and where not can be made * by implementing showContextMenuAt. * * @param enable if true, a context menu can be shown */ void setEnableContextMenu(const bool enable); /** * Sets whether to select the album under the mouse cursor on a context menu * request (so that the album is shown using the album manager) or not * * Defaults to true. * * @param select true if a context menu request shall select the album */ void setSelectOnContextMenu(const bool select); /** * Set the context menu title and icon. * This is used by the default implementation of contextMenuIcon() * and contextMenuTitle(). You can alternatively reimplement these methods. */ void setContextMenuIcon(const QPixmap& pixmap); void setContextMenuTitle(const QString& title); /** * This is a combination of indexAt() checked with visualRect(). * p must be in the viewport currently. Decoration will not be included. * Suitable for mouse click positions. */ QModelIndex indexVisuallyAt(const QPoint& p); /** * Ensures that every current match is visible by expanding all parent * entries. * * @param index index to start ensuring expansion state * @return true if there was a match under index. * This return value can normally be ignored by the caller because * it is only used for an internal recursion. */ bool expandMatches(const QModelIndex& index); + //@{ /** * Implements state loading for the album tree view in a somewhat clumsy * procedure because the model may not be fully loaded when this method is * called. Therefore the config is first parsed into d->statesByAlbumId * which holds the state of all tree view entries indexed by album id. * Afterwards an initial sync run is done restoring the state of all model * entries that are already present at this time. Every processed entry * is removed from d->statesByAlbumId. If there are still entries left in * this map we assume that the model is not fully loaded at the moment. * Therefore the rowsInserted signal is connected to a slot that restores * the state of new rows based on the remaining entries in * d->statesByAlbumId. */ virtual void doLoadState() override; virtual void doSaveState() override; + //@} /** * Some treeviews shall control the global current album kept by AlbumManager. * Other treeview are self-contained and shall not change the current album. * Default: false */ void setAlbumManagerCurrentAlbum(const bool setCurrentAlbum); /** * Add a context menu element which can add actions to the context * menu when the menu is generated. * First, addCustomContextMenuActions is called, then * all elements' addActions method is called in order of addition. */ class ContextMenuElement { public: virtual ~ContextMenuElement() { } /** - * Add actions to the context menu being generated - * - * @param view The AbstractAlbumTreeView which generates the menu - * @param cmh helper object to create the context menu - * @param album album on which the context menu will be created. May be null if - * it is requested on no tag entry - */ + * Add actions to the context menu being generated + * + * @param view The AbstractAlbumTreeView which generates the menu + * @param cmh helper object to create the context menu + * @param album album on which the context menu will be created. May be null if + * it is requested on no tag entry + */ virtual void addActions(AbstractAlbumTreeView* view, ContextMenuHelper& cmh, Album* album) = 0; }; void addContextMenuElement(ContextMenuElement* const element); void removeContextMenuElement(ContextMenuElement* const element); QList contextMenuElements() const; template QList currentAlbums(); // for internal use: public viewportEvent virtual bool viewportEvent(QEvent* event) override; /** * @brief selectedItems() - */ QList selectedItems(); public Q_SLOTS: void setSearchTextSettings(const SearchTextSettings& settings); /** * Selects the given album. * * @param albums albums to select * @param selectInAlbumManager the album will be set as current album, if both * this parameter is true and setAlbumManagerCurrentAlbum() was set to true. */ void setCurrentAlbums(const QList& albums, bool selectInAlbumManager = true); /** * Adapt the column sizes to the contents of the tree view. */ void adaptColumnsToContent(); /** * Scrolls to the first selected album if there is one. */ void scrollToSelectedAlbum(); /** * Expands the complete tree under the given index. * * @param index index to start expanding everything */ void expandEverything(const QModelIndex& index); Q_SIGNALS: /// Emitted when the currently selected album changes void currentAlbumChanged(Album* currentAlbum); /// Emitted when the current selection changes. Use currentChanged unless in multi-selection mode. void selectedAlbumsChanged(const QList& selectedAlbums); protected Q_SLOTS: // override if implemented behavior is not as intended virtual void slotRootAlbumAvailable(); void slotSearchTextSettingsChanged(bool wasSearching, bool searching); void slotSearchTextSettingsAboutToChange(bool searched, bool willSearch); void slotCurrentChanged(); void slotSelectionChanged(); void albumSettingsChanged(); protected: // context menu handling /** * Hook method to implement that determines if a context menu shall be * displayed for the given event at the position coded in the event. * * @param event context menu event to react on * @param albumForEvent the album at the mouse position or null if there is * no album at that position * @return true if a context menu shall be displayed at the event * coordinates, else false */ virtual bool showContextMenuAt(QContextMenuEvent* event, Album* albumForEvent); /** * Hook method that can be implemented to return a special icon used for the * context menu. * * @return the icon for the context menu */ virtual QPixmap contextMenuIcon() const; /** * Hook method to implement that returns the title for the context menu. * * @return title for the context menu */ virtual QString contextMenuTitle() const; /** * Hook method to add custom actions to the generated context menu. * * @param cmh helper object to create the context menu * @param album tag on which the context menu will be created. May be null if * it is requested on no tag entry */ virtual void addCustomContextMenuActions(ContextMenuHelper& cmh, Album* album); /** * Hook method to handle the custom context menu actions that were added * with addCustomContextMenuActions. * * @param action the action that was chosen by the user, may be null if none * of the custom actions were selected * @param album the tag on which the context menu was requested. May be null * if there was no */ virtual void handleCustomContextMenuAction(QAction* action, AlbumPointer album); // other stuff void mousePressEvent(QMouseEvent* e) override; void rowsInserted(const QModelIndex& index, int start, int end) override; void rowsAboutToBeRemoved(const QModelIndex& parent, int start, int end) override; void startDrag(Qt::DropActions supportedActions) override; void dragEnterEvent(QDragEnterEvent* e) override; void dragMoveEvent(QDragMoveEvent* e) override; void dragLeaveEvent(QDragLeaveEvent* e) override; void dropEvent(QDropEvent* e) override; virtual void middleButtonPressed(Album* a); virtual QPixmap pixmapForDrag(const QStyleOptionViewItem& option, QList indexes); void setAlbumFilterModel(AlbumFilterModel* const filterModel); void setAlbumModel(AbstractSpecificAlbumModel* const model); protected: AbstractSpecificAlbumModel* m_albumModel; AlbumFilterModel* m_albumFilterModel; AlbumModelDragDropHandler* m_dragDropHandler; bool m_checkOnMiddleClick; bool m_restoreCheckState; Flags m_flags; private: void saveStateRecursive(const QModelIndex& index, QList& selection, QList& expansion); /** * Restores the state of the index and all sub-indexes if there is an entry * for this index in stateStore. Every album that is restored is removed * from the stateStore. * * @param index index to start restoring * @param stateStore states indexed by album id */ void restoreStateForHierarchy(const QModelIndex& index, const QMap& stateStore); + /** * Restore the state for this index. */ void restoreState(const QModelIndex& index, const QMap& stateStore); /** * Creates the context menu. * * @param event event that requested the menu */ void contextMenuEvent(QContextMenuEvent* event) override; private Q_SLOTS: /** * Adapts the columns in between the given model indices to the content * size. This can be connected to dataChanged. * * @param topLeft top left index of changed data * @param bottomRight index of changed data */ void adaptColumnsOnDataChange(const QModelIndex& topLeft, const QModelIndex& bottomRight); /** * Adapt the column sizes to new contents. This can be connected to all * signals indicating row changes. * * @param parent parent index of changed rows * @param start start row changed under the parent * @param end end row changed under the parent */ void adaptColumnsOnRowChange(const QModelIndex& parent, int start, int end); /** * Adapts the column sizes if the layout changes. */ void adaptColumnsOnLayoutChange(); /** * This slot is used to ensure that after searching for entries the correct * album is selected again. Therefore it tracks new selections. */ void currentAlbumChangedForBackupSelection(Album* currentAlbum); private: class Private; Private* d; }; } // namespace Digikam Q_DECLARE_OPERATORS_FOR_FLAGS(Digikam::AbstractAlbumTreeView::Flags) #endif // DIGIKAM_ABSTRACT_ALBUM_TREE_VIEW_H diff --git a/core/libs/album/treeview/abstractalbumtreeview_p.h b/core/libs/album/treeview/abstractalbumtreeview_p.h index bb7fe41e17..4b1ea3133c 100644 --- a/core/libs/album/treeview/abstractalbumtreeview_p.h +++ b/core/libs/album/treeview/abstractalbumtreeview_p.h @@ -1,202 +1,202 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2009-03-25 * Description : Tree View for album models * * Copyright (C) 2009-2011 by Marcel Wiesweg * Copyright (C) 2010-2011 by Andi Clemens * Copyright (C) 2014 by Mohamed_Anwer * Copyright (C) 2014 by Michael G. Hansen * Copyright (C) 2009-2019 by Gilles Caulier * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #ifndef DIGIKAM_ABSTRACT_ALBUM_TREE_VIEW_P_H #define DIGIKAM_ABSTRACT_ALBUM_TREE_VIEW_P_H #include "abstractalbumtreeview.h" // Qt includes #include #include #include #include #include #include #include // KDE includes #include // Local includes #include "digikam_debug.h" #include "digikam_globals.h" #include "albumdragdrop.h" #include "albummanager.h" #include "albummodeldragdrophandler.h" #include "applicationsettings.h" #include "albumthumbnailloader.h" #include "contextmenuhelper.h" #include "fileactionmngr.h" #include "tagdragdrop.h" #include "tagmodificationhelper.h" #include "coredb.h" namespace Digikam { template static QList selectedAlbums(QItemSelectionModel* const selModel, AlbumFilterModel* const filterModel) { const QList indexes = selModel->selectedIndexes(); QList albums; foreach (const QModelIndex& index, indexes) { albums << static_cast(filterModel->albumForIndex(index)); } return albums; } // ------------------------------------------------------------------------------- struct State { State() : selected(false), expanded(false), currentIndex(false) { } bool selected; bool expanded; bool currentIndex; }; // ------------------------------------------------------------------------------- class Q_DECL_HIDDEN AlbumTreeViewDelegate : public QStyledItemDelegate { public: explicit AlbumTreeViewDelegate(AbstractAlbumTreeView* const treeView = nullptr) : QStyledItemDelegate(treeView), m_treeView(treeView), m_height(0) { updateHeight(); } virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const { QSize size = QStyledItemDelegate::sizeHint(option, index); size.setHeight(qMax(size.height(), m_height)); return size; } void updateHeight() { int h = qMax(AlbumThumbnailLoader::instance()->thumbnailSize() + 2, m_treeView->fontMetrics().height()); - if (h % 2 > 0) + if ((h % 2) > 0) { ++h; } setHeight(h); } void setHeight(int height) { if (m_height == height) { return; } m_height = height; emit sizeHintChanged(QModelIndex()); } protected: AbstractAlbumTreeView* m_treeView; int m_height; }; // ------------------------------------------------------------------------------- class Q_DECL_HIDDEN AbstractAlbumTreeView::Private { public: explicit Private() : delegate(nullptr), expandOnSingleClick(false), expandNewCurrent(false), selectAlbumOnClick(false), selectOnContextMenu(true), enableContextMenu(false), setInAlbumManager(false), resizeColumnsTimer(nullptr), configSelectionEntry(QLatin1String("Selection")), configExpansionEntry(QLatin1String("Expansion")), configCurrentIndexEntry(QLatin1String("CurrentIndex")), configSortColumnEntry(QLatin1String("SortColumn")), configSortOrderEntry(QLatin1String("SortOrder")) { } AlbumTreeViewDelegate* delegate; bool expandOnSingleClick; bool expandNewCurrent; bool selectAlbumOnClick; bool selectOnContextMenu; bool enableContextMenu; bool setInAlbumManager; QMap statesByAlbumId; QMap searchBackup; QTimer* resizeColumnsTimer; AlbumPointer lastSelectedAlbum; QList contextMenuElements; QPixmap contextMenuIcon; QString contextMenuTitle; const QString configSelectionEntry; const QString configExpansionEntry; const QString configCurrentIndexEntry; const QString configSortColumnEntry; const QString configSortOrderEntry; }; } // namespace Digikam #endif // DIGIKAM_ABSTRACT_ALBUM_TREE_VIEW_P_H diff --git a/core/libs/album/treeview/labelstreeview.cpp b/core/libs/album/treeview/labelstreeview.cpp index 560c325fdb..f851acd774 100644 --- a/core/libs/album/treeview/labelstreeview.cpp +++ b/core/libs/album/treeview/labelstreeview.cpp @@ -1,502 +1,502 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2014-05-17 * Description : Album Labels Tree View. * * Copyright (C) 2014-2015 by Mohamed_Anwer * Copyright (C) 2014-2019 by Gilles Caulier * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #include "labelstreeview.h" // QT includes #include #include #include #include // KDE includes #include #include // Local includes #include "digikam_debug.h" #include "digikam_globals.h" #include "coredbsearchxml.h" #include "searchtabheader.h" #include "albummanager.h" #include "albumtreeview.h" #include "coredbconstants.h" #include "itemlister.h" #include "statesavingobject.h" #include "coredbaccess.h" #include "coredb.h" #include "colorlabelfilter.h" #include "picklabelfilter.h" #include "tagscache.h" #include "applicationsettings.h" #include "dnotificationwrapper.h" #include "digikamapp.h" #include "ratingwidget.h" #include "dbjobsmanager.h" namespace Digikam { class Q_DECL_HIDDEN LabelsTreeView::Private { public: explicit Private() : ratings(nullptr), picks(nullptr), colors(nullptr), isCheckableTreeView(false), isLoadingState(false), iconSizeFromSetting(0) { } QFont regularFont; QSize iconSize; QTreeWidgetItem* ratings; QTreeWidgetItem* picks; QTreeWidgetItem* colors; bool isCheckableTreeView; bool isLoadingState; int iconSizeFromSetting; QHash > selectedLabels; static const QString configRatingSelectionEntry; static const QString configPickSelectionEntry; static const QString configColorSelectionEntry; static const QString configExpansionEntry; }; const QString LabelsTreeView::Private::configRatingSelectionEntry(QLatin1String("RatingSelection")); const QString LabelsTreeView::Private::configPickSelectionEntry(QLatin1String("PickSelection")); const QString LabelsTreeView::Private::configColorSelectionEntry(QLatin1String("ColorSelection")); const QString LabelsTreeView::Private::configExpansionEntry(QLatin1String("Expansion")); LabelsTreeView::LabelsTreeView(QWidget* const parent, bool setCheckable) : QTreeWidget(parent), StateSavingObject(this), d(new Private) { d->regularFont = ApplicationSettings::instance()->getTreeViewFont(); d->iconSizeFromSetting = ApplicationSettings::instance()->getTreeViewIconSize(); d->iconSize = QSize(d->iconSizeFromSetting, d->iconSizeFromSetting); d->isCheckableTreeView = setCheckable; setHeaderLabel(i18nc("@title", "Labels")); setUniformRowHeights(false); initTreeView(); if (d->isCheckableTreeView) { QTreeWidgetItemIterator it(this); while (*it) { if ((*it)->parent()) { (*it)->setFlags((*it)->flags()|Qt::ItemIsUserCheckable); (*it)->setCheckState(0, Qt::Unchecked); } ++it; } } else { setSelectionMode(QAbstractItemView::ExtendedSelection); } connect(ApplicationSettings::instance(), SIGNAL(setupChanged()), this, SLOT(slotSettingsChanged())); } LabelsTreeView::~LabelsTreeView() { delete d; } bool LabelsTreeView::isCheckable() const { return d->isCheckableTreeView; } bool LabelsTreeView::isLoadingState() const { return d->isLoadingState; } QPixmap LabelsTreeView::goldenStarPixmap(bool fillin) const { QPixmap pixmap = QPixmap(60, 60); pixmap.fill(Qt::transparent); QPainter p1(&pixmap); p1.setRenderHint(QPainter::Antialiasing, true); if (fillin) { p1.setBrush(qApp->palette().color(QPalette::Link)); } QPen pen(palette().color(QPalette::Active, foregroundRole())); p1.setPen(pen); QTransform transform; transform.scale(4, 4); // 60px/15px (RatingWidget::starPolygon() size is 15*15px) p1.setTransform(transform); p1.drawPolygon(RatingWidget::starPolygon(), Qt::WindingFill); p1.end(); return pixmap; } QPixmap LabelsTreeView::colorRectPixmap(const QColor& color) const { QRect rect(8, 8, 48, 48); QPixmap pixmap = QPixmap(60, 60); pixmap.fill(Qt::transparent); QPainter p1(&pixmap); p1.setRenderHint(QPainter::Antialiasing, true); p1.setBrush(color); p1.setPen(palette().color(QPalette::Active, foregroundRole())); p1.drawRect(rect); p1.end(); return pixmap; } QHash > LabelsTreeView::selectedLabels() { QHash > selectedLabelsHash; QList selectedRatings; QList selectedPicks; QList selectedColors; if (d->isCheckableTreeView) { QTreeWidgetItemIterator it(this, QTreeWidgetItemIterator::Checked); while (*it) { QTreeWidgetItem* const item = (*it); if (item->parent() == d->ratings) selectedRatings << indexFromItem(item).row(); else if (item->parent() == d->picks) selectedPicks << indexFromItem(item).row(); else selectedColors << indexFromItem(item).row(); ++it; } } else { foreach (QTreeWidgetItem* const item, selectedItems()) { if (item->parent() == d->ratings) selectedRatings << indexFromItem(item).row(); else if (item->parent() == d->picks) selectedPicks << indexFromItem(item).row(); else selectedColors << indexFromItem(item).row(); } } selectedLabelsHash[Ratings] = selectedRatings; selectedLabelsHash[Picks] = selectedPicks; selectedLabelsHash[Colors] = selectedColors; return selectedLabelsHash; } void LabelsTreeView::doLoadState() { d->isLoadingState = true; KConfigGroup configGroup = getConfigGroup(); const QList expansion = configGroup.readEntry(entryName(d->configExpansionEntry), QList()); const QList selectedRatings = configGroup.readEntry(entryName(d->configRatingSelectionEntry), QList()); const QList selectedPicks = configGroup.readEntry(entryName(d->configPickSelectionEntry), QList()); const QList selectedColors = configGroup.readEntry(entryName(d->configColorSelectionEntry), QList()); d->ratings->setExpanded(true); d->picks->setExpanded(true); d->colors->setExpanded(true); foreach (int parent, expansion) { switch (parent) { case 1: d->ratings->setExpanded(false); break; case 2: d->picks->setExpanded(false); break; case 3: d->colors->setExpanded(false); default: break; } } foreach (int rating, selectedRatings) { if (d->isCheckableTreeView) d->ratings->child(rating)->setCheckState(0, Qt::Checked); else d->ratings->child(rating)->setSelected(true); } foreach (int pick, selectedPicks) { if (d->isCheckableTreeView) d->picks->child(pick)->setCheckState(0, Qt::Checked); else d->picks->child(pick)->setSelected(true); } foreach (int color, selectedColors) { if (d->isCheckableTreeView) d->colors->child(color)->setCheckState(0, Qt::Checked); else d->colors->child(color)->setSelected(true); } d->isLoadingState = false; } void LabelsTreeView::doSaveState() { KConfigGroup configGroup = getConfigGroup(); QList expansion; if (!d->ratings->isExpanded()) { expansion << 1; } if (!d->picks->isExpanded()) { expansion << 2; } if (!d->colors->isExpanded()) { expansion << 3; } QHash > labels = selectedLabels(); configGroup.writeEntry(entryName(d->configExpansionEntry), expansion); configGroup.writeEntry(entryName(d->configRatingSelectionEntry), labels[Ratings]); configGroup.writeEntry(entryName(d->configPickSelectionEntry), labels[Picks]); configGroup.writeEntry(entryName(d->configColorSelectionEntry), labels[Colors]); } void LabelsTreeView::setCurrentAlbum() { emit signalSetCurrentAlbum(); } void LabelsTreeView::initTreeView() { setIconSize(QSize(d->iconSizeFromSetting*5,d->iconSizeFromSetting)); initRatingsTree(); initPicksTree(); initColorsTree(); expandAll(); setRootIsDecorated(false); } void LabelsTreeView::initRatingsTree() { d->ratings = new QTreeWidgetItem(this); d->ratings->setText(0, i18n("Rating")); d->ratings->setFont(0, d->regularFont); d->ratings->setFlags(Qt::ItemIsEnabled); QTreeWidgetItem* const noRate = new QTreeWidgetItem(d->ratings); noRate->setText(0, i18n("No Rating")); noRate->setFont(0, d->regularFont); - QPixmap pix(goldenStarPixmap().size()); - pix.fill(Qt::transparent); - QPainter p(&pix); - p.setRenderHint(QPainter::Antialiasing, true); - p.setPen(palette().color(QPalette::Active, foregroundRole())); - p.drawPixmap(0, 0, goldenStarPixmap(false)); - noRate->setIcon(0, QIcon(pix)); + QPixmap pix2(goldenStarPixmap().size()); + pix2.fill(Qt::transparent); + QPainter p2(&pix2); + p2.setRenderHint(QPainter::Antialiasing, true); + p2.setPen(palette().color(QPalette::Active, foregroundRole())); + p2.drawPixmap(0, 0, goldenStarPixmap(false)); + noRate->setIcon(0, QIcon(pix2)); noRate->setSizeHint(0, d->iconSize); for (int rate = 1 ; rate <= 5 ; ++rate) { QTreeWidgetItem* const rateWidget = new QTreeWidgetItem(d->ratings); QPixmap pix(goldenStarPixmap().width()*rate, goldenStarPixmap().height()); pix.fill(Qt::transparent); QPainter p(&pix); int offset = 0; p.setRenderHint(QPainter::Antialiasing, true); p.setPen(palette().color(QPalette::Active, foregroundRole())); for (int i = 0 ; i < rate ; ++i) { p.drawPixmap(offset, 0, goldenStarPixmap()); offset += goldenStarPixmap().width(); } rateWidget->setIcon(0, QIcon(pix)); rateWidget->setSizeHint(0, d->iconSize); } } void LabelsTreeView::initPicksTree() { d->picks = new QTreeWidgetItem(this); d->picks->setText(0, i18n("Pick")); d->picks->setFont(0, d->regularFont); d->picks->setFlags(Qt::ItemIsEnabled); QStringList pickSetNames; pickSetNames << i18n("No Pick") << i18n("Rejected Item") << i18n("Pending Item") << i18n("Accepted Item"); QStringList pickSetIcons; pickSetIcons << QLatin1String("flag-black") << QLatin1String("flag-red") << QLatin1String("flag-yellow") << QLatin1String("flag-green"); foreach (const QString& pick, pickSetNames) { QTreeWidgetItem* const pickWidgetItem = new QTreeWidgetItem(d->picks); pickWidgetItem->setText(0, pick); pickWidgetItem->setFont(0, d->regularFont); pickWidgetItem->setIcon(0, QIcon::fromTheme(pickSetIcons.at(pickSetNames.indexOf(pick)))); } } void LabelsTreeView::initColorsTree() { d->colors = new QTreeWidgetItem(this); d->colors->setText(0, i18n("Color")); d->colors->setFont(0, d->regularFont); d->colors->setFlags(Qt::ItemIsEnabled); QTreeWidgetItem* const noColor = new QTreeWidgetItem(d->colors); noColor->setText(0, i18n("No Color")); noColor->setFont(0, d->regularFont); noColor->setIcon(0, QIcon::fromTheme(QLatin1String("emblem-unmounted"))); QStringList colorSet; colorSet << QLatin1String("red") << QLatin1String("orange") << QLatin1String("yellow") << QLatin1String("darkgreen") << QLatin1String("darkblue") << QLatin1String("magenta") << QLatin1String("darkgray") << QLatin1String("black") << QLatin1String("white"); QStringList colorSetNames; colorSetNames << i18n("Red") << i18n("Orange") << i18n("Yellow") << i18n("Green") << i18n("Blue") << i18n("Magenta") << i18n("Gray") << i18n("Black") << i18n("White"); foreach (const QString& color, colorSet) { QTreeWidgetItem* const colorWidgetItem = new QTreeWidgetItem(d->colors); colorWidgetItem->setText(0, colorSetNames.at(colorSet.indexOf(color))); colorWidgetItem->setFont(0, d->regularFont); QPixmap colorIcon = colorRectPixmap(QColor(color)); colorWidgetItem->setIcon(0, QIcon(colorIcon)); colorWidgetItem->setSizeHint(0, d->iconSize); } } void LabelsTreeView::slotSettingsChanged() { if (d->iconSizeFromSetting != ApplicationSettings::instance()->getTreeViewIconSize()) { d->iconSizeFromSetting = ApplicationSettings::instance()->getTreeViewIconSize(); setIconSize(QSize(d->iconSizeFromSetting*5, d->iconSizeFromSetting)); d->iconSize = QSize(d->iconSizeFromSetting, d->iconSizeFromSetting); QTreeWidgetItemIterator it(this); while (*it) { (*it)->setSizeHint(0, d->iconSize); ++it; } } if (d->regularFont != ApplicationSettings::instance()->getTreeViewFont()) { d->regularFont = ApplicationSettings::instance()->getTreeViewFont(); QTreeWidgetItemIterator it(this); while (*it) { (*it)->setFont(0, d->regularFont); ++it; } } } void LabelsTreeView::restoreSelectionFromHistory(QHash > neededLabels) { QTreeWidgetItemIterator it(this, QTreeWidgetItemIterator::Selected); while (*it) { (*it)->setSelected(false); ++it; } foreach (int rateItemIndex, neededLabels[Ratings]) { d->ratings->child(rateItemIndex)->setSelected(true); } foreach (int pickItemIndex, neededLabels[Picks]) { d->picks->child(pickItemIndex)->setSelected(true); } foreach (int colorItemIndex, neededLabels[Colors]) { d->colors->child(colorItemIndex)->setSelected(true); } } } // namespace Digikam