Added direct search of translation, changed searching for translation of words list...
[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(Backbone *backbone, QWidget *parent):
29     QScrollArea(parent) {
30
31     this->backbone = backbone;
32
33     #ifdef Q_WS_MAEMO_5
34         setAttribute(Qt::WA_Maemo5StackedWindow);
35     #endif
36     setWindowFlags(windowFlags() | Qt::Window);
37
38     initializeUI();
39
40     connect(backbone, SIGNAL(htmlReady()),
41             this, SLOT(show()));
42
43     setWindowTitle(tr("Translation"));
44 }
45
46 void TranslationWidget::show() {
47     QScrollArea::show();
48
49     textEdit->clear();
50
51     QStringList translations = backbone->htmls();
52
53     QString trans;
54     QString t;
55     foreach(t, translations) {
56         trans += t + "\n";
57     }
58
59     textEdit->setPlainText(trans);
60
61     textEdit->repaint(this->rect());
62
63     update(this->rect());
64
65     emit updateSize();
66 }
67
68 void TranslationWidget::initializeUI() {
69
70     zoomInToolButton = new QToolButton;
71     zoomInToolButton->setIcon(QIcon::fromTheme("pdf_zoomin"));
72
73     zoomOutToolButton = new QToolButton;
74     zoomOutToolButton->setIcon(QIcon::fromTheme("pdf_zoomout"));
75
76     horizontalLayout = new QHBoxLayout;
77     horizontalLayout->addWidget(zoomInToolButton);
78     horizontalLayout->addWidget(zoomOutToolButton);
79
80     textEdit = new QTextEdit;
81     textEdit->setReadOnly(true);
82
83     resizer = new TranslationWidgetAutoResizer(textEdit);
84     connect(this, SIGNAL(updateSize()),
85             resizer, SLOT(textEditChanged()));
86
87     QWidget*w = new QWidget;
88     verticalLayout = new QVBoxLayout(w);
89     verticalLayout->addLayout(horizontalLayout);
90     verticalLayout->addWidget(textEdit);
91
92     this->setWidget(w);
93     this->setWidgetResizable(true);
94
95     connect(zoomInToolButton, SIGNAL(clicked()),
96             textEdit, SLOT(zoomIn()));
97
98     connect(zoomInToolButton, SIGNAL(clicked()),
99             this, SIGNAL(updateSize()));
100
101     connect(zoomOutToolButton, SIGNAL(clicked()),
102             textEdit, SLOT(zoomOut()));
103
104     connect(zoomInToolButton, SIGNAL(clicked()),
105             this, SIGNAL(updateSize()));
106
107 }
108
109 void TranslationWidget::showContextMenu(QPoint pos) {
110     contextMenu->exec(pos);
111 }
112