aboutsummaryrefslogtreecommitdiff
path: root/mainwindow.cc
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2015-06-07 21:22:45 +0200
committerJavier <dev.git@javispedro.com>2015-06-07 21:22:45 +0200
commita69e97943539a8abc4d2762638c169dc19c88516 (patch)
treef3516ea29745db65971247cee4c260b49f1067b2 /mainwindow.cc
downloadscribiu-a69e97943539a8abc4d2762638c169dc19c88516.tar.gz
scribiu-a69e97943539a8abc4d2762638c169dc19c88516.zip
initial import
Diffstat (limited to 'mainwindow.cc')
-rw-r--r--mainwindow.cc66
1 files changed, 66 insertions, 0 deletions
diff --git a/mainwindow.cc b/mainwindow.cc
new file mode 100644
index 0000000..793a722
--- /dev/null
+++ b/mainwindow.cc
@@ -0,0 +1,66 @@
+#include <QtCore/QDebug>
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+MainWindow::MainWindow(QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::MainWindow),
+ _notebooks(new NotebookModel(this)),
+ _manager(new SmartpenManager(this))
+{
+ ui->setupUi(this);
+ ui->notebookTree->setModel(_notebooks);
+ ui->notebookTree->header()->setResizeMode(0, QHeaderView::Stretch);
+ ui->notebookTree->header()->setResizeMode(1, QHeaderView::Fixed);
+ ui->notebookTree->header()->setResizeMode(2, QHeaderView::Fixed);
+ ui->notebookTree->expandAll();
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
+
+void MainWindow::closeNotebook()
+{
+ _curPenName.clear();
+ _curNotebookName.clear();
+ ui->notebookView->setNotebook(QString());
+}
+
+void MainWindow::openNotebook(const QString &pen, const QString &notebook)
+{
+ if (_curPenName == pen && _curNotebookName == notebook) return;
+
+ _curPenName = pen;
+ _curNotebookName = notebook;
+
+ QString nbDir = _notebooks->notebookDirectory(_curPenName, _curNotebookName);
+
+ qDebug() << "Opening notebook" << _curPenName << _curNotebookName << nbDir;
+
+ ui->notebookView->setNotebook(nbDir);
+}
+
+void MainWindow::handleNotebookSelected(const QModelIndex &index)
+{
+ if (!index.isValid()) {
+ closeNotebook();
+ return;
+ }
+ QModelIndex parent = index.parent();
+ if (!parent.isValid()) {
+ closeNotebook();
+ return;
+ }
+
+ QModelIndex child = parent.child(index.row(), 0);
+
+ openNotebook(_notebooks->data(parent, Qt::DisplayRole).toString(),
+ _notebooks->data(child, Qt::DisplayRole).toString());
+}
+
+void MainWindow::handleCurPageChanged()
+{
+ ui->pageEdit->setText(QString::number(ui->notebookView->curPage() + 1));
+}