~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to libs/oxygen/oxygentileset.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef oxygentileset_h
 
2
#define oxygentileset_h
 
3
 
 
4
/*
 
5
 * Copyright 2009-2010 Hugo Pereira Da Costa <hugo@oxygen-icons.org>
 
6
 * Copyright 2008 Long Huynh Huu <long.upcase@googlemail.com>
 
7
 * Copyright 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
 
8
 *
 
9
 * This library is free software; you can redistribute it and/or
 
10
 * modify it under the terms of the GNU Library General Public
 
11
 * License version 2 as published by the Free Software Foundation.
 
12
 *
 
13
 * This library is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * Library General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU Library General Public License
 
19
 * along with this library; see the file COPYING.LIB.  If not, write to
 
20
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
21
 * Boston, MA 02110-1301, USA.
 
22
 */
 
23
 
 
24
#include "oxygen_export.h"
 
25
 
 
26
#include <QtGui/QPixmap>
 
27
#include <QtCore/QRect>
 
28
#include <QtCore/QVector>
 
29
 
 
30
#include <cassert>
 
31
 
 
32
//! handles proper scaling of pixmap to match widget rect.
 
33
/*!
 
34
tilesets are collections of stretchable pixmaps corresponding to a given widget corners, sides, and center.
 
35
corner pixmaps are never stretched. center pixmaps are
 
36
*/
 
37
namespace Oxygen
 
38
{
 
39
    class OXYGEN_EXPORT TileSet
 
40
    {
 
41
        public:
 
42
        /*!
 
43
        Create a TileSet from a pixmap. The size of the bottom/right chunks is
 
44
        whatever is left over from the other chunks, whose size is specified
 
45
        in the required parameters.
 
46
 
 
47
        @param w1 width of the left chunks
 
48
        @param h1 height of the top chunks
 
49
        @param w2 width of the not-left-or-right chunks
 
50
        @param h2 height of the not-top-or-bottom chunks
 
51
        */
 
52
        TileSet(const QPixmap&, int w1, int h1, int w2, int h2);
 
53
 
 
54
        /*!
 
55
        Create a TileSet from a pixmap. The size of the top/left and bottom/right
 
56
        chunks is specified, with the middle chunks created from the specified
 
57
        portion of the pixmap. This allows the middle chunks to overlap the outer
 
58
        chunks (or to not use all pixels). The top/left and bottom/right chunks
 
59
        are carved out of the corners of the pixmap.
 
60
 
 
61
        @param w1 width of the left chunks
 
62
        @param h1 height of the top chunks
 
63
        @param w3 width of the right chunks
 
64
        @param h3 height of bottom chunks
 
65
        @param x2 x-coordinate of the top of the not-left-or-right chunks
 
66
        @param y2 y-coordinate of the left of the not-top-or-bottom chunks
 
67
        @param w2 width of the not-left-or-right chunks
 
68
        @param h2 height of the not-top-or-bottom chunks
 
69
        */
 
70
        TileSet(const QPixmap &pix, int w1, int h1, int w3, int h3, int x2, int y2, int w2, int h2);
 
71
 
 
72
        //! empty constructor
 
73
        TileSet();
 
74
 
 
75
        //! destructor
 
76
        virtual ~TileSet()
 
77
        {}
 
78
 
 
79
        /*!
 
80
        Flags specifying what sides to draw in ::render. Corners are drawn when
 
81
        the sides forming that corner are drawn, e.g. Top|Left draws the
 
82
        top-center, center-left, and top-left chunks. The center-center chunk is
 
83
        only drawn when Center is requested.
 
84
        */
 
85
        enum Tile {
 
86
            Top = 0x1,
 
87
            Left = 0x2,
 
88
            Bottom = 0x4,
 
89
            Right = 0x8,
 
90
            Center = 0x10,
 
91
            TopLeft = Top|Left,
 
92
            TopRight = Top|Right,
 
93
            BottomLeft = Bottom|Left,
 
94
            BottomRight = Bottom|Right,
 
95
            Ring = Top|Left|Bottom|Right,
 
96
            Horizontal = Left|Right|Center,
 
97
            Vertical = Top|Bottom|Center,
 
98
            Full = Ring|Center
 
99
        };
 
100
        Q_DECLARE_FLAGS(Tiles, Tile)
 
101
 
 
102
        /*!
 
103
        Fills the specified rect with tiled chunks. Corners are never tiled,
 
104
        edges are tiled in one direction, and the center chunk is tiled in both
 
105
        directions. Partial tiles are used as needed so that the entire rect is
 
106
        perfectly filled. Filling is performed as if all chunks are being drawn.
 
107
        */
 
108
        void render(const QRect&, QPainter*, Tiles = Ring) const;
 
109
 
 
110
        //! return size associated to this tileset
 
111
        QSize size( void ) const
 
112
        { return QSize( _w1 + _w3, _h1 + _h3 ); }
 
113
 
 
114
        //! is valid
 
115
        bool isValid( void ) const
 
116
        { return size().isValid() && _pixmaps.size() == 9; }
 
117
 
 
118
        //! save all pixmaps
 
119
        /*! pixmap names will be \p basename-position.suffix. Other arguments are the same as for QPixmap::save */
 
120
        void save( const QString& basename, const QString& suffix = "png", const char* format = 0, int quality = -1 ) const;
 
121
 
 
122
        //! side extend
 
123
        /*!
 
124
        it is used to (pre) tile the side pixmaps, in order to make further tiling faster when rendering, at the cost of
 
125
        using more memory for the cache. Changes to this member only affects tilesets that are created afterwards.
 
126
        */
 
127
        void setSideExtent( int value )
 
128
        { _sideExtent = value; }
 
129
 
 
130
        //! returns pixmap for given index
 
131
        QPixmap pixmap( int index ) const
 
132
        {
 
133
            assert( index >= 0 && index < _pixmaps.size() );
 
134
            return _pixmaps[index];
 
135
        }
 
136
 
 
137
        protected:
 
138
 
 
139
        //! shortcut to pixmap list
 
140
        typedef QVector<QPixmap> PixmapList;
 
141
 
 
142
        //! initialize pixmap
 
143
        void initPixmap( PixmapList&, const QPixmap&, int w, int h, const QRect& );
 
144
 
 
145
        private:
 
146
 
 
147
        //! side extend
 
148
        /*!
 
149
        it is used to (pre) tile the side pixmaps, in order to make further tiling faster when rendering, at the cost of
 
150
        using more memory for the cache.
 
151
        */
 
152
        static int _sideExtent;
 
153
 
 
154
        //! pixmap arry
 
155
        PixmapList _pixmaps;
 
156
 
 
157
        // dimensions
 
158
        int _w1;
 
159
        int _h1;
 
160
        int _w3;
 
161
        int _h3;
 
162
 
 
163
    };
 
164
 
 
165
}
 
166
 
 
167
Q_DECLARE_OPERATORS_FOR_FLAGS(Oxygen::TileSet::Tiles)
 
168
 
 
169
#endif //TILESET_H