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 //! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
26 #include "TranslationView.h"
27 #include "TranslationWidget.h"
29 TranslationView::TranslationView(QWidget *parent) :
32 realParent = qobject_cast<TranslationWidget*>(parent);
33 searchSelectedAction = new QAction(tr("Search"), this);
34 copySelectedAction = new QAction(tr("Copy"), this);
35 selectAllAction = new QAction(tr("Select All"), this);
36 setAcceptDrops(false);
39 installEventFilter(this);
40 property("kineticScroller").value<QAbstractKineticScroller*>()->
45 connect(searchSelectedAction, SIGNAL(triggered()),
46 this, SIGNAL(search()));
47 connect(page(), SIGNAL(selectionChanged()), this, SLOT(selection()));
50 void TranslationView::wheelEvent(QWheelEvent *e) {
51 if(e->modifiers() & Qt::ControlModifier) {
61 QWebView::wheelEvent(e);
65 bool TranslationView::eventFilter(QObject *, QEvent *e) {
67 case QEvent::MouseButtonPress:
68 if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
71 case QEvent::MouseButtonRelease:
72 if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
75 case QEvent::MouseMove:
85 void TranslationView::contextMenuEvent(QContextMenuEvent *e) {
86 QMenu *menu = new QMenu;
87 if(selectedText().isEmpty())
88 searchSelectedAction->setEnabled(false);
90 searchSelectedAction->setEnabled(true);
92 menu->addAction(searchSelectedAction);
94 menu->addAction(pageAction(QWebPage::Copy));
95 menu->addAction(pageAction(QWebPage::SelectAll));
97 menu->exec(e->globalPos());
104 void TranslationView::zoomIn() {
105 if(zoomFactor() >= 3)
107 setZoomFactor(zoomFactor()*1.05);
108 realParent->updateZoom(zoomFactor());
112 void TranslationView::zoomOut() {
113 if(zoomFactor() <= 0.5)
115 setZoomFactor(zoomFactor()*0.95);
116 realParent->updateZoom(zoomFactor());
119 void TranslationView::copy() {
120 pageAction(QWebPage::Copy)->trigger();
123 void TranslationView::selection() {
124 if(selectedText().size())
125 Q_EMIT copyAvailable(true);
127 Q_EMIT copyAvailable(false);
131 void TranslationView::selectAll() {
132 pageAction(QWebPage::SelectAll)->trigger();