aboutsummaryrefslogtreecommitdiff
path: root/notebookview.cc
diff options
context:
space:
mode:
Diffstat (limited to 'notebookview.cc')
-rw-r--r--notebookview.cc61
1 files changed, 47 insertions, 14 deletions
diff --git a/notebookview.cc b/notebookview.cc
index 1f97ead..833f8e8 100644
--- a/notebookview.cc
+++ b/notebookview.cc
@@ -25,7 +25,7 @@
NotebookView::NotebookView(QWidget *parent) :
QGraphicsView(parent), _nb(new AfdNotebook(this)), _replay(new PaperReplay(this)),
- _zoom(100), _curPage(0)
+ _numColumns(1), _zoom(100), _curPage(0)
{
setScene(new QGraphicsScene(this));
setTransformationAnchor(AnchorUnderMouse);
@@ -102,7 +102,12 @@ void NotebookView::setZoom(int zoom)
{
if (zoom != _zoom) {
_zoom = zoom;
+ int oldNumColumns = _numColumns;
calculateScale();
+ if (_numColumns != oldNumColumns) {
+ layoutPages();
+ }
+ emit zoomChanged(_zoom);
}
}
@@ -118,7 +123,7 @@ QRect NotebookView::getCurPageTrim() const
QImage NotebookView::exportPage(int pageNum) const
{
- const QRect pageTrim = getCurPageTrim();
+ const QRect pageTrim = _nb->getPageTrim(pageNum);
QImage image(pageTrim.width() / 4, pageTrim.height() / 4, QImage::Format_RGB32);
QPainter painter(&image);
painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
@@ -162,6 +167,16 @@ void NotebookView::nextPage()
}
}
+void NotebookView::focusOnPage(int pageNum)
+{
+ if (_pages.contains(pageNum)) {
+ if (_zoom < 100) {
+ setZoom(100);
+ }
+ setCurPage(pageNum);
+ }
+}
+
void NotebookView::resizeEvent(QResizeEvent *event)
{
QGraphicsView::resizeEvent(event);
@@ -226,21 +241,11 @@ bool NotebookView::createPages()
_maxPageSize.setHeight(box.height());
}
_pages.insert(pageNum, page);
- }
-
- calculateScale();
-
- qreal curY = 0;
- foreach (PageItem *page, _pages) {
- QRectF box = page->boundingRect();
- page->setPos((_maxPageSize.width() - box.width()) / 2.0, curY);
- curY += box.height();
- curY += PAGE_SEPARATION;
-
scene()->addItem(page);
}
- scene()->setSceneRect(0, 0, _maxPageSize.width(), curY);
+ calculateScale();
+ layoutPages();
return true;
}
@@ -253,12 +258,40 @@ void NotebookView::calculateScale()
qreal baseScale = qMin(viewRect.width() / _maxPageSize.width(),
viewRect.height() / _maxPageSize.height());
resetTransform();
+ _numColumns = 1;
+
scale(baseScale, baseScale);
+
if (_zoom < 100) {
qreal s = 0.25 + ((_zoom / 100.0) * 0.75);
+ int potentialColumns = viewRect.width() / (_maxPageSize.width() * baseScale * s);
+ if (potentialColumns >= 2) {
+ _numColumns = std::min(potentialColumns, _pages.size());
+ }
scale(s, s);
} else if (_zoom > 100) {
qreal s = 1.0 + (_zoom - 100) * 0.015;
scale(s, s);
}
}
+
+void NotebookView::layoutPages()
+{
+ const int numRows = (_pages.size() + 1) / _numColumns;
+ const QSizeF pageSpace( _maxPageSize.width() + PAGE_SEPARATION,
+ _maxPageSize.height() + PAGE_SEPARATION);
+
+ int pageIndex = 0;
+ foreach (PageItem *page, _pages) {
+ QRectF box = page->boundingRect();
+ qreal curX = (pageIndex % _numColumns) * pageSpace.width();
+ qreal curY = (pageIndex / _numColumns) * pageSpace.height();
+ page->setPos(curX + (_maxPageSize.width() - box.width()) / 2.0,
+ curY + (_maxPageSize.height() - box.height()) / 2.0);
+ pageIndex++;
+ }
+
+ scene()->setSceneRect(0, 0,
+ pageSpace.width() * _numColumns,
+ pageSpace.height() * numRows);
+}