Added settings widget
[mdictionary] / trunk / src / base / gui / TranslationWidget.cpp
1 /*******************************************************************************
2
3     This file is part of mDictionary.
4
5     mDictionary is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9
10     mDictionary is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
17
18     Copyright 2010 Comarch S.A.
19
20 *******************************************************************************/
21
22 //Created by Mateusz Półrola
23
24 #include "TranslationWidget.h"
25 #include "TranslationWidgetAutoResizer.h"
26 #include <QDebug>
27
28 TranslationWidget::TranslationWidget(QWidget *parent):
29     QScrollArea(parent) {
30
31     #ifdef Q_WS_MAEMO_5
32         setAttribute(Qt::WA_Maemo5StackedWindow);
33     #endif
34     setWindowFlags(windowFlags() | Qt::Window);
35
36     initializeUI();
37
38     setWindowTitle(tr("Translation"));
39 }
40
41
42 void TranslationWidget::show() {
43     QScrollArea::show();
44 }
45
46 void TranslationWidget::show(QStringList translations) {
47
48     show();
49
50     textEdit->clear();
51
52     QString trans;
53     QString t;
54     foreach(t, translations) {
55         trans += t + "\n";
56     }
57
58     textEdit->setPlainText(trans);
59
60     textEdit->repaint(this->rect());
61
62     update(this->rect());
63
64     emit updateSize();
65 }
66
67 void TranslationWidget::initializeUI() {
68
69     zoomInToolButton = new QToolButton;
70     zoomInToolButton->setIcon(QIcon::fromTheme("pdf_zoomin"));
71
72     zoomOutToolButton = new QToolButton;
73     zoomOutToolButton->setIcon(QIcon::fromTheme("pdf_zoomout"));
74
75    // horizontalLayout = new QHBoxLayout;
76     //horizontalLayout->addWidget(zoomInToolButton);
77    // horizontalLayout->addWidget(zoomOutToolButton);
78
79     textEdit = new QTextEdit;
80     textEdit->setReadOnly(true);
81
82     resizer = new TranslationWidgetAutoResizer(textEdit);
83     connect(this, SIGNAL(updateSize()),
84             resizer, SLOT(textEditChanged()));
85
86     QWidget*w = new QWidget;
87     verticalLayout = new QVBoxLayout(w);
88     verticalLayout->addWidget(textEdit);
89
90     textEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
91     textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
92
93
94     this->setWidget(w);
95     this->setWidgetResizable(true);
96
97     connect(zoomInToolButton, SIGNAL(clicked()),
98             textEdit, SLOT(zoomIn()));
99
100     connect(zoomInToolButton, SIGNAL(clicked()),
101             this, SIGNAL(updateSize()));
102
103     connect(zoomOutToolButton, SIGNAL(clicked()),
104             textEdit, SLOT(zoomOut()));
105
106     connect(zoomInToolButton, SIGNAL(clicked()),
107             this, SIGNAL(updateSize()));
108
109    /* #ifdef Q_WS_MAEMO_5
110         fullScreenButton = new QToolButton(this);
111         fullScreenButton->setIcon(QIcon::fromTheme("general_fullsize"));
112         fullScreenButton->setMinimumSize(fullScreenButton->sizeHint());
113         int x = QApplication::desktop()->screenGeometry(this).width()  -
114                 fullScreenButton->sizeHint().width();
115         int y = QApplication::desktop()->screenGeometry(this).height() -
116                 fullScreenButton->sizeHint().height();
117         fullScreenButton->move(QPoint(x,y));
118         fullScreenButton->show();
119         fullScreenButton->setWindowOpacity(0.5);
120
121
122         backButton = new QToolButton(this);
123         backButton->setIcon(QIcon::fromTheme("general_overlay_back"));
124         backButton->setMinimumSize(fullScreenButton->sizeHint());
125         x = QApplication::desktop()->screenGeometry(this).width()  -
126                 backButton->sizeHint().width();
127         y = 0;
128         backButton->move(QPoint(x,y));
129         backButton->show();
130         backButton->setWindowOpacity(0.5);
131
132         connect(backButton, SIGNAL(clicked()),
133                 this, SLOT(hide()));
134     #endif*/
135 }
136