MarkdownEditor.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package
19 * @author
20 * @date
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#include "MarkdownEditor.h"
25
26#include <sstream>
27
28#include <QDesktopServices>
29#include <QMenu>
30
31#include <ArmarXGui/libraries/ArmarXGuiBase/ui_MarkdownEditor.h>
32
34
35namespace armarx
36{
37
38 MarkdownEditor::MarkdownEditor(QWidget* parent) : QWidget(parent), ui(new Ui::MarkdownEditor)
39 {
40 ui->setupUi(this);
41 connect(ui->btnEdit, SIGNAL(toggled(bool)), this, SLOT(toggleEditor(bool)));
42 connect(ui->btnSyntax, SIGNAL(clicked()), this, SLOT(openSyntaxUrl()));
43 connect(ui->htmlView, SIGNAL(textChanged()), this, SLOT(__forwardTextChanged()));
44 }
45
47 {
48 delete ui;
49 }
50
51 QString
53 {
54 if (ui->btnEdit->isChecked())
55 {
56 return ui->htmlView->toPlainText();
57 }
58 else
59 {
60 return plainText;
61 }
62 }
63
64 void
65 MarkdownEditor::setPlainText(const QString& plainText)
66 {
67 this->plainText = plainText;
68
69 if (ui->btnEdit->isChecked())
70 {
71 ui->htmlView->setPlainText(plainText);
72 }
73 else
74 {
75 showMarkdown(plainText);
76 }
77 }
78
79 void
80 MarkdownEditor::showMarkdown(const QString& rawString)
81 {
83
84 if (rawString.length() > 0)
85 {
86 doc.read(rawString.toStdString());
87 }
88 else
89 {
90 doc.read(plainText.toStdString());
91 }
92
93 std::stringstream html;
94 doc.write(html);
95 ui->htmlView->setHtml(html.str().c_str());
96 }
97
98 void
100 {
101 if (toggled)
102 {
103 ui->htmlView->setPlainText(plainText);
104 ui->htmlView->setReadOnly(false);
105 }
106 else
107 {
108 plainText = ui->htmlView->toPlainText();
109 showMarkdown();
110 ui->htmlView->setReadOnly(true);
111 }
112
113 // ui->plainView->setVisible(toggled);
114 // ui->htmlView->setVisible(!toggled);
115 }
116
117 void
119 {
120 QDesktopServices::openUrl(QUrl("https://help.github.com/articles/markdown-basics/"));
121 }
122
123 void
124 MarkdownEditor::__forwardTextChanged()
125 {
126 if (ui->btnEdit->isChecked())
127 {
128 emit textChanged();
129 }
130 }
131
132} // namespace armarx
MarkdownEditor(QWidget *parent=0)
void showMarkdown(const QString &rawString="")
QString toPlainText() const
void toggleEditor(bool toggled)
void setPlainText(const QString &plainText)
void write(std::ostream &)
bool read(const std::string &)
Definition markdown.cpp:956
ArmarX Headers.
This file offers overloads of toIce() and fromIce() functions for STL container types.