From 15cac36bd19b7fd659ee462913295f653e283b13 Mon Sep 17 00:00:00 2001 From: James Hogan Date: Tue, 23 Dec 2008 20:54:07 +0000 Subject: [PATCH] Some DOM code in place for export of style scopes, but without CSS translation i.e. The XML stuff is fine for export, but CSS just shows a comment saying its unimplemented --- kworship/css/KwCssScope.cpp | 51 +++++++++++++++++++++++++++++++++--- kworship/css/KwCssScope.h | 16 +++++++++++ kworship/css/KwCssStyleSheet.cpp | 6 +++++ kworship/css/KwCssStyleSheet.h | 3 +++ kworship/css/KwCssStyles.cpp | 12 +++++++++ kworship/css/KwCssStyles.h | 6 +++++ kworship/playlist/KwPlaylistItem.cpp | 12 +++++++++ 7 files changed, 103 insertions(+), 3 deletions(-) diff --git a/kworship/css/KwCssScope.cpp b/kworship/css/KwCssScope.cpp index 10775d0..2e29444 100644 --- a/kworship/css/KwCssScope.cpp +++ b/kworship/css/KwCssScope.cpp @@ -27,6 +27,9 @@ #include "KwCssStyleRule.h" #include "KwCssStyleSheet.h" +#include +#include + /* * Constructors + destructors */ @@ -67,16 +70,52 @@ KwCssScope::~KwCssScope() // Clean style sheets { - StyleSheetList::iterator it; - for (it = m_styleSheets.begin(); it != m_styleSheets.end(); ++it) + foreach (KwCssStyleSheet* stylesheet, m_styleSheets) { /// @todo reference count - delete *it; + delete stylesheet; } } } /* + * DOM filters + */ + +/// Import the style information from a DOM. +void KwCssScope::importStylesFromDom(const QDomElement& element, KwResourceManager* resourceManager) +{ +} + +/// Export the style information to a DOM. +void KwCssScope::exportStylesToDom(QDomDocument& document, QDomElement& element, KwResourceManager* resourceManager) const +{ + // Start with the classes + foreach (QString className, m_classes) + { + QDomElement classElem = document.createElement("class"); + element.appendChild(classElem); + classElem.appendChild(document.createTextNode(className)); + } + + // Now for the stylesheets + foreach (KwCssStyleSheet* stylesheet, m_styleSheets) + { + QDomElement sheetElem = document.createElement("sheet"); + element.appendChild(sheetElem); + sheetElem.appendChild(document.createTextNode(stylesheet->toString())); + } + + // And finally the explicit styles + if (!m_styles.isEmpty()) + { + QDomElement explicitElem = document.createElement("explicit"); + element.appendChild(explicitElem); + explicitElem.appendChild(document.createTextNode(m_styles.toString())); + } +} + +/* * Main interface */ @@ -206,6 +245,12 @@ void KwCssScope::recalculateStyles() * Accessors */ +/// Find whether the scope is effectively empty. +bool KwCssScope::isScopeEmpty() const +{ + return m_classes.isEmpty() && m_styleSheets.isEmpty() && m_styles.isEmpty(); +} + /// Get explicit styles. const KwCssStyles& KwCssScope::getExplicitStyles() const { diff --git a/kworship/css/KwCssScope.h b/kworship/css/KwCssScope.h index a3d7d7b..d15dcff 100644 --- a/kworship/css/KwCssScope.h +++ b/kworship/css/KwCssScope.h @@ -37,6 +37,9 @@ #include class KwCssStyleSheet; +class KwResourceManager; +class QDomDocument; +class QDomElement; #define KW_CSS_SCOPE(TYPE_NAME) \ public: \ @@ -70,6 +73,16 @@ class KwCssScope virtual ~KwCssScope(); /* + * DOM filters + */ + + /// Import the style information from a DOM. + void importStylesFromDom(const QDomElement& element, KwResourceManager* resourceManager); + + /// Export the style information to a DOM. + void exportStylesToDom(QDomDocument& document, QDomElement& element, KwResourceManager* resourceManager) const; + + /* * Main interface */ @@ -97,6 +110,9 @@ class KwCssScope * Accessors */ + /// Find whether the scope is effectively empty. + bool isScopeEmpty() const; + /// Get explicit styles. const KwCssStyles& getExplicitStyles() const; diff --git a/kworship/css/KwCssStyleSheet.cpp b/kworship/css/KwCssStyleSheet.cpp index 74dac29..2f1e18a 100644 --- a/kworship/css/KwCssStyleSheet.cpp +++ b/kworship/css/KwCssStyleSheet.cpp @@ -91,3 +91,9 @@ const KwCssStyleSheet::RuleList& KwCssStyleSheet::getRules() const { return m_rules; } + +/// Convert to CSS-like format. +QString KwCssStyleSheet::toString() const +{ + return "/* KwCssStyleSheet::toString() unimplemented */"; +} diff --git a/kworship/css/KwCssStyleSheet.h b/kworship/css/KwCssStyleSheet.h index 5bc0116..8c74424 100644 --- a/kworship/css/KwCssStyleSheet.h +++ b/kworship/css/KwCssStyleSheet.h @@ -91,6 +91,9 @@ class KwCssStyleSheet /// Get the constant rules. const RuleList& getRules() const; + /// Convert to CSS-like format. + QString toString() const; + private: /* diff --git a/kworship/css/KwCssStyles.cpp b/kworship/css/KwCssStyles.cpp index f315723..3d50a39 100644 --- a/kworship/css/KwCssStyles.cpp +++ b/kworship/css/KwCssStyles.cpp @@ -76,6 +76,18 @@ void KwCssStyles::setRawStyle(QString name, KwCssAbstractStyle* style) m_styles[name] = style; } +/// Return whether the styles container is empty. +bool KwCssStyles::isEmpty() const +{ + return m_styles.isEmpty(); +} + +/// Convert to CSS-like format. +QString KwCssStyles::toString() const +{ + return "/* KwCssStyle::toString() unimplemented */"; +} + /* * Operators */ diff --git a/kworship/css/KwCssStyles.h b/kworship/css/KwCssStyles.h index 0f869ab..4fe8755 100644 --- a/kworship/css/KwCssStyles.h +++ b/kworship/css/KwCssStyles.h @@ -65,6 +65,12 @@ class KwCssStyles setRawStyle(name, new KwCssStyle(value)); } + /// Return whether the styles container is empty. + bool isEmpty() const; + + /// Convert to CSS-like format. + QString toString() const; + /* * Operators */ diff --git a/kworship/playlist/KwPlaylistItem.cpp b/kworship/playlist/KwPlaylistItem.cpp index 187c067..af13605 100644 --- a/kworship/playlist/KwPlaylistItem.cpp +++ b/kworship/playlist/KwPlaylistItem.cpp @@ -77,6 +77,11 @@ KwPlaylistItem::KwPlaylistItem(const QDomElement& element, KwResourceManager* re continue; } } + else if (childElement.tagName() == "style") + { + importStylesFromDom(childElement, resourceManager); + continue; + } } QDomNode preserved = m_domDocument.importNode(child, true); // deep copy m_domPreserve.appendChild(preserved); @@ -120,6 +125,13 @@ void KwPlaylistItem::exportToDom(QDomDocument& document, QDomElement& element, K QString type = itemType(); itemElement.setAttribute("type", type); + if (!isScopeEmpty()) + { + QDomElement styleElem = document.createElement("style"); + itemElement.appendChild(styleElem); + exportStylesToDom(document, styleElem, resourceManager); + } + exportDetailsToDom(document, itemElement, resourceManager); // Export resources after type specific stuff so they can be modified at the last minute -- 2.11.4.GIT