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"
32 TranslationView::TranslationView(QWidget *parent) :
35 realParent = qobject_cast<TranslationWidget*>(parent);
36 searchSelectedAction = new QAction(tr("Search"), this);
37 copySelectedAction = new QAction(tr("Copy"), this);
38 selectAllAction = new QAction(tr("Select All"), this);
39 setAcceptDrops(false);
42 installEventFilter(this);
43 property("kineticScroller").value<QAbstractKineticScroller*>()->
48 connect(searchSelectedAction, SIGNAL(triggered()),
49 this, SIGNAL(search()));
50 connect(page(), SIGNAL(selectionChanged()), this, SLOT(selection()));
53 void TranslationView::wheelEvent(QWheelEvent *e) {
54 if(e->modifiers() & Qt::ControlModifier) {
64 QWebView::wheelEvent(e);
68 bool TranslationView::eventFilter(QObject *, QEvent *e) {
70 case QEvent::MouseButtonPress:
71 if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
74 case QEvent::MouseButtonRelease:
75 if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
78 case QEvent::MouseMove:
88 void TranslationView::contextMenuEvent(QContextMenuEvent *e) {
89 QMenu *menu = new QMenu;
90 if(selectedText().isEmpty())
91 searchSelectedAction->setEnabled(false);
93 searchSelectedAction->setEnabled(true);
95 menu->addAction(searchSelectedAction);
97 menu->addAction(pageAction(QWebPage::Copy));
98 menu->addAction(pageAction(QWebPage::SelectAll));
100 menu->exec(e->globalPos());
107 void TranslationView::zoomIn() {
108 if(zoomFactor() >= 3)
110 setZoomFactor(zoomFactor()*1.05);
111 realParent->updateZoom(zoomFactor());
115 void TranslationView::zoomOut() {
116 if(zoomFactor() <= 0.5)
118 setZoomFactor(zoomFactor()*0.95);
119 realParent->updateZoom(zoomFactor());
122 void TranslationView::copy() {
123 pageAction(QWebPage::Copy)->trigger();
126 void TranslationView::selection() {
127 if(selectedText().size())
128 Q_EMIT copyAvailable(true);
130 Q_EMIT copyAvailable(false);
134 void TranslationView::selectAll() {
135 pageAction(QWebPage::SelectAll)->trigger();