Loading books from a folder, library view and bug fixes.
[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     Book *book = new Book(filename);
8     MainWindow(book, parent);
9 }
10
11 MainWindow::MainWindow(Book *book, QWidget *parent) : QMainWindow(parent)
12 {
13     bookView = new BookView(this);
14     setCentralWidget(bookView); 
15
16     currentBook = book;
17
18     bookView->setBook(book);
19
20     bookView->installEventFilter(this);
21
22     toolbar = new QToolBar("toolbar", this);
23     QAction *tocAction = toolbar->addAction("TOC");
24     connect(tocAction, SIGNAL(triggered()), this, SLOT(tocNavigation()));
25
26     setAttribute(Qt::WA_Maemo5StackedWindow);
27     addToolBar(toolbar);
28 }
29
30 MainWindow::~MainWindow()
31 {
32
33 }
34
35 void MainWindow::setFont(const QString &family, int size)
36 {
37     if(bookView)
38         bookView->setFont(family, size);
39 }
40
41 bool MainWindow::eventFilter(QObject *object, QEvent *event)
42 {
43     if(event->type() == QEvent::MouseButtonDblClick)
44     {
45         if(!isFullScreen()){
46             showFullScreen();
47             toolbar->hide();            
48         }
49         else{
50             showNormal();
51             toolbar->show();
52         }
53     }else {
54         return QObject::eventFilter(object, event);
55     }
56 }
57
58
59 void MainWindow::tocNavigation()
60 {
61     QList<QString> toc = currentBook->getTOC();
62     dialog = new SelectorDialog(toc, this);
63     dialog->setAttribute(Qt::WA_Maemo5StackedWindow);
64     dialog->setWindowFlags(dialog->windowFlags() | Qt::Window);
65     connect(dialog, SIGNAL(selectedString(QString)), bookView, SLOT(goToChapter(QString)));
66     dialog->show();
67
68
69 }