From 10f24c2dff3e96cee5104d8f54bca504fdcd9be9 Mon Sep 17 00:00:00 2001 From: Jakub Melka Date: Sat, 7 Oct 2023 18:24:04 +0200 Subject: [PATCH] Issue #97: Context menu + layout items on window size changed --- Pdf4QtDocPageOrganizer/mainwindow.cpp | 38 ++++++++++++++++++++++++ Pdf4QtDocPageOrganizer/mainwindow.h | 4 +++ Pdf4QtDocPageOrganizer/mainwindow.ui | 3 ++ Pdf4QtDocPageOrganizer/pageitemmodel.cpp | 17 ++++++++++- 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/Pdf4QtDocPageOrganizer/mainwindow.cpp b/Pdf4QtDocPageOrganizer/mainwindow.cpp index e99ca6d..75c1fc1 100644 --- a/Pdf4QtDocPageOrganizer/mainwindow.cpp +++ b/Pdf4QtDocPageOrganizer/mainwindow.cpp @@ -56,6 +56,8 @@ MainWindow::MainWindow(QWidget* parent) : ui->documentItemsView->setModel(m_model); ui->documentItemsView->setItemDelegate(m_delegate); + connect(ui->documentItemsView, &QListView::customContextMenuRequested, this, &MainWindow::onWorkspaceCustomContextMenuRequested); + setMinimumSize(pdf::PDFWidgetUtils::scaleDPI(this, QSize(800, 600))); ui->actionClear->setData(int(Operation::Clear)); @@ -221,6 +223,13 @@ QSize MainWindow::getMaxPageImageSize() const return pdf::PDFWidgetUtils::scaleDPI(this, QSize(250, 250)); } +void MainWindow::resizeEvent(QResizeEvent* resizeEvent) +{ + QMainWindow::resizeEvent(resizeEvent); + + ui->documentItemsView->doItemsLayout(); +} + void MainWindow::on_actionClose_triggered() { close(); @@ -246,6 +255,35 @@ void MainWindow::onMappedActionTriggered(int actionId) performOperation(static_cast(actionId)); } +void MainWindow::onWorkspaceCustomContextMenuRequested(const QPoint& point) +{ + QMenu* contextMenu = new QMenu(this); + contextMenu->addAction(ui->actionCut); + contextMenu->addAction(ui->actionCopy); + contextMenu->addAction(ui->actionPaste); + contextMenu->addSeparator(); + contextMenu->addAction(ui->actionRotate_Left); + contextMenu->addAction(ui->actionRotate_Right); + QMenu* selectMenu = contextMenu->addMenu(tr("Select")); + selectMenu->addAction(ui->actionSelect_All); + selectMenu->addAction(ui->actionSelect_Even); + selectMenu->addAction(ui->actionSelect_Odd); + selectMenu->addAction(ui->actionSelect_Landscape); + selectMenu->addAction(ui->actionSelect_Portrait); + selectMenu->addAction(ui->actionSelect_None); + QMenu* regroupMenu = contextMenu->addMenu(tr("Regroup")); + regroupMenu->addAction(ui->actionRegroup_Even_Odd); + regroupMenu->addAction(ui->actionRegroup_by_Alternating_Pages); + regroupMenu->addAction(ui->actionRegroup_by_Alternating_Pages_Reversed_Order); + regroupMenu->addAction(ui->actionRegroup_by_Page_Pairs); + regroupMenu->addAction(ui->actionRegroup_by_Bookmarks); + contextMenu->addSeparator(); + contextMenu->addAction(ui->actionGroup); + contextMenu->addAction(ui->actionUngroup); + + contextMenu->exec(ui->documentItemsView->viewport()->mapToGlobal(point)); +} + void MainWindow::updateActions() { QList actions = findChildren(); diff --git a/Pdf4QtDocPageOrganizer/mainwindow.h b/Pdf4QtDocPageOrganizer/mainwindow.h index b0eb2dc..95ab66e 100644 --- a/Pdf4QtDocPageOrganizer/mainwindow.h +++ b/Pdf4QtDocPageOrganizer/mainwindow.h @@ -100,10 +100,14 @@ public: PrepareIconTheme }; +protected: + virtual void resizeEvent(QResizeEvent* resizeEvent) override; + private slots: void on_actionClose_triggered(); void on_actionAddDocuments_triggered(); void onMappedActionTriggered(int actionId); + void onWorkspaceCustomContextMenuRequested(const QPoint& point); void updateActions(); private: diff --git a/Pdf4QtDocPageOrganizer/mainwindow.ui b/Pdf4QtDocPageOrganizer/mainwindow.ui index 8025ad1..4df97d2 100644 --- a/Pdf4QtDocPageOrganizer/mainwindow.ui +++ b/Pdf4QtDocPageOrganizer/mainwindow.ui @@ -20,6 +20,9 @@ + + Qt::CustomContextMenu + true diff --git a/Pdf4QtDocPageOrganizer/pageitemmodel.cpp b/Pdf4QtDocPageOrganizer/pageitemmodel.cpp index 9ea0261..3fab2a6 100644 --- a/Pdf4QtDocPageOrganizer/pageitemmodel.cpp +++ b/Pdf4QtDocPageOrganizer/pageitemmodel.cpp @@ -83,10 +83,25 @@ QVariant PageItemModel::data(const QModelIndex& index, int role) const return QVariant(); } + const PageGroupItem* item = getItem(index); switch (role) { case Qt::DisplayRole: - return m_pageGroupItems.at(index.row()).groupName; + return item->groupName; + + case Qt::ToolTipRole: + { + QStringList texts; + texts << QString("%1").arg(item->groupName); + + if (item->isGrouped()) + { + texts << QString("%1 pages").arg(item->groups.size()); + } + + return texts.join("
"); + } + default: break;