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 /*! \file TranslationView.cpp
23 \brief Web view with translations
25 \author Mateusz Półrola <mateusz.polrola@comarch.pl>
29 #include "TranslationView.h"
30 #include "TranslationWidget.h"
34 TranslationView::TranslationView(QWidget *parent) : QWebView(parent) {
38 view= new QDeclarativeView();
39 view->setSource(QUrl("src/mdictionary/qml/TranslationView.qml"));
40 view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
41 view->setAlignment(Qt::AlignCenter);
46 realParent = qobject_cast<TranslationWidget*>(parent);
47 searchSelectedAction = new QAction(tr("Search"), this);
48 copySelectedAction = new QAction(tr("Copy"), this);
49 selectAllAction = new QAction(tr("Select All"), this);
50 setAcceptDrops(false);
53 installEventFilter(this);
54 property("kineticScroller").value<QAbstractKineticScroller*>()->
59 connect(searchSelectedAction, SIGNAL(triggered()),
60 this, SIGNAL(search()));
61 connect(page(), SIGNAL(selectionChanged()), this, SLOT(selection()));
66 void TranslationView::wheelEvent(QWheelEvent *e) {
67 if(e->modifiers() & Qt::ControlModifier) {
77 QWebView::wheelEvent(e);
81 bool TranslationView::eventFilter(QObject *, QEvent *e) {
83 case QEvent::MouseButtonPress:
84 if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
87 case QEvent::MouseButtonRelease:
88 if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
91 case QEvent::MouseMove:
101 void TranslationView::contextMenuEvent(QContextMenuEvent *e) {
102 QMenu *menu = new QMenu;
103 if(selectedText().isEmpty())
104 searchSelectedAction->setEnabled(false);
106 searchSelectedAction->setEnabled(true);
108 menu->addAction(searchSelectedAction);
109 menu->addSeparator();
110 menu->addAction(pageAction(QWebPage::Copy));
111 menu->addAction(pageAction(QWebPage::SelectAll));
113 menu->exec(e->globalPos());
120 void TranslationView::zoomIn() {
121 if(zoomFactor() >= 3)
123 setZoomFactor(zoomFactor()*1.05);
124 realParent->updateZoom(zoomFactor());
128 void TranslationView::zoomOut() {
129 if(zoomFactor() <= 0.5)
131 setZoomFactor(zoomFactor()*0.95);
132 realParent->updateZoom(zoomFactor());
135 void TranslationView::copy() {
136 pageAction(QWebPage::Copy)->trigger();
139 void TranslationView::selection() {
140 if(selectedText().size())
141 Q_EMIT copyAvailable(true);
143 Q_EMIT copyAvailable(false);
147 void TranslationView::selectAll() {
148 pageAction(QWebPage::SelectAll)->trigger();