[kde-doc-english] [calligra] /: Store zoom config in Calligra Stage

Paul Mendez paulestebanms at gmail.com
Mon May 16 18:06:43 CEST 2011


Git commit 76d298d048bd7f519c4c022489151793650e8e7a by Paul Mendez.
Committed on 16/05/2011 at 17:49.
Pushed by mendez into branch 'master'.

Store zoom config in Calligra Stage

Calligra Stage now store zoom config between sessions. SlidesSorter view
mode stores a separate zoom value.
Some zoom options was removed in slides sorter, because they haven't meaning
in that view.
REVIEW: 101129
GUI: Remove not applicable zoom options from slides sorter view in Stage

M  +59   -0    kpresenter/part/KPrView.cpp     
M  +41   -2    kpresenter/part/KPrView.h     
M  +64   -9    kpresenter/part/KPrViewModeSlidesSorter.cpp     
M  +27   -2    kpresenter/part/KPrViewModeSlidesSorter.h     
M  +14   -0    libs/kopageapp/KoPAView.cpp     
M  +2    -0    libs/kopageapp/KoPAView.h     

http://commits.kde.org/calligra/76d298d048bd7f519c4c022489151793650e8e7a

diff --git a/kpresenter/part/KPrView.cpp b/kpresenter/part/KPrView.cpp
index 0ba563a..04d502d 100644
--- a/kpresenter/part/KPrView.cpp
+++ b/kpresenter/part/KPrView.cpp
@@ -38,6 +38,7 @@
 #include <KoDocumentInfo.h>
 #include <KoShapeRegistry.h>
 #include <KoShapeLayer.h>
+#include <KoZoomController.h>
 
 #include "KPrDocument.h"
 #include "KPrPage.h"
@@ -50,6 +51,7 @@
 #include "KPrShapeManagerDisplayMasterStrategy.h"
 #include "KPrPageSelectStrategyActive.h"
 #include "KPrPicturesImport.h"
+#include "KPrFactory.h"
 #include "commands/KPrAnimationCreateCommand.h"
 #include "commands/KPrSetCustomSlideShowsCommand.h"
 #include "dockers/KPrPageLayoutDockerFactory.h"
@@ -101,10 +103,12 @@ KPrView::KPrView( KPrDocument *document, QWidget *parent )
     if (canvas) {
         m_slidesSorterMode = new KPrViewModeSlidesSorter(this, canvas);
     }
+    connect(zoomController(), SIGNAL(zoomChanged(KoZoomMode::Mode,qreal)), this, SLOT(zoomChanged(KoZoomMode::Mode,qreal)));
 }
 
 KPrView::~KPrView()
 {
+    saveZoomConfig(zoomMode(), zoom());
     delete m_presentationMode;
     delete m_notesMode;
     delete m_slidesSorterMode;
@@ -180,6 +184,7 @@ void KPrView::initGUI()
     if ( !group.hasKey( "State" ) ) {
         group.writeEntry( "State", state );
     }
+    initZoomConfig();
 }
 
 void KPrView::initActions()
@@ -433,4 +438,58 @@ void KPrView::insertPictures()
     pictureImport.import(this);
 }
 
+void KPrView::initZoomConfig()
+{
+    KSharedConfigPtr config = KPrFactory::componentData().config();
+    int m_zoom = 100;
+    KoZoomMode::Mode m_zoomMode = KoZoomMode::ZOOM_PAGE;
+
+    if (config->hasGroup("Interface")) {
+        const KConfigGroup interface = config->group("Interface");
+        m_zoom = interface.readEntry("Zoom", m_zoom);
+        m_zoomMode = static_cast<KoZoomMode::Mode>(interface.readEntry("ZoomMode", (int) m_zoomMode));
+    }
+    zoomController()->setZoom(m_zoomMode, m_zoom/100.);
+    setZoom(m_zoomMode, m_zoom);
+    centerPage();
+}
+
+void KPrView::zoomChanged(KoZoomMode::Mode mode, qreal zoom)
+{
+    setZoom(mode, qRound(zoom * 100.));
+}
+
+void KPrView::saveZoomConfig(KoZoomMode::Mode mode, int zoom)
+{
+    KSharedConfigPtr config = KPrFactory::componentData().config();
+
+    if (config->hasGroup("Interface")) {
+        KConfigGroup interface = config->group("Interface");
+        interface.writeEntry("Zoom", zoom);
+        interface.writeEntry("ZoomMode", (int)mode);
+    }
+}
+
+void KPrView::setZoom(KoZoomMode::Mode zoomMode, int zoom)
+{
+    m_zoom = zoom;
+    m_zoomMode = zoomMode;
+}
+
+int KPrView::zoom()
+{
+    return m_zoom;
+}
+
+KoZoomMode::Mode KPrView::zoomMode()
+{
+    return m_zoomMode;
+}
+
+void KPrView::restoreZoomConfig()
+{
+    zoomController()->setZoom(zoomMode(), zoom()/100.);
+    centerPage();
+}
+
 #include "KPrView.moc"
