diff --git a/src/core/coreconfig.h b/src/core/coreconfig.h index b3a0d804..71d61806 100644 --- a/src/core/coreconfig.h +++ b/src/core/coreconfig.h @@ -16,6 +16,7 @@ namespace vnotex enum Shortcut { FullScreen, + StayOnTop, ExpandContentArea, Settings, NewNote, diff --git a/src/core/viewerresource.h b/src/core/viewerresource.h index ea05d658..795d8a78 100644 --- a/src/core/viewerresource.h +++ b/src/core/viewerresource.h @@ -20,13 +20,13 @@ namespace vnotex m_styles.clear(); auto stylesArray = p_obj[QStringLiteral("styles")].toArray(); - for (size_t i = 0; i < stylesArray.size(); ++i) { + for (int i = 0; i < stylesArray.size(); ++i) { m_styles << stylesArray[i].toString(); } m_scripts.clear(); auto scriptsArray = p_obj[QStringLiteral("scripts")].toArray(); - for (size_t i = 0; i < scriptsArray.size(); ++i) { + for (int i = 0; i < scriptsArray.size(); ++i) { m_scripts << scriptsArray[i].toString(); } } diff --git a/src/data/core/vnotex.json b/src/data/core/vnotex.json index 2c3fc5d4..7dd479c9 100644 --- a/src/data/core/vnotex.json +++ b/src/data/core/vnotex.json @@ -10,6 +10,7 @@ "locale" : "", "shortcuts" : { "FullScreen" : "F11", + "StayOnTop" : "F10", "ExpandContentArea" : "Ctrl+G, E", "Settings" : "Ctrl+Alt+P", "NewNote" : "Ctrl+Alt+N", diff --git a/src/data/extra/docs/en/markdown_guide.md b/src/data/extra/docs/en/markdown_guide.md new file mode 100644 index 00000000..72920b64 --- /dev/null +++ b/src/data/extra/docs/en/markdown_guide.md @@ -0,0 +1,250 @@ +# Markdown Guide +This is a quick guide [^1] for Markdown, a lightweight and easy-to-use syntax for writing. + +## What is Markdown? +Markdown is a way to style text via a few simple markers. You could write the document in plain text and then read it with a beautiful typesetting. + +There is no standard Markdown syntax and many editors will support its own additional syntax. VNote supports only the widely-used basic syntax. + +## How to Use Markdown? +If you are new to Markdown, it is better to learn the syntax elements step by step. Knowing headers and emphasis is enough to survive. You could learn another new syntax and practise it every one or two days. + +## Syntax Guide +Here is an overview of Markdown syntax supported by VNote. + +### Headers +```md +# This is a

tag +## This is a

tag +###### This is a

tag +``` + +**Notes**: + +* At least one space is needed after the `#`; +* A header should occupy one entire line; + +### Emphasis +```md +*This text will be italic* +_This text will be italic_ + +**This text will be bold** +__This text will be bold__ +``` + +**Notes**: + +* `*` is recommended in VNote; +* If the render failed, try to add an additional space before the first `*` and after the last `*`. The space is necessary if the surrounded text begins or ends with full width punctuation; + +### Lists +#### Unordered +```md +* Item 1 +This is a text under Item 1. Notice that there are two spaces at the end above. +* Item 2 + * Item 2a + * Item 2b +* Item 3 + +To end a list, there should be one empty line above. +``` + +#### Ordered +```md +1. Item 1 +1. Item 2 +Notice that the sequence number is irrelevant. Markdown will change the sequence automatically when renderring. +3. Item 3 + 1. Item 3a + 2. Item 3b +4. Item 4 +``` + +### Tables +```md +| col 1 | col 2 | col 3 | +| --- | --- | --- | +| cell1 | cell2 | cell3 | +| cell4 | cell5 | cell6 | +``` + +### Images and Links +```md +![Image Alt Text](/url/to/image.png "Optional Text") + +![Image Alt Text](/url/to/image.png "Image specified with width and height" =800x600) + +![Image Alt Text](/url/to/image.png =800x600) + +![Image Alt Text](/url/to/image.png "Image specified with width" =800x) + +![Image Alt Text](/url/to/image.png "Image specified with height" =x600) + +[Link Text](/url/of/the/link) +``` + +**Notes**: + +* It is not recommended to use image links in reference format. VNote will not preview those images. + +### Blockquotes +```md +As VNote suggests: + +> VNote is the best Markdown note-taking application +> ever. +> +> THere is two spaces after `ever.` above to insert a +> new line. + +It also suggests: + +> VNote is good. +Here is another sentence within the quote. +``` + +**Notes**: + +* Space is needed after the marker `>`; +* You could just add only one `>` at the first line; + +### Fenced Code Block + ```lang + This is a fenced code block. + ``` + + ~~~cpp + This is another fenced code block. + ~~~ + +**Notes**: + +* `lang` is optional to specify the language of the code; if not specified, VNote won't highlight the code; +* It is always a good practice to add one empty line before the whole fenced code block. + +### Diagrams +VNote supports the following engines to draw diagrams. You should specify particular language of the fenced code block and write the definition of your diagram within it. + +* [Flowchart.js](http://flowchart.js.org/) for *flowchart* with language `flow` or `flowchart`; +* [Mermaid](https://mermaidjs.github.io/) with language `mermaid`; +* [WaveDrom](https://wavedrom.com/) for *digital timing diagram* with language `wavedrom`; + +For example, + + ```flowchart + st=>start: Start:>http://www.google.com[blank] + e=>end:>http://www.google.com + op1=>operation: My Operation + sub1=>subroutine: My Subroutine + cond=>condition: Yes + or No?:>http://www.google.com + io=>inputoutput: catch something... + + st->op1->cond + cond(yes)->io->e + cond(no)->sub1(right)->op1 + ``` + +#### UML +VNote supports [PlantUML](http://plantuml.com/) to draw UML diagrams. You should use `puml` specified as the language of the fenced code block and write the definition of your diagram within it. + + ```puml + @startuml + Bob -> Alice : hello + @enduml + ``` + +#### Graphviz +VNote supports [Graphviz](http://www.graphviz.org/) to draw diagrams. You should use `dot` specified as the language of the fenced code block and write the definition of your diagram within it. + +### Math Formulas +VNote supports math formulas via [MathJax](https://www.mathjax.org/). The default math delimiters are `$$...$$` for **displayed mathematics**, and `$...$` for **inline mathematics**. + +* Inline mathematics should not cross multiple lines; +* Forms like `3$abc$`, `$abc$4`, `$ abc$`, and `$abc $` will not be treated as mathematics; +* Use `\` to escape `$`; +* There should be only space chars before opening `$$` and after closing `$$`; +* Use `\\` to new a line within a displayed mathematics; + +VNote also supports displayed mathematics via fenced code block with language `mathjax` specified. + + ```mathjax + $$ + J(\theta) = \frac 1 2 \sum_{i=1}^m (h_\theta(x^{(i)})-y^{(i)})^2 + $$ + ``` + +Equation number of displayed mathematics is supported: + + $$vnote x markdown = awesome$$ (1.2.1) + +### Inline Code +```md +Here is a `inline code`. +``` + +To insert one `` ` ``, you need to use two `` ` `` to enclose it, such as ``` `` ` `` ```. To insert two `` ` ``, you need to use three `` ` ``. + +### Strikethrough +```md +Here is a ~~text~~ with strikethrough. +``` + +### Task Lists +```md +* [x] this is a complete item. +* [ ] this is an incomplete item. +``` + +### Footnote +```md +This is a footnote [^1]. + +[^1]: Here is the detail of the footnote. +``` + +### Superscript and Subscript +```md +This is the 1^st^ superscript. + +This is the H~2~O subscript. +``` + +### Alert +```md +::: alert-info + +This is an info text. + +::: + +::: alert-danger + +This is a danger text. + +::: +``` + +Available variants: + +``` +alert-primary +alert-secondary +alert-success +alert-info +alert-warning +alert-danger +alert-light +alert-dark +``` + +### New Line and Paragraph +If you want to enter a new line, you should add two spaces after current line and then continue your input. VNote provides `Shift+Enter` to help. + +If you want to enter a new paragraph, you should add an empty line and then continue entering the new paragraph. + +Generally, you need to add an empty line after a block element (such as code block, lists, blockquote) to explicitly end it. + +[^1]: This guide references [Mastering Markdown](https://guides.github.com/features/mastering-markdown/). diff --git a/src/data/extra/extra.qrc b/src/data/extra/extra.qrc index 5fd5928f..ae89b703 100644 --- a/src/data/extra/extra.qrc +++ b/src/data/extra/extra.qrc @@ -8,6 +8,7 @@ docs/en/get_started.txt docs/en/about_vnotex.txt docs/en/shortcuts.md + docs/en/markdown_guide.md web/markdownviewertemplate.html web/css/globalstyles.css web/css/markdownit.css diff --git a/src/widgets/editors/statuswidget.cpp b/src/widgets/editors/statuswidget.cpp new file mode 100644 index 00000000..5846a5a7 --- /dev/null +++ b/src/widgets/editors/statuswidget.cpp @@ -0,0 +1,44 @@ +#include "statuswidget.h" + +#include +#include +#include + +using namespace vnotex; + +StatusWidget::StatusWidget(QWidget *p_parent) + : QWidget(p_parent) +{ + auto layout = new QHBoxLayout(this); + layout->setContentsMargins(0, 0, 0, 0); + layout->setSpacing(0); + + m_messageLabel = new QLabel(this); + m_messageLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); + layout->addWidget(m_messageLabel); + + m_messageTimer = new QTimer(this); + m_messageTimer->setSingleShot(true); + connect(m_messageTimer, &QTimer::timeout, + m_messageLabel, &QLabel::clear); +} + +StatusWidget::~StatusWidget() +{ + if (m_editorWidget) { + m_editorWidget->setParent(nullptr); + } +} + +void StatusWidget::showMessage(const QString &p_msg, int p_milliseconds) +{ + m_messageLabel->setText(p_msg); + m_messageTimer->start(p_milliseconds); +} + +void StatusWidget::setEditorStatusWidget(const QSharedPointer &p_editorWidget) +{ + Q_ASSERT(!m_editorWidget); + m_editorWidget = p_editorWidget; + layout()->addWidget(m_editorWidget.data()); +} diff --git a/src/widgets/editors/statuswidget.h b/src/widgets/editors/statuswidget.h new file mode 100644 index 00000000..47cc5d3e --- /dev/null +++ b/src/widgets/editors/statuswidget.h @@ -0,0 +1,36 @@ +#ifndef STATUSWIDGET_H +#define STATUSWIDGET_H + +#include +#include + +class QLabel; +class QTimer; + +namespace vnotex +{ + // A status widget wrapper for ViewWindow. + class StatusWidget : public QWidget + { + Q_OBJECT + public: + explicit StatusWidget(QWidget *p_parent = nullptr); + + ~StatusWidget(); + + void showMessage(const QString &p_msg, int p_milliseconds = 3000); + + void setEditorStatusWidget(const QSharedPointer &p_editorWidget); + + private: + QLabel *m_messageLabel = nullptr; + + QTimer *m_messageTimer = nullptr; + + // Use shared pointer here to hold the widget. + // Should detach the widget in destructor. + QSharedPointer m_editorWidget; + }; +} + +#endif // STATUSWIDGET_H diff --git a/src/widgets/markdownviewwindow.cpp b/src/widgets/markdownviewwindow.cpp index de2817d1..7c83c50d 100644 --- a/src/widgets/markdownviewwindow.cpp +++ b/src/widgets/markdownviewwindow.cpp @@ -28,6 +28,7 @@ #include "outlineprovider.h" #include "toolbarhelper.h" #include "findandreplacewidget.h" +#include "editors/statuswidget.h" using namespace vnotex; @@ -58,6 +59,8 @@ MarkdownViewWindow::~MarkdownViewWindow() getMainStatusWidget()->removeWidget(m_viewerStatusWidget.get()); m_viewerStatusWidget->setParent(nullptr); } + + m_mainStatusWidget->setParent(nullptr); } void MarkdownViewWindow::setupUI() @@ -72,9 +75,13 @@ void MarkdownViewWindow::setupUI() // Status widget. // We use a QTabWidget as status widget since we have two widgets for different modes. - auto stackedWidget = QSharedPointer::create(this); - stackedWidget->setContentsMargins(0, 0, 0, 0); - setStatusWidget(stackedWidget); + { + auto statusWidget = QSharedPointer::create(this); + m_mainStatusWidget = QSharedPointer::create(this); + m_mainStatusWidget->setContentsMargins(0, 0, 0, 0); + statusWidget->setEditorStatusWidget(m_mainStatusWidget); + setStatusWidget(statusWidget); + } setupToolBar(); } @@ -339,7 +346,7 @@ void MarkdownViewWindow::setupTextEditor() QStackedWidget *MarkdownViewWindow::getMainStatusWidget() const { - return static_cast(m_statusWidget.get()); + return m_mainStatusWidget.data(); } bool MarkdownViewWindow::eventFilter(QObject *p_obj, QEvent *p_event) @@ -422,7 +429,9 @@ void MarkdownViewWindow::setupViewer() } }); connect(adapter, &MarkdownViewerAdapter::findTextReady, - this, &ViewWindow::showFindResult); + this, [this](const QString &p_text, int p_totalMatches, int p_currentMatchIndex) { + this->showFindResult(p_text, p_totalMatches, p_currentMatchIndex); + }); } void MarkdownViewWindow::syncTextEditorFromBuffer(bool p_syncPositionFromReadMode) diff --git a/src/widgets/markdownviewwindow.h b/src/widgets/markdownviewwindow.h index cc436df6..b6a24837 100644 --- a/src/widgets/markdownviewwindow.h +++ b/src/widgets/markdownviewwindow.h @@ -145,6 +145,8 @@ namespace vnotex QSharedPointer m_viewerStatusWidget; + QSharedPointer m_mainStatusWidget; + // Managed by QObject. PreviewHelper *m_previewHelper = nullptr; diff --git a/src/widgets/textviewwindow.cpp b/src/widgets/textviewwindow.cpp index 4de19a0f..39b4fe1c 100644 --- a/src/widgets/textviewwindow.cpp +++ b/src/widgets/textviewwindow.cpp @@ -13,6 +13,7 @@ #include "editors/texteditor.h" #include #include +#include "editors/statuswidget.h" using namespace vnotex; @@ -45,7 +46,11 @@ void TextViewWindow::setupUI() TextViewWindowHelper::connectEditor(this); // Status widget. - setStatusWidget(m_editor->statusWidget()); + { + auto statusWidget = QSharedPointer::create(); + statusWidget->setEditorStatusWidget(m_editor->statusWidget()); + setStatusWidget(statusWidget); + } setupToolBar(); } diff --git a/src/widgets/toolbarhelper.cpp b/src/widgets/toolbarhelper.cpp index e4c1322c..d84e48d1 100644 --- a/src/widgets/toolbarhelper.cpp +++ b/src/widgets/toolbarhelper.cpp @@ -224,6 +224,8 @@ QToolBar *ToolBarHelper::setupSettingsToolBar(MainWindow *p_win, QToolBar *p_too auto stayOnTopAct = menu->addAction(generateIcon("stay_on_top.svg"), MainWindow::tr("Stay On Top"), p_win, &MainWindow::setStayOnTop); stayOnTopAct->setCheckable(true); + WidgetUtils::addActionShortcut(stayOnTopAct, + coreConfig.getShortcut(CoreConfig::Shortcut::StayOnTop)); menu->addSeparator(); @@ -337,6 +339,17 @@ QToolBar *ToolBarHelper::setupSettingsToolBar(MainWindow *p_win, QToolBar *p_too } }); + menu->addAction(MainWindow::tr("Markdown Guide"), + menu, + []() { + const auto file = DocsUtils::getDocFile(QStringLiteral("markdown_guide.md")); + if (!file.isEmpty()) { + auto paras = QSharedPointer::create(); + paras->m_readOnly = true; + emit VNoteX::getInst().openFileRequested(file, paras); + } + }); + menu->addSeparator(); menu->addAction(MainWindow::tr("View Logs"), diff --git a/src/widgets/viewwindow.cpp b/src/widgets/viewwindow.cpp index 7ace76f1..ad641e24 100644 --- a/src/widgets/viewwindow.cpp +++ b/src/widgets/viewwindow.cpp @@ -31,6 +31,7 @@ #include "attachmentdragdropareaindicator.h" #include "exception.h" #include "findandreplacewidget.h" +#include "editors/statuswidget.h" using namespace vnotex; @@ -231,7 +232,7 @@ void ViewWindow::addBottomWidget(QWidget *p_widget) m_bottomLayout->addWidget(p_widget); } -void ViewWindow::setStatusWidget(const QSharedPointer &p_widget) +void ViewWindow::setStatusWidget(const QSharedPointer &p_widget) { m_statusWidget = p_widget; m_bottomLayout->insertWidget(0, p_widget.data()); @@ -863,12 +864,12 @@ void ViewWindow::wheelEvent(QWheelEvent *p_event) void ViewWindow::showZoomFactor(qreal p_factor) { - VNoteX::getInst().showStatusMessageShort(tr("Zoomed: %1%").arg(p_factor * 100)); + showMessage(tr("Zoomed: %1%").arg(p_factor * 100)); } void ViewWindow::showZoomDelta(int p_delta) { - VNoteX::getInst().showStatusMessageShort(tr("Zoomed: %1%2").arg(p_delta > 0 ? "+" : "").arg(p_delta)); + showMessage(tr("Zoomed: %1%2").arg(p_delta > 0 ? "+" : "").arg(p_delta)); } void ViewWindow::showFindAndReplaceWidget() @@ -1003,19 +1004,26 @@ void ViewWindow::replaceAll(const QString &p_text, FindOptions p_options, const void ViewWindow::showFindResult(const QString &p_text, int p_totalMatches, int p_currentMatchIndex) { if (p_totalMatches == 0) { - VNoteX::getInst().showStatusMessageShort(tr("Pattern not found: %1").arg(p_text)); + showMessage(tr("Pattern not found: %1").arg(p_text)); } else { - VNoteX::getInst().showStatusMessageShort(tr("Match found: %1/%2").arg(p_currentMatchIndex + 1).arg(p_totalMatches)); + showMessage(tr("Match found: %1/%2").arg(p_currentMatchIndex + 1).arg(p_totalMatches)); } } void ViewWindow::showReplaceResult(const QString &p_text, int p_totalReplaces) { if (p_totalReplaces == 0) { - VNoteX::getInst().showStatusMessageShort(tr("Pattern not found: %1").arg(p_text)); + showMessage(tr("Pattern not found: %1").arg(p_text)); } else { - VNoteX::getInst().showStatusMessageShort(tr("Replaced %n match(es)", "", p_totalReplaces)); + showMessage(tr("Replaced %n match(es)", "", p_totalReplaces)); } } - +void ViewWindow::showMessage(const QString p_msg) +{ + if (m_statusWidget) { + m_statusWidget->showMessage(p_msg); + } else { + VNoteX::getInst().showStatusMessageShort(p_msg); + } +} diff --git a/src/widgets/viewwindow.h b/src/widgets/viewwindow.h index 03ee5978..00ac99f9 100644 --- a/src/widgets/viewwindow.h +++ b/src/widgets/viewwindow.h @@ -21,6 +21,7 @@ namespace vnotex class OutlineProvider; class EditReadDiscardAction; class FindAndReplaceWidget; + class StatusWidget; class ViewWindow : public QFrame { @@ -148,6 +149,9 @@ namespace vnotex virtual void handleFindAndReplaceWidgetOpened(); + // Show message in status widget if exists. Otherwise, show it in the mainwindow's status widget. + void showMessage(const QString p_msg); + protected: void setCentralWidget(QWidget *p_widget); @@ -157,7 +161,7 @@ namespace vnotex void addBottomWidget(QWidget *p_widget); - void setStatusWidget(const QSharedPointer &p_widget); + void setStatusWidget(const QSharedPointer &p_widget); bool eventFilter(QObject *p_obj, QEvent *p_event) Q_DECL_OVERRIDE; @@ -202,14 +206,12 @@ namespace vnotex bool findAndReplaceWidgetVisible() const; // @p_currentMatchIndex: 0-based. - static void showFindResult(const QString &p_text, int p_totalMatches, int p_currentMatchIndex); + void showFindResult(const QString &p_text, int p_totalMatches, int p_currentMatchIndex); - static void showReplaceResult(const QString &p_text, int p_totalReplaces); + void showReplaceResult(const QString &p_text, int p_totalReplaces); static ViewWindow::Mode modeFromOpenParameters(const FileOpenParameters &p_paras); - QSharedPointer m_statusWidget; - // The revision of the buffer of the last sync content. int m_bufferRevision = 0; @@ -306,6 +308,8 @@ namespace vnotex // Last find info. FindInfo m_findInfo; + QSharedPointer m_statusWidget; + static QIcon s_savedIcon; static QIcon s_modifiedIcon; }; diff --git a/src/widgets/widgets.pri b/src/widgets/widgets.pri index 92ffeb93..2bab2a94 100644 --- a/src/widgets/widgets.pri +++ b/src/widgets/widgets.pri @@ -26,6 +26,7 @@ SOURCES += \ $$PWD/editors/markdownviewer.cpp \ $$PWD/editors/markdownvieweradapter.cpp \ $$PWD/editors/previewhelper.cpp \ + $$PWD/editors/statuswidget.cpp \ $$PWD/editors/texteditor.cpp \ $$PWD/editreaddiscardaction.cpp \ $$PWD/filesystemviewer.cpp \ @@ -103,6 +104,7 @@ HEADERS += \ $$PWD/editors/markdownviewer.h \ $$PWD/editors/markdownvieweradapter.h \ $$PWD/editors/previewhelper.h \ + $$PWD/editors/statuswidget.h \ $$PWD/editors/texteditor.h \ $$PWD/editreaddiscardaction.h \ $$PWD/filesystemviewer.h \