DocPage Organizer: page rotation

This commit is contained in:
Jakub Melka 2021-07-15 19:44:44 +02:00
parent 7b768d3b09
commit 688c0b701c
4 changed files with 85 additions and 1 deletions

View File

@ -451,7 +451,13 @@ void MainWindow::performOperation(Operation operation)
}
case Operation::RotateLeft:
m_model->rotateLeft(ui->documentItemsView->selectionModel()->selection().indexes());
break;
case Operation::RotateRight:
m_model->rotateRight(ui->documentItemsView->selectionModel()->selection().indexes());
break;
case Operation::ReplaceSelection:
Q_ASSERT(false);
break;

View File

@ -58,7 +58,8 @@ void PageItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& opti
if (!item->groups.empty())
{
const PageGroupItem::GroupItem& groupItem = item->groups.front();
QSize pageImageSize = groupItem.rotatedPageDimensionsMM.scaled(pageBoundingRect.size(), Qt::KeepAspectRatio).toSize();
QSizeF rotatedPageSize = pdf::PDFPage::getRotatedBox(QRectF(QPointF(0, 0), groupItem.rotatedPageDimensionsMM), groupItem.pageAdditionalRotation).size();
QSize pageImageSize = rotatedPageSize.scaled(pageBoundingRect.size(), Qt::KeepAspectRatio).toSize();
QRect pageImageRect(pageBoundingRect.topLeft() + QPoint((pageBoundingRect.width() - pageImageSize.width()) / 2, (pageBoundingRect.height() - pageImageSize.height()) / 2), pageImageSize);
painter->setPen(QPen(Qt::black));

View File

@ -344,6 +344,60 @@ void PageItemModel::removeSelection(const QModelIndexList& list)
endResetModel();
}
void PageItemModel::rotateLeft(const QModelIndexList& list)
{
if (list.isEmpty())
{
return;
}
int rowMin = list.front().row();
int rowMax = list.front().row();
for (const QModelIndex& index : list)
{
if (PageGroupItem* item = getItem(index))
{
item->rotateLeft();
}
rowMin = qMin(rowMin, index.row());
rowMax = qMax(rowMax, index.row());
}
rowMin = qMax(rowMin, 0);
rowMax = qMin(rowMax, rowCount(QModelIndex()) - 1);
emit dataChanged(index(rowMin, 0, QModelIndex()), index(rowMax, 0, QModelIndex()));
}
void PageItemModel::rotateRight(const QModelIndexList& list)
{
if (list.isEmpty())
{
return;
}
int rowMin = list.front().row();
int rowMax = list.front().row();
for (const QModelIndex& index : list)
{
if (PageGroupItem* item = getItem(index))
{
item->rotateRight();
}
rowMin = qMin(rowMin, index.row());
rowMax = qMax(rowMax, index.row());
}
rowMin = qMax(rowMin, 0);
rowMax = qMin(rowMax, rowCount(QModelIndex()) - 1);
emit dataChanged(index(rowMin, 0, QModelIndex()), index(rowMax, 0, QModelIndex()));
}
QItemSelection PageItemModel::getSelectionImpl(std::function<bool (const PageGroupItem::GroupItem&)> filter) const
{
QItemSelection result;
@ -463,6 +517,22 @@ std::set<int> PageGroupItem::getDocumentIndices() const
return result;
}
void PageGroupItem::rotateLeft()
{
for (auto& groupItem : groups)
{
groupItem.pageAdditionalRotation = pdf::getPageRotationRotatedLeft(groupItem.pageAdditionalRotation);
}
}
void PageGroupItem::rotateRight()
{
for (auto& groupItem : groups)
{
groupItem.pageAdditionalRotation = pdf::getPageRotationRotatedRight(groupItem.pageAdditionalRotation);
}
}
QStringList PageItemModel::mimeTypes() const
{
return { getMimeDataType() };

View File

@ -39,6 +39,7 @@ struct PageGroupItem
int documentIndex = 0;
pdf::PDFInteger pageIndex;
QSizeF rotatedPageDimensionsMM;
pdf::PageRotation pageAdditionalRotation = pdf::PageRotation::None;
};
std::vector<GroupItem> groups;
@ -48,6 +49,9 @@ struct PageGroupItem
bool isGrouped() const { return groups.size() > 1; }
std::set<int> getDocumentIndices() const;
void rotateLeft();
void rotateRight();
};
struct DocumentItem
@ -119,6 +123,9 @@ public:
QModelIndexList cloneSelection(const QModelIndexList& list);
void removeSelection(const QModelIndexList& list);
void rotateLeft(const QModelIndexList& list);
void rotateRight(const QModelIndexList& list);
static QString getMimeDataType() { return QLatin1String("application/pagemodel.PDF4QtDocPageOrganizer"); }
private: