[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kphotoalbum/area_workflow_improvement] AnnotationDialog: Include ResizableFrame context-menu action
From:       Johannes Zarl-Zierl <johannes () zarl-zierl ! at>
Date:       2016-11-30 23:40:14
Message-ID: E1cCEU2-0006sv-2v () code ! kde ! org
[Download RAW message or body]

Git commit 644a155ff6b0b8d5bc63376875c5356df83f28b8 by Johannes Zarl-Zierl.
Committed on 30/11/2016 at 23:39.
Pushed by johanneszarl into branch 'area_workflow_improvement'.

Include ResizableFrame context-menu actions into AreaTagSelectionDialog.

M  +8    -1    AnnotationDialog/AreaTagSelectDialog.cpp
M  +83   -79   AnnotationDialog/ResizableFrame.cpp
M  +6    -0    AnnotationDialog/ResizableFrame.h

https://commits.kde.org/kphotoalbum/644a155ff6b0b8d5bc63376875c5356df83f28b8

diff --git a/AnnotationDialog/AreaTagSelectDialog.cpp \
b/AnnotationDialog/AreaTagSelectDialog.cpp index 50188ff..0cc9a31 100644
--- a/AnnotationDialog/AreaTagSelectDialog.cpp
+++ b/AnnotationDialog/AreaTagSelectDialog.cpp
@@ -33,6 +33,7 @@
 #include <QGridLayout>
 #include <QLabel>
 #include <QLineEdit>
