2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
7
/* This file is part of the KDE project
8
Copyright (c) 2003 Lukas Tinkl <lukas@kde.org>
9
Copyright (c) 2003 David Faure <faure@kde.org>
11
This library is free software; you can redistribute it and/or
12
modify it under the terms of the GNU Library General Public
13
License as published by the Free Software Foundation; either
14
version 2 of the License, or (at your option) any later version.
16
This library is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
Library General Public License for more details.
21
You should have received a copy of the GNU Library General Public License
22
along with this library; see the file COPYING.LIB. If not, write to
23
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24
Boston, MA 02111-1307, USA.
30
#include <QDomElement>
31
#include <QStringList>
37
* This class implements a stack for the different styles of an object.
39
* There can be several styles that are valid for one object. For example
40
* a textobject on a page has styles 'pr3' and 'P7' and a paragraph in
41
* that textobject has styles 'P1' and 'T3'. And some styles even have
44
* If you want to know if there is, for example, the attribute 'fo:font-family'
45
* for this paragraph, you have to look into style 'T3', 'P1', 'P7' and 'pr3'.
46
* When you find this attribute in one style you have to stop processing the list
47
* and take the found attribute for this object.
49
* This is what this class does. You can push styles on the stack while walking
50
* through the xml-tree to your object and then ask the stack if any of the styles
51
* provides a certain attribute. The stack will search from top to bottom, i.e.
52
* in our example from 'T3' to 'pr3' and return the first occurrence of the wanted
55
* So this is some sort of inheritance where the styles on top of the stack overwrite
56
* the same attribute of a lower style on the stack.
62
virtual ~StyleStack();
71
* Set attribute analysis mode.
73
void setMode( const StyleStack::Mode mode );
76
* Clears the complete stack.
81
* Save the current state of the stack. Any items added between
82
* this call and its corresponding restore() will be removed when calling restore().
87
* Restore the stack to the state it was at the corresponding save() call.
92
* Removes the style on top of the stack.
97
* Pushes the new style onto the stack.
99
void push( const QDomElement& style );
102
* Check if any of the styles on the stack has an attribute called 'name'.
104
bool hasAttribute( const QString& name ) const;
107
* Search for the attribute called 'name', starting on top of the stack,
110
QString attribute( const QString& name ) const;
113
* Check if any of the styles on the stack has an attribute called 'name'-'detail'
114
* where detail is e.g. left, right, top or bottom.
115
* This allows to also find 'name' alone (e.g. padding implies padding-left, padding-right etc.)
117
bool hasAttribute( const QString& name, const QString& detail ) const;
120
* Search for the attribute called 'name', starting on top of the stack,
123
QString attribute( const QString& name, const QString& detail ) const;
126
* Check if any of the styles on the stack has a child node called 'name'.
128
bool hasChildNode(const QString & name) const;
131
* Search for a child node called 'name', starting on top of the stack,
134
QDomNode childNode(const QString & name) const;
137
* Special case for the current font size, due to special handling of fo:font-size="115%".
139
double fontSize() const;
142
* Return the name of the style specified by the user,
143
* i.e. not an auto style
145
QString userStyleName() const;
149
// Node names to look for style properties
150
QStringList m_nodeNames;
152
// For save/restore: stack of "marks". Each mark is an index in m_stack.
155
// We use QValueList instead of QValueStack because we need access to all styles
156
// not only the top one.
157
QList<QDomElement> m_stack;
159
// Get node name to look for according to property type
160
void fillNodeNameList( QStringList& names, const StyleStack::Mode mode );
162
// Search a specific attribute amongst childs of an element
163
QDomElement searchAttribute( const QDomElement& element, const QStringList& names,const QString& name ) const;
165
// Search a specific attribute amongst childs of an element
166
QDomElement searchAttribute( const QDomElement& element, const QStringList& names, const QString& name, const QString& fullName ) const;
170
#endif /* STYLESTACK_H */