MauiKit Controls

linux/shadowhelper/tileset.h
1#ifndef TILESET_H
2#define TILESET_H
3
4/*************************************************************************
5 * Copyright (C) 2014 by Hugo Pereira Da Costa <hugo.pereira@free.fr> *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
21 *************************************************************************/
22
23
24#include <QPixmap>
25#include <QRect>
26#include <QVector>
27
28//* handles proper scaling of pixmap to match widget rect.
29/**
30tilesets are collections of stretchable pixmaps corresponding to a given widget corners, sides, and center.
31corner pixmaps are never stretched. center pixmaps are
32*/
33class TileSet
34{
35 public:
36 /**
37 Create a TileSet from a pixmap. The size of the bottom/right chunks is
38 whatever is left over from the other chunks, whose size is specified
39 in the required parameters.
40
41 @param w1 width of the left chunks
42 @param h1 height of the top chunks
43 @param w2 width of the not-left-or-right chunks
44 @param h2 height of the not-top-or-bottom chunks
45 */
46 TileSet(const QPixmap&, int w1, int h1, int w2, int h2 );
47
48 //* empty constructor
49 TileSet();
50
51 //* destructor
52 virtual ~TileSet()
53 {}
54
55 /**
56 Flags specifying what sides to draw in ::render. Corners are drawn when
57 the sides forming that corner are drawn, e.g. Top|Left draws the
58 top-center, center-left, and top-left chunks. The center-center chunk is
59 only drawn when Center is requested.
60 */
61 enum Tile {
62 Top = 0x1,
63 Left = 0x2,
64 Bottom = 0x4,
65 Right = 0x8,
66 Center = 0x10,
67 TopLeft = Top|Left,
68 TopRight = Top|Right,
69 BottomLeft = Bottom|Left,
70 BottomRight = Bottom|Right,
71 Ring = Top|Left|Bottom|Right,
72 Horizontal = Left|Right|Center,
73 Vertical = Top|Bottom|Center,
74 Full = Ring|Center
75 };
76 Q_DECLARE_FLAGS(Tiles, Tile)
77
78 /**
79 Fills the specified rect with tiled chunks. Corners are never tiled,
80 edges are tiled in one direction, and the center chunk is tiled in both
81 directions. Partial tiles are used as needed so that the entire rect is
82 perfectly filled. Filling is performed as if all chunks are being drawn.
83 */
84 void render(const QRect&, QPainter*, Tiles = Ring) const;
85
86 //* return size associated to this tileset
87 QSize size() const
88 { return QSize( _w1 + _w3, _h1 + _h3 ); }
89
90 //* is valid
91 bool isValid() const
92 { return _pixmaps.size() == 9; }
93
94 //* returns pixmap for given index
95 QPixmap pixmap( int index ) const
96 { return _pixmaps[index]; }
97
98 protected:
99
100 //* shortcut to pixmap list
101 using PixmapList = QVector<QPixmap>;
102
103 //* initialize pixmap
104 void initPixmap( PixmapList&, const QPixmap&, int w, int h, const QRect& );
105
106 private:
107
108 //* pixmap arry
109 PixmapList _pixmaps;
110
111 // dimensions
112 int _w1;
113 int _h1;
114 int _w3;
115 int _h3;
116
117};
118
119Q_DECLARE_OPERATORS_FOR_FLAGS(TileSet::Tiles)
120
121#endif //TILESET_H
tilesets are collections of stretchable pixmaps corresponding to a given widget corners,...
Tile
Flags specifying what sides to draw in render.
TileSet(const QPixmap &, int w1, int h1, int w2, int h2)
Create a TileSet from a pixmap.
void render(const QRect &, QPainter *, Tiles=Ring) const
Fills the specified rect with tiled chunks.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:56:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.