Switched to Ipe's own PageSelector instead of the internal PageDialog (requires Ipe 7.0.13)
authorDmitriy Morozov <dmitriy@mrzv.org>
Sat, 27 Nov 2010 09:58:18 -0800
changeset 7 a01d4a949adf
parent 6 0ffafff7682f
child 8 6e21d1f3b806
Switched to Ipe's own PageSelector instead of the internal PageDialog (requires Ipe 7.0.13)
Makefile
canvasview.cpp
mainwindow.cpp
mainwindow.h
pagedialog.cpp
pagedialog.h
--- a/Makefile	Sat Nov 27 09:56:16 2010 -0800
+++ b/Makefile	Sat Nov 27 09:58:18 2010 -0800
@@ -9,7 +9,7 @@
 DESTDIR=/usr/bin
 
 OBJECTS = mainwindow.o moc_mainwindow.o canvasview.o moc_canvasview.o \
-		  timelabel.o moc_timelabel.o pagedialog.o moc_pagedialog.o
+		  timelabel.o moc_timelabel.o 
 
 # .INTERMEDIATE: $(OBJECTS)		  
 
--- a/canvasview.cpp	Sat Nov 27 09:56:16 2010 -0800
+++ b/canvasview.cpp	Sat Nov 27 09:58:18 2010 -0800
@@ -86,7 +86,7 @@
 
     // iDoc->page(iPageNo)->setSelect(0, EPrimarySelected);
     iCanvas->setFontPool(iDoc->fontPool());
-    iCanvas->setPage(iDoc->page(iPageNo), iViewNo, iDoc->cascade());
+    iCanvas->setPage(iDoc->page(iPageNo), iPageNo, iViewNo, iDoc->cascade());
     iCanvas->setPan(Vector(300, 400));
     iCanvas->update();
 
@@ -109,7 +109,7 @@
 
 void CanvasView::setView(int pageNo, int viewNo)
 {
-    iCanvas->setPage(iDoc->page(pageNo), viewNo, iDoc->cascade());
+    iCanvas->setPage(iDoc->page(pageNo), pageNo, viewNo, iDoc->cascade());
     iCanvas->update();
 }
 
--- a/mainwindow.cpp	Sat Nov 27 09:56:16 2010 -0800
+++ b/mainwindow.cpp	Sat Nov 27 09:58:18 2010 -0800
@@ -45,7 +45,6 @@
     setupUi(this);
 
     iDoc = 0;
-    page_dialog = 0;
 
     // iFileMenu = menuBar()->addMenu(tr("&File"));
     // iFileMenu->addAction(new IpeAction(EOpen, "Open", "Ctrl+O", this));
@@ -149,19 +148,14 @@
             break;
         case EJumpTo:
         {
-            page_dialog->exec();
-            if (page_dialog->isOk())
+            int page = PageSelector::selectPageOrView(iDoc,-1,240,this->width(),this->height());
+            if (page >= 0)
             {
-                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())
+                int view = PageSelector::selectPageOrView(iDoc, page, 240, this->width(),this->height());
+                if (view >= 0)
                 {
-                    iPageNo = view_dialog.page();
-                    iViewNo = view_dialog.view();
+                    iPageNo = page;
+                    iViewNo = view;
                     setView();
                 }
             }
@@ -195,19 +189,13 @@
     currentViewCanvas->setFontPool(iDoc->fontPool());
     nextViewCanvas->setFontPool(iDoc->fontPool());
     
-    currentViewCanvas->setPage(iDoc->page(iPageNo), iViewNo, iDoc->cascade());
+    currentViewCanvas->setPage(iDoc->page(iPageNo), iPageNo, iViewNo, iDoc->cascade());
     currentViewCanvas->setPan(Vector(300, 400));
     currentViewCanvas->update();
     setNextViewCanvas();
     
     canvas_view->load(doc, iPageNo, iViewNo);
      
-    delete page_dialog;
-    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);
-    
     setView();
     return true;
 }
@@ -285,7 +273,7 @@
     std::pair<int,int> page_view = nextPageView(1);
     int iPageNo = page_view.first;
     int iViewNo = page_view.second;
-    nextViewCanvas->setPage(iDoc->page(iPageNo), iViewNo, iDoc->cascade());
+    nextViewCanvas->setPage(iDoc->page(iPageNo), iPageNo, iViewNo, iDoc->cascade());
     nextViewCanvas->update();
 }
 