diff --git a/kpresenter/part/KPrView.h b/kpresenter/part/KPrView.h
index 80b6752..a558a2e 100644
--- a/kpresenter/part/KPrView.h
+++ b/kpresenter/part/KPrView.h
@@ -22,9 +22,7 @@
 #define KPRVIEW_H
 
 #include "stage_export.h"
-
 #include <QObject>
-
 #include <KoPAView.h>
 
 class KPrDocument;
@@ -66,6 +64,43 @@ public:
      */
     bool isPresentationRunning() const;
 
+    /**
+      * Load zoom configuration
+      */
+    void initZoomConfig();
+
+    /**
+      * Restore zoom configuration
+      */
+    void restoreZoomConfig();
+
+    /**
+      * Save zoom value
+      */
+    void saveZoomConfig(KoZoomMode::Mode zoomMode, int zoom);
+
+    /**
+     * Setter of the zoom
+     *
+     * @param zoom percent
+     * @param zoom mode
+     */
+    void setZoom(KoZoomMode::Mode zoomMode, int zoom);
+
+    /**
+     * Return the last zoom stored
+     *
+     * @return the last zoom stored
+     */
+    int zoom();
+
+    /**
+     * Return the last zoom mode stored
+     *
+     * @return the last zoom mode stored
+     */
+    KoZoomMode::Mode zoomMode();
+
 public slots:
     /**
      * Activate the presentation view mode
@@ -101,6 +136,8 @@ protected slots:
     void highlightPresentation();
     void blackPresentation();
     void showStatusBar(bool toggled);
+    /// called if the zoom changed
+    void zoomChanged(KoZoomMode::Mode mode, qreal zoom);
 
 private:
     KActionMenu *m_actionStartPresentation;
@@ -121,6 +158,8 @@ private:
     KPrViewModeSlidesSorter *m_slidesSorterMode;
 
     KPrViewAdaptor *m_dbus;
+    int m_zoom;
+    KoZoomMode::Mode m_zoomMode;
 
     virtual KoPrintJob *createPdfPrintJob();
 };
diff --git a/kpresenter/part/KPrViewModeSlidesSorter.cpp b/kpresenter/part/KPrViewModeSlidesSorter.cpp
index b4fee3c..b71c1b9 100644
--- a/kpresenter/part/KPrViewModeSlidesSorter.cpp
+++ b/kpresenter/part/KPrViewModeSlidesSorter.cpp
@@ -28,6 +28,7 @@
 #include <QtCore/qmath.h>
 
 #include "KPrSlidesSorterDocumentModel.h"
+#include "KPrFactory.h"
 #include <KoResourceManager.h>
 #include <KoRuler.h>
 #include <KoSelection.h>
@@ -51,6 +52,7 @@
 
 #include <klocale.h>
 #include <KDebug>
+#include <kconfiggroup.h>
 
 KPrViewModeSlidesSorter::KPrViewModeSlidesSorter(KoPAView *view, KoPACanvas *canvas)
     : KoPAViewMode( view, canvas )
@@ -73,6 +75,8 @@ KPrViewModeSlidesSorter::KPrSlidesSorter::~KPrSlidesSorter()
 
 KPrViewModeSlidesSorter::~KPrViewModeSlidesSorter()
 {
+    //save zoom value
+    saveZoomConfig(zoom());
 }
 
 void KPrViewModeSlidesSorter::paint(KoPACanvasBase* /*canvas*/, QPainter& /*painter*/, const QRectF &/*paintRect*/)
