#include "MainWindow.h"
#include "ui_MainWindow.h"
+#include <QtGui>
#ifdef Q_WS_MAEMO_5
#include <QMaemo5InformationBox>
#endif
+
MainWindow::MainWindow(Backbone *backbone, QWidget *parent):
GUIInterface(parent),
ui(new Ui::MainWindow) {
this->backbone = backbone;
+ initializeUI();
+
+ connectBackbone();
+ connectSearchBar();
+ connectWordList();
+ connectTranslationWidget();
+ connectDictManager();
+ connectMenu();
+ connectBookmarksWidget();
+
+
+ setExactSearch(false);
+
+ setWindowTitle("mDictionary");
+
+ showMaximized();
+}
+
+MainWindow::~MainWindow() {
+ delete ui;
+}
+
+
+void MainWindow::initializeUI() {
ui->setupUi(this);
#ifdef Q_WS_MAEMO_5
setAttribute(Qt::WA_Maemo5StackedWindow);
#endif
-
-
searchBarWidget = new SearchBarWidget;
+
wordListWidget = new WordListWidget;
+
+ //translationWidget is antoher stacked window, so we don't add it to layout
+ //only create it with this widget as parent
translationWidget = new TranslationWidget(this);
- ui->centralWidget->layout()->addWidget(wordListWidget);
- ui->centralWidget->layout()->addWidget(searchBarWidget);
+ welcomeScreenWidget = new WelcomeScreenWidget;
+
+
+ #ifdef Q_WS_MAEMO_5
+ //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(welcomeScreenWidget);
+ splitter->setStretchFactor(1, 150);
+ ui->centralWidget->layout()->addWidget(splitter);
+ ui->centralWidget->layout()->addWidget(searchBarWidget);
+ #endif
dictManagerWidget = new DictManagerWidget(this);
+ dictManagerWidget->hide();
- menuWidget = new MenuWidget(this);
- menuWidget->addSubMenu(tr("Dictionaries"), dictManagerWidget);
- menuWidget->addSubMenu(tr("Settings"), new QPushButton("Settings"));
- menuWidget->addSubMenu(tr("About"), new QPushButton("About"));
+ settingsWidget = new SettingsWidget(this);
+ settingsWidget->hide();
- ui->menuBar->addAction(menuWidget);
+ bookmarksWidget = new BookmarksWidget(this);
+ bookmarksWidget->hide();
- connectBackbone();
- connectSearchBar();
- connectWordList();
- connectTranslationWidget();
- connectDictManager();
- connectMenu();
+ aboutWidget = new AboutWidget(this);
+ aboutWidget->hide();
- setExactSearch(false);
- setWindowTitle("mDictionary");
-}
+ //creating menus
-MainWindow::~MainWindow() {
- delete ui;
-}
+ #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
+ dictionariesAction = ui->menuBar->addAction(tr("Dictionaries"));
+ connect(dictionariesAction, SIGNAL(triggered()),
+ dictManagerWidget, SLOT(show()));
+
+ settingsAction = ui->menuBar->addAction(tr("Settings"));
+ 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()));
+ #endif
+}
void MainWindow::closeEvent(QCloseEvent *event) {
+ //reqest to stop all searches and close app
emit quit();
event->accept();
}
}
void MainWindow::wordListReady() {
+ //gets results from backbone
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
QMaemo5InformationBox::information(this,
tr("Can't find any matching words"),
QMaemo5InformationBox::DefaultTimeout);
#endif
-
+ //show empty list to remove results of old search
emit showWordList(searchResult);
}
else {
-
+ //find translations of the same key word
QMultiHash<QString, Translation*>::iterator i;
for(i = res.begin(); i != res.end(); i++) {
searchResult[i.key()].push_back(i.value());
emit showWordList(searchResult);
}
else {
-
+ #ifndef Q_WS_MAEMO_5
+ //on desktop we show word list in exact search
+ emit showWordList(searchResult);
+ #endif
bool foundExactMatch = false;
QHash<QString, QList<Translation*> >::iterator j;
for(j = searchResult.begin(); j != searchResult.end(); j++) {
}
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());
}
void MainWindow::searchExact(QString word) {
setExactSearch(true);
+ //searching with searchBar, not directly by emiting searchWordList(),
+ //because it will set search word in searchBar's edit line
+ //this function is only used by history and when searching from attributes
searchBarWidget->search(word);
}
+
+
void MainWindow::breakSearching() {
+ //make sure to unset exact search mode
setExactSearch(false);
}
void MainWindow::historyNext() {
if(backbone->history()->nextAvailable()) {
QString next = backbone->history()->next();
- searchExact(next);
+ #ifndef Q_WS_MAEMO_5
+ setExactSearch(true);
+ #endif
+ searchBarWidget->searchDelay(next);
}
}
void MainWindow::historyPrev() {
if(backbone->history()->prevAvailable()) {
+ #ifndef Q_WS_MAEMO_5
+ setExactSearch(true);
+ #endif
QString prev = backbone->history()->previous();
- searchExact(prev);
+ searchBarWidget->searchDelay(prev);
}
}
void MainWindow::disableMenu() {
- if(ui->menuBar->actions().contains(menuWidget)) {
- ui->menuBar->removeAction(menuWidget);
- }
+ #ifdef Q_WS_MAEMO_5
+ if(ui->menuBar->actions().contains(menuWidget)) {
+ ui->menuBar->removeAction(menuWidget);
+ }
+ #else
+ ui->menuBar->setEnabled(false);
+ #endif
}
void MainWindow::enableMenu() {
- if(!ui->menuBar->actions().contains(menuWidget)) {
- ui->menuBar->addAction(menuWidget);
- }
+ #ifdef Q_WS_MAEMO_5
+ if(!ui->menuBar->actions().contains(menuWidget)) {
+ ui->menuBar->addAction(menuWidget);
+ }
+ #else
+ ui->menuBar->setEnabled(true);
+ #endif
}
void MainWindow::showHistory() {
}
}
+void MainWindow::setSettings(Settings *s) {
+ backbone->setSettings(s);
+}
+
+Settings* MainWindow::settings() {
+ return backbone->settings();
+}
+
void MainWindow::connectBackbone() {
connect(this, SIGNAL(quit()),
backbone, SLOT(quit()));
connect(backbone, SIGNAL(htmlReady()),
this, SLOT(translationsReady()));
+ connect(backbone, SIGNAL(searchCanceled()),
+ this, SIGNAL(setIdle()));
+
this, SIGNAL(searchTranslations(QList<Translation*>)));
+
+
connect(this, SIGNAL(setBusy()),
wordListWidget, SLOT(lockList()));
connect(this, SIGNAL(setIdle()),
wordListWidget, SLOT(unlockList()));
+
+ connect(wordListWidget, SIGNAL(addBookmark(QList<Translation*>)),
+ backbone, SLOT(addBookmark(QList<Translation*>)));
+
+ connect(wordListWidget, SIGNAL(removeBookmark(QList<Translation*>)),
+ backbone, SLOT(removeBookmark(QList<Translation*>)));
}
void MainWindow::connectTranslationWidget() {
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
+}