1
/***************************************************************************
2
* Copyright (c) 2004 J�rgen Riegel <juergen.riegel@web.de> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
24
#ifndef GUI_BITMAPFACTORY_H
25
#define GUI_BITMAPFACTORY_H
27
#include <Base/Factory.h>
33
// forward declaration
38
/** The Bitmap Factory
39
* the main purpose is to collect all build in Bitmaps and
40
* hold all paths for the extern bitmaps (files) to serve
41
* as a single point of accessing bitmaps in FreeCAD
42
* \author Werner Mayer, J�rgen Riegel
44
class BitmapFactoryInstP;
45
class GuiExport BitmapFactoryInst : public Base::Factory
50
TopLeft, /**< Place to the top left corner */
51
TopRight, /**< Place to the top right corner */
52
BottomLeft, /**< Place to the bottom left corner */
53
BottomRight /**< Place to the bottom right corner */
56
static BitmapFactoryInst& instance(void);
57
static void destruct (void);
59
/// Adds a path where pixmaps can be found
60
void addPath(const QString& path);
61
/// Removes a path from the list of pixmap paths
62
void removePath(const QString& path);
63
/// Adds a build in XPM pixmap under a given name
64
void addXPM(const char* name, const char** pXPM);
65
/// Adds a build in XPM pixmap under a given name
66
void addPixmapToCache(const char* name, const QPixmap& icon);
67
/// Checks whether the pixmap is already registered.
68
bool findPixmapInCache(const char* name, QPixmap& icon) const;
69
/// Retrieves a pixmap by name
70
QPixmap pixmap(const char* name) const;
71
/** Retrieves a pixmap by name and size created by an
72
* scalable vector graphics (SVG).
74
QPixmap pixmapFromSvg(const char* name, const QSize& size) const;
75
/** This method is provided for convenience and does the same
76
* as the method above except that it creates the pixmap from
79
QPixmap pixmapFromSvg(const QByteArray& contents, const QSize& size) const;
80
/** Returns the names of all registered pixmaps.
81
* To get the appropriate pixmaps call pixmap() for each name.
83
QStringList pixmapNames() const;
84
/** Resizes the area of a pixmap
85
* If the new size is greater than the old one the pixmap
86
* will be placed in the center. The border area will be made
87
* depending on \a bgmode transparent or opaque.
89
QPixmap resize(int w, int h, const QPixmap& p, Qt::BGMode bgmode) const;
90
/** Creates an opaque or transparent area in a pixmap
91
* If the background mode is opaque then this method can
92
* be used for drawing a smaller pixmap into pixmap \a p.
93
* Note: To draw a smaller pixmap into another one the
94
* area in the resulting pixmap for the small pixmapmust
95
* be opaque in every pixel, otherwise the drawing may fail.
97
* If the background mode is transparent then this method can
98
* be used for resizing the pixmap \a p and make the new space
101
QPixmap fillRect(int x, int y, int w, int h, const QPixmap& p, Qt::BGMode) const;
102
/** Merges the two pixmaps \a p1 and \a p2 to one pixmap in
103
* vertical order if \a vertical is true, in horizontal order
104
* otherwise. The method resizes the resulting pixmap.
106
QPixmap merge(const QPixmap& p1, const QPixmap& p2, bool vertical) const;
107
/** Merges the two pixmaps \a p1 and \a p2 to one pixmap.
108
* The position of the smaller pimxap \a p2 is drawn into the given
109
* position \a pos of the bigger pixmap \a p1. This method does not
110
* resize the resulting pixmap.
112
QPixmap merge(const QPixmap& p1, const QPixmap& p2, Position pos = BitmapFactoryInst::BottomLeft) const;
113
/** Creates a disabled pixmap of the given pixmap \a p by changing the brightness
114
* of all opaque pixels to a higher value.
116
QPixmap disabled(const QPixmap& p) const;
117
/** Converts a QImage into a SoSFImage to use it inside a SoImage node.
119
void convert(const QImage& img, SoSFImage& out) const;
120
/** Converts a SoSFImage into a QImage.
122
void convert(const SoSFImage& img, QImage& out) const;
125
static BitmapFactoryInst* _pcSingleton;
127
~BitmapFactoryInst();
129
BitmapFactoryInstP* d;
132
/// Get the global instance
133
inline GuiExport BitmapFactoryInst& BitmapFactory(void)
135
return BitmapFactoryInst::instance();
140
#endif // GUI_BITMAPFACTORY_H