Fullscreen mode enabled by doubletapping.
[mebook:mebook.git] / ui / mainwindow.cpp
1 #include "mainwindow.h"
2 #include "selectordialog.h"
3 #include <QAction>
4
5 MainWindow::MainWindow(const QString &filename, QWidget *parent) : QMainWindow(parent)
6 {
7     bookView = new BookView(this);
8     setCentralWidget(bookView); 
9
10     Book *book = new Book();
11     book->openBook(filename);
12     currentBook = book;
13
14     bookView->setBook(book);
15
16     bookView->installEventFilter(this);
17
18     toolbar = new QToolBar("toolbar", this);
19     QAction *tocAction = toolbar->addAction("TOC");
20     connect(tocAction, SIGNAL(triggered()), this, SLOT(tocNavigation()));
21
22     setAttribute(Qt::WA_Maemo5StackedWindow);
23     addToolBar(toolbar);
24 }
25
26 MainWindow::~MainWindow()
27 {
28
29 }
30
31 bool MainWindow::eventFilter(QObject *object, QEvent *event)
32 {
33     if(event->type() == QEvent::MouseButtonDblClick)
34     {
35         if(!isFullScreen()){
36             showFullScreen();
37             toolbar->hide();            
38         }
39         else{
40             showNormal();
41             toolbar->show();
42         }
43     }else {
44         return QObject::eventFilter(object, event);
45     }
46 }
47
48
49 void MainWindow::tocNavigation()
50 {
51     QList<QString> toc = currentBook->getTOC();
52     dialog = new SelectorDialog(toc, this);
53     dialog->setAttribute(Qt::WA_Maemo5StackedWindow);
54     dialog->setWindowFlags(dialog->windowFlags() | Qt::Window);
55     connect(dialog, SIGNAL(selectedString(QString)), bookView, SLOT(goToChapter(QString)));
56     dialog->show();
57
58
59 }