@@ -219,10 +223,20 @@ void KPrViewModeSlidesSorter::activate(KoPAViewMode *previousViewMode)
 
     connect(m_slidesSorter, SIGNAL(pressed(QModelIndex)), this, SLOT(itemClicked(const QModelIndex)));
     connect(this, SIGNAL(pageChanged(KoPAPageBase*)), m_view->proxyObject, SLOT(updateActivePage(KoPAPageBase*)));
-    connect(m_view->proxyObject, SIGNAL(activePageChanged()), this, SLOT(updatePageAdded()));
+    connect(m_view->proxyObject, SIGNAL(activePageChanged()), this, SLOT(updateToActivePageIndex()));
     connect(m_view->kopaDocument(),SIGNAL(pageAdded(KoPAPageBase*)),this, SLOT(updateModel()));
     connect(m_view->kopaDocument(),SIGNAL(pageRemoved(KoPAPageBase*)),this, SLOT(updateModel()));
-    connect(m_view->zoomController(), SIGNAL(zoomChanged(KoZoomMode::Mode,qreal)), this, SLOT(updateZoom(KoZoomMode::Mode,qreal)));
+
+    //change zoom saving slot
+    connect(m_view->zoomController(), SIGNAL(zoomChanged(KoZoomMode::Mode, qreal)), this, SLOT(updateZoom(KoZoomMode::Mode, qreal)));
+
+    KPrView *kPrview = dynamic_cast<KPrView *>(m_view);
+    if (kPrview) {
+        disconnect(kPrview->zoomController(), SIGNAL(zoomChanged(KoZoomMode::Mode, qreal)), kPrview, SLOT(zoomChanged(KoZoomMode::Mode, qreal)));
+        m_view->zoomController()->zoomAction()->setZoomModes(KoZoomMode::ZOOM_CONSTANT);
+        loadZoomConfig();
+    }
+
 }
 
 void KPrViewModeSlidesSorter::deactivate()
@@ -237,20 +251,30 @@ void KPrViewModeSlidesSorter::deactivate()
     if (view) {
         view->show();
     }
+
+    //save zoom value
+    saveZoomConfig(zoom());
+
+    //change zoom saving slot and restore normal view zoom values
+    disconnect(m_view->zoomController(), SIGNAL(zoomChanged(KoZoomMode::Mode, qreal)), this, SLOT(updateZoom(KoZoomMode::Mode, qreal)));
+
+    m_view->zoomController()->zoomAction()->setZoomModes(KoZoomMode::ZOOM_PAGE | KoZoomMode::ZOOM_WIDTH);
+
     m_view->setActivePage(m_view->kopaDocument()->pageByIndex(m_slidesSorter->currentIndex().row(), false));
+
+    KPrView *kPrview = dynamic_cast<KPrView *>(m_view);
+    if (kPrview) {
+        kPrview->restoreZoomConfig();
+        connect(kPrview->zoomController(), SIGNAL(zoomChanged(KoZoomMode::Mode, qreal)), kPrview, SLOT(zoomChanged(KoZoomMode::Mode, qreal)));
+    }
+
+
 }
 void KPrViewModeSlidesSorter::updateModel()
 {
     m_documentModel->update();
     updateToActivePageIndex();
 }
-void KPrViewModeSlidesSorter::updatePageAdded()
-{
-    m_documentModel->update();
-    int row = m_view->kopaDocument()->pageIndex(m_view->activePage());
-    QModelIndex index = m_documentModel->index(row, 0);
-    m_slidesSorter->setCurrentIndex(index);
-}
 
 void KPrViewModeSlidesSorter::updateActivePage( KoPAPageBase *page )
 {
@@ -536,6 +560,8 @@ void KPrViewModeSlidesSorter::updateZoom(KoZoomMode::Mode mode, qreal zoom)
     //update item size
     QModelIndex item = m_documentModel->index(0,0);
     setItemSize(m_slidesSorter->visualRect(item));
+
+    setZoom(qRound(zoom * 100.));
 }
 
 void KPrViewModeSlidesSorter::setIconSize(QSize size)
@@ -545,3 +571,32 @@ void KPrViewModeSlidesSorter::setIconSize(QSize size)
     }
 
 }
