Updated comments
[mdictionary] / trunk / src / base / gui / MainWindow.cpp
index 30b049b..a9a70d9 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "MainWindow.h"
 #include "ui_MainWindow.h"
+#include <QtGui>
 #ifdef Q_WS_MAEMO_5
     #include <QMaemo5InformationBox>
 #endif
@@ -32,10 +33,6 @@ MainWindow::MainWindow(Backbone *backbone, QWidget *parent):
     GUIInterface(parent),
     ui(new Ui::MainWindow) {
 
-    #ifdef Q_WS_MAEMO_5
-        setAttribute(Qt::WA_Maemo5StackedWindow);
-    #endif
-
     this->backbone = backbone;
 
     initializeUI();
@@ -46,6 +43,8 @@ MainWindow::MainWindow(Backbone *backbone, QWidget *parent):
     connectTranslationWidget();
     connectDictManager();
     connectMenu();
+    connectBookmarksWidget();
+
 
     setExactSearch(false);
 
@@ -62,10 +61,9 @@ MainWindow::~MainWindow() {
 void MainWindow::initializeUI() {
     ui->setupUi(this);
 
-    //showFullScreen();
-    //sets attribute to maemo's stacked window
-
-
+    #ifdef Q_WS_MAEMO_5
+        setAttribute(Qt::WA_Maemo5StackedWindow);
+    #endif
 
     searchBarWidget = new SearchBarWidget;
 
@@ -75,16 +73,24 @@ void MainWindow::initializeUI() {
     //only create it with this widget as parent
     translationWidget = new TranslationWidget(this);
 
+    welcomeScreenWidget = new WelcomeScreenWidget;
+
+
     #ifdef Q_WS_MAEMO_5
-        ui->centralWidget->layout()->addWidget(wordListWidget);
+    //At start we set widget as welcome screen widget
+        ui->centralWidget->layout()->addWidget(welcomeScreenWidget);
+        QVBoxLayout* vl = (QVBoxLayout*)(ui->centralWidget->layout());
+        vl->addWidget(searchBarWidget, 0, Qt::AlignBottom);
     #else
+        translationWidget->hide();
+        //we add to splitter word list and welcome screen
         splitter = new QSplitter(Qt::Horizontal);
         splitter->addWidget(wordListWidget);
-        splitter->addWidget(translationWidget);
+        splitter->addWidget(welcomeScreenWidget);
         splitter->setStretchFactor(1, 150);
         ui->centralWidget->layout()->addWidget(splitter);
+        ui->centralWidget->layout()->addWidget(searchBarWidget);
     #endif
-    ui->centralWidget->layout()->addWidget(searchBarWidget);
 
 
 
@@ -94,15 +100,20 @@ void MainWindow::initializeUI() {
     settingsWidget = new SettingsWidget(this);
     settingsWidget->hide();
 
+    bookmarksWidget = new BookmarksWidget(this);
+    bookmarksWidget->hide();
+
     aboutWidget = new AboutWidget(this);
     aboutWidget->hide();
 
 
+    //creating menus
 
     #ifdef Q_WS_MAEMO_5
         menuWidget = new MenuWidget(this);
         menuWidget->addSubMenu(tr("Settings"), settingsWidget);
         menuWidget->addSubMenu(tr("Dictionaries"), dictManagerWidget);
+        menuWidget->addSubMenu(tr("Bookmarks"), bookmarksWidget);
         menuWidget->addSubMenu(tr("About"), aboutWidget);
         ui->menuBar->addAction(menuWidget);
     #else
@@ -114,6 +125,14 @@ void MainWindow::initializeUI() {
         connect(settingsAction, SIGNAL(triggered()),
                 settingsWidget, SLOT(show()));
 
+        QMenu* m = ui->menuBar->addMenu(tr("Bookmarks"));
+        bookmarksShowAllAction = new QAction(tr("Show all"), m);
+
+        bookmarksRemoveAllAction = new QAction(tr("Remove all"), m);
+
+        m->addAction(bookmarksShowAllAction);
+        m->addAction(bookmarksRemoveAllAction);
+
         aboutAction = ui->menuBar->addAction(tr("About"));
         connect(aboutAction, SIGNAL(triggered()),
                 aboutWidget, SLOT(show()));
@@ -144,6 +163,17 @@ void MainWindow::wordListReady() {
     QMultiHash<QString, Translation*> res = backbone->result();
     QHash<QString, QList<Translation*> > searchResult;
 
+    #ifdef Q_WS_MAEMO_5
+    //switch welcome screen with word list
+    if(!wordListWidget->isVisible()) {
+        int i = ui->centralWidget->layout()->indexOf(welcomeScreenWidget);
+        QBoxLayout* l = (QBoxLayout*)(ui->centralWidget->layout());
+        l->removeWidget(welcomeScreenWidget);
+        welcomeScreenWidget->deleteLater();
+        l->insertWidget(0, wordListWidget);
+    }
+    #endif
+
     //if nothing was found
     if(res.count() == 0) {
         #ifdef Q_WS_MAEMO_5
@@ -167,6 +197,7 @@ void MainWindow::wordListReady() {
         }
         else {
             #ifndef Q_WS_MAEMO_5
+            //on desktop we show word list in exact search
                 emit showWordList(searchResult);
             #endif
             bool foundExactMatch = false;
@@ -195,6 +226,18 @@ void MainWindow::wordListReady() {
 }
 
 void MainWindow::translationsReady() {
+    #ifndef Q_WS_MAEMO_5
+    //switch welcome screen with translation widget
+    if(!translationWidget->isVisible()) {
+        int i = ui->centralWidget->layout()->indexOf(welcomeScreenWidget);
+        QBoxLayout* l = (QBoxLayout*)(ui->centralWidget->layout());
+        QSplitter* s = (QSplitter*)((QWidgetItem*)(l->itemAt(0))->widget());
+        s->insertWidget(1,translationWidget);
+        s->setStretchFactor(1, 150);
+        welcomeScreenWidget->deleteLater();
+    }
+    #endif
+
     emit showTranslation(backbone->htmls());
 }
 
@@ -426,3 +469,33 @@ void MainWindow::connectMenu() {
     connect(this, SIGNAL(setIdle()),
             this, SLOT(enableMenu()));
 }
+
+
+void MainWindow::connectBookmarksWidget() {
+    #ifdef Q_WS_MAEMO_5
+        //after removing bookmarks we search for it once again to clear word list
+        connect(bookmarksWidget, SIGNAL(removeAllBookmarks()),
+                backbone, SLOT(removeAllBookmark()));
+
+        connect(bookmarksWidget, SIGNAL(removeAllBookmarks()),
+                backbone, SLOT(fetchBookmarks()));
+
+
+        connect(bookmarksWidget, SIGNAL(showAllBookmarks()),
+                menuWidget, SLOT(hideMenu()));
+
+        connect(bookmarksWidget, SIGNAL(showAllBookmarks()),
+                backbone, SLOT(fetchBookmarks()));
+
+
+    #else
+        connect(bookmarksShowAllAction, SIGNAL(triggered()),
+                backbone, SLOT(fetchBookmarks()));
+
+        connect(bookmarksRemoveAllAction, SIGNAL(triggered()),
+                backbone, SLOT(removeAllBookmark()));
+
+        connect(bookmarksRemoveAllAction, SIGNAL(triggered()),
+                backbone, SLOT(fetchBookmarks()));
+    #endif
+}