diff --git a/Pdf4QtDocPageOrganizer/mainwindow.cpp b/Pdf4QtDocPageOrganizer/mainwindow.cpp index 148f61c..c630325 100644 --- a/Pdf4QtDocPageOrganizer/mainwindow.cpp +++ b/Pdf4QtDocPageOrganizer/mainwindow.cpp @@ -35,7 +35,8 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow), m_model(new PageItemModel(this)), - m_delegate(new PageItemDelegate(m_model, this)) + m_delegate(new PageItemDelegate(m_model, this)), + m_dropAction(Qt::IgnoreAction) { ui->setupUi(this); @@ -45,6 +46,7 @@ MainWindow::MainWindow(QWidget* parent) : ui->documentItemsView->setItemDelegate(m_delegate); setMinimumSize(pdf::PDFWidgetUtils::scaleDPI(this, QSize(800, 600))); + ui->actionClear->setData(int(Operation::Clear)); ui->actionCloneSelection->setData(int(Operation::CloneSelection)); ui->actionRemoveSelection->setData(int(Operation::RemoveSelection)); ui->actionReplaceSelection->setData(int(Operation::ReplaceSelection)); @@ -258,6 +260,9 @@ bool MainWindow::canPerformOperation(Operation operation) const switch (operation) { + case Operation::Clear: + return true; + case Operation::CloneSelection: case Operation::RemoveSelection: case Operation::ReplaceSelection: @@ -318,18 +323,59 @@ void MainWindow::performOperation(Operation operation) { switch (operation) { + case Operation::Clear: + { + m_model->clear(); + break; + } case Operation::CloneSelection: case Operation::RemoveSelection: case Operation::ReplaceSelection: case Operation::RestoreRemovedItems: - case Operation::Cut: - case Operation::Copy: - case Operation::Paste: case Operation::RotateLeft: case Operation::RotateRight: Q_ASSERT(false); break; + case Operation::Cut: + case Operation::Copy: + { + QModelIndexList indices = ui->documentItemsView->selectionModel()->selection().indexes(); + + if (indices.isEmpty()) + { + return; + } + + if (QMimeData* mimeData = m_model->mimeData(indices)) + { + QApplication::clipboard()->setMimeData(mimeData); + } + + ui->documentItemsView->clearSelection(); + m_dropAction = (operation == Operation::Cut) ? Qt::MoveAction : Qt::CopyAction; + break; + } + + case Operation::Paste: + { + QModelIndexList indices = ui->documentItemsView->selectionModel()->selection().indexes(); + + int insertRow = m_model->rowCount(QModelIndex()) - 1; + if (!indices.isEmpty()) + { + insertRow = indices.back().row(); + } + + QModelIndex insertIndex = m_model->index(insertRow, 0, QModelIndex()); + const QMimeData* mimeData = QApplication::clipboard()->mimeData(); + if (m_model->canDropMimeData(mimeData, m_dropAction, -1, -1, insertIndex)) + { + m_model->dropMimeData(mimeData, m_dropAction, -1, -1, insertIndex); + } + break; + } + case Operation::Group: m_model->group(ui->documentItemsView->selectionModel()->selection().indexes()); break; diff --git a/Pdf4QtDocPageOrganizer/mainwindow.h b/Pdf4QtDocPageOrganizer/mainwindow.h index 6cfad83..df948bc 100644 --- a/Pdf4QtDocPageOrganizer/mainwindow.h +++ b/Pdf4QtDocPageOrganizer/mainwindow.h @@ -47,6 +47,7 @@ public: enum class Operation { + Clear, CloneSelection, RemoveSelection, ReplaceSelection, @@ -102,6 +103,7 @@ private: PageItemDelegate* m_delegate; Settings m_settings; QSignalMapper m_mapper; + Qt::DropAction m_dropAction; }; } // namespace pdfdocpage diff --git a/Pdf4QtDocPageOrganizer/mainwindow.ui b/Pdf4QtDocPageOrganizer/mainwindow.ui index b866711..3304a0c 100644 --- a/Pdf4QtDocPageOrganizer/mainwindow.ui +++ b/Pdf4QtDocPageOrganizer/mainwindow.ui @@ -56,6 +56,7 @@ File + @@ -143,7 +144,7 @@ Close - Ctrl+W + Alt+F4 @@ -467,6 +468,18 @@ Ctrl+Shift+G + + + + :/pdfdocpage/resources/clear.svg:/pdfdocpage/resources/clear.svg + + + Clear + + + Ctrl+W + + diff --git a/Pdf4QtDocPageOrganizer/pageitemmodel.cpp b/Pdf4QtDocPageOrganizer/pageitemmodel.cpp index 8c27a1f..a8571a7 100644 --- a/Pdf4QtDocPageOrganizer/pageitemmodel.cpp +++ b/Pdf4QtDocPageOrganizer/pageitemmodel.cpp @@ -548,4 +548,13 @@ Qt::ItemFlags PageItemModel::flags(const QModelIndex& index) const return flags; } +void PageItemModel::clear() +{ + beginResetModel(); + m_pageGroupItems.clear(); + m_documents.clear(); + m_trashBin.clear(); + endResetModel(); +} + } // namespace pdfdocpage diff --git a/Pdf4QtDocPageOrganizer/pageitemmodel.h b/Pdf4QtDocPageOrganizer/pageitemmodel.h index 8bee1d4..6c8398a 100644 --- a/Pdf4QtDocPageOrganizer/pageitemmodel.h +++ b/Pdf4QtDocPageOrganizer/pageitemmodel.h @@ -80,6 +80,9 @@ public: virtual Qt::DropActions supportedDragActions() const override; virtual Qt::ItemFlags flags(const QModelIndex& index) const override; + /// Clear all data and undo/redo + void clear(); + /// Adds document to the model, inserts one single page group containing /// the whole document. Returns index of a newly added document. If document /// cannot be added (for example, it already exists), -1 is returned. diff --git a/Pdf4QtDocPageOrganizer/resources.qrc b/Pdf4QtDocPageOrganizer/resources.qrc index 5fd3445..5d92f56 100644 --- a/Pdf4QtDocPageOrganizer/resources.qrc +++ b/Pdf4QtDocPageOrganizer/resources.qrc @@ -29,5 +29,6 @@ resources/ungroup.svg resources/zoom-in.svg resources/zoom-out.svg + resources/clear.svg diff --git a/Pdf4QtDocPageOrganizer/resources/clear.svg b/Pdf4QtDocPageOrganizer/resources/clear.svg new file mode 100644 index 0000000..495d25b --- /dev/null +++ b/Pdf4QtDocPageOrganizer/resources/clear.svg @@ -0,0 +1,108 @@ + + + + + + + + + + + + image/svg+xml + + + + + Jakub Melka + + + + + + + + + + + + + + + + + + + + diff --git a/Pdf4QtLib/sources/pdfpainterutils.cpp b/Pdf4QtLib/sources/pdfpainterutils.cpp index 71a0642..f185eae 100644 --- a/Pdf4QtLib/sources/pdfpainterutils.cpp +++ b/Pdf4QtLib/sources/pdfpainterutils.cpp @@ -51,6 +51,7 @@ QRect PDFPainterHelper::drawBubble(QPainter* painter, QPoint point, QColor color } PDFPainterStateGuard guard(painter); + painter->setRenderHint(QPainter::Antialiasing); painter->setPen(Qt::NoPen); painter->setBrush(QBrush(color)); painter->drawRoundedRect(rectangle, rectangle.height() / 2, rectangle.height() / 2, Qt::AbsoluteSize);