Skip to content

Commit

Permalink
Add possibility to choose from reveal.js built-in presentation styles
Browse files Browse the repository at this point in the history
  • Loading branch information
cloose committed Nov 20, 2014
1 parent d809277 commit 56d5329
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 21 deletions.
51 changes: 46 additions & 5 deletions app-static/styles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ static const Style BUILTIN_CLEARNESS_STYLE = { "Default", "Default", "Clearness"
static const Style BUILTIN_CLEARNESS_DARK_STYLE = { "Clearness Dark", "Default", "Clearness Dark" };
static const Style BUILTIN_BYWORD_DARK_STYLE = { "Byword Dark", "Default", "Byword Dark" };

static const Style DEFAULT_PRESENTATION_STYLE = { "Default", "Default", "Default Presentation" };
static const Style BEIGE_PRESENTATION_STYLE = { "Default", "Default", "Beige" };
static const Style SKY_PRESENTATION_STYLE = { "Default", "Default", "Sky" };
static const Style NIGHT_PRESENTATION_STYLE = { "Default", "Default", "Night" };
static const Style SERIF_PRESENTATION_STYLE = { "Default", "Default", "Serif" };
static const Style SIMPLE_PRESENTATION_STYLE = { "Default", "Default", "Simple" };
static const Style SOLARIZED_PRESENTATION_STYLE = { "Solarized Light", "Default", "Solarized" };


Styles::Styles()
{
setupBuiltinMarkdownHighlightings();
Expand All @@ -32,14 +41,22 @@ Styles::Styles()
setupBuiltinStyles();
}

QStringList Styles::styleNames() const
QStringList Styles::htmlPreviewStyleNames() const
{
return m_htmlPreviewStylesIndex;
}

QStringList Styles::presentationStyleNames() const
{
return QStringList(m_stylesIndex);
return m_presentationStylesIndex;
}

Style Styles::style(const QString &name) const
{
return m_styles[m_stylesIndex.indexOf(name)];
if (m_htmlPreviewStylesIndex.contains(name))
return m_htmlPreviewStyles[m_htmlPreviewStylesIndex.indexOf(name)];
else
return m_presentationStyles[m_presentationStylesIndex.indexOf(name)];
}

QStringList Styles::markdownHighlightings() const
Expand Down Expand Up @@ -98,16 +115,40 @@ void Styles::setupBuiltinPreviewStylesheets()
m_previewStylesheets.insert("Clearness", "qrc:/css/clearness.css");
m_previewStylesheets.insert("Clearness Dark", "qrc:/css/clearness-dark.css");
m_previewStylesheets.insert("Byword Dark", "qrc:/css/byword-dark.css");

m_previewStylesheets.insert("Default Presentation", "https://cdn.jsdelivr.net/reveal.js/2.6.2/css/theme/default.css");
m_previewStylesheets.insert("Beige", "https://cdn.jsdelivr.net/reveal.js/2.6.2/css/theme/beige.css");
m_previewStylesheets.insert("Sky", "https://cdn.jsdelivr.net/reveal.js/2.6.2/css/theme/sky.css");
m_previewStylesheets.insert("Night", "https://cdn.jsdelivr.net/reveal.js/2.6.2/css/theme/night.css");
m_previewStylesheets.insert("Serif", "https://cdn.jsdelivr.net/reveal.js/2.6.2/css/theme/serif.css");
m_previewStylesheets.insert("Simple", "https://cdn.jsdelivr.net/reveal.js/2.6.2/css/theme/simple.css");
m_previewStylesheets.insert("Solarized", "https://cdn.jsdelivr.net/reveal.js/2.6.2/css/theme/solarized.css");
}

void Styles::setupBuiltinStyles()
{
m_stylesIndex << "Default" << "Github" << "Solarized Light"
m_htmlPreviewStylesIndex << "Default" << "Github" << "Solarized Light"
<< "Solarized Dark" << "Clearness" << "Clearness Dark"
<< "Byword Dark";
m_styles << BUILTIN_DEFAULT_STYLE << BUILTIN_GITHUB_STYLE
m_htmlPreviewStyles << BUILTIN_DEFAULT_STYLE << BUILTIN_GITHUB_STYLE
<< BUILTIN_SOLARIZED_LIGHT_STYLE << BUILTIN_SOLARIZED_DARK_STYLE
<< BUILTIN_CLEARNESS_STYLE << BUILTIN_CLEARNESS_DARK_STYLE
<< BUILTIN_BYWORD_DARK_STYLE;

m_presentationStylesIndex << DEFAULT_PRESENTATION_STYLE.previewStylesheet
<< BEIGE_PRESENTATION_STYLE.previewStylesheet
<< SKY_PRESENTATION_STYLE.previewStylesheet
<< NIGHT_PRESENTATION_STYLE.previewStylesheet
<< SERIF_PRESENTATION_STYLE.previewStylesheet
<< SIMPLE_PRESENTATION_STYLE.previewStylesheet
<< SOLARIZED_PRESENTATION_STYLE.previewStylesheet;

m_presentationStyles << DEFAULT_PRESENTATION_STYLE
<< BEIGE_PRESENTATION_STYLE
<< SKY_PRESENTATION_STYLE
<< NIGHT_PRESENTATION_STYLE
<< SERIF_PRESENTATION_STYLE
<< SIMPLE_PRESENTATION_STYLE
<< SOLARIZED_PRESENTATION_STYLE;
}

