Added preserving zoom level
authorBartosz Szatkowski <bulislaw@linux.com>
Tue, 31 Aug 2010 12:46:52 +0000 (14:46 +0200)
committerBartosz Szatkowski <bulislaw@linux.com>
Tue, 31 Aug 2010 12:46:52 +0000 (14:46 +0200)
trunk/src/base/backbone/backbone.cpp
trunk/src/base/backbone/backbone.h
trunk/src/base/gui/TranslationTextEdit.cpp
trunk/src/base/gui/TranslationTextEdit.h
trunk/src/base/gui/TranslationWidget.cpp
trunk/src/base/gui/TranslationWidget.h

index d9eae98..1dff134 100644 (file)
@@ -379,6 +379,7 @@ void Backbone::loadPrefs(QString fileName) {
     _searchLimit = set.value("general/search_limit", 15).toInt();
     _searchBookmarks = set.value("general/search_bookmarks",1).toBool();
     _searchDicts = set.value("general/search_dictionaries",1).toBool();
+    _zoom = set.value("general/zoom", 1.0).toReal();
 }
 
 
@@ -391,6 +392,7 @@ void Backbone::savePrefs(QSettings *set) {
     set->setValue("general/search_limit", _searchLimit);
     set->setValue("general/search_bookmarks", _searchBookmarks);
     set->setValue("general/search_dictionaries", _searchDicts);
+    set->setValue("general/zoom", _zoom);
 }
 
 
@@ -567,6 +569,10 @@ void Backbone::setSettings(Settings *settings) {
         _searchBookmarks = 1;
     else
         _searchBookmarks = 0;
+    _zoom = settings->value("zoom").toFloat();
+    if(!_zoom)
+        _zoom ++;
+
     dictUpdated();
     if(settings)
         delete settings;
@@ -579,6 +585,7 @@ Settings* Backbone::settings() {
     Settings * settings = new Settings();
     settings->setValue("history_size", QString("%1").arg(_historyLen));
     settings->setValue("search_limit", QString("%1").arg(_searchLimit));
+    settings->setValue("zoom", QString("%1").arg(_zoom));
     if(_searchBookmarks)
         settings->setValue("search_bookmarks", "true");
     else
index 55b3ebb..623dd98 100644 (file)
@@ -307,6 +307,7 @@ private:
     QString _configPath;
     QString _dir;
     int _historyLen;
+    qreal _zoom;
 
     bool dryRun; // mainly for testing - when true then doesn't bother configs etc
     bool stopped; // true when user stops searching/fetching
index d6b7d7a..16160bc 100644 (file)
 
 #include <QtGui>
 #include "TranslationTextEdit.h"
+#include "TranslationWidget.h"
 
 TranslationTextEdit::TranslationTextEdit(QWidget *parent) :
     QWebView(parent)
 {
+    realParent = qobject_cast<TranslationWidget*>(parent);
     searchSelectedAction = new QAction(tr("Search"), this);
     copySelectedAction = new QAction(tr("Copy"), this);
     selectAllAction = new QAction(tr("Select All"), this);
@@ -57,10 +59,13 @@ void TranslationTextEdit::contextMenuEvent(QContextMenuEvent *e) {
 
 void TranslationTextEdit::zoomIn() {
     setZoomFactor(zoomFactor()*1.05);
+    realParent->updateZoom(zoomFactor());
+
 }
 
 void TranslationTextEdit::zoomOut() {
     setZoomFactor(zoomFactor()*0.95);
+    realParent->updateZoom(zoomFactor());
 }
 
 void TranslationTextEdit::copy() {
index 1c9adff..df47d30 100644 (file)
@@ -27,6 +27,7 @@
 #include <QTextEdit>
 #include <QAction>
 #include <QWebView>
+class TranslationWidget;
 
 class TranslationTextEdit : public QWebView
 {
@@ -52,6 +53,7 @@ private:
     QAction* searchSelectedAction;
     QAction* copySelectedAction;
     QAction* selectAllAction;
+    TranslationWidget* realParent;
 
 };
 
index 3cfc892..b8f1bfd 100644 (file)
@@ -30,7 +30,9 @@
 #endif
 
 TranslationWidget::TranslationWidget(QWidget *parent):
-    QScrollArea(parent) {
+        QScrollArea(parent){
+
+    guiinterface = qobject_cast<GUIInterface*>(parent);
 
     #ifdef Q_WS_MAEMO_5
         setAttribute(Qt::WA_Maemo5StackedWindow);
@@ -199,6 +201,11 @@ void TranslationWidget::initButtons() {
 void TranslationWidget::initializeUI() {
 
     webkit = new TranslationTextEdit(this);
+    Settings* set = guiinterface->settings();
+    qreal fac = set->value("zoom").toFloat();
+    if(!fac)
+        fac++;
+    webkit->setZoomFactor(fac);
 
     QWidget*w = new QWidget(this);
     verticalLayout = new QVBoxLayout(w);
@@ -334,4 +341,11 @@ void TranslationWidget::keyPressEvent(QKeyEvent* event) {
 #endif
 
 
+void TranslationWidget::updateZoom(qreal factor) {
+    Settings* set = guiinterface->settings();
+    set->setValue("zoom", QString("%1").arg(factor));
+    guiinterface->setSettings(set);
+}
+
+
 
index 92139d8..055aaad 100644 (file)
@@ -33,6 +33,7 @@
 #include <QXmlQuery>
 #include "TranslationTextEdit.h"
 #include <QPropertyAnimation>
+#include "../../includes/GUIInterface.h"
 
 //! Displays translation of word found in dictionaries
 /*!
@@ -55,6 +56,9 @@ public Q_SLOTS:
     //! Requests to show translation of word list passed as parameter.
     void show(QStringList);
 
+    //! Updates users zoom preferences and sends its to backbone to be saved
+    void updateZoom(qreal);
+
 protected:
     #ifdef Q_WS_MAEMO_5
         void keyPressEvent(QKeyEvent *);
@@ -96,6 +100,7 @@ private:
     #endif
     QVBoxLayout *verticalLayout;
     QHBoxLayout* horizontalLayout;
+    GUIInterface* guiinterface;
 
     void initializeUI();
 };