summaryrefslogtreecommitdiffstatshomepage
path: root/NoteEditor.cpp
blob: bddfd5ca4268bb23941f9008ea461a7c86575005 (plain) (blame)
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
#include "NoteEditor.h"
#include "Instructions.h"
#include <QTextEdit>
#include <QToolBar>
#include <QAction>
#include <QDockWidget>
#include <QMessageBox>
#include <QCloseEvent>
#include <QApplication>
#include <QSettings>
#include <QDebug>

NoteEditor::NoteEditor(const QString &title, QWidget *parent) :
	QMainWindow(parent)
{
	setWindowTitle(tr("Author - Note Editor"));
	setUnifiedTitleAndToolBarOnMac(true);

	m_editor = new QTextEdit;
	m_editor->setFontFamily("CMU Typewriter Text Variable Width");
	m_editor->setText("<h2><font face=\"CMU Typewriter Text Variable Width\">" + title + "</font></h2><p><font face=\"CMU Typewriter Text Variable Width\">" + tr("notes...") + "</font></p>");
	setCentralWidget(m_editor);

	QDockWidget *sideInstructions = new QDockWidget(tr("Instructions"));
	sideInstructions->setWidget(new Instructions(1, false));
	addDockWidget(Qt::RightDockWidgetArea, sideInstructions);

	QToolBar *toolbar = new QToolBar(tr("Editing"));
	toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
	addToolBar(Qt::TopToolBarArea, toolbar);
	connect(toolbar->addAction(QIcon(QLatin1String(":/journal.png")), tr("Begin Writing")), SIGNAL(triggered()), this, SIGNAL(finished()));
}
QString NoteEditor::html() const
{
	return m_editor->toHtml();
}
void NoteEditor::closeEvent(QCloseEvent *event)
{
	if (QMessageBox::question(this, tr("Quit?"), tr("You are still writing. Are you sure you'd like to quit?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)
		QApplication::quit();
	else
		event->ignore();
}
QSize NoteEditor::sizeHint() const
{
	return QSize(900, 900);
}
void NoteEditor::saveState(const QString &key) const
{
	QSettings s;
	s.setValue(key.arg(QLatin1String("html")), m_editor->toHtml());
}
void NoteEditor::restoreState(const QString &key)
{
	QSettings s;
	m_editor->setHtml(s.value(key.arg(QLatin1String("html"))).toString());
}
void NoteEditor::finish()
{
	emit finished();
}