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
25 #include "TranslationTextEdit.h"
26 #include "TranslationWidget.h"
28 TranslationTextEdit::TranslationTextEdit(QWidget *parent) :
31 realParent = qobject_cast<TranslationWidget*>(parent);
32 searchSelectedAction = new QAction(tr("Search"), this);
33 copySelectedAction = new QAction(tr("Copy"), this);
34 selectAllAction = new QAction(tr("Select All"), this);
35 setAcceptDrops(false);
38 installEventFilter(this);
39 property("kineticScroller").value<QAbstractKineticScroller*>()->
44 connect(searchSelectedAction, SIGNAL(triggered()),
45 this, SIGNAL(search()));
46 connect(page(), SIGNAL(selectionChanged()), this, SLOT(selection()));
50 bool TranslationTextEdit::eventFilter(QObject *, QEvent *e)
53 case QEvent::MouseButtonPress:
54 if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
57 case QEvent::MouseButtonRelease:
58 if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
61 case QEvent::MouseMove:
72 void TranslationTextEdit::contextMenuEvent(QContextMenuEvent *e) {
73 QMenu *menu = new QMenu;
74 if(selectedText().isEmpty())
75 searchSelectedAction->setEnabled(false);
77 searchSelectedAction->setEnabled(true);
79 menu->addAction(searchSelectedAction);
81 menu->addAction(pageAction(QWebPage::Copy));
82 menu->addAction(pageAction(QWebPage::SelectAll));
84 menu->exec(e->globalPos());
91 void TranslationTextEdit::zoomIn() {
92 setZoomFactor(zoomFactor()*1.05);
93 realParent->updateZoom(zoomFactor());
97 void TranslationTextEdit::zoomOut() {
98 setZoomFactor(zoomFactor()*0.95);
99 realParent->updateZoom(zoomFactor());
102 void TranslationTextEdit::copy() {
103 pageAction(QWebPage::Copy)->trigger();
106 void TranslationTextEdit::selection() {
107 if(selectedText().size())
108 Q_EMIT copyAvailable(true);
110 Q_EMIT copyAvailable(false);
114 void TranslationTextEdit::selectAll() {
115 pageAction(QWebPage::SelectAll)->trigger();