[Digikam-devel] [digikam] digikam/items: Implement operation on all selected images for the rating on rotation overlay.

Marcel Wiesweg marcel.wiesweg at gmx.de
Mon Mar 7 15:24:35 GMT 2011


Git commit 1bd6884ff54022e6ba5bac55dbb25f678ed1074e by Marcel Wiesweg.
Committed on 07/03/2011 at 16:21.
Pushed by mwiesweg into branch 'master'.

Implement operation on all selected images for the rating on rotation overlay.
On the way, clean up code duplication mostly in the rotate overlays.

Question: Now, one click can be very powerful and edit a large number of images.
Should we add a confirmation KMessageBox if the number of edited images exceeds
a constant (n = 5, 10?)?

CCMAIL: digikam-devel at kde.org

M  +13   -34   digikam/items/digikamimageview.cpp     
M  +3    -3    digikam/items/digikamimageview.h     
M  +34   -8    digikam/items/digikamimageview_p.cpp     
M  +3    -2    digikam/items/digikamimageview_p.h     
M  +11   -1    digikam/items/imageratingoverlay.cpp     
M  +3    -1    digikam/items/imageratingoverlay.h     
M  +39   -89   digikam/items/imagerotationoverlay.cpp     
M  +22   -41   digikam/items/imagerotationoverlay.h     
M  +4    -4    digikam/items/imagethumbnailbar.cpp     
M  +1    -1    digikam/items/imagethumbnailbar.h     

http://commits.kde.org/digikam/1bd6884ff54022e6ba5bac55dbb25f678ed1074e

diff --git a/digikam/items/digikamimageview.cpp b/digikam/items/digikamimageview.cpp
index da40734..872190f 100644
--- a/digikam/items/digikamimageview.cpp
+++ b/digikam/items/digikamimageview.cpp
@@ -115,8 +115,8 @@ DigikamImageView::DigikamImageView(QWidget* parent)
     addSelectionOverlay(d->faceDelegate);
 
     // rotation overlays
-    d->rotateLeftOverlay = new ImageRotateLeftOverlay(this);
-    d->rotateRightOverlay = new ImageRotateRightOverlay(this);
+    d->rotateLeftOverlay = ImageRotateOverlay::left(this);
+    d->rotateRightOverlay = ImageRotateOverlay::right(this);
     d->updateOverlays();
 
     // rating overlay
@@ -130,8 +130,8 @@ DigikamImageView::DigikamImageView(QWidget* parent)
     GroupIndicatorOverlay* groupOverlay = new GroupIndicatorOverlay(this);
     addOverlay(groupOverlay);
 
-    connect(ratingOverlay, SIGNAL(ratingEdited(const QModelIndex&, int)),
-            this, SLOT(assignRating(const QModelIndex&, int)));
+    connect(ratingOverlay, SIGNAL(ratingEdited(const QList<QModelIndex>&, int)),
+            this, SLOT(assignRating(const QList<QModelIndex>&, int)));
 
     connect(groupOverlay, SIGNAL(toggleGroupOpen(const QModelIndex&)),
             this, SLOT(groupIndicatorClicked(const QModelIndex&)));
@@ -357,6 +357,7 @@ void DigikamImageView::showContextMenuOnInfo(QContextMenuEvent* event, const Ima
 
 void DigikamImageView::showGroupContextMenu(const QModelIndex& index, QContextMenuEvent* event)
 {
+    Q_UNUSED(index);
     QList<ImageInfo> selectedInfos = selectedImageInfosCurrentFirst();
     QList<qlonglong> selectedImageIDs;
     foreach (const ImageInfo& info, selectedInfos)
@@ -584,9 +585,9 @@ void DigikamImageView::assignRatingToSelected(int rating)
     MetadataManager::instance()->assignRating(selectedImageInfos(), rating);
 }
 
-void DigikamImageView::assignRating(const QModelIndex& index, int rating)
+void DigikamImageView::assignRating(const QList<QModelIndex>& indexes, int rating)
 {
-    MetadataManager::instance()->assignRating(QList<ImageInfo>() << imageFilterModel()->imageInfo(index), rating);
+    MetadataManager::instance()->assignRating(imageFilterModel()->imageInfos(indexes), rating);
 }
 
 void DigikamImageView::assignTag(const QModelIndex& index, const QString& name)
@@ -664,38 +665,16 @@ void DigikamImageView::rename()
     }
 }
 
