Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Support for custom styles #190

Open
wants to merge 38 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
396146d
Introduce Styles class that handles the builtin styles
cloose Nov 13, 2014
d809277
Use new Styles class to setup actions for builtin styles
cloose Nov 14, 2014
56d5329
Add possibility to choose from reveal.js built-in presentation styles
cloose Nov 20, 2014
f5c680b
Introduce Styles class that handles the builtin styles
cloose Nov 13, 2014
0cfced8
Use new Styles class to setup actions for builtin styles
cloose Nov 14, 2014
5c998bd
Add possibility to choose from reveal.js built-in presentation styles
cloose Nov 20, 2014
b30d4cd
First rough version of UI for changing styles via options dialog (no …
cloose Nov 25, 2014
e3e7b67
Merge branch 'wip/custom-styles' of https://github.com/cloose/CuteMar…
cloose Nov 25, 2014
2cbf273
Moved Style struct to own header
cloose Nov 26, 2014
e05670f
Merge branch 'wip/custom-styles' of https://github.com/cloose/CuteMar…
cloose Nov 26, 2014
4c66dbe
Fix compile with changed Style struct
cloose Nov 26, 2014
0b3ab3b
Add new StyleCollection class
cloose Nov 28, 2014
eb67ede
Add unit test for StyleCollection class
cloose Dec 1, 2014
f0d6232
Add contains() method to StyleCollection (inkl. unit test)
cloose Dec 1, 2014
bc17043
Add base classes for collections and JSON translators
cloose Dec 3, 2014
9e24907
Generalize reading and saving JSON files
cloose Dec 4, 2014
4264fee
Add JSON translator for style structure
cloose Dec 4, 2014
d833792
Add missing virtual destructor to JsonTranslator
cloose Dec 5, 2014
0771f39
Fix memory leak in JsonFile
cloose Dec 5, 2014
4e28b9d
Add factory for JsonStyleTranslator and unit test for JsonTranslatorF…
cloose Dec 5, 2014
a41cfcf
Add JsonStyleFileTest and complete JsonStyleTranslator implementation
cloose Dec 5, 2014
464295e
Add missing include for QTextStream header
cloose Dec 5, 2014
94eb852
Load builtin HTML preview styles from JSON file
cloose Dec 5, 2014
447acae
Load builtin styles from JSON files
cloose Dec 5, 2014
87c657e
Add all existing styles to JSON files
cloose Dec 8, 2014
5bdc574
Starting to rework styles tab on OptionsDialog
cloose Dec 8, 2014
6077e91
Some more progress on style dialog
cloose Dec 10, 2014
c3a1992
Add update() and remove() method to Collection<T> interface and Style…
cloose Dec 11, 2014
bb3cb26
It's now possible to add/edit/remove HTML preview styles via the opti…
cloose Dec 11, 2014
b176ce1
Move all JSON handling classes to a subfolder
cloose Dec 12, 2014
dc68716
Renamed Collection<T> to JsonCollection<T> and also moved to subfolder
cloose Dec 12, 2014
ce9663d
Add name() method to JsonCollection implementations and use it in the…
cloose Dec 12, 2014
d3d89c0
Also use name() in private isValid() methods
cloose Dec 12, 2014
04615d6
Merge branch 'develop' into wip/custom-styles
cloose Dec 15, 2014
2dd7a3b
Fix compile after merge
cloose Dec 15, 2014
df3b017
Remove duplicate headers from qmake project
cloose Dec 15, 2014
d6cd569
Merge branch 'develop' into wip/custom-styles
cloose Dec 15, 2014
e38b22d
Simplify JsonStyleTranslator based on the JsonTranslator changes
cloose Dec 15, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions app-static/app-static.pro
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ SOURCES += \
converter/revealmarkdownconverter.cpp \
template/htmltemplate.cpp \
template/presentationtemplate.cpp \
styles/jsonstyletranslator.cpp \
styles/stylecollection.cpp \
datalocation.cpp \
slidelinemapping.cpp \
viewsynchronizer.cpp \
revealviewsynchronizer.cpp \
htmlviewsynchronizer.cpp
htmlviewsynchronizer.cpp \
styles.cpp

HEADERS += \
json/jsoncollection.h \
Expand All @@ -42,11 +45,15 @@ HEADERS += \
template/template.h \
template/htmltemplate.h \
template/presentationtemplate.h \
styles/jsonstyletranslator.h \
styles/style.h \
styles/stylecollection.h \
datalocation.h \
slidelinemapping.h \
viewsynchronizer.h \
revealviewsynchronizer.h \
htmlviewsynchronizer.h
htmlviewsynchronizer.h \
styles.h

#unix:!symbian {
# maemo5 {
Expand Down
11 changes: 11 additions & 0 deletions app-static/json/jsontranslatorfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "snippets/snippet.h"
#include "snippets/jsonsnippettranslator.h"

#include "styles/style.h"
#include "styles/jsonstyletranslator.h"

template <class T>
class JsonTranslatorFactory
Expand All @@ -39,6 +41,15 @@ template <> class JsonTranslatorFactory<Snippet>
}
};

