Jumping to a page offers view selection
authorDmitriy Morozov <dmitriy@mrzv.org>
Tue, 09 Nov 2010 22:32:37 -0800
changeset 2 035dc97b8d04
parent 1 14e9780340d7
child 3 b239dd8c8689
Jumping to a page offers view selection
mainwindow.cpp
pagedialog.cpp
pagedialog.h
--- a/mainwindow.cpp	Mon Nov 08 22:45:19 2010 -0800
+++ b/mainwindow.cpp	Tue Nov 09 22:32:37 2010 -0800
@@ -145,13 +145,21 @@
             break;
         case EJumpTo:
         {
-            page_dialog->reset();
             page_dialog->exec();
             if (page_dialog->isOk())
             {
-                iPageNo = page_dialog->page();
-                iViewNo = 0;
-                setView();
+                std::vector<PageDialog::PageViewPair> views;
+                for (unsigned i = 0; i < iDoc->page(page_dialog->page())->countViews(); ++i)
+                    views.push_back(PageDialog::PageViewPair(page_dialog->page(), i));
+                
+                PageDialog  view_dialog(iDoc, views);
+                view_dialog.exec();
+                if (view_dialog.isOk())
+                {
+                    iPageNo = view_dialog.page();
+                    iViewNo = view_dialog.view();
+                    setView();
+                }
             }
             break;
         }
@@ -191,7 +199,10 @@
     canvas_view->load(doc, iPageNo, iViewNo);
      
     delete page_dialog;
-    page_dialog = new PageDialog(iDoc);
+    std::vector<PageDialog::PageViewPair>    views;
+    for (unsigned i = 0; i < iDoc->countPages(); ++i)
+        views.push_back(PageDialog::PageViewPair(i, 0));
+    page_dialog = new PageDialog(iDoc, views);
     
     updateLabel();
     return true;
--- a/pagedialog.cpp	Mon Nov 08 22:45:19 2010 -0800
+++ b/pagedialog.cpp	Tue Nov 09 22:32:37 2010 -0800
@@ -2,7 +2,7 @@
 
 #include "pagedialog.h"
 
-PageDialog::PageDialog(Document* d): iDoc(d)
+PageDialog::PageDialog(Document* d, const std::vector<PageViewPair>& v): iDoc(d), views(v)
 {
     // buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
     // connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
@@ -11,18 +11,18 @@
     QGridLayout *mainLayout = new QGridLayout;
     fillPages(mainLayout);
     setLayout(mainLayout);
-    setWindowTitle(tr("Select page"));
-    reset();
+    setWindowTitle(tr("Select page/view"));
+    ok = false;
 }
 
 void PageDialog::fillPages(QGridLayout* layout)
 {
-    for (unsigned i = 0; i < iDoc->countPages(); ++i)
+    for (unsigned i = 0; i < views.size(); ++i)
     {
         Canvas* c = new Canvas(this);
         c->setFontPool(iDoc->fontPool());
         c->setPretty(true);
-        c->setPage(iDoc->page(i), 0, iDoc->cascade());
+        c->setPage(iDoc->page(views[i].first), views[i].second, iDoc->cascade());
         connect(c, SIGNAL(mouseAction(int)), this, SLOT(pageChosen(int)));
         canvases.push_back(c);
         layout->addWidget(c, i/5, i%5);
@@ -48,7 +48,8 @@
         if (canvases[i] == QObject::sender())
         {
             ok = true;
-            pageChoice = i;
+            pageChoice = views[i].first;
+            viewChoice = views[i].second;
         }
     accept();
 }
--- a/pagedialog.h	Mon Nov 08 22:45:19 2010 -0800
+++ b/pagedialog.h	Tue Nov 09 22:32:37 2010 -0800
@@ -16,11 +16,15 @@
     Q_OBJECT
 
 public:
-            PageDialog(Document* d);
+    typedef std::pair<int,int>      PageViewPair;
+
+public:
+            PageDialog(Document* d, const std::vector<PageViewPair>& v);
 
     bool    isOk()     { return ok; }
     int     page()     { return pageChoice; }
-    void    reset()    { ok = false; }
+    int     view()     { return viewChoice; }
+    void    exec()     { ok = false; QDialog::exec(); }
 
 public slots:
     void    pageChosen(int button);
@@ -32,12 +36,14 @@
     void    fillPages(QGridLayout* layout);
     void    fitBox(const Rect &box, Canvas* canvas);
 
-    std::vector<Canvas*>    canvases;
-    Document*               iDoc;
-    QDialogButtonBox*       buttonBox;
+    std::vector<Canvas*>        canvases;
+    std::vector<PageViewPair>   views;
+    Document*                   iDoc;
+    QDialogButtonBox*           buttonBox;
 
-    bool                    ok;
-    int                     pageChoice;
+    bool                        ok;
+    int                         pageChoice;
+    int                         viewChoice;
 };
 
 #endif