File indexing completed on 2025-01-19 03:59:22

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2012-07-08
0007  * Description : Item delegate for import interface items.
0008  *
0009  * SPDX-FileCopyrightText: 2012      by Islam Wazery <wazery at ubuntu dot com>
0010  * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "itemviewimportdelegate_p.h"
0017 
0018 // Qt includes
0019 
0020 #include <QCache>
0021 #include <QPainter>
0022 #include <QIcon>
0023 #include <QApplication>
0024 
0025 // KDE includes
0026 
0027 #include <klocalizedstring.h>
0028 
0029 // Local includes
0030 
0031 #include "digikam_debug.h"
0032 #include "thememanager.h"
0033 #include "itemscanner.h"
0034 #include "itempropertiestab.h"
0035 #include "camiteminfo.h"
0036 #include "colorlabelwidget.h"
0037 #include "ratingwidget.h"
0038 
0039 namespace Digikam
0040 {
0041 
0042 ItemViewImportDelegatePrivate::ItemViewImportDelegatePrivate()
0043     : spacing      (0),
0044       thumbSize    (ThumbnailSize(0)),
0045       q            (nullptr),
0046       displayWidget(nullptr),
0047       radius       (3),       // painting constants
0048       margin       (5)
0049 {
0050     makeStarPolygon();
0051 
0052     ratingPixmaps = QVector<QPixmap>(10);
0053 }
0054 
0055 void ItemViewImportDelegatePrivate::init(ItemViewImportDelegate* const _q, QWidget* const _widget)
0056 {
0057     q             = _q;
0058     displayWidget = _widget;
0059 
0060     q->connect(ThemeManager::instance(), SIGNAL(signalThemeChanged()),
0061                q, SLOT(slotThemeChanged()));
0062 }
0063 
0064 void ItemViewImportDelegatePrivate::clearRects()
0065 {
0066     gridSize   = QSize(0, 0);
0067     rect       = QRect(0, 0, 0, 0);
0068     ratingRect = QRect(0, 0, 0, 0);
0069 }
0070 
0071 void ItemViewImportDelegatePrivate::makeStarPolygon()
0072 {
0073     // Pre-computed star polygon for a 15x15 pixmap.
0074 
0075     starPolygon     = RatingWidget::starPolygon();
0076     starPolygonSize = QSize(15, 15);
0077 }
0078 
0079 // ---- ItemViewImportDelegate -----------------------------------------------
0080 
0081 ItemViewImportDelegate::ItemViewImportDelegate(QWidget* const parent)
0082     : DItemDelegate(parent), d_ptr(new ItemViewImportDelegatePrivate)
0083 {
0084     d_ptr->init(this, parent);
0085 }
0086 
0087 ItemViewImportDelegate::ItemViewImportDelegate(ItemViewImportDelegatePrivate& dd, QWidget* const parent)
0088     : DItemDelegate(parent), d_ptr(&dd)
0089 {
0090     d_ptr->init(this, parent);
0091 }
0092 
0093 ItemViewImportDelegate::~ItemViewImportDelegate()
0094 {
0095     Q_D(ItemViewImportDelegate);
0096 
0097     removeAllOverlays();
0098     delete d;
0099 }
0100 
0101 ThumbnailSize ItemViewImportDelegate::thumbnailSize() const
0102 {
0103     Q_D(const ItemViewImportDelegate);
0104 
0105     return d->thumbSize;
0106 }
0107 
0108 double ItemViewImportDelegate::displayRatio() const
0109 {
0110     Q_D(const ItemViewImportDelegate);
0111 
0112     return d->displayWidget->devicePixelRatio();
0113 }
0114 
0115 void ItemViewImportDelegate::setThumbnailSize(const ThumbnailSize& thumbSize)
0116 {
0117     Q_D(ItemViewImportDelegate);
0118 
0119     if (d->thumbSize != thumbSize)
0120     {
0121         d->thumbSize = thumbSize;
0122         invalidatePaintingCache();
0123     }
0124 }
0125 
0126 void ItemViewImportDelegate::setSpacing(int spacing)
0127 {
0128     Q_D(ItemViewImportDelegate);
0129 
0130     if (d->spacing == spacing)
0131     {
0132         return;
0133     }
0134 
0135     d->spacing = spacing;
0136     invalidatePaintingCache();
0137 }
0138 
0139 int ItemViewImportDelegate::spacing() const
0140 {
0141     Q_D(const ItemViewImportDelegate);
0142 
0143     return d->spacing;
0144 }
0145 
0146 QRect ItemViewImportDelegate::rect() const
0147 {
0148     Q_D(const ItemViewImportDelegate);
0149 
0150     return d->rect;
0151 }
0152 
0153 QRect ItemViewImportDelegate::pixmapRect() const
0154 {
0155     return QRect();
0156 }
0157 
0158 QRect ItemViewImportDelegate::imageInformationRect() const
0159 {
0160     return QRect();
0161 }
0162 
0163 QRect ItemViewImportDelegate::ratingRect() const
0164 {
0165     Q_D(const ItemViewImportDelegate);
0166 
0167     return d->ratingRect;
0168 }
0169 
0170 void ItemViewImportDelegate::setRatingEdited(const QModelIndex& index)
0171 {
0172     Q_D(ItemViewImportDelegate);
0173 
0174     d->editingRating = index;
0175 }
0176 
0177 QSize ItemViewImportDelegate::sizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/) const
0178 {
0179     Q_D(const ItemViewImportDelegate);
0180 
0181     return d->rect.size();
0182 }
0183 
0184 QSize ItemViewImportDelegate::gridSize() const
0185 {
0186     Q_D(const ItemViewImportDelegate);
0187 
0188     return d->gridSize;
0189 }
0190 
0191 bool ItemViewImportDelegate::acceptsToolTip(const QPoint&, const QRect& visualRect, const QModelIndex&, QRect* retRect) const
0192 {
0193     if (retRect)
0194     {
0195         *retRect = visualRect;
0196     }
0197 
0198     return true;
0199 }
0200 
0201 bool ItemViewImportDelegate::acceptsActivation(const QPoint& , const QRect& visualRect, const QModelIndex&, QRect* retRect) const
0202 {
0203     if (retRect)
0204     {
0205         *retRect = visualRect;
0206     }
0207 
0208     return true;
0209 }
0210 
0211 QAbstractItemDelegate* ItemViewImportDelegate::asDelegate()
0212 {
0213     return this;
0214 }
0215 
0216 void ItemViewImportDelegate::overlayDestroyed(QObject* o)
0217 {
0218     ItemDelegateOverlayContainer::overlayDestroyed(o);
0219 }
0220 
0221 void ItemViewImportDelegate::mouseMoved(QMouseEvent* e, const QRect& visualRect, const QModelIndex& index)
0222 {
0223     // 3-way indirection AbstractImportItemDelegate -> ItemViewImportDelegate -> ItemDelegateOverlayContainer
0224 
0225     ItemDelegateOverlayContainer::mouseMoved(e, visualRect, index);
0226 }
0227 
0228 void ItemViewImportDelegate::setDefaultViewOptions(const QStyleOptionViewItem& option)
0229 {
0230     Q_D(ItemViewImportDelegate);
0231 
0232     d->font = option.font;
0233     invalidatePaintingCache();
0234 }
0235 
0236 void ItemViewImportDelegate::slotThemeChanged()
0237 {
0238     invalidatePaintingCache();
0239 }
0240 
0241 void ItemViewImportDelegate::slotSetupChanged()
0242 {
0243     invalidatePaintingCache();
0244 }
0245 
0246 void ItemViewImportDelegate::invalidatePaintingCache()
0247 {
0248     Q_D(ItemViewImportDelegate);
0249 
0250     QSize oldGridSize = d->gridSize;
0251     updateSizeRectsAndPixmaps();
0252 
0253     if (oldGridSize != d->gridSize)
0254     {
0255         Q_EMIT gridSizeChanged(d->gridSize);
0256 /*
0257         Q_EMIT sizeHintChanged(QModelIndex());
0258 */
0259     }
0260 
0261     Q_EMIT visualChange();
0262 }
0263 
0264 QRect ItemViewImportDelegate::drawThumbnail(QPainter* p, const QRect& thumbRect, const QPixmap& background,
0265                                             const QPixmap& thumbnail) const
0266 {
0267     p->drawPixmap(0, 0, background);
0268 
0269     if (thumbnail.isNull())
0270     {
0271         return QRect();
0272     }
0273 
0274     QRect r    = thumbRect;
0275     double dpr =  thumbnail.devicePixelRatio();
0276     int thumbW = qRound((double)thumbnail.width()  / dpr);
0277     int thumbH = qRound((double)thumbnail.height() / dpr);
0278 
0279     QRect actualPixmapRect(r.x() + (r.width()  - thumbW) / 2,
0280                            r.y() + (r.height() - thumbH) / 2,
0281                            thumbW, thumbH);
0282 
0283     QPixmap borderPix = thumbnailBorderPixmap(actualPixmapRect.size());
0284 
0285     p->drawPixmap(actualPixmapRect.x() - 3,
0286                   actualPixmapRect.y() - 3, borderPix);
0287 
0288     p->drawPixmap(r.x() + (r.width()  - thumbW) / 2,
0289                   r.y() + (r.height() - thumbH) / 2,
0290                   thumbW, thumbH, thumbnail);
0291 
0292     return actualPixmapRect;
0293 }
0294 
0295 void ItemViewImportDelegate::drawRating(QPainter* p, const QModelIndex& index, const QRect& ratingRect,
0296                                        int rating, bool isSelected) const
0297 {
0298     Q_D(const ItemViewImportDelegate);
0299 
0300     if (d->editingRating != index)
0301     {
0302         p->drawPixmap(ratingRect, ratingPixmap(rating, isSelected));
0303     }
0304 }
0305 
0306 void ItemViewImportDelegate::drawName(QPainter* p,const QRect& nameRect, const QString& name) const
0307 {
0308     Q_D(const ItemViewImportDelegate);
0309 
0310     p->setFont(d->fontReg);
0311     p->drawText(nameRect, Qt::AlignCenter, name);//squeezedTextCached(p, nameRect.width(), name));
0312 }
0313 
0314 void ItemViewImportDelegate::drawCreationDate(QPainter* p, const QRect& dateRect, const QDateTime& date) const
0315 {
0316     Q_D(const ItemViewImportDelegate);
0317 
0318     p->setFont(d->fontXtra);
0319     QString str = dateToString(date);
0320     str         = i18nc("date of image creation", "created: %1", str);
0321     p->drawText(dateRect, Qt::AlignCenter, str);//squeezedTextCached(p, dateRect.width(), str));
0322 }
0323 
0324 void ItemViewImportDelegate::drawImageFormat(QPainter* p, const QRect& r, const QString& mime) const
0325 {
0326     Q_D(const ItemViewImportDelegate);
0327 
0328     if (!mime.isEmpty() && !r.isNull())
0329     {
0330         QString type = mime.split(QLatin1Char('/')).at(1);
0331         type         = ItemScanner::formatToString(type);
0332 
0333         p->save();
0334 
0335         QFont fnt(d->fontReg);
0336         fnt.setWeight(QFont::Black);
0337         fnt.setItalic(false);
0338         p->setFont(fnt);
0339         p->setPen(QPen(Qt::gray));
0340         p->setOpacity(0.50);
0341 
0342         QRect bRect = p->boundingRect(r, Qt::AlignBottom | Qt::AlignHCenter, type.toUpper());
0343         bRect.adjust(1, 1, -1, -1);
0344         bRect.translate(0, 1);
0345 
0346         p->fillRect(bRect, Qt::SolidPattern);
0347         p->setPen(QPen(Qt::white));
0348         p->setOpacity(1.0);
0349         p->drawText(bRect, Qt::AlignBottom | Qt::AlignHCenter, type.toUpper());
0350 
0351         p->restore();
0352     }
0353 }
0354 
0355 void ItemViewImportDelegate::drawImageSize(QPainter* p, const QRect& dimsRect, const QSize& dims) const
0356 {
0357     Q_D(const ItemViewImportDelegate);
0358 
0359     if (dims.isValid())
0360     {
0361         p->setFont(d->fontXtra);
0362         QString mpixels, resolution;
0363         mpixels = QLocale().toString(dims.width()*dims.height()/1000000.0, 'f', 1);
0364 
0365         if (dims.isValid())
0366         {
0367             resolution = i18nc("%1 width, %2 height, %3 mpixels", "%1x%2 (%3Mpx)",
0368                                dims.width(), dims.height(), mpixels);
0369         }
0370         else
0371         {
0372             resolution = i18nc("unknown image resolution", "Unknown");
0373         }
0374 
0375         p->drawText(dimsRect, Qt::AlignCenter, resolution);
0376     }
0377 }
0378 
0379 void ItemViewImportDelegate::drawFileSize(QPainter* p, const QRect& r, qlonglong bytes) const
0380 {
0381     Q_D(const ItemViewImportDelegate);
0382 
0383     p->setFont(d->fontXtra);
0384     p->drawText(r, Qt::AlignCenter, ItemPropertiesTab::humanReadableBytesCount(bytes));
0385 }
0386 
0387 void ItemViewImportDelegate::drawTags(QPainter* p, const QRect& r, const QString& tagsString,
0388                                      bool isSelected) const
0389 {
0390     Q_D(const ItemViewImportDelegate);
0391 
0392     p->setFont(d->fontCom);
0393     p->setPen(isSelected ? qApp->palette().color(QPalette::HighlightedText)
0394                          : qApp->palette().color(QPalette::Link));
0395 
0396     p->drawText(r, Qt::AlignCenter, squeezedTextCached(p, r.width(), tagsString));
0397 }
0398 
0399 void ItemViewImportDelegate::drawPickLabelIcon(QPainter* p, const QRect& r, int pickId) const
0400 {
0401     // Draw Pick Label icon
0402 
0403     if (pickId != NoPickLabel)
0404     {
0405         QIcon icon;
0406 
0407         if      (pickId == RejectedLabel)
0408         {
0409             icon = QIcon::fromTheme(QLatin1String("flag-red"));
0410         }
0411         else if (pickId == PendingLabel)
0412         {
0413             icon = QIcon::fromTheme(QLatin1String("flag-yellow"));
0414         }
0415         else if (pickId == AcceptedLabel)
0416         {
0417             icon = QIcon::fromTheme(QLatin1String("flag-green"));
0418         }
0419 
0420         icon.paint(p, r);
0421     }
0422 }
0423 
0424 void ItemViewImportDelegate::drawColorLabelRect(QPainter* p, const QStyleOptionViewItem& option,
0425                                                 bool isSelected, int colorId) const
0426 {
0427     Q_D(const ItemViewImportDelegate);
0428     Q_UNUSED(option);
0429     Q_UNUSED(isSelected);
0430 
0431     if (colorId > NoColorLabel)
0432     {
0433         // This draw a simple rectangle around item.
0434 
0435         p->setPen(QPen(ColorLabelWidget::labelColor((ColorLabel)colorId), 5, Qt::SolidLine));
0436         p->drawRect(3, 3, d->rect.width()-7, d->rect.height()-7);
0437     }
0438 }
0439 
0440 void ItemViewImportDelegate::drawGeolocationIndicator(QPainter* p, const QRect& r) const
0441 {
0442     if (!r.isNull())
0443     {
0444         QIcon icon(QIcon::fromTheme(QLatin1String("globe")).pixmap(r.size()));
0445         QBrush brush = p->brush();
0446         p->setOpacity(0.50);
0447         p->setPen(QPen(p->background().color()));
0448         p->setBrush(QBrush(p->background().color()));
0449         p->drawEllipse(r);
0450         p->setBrush(brush);
0451         p->setOpacity(1.0);
0452         icon.paint(p, r);
0453     }
0454 }
0455 
0456 void ItemViewImportDelegate::drawDownloadIndicator(QPainter* p, const QRect& r, int itemType) const
0457 {
0458     QIcon icon;
0459 
0460     if (itemType == CamItemInfo::DownloadUnknown)
0461     {
0462         icon = QIcon::fromTheme(QLatin1String("dialog-information"));
0463     }
0464 
0465     if (itemType == CamItemInfo::DownloadedNo) // TODO: CamItemInfo::NewPicture
0466     {
0467         icon = QIcon::fromTheme(QLatin1String("folder-favorites"));
0468     }
0469 
0470     if (itemType == CamItemInfo::DownloadedYes)
0471     {
0472         icon = QIcon::fromTheme(QLatin1String("dialog-ok-apply"));
0473     }
0474 
0475     qreal op = p->opacity();
0476     p->setOpacity(0.5);
0477     icon.paint(p, r);
0478     p->setOpacity(op);
0479 }
0480 
0481 void ItemViewImportDelegate::drawLockIndicator(QPainter* p, const QRect& r, int lockStatus) const
0482 {
0483     QIcon icon;
0484 
0485     if (lockStatus == 1)
0486     {
0487         return; // draw lock only when image is locked
0488 /*
0489         icon = QIcon::fromTheme(QLatin1String("object-unlocked"));
0490 */
0491     }
0492 
0493     if (lockStatus == 0)
0494     {
0495         icon = QIcon::fromTheme(QLatin1String("object-locked"));
0496     }
0497 
0498     qreal op = p->opacity();
0499     p->setOpacity(0.5);
0500     icon.paint(p, r);
0501     p->setOpacity(op);
0502 }
0503 
0504 void ItemViewImportDelegate::drawFocusRect(QPainter* p, const QStyleOptionViewItem& option,
0505                                            bool isSelected) const
0506 {
0507     Q_D(const ItemViewImportDelegate);
0508 
0509     if (option.state & QStyle::State_HasFocus) //?? is current item
0510     {
0511         p->setPen(QPen(isSelected ? qApp->palette().color(QPalette::HighlightedText)
0512                                   : qApp->palette().color(QPalette::Text),
0513                        1, Qt::DotLine));
0514         p->drawRect(1, 1, d->rect.width()-3, d->rect.height()-3);
0515     }
0516 }
0517 
0518 void ItemViewImportDelegate::drawGroupIndicator(QPainter* p, const QRect& r,
0519                                                 int numberOfGroupedImages, bool open) const
0520 {
0521     if (numberOfGroupedImages)
0522     {
0523         QIcon icon;
0524 
0525         if (open)
0526         {
0527             icon = QIcon::fromTheme(QLatin1String("document-import"));
0528         }
0529         else
0530         {
0531             icon = QIcon::fromTheme(QLatin1String("document-multiple"));
0532         }
0533 
0534         qreal op = p->opacity();
0535         p->setOpacity(0.5);
0536         icon.paint(p, r);
0537         p->setOpacity(op);
0538 
0539         QString text = QString::number(numberOfGroupedImages);
0540         p->drawText(r, Qt::AlignCenter, text);
0541     }
0542 }
0543 
0544 void ItemViewImportDelegate::drawMouseOverRect(QPainter* p, const QStyleOptionViewItem& option) const
0545 {
0546     Q_D(const ItemViewImportDelegate);
0547 
0548     if (option.state & QStyle::State_MouseOver)
0549     {
0550         p->setPen(QPen(option.palette.color(QPalette::Highlight), 3, Qt::SolidLine));
0551         p->drawRect(1, 1, d->rect.width()-3, d->rect.height()-3);
0552     }
0553 }
0554 
0555 void ItemViewImportDelegate::prepareFonts()
0556 {
0557     Q_D(ItemViewImportDelegate);
0558 
0559     d->fontReg  = d->font;
0560     d->fontCom  = d->font;
0561     d->fontXtra = d->font;
0562     d->fontCom.setItalic(true);
0563 
0564     int fnSz    = d->fontReg.pointSize();
0565 
0566     if (fnSz > 0)
0567     {
0568         d->fontCom.setPointSize(fnSz-1);
0569         d->fontXtra.setPointSize(fnSz-2);
0570     }
0571     else
0572     {
0573         fnSz = d->fontReg.pixelSize();
0574         d->fontCom.setPixelSize(fnSz-1);
0575         d->fontXtra.setPixelSize(fnSz-2);
0576     }
0577 }
0578 
0579 void ItemViewImportDelegate::prepareMetrics(int maxWidth)
0580 {
0581     Q_D(ItemViewImportDelegate);
0582 
0583     QFontMetrics fm(d->fontReg);
0584     d->oneRowRegRect = fm.boundingRect(0, 0, maxWidth, 0xFFFFFFFF,
0585                                        Qt::AlignTop | Qt::AlignHCenter,
0586                                        QLatin1String("XXXXXXXXX"));
0587     fm = QFontMetrics(d->fontCom);
0588     d->oneRowComRect = fm.boundingRect(0, 0, maxWidth, 0xFFFFFFFF,
0589                                        Qt::AlignTop | Qt::AlignHCenter,
0590                                        QLatin1String("XXXXXXXXX"));
0591     fm = QFontMetrics(d->fontXtra);
0592     d->oneRowXtraRect = fm.boundingRect(0, 0, maxWidth, 0xFFFFFFFF,
0593                                         Qt::AlignTop | Qt::AlignHCenter,
0594                                         QLatin1String("XXXXXXXXX"));
0595 }
0596 
0597 void ItemViewImportDelegate::prepareBackground()
0598 {
0599     Q_D(ItemViewImportDelegate);
0600 
0601     if (!d->rect.isValid())
0602     {
0603         d->regPixmap = QPixmap();
0604         d->selPixmap = QPixmap();
0605     }
0606     else
0607     {
0608         d->regPixmap = QPixmap(d->rect.width(), d->rect.height());
0609         d->regPixmap.fill(qApp->palette().color(QPalette::Base));
0610         QPainter p1(&d->regPixmap);
0611         p1.setPen(qApp->palette().color(QPalette::Midlight));
0612         p1.drawRect(0, 0, d->rect.width()-1, d->rect.height()-1);
0613 
0614         d->selPixmap = QPixmap(d->rect.width(), d->rect.height());
0615         d->selPixmap.fill(qApp->palette().color(QPalette::Highlight));
0616         QPainter p2(&d->selPixmap);
0617         p2.setPen(qApp->palette().color(QPalette::Midlight));
0618         p2.drawRect(0, 0, d->rect.width()-1, d->rect.height()-1);
0619     }
0620 }
0621 
0622 void ItemViewImportDelegate::prepareRatingPixmaps(bool composeOverBackground)
0623 {
0624     /// Please call this method after prepareBackground() and when d->ratingPixmap is set
0625 
0626     Q_D(ItemViewImportDelegate);
0627 
0628     if (!d->ratingRect.isValid())
0629     {
0630         return;
0631     }
0632 
0633     // We use antialiasing and want to pre-render the pixmaps.
0634     // So we need the background at the time of painting,
0635     // and the background may be a gradient, and will be different for selected items.
0636     // This makes 5*2 (small) pixmaps.
0637 
0638     for (int sel = 0 ; sel < 2 ; ++sel)
0639     {
0640         QPixmap basePix;
0641 
0642         if (composeOverBackground)
0643         {
0644             // do this once for regular, once for selected backgrounds
0645 
0646             if (sel)
0647             {
0648                 basePix = d->selPixmap.copy(d->ratingRect);
0649             }
0650             else
0651             {
0652                 basePix = d->regPixmap.copy(d->ratingRect);
0653             }
0654         }
0655         else
0656         {
0657             basePix = QPixmap(d->ratingRect.size());
0658             basePix.fill(Qt::transparent);
0659         }
0660 
0661         double dpr = displayRatio();
0662         basePix    = basePix.scaled(d->ratingRect.size() * dpr);
0663         basePix.setDevicePixelRatio(dpr);
0664 
0665         for (int rating = 1; rating <= 5; ++rating)
0666         {
0667             // we store first the 5 regular, then the 5 selected pixmaps, for simplicity
0668 
0669             int index = (sel * 5 + rating) - 1;
0670 
0671             // copy background
0672 
0673             d->ratingPixmaps[index] = basePix;
0674 
0675             // open a painter
0676 
0677             QPainter painter(&d->ratingPixmaps[index]);
0678 
0679             // use antialiasing
0680 
0681             painter.setRenderHint(QPainter::Antialiasing, true);
0682             painter.setBrush(qApp->palette().color(QPalette::Link));
0683             QPen pen(qApp->palette().color(QPalette::Text));
0684 
0685             // set a pen which joins the lines at a filled angle
0686 
0687             pen.setJoinStyle(Qt::MiterJoin);
0688             painter.setPen(pen);
0689 
0690             // move painter while drawing polygons
0691 
0692             painter.translate( lround((d->ratingRect.width() - d->margin - rating*(d->starPolygonSize.width()+1))/2.0) + 2, 1 );
0693 
0694             for (int s = 0 ; s < rating ; ++s)
0695             {
0696                 painter.drawPolygon(d->starPolygon, Qt::WindingFill);
0697                 painter.translate(d->starPolygonSize.width() + 1, 0);
0698             }
0699         }
0700     }
0701 }
0702 
0703 QPixmap ItemViewImportDelegate::ratingPixmap(int rating, bool selected) const
0704 {
0705     Q_D(const ItemViewImportDelegate);
0706 
0707     if ((rating < 1) || (rating > 5))
0708     {
0709 /*
0710         QPixmap pix;
0711 
0712         if (selected)
0713         {
0714             pix = d->selPixmap.copy(d->ratingRect);
0715         }
0716         else
0717         {
0718             pix = d->regPixmap.copy(d->ratingRect);
0719         }
0720 
0721         return pix;
0722 */
0723         return QPixmap();
0724     }
0725 
0726     --rating;
0727 
0728     if (selected)
0729     {
0730         return d->ratingPixmaps.at(5 + rating);
0731     }
0732     else
0733     {
0734         return d->ratingPixmaps.at(rating);
0735     }
0736 }
0737 
0738 } // namespace Digikam
0739 
0740 #include "moc_itemviewimportdelegate.cpp"