Context menu added for webkig: search, copy, selectall
authorBartosz Szatkowski <bulislaw@linux.com>
Tue, 31 Aug 2010 08:37:32 +0000 (10:37 +0200)
committerBartosz Szatkowski <bulislaw@linux.com>
Tue, 31 Aug 2010 08:37:32 +0000 (10:37 +0200)
trunk/src/base/base.pro
trunk/src/base/gui/TranslationTextEdit.cpp
trunk/src/base/gui/TranslationTextEdit.h
trunk/src/base/gui/TranslationWidget.cpp
trunk/src/base/gui/TranslationWidget.h
trunk/src/base/gui/TranslationWidgetAutoResizer.h [deleted file]

index 632cc8b..5119976 100644 (file)
@@ -7,7 +7,6 @@ QT += core \
     xml \
     xmlpatterns \
     webkit
-
 maemo5:QT += maemo5
 TARGET = mdictionary
 TEMPLATE = app
@@ -48,7 +47,6 @@ HEADERS += gui/MainWindow.h \
     gui/MenuTabWidget.h \
     gui/DictManagerWidget.h \
     gui/DictTypeSelectDialog.h \
-    gui/TranslationWidgetAutoResizer.h \
     ../includes/History.h \
     gui/HistoryListDialog.h \
     ../includes/GUIInterface.h \
@@ -77,8 +75,7 @@ unix {
     INSTALLS += target \
         desktop \
         icon64 \
-       bookmarks
-
+        bookmarks
     target.path = $$BINDIR
     maemo5 { 
         desktop.path = $$DATADIR/applications/hildon
@@ -90,7 +87,6 @@ unix {
     }
     desktop.files += ../../../data/other/$${TARGET}.desktop
     icon64.files += ../../../data/icons/64x64/$${TARGET}.png
-
     bookmarks.path = $$LIBDIR
     bookmarks.files += ../../../data/icons/16x16/staron.png
 }
index 4f5766d..dd46e02 100644 (file)
@@ -28,23 +28,30 @@ TranslationTextEdit::TranslationTextEdit(QWidget *parent) :
     QWebView(parent)
 {
     searchSelectedAction = new QAction(tr("Search"), this);
+    copySelectedAction = new QAction(tr("Copy"), this);
+    selectAllAction = new QAction(tr("Select All"), this);
 
     connect(searchSelectedAction, SIGNAL(triggered()),
             this, SIGNAL(search()));
 }
 
 void TranslationTextEdit::contextMenuEvent(QContextMenuEvent *e) {
-    //QMenu *menu = createStandardContextMenu(e->pos());
-    //if(page()->selectedText().isEmpty())
-     //   searchSelectedAction->setEnabled(false);
-    //else
-     //   searchSelectedAction->setEnabled(true);
+    QMenu *menu = new QMenu;
+    if(selectedText().isEmpty())
+        searchSelectedAction->setEnabled(false);
+    else
+        searchSelectedAction->setEnabled(true);
 
-    //menu->addSeparator();
-    //menu->addAction(searchSelectedAction);
+    menu->addAction(searchSelectedAction);
+    menu->addSeparator();
+    menu->addAction(pageAction(QWebPage::Copy));
+    menu->addAction(pageAction(QWebPage::SelectAll));
 
-    //menu->exec(e->globalPos());
-    //delete menu;
+    menu->exec(e->globalPos());
+    delete menu;
 
-    //e->ignore();
+    e->ignore();
 }
+
+
+
index b6e48ae..6f3fe3b 100644 (file)
@@ -42,6 +42,9 @@ protected:
 
 private:
     QAction* searchSelectedAction;
+    QAction* copySelectedAction;
+    QAction* selectAllAction;
+
 };
 
 #endif // TRANSLATIONTEXTEDIT_H
index 379bdbe..161cf0b 100644 (file)
@@ -22,7 +22,6 @@
 //Created by Mateusz Półrola
 
 #include "TranslationWidget.h"
-#include "TranslationWidgetAutoResizer.h"
 #include <QDebug>
 #ifdef Q_WS_MAEMO_5
     #include <QtGui/QX11Info>
@@ -76,19 +75,6 @@ void TranslationWidget::show(QStringList translations) {
         trans += t + "\n";
     }
 
