1 /*******************************************************************************
3 This file is part of mDictionary.
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.
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.
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/>.
18 Copyright 2010 Comarch S.A.
20 *******************************************************************************/
22 //Created by Mateusz Półrola
24 #include "TranslationWidget.h"
25 #include "TranslationWidgetAutoResizer.h"
28 TranslationWidget::TranslationWidget(QWidget *parent):
32 setAttribute(Qt::WA_Maemo5StackedWindow);
34 setWindowFlags(windowFlags() | Qt::Window);
37 //Q_INIT_RESOURCE(xslt);
38 setWindowTitle(tr("Translation"));
42 void TranslationWidget::show() {
46 void TranslationWidget::show(QStringList translations) {
54 foreach(t, translations) {
59 trans=tr("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>") + tr("\n <ar>") + trans + tr("\n </ar>");
61 trans=XslConversion(trans);
62 textEdit->insertHtml(trans);
63 // textEdit->setPlainText(trans);
65 textEdit->repaint(this->rect());
72 QString TranslationWidget::XslConversion(QString translation)
74 QXmlQuery myQuery(QXmlQuery::XSLT20);
75 myQuery.setFocus(translation);
76 // qDebug()<<translation;
77 QFile file(":/xsl/xsl.xsl");
78 if(!file.open(QFile::ReadOnly)){
79 qDebug()<<"can't open a xslt file";
84 myQuery.setQuery(xslt);
86 myQuery.evaluateTo(&result);
90 void TranslationWidget::initializeUI() {
92 zoomInToolButton = new QToolButton;
93 zoomInToolButton->setIcon(QIcon::fromTheme("pdf_zoomin"));
95 zoomOutToolButton = new QToolButton;
96 zoomOutToolButton->setIcon(QIcon::fromTheme("pdf_zoomout"));
98 // horizontalLayout = new QHBoxLayout;
99 //horizontalLayout->addWidget(zoomInToolButton);
100 // horizontalLayout->addWidget(zoomOutToolButton);
102 textEdit = new QTextEdit;
103 textEdit->setReadOnly(true);
105 resizer = new TranslationWidgetAutoResizer(textEdit);
106 connect(this, SIGNAL(updateSize()),
107 resizer, SLOT(textEditChanged()));
109 QWidget*w = new QWidget;
110 verticalLayout = new QVBoxLayout(w);
111 verticalLayout->addWidget(textEdit);
113 textEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
114 textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
118 this->setWidgetResizable(true);
120 connect(zoomInToolButton, SIGNAL(clicked()),
121 textEdit, SLOT(zoomIn()));
123 connect(zoomInToolButton, SIGNAL(clicked()),
124 this, SIGNAL(updateSize()));
126 connect(zoomOutToolButton, SIGNAL(clicked()),
127 textEdit, SLOT(zoomOut()));
129 connect(zoomInToolButton, SIGNAL(clicked()),
130 this, SIGNAL(updateSize()));
132 /* #ifdef Q_WS_MAEMO_5
133 fullScreenButton = new QToolButton(this);
134 fullScreenButton->setIcon(QIcon::fromTheme("general_fullsize"));
135 fullScreenButton->setMinimumSize(fullScreenButton->sizeHint());
136 int x = QApplication::desktop()->screenGeometry(this).width() -
137 fullScreenButton->sizeHint().width();
138 int y = QApplication::desktop()->screenGeometry(this).height() -
139 fullScreenButton->sizeHint().height();
140 fullScreenButton->move(QPoint(x,y));
141 fullScreenButton->show();
142 fullScreenButton->setWindowOpacity(0.5);
145 backButton = new QToolButton(this);
146 backButton->setIcon(QIcon::fromTheme("general_overlay_back"));
147 backButton->setMinimumSize(fullScreenButton->sizeHint());
148 x = QApplication::desktop()->screenGeometry(this).width() -
149 backButton->sizeHint().width();
151 backButton->move(QPoint(x,y));
153 backButton->setWindowOpacity(0.5);
155 connect(backButton, SIGNAL(clicked()),