-void DigikamImageView::slotRotateLeft()
+void DigikamImageView::slotRotateLeft(const QList<QModelIndex>& indexes)
 {
-    KActionMenu* action = dynamic_cast<KActionMenu*>(ContextMenuHelper::kipiRotateAction());
-
-    if (action)
-    {
-        QList<QAction*> list = action->menu()->actions();
-        foreach(QAction* ac, list)
-        {
-            if (ac->objectName() == QString("rotate_ccw"))
-            {
-                ac->trigger();
-            }
-        }
-    }
+    setSelectedIndexes(indexes);
+    d->triggerRotateAction("rotate_ccw");
 }
 
-void DigikamImageView::slotRotateRight()
+void DigikamImageView::slotRotateRight(const QList<QModelIndex>& indexes)
 {
-    KActionMenu* action = dynamic_cast<KActionMenu*>(ContextMenuHelper::kipiRotateAction());
-
-    if (action)
-    {
-        QList<QAction*> list = action->menu()->actions();
-        foreach(QAction* ac, list)
-        {
-            if (ac->objectName() == QString("rotate_cw"))
-            {
-                ac->trigger();
-            }
-        }
-    }
+    setSelectedIndexes(indexes);
+    d->triggerRotateAction("rotate_cw");
 }
 
 } // namespace Digikam
diff --git a/digikam/items/digikamimageview.h b/digikam/items/digikamimageview.h
index 56c41a5..4e72a41 100644
--- a/digikam/items/digikamimageview.h
+++ b/digikam/items/digikamimageview.h
@@ -81,7 +81,7 @@ public Q_SLOTS:
 
     void assignPickLabel(const QModelIndex& index, int pickId);
     void assignColorLabel(const QModelIndex& index, int colorId);
-    void assignRating(const QModelIndex& index, int rating);
+    void assignRating(const QList<QModelIndex>& index, int rating);
     void assignTag(const QModelIndex& index, const QString& name);
 
     void createGroupFromSelection();
@@ -115,8 +115,8 @@ protected:
 
 private Q_SLOTS:
 
-    void slotRotateLeft();
-    void slotRotateRight();
+    void slotRotateLeft(const QList<QModelIndex>&);
+    void slotRotateRight(const QList<QModelIndex>&);
     void slotUntagFace(const QModelIndex& index);
 
 private:
diff --git a/digikam/items/digikamimageview_p.cpp b/digikam/items/digikamimageview_p.cpp
index ade2e41..15a7bf9 100644
--- a/digikam/items/digikamimageview_p.cpp
+++ b/digikam/items/digikamimageview_p.cpp
@@ -25,6 +25,15 @@
 
 #include "digikamimageview_p.moc"
 
+// KDE includes
+
+#include <KActionMenu>
+#include <KMenu>
+
+// Local includes
+
+#include "contextmenuhelper.h"
+
 namespace Digikam
 {
 
@@ -52,11 +61,11 @@ void DigikamImageViewPriv::updateOverlays()
     {
         if (!settings->getIconShowOverlays())
         {
-            disconnect(rotateLeftOverlay, SIGNAL(signalRotateLeft()),
-                       q, SLOT(slotRotateLeft()));
+            disconnect(rotateLeftOverlay, SIGNAL(signalRotate(const QList<QModelIndex>&)),
+                       q, SLOT(slotRotateLeft(const QList<QModelIndex>&)));
 
-            disconnect(rotateRightOverlay, SIGNAL(signalRotateRight()),
-                       q, SLOT(slotRotateRight()));
+            disconnect(rotateRightOverlay, SIGNAL(signalRotate(const QList<QModelIndex>&)),
+                       q, SLOT(slotRotateRight(const QList<QModelIndex>&)));
 
             q->removeOverlay(rotateLeftOverlay);
             q->removeOverlay(rotateRightOverlay);
@@ -71,15 +80,32 @@ void DigikamImageViewPriv::updateOverlays()
             q->addOverlay(rotateLeftOverlay, normalDelegate);
             q->addOverlay(rotateRightOverlay, normalDelegate);
 
-            connect(rotateLeftOverlay, SIGNAL(signalRotateLeft()),
-                    q, SLOT(slotRotateLeft()));
+            connect(rotateLeftOverlay, SIGNAL(signalRotate(const QList<QModelIndex>&)),
+                    q, SLOT(slotRotateLeft(const QList<QModelIndex>&)));
 
-            connect(rotateRightOverlay, SIGNAL(signalRotateRight()),
-                    q, SLOT(slotRotateRight()));
+            connect(rotateRightOverlay, SIGNAL(signalRotate(const QList<QModelIndex>&)),
+                    q, SLOT(slotRotateRight(const QList<QModelIndex>&)));
 
             overlaysActive = true;
         }
     }
 }
 
