22c55c00cebfc029d0ba6fac709636f9436e1f40
[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     show();
48
49     textEdit->clear();
50
51     QString trans;
52     QString t;
53     foreach(t, translations) {
54         trans += t + "\n";
55     }
56
57     textEdit->setPlainText(trans);
58
59     textEdit->repaint(this->rect());
60
61     update(this->rect());
62
63     emit updateSize();
64 }
65
66 void TranslationWidget::initializeUI() {
67
68     zoomInToolButton = new QToolButton;
69     zoomInToolButton->setIcon(QIcon::fromTheme("pdf_zoomin"));
70
71     zoomOutToolButton = new QToolButton;
72     zoomOutToolButton->setIcon(QIcon::fromTheme("pdf_zoomout"));
73
74    // horizontalLayout = new QHBoxLayout;
75     //horizontalLayout->addWidget(zoomInToolButton);
76    // horizontalLayout->addWidget(zoomOutToolButton);
77
78     textEdit = new QTextEdit;
79     textEdit->setReadOnly(true);
80
81     resizer = new TranslationWidgetAutoResizer(textEdit);
82     connect(this, SIGNAL(updateSize()),
83             resizer, SLOT(textEditChanged()));
84
85     QWidget*w = new QWidget;
86     verticalLayout = new QVBoxLayout(w);
87     //verticalLayout->addLayout(horizontalLayout);
88     verticalLayout->addWidget(textEdit);
89
90     this->setWidget(w);
91     this->setWidgetResizable(true);
92
93     connect(zoomInToolButton, SIGNAL(clicked()),
94             textEdit, SLOT(zoomIn()));
95
96     connect(zoomInToolButton, SIGNAL(clicked()),
97             this, SIGNAL(updateSize()));
98
99     connect(zoomOutToolButton, SIGNAL(clicked()),
100             textEdit, SLOT(zoomOut()));
101
102     connect(zoomInToolButton, SIGNAL(clicked()),
103             this, SIGNAL(updateSize()));
104
105 }
106