From: Mateusz Półrola Date: Wed, 15 Sep 2010 09:40:07 +0000 (+0200) Subject: Rename TranslationTextEdit to TranslationView X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=039bca6968ed3554d8d50adec8c36d5b8485d883;p=mdictionary Rename TranslationTextEdit to TranslationView --- diff --git a/src/mdictionary/gui/TranslationTextEdit.cpp b/src/mdictionary/gui/TranslationTextEdit.cpp deleted file mode 100644 index 41d5aaa..0000000 --- a/src/mdictionary/gui/TranslationTextEdit.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - - 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 . - - Copyright 2010 Comarch S.A. - -*******************************************************************************/ - -//! \file TranslationTextEdit.cpp -//! \author Mateusz Półrola - -#include -#include "TranslationTextEdit.h" -#include "TranslationWidget.h" - -TranslationTextEdit::TranslationTextEdit(QWidget *parent) : - QWebView(parent) -{ - realParent = qobject_cast(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()-> - 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(e)->button() == Qt::LeftButton) - mousePressed = true; - break; - case QEvent::MouseButtonRelease: - if (static_cast(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(); -} - - - diff --git a/src/mdictionary/gui/TranslationTextEdit.h b/src/mdictionary/gui/TranslationTextEdit.h deleted file mode 100644 index 917105a..0000000 --- a/src/mdictionary/gui/TranslationTextEdit.h +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - - 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 . - - Copyright 2010 Comarch S.A. - -*******************************************************************************/ - -//! \file TranslationTextEdit.h -//! \author Mateusz Półrola - -#ifndef TRANSLATIONTEXTEDIT_H -#define TRANSLATIONTEXTEDIT_H - -#include -#include -#include -#include - -class TranslationWidget; - -class TranslationTextEdit : public QWebView -{ - Q_OBJECT -public: - explicit TranslationTextEdit(QWidget *parent = 0); - -public Q_SLOTS: - void zoomIn(); - void zoomOut(); - void copy(); - void selection(); - void selectAll(); - -Q_SIGNALS: - void search(); - void copyAvailable(bool); - -protected: - void contextMenuEvent(QContextMenuEvent *); - void wheelEvent(QWheelEvent *); - -private: - QAction* searchSelectedAction; - QAction* copySelectedAction; - QAction* selectAllAction; - TranslationWidget* realParent; - bool mousePressed; - bool eventFilter(QObject *, QEvent *); - -}; - -#endif // TRANSLATIONTEXTEDIT_H diff --git a/src/mdictionary/gui/TranslationView.cpp b/src/mdictionary/gui/TranslationView.cpp new file mode 100644 index 0000000..79a6c14 --- /dev/null +++ b/src/mdictionary/gui/TranslationView.cpp @@ -0,0 +1,136 @@ +/******************************************************************************* + + 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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +//! \file TranslationView.cpp +//! \author Mateusz Półrola + +#include +#include "TranslationView.h" +#include "TranslationWidget.h" + +TranslationView::TranslationView(QWidget *parent) : + QWebView(parent) +{ + realParent = qobject_cast(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()-> + setEnabled(true); + #endif + + + connect(searchSelectedAction, SIGNAL(triggered()), + this, SIGNAL(search())); + connect(page(), SIGNAL(selectionChanged()), this, SLOT(selection())); +} + +void TranslationView::wheelEvent(QWheelEvent *e) { + if(e->modifiers() & Qt::ControlModifier) { + if(e->delta()>0) { + zoomIn(); + } + else { + zoomOut(); + } + e->ignore(); + } + else { + QWebView::wheelEvent(e); + } +} + +bool TranslationView::eventFilter(QObject *, QEvent *e) { + switch (e->type()) { + case QEvent::MouseButtonPress: + if (static_cast(e)->button() == Qt::LeftButton) + mousePressed = true; + break; + case QEvent::MouseButtonRelease: + if (static_cast(e)->button() == Qt::LeftButton) + mousePressed = false; + break; + case QEvent::MouseMove: + if (mousePressed) + return true; + default: + break; + } + return false; +} + + +void TranslationView::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 TranslationView::zoomIn() { + if(zoomFactor() >= 3) + return; + setZoomFactor(zoomFactor()*1.05); + realParent->updateZoom(zoomFactor()); + +} + +void TranslationView::zoomOut() { + if(zoomFactor() <= 0.5) + return; + setZoomFactor(zoomFactor()*0.95); + realParent->updateZoom(zoomFactor()); +} + +void TranslationView::copy() { + pageAction(QWebPage::Copy)->trigger(); +} + +void TranslationView::selection() { + if(selectedText().size()) + Q_EMIT copyAvailable(true); + else + Q_EMIT copyAvailable(false); +} + + +void TranslationView::selectAll() { + pageAction(QWebPage::SelectAll)->trigger(); +} + + + diff --git a/src/mdictionary/gui/TranslationView.h b/src/mdictionary/gui/TranslationView.h new file mode 100644 index 0000000..1ea9d12 --- /dev/null +++ b/src/mdictionary/gui/TranslationView.h @@ -0,0 +1,66 @@ +/******************************************************************************* + + 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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +//! \file TranslationView.h +//! \author Mateusz Półrola + +#ifndef TRANSLATIONVIEW_H +#define TRANSLATIONVIEW_H + +#include +#include +#include +#include + +class TranslationWidget; + +class TranslationView : public QWebView +{ + Q_OBJECT +public: + explicit TranslationView(QWidget *parent = 0); + +public Q_SLOTS: + void zoomIn(); + void zoomOut(); + void copy(); + void selection(); + void selectAll(); + +Q_SIGNALS: + void search(); + void copyAvailable(bool); + +protected: + void contextMenuEvent(QContextMenuEvent *); + void wheelEvent(QWheelEvent *); + +private: + QAction* searchSelectedAction; + QAction* copySelectedAction; + QAction* selectAllAction; + TranslationWidget* realParent; + bool mousePressed; + bool eventFilter(QObject *, QEvent *); + +}; + +#endif // TRANSLATIONVIEW_H diff --git a/src/mdictionary/gui/TranslationWidget.cpp b/src/mdictionary/gui/TranslationWidget.cpp index 404ca2f..a7bf713 100644 --- a/src/mdictionary/gui/TranslationWidget.cpp +++ b/src/mdictionary/gui/TranslationWidget.cpp @@ -214,7 +214,7 @@ void TranslationWidget::initButtons() { void TranslationWidget::initializeUI() { - webkit = new TranslationTextEdit(this); + webkit = new TranslationView(this); Settings* set = guiinterface->settings(); qreal fac = set->value("zoom").toFloat(); if(!fac) diff --git a/src/mdictionary/gui/TranslationWidget.h b/src/mdictionary/gui/TranslationWidget.h index 9e3e36c..5907f97 100644 --- a/src/mdictionary/gui/TranslationWidget.h +++ b/src/mdictionary/gui/TranslationWidget.h @@ -30,7 +30,7 @@ #include "../backbone/backbone.h" #include #include -#include "TranslationTextEdit.h" +#include "TranslationView.h" #include #include "../../include/GUIInterface.h" @@ -72,7 +72,7 @@ private: QString XslConversion(QString translation); QToolButton* zoomInToolButton; QToolButton* zoomOutToolButton; - TranslationTextEdit *webkit; + TranslationView *webkit; QString xslt; #ifdef Q_WS_MAEMO_5 diff --git a/src/mdictionary/mdictionary.pro b/src/mdictionary/mdictionary.pro index 8e3195b..0025ded 100644 --- a/src/mdictionary/mdictionary.pro +++ b/src/mdictionary/mdictionary.pro @@ -34,7 +34,7 @@ SOURCES += gui/main.cpp \ gui/BookmarksWidget.cpp \ gui/WelcomeScreenWidget.cpp \ gui/AboutWidget.cpp \ - gui/TranslationTextEdit.cpp \ + gui/TranslationView.cpp \ gui/DBusAdapter.cpp \ gui/NotifyManager.cpp \ gui/SpinBox.cpp @@ -63,7 +63,7 @@ HEADERS += gui/MainWindow.h \ gui/BookmarksWidget.h \ gui/WelcomeScreenWidget.h \ ../include/Notify.h \ - gui/TranslationTextEdit.h \ + gui/TranslationView.h \ ../include/AccentsNormalizer.h \ ../include/DictDialog.h \ gui/DBusAdapter.h \