@@ -329,7 +317,7 @@
 
 void MainWindow::setView()
 {
-    currentViewCanvas->setPage(iDoc->page(iPageNo), iViewNo, iDoc->cascade());
+    currentViewCanvas->setPage(iDoc->page(iPageNo), iPageNo, iViewNo, iDoc->cascade());
     currentViewCanvas->update();
     updateLabel();
 
--- a/mainwindow.h	Sat Nov 27 09:56:16 2010 -0800
+++ b/mainwindow.h	Sat Nov 27 09:58:18 2010 -0800
@@ -34,8 +34,8 @@
 #define MAINWINDOW_H
 
 #include "ipeqtcanvas.h"
+#include "ipeselector.h"
 #include "canvasview.h"
-#include "pagedialog.h"
 #include "ui_mainwindow.h"
 
 #include <QMainWindow>
@@ -101,7 +101,6 @@
         int iViewNo;
         
         CanvasView* canvas_view;
-        PageDialog* page_dialog;
 
     private slots:
         void splitterMoved(int pos, int index);
--- a/pagedialog.cpp	Sat Nov 27 09:56:16 2010 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,66 +0,0 @@
-#include <QtGui>
-
-#include "pagedialog.h"
-
-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()));
-    // connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
-
-    QGridLayout *mainLayout = new QGridLayout;
-    fillPages(mainLayout);
-    setLayout(mainLayout);
-    setWindowTitle(tr("Select page/view"));
-    ok = false;
-}
-
-void PageDialog::fillPages(QGridLayout* layout)
-{
-    for (unsigned i = 0; i < views.size(); ++i)
-    {
-        Canvas* c = new Canvas(this);
-        c->setFontPool(iDoc->fontPool());
-        Canvas::Style style = c->canvasStyle();
-        style.pretty = true;
-        c->setCanvasStyle(style);
-        c->setPage(iDoc->page(views[i].first), 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);
-    }
-}
-
-void PageDialog::fitBox(const Rect &box, Canvas* canvas)
-{
-    if (box.isEmpty())
-        return;
-    ipeDebug("canvas: %d x %d", canvas->width(), canvas->height());
-    double xfactor = box.width() > 0.0  ? (canvas->width() / box.width()) : 20.0;
-    double yfactor = box.height() > 0.0 ? (canvas->height() / box.height()) : 20.0;
-    double zoom = (xfactor > yfactor) ? yfactor : xfactor;
-    canvas->setPan(0.5 * (box.bottomLeft() + box.topRight()));
-    canvas->setZoom(zoom);
-    canvas->update();
-}
-
-void PageDialog::pageChosen(int button)
-{
-    for (unsigned i = 0; i < canvases.size(); ++i)
-        if (canvases[i] == QObject::sender())
-        {
-            ok = true;
-            pageChoice = views[i].first;
-            viewChoice = views[i].second;
-        }
-    accept();
-}
-
-void PageDialog::resizeEvent (QResizeEvent *event)
-{
-    for (unsigned i = 0; i < canvases.size(); ++i)
-    {
-        fitBox(iDoc->cascade()->findLayout()->paper(), canvases[i]);
-        canvases[i]->update();
-    }
-}
--- a/pagedialog.h	Sat Nov 27 09:56:16 2010 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-#ifndef PAGEDIALOG_H
-#define PAGEDIALOG_H
-
-#include <QDialog>
-#include <QDialogButtonBox>
-#include <QGridLayout>
-#include "ipeqtcanvas.h"
-#include <vector>
-
-using namespace ipe;
-using namespace ipeqt;
-
-
-class PageDialog : public QDialog
-{
-    Q_OBJECT
-
-public:
-    typedef std::pair<int,int>      PageViewPair;
-
-public:
-            PageDialog(Document* d, const std::vector<PageViewPair>& v);
-
-    bool    isOk()     { return ok; }
-    int     page()     { return pageChoice; }
-    int     view()     { return viewChoice; }
-    void    exec()     { ok = false; QDialog::exec(); }
-
-public slots:
-    void    pageChosen(int button);
-
-protected:
-    void    resizeEvent (QResizeEvent *event);
-
-private:
-    void    fillPages(QGridLayout* layout);
-    void    fitBox(const Rect &box, Canvas* canvas);
-
-    std::vector<Canvas*>        canvases;
-    std::vector<PageViewPair>   views;
-    Document*                   iDoc;
-    QDialogButtonBox*           buttonBox;
-
-    bool                        ok;
-    int                         pageChoice;
-    int                         viewChoice;
-};
-
-#endif