template <> class JsonTranslatorFactory<Style>
{
public:
static JsonTranslator<Style> *create()
{
return new JsonStyleTranslator();
}
};

#endif // JSONTRANSLATOR_H


158 changes: 158 additions & 0 deletions app-static/styles.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
* Copyright 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
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "styles.h"

#include <QSharedPointer>
#include <json/jsonfile.h>

static const Style BUILTIN_DEFAULT_STYLE = Style("Default", "Default", "Default", "Default", true );
static const Style DEFAULT_PRESENTATION_STYLE = Style("Default Presentation", "Default", "Default", "Default Presentation", true );

QMap<QString, QString> Styles::m_markdownHighlightings;
QMap<QString, QString> Styles::m_codeHighlightings;
QMap<QString, QString> Styles::m_previewStylesheets;
QSharedPointer<StyleCollection> Styles::m_htmlPreviewStyles;
QSharedPointer<StyleCollection> Styles::m_presentationStyles;

Styles::Styles()
{
if (m_htmlPreviewStyles.isNull()) {
setupBuiltinMarkdownHighlightings();
setupBuiltinCodeHighlightings();
setupBuiltinPreviewStylesheets();
setupBuiltinStyles();
}
}

QStringList Styles::htmlPreviewStyleNames() const
{
return m_htmlPreviewStyles->styleNames();
}

QStringList Styles::presentationStyleNames() const
{
return m_presentationStyles->styleNames();
}

Style Styles::style(const QString &name) const
{
if (m_htmlPreviewStyles->contains(name))
return m_htmlPreviewStyles->style(name);
else
return m_presentationStyles->style(name);
}

void Styles::addHtmlPreviewStyle(const Style &style)
{
m_htmlPreviewStyles->insert(style);
}

void Styles::updateHtmlPreviewStyle(const Style &style)
{
m_htmlPreviewStyles->update(style);
}

void Styles::removeHtmlPreviewStyle(const QString &styleName)
{
Style style = this->style(styleName);
m_htmlPreviewStyles->remove(style);
}

QStringList Styles::markdownHighlightings() const
{
return QStringList(m_markdownHighlightings.keys());
}

QString Styles::pathForMarkdownHighlighting(const Style &style) const
{
return m_markdownHighlightings[style.markdownHighlighting];
}

QStringList Styles::codeHighlightings() const
{
return QStringList(m_codeHighlightings.keys());
}

QString Styles::pathForCodeHighlighting(const Style &style) const
{
return m_codeHighlightings[style.codeHighlighting];
}

QStringList Styles::previewStylesheets() const
{
return QStringList(m_previewStylesheets.keys());
}

QString Styles::pathForPreviewStylesheet(const Style &style) const
{
return m_previewStylesheets[style.previewStylesheet];
}

QSharedPointer<StyleCollection> Styles::htmlPreviewStyles() const
{
return m_htmlPreviewStyles;
}

void Styles::setupBuiltinMarkdownHighlightings()
{
m_markdownHighlightings.insert("Default", ":/theme/default.txt");
m_markdownHighlightings.insert("Solarized Light", ":/theme/solarized-light+.txt");
m_markdownHighlightings.insert("Solarized Dark", ":/theme/solarized-dark+.txt");
m_markdownHighlightings.insert("Clearness Dark", ":/theme/clearness-dark+.txt");
m_markdownHighlightings.insert("Byword Dark", ":/theme/byword-dark.txt");
}

void Styles::setupBuiltinCodeHighlightings()
{
m_codeHighlightings.insert("Default", "default");
m_codeHighlightings.insert("Github", "github");
m_codeHighlightings.insert("Solarized Light", "solarized_light");
m_codeHighlightings.insert("Solarized Dark", "solarized_dark");
}

