Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
language: cpp
compiler:
- gcc
- g++
- clang
before_install:
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test # for g++ 4.8
- sudo add-apt-repository -y ppa:beineri/opt-qt521 # for Qt 5.2
- sudo apt-get update -qq
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
install:
- if [ "$CXX" == "g++" ]; then sudo apt-get install -qq g++-4.8; sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 90; fi
- sudo apt-get install -qq qt52base qt52declarative qt52webkit qt52tools libhunspell-dev
- sudo apt-get install -qq libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
before_script:
Expand Down
9 changes: 9 additions & 0 deletions app-static/app-static.pro
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ SOURCES += \
converter/revealmarkdownconverter.cpp \
template/htmltemplate.cpp \
template/presentationtemplate.cpp \
themes/jsonthemetranslator.cpp \
themes/stylemanager.cpp \
themes/theme.cpp \
themes/themecollection.cpp \
completionlistmodel.cpp \
datalocation.cpp \
slidelinemapping.cpp \
Expand All @@ -43,6 +47,11 @@ HEADERS += \
template/template.h \
template/htmltemplate.h \
template/presentationtemplate.h \
themes/jsonthemetranslator.h \
themes/jsonthemetranslatorfactory.h \
themes/stylemanager.h \
themes/theme.h \
themes/themecollection.h \
completionlistmodel.h \
datalocation.h \
slidelinemapping.h \
Expand Down
51 changes: 51 additions & 0 deletions app-static/themes/jsonthemetranslator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2015 Christian Loose <christian.loose@hamburg.de>
*
* 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 "jsonthemetranslator.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 BUILT_IN("builtIn");

}

Theme JsonThemeTranslator::fromJsonObject(const QJsonObject &object)
{
QString name = object.value(NAME).toString();
QString markdownHighlighting = object.value(MARKDOWN_HIGHLIGHTING).toString();
QString codeHighlighting = object.value(CODE_HIGHLIGHTING).toString();
QString previewStylesheet = object.value(PREVIEW_STYLESHEET).toString();
bool builtIn = object.value(BUILT_IN).toBool();

return { name, markdownHighlighting, codeHighlighting, previewStylesheet, builtIn };
}

QJsonObject JsonThemeTranslator::toJsonObject(const Theme &theme)
{
QJsonObject object;
object.insert(NAME, theme.name());
object.insert(MARKDOWN_HIGHLIGHTING, theme.markdownHighlighting());
object.insert(CODE_HIGHLIGHTING, theme.codeHighlighting());
object.insert(PREVIEW_STYLESHEET, theme.previewStylesheet());
object.insert(BUILT_IN, theme.isBuiltIn());

return object;
}

34 changes: 34 additions & 0 deletions app-static/themes/jsonthemetranslator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2015 Christian Loose <christian.loose@hamburg.de>
*
* 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 JSONTHEMETRANSLATOR_H
#define JSONTHEMETRANSLATOR_H

#include <jsontranslator.h>
#include <QJsonObject>
#include "theme.h"


class JsonThemeTranslator : public JsonTranslator<Theme>
{
private:
Theme fromJsonObject(const QJsonObject &object);
QJsonObject toJsonObject(const Theme &theme);
};

#endif // JSONTHEMETRANSLATOR_H


37 changes: 37 additions & 0 deletions app-static/themes/jsonthemetranslatorfactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2015 Christian Loose <christian.loose@hamburg.de>
*
* 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 JSONTHEMETRANSLATORFACTORY_H
#define JSONTHEMETRANSLATORFACTORY_H

#include <jsontranslatorfactory.h>
#include <jsontranslator.h>

#include "themes/theme.h"
#include "themes/jsonthemetranslator.h"


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

#endif // JSONTHEMETRANSLATORFACTORY_H

72 changes: 72 additions & 0 deletions app-static/themes/stylemanager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2015 Christian Loose <christian.loose@hamburg.de>
*
* 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 "stylemanager.h"

#include <QMap>


static const QMap<QString, QString> BUILTIN_MARKDOWN_HIGHLIGHTINGS = {
{ "Default", "default" },
{ "Solarized Light", "solarized-light" },
{ "Solarized Dark", "solarized-dark" },
{ "Clearness Dark", "clearness-dark" },
{ "Byword Dark", "byword-dark" }
};