9 changes: 6 additions & 3 deletions app-static/styles.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class Styles
public:
Styles();

QStringList styleNames() const;
QStringList htmlPreviewStyleNames() const;
QStringList presentationStyleNames() const;
Style style(const QString &name) const;

QStringList markdownHighlightings() const;
Expand All @@ -54,8 +55,10 @@ class Styles
QMap<QString, QString> m_markdownHighlightings;
QMap<QString, QString> m_codeHighlightings;
QMap<QString, QString> m_previewStylesheets;
QList<QString> m_stylesIndex;
QList<Style> m_styles;
QStringList m_htmlPreviewStylesIndex;
QList<Style> m_htmlPreviewStyles;
QStringList m_presentationStylesIndex;
QList<Style> m_presentationStyles;
};

#endif // STYLES_H
11 changes: 10 additions & 1 deletion app-static/template/presentationtemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ QString PresentationTemplate::render(const QString &body, RenderOptions options)
}

return QString(presentationTemplate)
.replace(QLatin1String("<!--__HTML_HEADER__-->"), QString())
.replace(QLatin1String("<!--__HTML_HEADER__-->"), buildHtmlHeader())
.replace(QLatin1String("<!--__HTML_CONTENT__-->"), body)
.replace(QLatin1String("<!--__REVEAL_PLUGINS__-->"), buildRevealPlugins(options));
}
Expand All @@ -43,6 +43,15 @@ QString PresentationTemplate::exportAsHtml(const QString &, const QString &body,
return render(body, options);
}

QString PresentationTemplate::buildHtmlHeader() const
{
QString header;

header += QString("<link rel=\"stylesheet\" href=\"%1\" id=\"theme\">").arg(previewStyleSheet());

return header;
}

QString PresentationTemplate::buildRevealPlugins(RenderOptions options) const
{
QString plugins;
Expand Down
1 change: 1 addition & 0 deletions app-static/template/presentationtemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class PresentationTemplate : public Template
virtual QString exportAsHtml(const QString &header, const QString &body, RenderOptions options) const;

private:
QString buildHtmlHeader() const;
QString buildRevealPlugins(RenderOptions options) const;

QString presentationTemplate;
Expand Down
10 changes: 7 additions & 3 deletions app-static/template/template.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ class Template

virtual ~Template() {}

QString codeHighlightingStyle() const { return highlightingStyle; }
void setCodeHighlightingStyle(const QString &style) { highlightingStyle = style; }
QString codeHighlightingStyle() const { return m_highlightingStyle; }
void setCodeHighlightingStyle(const QString &style) { m_highlightingStyle = style; }

QString previewStyleSheet() const { return m_previewStyleSheet; }
void setPreviewStyleSheet(const QString &stylesheet) { m_previewStyleSheet = stylesheet; }

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

private:
QString highlightingStyle;
QString m_highlightingStyle;
QString m_previewStyleSheet;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(Template::RenderOptions)
Expand Down
5 changes: 5 additions & 0 deletions app/htmlpreviewgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ void HtmlPreviewGenerator::setCodeHighlightingStyle(const QString &style)
generateHtmlFromMarkdown();
}

void HtmlPreviewGenerator::setPreviewStyleSheet(const QString &stylesheet)
{
converter->templateRenderer()->setPreviewStyleSheet(stylesheet);
}