-
-    QImage image(":icons/16x16/staron.png");
-//    QTextDocument *document = textEdit->document();
-//    document->addResource(QTextDocument::ImageResource,
-//            QUrl("mydata://image.png"), QVariant(image));
-
- //   QFile cssFile(QDir::homePath() + "/.mdictionary/style.css");
- //   cssFile.open(QFile::ReadOnly);
- //   document->addResource(QTextDocument::StyleSheetResource,
-//            QUrl("mydata://style.css"),
-//            QVariant(cssFile.readAll()));
-
-
     trans=tr("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") + tr("\n <ar>")
             + trans + tr("\n </ar>");
     trans=XslConversion(trans);
@@ -102,7 +88,6 @@ void TranslationWidget::show(QStringList translations) {
     trans.replace("$STAR$", "/usr/lib/mdictionary/staron.png");
 
 
-    qDebug () << trans;
     webkit->setHtml(trans, QUrl().fromLocalFile("/"));
 
 
@@ -214,19 +199,11 @@ void TranslationWidget::initButtons() {
 void TranslationWidget::initializeUI() {
 
     webkit = new TranslationTextEdit(this);
-//    textEdit->setReadOnly(true);
-
-    //resizer = new TranslationWidgetAutoResizer(textEdit);
-    //connect(this, SIGNAL(updateSize()),
-            //resizer, SLOT(textEditChanged()));
 
     QWidget*w = new QWidget(this);
     verticalLayout = new QVBoxLayout(w);
     verticalLayout->addWidget(webkit);
 
-//    textEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- //   textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-
     this->setWidget(w);
     this->setWidgetResizable(true);
 
@@ -291,7 +268,7 @@ void TranslationWidget::searchSelected() {
     #ifdef Q_WS_MAEMO_5
         hide();
     #endif
-    Q_EMIT search(webkit->page()->selectedText());
+    Q_EMIT search(webkit->selectedText().toLower());
 }
 
 #ifdef Q_WS_MAEMO_5
index 8e380c9..92139d8 100644 (file)
@@ -29,7 +29,6 @@
 #include <QModelIndex>
 #include <QtGui>
 #include "../backbone/backbone.h"
-#include "TranslationWidgetAutoResizer.h"
 #include <QtXml>
 #include <QXmlQuery>
 #include "TranslationTextEdit.h"
@@ -97,7 +96,6 @@ private:
     #endif
     QVBoxLayout *verticalLayout;
     QHBoxLayout* horizontalLayout;
-    TranslationWidgetAutoResizer* resizer;
 
     void initializeUI();
 };
diff --git a/trunk/src/base/gui/TranslationWidgetAutoResizer.h b/trunk/src/base/gui/TranslationWidgetAutoResizer.h
deleted file mode 100644 (file)
index 038e1bf..0000000
+++ /dev/null
@@ -1,67 +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 <http://www.gnu.org/licenses/>.
-
-    Copyright 2010 Comarch S.A.
-
-*******************************************************************************/
-//! \file TranslationWidgetAutoResizer.h
-//! \brief Implements translation widget auto resizer
-//! \author Mateusz Półrola <mateusz.polrola@comarch.pl>a
-
-#ifndef TRANSLATIONWIDGETAUTORESIZER_H
-#define TRANSLATIONWIDGETAUTORESIZER_H
-
-#include <QtGui/qtextedit.h>
-class TranslationWidgetAutoResizer : public QObject
-{
-    Q_OBJECT
-
-public:
-    TranslationWidgetAutoResizer(QWidget *parent) :QObject(parent),
-    textEdit(qobject_cast<QTextEdit* >((parent))),
-    edit(qobject_cast<QFrame* >((parent))) {
-
-  //   connect(parent, SIGNAL(textChanged()), this,
-   //          SLOT(textEditChanged()));
-   //  connect(parent, SIGNAL(cursorPositionChanged()),
-    //         this, SLOT(textEditChanged()));
-     }
-
-public Q_SLOTS:
-    inline void textEditChanged();
-
-private:
-    QTextEdit *textEdit;
-    QFrame *edit;
-};
-
-void TranslationWidgetAutoResizer::textEditChanged() {
-    QTextDocument *doc = textEdit->document();
-
-    QSize s = doc->size().toSize();
-
-    const QRect fr = edit->frameRect();
-    const QRect cr = edit->contentsRect();
-
-    edit->setMinimumHeight(qMax(70, s.height() + (fr.height() - cr.height()) -
-                                1));
-
-    edit->setMinimumHeight(qMax(70, s.height() + (fr.height() - cr.height()) -
-                                1));
-}
-
-#endif // TRANSLATIONWIDGETAUTORESIZER_H