1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qbitmap.h"
|
---|
43 | #include "qpixmapdata_p.h"
|
---|
44 | #include "qimage.h"
|
---|
45 | #include "qvariant.h"
|
---|
46 | #include <qpainter.h>
|
---|
47 | #include <private/qgraphicssystem_p.h>
|
---|
48 | #include <private/qapplication_p.h>
|
---|
49 |
|
---|
50 | QT_BEGIN_NAMESPACE
|
---|
51 |
|
---|
52 | /*!
|
---|
53 | \class QBitmap
|
---|
54 | \brief The QBitmap class provides monochrome (1-bit depth) pixmaps.
|
---|
55 |
|
---|
56 | \ingroup multimedia
|
---|
57 | \ingroup shared
|
---|
58 |
|
---|
59 | The QBitmap class is a monochrome off-screen paint device used
|
---|
60 | mainly for creating custom QCursor and QBrush objects,
|
---|
61 | constructing QRegion objects, and for setting masks for pixmaps
|
---|
62 | and widgets.
|
---|
63 |
|
---|
64 | QBitmap is a QPixmap subclass ensuring a depth of 1, except for
|
---|
65 | null objects which have a depth of 0. If a pixmap with a depth
|
---|
66 | greater than 1 is assigned to a bitmap, the bitmap will be
|
---|
67 | dithered automatically.
|
---|
68 |
|
---|
69 | Use the QColor objects Qt::color0 and Qt::color1 when drawing on a
|
---|
70 | QBitmap object (or a QPixmap object with depth 1).
|
---|
71 |
|
---|
72 | Painting with Qt::color0 sets the bitmap bits to 0, and painting
|
---|
73 | with Qt::color1 sets the bits to 1. For a bitmap, 0-bits indicate
|
---|
74 | background (or transparent pixels) and 1-bits indicate foreground
|
---|
75 | (or opaque pixels). Use the clear() function to set all the bits
|
---|
76 | to Qt::color0. Note that using the Qt::black and Qt::white colors
|
---|
77 | make no sense because the QColor::pixel() value is not necessarily
|
---|
78 | 0 for black and 1 for white.
|
---|
79 |
|
---|
80 | The QBitmap class provides the transformed() function returning a
|
---|
81 | transformed copy of the bitmap; use the QMatrix argument to
|
---|
82 | translate, scale, shear, and rotate the bitmap. In addition,
|
---|
83 | QBitmap provides the static fromData() function which returns a
|
---|
84 | bitmap constructed from the given \c uchar data, and the static
|
---|
85 | fromImage() function returning a converted copy of a QImage
|
---|
86 | object.
|
---|
87 |
|
---|
88 | Just like the QPixmap class, QBitmap is optimized by the use of
|
---|
89 | implicit data sharing. For more information, see the {Implicit
|
---|
90 | Data Sharing} documentation.
|
---|
91 |
|
---|
92 | \sa QPixmap, QImage, QImageReader, QImageWriter
|
---|
93 | */
|
---|
94 |
|
---|
95 |
|
---|
96 | /*!
|
---|
97 | Constructs a null bitmap.
|
---|
98 |
|
---|
99 | \sa QPixmap::isNull()
|
---|
100 | */
|
---|
101 |
|
---|
102 | QBitmap::QBitmap()
|
---|
103 | : QPixmap(QSize(0, 0), QPixmapData::BitmapType)
|
---|
104 | {
|
---|
105 | }
|
---|
106 |
|
---|
107 | /*!
|
---|
108 | \fn QBitmap::QBitmap(int width, int height)
|
---|
109 |
|
---|
110 | Constructs a bitmap with the given \a width and \a height. The pixels
|
---|
111 | inside are uninitialized.
|
---|
112 |
|
---|
113 | \sa clear()
|
---|
114 | */
|
---|
115 |
|
---|
116 | QBitmap::QBitmap(int w, int h)
|
---|
117 | : QPixmap(QSize(w, h), QPixmapData::BitmapType)
|
---|
118 | {
|
---|
119 | }
|
---|
120 |
|
---|
121 | /*!
|
---|
122 | Constructs a bitmap with the given \a size. The pixels in the
|
---|
123 | bitmap are uninitialized.
|
---|
124 |
|
---|
125 | \sa clear()
|
---|
126 | */
|
---|
127 |
|
---|
128 | QBitmap::QBitmap(const QSize &size)
|
---|
129 | : QPixmap(size, QPixmapData::BitmapType)
|
---|
130 | {
|
---|
131 | }
|
---|
132 |
|
---|
133 | /*!
|
---|
134 | \fn QBitmap::clear()
|
---|
135 |
|
---|
136 | Clears the bitmap, setting all its bits to Qt::color0.
|
---|
137 | */
|
---|
138 |
|
---|
139 | /*!
|
---|
140 | Constructs a bitmap that is a copy of the given \a pixmap.
|
---|
141 |
|
---|
142 | If the pixmap has a depth greater than 1, the resulting bitmap
|
---|
143 | will be dithered automatically.
|
---|
144 |
|
---|
145 | \sa QPixmap::depth(), fromImage(), fromData()
|
---|
146 | */
|
---|
147 |
|
---|
148 | QBitmap::QBitmap(const QPixmap &pixmap)
|
---|
149 | {
|
---|
150 | QBitmap::operator=(pixmap);
|
---|
151 | }
|
---|
152 |
|
---|
153 | /*!
|
---|
154 | \fn QBitmap::QBitmap(const QImage &image)
|
---|
155 |
|
---|
156 | Constructs a bitmap that is a copy of the given \a image.
|
---|
157 |
|
---|
158 | Use the static fromImage() function instead.
|
---|
159 | */
|
---|
160 |
|
---|
161 | /*!
|
---|
162 | Constructs a bitmap from the file specified by the given \a
|
---|
163 | fileName. If the file does not exist, or has an unknown format,
|
---|
164 | the bitmap becomes a null bitmap.
|
---|
165 |
|
---|
166 | The \a fileName and \a format parameters are passed on to the
|
---|
167 | QPixmap::load() function. If the file format uses more than 1 bit
|
---|
168 | per pixel, the resulting bitmap will be dithered automatically.
|
---|
169 |
|
---|
170 | \sa QPixmap::isNull(), QImageReader::imageFormat()
|
---|
171 | */
|
---|
172 |
|
---|
173 | QBitmap::QBitmap(const QString& fileName, const char *format)
|
---|
174 | : QPixmap(QSize(0, 0), QPixmapData::BitmapType)
|
---|
175 | {
|
---|
176 | load(fileName, format, Qt::MonoOnly);
|
---|
177 | }
|
---|
178 |
|
---|
179 | /*!
|
---|
180 | \overload
|
---|
181 |
|
---|
182 | Assigns the given \a pixmap to this bitmap and returns a reference
|
---|
183 | to this bitmap.
|
---|
184 |
|
---|
185 | If the pixmap has a depth greater than 1, the resulting bitmap
|
---|
186 | will be dithered automatically.
|
---|
|
---|