void HtmlPreviewGenerator::markdownConverterChanged()
{
QString style;
Expand Down
4 changes: 3 additions & 1 deletion app/htmlpreviewgenerator.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013 Christian Loose <[email protected]>
* Copyright 2013-2014 Christian Loose <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -45,6 +45,8 @@ public slots:
void setCodeHighlightingEnabled(bool enabled);
void setCodeHighlightingStyle(const QString &style);

void setPreviewStyleSheet(const QString &stylesheet);

void markdownConverterChanged();

signals:
Expand Down
38 changes: 33 additions & 5 deletions app/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ MainWindow::MainWindow(const QString &fileName, QWidget *parent) :
ui(new Ui::MainWindow),
options(new Options(this)),
diskCache(new QNetworkDiskCache(this)),
htmlPreviewStylesGroup(0),
presentationStylesGroup(0),
zoomInAction(0),
zoomOutAction(0),
zoomResetAction(0),
Expand Down Expand Up @@ -500,6 +502,7 @@ void MainWindow::styleBuiltinStyle()
QAction *action = qobject_cast<QAction*>(sender());
Style style = styles->style(action->data().toString());
generator->setCodeHighlightingStyle(styles->pathForCodeHighlighting(style));
generator->setPreviewStyleSheet(styles->pathForPreviewStylesheet(style));

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

menu->exec(styleLabel->mapToGlobal(pos));
}
Expand Down Expand Up @@ -877,9 +880,11 @@ void MainWindow::markdownConverterChanged()
viewSynchronizer = new HtmlViewSynchronizer(ui->webView, ui->plainTextEdit);
connect(generator, SIGNAL(htmlResultReady(QString)),
viewSynchronizer, SLOT(rememberScrollBarPos()));
loadBuiltinStyles();
break;
case Options::RevealMarkdownConverter:
viewSynchronizer = new RevealViewSynchronizer(ui->webView, ui->plainTextEdit);
setupPresentationStyles();
break;
default:
viewSynchronizer = 0;
Expand Down Expand Up @@ -1195,17 +1200,40 @@ void MainWindow::updateSplitter()
ui->splitter->setSizes(childSizes);
}

void MainWindow::setupPresentationStyles()
{
ui->menuStyles->clear();

// put style actions in a group
delete presentationStylesGroup;
presentationStylesGroup = new QActionGroup(this);

int key = 1;
foreach(const QString &styleName, styles->presentationStyleNames()) {
QAction *action = ui->menuStyles->addAction(styleName);
action->setShortcut(QKeySequence(tr("Ctrl+%1").arg(key++)));
action->setCheckable(true);
action->setActionGroup(presentationStylesGroup);
action->setData(styleName);
connect(action, SIGNAL(triggered()),
this, SLOT(styleBuiltinStyle()));
}
}

void MainWindow::loadBuiltinStyles()
{
ui->menuStyles->clear();

// put style actions in a group
stylesGroup = new QActionGroup(this);
delete htmlPreviewStylesGroup;
htmlPreviewStylesGroup = new QActionGroup(this);

int key = 1;
foreach(const QString &styleName, styles->styleNames()) {
foreach(const QString &styleName, styles->htmlPreviewStyleNames()) {
QAction *action = ui->menuStyles->addAction(styleName);
action->setShortcut(QKeySequence(tr("Ctrl+%1").arg(key++)));
action->setCheckable(true);
action->setActionGroup(stylesGroup);
action->setActionGroup(htmlPreviewStylesGroup);
action->setData(styleName);
connect(action, SIGNAL(triggered()),
this, SLOT(styleBuiltinStyle()));
Expand All @@ -1229,7 +1257,7 @@ void MainWindow::loadCustomStyles()
QString fileName = it.fileName();
QAction *action = ui->menuStyles->addAction(QFileInfo(fileName).baseName());
action->setCheckable(true);
action->setActionGroup(stylesGroup);
action->setActionGroup(htmlPreviewStylesGroup);
action->setData(it.filePath());

connect(action, SIGNAL(triggered()),
Expand Down
4 changes: 3 additions & 1 deletion app/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ private slots:
bool maybeSave();
void setFileName(const QString &fileName);
void updateSplitter();
void setupPresentationStyles();
void loadBuiltinStyles();
void loadCustomStyles();
void readSettings();
Expand All @@ -152,7 +153,8 @@ private slots:
RecentFilesMenu *recentFilesMenu;
Options *options;
QNetworkDiskCache *diskCache;
QActionGroup *stylesGroup;
QActionGroup *htmlPreviewStylesGroup;
QActionGroup *presentationStylesGroup;
QAction *zoomInAction;
QAction *zoomOutAction;
QAction *zoomResetAction;
Expand Down
3 changes: 1 addition & 2 deletions app/template_presentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/reveal.js/2.6.2/css/reveal.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/reveal.js/2.6.2/css/theme/default.css" id="theme">
<!--__HTML_HEADER__-->
<!-- For syntax highlighting -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/reveal.js/2.6.2/lib/css/zenburn.css">
<!--__HTML_HEADER__-->
</head>
<body>

Expand Down

0 comments on commit 56d5329

Please sign in to comment.