aboutsummaryrefslogtreecommitdiff
path: root/mainwindow.cc
blob: 793a722352ca188a552ce60b94a062e0db72fecf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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));
}