add history widget
[mdictionary] / src / mdictionary / gui / HistoryListDialog.cpp
index 0074181..804f907 100644 (file)
 #include "HistoryListDialog.h"
 
 HistoryListDialog::HistoryListDialog(QStringList words, QWidget *parent):
-        QDialog(parent)
-{
+        QDialog(parent) {
+
+    oryginalList = words;
     verticalLayout = new QVBoxLayout(this);
     setLayout(verticalLayout);
+    setModal(true);
+    setWindowFlags(Qt::Popup);
+
+#ifndef Q_WS_MAEMO_5
+
+    HistoryListModel *model=new HistoryListModel(words,this);
+    view= new QDeclarativeView();
+    QDeclarativeContext* ctxt=view->rootContext();
+    ctxt->setContextProperty("historyTypeModel", model);
+    view->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/HistoryListDialog.qml"));
+    view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+    view->setAlignment(Qt::AlignCenter);
+    view->show();
 
+    view->setMinimumWidth(250);
+    view->setMaximumWidth(250);
+    view->setMinimumHeight(300);
+    view->setWindowFlags(Qt::Popup);
+    verticalLayout->addWidget(view);
+
+    QGraphicsObject *rootObject = view->rootObject();
+
+    connect(rootObject,SIGNAL(selectedRow(int)),
+            this,SLOT(itemClicked(int)));
+
+#else
     #ifndef Q_WS_MAEMO_5
         setWindowFlags(Qt::Popup);
         QLabel* title = new QLabel(tr("History"));
         verticalLayout->addWidget(title,0, Qt::AlignCenter);
     #endif
-
-    oryginalList = words;
-
     historyListWidget = new QListWidget(this);
     verticalLayout->addWidget(historyListWidget);
 
@@ -50,14 +73,13 @@ HistoryListDialog::HistoryListDialog(QStringList words, QWidget *parent):
         historyListWidget->addItem(item);
     }
 
-     setModal(true);
-
      setWindowTitle(tr("History"));
 
      setMinimumHeight(300);
 
      connect(historyListWidget, SIGNAL(activated(QModelIndex)),
              this, SLOT(itemClicked(QModelIndex)));
+#endif
 }
 
 
@@ -67,6 +89,11 @@ void HistoryListDialog::itemClicked(QModelIndex index) {
     accept();
 }
 
+void HistoryListDialog::itemClicked(int index) {
+    _selectedWord = oryginalList[index];
+    _selectedRow = index;
+    accept();
+}
 
 QString HistoryListDialog::selectedWord() {
     return _selectedWord;
@@ -77,6 +104,11 @@ int HistoryListDialog::selectedRow() {
 }
 
 int HistoryListDialog::exec() {
+ #ifndef Q_WS_MAEMO_5
+
+ #else
     historyListWidget->setFocus();
+ #endif
+
     QDialog::exec();
 }