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 TranslationTextEdit.cpp
23 //! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
26 #include "TranslationTextEdit.h"
27 #include "TranslationWidget.h"
29 TranslationTextEdit::TranslationTextEdit(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()));
51 bool TranslationTextEdit::eventFilter(QObject *, QEvent *e)
54 case QEvent::MouseButtonPress:
55 if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
58 case QEvent::MouseButtonRelease:
59 if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
62 case QEvent::MouseMove:
73 void TranslationTextEdit::contextMenuEvent(QContextMenuEvent *e) {
74 QMenu *menu = new QMenu;
75 if(selectedText().isEmpty())
76 searchSelectedAction->setEnabled(false);
78 searchSelectedAction->setEnabled(true);
80 menu->addAction(searchSelectedAction);
82 menu->addAction(pageAction(QWebPage::Copy));
83 menu->addAction(pageAction(QWebPage::SelectAll));
85 menu->exec(e->globalPos());
92 void TranslationTextEdit::zoomIn() {
93 setZoomFactor(zoomFactor()*1.05);
94 realParent->updateZoom(zoomFactor());
98 void TranslationTextEdit::zoomOut() {
99 setZoomFactor(zoomFactor()*0.95);
100 realParent->updateZoom(zoomFactor());
103 void TranslationTextEdit::copy() {
104 pageAction(QWebPage::Copy)->trigger();
107 void TranslationTextEdit::selection() {
108 if(selectedText().size())
109 Q_EMIT copyAvailable(true);
111 Q_EMIT copyAvailable(false);
115 void TranslationTextEdit::selectAll() {
116 pageAction(QWebPage::SelectAll)->trigger();