7befd4c8b7a0be7eb15e6d58efcb2894e8966637
[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->addLayout(horizontalLayout);
89     verticalLayout->addWidget(textEdit);
90
91     this->setWidget(w);
92     this->setWidgetResizable(true);
93
94     connect(zoomInToolButton, SIGNAL(clicked()),
95             textEdit, SLOT(zoomIn()));
96
97     connect(zoomInToolButton, SIGNAL(clicked()),
98             this, SIGNAL(updateSize()));
99
100     connect(zoomOutToolButton, SIGNAL(clicked()),
101             textEdit, SLOT(zoomOut()));
102
103     connect(zoomInToolButton, SIGNAL(clicked()),
104             this, SIGNAL(updateSize()));
105
106    /* #ifdef Q_WS_MAEMO_5
107         fullScreenButton = new QToolButton(this);
108         fullScreenButton->setIcon(QIcon::fromTheme("general_fullsize"));
109         fullScreenButton->setMinimumSize(fullScreenButton->sizeHint());
110         int x = QApplication::desktop()->screenGeometry(this).width()  -
111                 fullScreenButton->sizeHint().width();
112         int y = QApplication::desktop()->screenGeometry(this).height() -
113                 fullScreenButton->sizeHint().height();
114         fullScreenButton->move(QPoint(x,y));
115         fullScreenButton->show();
116         fullScreenButton->setWindowOpacity(0.5);
117
118
119         backButton = new QToolButton(this);
120         backButton->setIcon(QIcon::fromTheme("general_overlay_back"));
121         backButton->setMinimumSize(fullScreenButton->sizeHint());
122         x = QApplication::desktop()->screenGeometry(this).width()  -
123                 backButton->sizeHint().width();
124         y = 0;
125         backButton->move(QPoint(x,y));
126         backButton->show();
127         backButton->setWindowOpacity(0.5);
128
129         connect(backButton, SIGNAL(clicked()),
130                 this, SLOT(hide()));
131     #endif*/
132 }
133