From 70d12982509d4cc6b540a5dcda8c21bb6323183c Mon Sep 17 00:00:00 2001 From: James Hogan Date: Fri, 26 Dec 2008 11:23:23 +0000 Subject: [PATCH] Basic stringification of KwCssStyle and KwCssUnprocessed placeholder --- kworship/css/CMakeLists.txt | 1 + kworship/css/KwCssStyle.cpp | 118 ++++++++++++++++++++++++++++++++++++++++ kworship/css/KwCssStyle.h | 34 +++++++++++- kworship/css/KwCssStyleRule.cpp | 2 +- kworship/css/KwCssStyleRule.h | 4 +- kworship/css/KwCssUnprocessed.h | 60 ++++++++++++++++++++ 6 files changed, 215 insertions(+), 4 deletions(-) create mode 100644 kworship/css/KwCssStyle.cpp create mode 100644 kworship/css/KwCssUnprocessed.h diff --git a/kworship/css/CMakeLists.txt b/kworship/css/CMakeLists.txt index 2c5d7dd..c093d45 100644 --- a/kworship/css/CMakeLists.txt +++ b/kworship/css/CMakeLists.txt @@ -9,6 +9,7 @@ set(kworshipcss_SRCS KwCssScope.cpp KwCssScopeKey.cpp KwCssStyles.cpp + KwCssStyle.cpp KwCssStyleStates.cpp KwCssStyleRule.cpp KwCssStyleSheet.cpp diff --git a/kworship/css/KwCssStyle.cpp b/kworship/css/KwCssStyle.cpp new file mode 100644 index 0000000..189144e --- /dev/null +++ b/kworship/css/KwCssStyle.cpp @@ -0,0 +1,118 @@ +/*************************************************************************** + * This file is part of KWorship. * + * Copyright 2008 James Hogan * + * * + * KWorship 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. * + * * + * KWorship 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 KWorship. If not, write to the Free Software Foundation, * + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +/** + * @file KwCssStyle.cpp + * @brief Typed cascading style property. + * @author James Hogan + */ + +#include "KwCssStyle.h" + +#include "KwCssUnprocessed.h" +template <> +KwCssUnprocessed KwCssStringify(const KwCssUnprocessed& value) +{ + return value; +} +template <> +KwCssUnprocessed KwCssUnstringify(const KwCssUnprocessed& value, bool* success) +{ + *success = true; + return value; +} + +#include +template <> +KwCssUnprocessed KwCssStringify(const KwResourceLink& value) +{ + switch (value.type()) + { + case KwResourceLink::Url: + { + QString url = value.url().url(); + url.replace('\\', "\\\\") + .replace('"', "\\\""); + return QString("\"%1\"").arg(url); + } + + case KwResourceLink::FileRelative: + { + QString url = value.path(); + url.replace('\\', "\\\\") + .replace('"', "\\\""); + return QString("frel \"%1\"").arg(url); + } + + case KwResourceLink::ArchiveRoot: + { + QString url = value.path(); + url.replace('\\', "\\\\") + .replace('"', "\\\""); + return QString("aroot \"%1\"").arg(url); + } + + case KwResourceLink::ArchiveRelative: + { + QString url = value.path(); + url.replace('\\', "\\\\") + .replace('"', "\\\""); + return QString("arel \"%1\"").arg(url); + } + + case KwResourceLink::Null: + default: + { + return "null"; + } + + } +} +template <> +KwResourceLink KwCssUnstringify(const KwCssUnprocessed& value, bool* success) +{ + *success = false; + return KwResourceLink(); +} + +#include +template <> +KwCssUnprocessed KwCssStringify(const QBrush& value) +{ + return "Brush()"; +} +template <> +QBrush KwCssUnstringify(const KwCssUnprocessed& value, bool* success) +{ + *success = true; + return QBrush(Qt::black); +} + +#include +template <> +KwCssUnprocessed KwCssStringify(const QPixmap& value) +{ + return "Pixmap()"; +} +template <> +QPixmap KwCssUnstringify(const KwCssUnprocessed& value, bool* success) +{ + *success = false; + return QPixmap(); +} diff --git a/kworship/css/KwCssStyle.h b/kworship/css/KwCssStyle.h index f1b0a81..95dc37e 100644 --- a/kworship/css/KwCssStyle.h +++ b/kworship/css/KwCssStyle.h @@ -27,6 +27,15 @@ */ #include "KwCssAbstractStyle.h" +#include "KwCssUnprocessed.h" + +/// Stringify a type. +template +KwCssUnprocessed KwCssStringify(const T& value); + +/// Unstringify a type. +template +T KwCssUnstringify(const KwCssUnprocessed& value, bool* success); /// Typed cascading style property. /** @@ -107,7 +116,30 @@ class KwCssStyle : public KwCssAbstractStyle // Reimplemented virtual QString toString() const { - return "/* unimplemented KwCssStyle::toString() */"; + switch (m_operation) + { + case revert: + { + return "revert"; + } + + case override: + { + return KwCssStringify(m_value); + } + + case clear: + { + return "clear"; + } + + case none: + default: + { + return "inherit"; + } + + } } /* diff --git a/kworship/css/KwCssStyleRule.cpp b/kworship/css/KwCssStyleRule.cpp index 095c34d..55bf771 100644 --- a/kworship/css/KwCssStyleRule.cpp +++ b/kworship/css/KwCssStyleRule.cpp @@ -60,7 +60,7 @@ void KwCssStyleRule::setCriteriaClasses(const StringSet& classes) } /// Set a style. -void KwCssStyleRule::setRawStyle(QString name, KwCssAbstractStyle* style) +void KwCssStyleRule::setRawStyle(const QString& name, KwCssAbstractStyle* style) { m_styles->setRawStyle(name, style); } diff --git a/kworship/css/KwCssStyleRule.h b/kworship/css/KwCssStyleRule.h index 5377f70..39e4fa7 100644 --- a/kworship/css/KwCssStyleRule.h +++ b/kworship/css/KwCssStyleRule.h @@ -72,11 +72,11 @@ class KwCssStyleRule void setCriteriaClasses(const StringSet& classes); /// Set a style. - void setRawStyle(QString name, KwCssAbstractStyle* style); + void setRawStyle(const QString& name, KwCssAbstractStyle* style); /// Set a style of a particular type. template - void setStyle(QString name, const T& value) + void setStyle(const QString& name, const T& value) { m_styles->setStyle(name, value); } diff --git a/kworship/css/KwCssUnprocessed.h b/kworship/css/KwCssUnprocessed.h new file mode 100644 index 0000000..8990961 --- /dev/null +++ b/kworship/css/KwCssUnprocessed.h @@ -0,0 +1,60 @@ +/*************************************************************************** + * This file is part of KWorship. * + * Copyright 2008 James Hogan * + * * + * KWorship 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. * + * * + * KWorship 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 KWorship. If not, write to the Free Software Foundation, * + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef _KwCssUnprocessed_h_ +#define _KwCssUnprocessed_h_ + +/** + * @file KwCssUnprocessed.h + * @brief Unprocessed string. + * @author James Hogan + */ + +#include + +/// Unprocessed string. +class KwCssUnprocessed : public QString +{ + public: + + /* + * Constructors + destructors + */ + + /// Default constructor. + KwCssUnprocessed() + : QString() + { + } + + /// Primary constructor. + KwCssUnprocessed(const QString& copy) + : QString(copy) + { + } + + /// Primary constructor. + KwCssUnprocessed(const char* copy) + : QString(copy) + { + } +}; + +#endif // _KwCssUnprocessed_h_ + -- 2.11.4.GIT