Skip to content

Commit

Permalink
update shortcuts and add help dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
weijiaming authored Nov 23, 2016
1 parent 94ef02b commit ef68a05
Show file tree
Hide file tree
Showing 11 changed files with 294 additions and 33 deletions.
2 changes: 1 addition & 1 deletion MDEditor.mimetypes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<mime-type type="text/x-markdown">
<sub-class-of type="text/plain"/>
<comment>Markdown Source file</comment>
<glob pattern="*.md"/>
<glob pattern="*.markdown"/>
<magic priority="256">
<match value="[*](*) " type="string" offset="0:2000"/>
<match value="![*](*) " type="string" offset="0:2000"/>
Expand Down
5 changes: 4 additions & 1 deletion markdown2htmlconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <QFile>
#include <QFileInfo>
#include <QProcess>

using namespace MDEditor;

Expand Down Expand Up @@ -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();
}
}
25 changes: 25 additions & 0 deletions markdowneditorhelpdialog.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
22 changes: 22 additions & 0 deletions markdowneditorhelpdialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef MARKDOWNEDITORHELPDIALOG_H
#define MARKDOWNEDITORHELPDIALOG_H

#include <QDialog>

namespace Ui {
class MarkdownEditorHelpDialog;
}

class MarkdownEditorHelpDialog : public QDialog
{
Q_OBJECT

public:
explicit MarkdownEditorHelpDialog(QWidget *parent = 0);
~MarkdownEditorHelpDialog();

private:
Ui::MarkdownEditorHelpDialog *ui;
};

#endif // MARKDOWNEDITORHELPDIALOG_H
165 changes: 165 additions & 0 deletions markdowneditorhelpdialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MarkdownEditorHelpDialog</class>
<widget class="QDialog" name="MarkdownEditorHelpDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>619</width>
<height>360</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>700</width>
<height>700</height>
</size>
</property>
<property name="windowTitle">
<string>About Markdown Editor</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="logo_label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>131</width>
<height>161</height>
</size>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>153</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="maximumSize">
<size>
<width>700</width>
<height>700</height>
</size>
</property>
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;QtCreator Markdown Editor Plugin&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-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;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;Markdown Editor Plugin is a plugin allowing developers to create and edit markdown files in Qt Creator IDE.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-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;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;It supports the &lt;/span&gt;&lt;a href=&quot;https://daringfireball.net/projects/markdown&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;standard Markdown&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;, &lt;/span&gt;&lt;a href=&quot;https://www.mathjax.org/&quot;&gt;&lt;span style=&quot; font-size:10pt; text-decoration: underline; color:#0000ff;&quot;&gt;MathJax&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;, &lt;/span&gt;&lt;a href=&quot;https://bramp.github.io/js-sequence-diagrams/&quot;&gt;&lt;span style=&quot; font-size:10pt; text-decoration: underline; color:#0000ff;&quot;&gt;js-sequence-diagrams &lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;and &lt;/span&gt;&lt;a href=&quot;http://flowchart.js.org/&quot;&gt;&lt;span style=&quot; font-size:10pt; text-decoration: underline; color:#0000ff;&quot;&gt;flowChart&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt; syntax.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-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;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;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.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-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;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;see more at &lt;/span&gt;&lt;a href=&quot;https://github.com/weijiaming/QtCreator-Markdown-Editor-Plugin&quot;&gt;&lt;span style=&quot; font-size:10pt; text-decoration: underline; color:#0000ff;&quot;&gt;https://github.com/weijiaming/QtCreator-Markdown-Editor-Plugin&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>MarkdownEditorHelpDialog</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>567</x>
<y>339</y>
</hint>
<hint type="destinationlabel">
<x>611</x>
<y>260</y>
</hint>
</hints>
</connection>
</connections>
</ui>
69 changes: 53 additions & 16 deletions markdowneditortoolbutton.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
#include "markdowneditortoolbutton.h"
#include "markdowneditorhelpdialog.h"
#include "texteditor/texteditor.h"
#include <QDebug>

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();
};
Expand All @@ -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:
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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"));
Expand All @@ -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"));
Expand All @@ -193,19 +225,24 @@ 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"));
tooltips = QString::fromUtf8("Code");
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;
Expand Down
3 changes: 2 additions & 1 deletion markdowneditortoolbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit ef68a05

Please sign in to comment.