Skip to content

Commit

Permalink
[feat] add text formatting shorcuts
Browse files Browse the repository at this point in the history
Add keyboard and button shortcuts for bold, italic and strikethrough.
  • Loading branch information
bgallois committed Nov 29, 2021
1 parent 7ab9ab0 commit 90d58f1
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 91 deletions.
26 changes: 25 additions & 1 deletion docs/source/shortcut.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ Keyboard shortcuts
Markdown features
-----------------

Bold text
~~~~~~~~~
.. code-block:: markdown
CTRL + Key_B
If a text is selected, it will be set as bold. If no text selected, cursor will be placed between balises.

Italic text
~~~~~~~~~~~
.. code-block:: markdown
CTRL + Key_I
If a text is selected, it will be set as bold. If no text selected, cursor will be placed between balises.

Strikethrough text
~~~~~~~~~~~~~~~~~~
.. code-block:: markdown
CTRL + Key_S
If a text is selected, it will be set as bold. If no text selected, cursor will be placed between balises.

Insert to-do list
~~~~~~~~~~~~~~~~~
.. code-block:: markdown
Expand Down Expand Up @@ -41,7 +65,7 @@ Insert image
~~~~~~~~~~~~
.. code-block:: markdown
CTRL + Key_I
CTRL + Key_SHIFT + Key_I
If a text is selected, it will be passed as as path.

Expand Down
Binary file added resources/bold.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/italic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions resources/openjournal.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<file>clocks.png</file>
<file>lock.png</file>
<file>icon.png</file>
<file>bold.png</file>
<file>italic.png</file>
<file>strikethrough.png</file>
<file>todo.png</file>
<file>table.png</file>
<file>link.png</file>
Expand Down
Binary file modified resources/readme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/strikethrough.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 39 additions & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,30 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
ui->toolBar->addAction(actionAddAlarm);
ui->toolBar->addSeparator();

keySequence = QKeySequence(Qt::CTRL + Qt::Key_B);
QAction *actionBoldTemplate = new QAction(QIcon(":/bold.png"), tr("Bold ") + keySequence.toString(), this);
actionBoldTemplate->setShortcut(keySequence);
connect(actionBoldTemplate, &QAction::triggered, [this]() {
insertFormattingTemplate("**");
});
ui->toolBar->addAction(actionBoldTemplate);

keySequence = QKeySequence(Qt::CTRL + Qt::Key_I);
QAction *actionItalicTemplate = new QAction(QIcon(":/italic.png"), tr("Italic ") + keySequence.toString(), this);
actionItalicTemplate->setShortcut(keySequence);
connect(actionItalicTemplate, &QAction::triggered, [this]() {
insertFormattingTemplate("*");
});
ui->toolBar->addAction(actionItalicTemplate);

keySequence = QKeySequence(Qt::CTRL + Qt::Key_S);
QAction *actionStrikeTemplate = new QAction(QIcon(":/strikethrough.png"), tr("Strikethrough ") + keySequence.toString(), this);
actionStrikeTemplate->setShortcut(keySequence);
connect(actionStrikeTemplate, &QAction::triggered, [this]() {
insertFormattingTemplate("~~");
});
ui->toolBar->addAction(actionStrikeTemplate);

keySequence = QKeySequence(Qt::CTRL + Qt::Key_D);
QAction *actionToDoTemplate = new QAction(QIcon(":/todo.png"), tr("To do list template ") + keySequence.toString(), this);
actionToDoTemplate->setShortcut(keySequence);
Expand Down Expand Up @@ -242,7 +266,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
connect(actionLinkTemplate, &QAction::triggered, this, &MainWindow::insertLinkTemplate);
ui->toolBar->addAction(actionLinkTemplate);

keySequence = QKeySequence(Qt::CTRL + Qt::Key_I);
keySequence = QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_I);
QAction *actionImageTemplate = new QAction(QIcon(":/image.png"), tr("Image template ") + keySequence.toString(), this);
actionImageTemplate->setShortcut(keySequence);
connect(actionImageTemplate, &QAction::triggered, this, &MainWindow::insertImageTemplate);
Expand Down Expand Up @@ -643,6 +667,20 @@ void MainWindow::about() {
QMessageBox::about(this, tr("About OpenJournal"), QString("<p align='center'><big><b>%1 %2</b></big><br/>%3<br/><small>%4<br/>%5</small></p>").arg(tr("OpenJournal"), QApplication::applicationVersion(), tr("A simple note taking journal, planner, reminder and Markdown editor."), tr("Copyright &copy; 2019-%1 Benjamin Gallois").arg("2021"), tr("Released under the <a href=%1>GPL 2</a> license").arg("\"https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html\"")));
}

void MainWindow::insertFormattingTemplate(QString balise) {
if (ui->entry->isEnabled()) {
QTextCursor cursor = ui->entry->textCursor();
if (cursor.hasSelection()) {
ui->entry->insertPlainText(balise + cursor.selectedText() + balise);
}
else {
ui->entry->insertPlainText(balise + cursor.selectedText() + balise);
cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, balise.size());
}
ui->entry->setTextCursor(cursor);
}
}

