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

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2012-07-08
0007  * Description : Qt item view to import items - the delegate
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 "importdelegate_p.h"
0017 
0018 // C++ includes
0019 
0020 #include <cmath>
0021 
0022 // Qt includes
0023 
0024 #include <QCache>
0025 #include <QPainter>
0026 #include <QRect>
0027 #include <QApplication>
0028 
0029 // Local includes
0030 
0031 #include "importimagemodel.h"
0032 #include "importfiltermodel.h"
0033 #include "importsettings.h"
0034 #include "importcategorizedview.h"
0035 #include "albummanager.h"
0036 
0037 namespace Digikam
0038 {
0039 
0040 void ImportDelegate::ImportDelegatePrivate::clearRects()
0041 {
0042     ItemViewImportDelegatePrivate::clearRects();
0043     dateRect             = QRect(0, 0, 0, 0);
0044     pixmapRect           = QRect(0, 0, 0, 0);
0045     nameRect             = QRect(0, 0, 0, 0);
0046 /*
0047     titleRect            = QRect(0, 0, 0, 0);
0048     commentsRect         = QRect(0, 0, 0, 0);
0049 */
0050     resolutionRect       = QRect(0, 0, 0, 0);
0051     sizeRect             = QRect(0, 0, 0, 0);
0052     downloadRect         = QRect(0, 0, 0, 0);
0053     lockRect             = QRect(0, 0, 0, 0);
0054     coordinatesRect      = QRect(0, 0, 0, 0);
0055     tagRect              = QRect(0, 0, 0, 0);
0056     ratingRect           = QRect(0, 0, 0, 0);
0057     imageInformationRect = QRect(0, 0, 0, 0);
0058     pickLabelRect        = QRect(0, 0, 0, 0);
0059     groupRect            = QRect(0, 0, 0, 0);
0060 }
0061 
0062 ImportDelegate::ImportDelegate(QWidget* const parent)
0063     : ItemViewImportDelegate(*new ImportDelegatePrivate, parent)
0064 {
0065 }
0066 
0067 ImportDelegate::ImportDelegate(ImportDelegate::ImportDelegatePrivate& dd, QWidget* const parent)
0068     : ItemViewImportDelegate(dd, parent)
0069 {
0070 }
0071 
0072 ImportDelegate::~ImportDelegate()
0073 {
0074     Q_D(ImportDelegate);
0075     Q_UNUSED(d); // To please compiler about warnings.
0076 }
0077 
0078 void ImportDelegate::setView(ImportCategorizedView* view)
0079 {
0080     Q_D(ImportDelegate);
0081     setViewOnAllOverlays(view);
0082 
0083     if (d->currentView)
0084     {
0085         disconnect(d->currentView, SIGNAL(modelChanged()),
0086                    this, SLOT(modelChanged()));
0087     }
0088 
0089     d->currentView = view;
0090 
0091     setModel(view ? view->model() : nullptr);
0092 
0093     if (d->currentView)
0094     {
0095         connect(d->currentView, SIGNAL(modelChanged()),
0096                 this, SLOT(modelChanged()));
0097     }
0098 }
0099 
0100 void ImportDelegate::setModel(QAbstractItemModel* model)
0101 {
0102     Q_D(ImportDelegate);
0103 
0104     // 1) We only need the model to invalidate model-index based caches on change
0105     // 2) We do not need to care for overlays. The view calls setActive() on them on model change
0106 
0107     if (model == d->currentModel)
0108     {
0109         return;
0110     }
0111 
0112     if (d->currentModel)
0113     {
0114         disconnect(d->currentModel, nullptr, this, nullptr);
0115     }
0116 
0117     d->currentModel = model;
0118 
0119     if (d->currentModel)
0120     {
0121         connect(d->currentModel, SIGNAL(layoutAboutToBeChanged()),
0122                 this, SLOT(modelContentsChanged()));
0123 
0124         connect(d->currentModel, SIGNAL(modelAboutToBeReset()),
0125                 this, SLOT(modelContentsChanged()));
0126 
0127         connect(d->currentModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
0128                 this, SLOT(modelContentsChanged()));
0129 
0130         connect(d->currentModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
0131                 this, SLOT(modelContentsChanged()));
0132 
0133         connect(d->currentModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
0134                 this, SLOT(modelContentsChanged()));
0135     }
0136 }
0137 
0138 void ImportDelegate::setSpacing(int spacing)
0139 {
0140     Q_D(ImportDelegate);
0141 
0142     if (d->categoryDrawer)
0143     {
0144         d->categoryDrawer->setLowerSpacing(spacing);
0145     }
0146 
0147     ItemViewImportDelegate::setSpacing(spacing);
0148 }
0149 
0150 ImportCategoryDrawer* ImportDelegate::categoryDrawer() const
0151 {
0152     Q_D(const ImportDelegate);
0153     return d->categoryDrawer;
0154 }
0155 
0156 /*
0157 QRect ImportDelegate::commentsRect() const
0158 {
0159    Q_D(const ImportDelegate);
0160    return d->commentsRect;
0161 }
0162 */
0163 
0164 QRect ImportDelegate::tagsRect() const
0165 {
0166     Q_D(const ImportDelegate);
0167     return d->tagRect;
0168 }
0169 
0170 QRect ImportDelegate::pixmapRect() const
0171 {
0172     Q_D(const ImportDelegate);
0173     return d->pixmapRect;
0174 }
0175 
0176 QRect ImportDelegate::imageInformationRect() const
0177 {
0178     Q_D(const ImportDelegate);
0179     return d->imageInformationRect;
0180 }
0181 
0182 QRect ImportDelegate::groupIndicatorRect() const
0183 {
0184     Q_D(const ImportDelegate);
0185     return d->groupRect;
0186 }
0187 
0188 QRect ImportDelegate::downloadIndicatorRect() const
0189 {
0190     Q_D(const ImportDelegate);
0191     return d->downloadRect;
0192 }
0193 
0194 QRect ImportDelegate::lockIndicatorRect() const
0195 {
0196     Q_D(const ImportDelegate);
0197     return d->lockRect;
0198 }
0199 
0200 QRect ImportDelegate::coordinatesIndicatorRect() const
0201 {
0202     Q_D(const ImportDelegate);
0203     return d->coordinatesRect;
0204 }
0205 
0206 QPixmap ImportDelegate::retrieveThumbnailPixmap(const QModelIndex& index, int thumbnailSize)
0207 {
0208     // work around constness
0209 
0210     QAbstractItemModel* const model = const_cast<QAbstractItemModel*>(index.model());
0211 
0212     // set requested thumbnail size
0213 
0214     model->setData(index, thumbnailSize, ImportItemModel::ThumbnailRole);
0215 
0216     // get data from model
0217 
0218     QVariant thumbData              = index.data(ImportItemModel::ThumbnailRole);
0219 
0220     return (thumbData.value<QPixmap>());
0221 }
0222 
0223 QPixmap ImportDelegate::thumbnailPixmap(const QModelIndex& index) const
0224 {
0225     Q_D(const ImportDelegate);
0226     return retrieveThumbnailPixmap(index, d->thumbSize.size());
0227 }
0228 
0229 void ImportDelegate::paint(QPainter* p, const QStyleOptionViewItem& option, const QModelIndex& index) const
0230 {
0231     Q_D(const ImportDelegate);
0232     CamItemInfo info = ImportItemModel::retrieveCamItemInfo(index);
0233 
0234     if (info.isNull())
0235     {
0236         return;
0237     }
0238 
0239     // state of painter must not be changed
0240 
0241     p->save();
0242     p->translate(option.rect.topLeft());
0243 
0244     bool isSelected = (option.state & QStyle::State_Selected);
0245 
0246     // Thumbnail
0247 
0248     QPixmap pix;
0249 
0250     if (isSelected)
0251     {
0252         pix = d->selPixmap;
0253     }
0254     else
0255     {
0256         pix = d->regPixmap;
0257     }
0258 
0259     QRect actualPixmapRect = drawThumbnail(p, d->pixmapRect, pix, thumbnailPixmap(index));
0260 
0261     if (!actualPixmapRect.isNull())
0262     {
0263         const_cast<ImportDelegate*>(this)->updateActualPixmapRect(index, actualPixmapRect);
0264     }
0265 
0266     if (!d->ratingRect.isNull())
0267     {
0268         drawRating(p, index, d->ratingRect, info.rating, isSelected);
0269     }
0270 
0271     // Draw Color Label rectangle
0272 
0273     drawColorLabelRect(p, option, isSelected, info.colorLabel);
0274 
0275     p->setPen(isSelected ? qApp->palette().color(QPalette::HighlightedText)
0276                          : qApp->palette().color(QPalette::Text));
0277 
0278 /*
0279     // If there is ImageHistory present, paint a small icon over the thumbnail to indicate that this is derived image
0280 
0281     if (info.hasImageHistory())
0282     {
0283         p->drawPixmap(d->pixmapRect.right()-24, d->pixmapRect.bottom()-24, QIcon::fromTheme(QLatin1String("svn_switch")).pixmap(22));
0284     }
0285 */
0286 
0287     if (!d->nameRect.isNull())
0288     {
0289         drawName(p, d->nameRect, info.name);
0290     }
0291 
0292     if (!d->dateRect.isNull())
0293     {
0294         drawCreationDate(p, d->dateRect, info.ctime);
0295     }
0296 
0297     if (!d->sizeRect.isNull())
0298     {
0299         drawFileSize(p, d->sizeRect, info.size);
0300     }
0301 
0302     if (!d->downloadRect.isNull())
0303     {
0304         drawDownloadIndicator(p, d->downloadRect, info.downloaded);
0305     }
0306 
0307     if (!d->lockRect.isNull())
0308     {
0309         drawLockIndicator(p, d->lockRect, info.writePermissions);
0310     }
0311 
0312     if (!d->resolutionRect.isNull())
0313     {
0314         QSize dimensions(info.width, info.height);
0315         drawImageSize(p, d->resolutionRect, dimensions);
0316     }
0317 
0318     //TODO: Implement grouping in import tool.
0319 
0320 /*
0321     if (!d->groupRect.isNull())
0322     {
0323         drawGroupIndicator(p, d->groupRect, info.numberOfGroupedImages(),
0324                            index.data(ImportFilterModel::GroupIsOpenRole).toBool());
0325     }
0326 */
0327 
0328     if (!d->tagRect.isNull())
0329     {
0330         QStringList tagsList = AlbumManager::instance()->tagNames(info.tagIds);
0331         tagsList.removeDuplicates();
0332         tagsList.sort();
0333         QString tags         = tagsList.join(QLatin1String(", "));
0334         drawTags(p, d->tagRect, tags, isSelected);
0335     }
0336 
0337     if (!d->pickLabelRect.isNull())
0338     {
0339         drawPickLabelIcon(p, d->pickLabelRect, info.pickLabel);
0340     }
0341 
0342     if (d->drawImageFormat)
0343     {
0344         QString frm = info.mime;
0345         drawImageFormat(p, actualPixmapRect, frm);
0346     }
0347 
0348     if (d->drawCoordinates && info.photoInfo.hasCoordinates)
0349     {
0350         drawGeolocationIndicator(p, d->coordinatesRect);
0351     }
0352 
0353     if (d->drawFocusFrame)
0354     {
0355         drawFocusRect(p, option, isSelected);
0356     }
0357 
0358     if (d->drawMouseOverFrame)
0359     {
0360         drawMouseOverRect(p, option);
0361     }
0362 
0363     p->restore();
0364 
0365     drawOverlays(p, option, index);
0366 }
0367 
0368 QPixmap ImportDelegate::pixmapForDrag(const QStyleOptionViewItem& option, const QList<QModelIndex>& indexes) const
0369 {
0370     QPixmap icon;
0371 
0372     if (!indexes.isEmpty())
0373     {
0374         icon = thumbnailPixmap(indexes.first());
0375     }
0376 
0377     return makeDragPixmap(option, indexes, displayRatio(), icon);
0378 }
0379 
0380 bool ImportDelegate::acceptsToolTip(const QPoint& pos, const QRect& visualRect, const QModelIndex& index,
0381                                     QRect* toolTipRect) const
0382 {
0383     return onActualPixmapRect(pos, visualRect, index, toolTipRect);
0384 }
0385 
0386 bool ImportDelegate::acceptsActivation(const QPoint& pos, const QRect& visualRect, const QModelIndex& index,
0387                                        QRect* activationRect) const
0388 {
0389     return onActualPixmapRect(pos, visualRect, index, activationRect);
0390 }
0391 
0392 bool ImportDelegate::onActualPixmapRect(const QPoint& pos, const QRect& visualRect, const QModelIndex& index,
0393                                         QRect* returnRect) const
0394 {
0395     QRect actualRect = actualPixmapRect(index);
0396 
0397     if (actualRect.isNull())
0398     {
0399         return false;
0400     }
0401 
0402     actualRect.translate(visualRect.topLeft());
0403 
0404     if (returnRect)
0405     {
0406         *returnRect = actualRect;
0407     }
0408 
0409     return actualRect.contains(pos);
0410 }
0411 
0412 void ImportDelegate::setDefaultViewOptions(const QStyleOptionViewItem& option)
0413 {
0414     Q_D(ImportDelegate);
0415 
0416     if (d->categoryDrawer)
0417     {
0418         d->categoryDrawer->setDefaultViewOptions(option);
0419     }
0420 
0421     ItemViewImportDelegate::setDefaultViewOptions(option);
0422 }
0423 
0424 void ImportDelegate::invalidatePaintingCache()
0425 {
0426     Q_D(ImportDelegate);
0427 
0428     if (d->categoryDrawer)
0429     {
0430         d->categoryDrawer->invalidatePaintingCache();
0431     }
0432 
0433     ItemViewImportDelegate::invalidatePaintingCache();
0434 }
0435 
0436 void ImportDelegate::updateContentWidth()
0437 {
0438     Q_D(ImportDelegate);
0439     d->contentWidth = d->thumbSize.size() + 2*d->radius;
0440 }
0441 
0442 void ImportDelegate::updateSizeRectsAndPixmaps()
0443 {
0444     Q_D(ImportDelegate);
0445 
0446     // ---- Reset rects and prepare fonts ----
0447 
0448     d->clearRects();
0449     prepareFonts();
0450 
0451     // ---- Fixed sizes and metrics ----
0452 
0453     updateContentWidth();
0454     prepareMetrics(d->contentWidth);
0455 
0456     // ---- Calculate rects ----
0457 
0458     updateRects();
0459 
0460     // ---- Cached pixmaps ----
0461 
0462     prepareBackground();
0463 
0464     if (!d->ratingRect.isNull())
0465     {
0466         // Normally we prepare the pixmaps over the background of the rating rect.
0467         // If the rating is drawn over the thumbnail, we can only draw over a transparent pixmap.
0468 
0469         prepareRatingPixmaps(!d->ratingOverThumbnail);
0470     }
0471 
0472     // ---- Drawing related caches ----
0473 
0474     clearCaches();
0475 }
0476 
0477 void ImportDelegate::clearCaches()
0478 {
0479     Q_D(ImportDelegate);
0480     ItemViewImportDelegate::clearCaches();
0481     d->actualPixmapRectCache.clear();
0482 }
0483 
0484 void ImportDelegate::clearModelDataCaches()
0485 {
0486     Q_D(ImportDelegate);
0487     d->actualPixmapRectCache.clear();
0488 }
0489 
0490 void ImportDelegate::modelChanged()
0491 {
0492     Q_D(ImportDelegate);
0493     clearModelDataCaches();
0494     setModel(d->currentView ? d->currentView->model() : nullptr);
0495 }
0496 
0497 void ImportDelegate::modelContentsChanged()
0498 {
0499     clearModelDataCaches();
0500 }
0501 
0502 QRect ImportDelegate::actualPixmapRect(const QModelIndex& index) const
0503 {
0504     Q_D(const ImportDelegate);
0505 
0506     // We do not recompute if not found. Assumption is cache is always properly updated.
0507 
0508     QRect* const rect = d->actualPixmapRectCache.object(index.row());
0509 
0510     if (rect)
0511     {
0512         return *rect;
0513     }
0514     else
0515     {
0516         return d->pixmapRect;
0517     }
0518 }
0519 
0520 void ImportDelegate::updateActualPixmapRect(const QModelIndex& index, const QRect& rect)
0521 {
0522     Q_D(ImportDelegate);
0523     QRect* const old = d->actualPixmapRectCache.object(index.row());
0524 
0525     if (!old || (*old != rect))
0526     {
0527         d->actualPixmapRectCache.insert(index.row(), new QRect(rect));
0528     }
0529 }
0530 
0531 int ImportDelegate::calculatethumbSizeToFit(int ws)
0532 {
0533     Q_D(ImportDelegate);
0534 
0535     int ts     = thumbnailSize().size();
0536     int gs     = gridSize().width();
0537     int sp     = spacing();
0538     ws         = ws - 2*sp;
0539 
0540     // Thumbnails size loop to check (upper/lower)
0541 
0542     int ts1, ts2;
0543 
0544     // New grid size used in loop
0545 
0546     int ngs;
0547 
0548     double rs1 = fmod((double)ws, (double)gs);
0549 
0550     for (ts1 = ts ; ts1 < ThumbnailSize::maxThumbsSize() ; ++ts1)
0551     {
0552         ngs        = ts1 + 2*(d->margin + d->radius) + sp;
0553         double nrs = fmod((double)ws, (double)ngs);
0554 
0555         if (nrs <= rs1)
0556         {
0557             rs1 = nrs;
0558         }
0559         else
0560         {
0561             break;
0562         }
0563     }
0564 
0565     double rs2 = fmod((double)ws, (double)gs);
0566 
0567     for (ts2 = ts ; ts2 > ThumbnailSize::Small ; --ts2)
0568     {
0569         ngs        = ts2 + 2*(d->margin + d->radius) + sp;
0570         double nrs = fmod((double)ws, (double)ngs);
0571 
0572         if (nrs >= rs2)
0573         {
0574             rs2 = nrs;
0575         }
0576         else
0577         {
0578             rs2 = nrs;
0579             break;
0580         }
0581     }
0582 
0583     if (rs1 > rs2)
0584     {
0585         return (ts2);
0586     }
0587 
0588     return (ts1);
0589 }
0590 
0591 // --- ImportThumbnailDelegate ---------------------------------------
0592 
0593 void ImportThumbnailDelegatePrivate::init(ImportThumbnailDelegate* const q)
0594 {
0595     QObject::connect(ImportSettings::instance(), SIGNAL(setupChanged()),
0596                      q, SLOT(slotSetupChanged()));
0597 }
0598 
0599 // ------------------------------------------------------------------------------------------------
0600 
0601 ImportThumbnailDelegate::ImportThumbnailDelegate(ImportCategorizedView* const parent)
0602     : ImportDelegate(*new ImportThumbnailDelegatePrivate, parent)
0603 {
0604     Q_D(ImportThumbnailDelegate);
0605     d->init(this);
0606 }
0607 
0608 ImportThumbnailDelegate::~ImportThumbnailDelegate()
0609 {
0610 }
0611 
0612 void ImportThumbnailDelegate::setFlow(QListView::Flow flow)
0613 {
0614     Q_D(ImportThumbnailDelegate);
0615     d->flow = flow;
0616 }
0617 
0618 void ImportThumbnailDelegate::setDefaultViewOptions(const QStyleOptionViewItem& option)
0619 {
0620     Q_D(ImportThumbnailDelegate);
0621 
0622     // store before calling parent class
0623 
0624     d->viewSize = option.rect;
0625     ImportDelegate::setDefaultViewOptions(option);
0626 }
0627 
0628 int ImportThumbnailDelegate::maximumSize() const
0629 {
0630     Q_D(const ImportThumbnailDelegate);
0631 
0632     return ThumbnailSize::maxThumbsSize() + (2*d->radius + 2*d->margin);
0633 }
0634 
0635 int ImportThumbnailDelegate::minimumSize() const
0636 {
0637     Q_D(const ImportThumbnailDelegate);
0638 
0639     return ThumbnailSize::Small + 2*d->radius + 2*d->margin;
0640 }
0641 
0642 bool ImportThumbnailDelegate::acceptsActivation(const QPoint& pos, const QRect& visualRect,
0643                                                 const QModelIndex& index, QRect* activationRect) const
0644 {
0645     // reuse implementation from grand-parent
0646 
0647     return ItemViewImportDelegate::acceptsActivation(pos, visualRect, index, activationRect); // clazy:exclude=skipped-base-method
0648 }
0649 
0650 void ImportThumbnailDelegate::updateContentWidth()
0651 {
0652     Q_D(ImportThumbnailDelegate);
0653     int maxSize;
0654 
0655     if (d->flow == QListView::LeftToRight)
0656     {
0657         maxSize = d->viewSize.height();
0658     }
0659     else
0660     {
0661         maxSize = d->viewSize.width();
0662     }
0663 
0664     d->thumbSize = ThumbnailSize(thumbnailPixmapSize(true, maxSize - 2*d->radius - 2*d->margin));
0665 
0666     ImportDelegate::updateContentWidth();
0667 }
0668 
0669 int ImportThumbnailDelegate::thumbnailPixmapSize(bool withHighlight, int size)
0670 {
0671     if (withHighlight && (size >= 10))
0672     {
0673         return size + 2;
0674     }
0675 
0676     return size;
0677 }
0678 
0679 void ImportThumbnailDelegate::updateRects()
0680 {
0681     Q_D(ImportThumbnailDelegate);
0682 
0683     d->pixmapRect      = QRect(d->margin, d->margin, d->contentWidth, d->contentWidth);
0684     d->rect            = QRect(0, 0, d->contentWidth + 2*d->margin, d->contentWidth + 2*d->margin);
0685     d->drawImageFormat = ImportSettings::instance()->getIconShowImageFormat();
0686     d->drawCoordinates = ImportSettings::instance()->getIconShowCoordinates();
0687 
0688     const int iconSize = qBound(16, (d->contentWidth + 2*d->margin) / 8 - 2, 48);
0689     int pos            = iconSize + 2;
0690     d->downloadRect    = QRect(d->contentWidth - pos, d->pixmapRect.top(), iconSize, iconSize);
0691     pos += iconSize;
0692     d->lockRect        = QRect(d->contentWidth - pos, d->pixmapRect.top(), iconSize, iconSize);
0693     pos += iconSize;
0694     d->coordinatesRect = QRect(d->contentWidth - pos, d->pixmapRect.top(), iconSize, iconSize);
0695 
0696     if (ImportSettings::instance()->getIconShowRating())
0697     {
0698         int top       = d->rect.bottom() - d->margin - d->starPolygonSize.height() - 2;
0699         d->ratingRect = QRect(d->margin, top, d->contentWidth, d->starPolygonSize.height());
0700     }
0701 
0702     if (d->flow == QListView::LeftToRight)
0703     {
0704         d->gridSize = QSize(d->rect.width() + d->spacing, d->rect.height());
0705     }
0706     else
0707     {
0708         d->gridSize = QSize(d->rect.width(), d->rect.height() + d->spacing);
0709     }
0710 }
0711 
0712 // --- ImportNormalDelegate -----------------------------------------------------------------------
0713 
0714 void ImportNormalDelegatePrivate::init(ImportNormalDelegate* const q, ImportCategorizedView* const parent)
0715 {
0716     categoryDrawer = new ImportCategoryDrawer(parent);
0717 
0718     QObject::connect(ImportSettings::instance(), SIGNAL(setupChanged()),
0719                      q, SLOT(slotSetupChanged()));
0720 }
0721 
0722 ImportNormalDelegatePrivate::~ImportNormalDelegatePrivate()
0723 {
0724     delete categoryDrawer;
0725 }
0726 
0727 // ------------------------------------------------------------------------------------------------
0728 
0729 ImportNormalDelegate::ImportNormalDelegate(ImportCategorizedView* const parent)
0730     : ImportDelegate(*new ImportNormalDelegatePrivate, parent)
0731 {
0732     Q_D(ImportNormalDelegate);
0733     d->init(this, parent);
0734 }
0735 
0736 ImportNormalDelegate::ImportNormalDelegate(ImportNormalDelegatePrivate& dd, ImportCategorizedView* const parent)
0737     : ImportDelegate(dd, parent)
0738 {
0739 
0740     Q_D(ImportNormalDelegate);
0741     d->init(this, parent);
0742 }
0743 
0744 ImportNormalDelegate::~ImportNormalDelegate()
0745 {
0746 }
0747 
0748 void ImportNormalDelegate::updateRects()
0749 {
0750     Q_D(ImportNormalDelegate);
0751 
0752     int y                                      = d->margin;
0753     d->pixmapRect                              = QRect(d->margin, y, d->contentWidth, d->contentWidth);
0754     y                                          = d->pixmapRect.bottom();
0755     d->imageInformationRect                    = QRect(d->margin, y, d->contentWidth, 0);
0756     const ImportSettings* const importSettings = ImportSettings::instance();
0757     d->drawImageFormat                         = importSettings->getIconShowImageFormat();
0758     d->drawCoordinates                         = ImportSettings::instance()->getIconShowCoordinates();
0759     const int iconSize                         = qBound(16, (d->contentWidth + 2*d->margin) / 8 - 2, 48);
0760 
0761     d->pickLabelRect   = QRect(d->margin, y, iconSize, iconSize);
0762 /*
0763     d->groupRect       = QRect(d->contentWidth - iconSize, y, iconSize, iconSize); // TODO
0764 */
0765     int pos            = iconSize + 2;
0766     d->downloadRect    = QRect(d->contentWidth - pos, d->pixmapRect.top(), iconSize, iconSize);
0767     pos += iconSize;
0768     d->lockRect        = QRect(d->contentWidth - pos, d->pixmapRect.top(), iconSize, iconSize);
0769     pos += iconSize;
0770     d->coordinatesRect = QRect(d->contentWidth - pos, d->pixmapRect.top(), iconSize, iconSize);
0771 
0772     if (importSettings->getIconShowRating())
0773     {
0774         d->ratingRect = QRect(d->margin, y, d->contentWidth, d->starPolygonSize.height());
0775         y             = d->ratingRect.bottom();
0776     }
0777 
0778     if (importSettings->getIconShowName())
0779     {
0780         d->nameRect = QRect(d->margin, y, d->contentWidth-d->margin, d->oneRowRegRect.height());
0781         y           = d->nameRect.bottom();
0782     }
0783 
0784     if (importSettings->getIconShowDate())
0785     {
0786         d->dateRect = QRect(d->margin, y, d->contentWidth, d->oneRowXtraRect.height());
0787         y           = d->dateRect.bottom();
0788     }
0789 
0790     //TODO: Add resolution entry in importSettings.
0791 
0792 /*
0793     if (importSettings->getIconShowResolution())
0794     {
0795         d->resolutionRect = QRect(d->margin, y, d->contentWidth, d->oneRowXtraRect.height());
0796         y                 = d->resolutionRect.bottom() ;
0797     }
0798 */
0799 
0800     if (importSettings->getIconShowSize())
0801     {
0802         d->sizeRect = QRect(d->margin, y, d->contentWidth, d->oneRowXtraRect.height());
0803         y           = d->sizeRect.bottom();
0804     }
0805 
0806     if (importSettings->getIconShowTags())
0807     {
0808         d->tagRect = QRect(d->margin, y, d->contentWidth, d->oneRowComRect.height());
0809         y          = d->tagRect.bottom();
0810     }
0811 
0812     d->imageInformationRect.setBottom(y);
0813 
0814     d->rect     = QRect(0, 0, d->contentWidth + 2*d->margin, y+d->margin+d->radius);
0815     d->gridSize = QSize(d->rect.width() + d->spacing, d->rect.height() + d->spacing);
0816 }
0817 
0818 } // namespace Digikam
0819 
0820 #include "moc_importdelegate.cpp"