From kde-commits Wed Nov 30 23:40:14 2016 From: Johannes Zarl-Zierl Date: Wed, 30 Nov 2016 23:40:14 +0000 To: kde-commits Subject: [kphotoalbum/area_workflow_improvement] AnnotationDialog: Include ResizableFrame context-menu action Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=148054922531334 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/Ar= eaTagSelectDialog.cpp index 50188ff..0cc9a31 100644 --- a/AnnotationDialog/AreaTagSelectDialog.cpp +++ b/AnnotationDialog/AreaTagSelectDialog.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include = AnnotationDialog::AreaTagSelectDialog::AreaTagSelectDialog(AnnotationDialo= g::ResizableFrame *area, @@ -54,7 +55,8 @@ AnnotationDialog::AreaTagSelectDialog::AreaTagSelectDialo= g(AnnotationDialog::Res m_areaImageLabel =3D 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 =3D new CompletableLineEdit(ls, this); ls->connectLineEdit(tagSelect); @@ -65,6 +67,11 @@ AnnotationDialog::AreaTagSelectDialog::AreaTagSelectDial= og(AnnotationDialog::Res mainLayout->addWidget(m_messageLabel, 1, 1); m_messageLabel->hide(); = + QMenu *tagMenu =3D 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, &AreaTagSelectDial= og::slotSetTag); connect(tagSelect, &QLineEdit::textChanged, this, &AreaTagSelectDialog= ::slotValidateTag); } diff --git a/AnnotationDialog/ResizableFrame.cpp b/AnnotationDialog/Resizab= leFrame.cpp index c9b69c4..64d6f7a 100644 --- a/AnnotationDialog/ResizableFrame.cpp +++ b/AnnotationDialog/ResizableFrame.cpp @@ -331,85 +331,7 @@ void AnnotationDialog::ResizableFrame::contextMenuEven= t(QContextMenuEvent* event { // Create the context menu QMenu* menu =3D 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 a= rea 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 lastSelectedPositionableTag =3D m_dialog->= lastSelectedPositionableTag(); - if (! lastSelectedPositionableTag.first.isEmpty()) { - QAction* associateLastSelectedTagAction =3D createAssociateTag= Action( - lastSelectedPositionableTag, - i18n("Associate with") - ); - connect(associateLastSelectedTagAction, SIGNAL(triggered()), t= his, SLOT(associateTag())); - menu->addAction(associateLastSelectedTagAction); - } - - // Handle all positionable tag candidates - - QList> positionableTagCandidates =3D m_dia= log->positionableTagCandidates(); - // If we have a last selected positionable tag: remove it - positionableTagCandidates.removeAt(positionableTagCandidates.index= Of(lastSelectedPositionableTag)); - - // If we still have candidates: - if (positionableTagCandidates.length() > 0) { - if (positionableTagCandidates.length() =3D=3D 1 - && lastSelectedPositionableTag.first.isEmpty()) { - - // Add a single action - QAction* associateOnlyCandidateAction =3D createAssociateT= agAction( - 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 =3D 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& tag : positionableTagC= andidates) { - submenu->addAction(createAssociateTagAction(tag)); - } - - connect(submenu, SIGNAL(triggered(QAction*)), this, SLOT(a= ssociateTag(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_t= agData.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::removeProposedT= agData() 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 a= rea 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 lastSelectedPositionableTag =3D m_dialog->= lastSelectedPositionableTag(); + if (! lastSelectedPositionableTag.first.isEmpty()) { + QAction* associateLastSelectedTagAction =3D createAssociateTag= Action( + lastSelectedPositionableTag, + i18n("Associate with") + ); + connect(associateLastSelectedTagAction, SIGNAL(triggered()), t= his, SLOT(associateTag())); + menu->addAction(associateLastSelectedTagAction); + } + + // Handle all positionable tag candidates + + QList> positionableTagCandidates =3D m_dia= log->positionableTagCandidates(); + // If we have a last selected positionable tag: remove it + positionableTagCandidates.removeAt(positionableTagCandidates.index= Of(lastSelectedPositionableTag)); + + // If we still have candidates: + if (positionableTagCandidates.length() > 0) { + if (positionableTagCandidates.length() =3D=3D 1 + && lastSelectedPositionableTag.first.isEmpty()) { + + // Add a single action + QAction* associateOnlyCandidateAction =3D createAssociateT= agAction( + 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 =3D 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& tag : positionableTagC= andidates) { + submenu->addAction(createAssociateTagAction(tag)); + } + + connect(submenu, SIGNAL(triggered(QAction*)), this, SLOT(a= ssociateTag(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_t= agData.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/Resizable= Frame.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);