mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Finishing of outline, zoom actions
This commit is contained in:
@ -114,6 +114,25 @@ PDFDrawSpaceController::LayoutItem PDFDrawSpaceController::getLayoutItemForPage(
|
||||
return result;
|
||||
}
|
||||
|
||||
QSizeF PDFDrawSpaceController::getReferenceBoundingBox() const
|
||||
{
|
||||
QRectF rect;
|
||||
|
||||
for (const LayoutItem& item : m_layoutItems)
|
||||
{
|
||||
QRectF pageRect = item.pageRectMM;
|
||||
pageRect.translate(0, -pageRect.top());
|
||||
rect = rect.united(pageRect);
|
||||
}
|
||||
|
||||
if (rect.isValid())
|
||||
{
|
||||
rect.adjust(0, 0, m_horizontalSpacingMM, m_verticalSpacingMM);
|
||||
}
|
||||
|
||||
return rect.size();
|
||||
}
|
||||
|
||||
void PDFDrawSpaceController::recalculate()
|
||||
{
|
||||
if (!m_document)
|
||||
@ -697,6 +716,24 @@ void PDFDrawWidgetProxy::performOperation(Operation operation)
|
||||
break;
|
||||
}
|
||||
|
||||
case ZoomFit:
|
||||
{
|
||||
zoom(getZoomHint(ZoomHint::Fit));
|
||||
break;
|
||||
}
|
||||
|
||||
case ZoomFitWidth:
|
||||
{
|
||||
zoom(getZoomHint(ZoomHint::FitWidth));
|
||||
break;
|
||||
}
|
||||
|
||||
case ZoomFitHeight:
|
||||
{
|
||||
zoom(getZoomHint(ZoomHint::FitHeight));
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
Q_ASSERT(false);
|
||||
@ -734,6 +771,38 @@ void PDFDrawWidgetProxy::zoom(PDFReal zoom)
|
||||
}
|
||||
}
|
||||
|
||||
PDFReal PDFDrawWidgetProxy::getZoomHint(ZoomHint hint) const
|
||||
{
|
||||
QSizeF referenceSize = m_controller->getReferenceBoundingBox();
|
||||
if (referenceSize.isValid())
|
||||
{
|
||||
const PDFReal ratio = 0.95;
|
||||
const PDFReal widthMM = m_widget->widthMM() * ratio;
|
||||
const PDFReal heightMM = m_widget->heightMM() * ratio;
|
||||
|
||||
const PDFReal widthHint = widthMM / referenceSize.width();
|
||||
const PDFReal heightHint = heightMM / referenceSize.height();
|
||||
|
||||
switch (hint)
|
||||
{
|
||||
case ZoomHint::Fit:
|
||||
return qMin(widthHint, heightHint);
|
||||
|
||||
case ZoomHint::FitWidth:
|
||||
return widthHint;
|
||||
|
||||
case ZoomHint::FitHeight:
|
||||
return heightHint;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Return default 100% zoom
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
void PDFDrawWidgetProxy::goToPage(PDFInteger pageIndex)
|
||||
{
|
||||
PDFDrawSpaceController::LayoutItem layoutItem = m_controller->getLayoutItemForPage(pageIndex);
|
||||
|
Reference in New Issue
Block a user