+void DigikamImageViewPriv::triggerRotateAction(const char* actionName)
+{
+    KActionMenu* action = dynamic_cast<KActionMenu*>(ContextMenuHelper::kipiRotateAction());
+
+    if (action)
+    {
+        QList<QAction*> list = action->menu()->actions();
+        foreach(QAction* ac, list)
+        {
+            if (ac->objectName() == actionName)
+            {
+                ac->trigger();
+            }
+        }
+    }
+}
+
 } // namespace Digikam
diff --git a/digikam/items/digikamimageview_p.h b/digikam/items/digikamimageview_p.h
index f12c18b..a4b2980 100644
--- a/digikam/items/digikamimageview_p.h
+++ b/digikam/items/digikamimageview_p.h
@@ -55,6 +55,7 @@ public:
     virtual ~DigikamImageViewPriv();
 
     void updateOverlays();
+    void triggerRotateAction(const char* actionName);
 
 public:
 
@@ -66,8 +67,8 @@ public:
 
     bool                      overlaysActive;
 
-    ImageRotateLeftOverlay*   rotateLeftOverlay;
-    ImageRotateRightOverlay*  rotateRightOverlay;
+    ImageRotateOverlay*       rotateLeftOverlay;
+    ImageRotateOverlay*       rotateRightOverlay;
 
 private:
 
diff --git a/digikam/items/imageratingoverlay.cpp b/digikam/items/imageratingoverlay.cpp
index a2c4b9d..f6a3693 100644
--- a/digikam/items/imageratingoverlay.cpp
+++ b/digikam/items/imageratingoverlay.cpp
@@ -95,6 +95,16 @@ void ImageRatingOverlay::visualChange()
     }
 }
 
+void ImageRatingOverlay::widgetEnterEvent()
+{
+    widgetEnterNotifyMultiple(m_index);
+}
+
+void ImageRatingOverlay::widgetLeaveEvent()
+{
+    widgetLeaveNotifyMultiple();
+}
+
 void ImageRatingOverlay::hide()
 {
     delegate()->setRatingEdited(QModelIndex());
@@ -138,7 +148,7 @@ void ImageRatingOverlay::slotRatingChanged(int rating)
 {
     if (m_widget && m_widget->isVisible() && m_index.isValid())
     {
-        emit ratingEdited(m_index, rating);
+        emit ratingEdited(affectedIndexes(m_index), rating);
     }
 }
 
diff --git a/digikam/items/imageratingoverlay.h b/digikam/items/imageratingoverlay.h
index a81e9b4..9ab1198 100644
--- a/digikam/items/imageratingoverlay.h
+++ b/digikam/items/imageratingoverlay.h
@@ -53,7 +53,7 @@ public:
 
 Q_SIGNALS:
 
-    void ratingEdited(const QModelIndex& index, int rating);
+    void ratingEdited(const QList<QModelIndex>& indexes, int rating);
 
 protected Q_SLOTS:
 
@@ -67,6 +67,8 @@ protected:
     virtual void visualChange();
     virtual void hide();
     virtual void slotEntered(const QModelIndex& index);
+    virtual void widgetEnterEvent();
+    virtual void widgetLeaveEvent();
 
     void updatePosition();
     void updateRating();
diff --git a/digikam/items/imagerotationoverlay.cpp b/digikam/items/imagerotationoverlay.cpp
index bf0ea5f..2499595 100644
--- a/digikam/items/imagerotationoverlay.cpp
+++ b/digikam/items/imagerotationoverlay.cpp
@@ -38,56 +38,50 @@
 namespace Digikam
 {
 
-ImageRotateLeftOverlayButton::ImageRotateLeftOverlayButton(QAbstractItemView* parentView)
-    : ItemViewHoverButton(parentView)
+ImageRotateOverlayButton::ImageRotateOverlayButton(ImageRotateOverlayDirection dir, QAbstractItemView* parentView)
+    : ItemViewHoverButton(parentView),
+      m_direction(dir)
 {
 }
 
-QSize ImageRotateLeftOverlayButton::sizeHint() const
+QSize ImageRotateOverlayButton::sizeHint() const
 {
     return QSize(16, 16);
 }
 
-QPixmap ImageRotateLeftOverlayButton::icon()
+QPixmap ImageRotateOverlayButton::icon()
 {
-    return KIconLoader::global()->loadIcon("object-rotate-left", KIconLoader::NoGroup, KIconLoader::SizeSmall);
-}
-
-void ImageRotateLeftOverlayButton::updateToolTip()
-{
-    setToolTip(i18nc("@info:tooltip", "Rotate Left"));
-}
-
-// --------------------------------------------------------------------
-
-ImageRotateRightOverlayButton::ImageRotateRightOverlayButton(QAbstractItemView* parentView)
-    : ItemViewHoverButton(parentView)
-{
-}
-
-QSize ImageRotateRightOverlayButton::sizeHint() const
-{
-    return QSize(16, 16);
-}
-
-QPixmap ImageRotateRightOverlayButton::icon()
-{
-    return KIconLoader::global()->loadIcon("object-rotate-right", KIconLoader::NoGroup, KIconLoader::SizeSmall);
+    if (m_direction == ImageRotateOverlayLeft)
+    {
+        return KIconLoader::global()->loadIcon("object-rotate-left", KIconLoader::NoGroup, KIconLoader::SizeSmall);
+    }
+    else
+    {
+        return KIconLoader::global()->loadIcon("object-rotate-right", KIconLoader::NoGroup, KIconLoader::SizeSmall);
+    }
 }
 
-void ImageRotateRightOverlayButton::updateToolTip()
+void ImageRotateOverlayButton::updateToolTip()
 {
-    setToolTip(i18nc("@info:tooltip", "Rotate Right"));
+    if (m_direction == ImageRotateOverlayLeft)
+    {
+        setToolTip(i18nc("@info:tooltip", "Rotate Left"));
+    }
+    else
+    {
+        setToolTip(i18nc("@info:tooltip", "Rotate Right"));
+    }
 }
 
 // --------------------------------------------------------------------
 
-ImageRotateLeftOverlay::ImageRotateLeftOverlay(QObject* parent)
-    : HoverButtonDelegateOverlay(parent)
+ImageRotateOverlay::ImageRotateOverlay(ImageRotateOverlayDirection dir, QObject* parent)
+    : HoverButtonDelegateOverlay(parent),
+      m_direction(dir)
 {
 }
 
-void ImageRotateLeftOverlay::setActive(bool active)
+void ImageRotateOverlay::setActive(bool active)
 {
     HoverButtonDelegateOverlay::setActive(active);
 
@@ -100,92 +94,48 @@ void ImageRotateLeftOverlay::setActive(bool active)
     // if !active, button() is deleted
 }
 
-ItemViewHoverButton* ImageRotateLeftOverlay::createButton()
+ItemViewHoverButton* ImageRotateOverlay::createButton()
 {
-    return new ImageRotateLeftOverlayButton(view());
+    return new ImageRotateOverlayButton(m_direction, view());
 }
 
-void ImageRotateLeftOverlay::updateButton(const QModelIndex& index)
+void ImageRotateOverlay::updateButton(const QModelIndex& index)
 {
     const QRect rect = m_view->visualRect(index);
     const int gap    = 5;
-    const int x      = rect.right() - 2*gap - 32;
+    const int x      = rect.right() - (isLeft() ? (2*gap + 32) : (gap + 16));
     const int y      = rect.top() + gap;
     button()->move(QPoint(x, y));
 }
 
-void ImageRotateLeftOverlay::slotClicked()
+void ImageRotateOverlay::slotClicked()
 {
     QModelIndex index = button()->index();
 
     if (index.isValid())
     {
-        QItemSelectionModel* selModel = m_view->selectionModel();
+        /*QItemSelectionModel* selModel = m_view->selectionModel();
         selModel->reset();
         selModel->select(index, QItemSelectionModel::Select);
-        selModel->setCurrentIndex(index, QItemSelectionModel::Current);
-        emit signalRotateLeft();
+        selModel->setCurrentIndex(index, QItemSelectionModel::Current);*/
+        emit signalRotate(affectedIndexes(index));
     }
 }
 
-bool ImageRotateLeftOverlay::checkIndex(const QModelIndex& index) const
+bool ImageRotateOverlay::checkIndex(const QModelIndex& index) const
 {
     ImageInfo info = ImageModel::retrieveImageInfo(index);
     return info.category() == DatabaseItem::Image;
 }
 
-// --------------------------------------------------------------------
-
-ImageRotateRightOverlay::ImageRotateRightOverlay(QObject* parent)
-    : HoverButtonDelegateOverlay(parent)
+void ImageRotateOverlay::widgetEnterEvent()
 {
+    widgetEnterNotifyMultiple(button()->index());
 }
 
-void ImageRotateRightOverlay::setActive(bool active)
+void ImageRotateOverlay::widgetLeaveEvent()
 {
-    HoverButtonDelegateOverlay::setActive(active);
-
-    if (active)
-    {
-        connect(button(), SIGNAL(clicked(bool)),
-                this, SLOT(slotClicked()));
-    }
-
-    // if !active, button() is deleted
-}
-
-ItemViewHoverButton* ImageRotateRightOverlay::createButton()
-{
-    return new ImageRotateRightOverlayButton(view());
-}
-
-void ImageRotateRightOverlay::updateButton(const QModelIndex& index)
-{
-    const QRect rect = m_view->visualRect(index);
-    const int gap    = 5;
-    const int x      = rect.right() - gap - 16;
-    const int y      = rect.top() + gap;
-    button()->move(QPoint(x, y));
-}
-
-void ImageRotateRightOverlay::slotClicked()
-{
-    QModelIndex index = button()->index();
-
-    if (index.isValid())
-    {
-        QItemSelectionModel* selModel = m_view->selectionModel();
-        selModel->reset();
-        selModel->select(index, QItemSelectionModel::Select);
-        selModel->setCurrentIndex(index, QItemSelectionModel::Current);
-        emit signalRotateRight();
-    }
-}
-
-bool ImageRotateRightOverlay::checkIndex(const QModelIndex& index) const
-{
-    ImageInfo info = ImageModel::retrieveImageInfo(index);
-    return info.category() == DatabaseItem::Image;
+    widgetLeaveNotifyMultiple();
 }
 
 } // namespace Digikam
diff --git a/digikam/items/imagerotationoverlay.h b/digikam/items/imagerotationoverlay.h
index bb9ed08..bb5b992 100644
--- a/digikam/items/imagerotationoverlay.h
+++ b/digikam/items/imagerotationoverlay.h
@@ -37,86 +37,67 @@
 namespace Digikam
 {
 
-class ImageRotateLeftOverlayButton : public ItemViewHoverButton
+enum ImageRotateOverlayDirection
 {
-public:
-
-    ImageRotateLeftOverlayButton(QAbstractItemView* parentView);
-    virtual QSize sizeHint() const;
-
-protected:
-
-    virtual QPixmap icon();
-    virtual void updateToolTip();
+    ImageRotateOverlayLeft,
+    ImageRotateOverlayRight
 };
 
-// --------------------------------------------------------------------
-
-class ImageRotateRightOverlayButton : public ItemViewHoverButton
+class ImageRotateOverlayButton : public ItemViewHoverButton
 {
 public:
 
-    ImageRotateRightOverlayButton(QAbstractItemView* parentView);
+    ImageRotateOverlayButton(ImageRotateOverlayDirection dir, QAbstractItemView* parentView);
     virtual QSize sizeHint() const;
 
 protected:
 
     virtual QPixmap icon();
     virtual void updateToolTip();
+
+    ImageRotateOverlayDirection const m_direction;
 };
 
 // --------------------------------------------------------------------
 
-class ImageRotateLeftOverlay : public HoverButtonDelegateOverlay
+class ImageRotateOverlay : public HoverButtonDelegateOverlay
 {
     Q_OBJECT
 
 public:
 
-    ImageRotateLeftOverlay(QObject* parent);
+    ImageRotateOverlay(ImageRotateOverlayDirection dir, QObject* parent);
     virtual void setActive(bool active);
 
-Q_SIGNALS:
+    ImageRotateOverlayDirection direction() const { return m_direction; }
+    bool isLeft() const { return m_direction  == ImageRotateOverlayLeft; }
+    bool isRight() const { return m_direction == ImageRotateOverlayRight; }
 
-    void signalRotateLeft();
-
-protected:
-
-    virtual ItemViewHoverButton* createButton();
-    virtual void updateButton(const QModelIndex& index);
-    virtual bool checkIndex(const QModelIndex& index) const;
-
-private Q_SLOTS:
-
-    void slotClicked();
-};
-
-// --------------------------------------------------------------------
-
-class ImageRotateRightOverlay : public HoverButtonDelegateOverlay
-{
-    Q_OBJECT
-
-public:
-
-    ImageRotateRightOverlay(QObject* parent);
-    virtual void setActive(bool active);
+    static ImageRotateOverlay* left(QObject* parent) { return new ImageRotateOverlay(ImageRotateOverlayLeft, parent); }
+    static ImageRotateOverlay* right(QObject* parent) { return new ImageRotateOverlay(ImageRotateOverlayRight, parent); }
 
 Q_SIGNALS:
 
-    void signalRotateRight();
+    void signalRotate(const QList<QModelIndex>& indexes);
 
 protected:
 
     virtual ItemViewHoverButton* createButton();
     virtual void updateButton(const QModelIndex& index);
     virtual bool checkIndex(const QModelIndex& index) const;
+    virtual void widgetEnterEvent();
+    virtual void widgetLeaveEvent();
 
 private Q_SLOTS:
 
     void slotClicked();
+
+private:
+
+    ImageRotateOverlayDirection const m_direction;
 };
 
+
 } // namespace Digikam
 
 #endif /* IMAGEROTATIONOVERLAY_H */
diff --git a/digikam/items/imagethumbnailbar.cpp b/digikam/items/imagethumbnailbar.cpp
index 2335d14..e554788 100644
--- a/digikam/items/imagethumbnailbar.cpp
+++ b/digikam/items/imagethumbnailbar.cpp
@@ -116,8 +116,8 @@ void ImageThumbnailBar::installRatingOverlay()
     ImageRatingOverlay* ratingOverlay = new ImageRatingOverlay(this);
     addOverlay(ratingOverlay);
 
-    connect(ratingOverlay, SIGNAL(ratingEdited(const QModelIndex&, int)),
-            this, SLOT(assignRating(const QModelIndex&, int)));
+    connect(ratingOverlay, SIGNAL(ratingEdited(const QList<QModelIndex>&, int)),
+            this, SLOT(assignRating(const QList<QModelIndex>&, int)));
 
 }
 
@@ -195,9 +195,9 @@ void ImageThumbnailBar::slotSetupChanged()
     ImageCategorizedView::slotSetupChanged();
 }
 
-void ImageThumbnailBar::assignRating(const QModelIndex& index, int rating)
+void ImageThumbnailBar::assignRating(const QList<QModelIndex>& indexes, int rating)
 {
-    MetadataManager::instance()->assignRating(QList<ImageInfo>() << imageSortFilterModel()->imageInfo(index), rating);
+    MetadataManager::instance()->assignRating(imageSortFilterModel()->imageInfos(indexes), rating);
 }
 
 bool ImageThumbnailBar::event(QEvent* e)
diff --git a/digikam/items/imagethumbnailbar.h b/digikam/items/imagethumbnailbar.h
index d9ec4ae..2d1fb75 100644
--- a/digikam/items/imagethumbnailbar.h
+++ b/digikam/items/imagethumbnailbar.h
@@ -60,7 +60,7 @@ public:
 
 public Q_SLOTS:
 
-    void assignRating(const QModelIndex& index, int rating);
+    void assignRating(const QList<QModelIndex>& index, int rating);
     void slotDockLocationChanged(Qt::DockWidgetArea area);
 
 protected:




More information about the Digikam-devel mailing list