First version
This commit is contained in:
15
src/frames/aboutdialog.cpp
Executable file
15
src/frames/aboutdialog.cpp
Executable file
@@ -0,0 +1,15 @@
|
||||
#include "aboutdialog.h"
|
||||
#include "ui_aboutdialog.h"
|
||||
|
||||
AboutDialog::AboutDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::AboutDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->appNameLabel->setText(QString("TaskNote (%1)").arg(QSysInfo::currentCpuArchitecture()));
|
||||
}
|
||||
|
||||
AboutDialog::~AboutDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
23
src/frames/aboutdialog.h
Executable file
23
src/frames/aboutdialog.h
Executable file
@@ -0,0 +1,23 @@
|
||||
#ifndef ABOUTDIALOG_H
|
||||
#define ABOUTDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QSysInfo>
|
||||
|
||||
namespace Ui {
|
||||
class AboutDialog;
|
||||
}
|
||||
|
||||
class AboutDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AboutDialog(QWidget *parent = nullptr);
|
||||
~AboutDialog();
|
||||
|
||||
private:
|
||||
Ui::AboutDialog *ui;
|
||||
};
|
||||
|
||||
#endif // ABOUTDIALOG_H
|
||||
97
src/frames/aboutdialog.ui
Executable file
97
src/frames/aboutdialog.ui
Executable file
@@ -0,0 +1,97 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AboutDialog</class>
|
||||
<widget class="QDialog" name="AboutDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>334</width>
|
||||
<height>180</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>334</width>
|
||||
<height>180</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>334</width>
|
||||
<height>180</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>About TaskNote</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>64</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>64</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">image: url(:/logo/resources/logo.png);</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="appNameLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>14</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TaskNote</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Version 1.1.0.0</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Author: Aurélie Delhaie (aureliedelhaie.fr)</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
133
src/frames/mainwindow.cpp
Executable file
133
src/frames/mainwindow.cpp
Executable file
@@ -0,0 +1,133 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
timer = new QTimer(this);
|
||||
connect(ui->actionAdd, &QAction::triggered, this, &MainWindow::createNote);
|
||||
connect(ui->actionRemove, &QAction::triggered, this, &MainWindow::removeSelected);
|
||||
connect(ui->actionSave, &QAction::triggered, this, &MainWindow::save);
|
||||
connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::showAboutBox);
|
||||
connect(ui->noteList, &QListWidget::currentRowChanged, this, &MainWindow::selectionChanged);
|
||||
connect(ui->titleEdit, &QLineEdit::textChanged, this, &MainWindow::titleChanged);
|
||||
connect(ui->contentEdit, &QPlainTextEdit::textChanged, this, &MainWindow::contentChanged);
|
||||
const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
|
||||
ui->contentEdit->setFont(fixedFont);
|
||||
this->savemng = new SaveManager();
|
||||
updateListView();
|
||||
connect(timer, &QTimer::timeout, this, &MainWindow::save);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete timer;
|
||||
delete savemng;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::createNote()
|
||||
{
|
||||
Note *n = new Note();
|
||||
n->setTitle("untitled note");
|
||||
savemng->addNote(n);
|
||||
updateListView();
|
||||
}
|
||||
|
||||
void MainWindow::selectionChanged(int i)
|
||||
{
|
||||
this->currentIndex = i;
|
||||
if (i == -1)
|
||||
{
|
||||
clearAndDisableFields();
|
||||
return;
|
||||
}
|
||||
Note *n = this->savemng->getNoteByIndex(i);
|
||||
if (n == nullptr)
|
||||
{
|
||||
QMessageBox::critical(this, tr("TaskNote"), "Failed to get this note, the memory pointer is empty", QMessageBox::Ok, QMessageBox::Ok);
|
||||
clearAndDisableFields();
|
||||
return;
|
||||
}
|
||||
ui->actionRemove->setDisabled(false);
|
||||
ui->titleEdit->setDisabled(false);
|
||||
ui->contentEdit->setDisabled(false);
|
||||
ui->titleEdit->setText(n->getTitle());
|
||||
ui->contentEdit->setPlainText(n->getContent());
|
||||
ui->markdownViewer->setMarkdown(n->getContent());
|
||||
}
|
||||
|
||||
void MainWindow::removeSelected()
|
||||
{
|
||||
if (this->currentIndex > -1)
|
||||
{
|
||||
this->savemng->removeNoteByIndex(this->currentIndex);
|
||||
clearAndDisableFields();
|
||||
updateListView();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::save()
|
||||
{
|
||||
if (this->currentIndex > -1)
|
||||
{
|
||||
Note *n = this->savemng->getNoteByIndex(this->currentIndex);
|
||||
n->setTitle(ui->titleEdit->text());
|
||||
n->setContent(ui->contentEdit->toPlainText());
|
||||
}
|
||||
this->savemng->flushSave();
|
||||
}
|
||||
|
||||
void MainWindow::titleChanged()
|
||||
{
|
||||
timer->stop();
|
||||
if (this->currentIndex > -1)
|
||||
{
|
||||
Note *n = this->savemng->getNoteByIndex(this->currentIndex);
|
||||
n->setTitle(ui->titleEdit->text());
|
||||
ui->noteList->item(this->currentIndex)->setText(ui->titleEdit->text());
|
||||
}
|
||||
timer->start(1000);
|
||||
}
|
||||
|
||||
void MainWindow::showAboutBox()
|
||||
{
|
||||
AboutDialog dialog;
|
||||
dialog.setModal(true);
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
void MainWindow::contentChanged()
|
||||
{
|
||||
timer->stop();
|
||||
if (this->currentIndex > -1)
|
||||
{
|
||||
Note *n = this->savemng->getNoteByIndex(this->currentIndex);
|
||||
n->setContent(ui->contentEdit->toPlainText());
|
||||
ui->markdownViewer->setMarkdown(ui->contentEdit->toPlainText());
|
||||
}
|
||||
timer->start(1000);
|
||||
}
|
||||
|
||||
void MainWindow::updateListView()
|
||||
{
|
||||
ui->noteList->clear();
|
||||
foreach (Note *n, savemng->getNotes())
|
||||
{
|
||||
ui->noteList->addItem(n->getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::clearAndDisableFields()
|
||||
{
|
||||
this->currentIndex = -1;
|
||||
ui->actionRemove->setDisabled(true);
|
||||
ui->titleEdit->setDisabled(true);
|
||||
ui->contentEdit->setDisabled(true);
|
||||
ui->titleEdit->clear();
|
||||
ui->contentEdit->clear();
|
||||
ui->markdownViewer->clear();
|
||||
}
|
||||
|
||||
44
src/frames/mainwindow.h
Executable file
44
src/frames/mainwindow.h
Executable file
@@ -0,0 +1,44 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
|
||||
#include "../services/savemanager.h"
|
||||
#include "aboutdialog.h"
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class MainWindow; }
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
private slots:
|
||||
void createNote();
|
||||
void selectionChanged(int);
|
||||
void removeSelected();
|
||||
void save();
|
||||
void contentChanged();
|
||||
void titleChanged();
|
||||
void showAboutBox();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
SaveManager *savemng;
|
||||
QTimer *timer;
|
||||
|
||||
int currentIndex = -1;
|
||||
|
||||
void updateListView();
|
||||
void clearAndDisableFields();
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
189
src/frames/mainwindow.ui
Executable file
189
src/frames/mainwindow.ui
Executable file
@@ -0,0 +1,189 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1075</width>
|
||||
<height>710</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>1075</width>
|
||||
<height>710</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>TaskNote</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QListWidget" name="noteList">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>250</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>13</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Title</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="titleEdit">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Markdown editor</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Viewer</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="contentEdit">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="markdownViewer">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="autoFormatting">
|
||||
<set>QTextEdit::AutoAll</set>
|
||||
</property>
|
||||
<property name="lineWrapMode">
|
||||
<enum>QTextEdit::WidgetWidth</enum>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="acceptRichText">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="toolBar">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>33</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>toolBar</string>
|
||||
</property>
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="actionAdd"/>
|
||||
<addaction name="actionRemove"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionSave"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionAbout"/>
|
||||
</widget>
|
||||
<action name="actionAdd">
|
||||
<property name="icon">
|
||||
<iconset resource="../../icons.qrc">
|
||||
<normaloff>:/icon/resources/outline_add_circle_outline_black_18dp.png</normaloff>:/icon/resources/outline_add_circle_outline_black_18dp.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRemove">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../icons.qrc">
|
||||
<normaloff>:/icon/resources/outline_delete_forever_black_18dp.png</normaloff>:/icon/resources/outline_delete_forever_black_18dp.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSave">
|
||||
<property name="icon">
|
||||
<iconset resource="../../icons.qrc">
|
||||
<normaloff>:/icon/resources/outline_save_black_18dp.png</normaloff>:/icon/resources/outline_save_black_18dp.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAbout">
|
||||
<property name="icon">
|
||||
<iconset resource="../../icons.qrc">
|
||||
<normaloff>:/icon/resources/outline_help_outline_black_18dp.png</normaloff>:/icon/resources/outline_help_outline_black_18dp.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>About</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../icons.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user