add focus in qml
[mdictionary] / src / mdictionary / gui / TranslationView.cpp
index 7e9cd8c..e54498a 100644 (file)
 #include "TranslationView.h"
 #include "TranslationWidget.h"
 
-TranslationView::TranslationView(QWidget *parent) :
-    QWebView(parent)
-{
+
+
+TranslationView::TranslationView(QWidget *parent) : QWebView(parent) {
+
+#ifndef Q_WS_MAEMO_5
+
+    view= new QDeclarativeView();
+    view->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/TranslationView.qml"));
+    view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+    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)));
+    emit setUrl(QDir::homePath() + "/.mdictionary/" + "html.html");
+
+#else
+
     realParent = qobject_cast<TranslationWidget*>(parent);
     searchSelectedAction = new QAction(tr("Search"), this);
     copySelectedAction = new QAction(tr("Copy"), this);
@@ -47,10 +68,26 @@ TranslationView::TranslationView(QWidget *parent) :
 
     connect(searchSelectedAction, SIGNAL(triggered()),
             this, SIGNAL(search()));
-    connect(page(), SIGNAL(selectionChanged()), this, SLOT(selection()));
+    connect(page(), SIGNAL(selectionChanged()),
+            this, SLOT(selection()));
+
+#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();
@@ -63,9 +100,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)
@@ -82,10 +122,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);
@@ -101,38 +144,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
 }