+
+void KPrViewModeSlidesSorter::loadZoomConfig()
+{
+    KSharedConfigPtr config = KPrFactory::componentData().config();
+    int s_zoom = 100;
+
+    if (config->hasGroup("Interface")) {
+        const KConfigGroup interface = config->group("Interface");
+        s_zoom = interface.readEntry("ZoomSlidesSorter", s_zoom);
+    }
+    m_view->zoomController()->setZoom(KoZoomMode::ZOOM_CONSTANT, s_zoom/100.);
+}
+
+void KPrViewModeSlidesSorter::saveZoomConfig(int zoom)
+{
+    KSharedConfigPtr config = KPrFactory::componentData().config();
+    KConfigGroup interface = config->group("Interface");
+    interface.writeEntry("ZoomSlidesSorter", zoom);
+}
+
+void KPrViewModeSlidesSorter::setZoom(int zoom)
+{
+    m_zoom = zoom;
+}
+
+int KPrViewModeSlidesSorter::zoom()
+{
+    return m_zoom;
+}
diff --git a/kpresenter/part/KPrViewModeSlidesSorter.h b/kpresenter/part/KPrViewModeSlidesSorter.h
index ec5f669..917bd37 100644
--- a/kpresenter/part/KPrViewModeSlidesSorter.h
+++ b/kpresenter/part/KPrViewModeSlidesSorter.h
@@ -53,7 +53,6 @@ public:
     void updateActivePage( KoPAPageBase *page );
     void updateDocumentModel();
     void activateNormalViewMode();
-    void updateToActivePageIndex();
 
     void addShape( KoShape *shape );
     void removeShape( KoShape *shape );
@@ -138,6 +137,31 @@ protected:
     void setIconSize(QSize size);
 
     /**
+     * load the last zoom value used
+     */
+    void loadZoomConfig();
+
+    /**
+     * Setter of the zoom value
+     *
+     * @param zoom percent
+     */
+    void setZoom(int zoom);
+
+    /**
+     * Return the last zoom stored
+     *
+     * @return the last zoom stored
+     */
+    int zoom();
+
+    /**
+      * save zoom value
+      */
+    void saveZoomConfig(int zoom);
+
+
+    /**
      * This class manage the QListWidget itself.
      * Use all the getters and setters of the KPrViewModeSlidesSorter.
      * Most of the functions are Qt overrides to have the wished comportment.
@@ -190,11 +214,11 @@ private:
     const int m_pageCount;
     bool m_dragingFlag;
     int m_lastItemNumber;
+    int m_zoom;
 
 private slots:
     void updateDocumentDock();
     void updateModel();
-    void updatePageAdded();
     void itemClicked(const QModelIndex);
     void deleteSlide();
     void addSlide();
@@ -202,6 +226,7 @@ private slots:
     void editCopy();
     void editPaste();
     void updateZoom(KoZoomMode::Mode mode, qreal zoom);
+    void updateToActivePageIndex();
 
 signals:
     void pageChanged(KoPAPageBase *page);
diff --git a/libs/kopageapp/KoPAView.cpp b/libs/kopageapp/KoPAView.cpp
index c53edec..141e46c 100644
--- a/libs/kopageapp/KoPAView.cpp
+++ b/libs/kopageapp/KoPAView.cpp
@@ -1068,4 +1068,18 @@ bool KoPAView::isMasterUsed( KoPAPageBase * page )
     return used;
 }
 
+void KoPAView::centerPage()
+{
+    KoPageLayout &layout = d->activePage->pageLayout();
+    QSizeF pageSize( layout.width, layout.height );
+
+    QPoint documentCenter =
+        zoomHandler()->documentToView(QPoint(pageSize.width(),
+                                              pageSize.height())).toPoint();
+
+    d->canvasController->setPreferredCenter(documentCenter);
+    d->canvasController->recenterPreferred();
+
+}
+
 #include <KoPAView.moc>
diff --git a/libs/kopageapp/KoPAView.h b/libs/kopageapp/KoPAView.h
index 5585364..f5dd5fb 100644
--- a/libs/kopageapp/KoPAView.h
+++ b/libs/kopageapp/KoPAView.h
@@ -150,6 +150,8 @@ public:
     /// Insert a new page after the current one
     void insertPage();
 
+    void centerPage();
+
 protected:
 
     /// creates the widgets (called from the constructor)


More information about the kde-doc-english mailing list