void Styles::setupBuiltinPreviewStylesheets()
{
m_previewStylesheets.insert("Default", "qrc:/css/markdown.css");
m_previewStylesheets.insert("Github", "qrc:/css/github.css");
m_previewStylesheets.insert("Solarized Light", "qrc:/css/solarized-light.css");
m_previewStylesheets.insert("Solarized Dark", "qrc:/css/solarized-dark.css");
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_htmlPreviewStyles = QSharedPointer<StyleCollection>::create();
if (!JsonFile<Style>::load(":/builtin-htmlpreview-styles.json", m_htmlPreviewStyles.data())) {
m_htmlPreviewStyles->insert(BUILTIN_DEFAULT_STYLE);
}

m_presentationStyles = QSharedPointer<StyleCollection>::create();
if (!JsonFile<Style>::load(":/builtin-presentation-styles.json", m_presentationStyles.data())) {
m_presentationStyles->insert(DEFAULT_PRESENTATION_STYLE);
}
}

64 changes: 64 additions & 0 deletions app-static/styles.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 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
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef STYLES_H
#define STYLES_H

#include <QMap>
#include <QString>
#include <QStringList>

#include "styles/style.h"
#include "styles/stylecollection.h"


class Styles
{
public:
Styles();

QStringList htmlPreviewStyleNames() const;
QStringList presentationStyleNames() const;
Style style(const QString &name) const;
void addHtmlPreviewStyle(const Style &style);
void updateHtmlPreviewStyle(const Style &style);
void removeHtmlPreviewStyle(const QString &styleName);

QStringList markdownHighlightings() const;
QString pathForMarkdownHighlighting(const Style &style) const;

QStringList codeHighlightings() const;
QString pathForCodeHighlighting(const Style &style) const;

QStringList previewStylesheets() const;
QString pathForPreviewStylesheet(const Style &style) const;

QSharedPointer<StyleCollection> htmlPreviewStyles() const;

private:
void setupBuiltinMarkdownHighlightings();
void setupBuiltinCodeHighlightings();
void setupBuiltinPreviewStylesheets();
void setupBuiltinStyles();

static QMap<QString, QString> m_markdownHighlightings;
static QMap<QString, QString> m_codeHighlightings;
static QMap<QString, QString> m_previewStylesheets;
static QSharedPointer<StyleCollection> m_htmlPreviewStyles;
static QSharedPointer<StyleCollection> m_presentationStyles;
};

#endif // STYLES_H
56 changes: 56 additions & 0 deletions app-static/styles/jsonstyletranslator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 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
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "jsonstyletranslator.h"

#include "style.h"

namespace {

static const QLatin1String NAME("name");
static const QLatin1String MARKDOWN_HIGHLIGHTING("markdownHighlighting");
static const QLatin1String CODE_HIGHLIGHTING("codeHighlighting");
static const QLatin1String PREVIEW_STYLESHEET("previewStylesheet");
static const QLatin1String BUILTIN("builtIn");

}

Style JsonStyleTranslator::fromJsonObject(const QJsonObject &object)
{
Style style;

style.name = object.value(NAME).toString();
style.markdownHighlighting = object.value(MARKDOWN_HIGHLIGHTING).toString();
style.codeHighlighting = object.value(CODE_HIGHLIGHTING).toString();
style.previewStylesheet = object.value(PREVIEW_STYLESHEET).toString();
style.builtIn = object.value(BUILTIN).toBool();

return style;
}

QJsonObject JsonStyleTranslator::toJsonObject(const Style &style)
{
QJsonObject object;

object.insert(NAME, style.name);
object.insert(MARKDOWN_HIGHLIGHTING, style.markdownHighlighting);
object.insert(CODE_HIGHLIGHTING, style.codeHighlighting);
object.insert(PREVIEW_STYLESHEET, style.previewStylesheet);
object.insert(BUILTIN, style.builtIn);

return object;
}

33 changes: 33 additions & 0 deletions app-static/styles/jsonstyletranslator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 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
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef JSONSTYLETRANSLATOR_H
#define JSONSTYLETRANSLATOR_H

#include "json/jsontranslator.h"
#include <QJsonObject>
struct Style;


class JsonStyleTranslator : public JsonTranslator<Style>
{
private:
Style fromJsonObject(const QJsonObject &object);
QJsonObject toJsonObject(const Style &style);
};

#endif // JSONSTYLETRANSLATOR_H

Loading