static const QMap<QString, QString> BUILTIN_CODE_HIGHLIGHTINGS = {
{ "Default", "default" },
{ "Github", "github" },
{ "Solarized Light", "solarized_light" },
{ "Solarized Dark", "solarized_dark" }
};

static const QMap<QString, QString> BUILTIN_PREVIEW_STYLESHEETS = {
{ "Default", "qrc:/css/markdown.css" },
{ "Github", "qrc:/css/github.css" },
{ "Solarized Light", "qrc:/css/solarized-light.css" },
{ "Solarized Dark", "qrc:/css/solarized-dark.css" },
{ "Clearness", "qrc:/css/clearness.css" },
{ "Clearness Dark", "qrc:/css/clearness-dark.css" },
{ "Byword Dark", "qrc:/css/byword-dark.css" }
};

QMap<QString, QString> StyleManager::customPreviewStylesheets;


void StyleManager::insertCustomPreviewStylesheet(const QString &styleName, const QString &stylePath)
{
customPreviewStylesheets.insert(styleName, stylePath);
}

QString StyleManager::markdownHighlightingPath(const Theme &theme)
{
return BUILTIN_MARKDOWN_HIGHLIGHTINGS[theme.markdownHighlighting()];
}

QString StyleManager::codeHighlightingPath(const Theme &theme)
{
return BUILTIN_CODE_HIGHLIGHTINGS[theme.codeHighlighting()];
}

QString StyleManager::previewStylesheetPath(const Theme &theme)
{
if (customPreviewStylesheets.contains(theme.previewStylesheet())) {
return customPreviewStylesheets[theme.previewStylesheet()];
}

return BUILTIN_PREVIEW_STYLESHEETS[theme.previewStylesheet()];
}
39 changes: 39 additions & 0 deletions app-static/themes/stylemanager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2015 Christian Loose <christian.loose@hamburg.de>
*
* 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 STYLEMANAGER_H
#define STYLEMANAGER_H

#include <QMap>
#include <QString>
#include "theme.h"


class StyleManager
{
public:
void insertCustomPreviewStylesheet(const QString &styleName, const QString &stylePath);

static QString markdownHighlightingPath(const Theme &theme);
static QString codeHighlightingPath(const Theme &theme);
static QString previewStylesheetPath(const Theme &theme);

private:
static QMap<QString, QString> customPreviewStylesheets;
};

#endif // STYLEMANAGER_H

47 changes: 47 additions & 0 deletions app-static/themes/theme.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2015 Christian Loose <christian.loose@hamburg.de>
*
* 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 "theme.h"

Theme::Theme(const QString &name,
const QString &markdownHighlighting,
const QString &codeHighlighting,
const QString &previewStylesheet,
bool builtIn) :
m_name(name),
m_markdownHighlighting(markdownHighlighting),
m_codeHighlighting(codeHighlighting),
m_previewStylesheet(previewStylesheet),
m_builtIn(builtIn)
{
checkInvariants();
}

void Theme::checkInvariants() const
{
if (m_name.isEmpty()) {
throw std::runtime_error("theme name must not be empty");
}
if (m_markdownHighlighting.isEmpty()) {
throw std::runtime_error("markdown highlighting style must not be empty");
}
if (m_codeHighlighting.isEmpty()) {
throw std::runtime_error("code highlighting style must not be empty");
}
if (m_previewStylesheet.isEmpty()) {
throw std::runtime_error("preview stylesheet must not be empty");
}
}
64 changes: 64 additions & 0 deletions app-static/themes/theme.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2015 Christian Loose <christian.loose@hamburg.de>
*
* 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 THEME_H
#define THEME_H

#include <QString>
#include <stdexcept>


class Theme
{
public:
Theme(const QString &name,
const QString &markdownHighlighting,
const QString &codeHighlighting,
const QString &previewStylesheet,
bool builtIn = false);

QString name() const { return m_name; }

QString markdownHighlighting() const { return m_markdownHighlighting; }

QString codeHighlighting() const { return m_codeHighlighting; }

QString previewStylesheet() const { return m_previewStylesheet; }

bool isBuiltIn() const { return m_builtIn; }

bool operator<(const Theme &rhs) const
{
return m_name < rhs.name();
}

bool operator ==(const Theme &rhs) const
{
return m_name == rhs.name();
}

private:
void checkInvariants() const;

private:
QString m_name;
QString m_markdownHighlighting;
QString m_codeHighlighting;
QString m_previewStylesheet;
bool m_builtIn;
};

#endif // THEME_H
Loading