summaryrefslogtreecommitdiffstats
path: root/kword/KWFrameStyle.h
blob: 23dede0ec492265e0c28c4fa89917bc9ba2890ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* This file is part of the KDE project
   Copyright (C) 2002 Nash Hoogwater <nrhoogwater@wanadoo.nl>
                 2005 David Faure <faure@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; using
   version 2 of the License.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef kwframestyle_h
#define kwframestyle_h

#include <KoUserStyle.h>
#include <KoUserStyleCollection.h>

#include "KoBorder.h"
#include <tqbrush.h>

class TQDomElement;
class KoOasisContext;
class KoSavingContext;
class KoGenStyles;
class KWFrameStyle;
class KWFrame;

/**
 * The user-visible style for frames
 * (borders and background)
 */
class KWFrameStyle : public KoUserStyle
{
public:
    /** Create a blank framestyle (with default attributes) */
    KWFrameStyle( const TQString & name );

    KWFrameStyle( const TQString & name, KWFrame * frame );
    KWFrameStyle( TQDomElement & parentElem, int docVersion=2 );

    /** Copy another framestyle */
    KWFrameStyle( const KWFrameStyle & rhs );
    void operator=( const KWFrameStyle& rhs );

    ~KWFrameStyle() {}

    enum { Borders = 1,
           Background = 2
    } Flags;

    int compare( const KWFrameStyle & frameStyle ) const;

    // ATTRIBUTES
    TQBrush backgroundColor() const { return m_backgroundColor; }
    void setBackgroundColor( const TQBrush &_color ) { m_backgroundColor = _color; }

    const KoBorder & leftBorder() const { return m_borderLeft; }
    void setLeftBorder( KoBorder _left )  { m_borderLeft = _left; }

    const KoBorder & rightBorder() const { return m_borderRight; }
    void setRightBorder( KoBorder _right )  { m_borderRight = _right; }

    const KoBorder & topBorder() const { return m_borderTop; }
    void setTopBorder( KoBorder _top )  { m_borderTop = _top; }

    const KoBorder & bottomBorder() const { return m_borderBottom; }
    void setBottomBorder( KoBorder _bottom )  { m_borderBottom = _bottom; }

    /// save (old xml format)
    void saveFrameStyle( TQDomElement & parentElem );
    /// save (new oasis xml format)
    void saveOasis( KoGenStyles& mainStyles, KoSavingContext& savingContext ) const;

    /// load (old xml format)
    static KWFrameStyle *loadStyle( TQDomElement & parentElem, int docVersion=2 );
    /// load (new oasis xml format)
    void loadOasis( TQDomElement & styleElem, KoOasisContext& context );

private:
    TQBrush m_backgroundColor;
    KoBorder m_borderLeft, m_borderRight, m_borderTop, m_borderBottom;
};

/**
 * Collection of frame styles
 */
class KWFrameStyleCollection : public KoUserStyleCollection
{
public:
    KWFrameStyleCollection();

    static TQString defaultStyleName() { return TQString::fromLatin1( "Plain" ); }

    /**
     * Find style based on the untranslated name @p name.
     * Overloaded for convenience
     */
    KWFrameStyle* findStyle( const TQString & name ) const {
        return static_cast<KWFrameStyle*>( KoUserStyleCollection::findStyle( name, defaultStyleName() ) );
    }

    /**
     * Find style based on the display name @p name.
     * This is only for the old XML loading.
     * Overloaded for convenience
     */
    KWFrameStyle* findStyleByDisplayName( const TQString & name ) const {
        return static_cast<KWFrameStyle*>( KoUserStyleCollection::findStyleByDisplayName( name ) );
    }

    /**
     * See KoUserStyleCollection::addStyle.
     * Overloaded for convenience.
     */
    KWFrameStyle* addStyle( KWFrameStyle* sty ) {
        return static_cast<KWFrameStyle*>( KoUserStyleCollection::addStyle( sty ) );
    }

    /**
     * Return style number @p i.
     */
    KWFrameStyle* frameStyleAt( int i ) const {
        return static_cast<KWFrameStyle*>( m_styleList[i] );
    }

    void saveOasis( KoGenStyles& mainStyles, KoSavingContext& savingContext ) const;
    int loadOasisStyles( KoOasisContext& context );
};

#endif