https://bugs.kde.org/show_bug.cgi?id=361047
Omar Amin <omar.moh.a...@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #99001|0 |1 is obsolete| | --- Comment #45 from Omar Amin <omar.moh.a...@gmail.com> --- Comment on attachment 99001 --> https://bugs.kde.org/attachment.cgi?id=99001 patch3 grouped images, fitting grouped borders >diff --git a/app/items/imagedelegate.cpp b/app/items/imagedelegate.cpp >index 25f36c8..716afc4 100644 >--- a/app/items/imagedelegate.cpp >+++ b/app/items/imagedelegate.cpp >@@ -253,16 +253,22 @@ void ImageDelegate::paint(QPainter* p, const >QStyleOptionViewItem& option, const > // Thumbnail > QPixmap pix; > >+ bool isGroupExpanded = (info.hasGroupedImages() && >index.data(ImageFilterModel::GroupIsOpenRole).toBool()) >+ || (info.isGrouped()); > if (isSelected) > { > pix = d->selPixmap; > } >+ else if(isGroupExpanded) >+ { >+ pix = d->grpPixmap; >+ } > else > { > pix = d->regPixmap; > } > >- QRect actualPixmapRect = drawThumbnail(p, d->pixmapRect, pix, >thumbnailPixmap(index)); >+ QRect actualPixmapRect = drawThumbnail(p, d->pixmapRect, pix, >thumbnailPixmap(index), info.hasGroupedImages()); > > if (!actualPixmapRect.isNull()) > { >@@ -271,7 +277,16 @@ void ImageDelegate::paint(QPainter* p, const >QStyleOptionViewItem& option, const > > if (!d->ratingRect.isNull()) > { >- drawRating(p, index, d->ratingRect, info.rating(), isSelected); >+ int backgroundtype = 0; >+ if(isSelected) >+ { >+ backgroundtype = 1; >+ } >+ else if(isGroupExpanded) >+ { >+ backgroundtype = 2; >+ } >+ drawRating(p, index, d->ratingRect, info.rating(), backgroundtype); > } > > // Draw Color Label rectangle >diff --git a/libs/widgets/itemview/ditemdelegate.cpp >b/libs/widgets/itemview/ditemdelegate.cpp >index b92fd43..9fa3824 100644 >--- a/libs/widgets/itemview/ditemdelegate.cpp >+++ b/libs/widgets/itemview/ditemdelegate.cpp >@@ -78,19 +78,35 @@ void DItemDelegate::clearCaches() > d->squeezedTextCache.clear(); > } > >-QPixmap DItemDelegate::thumbnailBorderPixmap(const QSize& pixSize) const >+QPixmap DItemDelegate::thumbnailBorderPixmap(const QSize& pixSize, bool >isGrouped) const > { > const QColor borderColor = QColor(0, 0, 0, 128); >- QString cacheKey = QString::number(pixSize.width()) + >QLatin1Char('-') + QString::number(pixSize.height()); >+ QString cacheKey = QString::number(pixSize.width()) + >QLatin1Char('-') >+ + QString::number(pixSize.height()) + >QLatin1Char('-') >+ + QString::number(isGrouped); > QPixmap* const cachePix = d->thumbnailBorderCache.object(cacheKey); > > if (!cachePix) > { > const int radius = 3; >- QPixmap pix = >ThumbBarDock::generateFuzzyRect(QSize(pixSize.width() + 2*radius, >- pixSize.height() + 2*radius), >- borderColor, radius); >- >const_cast<DItemDelegate*>(this)->d->thumbnailBorderCache.insert(cacheKey, new >QPixmap(pix)); >+ QPixmap pix; >+ const int width = pixSize.width() + 2*radius; >+ const int height = pixSize.height() + 2*radius; >+ >+ if(!isGrouped) >+ { >+ pix = ThumbBarDock::generateFuzzyRect(QSize(width, height), >+ borderColor, >+ radius); >+ } >+ else >+ { >+ pix = ThumbBarDock::generateFuzzyRectForGroup(QSize(width, >height), >+ borderColor, >+ radius); >+ } >+ >+ d->thumbnailBorderCache.insert(cacheKey, new QPixmap(pix)); > return pix; > } > >diff --git a/libs/widgets/itemview/ditemdelegate.h >b/libs/widgets/itemview/ditemdelegate.h >index 87f4614..7caa5c0 100644 >--- a/libs/widgets/itemview/ditemdelegate.h >+++ b/libs/widgets/itemview/ditemdelegate.h >@@ -85,7 +85,7 @@ protected: > virtual void clearCaches(); > > QString squeezedTextCached(QPainter* const p, int width, const QString& > text) const; >- QPixmap thumbnailBorderPixmap(const QSize& pixSize) const; >+ QPixmap thumbnailBorderPixmap(const QSize& pixSize, bool isGrouped = >false) const; > > private: > >diff --git a/libs/widgets/itemview/itemviewimagedelegate.cpp >b/libs/widgets/itemview/itemviewimagedelegate.cpp >index 35b9177..cba6afc 100644 >--- a/libs/widgets/itemview/itemviewimagedelegate.cpp >+++ b/libs/widgets/itemview/itemviewimagedelegate.cpp >@@ -62,11 +62,13 @@ >ItemViewImageDelegatePrivate::ItemViewImageDelegatePrivate() > > // painting constants > radius = 3; >- margin = 5; >+ margin = 14; > > makeStarPolygon(); > >- ratingPixmaps = QVector<QPixmap>(10); >+ setGroupBackgroundColors(); >+ >+ ratingPixmaps = QVector<QPixmap>(15); > } > > void ItemViewImageDelegatePrivate::init(ItemViewImageDelegate* const _q) >@@ -77,6 +79,28 @@ void >ItemViewImageDelegatePrivate::init(ItemViewImageDelegate* const _q) > q, SLOT(slotThemeChanged())); > } > >+void ItemViewImageDelegatePrivate::setGroupBackgroundColors() >+{ >+ grpBackgroundColors["Breeze"] = QColor(200, 200, 200); >+ grpBackgroundColors["Breeze Dark"] = QColor(200, 200, 200); >+ grpBackgroundColors["Breeze High Contrast"] = QColor(200, 200, 200); >+ grpBackgroundColors["ColorContrast"] = QColor(200, 200, 200); >+ grpBackgroundColors["DarkRoom"] = QColor(200, 200, 200); >+ grpBackgroundColors["GrayCard"] = QColor(200, 200, 200); >+ grpBackgroundColors["Honeycomb"] = QColor(200, 200, 200); >+ grpBackgroundColors["LowKey"] = QColor(200, 200, 200); >+ grpBackgroundColors["Norway"] = QColor(200, 200, 200); >+ grpBackgroundColors["Obsidian Coast"] = QColor(200, 200, 200); >+ grpBackgroundColors["Oxygen"] = QColor(200, 200, 200); >+ grpBackgroundColors["Oxygen Cold"] = QColor(200, 200, 200); >+ grpBackgroundColors["Steel"] = QColor(200, 200, 200); >+ grpBackgroundColors["SunsetColor"] = QColor(200, 200, 200); >+ grpBackgroundColors["Wonton Soup"] = QColor(200, 200, 200); >+ grpBackgroundColors["Zion"] = QColor(200, 200, 200); >+ grpBackgroundColors["Zion (Reversed)"] = QColor(200, 200, 200); >+ grpBackgroundColors["Default"] = >grpBackgroundColors["Breeze"] ; >+} >+ > void ItemViewImageDelegatePrivate::clearRects() > { > gridSize = QSize(0, 0); >@@ -267,7 +291,7 @@ void ItemViewImageDelegate::invalidatePaintingCache() > } > > QRect ItemViewImageDelegate::drawThumbnail(QPainter* p, const QRect& > thumbRect, const QPixmap& background, >- const QPixmap& thumbnail) const >+ const QPixmap& thumbnail, bool >isGrouped) const > { > p->drawPixmap(0, 0, background); > >@@ -293,24 +317,38 @@ QRect ItemViewImageDelegate::drawThumbnail(QPainter* p, >const QRect& thumbRect, > > p->drawPixmap(0, 0, background); > */ >- QPixmap borderPix = thumbnailBorderPixmap(actualPixmapRect.size()); >- p->drawPixmap(actualPixmapRect.x()-3, actualPixmapRect.y()-3, borderPix); >+ QPixmap borderPix = thumbnailBorderPixmap(actualPixmapRect.size(), >isGrouped); >+ >+ if(isGrouped) >+ { >+ const int xPadding = (borderPix.width()-actualPixmapRect.width())/2; >+ const int yPadding = (borderPix.height()-actualPixmapRect.height())/2; >+ >+ p->drawPixmap(actualPixmapRect.x()-xPadding, >+ actualPixmapRect.y()-yPadding, borderPix); >+ } >+ else >+ { >+ p->drawPixmap(actualPixmapRect.x()-IMAGE_BORDER_RADIUS, >+ actualPixmapRect.y()-IMAGE_BORDER_RADIUS, borderPix); >+ } > > p->drawPixmap(r.x() + (r.width()-thumbnail.width())/2, > r.y() + (r.height()-thumbnail.height())/2, > thumbnail); >+ > //p->restore(); > return actualPixmapRect; > } > > void ItemViewImageDelegate::drawRating(QPainter* p, const QModelIndex& index, > const QRect& ratingRect, >- int rating, bool isSelected) const >+ int rating, int bgType) const > { > Q_D(const ItemViewImageDelegate); > > if (d->editingRating != index) > { >- p->drawPixmap(ratingRect, ratingPixmap(rating, isSelected)); >+ p->drawPixmap(ratingRect, ratingPixmap(rating, bgType)); > } > } > >@@ -622,6 +660,7 @@ void ItemViewImageDelegate::prepareBackground() > { > d->regPixmap = QPixmap(); > d->selPixmap = QPixmap(); >+ d->grpPixmap = QPixmap(); > } > else > { >@@ -636,6 +675,15 @@ void ItemViewImageDelegate::prepareBackground() > QPainter p2(&d->selPixmap); > p2.setPen(qApp->palette().color(QPalette::Midlight)); > p2.drawRect(0, 0, d->rect.width()-1, d->rect.height()-1); >+ >+ // getting grouped background color >+ QColor groupedImagesBGColor = >d->grpBackgroundColors[ThemeManager::instance()->currentThemeName()]; >+ >+ d->grpPixmap = QPixmap(d->rect.width(), d->rect.height()); >+ d->grpPixmap.fill(groupedImagesBGColor); >+ QPainter p3(&d->grpPixmap); >+ p3.setPen(qApp->palette().color(QPalette::Midlight)); >+ p3.drawRect(0, 0, d->rect.width()-1, d->rect.height()-1); > } > } > >@@ -653,33 +701,34 @@ void ItemViewImageDelegate::prepareRatingPixmaps(bool >composeOverBackground) > // We use antialiasing and want to pre-render the pixmaps. > // So we need the background at the time of painting, > // and the background may be a gradient, and will be different for > selected items. >- // This makes 5*2 (small) pixmaps. >+ // This makes 5*3 (small) pixmaps. > >- for (int sel=0; sel<2; ++sel) >+ for (int sel=0; sel<3; ++sel) > { > QPixmap basePix; > >- if (composeOverBackground) >- { >- // do this once for regular, once for selected backgrounds >- if (sel) >- { >- basePix = d->selPixmap.copy(d->ratingRect); >- } >- else >- { >- basePix = d->regPixmap.copy(d->ratingRect); >- } >- } >- else >- { >- basePix = QPixmap(d->ratingRect.size()); >- basePix.fill(Qt::transparent); >- } >+// if (composeOverBackground) >+// { >+// // do this once for regular, once for selected backgrounds, and >once for grouped backgrounds >+// if(sel == 2) >+// { >+// basePix = d->grpPixmap.copy(d->ratingRect); >+// } >+// else if(sel == 1) >+// { >+// basePix = d->selPixmap.copy(d->ratingRect); >+// } >+// else >+// { >+// basePix = d->regPixmap.copy(d->ratingRect); >+// } >+// } >+ basePix = QPixmap(d->ratingRect.size()); >+ basePix.fill(Qt::transparent); > > for (int rating=1; rating<=5; ++rating) > { >- // we store first the 5 regular, then the 5 selected pixmaps, for >simplicity >+ // we store first the 5 regular, then the 5 selected ,then the 5 >grouped pixmaps > int index = (sel * 5 + rating) - 1; > > // copy background >@@ -707,7 +756,7 @@ void ItemViewImageDelegate::prepareRatingPixmaps(bool >composeOverBackground) > } > } > >-QPixmap ItemViewImageDelegate::ratingPixmap(int rating, bool selected) const >+QPixmap ItemViewImageDelegate::ratingPixmap(int rating, int backgroundType) >const > { > Q_D(const ItemViewImageDelegate); > >@@ -718,7 +767,11 @@ QPixmap ItemViewImageDelegate::ratingPixmap(int rating, >bool selected) const > > --rating; > >- if (selected) >+ if(backgroundType == 2) >+ { >+ return d->ratingPixmaps.at(10 + rating); >+ } >+ else if (backgroundType == 1) > { > return d->ratingPixmaps.at(5 + rating); > } >diff --git a/libs/widgets/itemview/itemviewimagedelegate.h >b/libs/widgets/itemview/itemviewimagedelegate.h >index 16e1f0a..bfcabd9 100644 >--- a/libs/widgets/itemview/itemviewimagedelegate.h >+++ b/libs/widgets/itemview/itemviewimagedelegate.h >@@ -100,8 +100,9 @@ Q_SIGNALS: > protected: > > /// Use the tool methods for painting in subclasses >- QRect drawThumbnail(QPainter* p, const QRect& thumbRect, const QPixmap& >background, const QPixmap& thumbnail) const; >- void drawRating(QPainter* p, const QModelIndex& index, const QRect& >ratingRect, int rating, bool isSelected) const; >+ QRect drawThumbnail(QPainter* p, const QRect& thumbRect, >+ const QPixmap& background, const QPixmap& thumbnail, >bool isGrouped) const; >+ void drawRating(QPainter* p, const QModelIndex& index, const QRect& >ratingRect, int rating, int bgType) const; > void drawName(QPainter* p,const QRect& nameRect, const QString& name) > const; > void drawTitle(QPainter *p, const QRect& titleRect, const QString& title) > const; > void drawComments(QPainter* p, const QRect& commentsRect, const QString& > comments) const; >@@ -126,7 +127,7 @@ protected: > > /** Returns the relevant pixmap from the cached rating pixmaps. > */ >- QPixmap ratingPixmap(int rating, bool selected) const; >+ QPixmap ratingPixmap(int rating, int backgroundType) const; > > virtual QAbstractItemDelegate* asDelegate(); > >diff --git a/libs/widgets/itemview/itemviewimagedelegatepriv.h >b/libs/widgets/itemview/itemviewimagedelegatepriv.h >index 5c38998..a5159e2 100644 >--- a/libs/widgets/itemview/itemviewimagedelegatepriv.h >+++ b/libs/widgets/itemview/itemviewimagedelegatepriv.h >@@ -33,6 +33,7 @@ > #include <QFont> > #include <QPainter> > #include <QPolygon> >+#include <QMap> > > // Local includes > >@@ -57,6 +58,8 @@ public: > > void makeStarPolygon(); > >+ void setGroupBackgroundColors(); >+ > /// Resets cached rects. Remember to reimplement in subclass for added > rects. > virtual void clearRects(); > >@@ -70,6 +73,7 @@ public: > > QPixmap regPixmap; > QPixmap selPixmap; >+ QPixmap grpPixmap; > QVector<QPixmap> ratingPixmaps; > > QFont font; >@@ -90,6 +94,8 @@ public: > QRect oneRowComRect; > QRect oneRowXtraRect; > >+ QMap<QString,QColor> grpBackgroundColors; >+ > // constant values for drawing > int radius; > int margin; >diff --git a/libs/widgets/mainview/thumbbardock.cpp >b/libs/widgets/mainview/thumbbardock.cpp >index 21d42a6..2910339 100644 >--- a/libs/widgets/mainview/thumbbardock.cpp >+++ b/libs/widgets/mainview/thumbbardock.cpp >@@ -239,7 +239,7 @@ void ThumbBarDock::showThumbBar(bool status) > QPixmap ThumbBarDock::generateFuzzyRect(const QSize& size, const QColor& > color, int radius) > { > QPixmap pix(size); >- pix.fill(Qt::transparent); >+ pix.fill(Qt::white); > > QPainter painter(&pix); > painter.setRenderHint(QPainter::Antialiasing, true); >@@ -304,4 +304,37 @@ QPixmap ThumbBarDock::generateFuzzyRect(const QSize& >size, const QColor& color, > return pix; > } > >+ >+QPixmap ThumbBarDock::generateFuzzyRectForGroup(const QSize& size, const >QColor& color, int radius) >+{ >+ // Create two normal borders >+ QPixmap border1 = generateFuzzyRect(size, color,radius); >+ QPixmap border2 = border1.copy(); >+ >+ QTransform rm; >+ // Rotate first border right by 3 degrees >+ rm.rotate(3); >+ border1 = border1.transformed(rm, Qt::SmoothTransformation); >+ >+ // Rotate second border left by 3 degrees >+ rm.rotate(-6); >+ border2 = border2.transformed(rm, Qt::SmoothTransformation); >+ >+ // Combine both borders >+ int width = std::max(border1.size().width() , border2.size().width()); >+ int height = std::max(border1.size().height() , border2.size().height()); >+ >+ QPixmap result(QSize(width, height)); >+ result.fill(Qt::transparent); // force alpha channel >+ { >+ QPainter painter(&result); >+ painter.setRenderHints(QPainter::Antialiasing, true); >+ painter.drawPixmap(0, 0, border1); >+ painter.drawPixmap(0, 0, border2); >+ } >+ >+ return result; >+} >+ >+ > } // namespace Digikam >diff --git a/libs/widgets/mainview/thumbbardock.h >b/libs/widgets/mainview/thumbbardock.h >index 655bf11..2b7f136 100644 >--- a/libs/widgets/mainview/thumbbardock.h >+++ b/libs/widgets/mainview/thumbbardock.h >@@ -123,7 +123,8 @@ public: > void setShouldBeVisible(bool); > void restoreVisibility(); > >- static QPixmap generateFuzzyRect(const QSize& size, const QColor& color, >int radius); >+ static QPixmap generateFuzzyRect(const QSize& size, const QColor& color, >int radius); >+ static QPixmap generateFuzzyRectForGroup(const QSize& size, const QColor& >color, int radius); > > public Q_SLOTS: > -- You are receiving this mail because: You are watching all bug changes.