void MainWindow::insertToDoTemplate() {
if (ui->entry->isEnabled()) {
QTextCursor cursor = ui->entry->textCursor();
Expand Down
1 change: 1 addition & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class MainWindow : public QMainWindow {
void setTodayReminder(const QString text, QMap<QString, QTimer *> &reminders);
bool eventFilter(QObject *obj, QEvent *event);
void about();
void insertFormattingTemplate(QString balise);
void insertToDoTemplate();
void insertTableTemplate();
void insertLinkTemplate();
Expand Down
107 changes: 61 additions & 46 deletions translations/openjournal_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ p, li { white-space: pre-wrap; }
<name>MainWindow</name>
<message>
<location filename="../src/mainwindow.ui" line="17"/>
<location filename="../src/mainwindow.cpp" line="643"/>
<location filename="../src/mainwindow.cpp" line="667"/>
<source>OpenJournal</source>
<translation type="unfinished"></translation>
</message>
Expand Down Expand Up @@ -236,9 +236,9 @@ databaseusername@hostname:port</source>
<message>
<location filename="../src/mainwindow.cpp" line="143"/>
<location filename="../src/mainwindow.cpp" line="155"/>
<location filename="../src/mainwindow.cpp" line="346"/>
<location filename="../src/mainwindow.cpp" line="391"/>
<location filename="../src/mainwindow.cpp" line="444"/>
<location filename="../src/mainwindow.cpp" line="370"/>
<location filename="../src/mainwindow.cpp" line="415"/>
<location filename="../src/mainwindow.cpp" line="468"/>
<source>No journal is opened</source>
<translation type="unfinished"></translation>
</message>
Expand All @@ -249,176 +249,191 @@ databaseusername@hostname:port</source>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="216"/>
<source>Bold </source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="224"/>
<source>Italic </source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="232"/>
<source>Strikethrough </source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="240"/>
<source>To do list template </source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="222"/>
<location filename="../src/mainwindow.cpp" line="246"/>
<source>Numbered list </source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="228"/>
<location filename="../src/mainwindow.cpp" line="252"/>
<source>Unordered list </source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="234"/>
<location filename="../src/mainwindow.cpp" line="258"/>
<source>Table template </source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="240"/>
<location filename="../src/mainwindow.cpp" line="264"/>
<source>URL template </source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="246"/>
<location filename="../src/mainwindow.cpp" line="270"/>
<source>Image template </source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="252"/>
<location filename="../src/mainwindow.cpp" line="276"/>
<source>Formula template </source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="259"/>
<location filename="../src/mainwindow.cpp" line="283"/>
<source>Lock journal </source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="266"/>
<location filename="../src/mainwindow.cpp" line="290"/>
<source>The journal is locked</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="269"/>
<location filename="../src/mainwindow.cpp" line="293"/>
<source>The journal is unlocked</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="308"/>
<location filename="../src/mainwindow.cpp" line="332"/>
<source>Private mode</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="327"/>
<location filename="../src/mainwindow.cpp" line="351"/>
<source>Alarm Sound</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="354"/>
<location filename="../src/mainwindow.cpp" line="378"/>
<source>Save new journal</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="354"/>
<location filename="../src/mainwindow.cpp" line="386"/>
<location filename="../src/mainwindow.cpp" line="378"/>
<location filename="../src/mainwindow.cpp" line="410"/>
<source>Journal (*.jnl)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="369"/>
<location filename="../src/mainwindow.cpp" line="393"/>
<source> journal cannot be created</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="373"/>
<location filename="../src/mainwindow.cpp" line="407"/>
<location filename="../src/mainwindow.cpp" line="437"/>
<location filename="../src/mainwindow.cpp" line="397"/>
<location filename="../src/mainwindow.cpp" line="431"/>
<location filename="../src/mainwindow.cpp" line="461"/>
<source> journal is opened</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="386"/>
<location filename="../src/mainwindow.cpp" line="410"/>
<source>Open journal</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="399"/>
<location filename="../src/mainwindow.cpp" line="423"/>
<source> journal failed to open</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="422"/>
<location filename="../src/mainwindow.cpp" line="446"/>
<source>Authentification failed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="473"/>
<location filename="../src/mainwindow.cpp" line="497"/>
<source>Journal was backed up </source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="478"/>
<location filename="../src/mainwindow.cpp" line="502"/>
<source>Cannot back up journal</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="507"/>
<location filename="../src/mainwindow.cpp" line="531"/>
<source>Hey!</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="507"/>
<location filename="../src/mainwindow.cpp" line="531"/>
<source>I&apos;m there</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="537"/>
<location filename="../src/mainwindow.cpp" line="561"/>
<source>Notification</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="571"/>
<location filename="../src/mainwindow.cpp" line="598"/>
<location filename="../src/mainwindow.cpp" line="595"/>
<location filename="../src/mainwindow.cpp" line="622"/>
<source>Select file</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="571"/>
<location filename="../src/mainwindow.cpp" line="584"/>
<location filename="../src/mainwindow.cpp" line="595"/>
<location filename="../src/mainwindow.cpp" line="608"/>
<source>Pdf Files (*.pdf)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="584"/>
<location filename="../src/mainwindow.cpp" line="608"/>
<source>Save file</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="615"/>
<location filename="../src/mainwindow.cpp" line="639"/>
<source>Open file</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="598"/>
<location filename="../src/mainwindow.cpp" line="615"/>
<location filename="../src/mainwindow.cpp" line="667"/>
<source>Released under the &lt;a href=%1&gt;GPL 2&lt;/a&gt; license</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="622"/>
<location filename="../src/mainwindow.cpp" line="639"/>
<source>Markdown Files (*.md)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.ui" line="306"/>
<location filename="../src/mainwindow.cpp" line="643"/>
<location filename="../src/mainwindow.cpp" line="667"/>
<source>About OpenJournal</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="643"/>
<location filename="../src/mainwindow.cpp" line="667"/>
<source>A simple note taking journal, planner, reminder and Markdown editor.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="643"/>
<location filename="../src/mainwindow.cpp" line="667"/>
<source>Copyright &amp;copy; 2019-%1 Benjamin Gallois</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="643"/>
<source>Released under the &lt;a href=%1&gt;GPL 3&lt;/a&gt; license</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>QPlainTextEditSearchWidget</name>
Expand Down
Loading

0 comments on commit 90d58f1

Please sign in to comment.