Commit aabff9db authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Merge remote-tracking branch 'origin/release/20.08' into master

parents 40e890ef 3f892463
Pipeline #35187 passed with stage
in 20 minutes and 30 seconds
......@@ -65,109 +65,103 @@ void AnnotationPopup::exec(const QPoint point)
QMenu menu(mParent);
QAction *action = nullptr;
addActionsToMenu(&menu);
const char *actionTypeId = "actionType";
menu.exec(point.isNull() ? QCursor::pos() : point);
}
const QString openId = QStringLiteral("open");
const QString deleteId = QStringLiteral("delete");
const QString deleteAllId = QStringLiteral("deleteAll");
const QString propertiesId = QStringLiteral("properties");
const QString saveId = QStringLiteral("save");
void AnnotationPopup::addActionsToMenu(QMenu *menu)
{
QAction *action = nullptr;
if (mMenuMode == SingleAnnotationMode) {
const bool onlyOne = (mAnnotations.count() == 1);
const AnnotPagePair &pair = mAnnotations.at(0);
menu.addAction(new OKMenuTitle(&menu, i18np("Annotation", "%1 Annotations", mAnnotations.count())));
menu->addAction(new OKMenuTitle(menu, i18np("Annotation", "%1 Annotations", mAnnotations.count())));
action = menu.addAction(QIcon::fromTheme(QStringLiteral("comment")), i18n("&Open Pop-up Note"));
action->setData(QVariant::fromValue(pair));
action = menu->addAction(QIcon::fromTheme(QStringLiteral("comment")), i18n("&Open Pop-up Note"));
action->setEnabled(onlyOne);
action->setProperty(actionTypeId, openId);
connect(action, &QAction::triggered, menu, [this, pair] { doOpenAnnotationWindow(pair); });
action = menu.addAction(QIcon::fromTheme(QStringLiteral("list-remove")), i18n("&Delete"));
action = menu->addAction(QIcon::fromTheme(QStringLiteral("list-remove")), i18n("&Delete"));
action->setEnabled(mDocument->isAllowed(Okular::AllowNotes));
action->setProperty(actionTypeId, deleteAllId);
connect(action, &QAction::triggered, menu, [this] {
for (const AnnotPagePair &pair : qAsConst(mAnnotations)) {
doRemovePageAnnotation(pair);
}
});
for (const AnnotPagePair &pair : qAsConst(mAnnotations)) {
if (!mDocument->canRemovePageAnnotation(pair.annotation))
action->setEnabled(false);
}
action = menu.addAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("&Properties"));
action->setData(QVariant::fromValue(pair));
action = menu->addAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("&Properties"));
action->setEnabled(onlyOne);
action->setProperty(actionTypeId, propertiesId);
connect(action, &QAction::triggered, menu, [this, pair] { doOpenPropertiesDialog(pair); });
if (onlyOne && annotationHasFileAttachment(pair.annotation)) {
const Okular::EmbeddedFile *embeddedFile = embeddedFileFromAnnotation(pair.annotation);
if (embeddedFile) {
const QString saveText = i18nc("%1 is the name of the file to save", "&Save '%1'...", embeddedFile->name());
menu.addSeparator();
action = menu.addAction(QIcon::fromTheme(QStringLiteral("document-save")), saveText);
action->setData(QVariant::fromValue(pair));
action->setProperty(actionTypeId, saveId);
menu->addSeparator();
action = menu->addAction(QIcon::fromTheme(QStringLiteral("document-save")), saveText);
connect(action, &QAction::triggered, menu, [this, pair] { doSaveEmbeddedFile(pair); });
}
}
} else {
for (const AnnotPagePair &pair : qAsConst(mAnnotations)) {
menu.addAction(new OKMenuTitle(&menu, GuiUtils::captionForAnnotation(pair.annotation)));
menu->addAction(new OKMenuTitle(menu, GuiUtils::captionForAnnotation(pair.annotation)));
action = menu.addAction(QIcon::fromTheme(QStringLiteral("comment")), i18n("&Open Pop-up Note"));
action->setData(QVariant::fromValue(pair));
action->setProperty(actionTypeId, openId);
action = menu->addAction(QIcon::fromTheme(QStringLiteral("comment")), i18n("&Open Pop-up Note"));
connect(action, &QAction::triggered, menu, [this, pair] { doOpenAnnotationWindow(pair); });
action = menu.addAction(QIcon::fromTheme(QStringLiteral("list-remove")), i18n("&Delete"));
action = menu->addAction(QIcon::fromTheme(QStringLiteral("list-remove")), i18n("&Delete"));
action->setEnabled(mDocument->isAllowed(Okular::AllowNotes) && mDocument->canRemovePageAnnotation(pair.annotation));
action->setData(QVariant::fromValue(pair));
action->setProperty(actionTypeId, deleteId);
connect(action, &QAction::triggered, menu, [this, pair] { doRemovePageAnnotation(pair); });
action = menu.addAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("&Properties"));
action->setData(QVariant::fromValue(pair));
action->setProperty(actionTypeId, propertiesId);
action = menu->addAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("&Properties"));
connect(action, &QAction::triggered, menu, [this, pair] { doOpenPropertiesDialog(pair); });
if (annotationHasFileAttachment(pair.annotation)) {
const Okular::EmbeddedFile *embeddedFile = embeddedFileFromAnnotation(pair.annotation);
if (embeddedFile) {
const QString saveText = i18nc("%1 is the name of the file to save", "&Save '%1'...", embeddedFile->name());
menu.addSeparator();
action = menu.addAction(QIcon::fromTheme(QStringLiteral("document-save")), saveText);
action->setData(QVariant::fromValue(pair));
action->setProperty(actionTypeId, saveId);
menu->addSeparator();
action = menu->addAction(QIcon::fromTheme(QStringLiteral("document-save")), saveText);
connect(action, &QAction::triggered, menu, [this, pair] { doSaveEmbeddedFile(pair); });
}
}
}
}
}
QAction *choice = menu.exec(point.isNull() ? QCursor::pos() : point);
void AnnotationPopup::doRemovePageAnnotation(AnnotPagePair pair)
{
if (pair.pageNumber != -1) {
mDocument->removePageAnnotation(pair.pageNumber, pair.annotation);
}
}
// check if the user really selected an action
if (choice) {
const AnnotPagePair pair = choice->data().value<AnnotPagePair>();
void AnnotationPopup::doOpenAnnotationWindow(AnnotPagePair pair)
{
emit openAnnotationWindow(pair.annotation, pair.pageNumber);
}
const QString actionType = choice->property(actionTypeId).toString();
if (actionType == openId) {
emit openAnnotationWindow(pair.annotation, pair.pageNumber);
} else if (actionType == deleteId) {
if (pair.pageNumber != -1)
mDocument->removePageAnnotation(pair.pageNumber, pair.annotation);
} else if (actionType == deleteAllId) {
for (const AnnotPagePair &pair : qAsConst(mAnnotations)) {
if (pair.pageNumber != -1)
mDocument->removePageAnnotation(pair.pageNumber, pair.annotation);
}
} else if (actionType == propertiesId) {
if (pair.pageNumber != -1) {
AnnotsPropertiesDialog propdialog(mParent, mDocument, pair.pageNumber, pair.annotation);
propdialog.exec();
}
} else if (actionType == saveId) {
Okular::EmbeddedFile *embeddedFile = embeddedFileFromAnnotation(pair.annotation);
GuiUtils::saveEmbeddedFile(embeddedFile, mParent);
}
void AnnotationPopup::doOpenPropertiesDialog(AnnotPagePair pair)
{
if (pair.pageNumber != -1) {
AnnotsPropertiesDialog propdialog(mParent, mDocument, pair.pageNumber, pair.annotation);
propdialog.exec();
}
}
void AnnotationPopup::doSaveEmbeddedFile(AnnotPagePair pair)
{
Okular::EmbeddedFile *embeddedFile = embeddedFileFromAnnotation(pair.annotation);
GuiUtils::saveEmbeddedFile(embeddedFile, mParent);
}
......@@ -15,6 +15,8 @@
#include <QPair>
#include <QPoint>
class QMenu;
namespace Okular
{
class Annotation;
......@@ -38,6 +40,9 @@ public:
void addAnnotation(Okular::Annotation *annotation, int pageNumber);
/* You only need to use this if you don't plan on using exec() */
void addActionsToMenu(QMenu *menu);
void exec(const QPoint point = QPoint());
Q_SIGNALS:
......@@ -67,6 +72,11 @@ public:
};
private:
void doRemovePageAnnotation(AnnotPagePair pair);
void doOpenAnnotationWindow(AnnotPagePair pair);
void doOpenPropertiesDialog(AnnotPagePair pair);
void doSaveEmbeddedFile(AnnotPagePair pair);
QWidget *mParent;
QList<AnnotPagePair> mAnnotations;
......
......@@ -2230,32 +2230,6 @@ void PageView::mousePressEvent(QMouseEvent *e)
d->scroller->handleInput(QScroller::InputPress, e->pos(), e->timestamp());
d->leftClickTimer.start(QApplication::doubleClickInterval() + 10);
}
} else if (rightButton) {
if (pageItem) {
// find out normalized mouse coords inside current item
const QRect &itemRect = pageItem->uncroppedGeometry();
double nX = pageItem->absToPageX(eventPos.x());
double nY = pageItem->absToPageY(eventPos.y());
const QLinkedList<const Okular::ObjectRect *> orects = pageItem->page()->objectRects(Okular::ObjectRect::OAnnotation, nX, nY, itemRect.width(), itemRect.height());
if (!orects.isEmpty()) {
AnnotationPopup popup(d->document, AnnotationPopup::MultiAnnotationMode, this);
for (const Okular::ObjectRect *orect : orects) {
Okular::Annotation *ann = ((Okular::AnnotationObjectRect *)orect)->annotation();
if (ann && (ann->subType() != Okular::Annotation::AWidget))
popup.addAnnotation(ann, pageItem->pageNumber());
}
connect(&popup, &AnnotationPopup::openAnnotationWindow, this, &PageView::openAnnotationWindow);
popup.exec(e->globalPos());
// Since ↑ spins its own event loop we won't get the mouse release event
// so reset mousePressPos here
d->mousePressPos = QPoint();
}
}
}
} break;
......@@ -2476,15 +2450,38 @@ void PageView::mouseReleaseEvent(QMouseEvent *e)
} else if (rightButton && !d->mouseAnnotation->isModified()) {
if (pageItem && pageItem == pageItemPressPos && ((d->mousePressPos - e->globalPos()).manhattanLength() < QApplication::startDragDistance())) {
QMenu *menu = createProcessLinkMenu(pageItem, eventPos);
const QRect &itemRect = pageItem->uncroppedGeometry();
const double nX = pageItem->absToPageX(eventPos.x());
const double nY = pageItem->absToPageY(eventPos.y());
const QLinkedList<const Okular::ObjectRect *> annotRects = pageItem->page()->objectRects(Okular::ObjectRect::OAnnotation, nX, nY, itemRect.width(), itemRect.height());
AnnotationPopup annotPopup(d->document, AnnotationPopup::MultiAnnotationMode, this);
// Do not move annotPopup inside the if, it needs to live until menu->exec()
if (!annotRects.isEmpty()) {
for (const Okular::ObjectRect *annotRect : annotRects) {
Okular::Annotation *ann = ((Okular::AnnotationObjectRect *)annotRect)->annotation();
if (ann && (ann->subType() != Okular::Annotation::AWidget)) {
annotPopup.addAnnotation(ann, pageItem->pageNumber());
}
}
connect(&annotPopup, &AnnotationPopup::openAnnotationWindow, this, &PageView::openAnnotationWindow);
if (!menu) {
menu = new QMenu(this);
}
annotPopup.addActionsToMenu(menu);
}
if (menu) {
menu->exec(e->globalPos());
menu->deleteLater();
} else {
const double nX = pageItem->absToPageX(eventPos.x());
const double nY = pageItem->absToPageY(eventPos.y());
// a link can move us to another page or even to another document, there's no point in trying to
// process the click on the image once we have processes the click on the link
const Okular::ObjectRect *rect = pageItem->page()->objectRect(Okular::ObjectRect::Image, nX, nY, pageItem->uncroppedWidth(), pageItem->uncroppedHeight());
const Okular::ObjectRect *rect = pageItem->page()->objectRect(Okular::ObjectRect::Image, nX, nY, itemRect.width(), itemRect.height());
if (rect) {
// handle right click over a image
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment