Skip to content

Commit 56d5329

Browse files
committed
Add possibility to choose from reveal.js built-in presentation styles
1 parent d809277 commit 56d5329

10 files changed

Lines changed: 115 additions & 21 deletions

app-static/styles.cpp

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ static const Style BUILTIN_CLEARNESS_STYLE = { "Default", "Default", "Clearness"
2424
static const Style BUILTIN_CLEARNESS_DARK_STYLE = { "Clearness Dark", "Default", "Clearness Dark" };
2525
static const Style BUILTIN_BYWORD_DARK_STYLE = { "Byword Dark", "Default", "Byword Dark" };
2626

27+
static const Style DEFAULT_PRESENTATION_STYLE = { "Default", "Default", "Default Presentation" };
28+
static const Style BEIGE_PRESENTATION_STYLE = { "Default", "Default", "Beige" };
29+
static const Style SKY_PRESENTATION_STYLE = { "Default", "Default", "Sky" };
30+
static const Style NIGHT_PRESENTATION_STYLE = { "Default", "Default", "Night" };
31+
static const Style SERIF_PRESENTATION_STYLE = { "Default", "Default", "Serif" };
32+
static const Style SIMPLE_PRESENTATION_STYLE = { "Default", "Default", "Simple" };
33+
static const Style SOLARIZED_PRESENTATION_STYLE = { "Solarized Light", "Default", "Solarized" };
34+
35+
2736
Styles::Styles()
2837
{
2938
setupBuiltinMarkdownHighlightings();
@@ -32,14 +41,22 @@ Styles::Styles()
3241
setupBuiltinStyles();
3342
}
3443

35-
QStringList Styles::styleNames() const
44+
QStringList Styles::htmlPreviewStyleNames() const
45+
{
46+
return m_htmlPreviewStylesIndex;
47+
}
48+
49+
QStringList Styles::presentationStyleNames() const
3650
{
37-
return QStringList(m_stylesIndex);
51+
return m_presentationStylesIndex;
3852
}
3953

4054
Style Styles::style(const QString &name) const
4155
{
42-
return m_styles[m_stylesIndex.indexOf(name)];
56+
if (m_htmlPreviewStylesIndex.contains(name))
57+
return m_htmlPreviewStyles[m_htmlPreviewStylesIndex.indexOf(name)];
58+
else
59+
return m_presentationStyles[m_presentationStylesIndex.indexOf(name)];
4360
}
4461

4562
QStringList Styles::markdownHighlightings() const
@@ -98,16 +115,40 @@ void Styles::setupBuiltinPreviewStylesheets()
98115
m_previewStylesheets.insert("Clearness", "qrc:/css/clearness.css");
99116
m_previewStylesheets.insert("Clearness Dark", "qrc:/css/clearness-dark.css");
100117
m_previewStylesheets.insert("Byword Dark", "qrc:/css/byword-dark.css");
118+
119+
m_previewStylesheets.insert("Default Presentation", "https://cdn.jsdelivr.net/reveal.js/2.6.2/css/theme/default.css");
120+
m_previewStylesheets.insert("Beige", "https://cdn.jsdelivr.net/reveal.js/2.6.2/css/theme/beige.css");
121+
m_previewStylesheets.insert("Sky", "https://cdn.jsdelivr.net/reveal.js/2.6.2/css/theme/sky.css");
122+
m_previewStylesheets.insert("Night", "https://cdn.jsdelivr.net/reveal.js/2.6.2/css/theme/night.css");
123+
m_previewStylesheets.insert("Serif", "https://cdn.jsdelivr.net/reveal.js/2.6.2/css/theme/serif.css");
124+
m_previewStylesheets.insert("Simple", "https://cdn.jsdelivr.net/reveal.js/2.6.2/css/theme/simple.css");
125+
m_previewStylesheets.insert("Solarized", "https://cdn.jsdelivr.net/reveal.js/2.6.2/css/theme/solarized.css");
101126
}
102127

103128
void Styles::setupBuiltinStyles()
104129
{
105-
m_stylesIndex << "Default" << "Github" << "Solarized Light"
130+
m_htmlPreviewStylesIndex << "Default" << "Github" << "Solarized Light"
106131
<< "Solarized Dark" << "Clearness" << "Clearness Dark"
107132
<< "Byword Dark";
108-
m_styles << BUILTIN_DEFAULT_STYLE << BUILTIN_GITHUB_STYLE
133+
m_htmlPreviewStyles << BUILTIN_DEFAULT_STYLE << BUILTIN_GITHUB_STYLE
109134
<< BUILTIN_SOLARIZED_LIGHT_STYLE << BUILTIN_SOLARIZED_DARK_STYLE
110135
<< BUILTIN_CLEARNESS_STYLE << BUILTIN_CLEARNESS_DARK_STYLE
111136
<< BUILTIN_BYWORD_DARK_STYLE;
137+
138+
m_presentationStylesIndex << DEFAULT_PRESENTATION_STYLE.previewStylesheet
139+
<< BEIGE_PRESENTATION_STYLE.previewStylesheet
140+
<< SKY_PRESENTATION_STYLE.previewStylesheet
141+
<< NIGHT_PRESENTATION_STYLE.previewStylesheet
142+
<< SERIF_PRESENTATION_STYLE.previewStylesheet
143+
<< SIMPLE_PRESENTATION_STYLE.previewStylesheet
144+
<< SOLARIZED_PRESENTATION_STYLE.previewStylesheet;
145+
146+
m_presentationStyles << DEFAULT_PRESENTATION_STYLE
147+
<< BEIGE_PRESENTATION_STYLE
148+
<< SKY_PRESENTATION_STYLE
149+
<< NIGHT_PRESENTATION_STYLE
150+
<< SERIF_PRESENTATION_STYLE
151+
<< SIMPLE_PRESENTATION_STYLE
152+
<< SOLARIZED_PRESENTATION_STYLE;
112153
}
113154

app-static/styles.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class Styles
3333
public:
3434
Styles();
3535

36-
QStringList styleNames() const;
36+
QStringList htmlPreviewStyleNames() const;
37+
QStringList presentationStyleNames() const;
3738
Style style(const QString &name) const;
3839

3940
QStringList markdownHighlightings() const;
@@ -54,8 +55,10 @@ class Styles
5455
QMap<QString, QString> m_markdownHighlightings;
5556
QMap<QString, QString> m_codeHighlightings;
5657
QMap<QString, QString> m_previewStylesheets;
57-
QList<QString> m_stylesIndex;
58-
QList<Style> m_styles;
58+
QStringList m_htmlPreviewStylesIndex;
59+
QList<Style> m_htmlPreviewStyles;
60+
QStringList m_presentationStylesIndex;
61+
QList<Style> m_presentationStyles;
5962
};
6063

6164
#endif // STYLES_H

app-static/template/presentationtemplate.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ QString PresentationTemplate::render(const QString &body, RenderOptions options)
3333
}
3434

3535
return QString(presentationTemplate)
36-
.replace(QLatin1String("<!--__HTML_HEADER__-->"), QString())
36+
.replace(QLatin1String("<!--__HTML_HEADER__-->"), buildHtmlHeader())
3737
.replace(QLatin1String("<!--__HTML_CONTENT__-->"), body)
3838
.replace(QLatin1String("<!--__REVEAL_PLUGINS__-->"), buildRevealPlugins(options));
3939
}
@@ -43,6 +43,15 @@ QString PresentationTemplate::exportAsHtml(const QString &, const QString &body,
4343
return render(body, options);
4444
}
4545

46+
QString PresentationTemplate::buildHtmlHeader() const
47+
{
48+
QString header;
49+
50+
header += QString("<link rel=\"stylesheet\" href=\"%1\" id=\"theme\">").arg(previewStyleSheet());
51+
52+
return header;
53+
}
54+
4655
QString PresentationTemplate::buildRevealPlugins(RenderOptions options) const
4756
{
4857
QString plugins;

app-static/template/presentationtemplate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class PresentationTemplate : public Template
2828
virtual QString exportAsHtml(const QString &header, const QString &body, RenderOptions options) const;
2929

3030
private:
31+
QString buildHtmlHeader() const;
3132
QString buildRevealPlugins(RenderOptions options) const;
3233

3334
QString presentationTemplate;

app-static/template/template.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ class Template
3131

3232
virtual ~Template() {}
3333

34-
QString codeHighlightingStyle() const { return highlightingStyle; }
35-
void setCodeHighlightingStyle(const QString &style) { highlightingStyle = style; }
34+
QString codeHighlightingStyle() const { return m_highlightingStyle; }
35+
void setCodeHighlightingStyle(const QString &style) { m_highlightingStyle = style; }
36+
37+
QString previewStyleSheet() const { return m_previewStyleSheet; }
38+
void setPreviewStyleSheet(const QString &stylesheet) { m_previewStyleSheet = stylesheet; }
3639

3740
virtual QString render(const QString &body, RenderOptions options) const = 0;
3841
virtual QString exportAsHtml(const QString &header, const QString &body, RenderOptions options) const = 0;
3942

4043
private:
41-
QString highlightingStyle;
44+
QString m_highlightingStyle;
45+
QString m_previewStyleSheet;
4246
};
4347

4448
Q_DECLARE_OPERATORS_FOR_FLAGS(Template::RenderOptions)

app/htmlpreviewgenerator.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ void HtmlPreviewGenerator::setCodeHighlightingStyle(const QString &style)
103103
generateHtmlFromMarkdown();
104104
}
105105

106+
void HtmlPreviewGenerator::setPreviewStyleSheet(const QString &stylesheet)
107+
{
108+
converter->templateRenderer()->setPreviewStyleSheet(stylesheet);
109+
}
110+
106111
void HtmlPreviewGenerator::markdownConverterChanged()
107112
{
108113
QString style;

app/htmlpreviewgenerator.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 Christian Loose <christian.loose@hamburg.de>
2+
* Copyright 2013-2014 Christian Loose <christian.loose@hamburg.de>
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -45,6 +45,8 @@ public slots:
4545
void setCodeHighlightingEnabled(bool enabled);
4646
void setCodeHighlightingStyle(const QString &style);
4747

48+
void setPreviewStyleSheet(const QString &stylesheet);
49+
4850
void markdownConverterChanged();
4951

5052
signals:

app/mainwindow.cpp

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ MainWindow::MainWindow(const QString &fileName, QWidget *parent) :
7272
ui(new Ui::MainWindow),
7373
options(new Options(this)),
7474
diskCache(new QNetworkDiskCache(this)),
75+
htmlPreviewStylesGroup(0),
76+
presentationStylesGroup(0),
7577
zoomInAction(0),
7678
zoomOutAction(0),
7779
zoomResetAction(0),
@@ -500,6 +502,7 @@ void MainWindow::styleBuiltinStyle()
500502
QAction *action = qobject_cast<QAction*>(sender());
501503
Style style = styles->style(action->data().toString());
502504
generator->setCodeHighlightingStyle(styles->pathForCodeHighlighting(style));
505+
generator->setPreviewStyleSheet(styles->pathForPreviewStylesheet(style));
503506

504507
ui->plainTextEdit->loadStyleFromStylesheet(styles->pathForMarkdownHighlighting(style));
505508
ui->webView->page()->settings()->setUserStyleSheetUrl(QUrl(styles->pathForPreviewStylesheet(style)));
@@ -671,7 +674,7 @@ void MainWindow::helpAbout()
671674
void MainWindow::styleContextMenu(const QPoint &pos)
672675
{
673676
QMenu *menu = new QMenu();
674-
menu->addActions(stylesGroup->actions());
677+
menu->addActions(htmlPreviewStylesGroup->actions());
675678

676679
menu->exec(styleLabel->mapToGlobal(pos));
677680
}
@@ -877,9 +880,11 @@ void MainWindow::markdownConverterChanged()
877880
viewSynchronizer = new HtmlViewSynchronizer(ui->webView, ui->plainTextEdit);
878881
connect(generator, SIGNAL(htmlResultReady(QString)),
879882
viewSynchronizer, SLOT(rememberScrollBarPos()));
883+
loadBuiltinStyles();
880884
break;
881885
case Options::RevealMarkdownConverter:
882886
viewSynchronizer = new RevealViewSynchronizer(ui->webView, ui->plainTextEdit);
887+
setupPresentationStyles();
883888
break;
884889
default:
885890
viewSynchronizer = 0;
@@ -1195,17 +1200,40 @@ void MainWindow::updateSplitter()
11951200
ui->splitter->setSizes(childSizes);
11961201
}
11971202

1203+
void MainWindow::setupPresentationStyles()
1204+
{
1205+
ui->menuStyles->clear();
1206+
1207+
// put style actions in a group
1208+
delete presentationStylesGroup;
1209+
presentationStylesGroup = new QActionGroup(this);
1210+
1211+
int key = 1;
1212+
foreach(const QString &styleName, styles->presentationStyleNames()) {
1213+
QAction *action = ui->menuStyles->addAction(styleName);
1214+
action->setShortcut(QKeySequence(tr("Ctrl+%1").arg(key++)));
1215+
action->setCheckable(true);
1216+
action->setActionGroup(presentationStylesGroup);
1217+
action->setData(styleName);
1218+
connect(action, SIGNAL(triggered()),
1219+
this, SLOT(styleBuiltinStyle()));
1220+
}
1221+
}
1222+
11981223
void MainWindow::loadBuiltinStyles()
11991224
{
1225+
ui->menuStyles->clear();
1226+
12001227
// put style actions in a group
1201-
stylesGroup = new QActionGroup(this);
1228+
delete htmlPreviewStylesGroup;
1229+
htmlPreviewStylesGroup = new QActionGroup(this);
12021230

12031231
int key = 1;
1204-
foreach(const QString &styleName, styles->styleNames()) {
1232+
foreach(const QString &styleName, styles->htmlPreviewStyleNames()) {
12051233
QAction *action = ui->menuStyles->addAction(styleName);
12061234
action->setShortcut(QKeySequence(tr("Ctrl+%1").arg(key++)));
12071235
action->setCheckable(true);
1208-
action->setActionGroup(stylesGroup);
1236+
action->setActionGroup(htmlPreviewStylesGroup);
12091237
action->setData(styleName);
12101238
connect(action, SIGNAL(triggered()),
12111239
this, SLOT(styleBuiltinStyle()));
@@ -1229,7 +1257,7 @@ void MainWindow::loadCustomStyles()
12291257
QString fileName = it.fileName();
12301258
QAction *action = ui->menuStyles->addAction(QFileInfo(fileName).baseName());
12311259
action->setCheckable(true);
1232-
action->setActionGroup(stylesGroup);
1260+
action->setActionGroup(htmlPreviewStylesGroup);
12331261
action->setData(it.filePath());
12341262

12351263
connect(action, SIGNAL(triggered()),

app/mainwindow.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ private slots:
142142
bool maybeSave();
143143
void setFileName(const QString &fileName);
144144
void updateSplitter();
145+
void setupPresentationStyles();
145146
void loadBuiltinStyles();
146147
void loadCustomStyles();
147148
void readSettings();
@@ -152,7 +153,8 @@ private slots:
152153
RecentFilesMenu *recentFilesMenu;
153154
Options *options;
154155
QNetworkDiskCache *diskCache;
155-
QActionGroup *stylesGroup;
156+
QActionGroup *htmlPreviewStylesGroup;
157+
QActionGroup *presentationStylesGroup;
156158
QAction *zoomInAction;
157159
QAction *zoomOutAction;
158160
QAction *zoomResetAction;

app/template_presentation.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
<meta http-equiv="content-type" content="text/html; charset=utf-8">
44
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
55
<link rel="stylesheet" href="https://cdn.jsdelivr.net/reveal.js/2.6.2/css/reveal.min.css">
6-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/reveal.js/2.6.2/css/theme/default.css" id="theme">
6+
<!--__HTML_HEADER__-->
77
<!-- For syntax highlighting -->
88
<link rel="stylesheet" href="https://cdn.jsdelivr.net/reveal.js/2.6.2/lib/css/zenburn.css">
9-
<!--__HTML_HEADER__-->
109
</head>
1110
<body>
1211

0 commit comments

Comments
 (0)