-/*******************************************************************************
-
- This file is part of mDictionary.
-
- mDictionary is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- mDictionary is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
-
- Copyright 2010 Comarch S.A.
-
-*******************************************************************************/
-
-//! \file TranslationTextEdit.cpp
-//! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
-
-#include <QtGui>
-#include "TranslationTextEdit.h"
-#include "TranslationWidget.h"
-
-TranslationTextEdit::TranslationTextEdit(QWidget *parent) :
- QWebView(parent)
-{
- realParent = qobject_cast<TranslationWidget*>(parent);
- searchSelectedAction = new QAction(tr("Search"), this);
- copySelectedAction = new QAction(tr("Copy"), this);
- selectAllAction = new QAction(tr("Select All"), this);
- setAcceptDrops(false);
-
- #ifdef Q_WS_MAEMO_5
- installEventFilter(this);
- property("kineticScroller").value<QAbstractKineticScroller*>()->
- setEnabled(true);
- #endif
-
-
- connect(searchSelectedAction, SIGNAL(triggered()),
- this, SIGNAL(search()));
- connect(page(), SIGNAL(selectionChanged()), this, SLOT(selection()));
-}
-
-void TranslationTextEdit::wheelEvent(QWheelEvent *e) {
- if(e->modifiers() & Qt::ControlModifier) {
- if(e->delta()>0) {
- zoomIn();
- }
- else {
- zoomOut();
- }
- e->ignore();
- }
- else {
- QWebView::wheelEvent(e);
- }
-}
-
-bool TranslationTextEdit::eventFilter(QObject *, QEvent *e) {
- switch (e->type()) {
- case QEvent::MouseButtonPress:
- if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
- mousePressed = true;
- break;
- case QEvent::MouseButtonRelease:
- if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
- mousePressed = false;
- break;
- case QEvent::MouseMove:
- if (mousePressed)
- return true;
- default:
- break;
- }
- return false;
-}
-
-
-void TranslationTextEdit::contextMenuEvent(QContextMenuEvent *e) {
- QMenu *menu = new QMenu;
- if(selectedText().isEmpty())
- searchSelectedAction->setEnabled(false);
- else
- searchSelectedAction->setEnabled(true);
-
- menu->addAction(searchSelectedAction);
- menu->addSeparator();
- menu->addAction(pageAction(QWebPage::Copy));
- menu->addAction(pageAction(QWebPage::SelectAll));
-
- menu->exec(e->globalPos());
- delete menu;
-
- e->ignore();
-}
-
-
-void TranslationTextEdit::zoomIn() {
- if(zoomFactor() >= 3)
- return;
- setZoomFactor(zoomFactor()*1.05);
- realParent->updateZoom(zoomFactor());
-
-}
-
-void TranslationTextEdit::zoomOut() {
- if(zoomFactor() <= 0.5)
- return;
- setZoomFactor(zoomFactor()*0.95);
- realParent->updateZoom(zoomFactor());
-}
-
-void TranslationTextEdit::copy() {
- pageAction(QWebPage::Copy)->trigger();
-}
-
-void TranslationTextEdit::selection() {
- if(selectedText().size())
- Q_EMIT copyAvailable(true);
- else
- Q_EMIT copyAvailable(false);
-}
-
-
-void TranslationTextEdit::selectAll() {
- pageAction(QWebPage::SelectAll)->trigger();
-}
-
-
-