+#include <QMenu>
 #include <QPainter>
 
 AnnotationDialog::AreaTagSelectDialog::AreaTagSelectDialog(AnnotationDialog::ResizableFrame \
*area, @@ -54,7 +55,8 @@ \
AnnotationDialog::AreaTagSelectDialog::AreaTagSelectDialog(AnnotationDialog::Res  \
m_areaImageLabel = new QLabel();  m_areaImageLabel->setAlignment(Qt::AlignTop);
     m_areaImageLabel->setPixmap(areaImage);
-    mainLayout->addWidget(m_areaImageLabel, 0, 0);
+    // span 2 rows:
+    mainLayout->addWidget(m_areaImageLabel, 0, 0, 2, 1);
 
     CompletableLineEdit* tagSelect = new CompletableLineEdit(ls, this);
     ls->connectLineEdit(tagSelect);
@@ -65,6 +67,11 @@ AnnotationDialog::AreaTagSelectDialog::AreaTagSelectDialog(AnnotationDialog::Res
  mainLayout->addWidget(m_messageLabel, 1, 1);
     m_messageLabel->hide();
 
+    QMenu *tagMenu = new QMenu();
+    m_area->addTagActions(tagMenu);
+    mainLayout->addWidget(tagMenu, 2, 0, 1, 2);
+    connect(tagMenu, &QMenu::triggered, this, &QMenu::close);
+
     connect(tagSelect, &KLineEdit::returnPressed, this, \
                &AreaTagSelectDialog::slotSetTag);
     connect(tagSelect, &QLineEdit::textChanged, this, \
&AreaTagSelectDialog::slotValidateTag);  }
diff --git a/AnnotationDialog/ResizableFrame.cpp \
b/AnnotationDialog/ResizableFrame.cpp index c9b69c4..64d6f7a 100644
--- a/AnnotationDialog/ResizableFrame.cpp
+++ b/AnnotationDialog/ResizableFrame.cpp
@@ -331,85 +331,7 @@ void \
AnnotationDialog::ResizableFrame::contextMenuEvent(QContextMenuEvent* event  {
     // Create the context menu
     QMenu* menu = new QMenu(this);
-
-    // Let's see if we already have an associated tag
-    if (! m_tagData.first.isEmpty()) {
-        m_removeTagAct->setText(
-            i18nc("As in: remove tag %1 in category %2 [from this marked area of the \
                image]",
-                  "Remove tag %1 (%2)",
-                  m_tagData.second,
-                  m_tagData.first)
-        );
-        menu->addAction(m_removeTagAct);
-
-    } else {
-        // Handle the last selected positionable tag (if we have one)
-        QPair<QString, QString> lastSelectedPositionableTag = \
                m_dialog->lastSelectedPositionableTag();
-        if (! lastSelectedPositionableTag.first.isEmpty()) {
-            QAction* associateLastSelectedTagAction = createAssociateTagAction(
-                lastSelectedPositionableTag,
-                i18n("Associate with")
-            );
-            connect(associateLastSelectedTagAction, SIGNAL(triggered()), this, \
                SLOT(associateTag()));
-            menu->addAction(associateLastSelectedTagAction);
-        }
-
-        // Handle all positionable tag candidates
-
-        QList<QPair<QString, QString>> positionableTagCandidates = \
                m_dialog->positionableTagCandidates();
-        // If we have a last selected positionable tag: remove it
-        positionableTagCandidates.removeAt(positionableTagCandidates.indexOf(lastSelectedPositionableTag));
                
-
-        // If we still have candidates:
-        if (positionableTagCandidates.length() > 0) {
-            if (positionableTagCandidates.length() == 1
-                && lastSelectedPositionableTag.first.isEmpty()) {
-
-                // Add a single action
-                QAction* associateOnlyCandidateAction = createAssociateTagAction(
-                    positionableTagCandidates[0],
-                    i18nc("As in: associate [this marked area of the image] with one \
                of the "
-                          "following choices/menu items",
-                          "Associate with")
-                );
-                connect(associateOnlyCandidateAction, SIGNAL(triggered()), this, \
                SLOT(associateTag()));
-                menu->addAction(associateOnlyCandidateAction);
-            } else {
-                // Create a new menu for all other tags
-                QMenu* submenu = menu->addMenu(
-                    i18nc("As in: associate [this marked area of the image] with one \
                of the "
-                          "following choices/menu items",
-                          "Associate with")
-                );
-
-                for (const QPair<QString, QString>& tag : positionableTagCandidates) \
                {
-                    submenu->addAction(createAssociateTagAction(tag));
-                }
-
-                connect(submenu, SIGNAL(triggered(QAction*)), this, \
                SLOT(associateTag(QAction*)));
-            }
-        }
-    }
-
-    menu->addSeparator();
-
-#ifdef HAVE_KFACE
-    if (m_tagData.first.isEmpty() &&  m_proposedTagData.first.isEmpty()) {
-        // If we have nothing, offer a recognition database lookup
-        menu->addAction(m_recognizeAct);
-    }
-
-    if (! m_tagData.first.isEmpty() && m_changed && ! m_trained) {
-        // Append a "Update recognition database with this face" action
-        m_updateRecognitionDatabaseAct->setText(
-            i18n("Train the recognition database with the face of %1", \
                m_tagData.second)
-        );
-        menu->addAction(m_updateRecognitionDatabaseAct);
-    }
-#endif
-
-    // Append the "Remove area" action
-    menu->addAction(m_removeAct);
+    addTagActions(menu);
 
     // Show the menu
     menu->exec(event->globalPos());
@@ -595,6 +517,88 @@ void AnnotationDialog::ResizableFrame::removeProposedTagData()
     setToolTip(QString());
 }
 
+void AnnotationDialog::ResizableFrame::addTagActions(QMenu *menu)
+{
+    // Let's see if we already have an associated tag
+    if (! m_tagData.first.isEmpty()) {
+        m_removeTagAct->setText(
+            i18nc("As in: remove tag %1 in category %2 [from this marked area of the \
image]", +                  "Remove tag %1 (%2)",
+                  m_tagData.second,
+                  m_tagData.first)
+        );
+        menu->addAction(m_removeTagAct);
+
+    } else {
+        // Handle the last selected positionable tag (if we have one)
+        QPair<QString, QString> lastSelectedPositionableTag = \
m_dialog->lastSelectedPositionableTag(); +        if (! \
lastSelectedPositionableTag.first.isEmpty()) { +            QAction* \
associateLastSelectedTagAction = createAssociateTagAction( +                \
lastSelectedPositionableTag, +                i18n("Associate with")
+            );
+            connect(associateLastSelectedTagAction, SIGNAL(triggered()), this, \
SLOT(associateTag())); +            menu->addAction(associateLastSelectedTagAction);
+        }
+
+        // Handle all positionable tag candidates
+
+        QList<QPair<QString, QString>> positionableTagCandidates = \
m_dialog->positionableTagCandidates(); +        // If we have a last selected \
positionable tag: remove it +        \
positionableTagCandidates.removeAt(positionableTagCandidates.indexOf(lastSelectedPositionableTag));
 +
+        // If we still have candidates:
+        if (positionableTagCandidates.length() > 0) {
+            if (positionableTagCandidates.length() == 1
+                && lastSelectedPositionableTag.first.isEmpty()) {
+
+                // Add a single action
+                QAction* associateOnlyCandidateAction = createAssociateTagAction(
+                    positionableTagCandidates[0],
+                    i18nc("As in: associate [this marked area of the image] with one \
of the " +                          "following choices/menu items",
+                          "Associate with")
+                );
+                connect(associateOnlyCandidateAction, SIGNAL(triggered()), this, \
SLOT(associateTag())); +                \
menu->addAction(associateOnlyCandidateAction); +            } else {
+                // Create a new menu for all other tags
+                QMenu* submenu = menu->addMenu(
+                    i18nc("As in: associate [this marked area of the image] with one \
of the " +                          "following choices/menu items",
+                          "Associate with")
+                );
+
+                for (const QPair<QString, QString>& tag : positionableTagCandidates) \
{ +                    submenu->addAction(createAssociateTagAction(tag));
+                }
+
+                connect(submenu, SIGNAL(triggered(QAction*)), this, \
SLOT(associateTag(QAction*))); +            }
+        }
+    }
+
+    menu->addSeparator();
+
+#ifdef HAVE_KFACE
+    if (m_tagData.first.isEmpty() &&  m_proposedTagData.first.isEmpty()) {
+        // If we have nothing, offer a recognition database lookup
+        menu->addAction(m_recognizeAct);
+    }
+
+    if (! m_tagData.first.isEmpty() && m_changed && ! m_trained) {
+        // Append a "Update recognition database with this face" action
+        m_updateRecognitionDatabaseAct->setText(
+            i18n("Train the recognition database with the face of %1", \
m_tagData.second) +        );
+        menu->addAction(m_updateRecognitionDatabaseAct);
+    }
+#endif
+
+    // Append the "Remove area" action
+    menu->addAction(m_removeAct);
+}
+
 #ifdef HAVE_KFACE
 void AnnotationDialog::ResizableFrame::acceptTag()
 {
diff --git a/AnnotationDialog/ResizableFrame.h b/AnnotationDialog/ResizableFrame.h
index 18a43ef..ee3ba5f 100644
--- a/AnnotationDialog/ResizableFrame.h
+++ b/AnnotationDialog/ResizableFrame.h
@@ -73,6 +73,12 @@ public:
 public slots:
     void acceptTag();
 #endif
+    /**
+     * @brief Add the context menu actions to a QMenu.
+     * @sa AreaTagSelectDialog
+     * @param w
+     */
+    void addTagActions(QMenu *menu);
 
 protected:
     void mousePressEvent(QMouseEvent* event);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic