diff --git a/MDEditor.mimetypes.xml b/MDEditor.mimetypes.xml index f1b3e21..1c7096b 100644 --- a/MDEditor.mimetypes.xml +++ b/MDEditor.mimetypes.xml @@ -12,7 +12,7 @@ Markdown Source file - + diff --git a/markdown2htmlconverter.cpp b/markdown2htmlconverter.cpp index c6ed775..6f4c935 100644 --- a/markdown2htmlconverter.cpp +++ b/markdown2htmlconverter.cpp @@ -4,6 +4,7 @@ #include #include +#include using namespace MDEditor; @@ -70,6 +71,8 @@ void Markdown2HtmlConverter::initHiddenFolder(const Utils::FileName inputFileNam if(fi.exists()) { QString extractCmd = QString::fromLatin1("tar zxvf %1 -C %2").arg(sourcePkg).arg(targetPath.toString()); - system((const char*)extractCmd.toLocal8Bit()); + QProcess process; + process.start(extractCmd); + process.waitForFinished(); } } diff --git a/markdowneditorhelpdialog.cpp b/markdowneditorhelpdialog.cpp new file mode 100644 index 0000000..73c4a2a --- /dev/null +++ b/markdowneditorhelpdialog.cpp @@ -0,0 +1,25 @@ +#include "markdowneditorhelpdialog.h" +#include "ui_markdowneditorhelpdialog.h" + +MarkdownEditorHelpDialog::MarkdownEditorHelpDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::MarkdownEditorHelpDialog) +{ + ui->setupUi(this); + QImage img = QImage(QLatin1String(":/mdeditor/icons/markdown.png")); + + ui->logo_label->setPixmap(QPixmap::fromImage(img).scaled(QSize(128,128))); + ui->logo_label->setText(QString::null); + + ui->label->adjustSize(); + ui->label->setGeometry(QRect(328, 240, 329, 27*4)); //四倍行距 + ui->label->setWordWrap(true); + ui->label->setAlignment(Qt::AlignTop); + + ui->label->setOpenExternalLinks(true); +} + +MarkdownEditorHelpDialog::~MarkdownEditorHelpDialog() +{ + delete ui; +} diff --git a/markdowneditorhelpdialog.h b/markdowneditorhelpdialog.h new file mode 100644 index 0000000..071411e --- /dev/null +++ b/markdowneditorhelpdialog.h @@ -0,0 +1,22 @@ +#ifndef MARKDOWNEDITORHELPDIALOG_H +#define MARKDOWNEDITORHELPDIALOG_H + +#include + +namespace Ui { +class MarkdownEditorHelpDialog; +} + +class MarkdownEditorHelpDialog : public QDialog +{ + Q_OBJECT + +public: + explicit MarkdownEditorHelpDialog(QWidget *parent = 0); + ~MarkdownEditorHelpDialog(); + +private: + Ui::MarkdownEditorHelpDialog *ui; +}; + +#endif // MARKDOWNEDITORHELPDIALOG_H diff --git a/markdowneditorhelpdialog.ui b/markdowneditorhelpdialog.ui new file mode 100644 index 0000000..3b6cf7f --- /dev/null +++ b/markdowneditorhelpdialog.ui @@ -0,0 +1,165 @@ + + + MarkdownEditorHelpDialog + + + + 0 + 0 + 619 + 360 + + + + + 700 + 700 + + + + About Markdown Editor + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 0 + + + + + 131 + 161 + + + + TextLabel + + + + + + + Qt::Vertical + + + + 20 + 153 + + + + + + + + + + + + + 700 + 700 + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">QtCreator Markdown Editor Plugin</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Markdown Editor Plugin is a plugin allowing developers to create and edit markdown files in Qt Creator IDE.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">It supports the </span><a href="https://daringfireball.net/projects/markdown"><span style=" text-decoration: underline; color:#0000ff;">standard Markdown</span></a><span style=" font-size:10pt;">, </span><a href="https://www.mathjax.org/"><span style=" font-size:10pt; text-decoration: underline; color:#0000ff;">MathJax</span></a><span style=" font-size:10pt;">, </span><a href="https://bramp.github.io/js-sequence-diagrams/"><span style=" font-size:10pt; text-decoration: underline; color:#0000ff;">js-sequence-diagrams </span></a><span style=" font-size:10pt;">and </span><a href="http://flowchart.js.org/"><span style=" font-size:10pt; text-decoration: underline; color:#0000ff;">flowChart</span></a><span style=" font-size:10pt;"> syntax.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Donnot commit its output files (*.html file and .mardown folder) to SVN or GIT, they can be generated by the plugin automatically. The html files can also be displayed in browsers like ie, chrome, etc.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">see more at </span><a href="https://github.com/weijiaming/QtCreator-Markdown-Editor-Plugin"><span style=" font-size:10pt; text-decoration: underline; color:#0000ff;">https://github.com/weijiaming/QtCreator-Markdown-Editor-Plugin</span></a></p></body></html> + + + Qt::RichText + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Close + + + + + + + + + + + + + pushButton + clicked() + MarkdownEditorHelpDialog + close() + + + 567 + 339 + + + 611 + 260 + + + + + diff --git a/markdowneditortoolbutton.cpp b/markdowneditortoolbutton.cpp index b1a3ad1..ac4ce55 100644 --- a/markdowneditortoolbutton.cpp +++ b/markdowneditortoolbutton.cpp @@ -1,4 +1,5 @@ #include "markdowneditortoolbutton.h" +#include "markdowneditorhelpdialog.h" #include "texteditor/texteditor.h" #include @@ -6,8 +7,19 @@ namespace MDEditor{ class MarkdownEditorToolButtonPrivate { public: + + MarkdownEditorToolButtonPrivate() {} + ~MarkdownEditorToolButtonPrivate() + { + if(helpDlg) + { + delete helpDlg; + helpDlg = nullptr; + } + } MarkdownEditorToolButton::ButtonId m_ButtonId = MarkdownEditorToolButton::ID_Unknown; TextEditor::TextEditorWidget* m_editorWidget = nullptr; + MarkdownEditorHelpDialog* helpDlg = nullptr; void apply(); }; @@ -23,22 +35,34 @@ void MarkdownEditorToolButtonPrivate::apply() case MarkdownEditorToolButton::ID_StrikeThrough: case MarkdownEditorToolButton::ID_Code: { - QString str; + QString markerStr; if(m_ButtonId == MarkdownEditorToolButton::ID_Bold) - str = QString::fromUtf8("****"); + markerStr = QString::fromUtf8("**"); else if(m_ButtonId == MarkdownEditorToolButton::ID_Italic) - str = QString::fromUtf8("**"); + markerStr = QString::fromUtf8("*"); else if(m_ButtonId == MarkdownEditorToolButton::ID_StrikeThrough) - str = QString::fromUtf8("~~~~"); - else if(m_ButtonId == MarkdownEditorToolButton::ID_Code) - str = QString::fromUtf8("\n```\n\n```\n"); + markerStr = QString::fromUtf8("~~"); + else if(m_ButtonId ==MarkdownEditorToolButton::ID_Code ) + markerStr = QString::fromUtf8("\n```\n"); - int moveCursorNum = str.length()/2; - str.insert(moveCursorNum, m_editorWidget->selectedText()); - m_editorWidget->insertPlainText(str); + int markerStrLength = markerStr.length(); + QString targetStr = m_editorWidget->selectedText(); + + if(targetStr.startsWith(markerStr) && targetStr.endsWith(markerStr)) + { + targetStr.remove(0, markerStrLength); + targetStr.remove(targetStr.length() - markerStrLength,markerStrLength); + } + else + { + targetStr.prepend(markerStr); + targetStr.append(markerStr); + } + m_editorWidget->insertPlainText(targetStr); QTextCursor tc = m_editorWidget->textCursor(); - tc.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, moveCursorNum); + tc.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, markerStrLength); m_editorWidget->setTextCursor(tc); + break; } case MarkdownEditorToolButton::ID_H1: @@ -107,6 +131,14 @@ Note right of D: Note right of D\n```")); m_editorWidget->insertLineBelow(); break; } + case MarkdownEditorToolButton::ID_Help: + { + if(!helpDlg) + { + helpDlg = new MarkdownEditorHelpDialog(m_editorWidget); + } + helpDlg->show(); + } default: break; } @@ -151,7 +183,7 @@ void MarkdownEditorToolButton::setButtonId(ButtonId id) break; case ID_StrikeThrough: img = QImage(QLatin1String(":/mdeditor/icons/strikethrough.png")); - tooltips = QString::fromUtf8("StrikeThrough"); + tooltips = QString::fromUtf8("Strike Through"); break; case ID_H1: setText(QString::fromUtf8("H1")); @@ -173,11 +205,11 @@ void MarkdownEditorToolButton::setButtonId(ButtonId id) break; case ID_HorizonalRule: img = QImage(QLatin1String(":/mdeditor/icons/line.png")); - tooltips = QString::fromUtf8("HorizonalRule"); + tooltips = QString::fromUtf8("Horizonal Rule"); break; case ID_Tastlist: img = QImage(QLatin1String(":/mdeditor/icons/tasklist.png")); - tooltips = QString::fromUtf8("TaskList"); + tooltips = QString::fromUtf8("Task List"); break; case ID_Link: img = QImage(QLatin1String(":/mdeditor/icons/link.png")); @@ -193,7 +225,7 @@ void MarkdownEditorToolButton::setButtonId(ButtonId id) break; case ID_MathFormula: img = QImage(QLatin1String(":/mdeditor/icons/math.png")); - tooltips = QString::fromUtf8("MathFormula"); + tooltips = QString::fromUtf8("Math Formula"); break; case ID_Code: img = QImage(QLatin1String(":/mdeditor/icons/code.png")); @@ -201,11 +233,16 @@ void MarkdownEditorToolButton::setButtonId(ButtonId id) break; case ID_FlowChart: img = QImage(QLatin1String(":/mdeditor/icons/flow.png")); - tooltips = QString::fromUtf8("FlowChart"); + tooltips = QString::fromUtf8("Flow Chart"); break; case ID_SequenceDiagram: img = QImage(QLatin1String(":/mdeditor/icons/sequence.png")); - tooltips = QString::fromUtf8("SequenceDiagram"); + tooltips = QString::fromUtf8("Sequence Diagram"); + break; + + case ID_Help: + img = QImage(QLatin1String(":/mdeditor/icons/help.png")); + tooltips = QString::fromUtf8("Help Contents"); break; default: break; diff --git a/markdowneditortoolbutton.h b/markdowneditortoolbutton.h index 2bb1f37..0ba75bd 100644 --- a/markdowneditortoolbutton.h +++ b/markdowneditortoolbutton.h @@ -34,7 +34,8 @@ class MDEDITORSHARED_EXPORT MarkdownEditorToolButton : public QToolButton ID_MathFormula, ID_Code, ID_FlowChart, - ID_SequenceDiagram + ID_SequenceDiagram, + ID_Help }; MarkdownEditorToolButton(ButtonId, QWidget* parent = 0); diff --git a/markdowneditorwidget.cpp b/markdowneditorwidget.cpp index 7c8d469..51cb1d5 100644 --- a/markdowneditorwidget.cpp +++ b/markdowneditorwidget.cpp @@ -58,23 +58,24 @@ void MarkdownEditorWidget::addToolBar() { QList ids; ids<icons/table.png icons/tasklist.png icons/underline.png + icons/help.png + icons/markdown.png diff --git a/pandocconverter.cpp b/pandocconverter.cpp index b410c67..a511c3a 100644 --- a/pandocconverter.cpp +++ b/pandocconverter.cpp @@ -296,6 +296,8 @@ void PandocConverter::initHiddenFolder(const Utils::FileName inputFileName) if(fi.exists()) { QString extractCmd = QString::fromLatin1("tar zxvf %1 -C %2").arg(sourcePkg).arg(targetPath.toString()); - system((const char*)extractCmd.toLocal8Bit()); + QProcess process; + process.start(extractCmd); + process.waitForFinished(); } }