qml - webView widget
[mdictionary] / src / mdictionary / gui / TranslationView.cpp
index 351ed6b..84efd21 100644 (file)
@@ -41,6 +41,14 @@ TranslationView::TranslationView(QWidget *parent) : QWebView(parent) {
     view->setAlignment(Qt::AlignCenter);
     view->show();
 
+    mainLayout = new QVBoxLayout;
+    mainLayout->addWidget(view);
+    setLayout(mainLayout);
+
+    QGraphicsObject *rootObject = view->rootObject();
+
+    connect(this, SIGNAL(setUrl(QVariant)),
+           rootObject, SLOT(setUrl(QVariant)));
 #else
 
     realParent = qobject_cast<TranslationWidget*>(parent);
@@ -63,7 +71,20 @@ TranslationView::TranslationView(QWidget *parent) : QWebView(parent) {
 #endif
 }
 
+void TranslationView::setHtml(QString htmlString){
+    QString url = QDir::homePath() + "/.mdictionary/" + "html.html";
+    QFile file(url);
+    if(file.open(QIODevice::WriteOnly | QIODevice::Text)){
+        QByteArray array = htmlString.toUtf8();
+        file.write(array);
+        file.close();
+        emit setUrl(url);
+    }
+}
+
 void TranslationView::wheelEvent(QWheelEvent *e) {
+#ifndef Q_WS_MAEMO_5
+#else
     if(e->modifiers() & Qt::ControlModifier) {
         if(e->delta()>0) {
             zoomIn();
@@ -76,9 +97,12 @@ void TranslationView::wheelEvent(QWheelEvent *e) {
     else {
         QWebView::wheelEvent(e);
     }
+#endif
 }
 
 bool TranslationView::eventFilter(QObject *, QEvent *e) {
+#ifndef Q_WS_MAEMO_5
+#else
     switch (e->type()) {
     case QEvent::MouseButtonPress:
         if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
@@ -95,10 +119,13 @@ bool TranslationView::eventFilter(QObject *, QEvent *e) {
         break;
     }
     return false;
+#endif
 }
 
 
 void TranslationView::contextMenuEvent(QContextMenuEvent *e) {
+#ifndef Q_WS_MAEMO_5
+#else
     QMenu *menu = new QMenu;
     if(selectedText().isEmpty())
         searchSelectedAction->setEnabled(false);
@@ -114,38 +141,53 @@ void TranslationView::contextMenuEvent(QContextMenuEvent *e) {
     delete menu;
 
     e->ignore();
+#endif
 }
 
 
 void TranslationView::zoomIn() {
+#ifndef Q_WS_MAEMO_5
+#else
     if(zoomFactor() >= 3)
         return;
     setZoomFactor(zoomFactor()*1.05);
     realParent->updateZoom(zoomFactor());
-
+#endif
 }
 
 void TranslationView::zoomOut() {
+#ifndef Q_WS_MAEMO_5
+#else
     if(zoomFactor() <= 0.5)
         return;
     setZoomFactor(zoomFactor()*0.95);
     realParent->updateZoom(zoomFactor());
+#endif
 }
 
 void TranslationView::copy() {
+#ifndef Q_WS_MAEMO_5
+#else
       pageAction(QWebPage::Copy)->trigger();
+#endif
 }
 
 void TranslationView::selection() {
+#ifndef Q_WS_MAEMO_5
+#else
     if(selectedText().size())
         Q_EMIT copyAvailable(true);
     else
         Q_EMIT copyAvailable(false);
+#endif
 }
 
 
 void TranslationView::selectAll() {
+#ifndef Q_WS_MAEMO_5
+#else
     pageAction(QWebPage::SelectAll)->trigger();
+#endif
 }