Added settings widget
[mdictionary] / trunk / src / base / gui / TranslationWidget.cpp
index 51a8547..04c7565 100644 (file)
 //Created by Mateusz Półrola
 
 #include "TranslationWidget.h"
+#include "TranslationWidgetAutoResizer.h"
 #include <QDebug>
 
-TranslationWidget::TranslationWidget(Backbone *backbone, QWidget *parent):
-    QWidget(parent) {
-
-    this->backbone = backbone;
-
+TranslationWidget::TranslationWidget(QWidget *parent):
+    QScrollArea(parent) {
 
     #ifdef Q_WS_MAEMO_5
         setAttribute(Qt::WA_Maemo5StackedWindow);
@@ -37,48 +35,102 @@ TranslationWidget::TranslationWidget(Backbone *backbone, QWidget *parent):
 
     initializeUI();
 
-    connect(textEdit, SIGNAL(customContextMenuRequested(QPoint)),
-            this, SLOT(showContextMenu(QPoint)));
-
-
+    setWindowTitle(tr("Translation"));
 }
 
 
 void TranslationWidget::show() {
-    QWidget::show();
+    QScrollArea::show();
 }
 
-void TranslationWidget::show(QModelIndex index) {
+void TranslationWidget::show(QStringList translations) {
 
     show();
-    QString v = index.model()->data(index, Qt::DisplayRole).toString();
-    Translation* t = backbone->result().value(v);
 
     textEdit->clear();
 
-    textEdit->setPlainText(t->toHtml());
+    QString trans;
+    QString t;
+    foreach(t, translations) {
+        trans += t + "\n";
+    }
+
+    textEdit->setPlainText(trans);
 
     textEdit->repaint(this->rect());
 
+    update(this->rect());
+
+    emit updateSize();
 }
 
 void TranslationWidget::initializeUI() {
-    contextMenu = new QMenu;
 
-    contextMenu->addAction(tr("Copy"), this, SLOT(copy()));
-    contextMenu->addAction(tr("Paste"), this, SLOT(paste()));
-    contextMenu->addAction(tr("Select all"), this, SLOT(selectAll()));
+    zoomInToolButton = new QToolButton;
+    zoomInToolButton->setIcon(QIcon::fromTheme("pdf_zoomin"));
+
+    zoomOutToolButton = new QToolButton;
+    zoomOutToolButton->setIcon(QIcon::fromTheme("pdf_zoomout"));
+
+   // horizontalLayout = new QHBoxLayout;
+    //horizontalLayout->addWidget(zoomInToolButton);
+   // horizontalLayout->addWidget(zoomOutToolButton);
 
     textEdit = new QTextEdit;
     textEdit->setReadOnly(true);
-    textEdit->setContextMenuPolicy(Qt::CustomContextMenu);
 
-    verticalLayout = new QVBoxLayout;
-    setLayout(verticalLayout);
+    resizer = new TranslationWidgetAutoResizer(textEdit);
+    connect(this, SIGNAL(updateSize()),
+            resizer, SLOT(textEditChanged()));
+
+    QWidget*w = new QWidget;
+    verticalLayout = new QVBoxLayout(w);
     verticalLayout->addWidget(textEdit);
-}
 
-void TranslationWidget::showContextMenu(QPoint pos) {
-    contextMenu->exec(pos);
+    textEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+
+    this->setWidget(w);
+    this->setWidgetResizable(true);
+
+    connect(zoomInToolButton, SIGNAL(clicked()),
+            textEdit, SLOT(zoomIn()));
+
+    connect(zoomInToolButton, SIGNAL(clicked()),
+            this, SIGNAL(updateSize()));
+
+    connect(zoomOutToolButton, SIGNAL(clicked()),
+            textEdit, SLOT(zoomOut()));
+
+    connect(zoomInToolButton, SIGNAL(clicked()),
+            this, SIGNAL(updateSize()));
+
+   /* #ifdef Q_WS_MAEMO_5
+        fullScreenButton = new QToolButton(this);
+        fullScreenButton->setIcon(QIcon::fromTheme("general_fullsize"));
+        fullScreenButton->setMinimumSize(fullScreenButton->sizeHint());
+        int x = QApplication::desktop()->screenGeometry(this).width()  -
+                fullScreenButton->sizeHint().width();
+        int y = QApplication::desktop()->screenGeometry(this).height() -
+                fullScreenButton->sizeHint().height();
+        fullScreenButton->move(QPoint(x,y));
+        fullScreenButton->show();
+        fullScreenButton->setWindowOpacity(0.5);
+
+
+        backButton = new QToolButton(this);
+        backButton->setIcon(QIcon::fromTheme("general_overlay_back"));
+        backButton->setMinimumSize(fullScreenButton->sizeHint());
+        x = QApplication::desktop()->screenGeometry(this).width()  -
+                backButton->sizeHint().width();
+        y = 0;
+        backButton->move(QPoint(x,y));
+        backButton->show();
+        backButton->setWindowOpacity(0.5);
+
+        connect(backButton, SIGNAL(clicked()),
+                this, SLOT(hide()));
+    #endif*/
 }