~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Gui/BitmapFactory.h

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
Import upstream version 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) 2004 J�rgen Riegel <juergen.riegel@web.de>              *
 
3
 *                                                                         *
 
4
 *   This file is part of the FreeCAD CAx development system.              *
 
5
 *                                                                         *
 
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.      *
 
10
 *                                                                         *
 
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.                  *
 
15
 *                                                                         *
 
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                                *
 
20
 *                                                                         *
 
21
 ***************************************************************************/
 
22
 
 
23
 
 
24
#ifndef GUI_BITMAPFACTORY_H
 
25
#define GUI_BITMAPFACTORY_H
 
26
 
 
27
#include <Base/Factory.h>
 
28
 
 
29
#ifndef __Qt4All__
 
30
# include "Qt4All.h"
 
31
#endif
 
32
 
 
33
// forward declaration
 
34
class SoSFImage;
 
35
 
 
36
namespace Gui {
 
37
 
 
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
 
43
  */
 
44
class BitmapFactoryInstP;
 
45
class GuiExport BitmapFactoryInst : public Base::Factory
 
46
{
 
47
public:
 
48
    enum Position
 
49
    {
 
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 */
 
54
    };
 
55
 
 
56
    static BitmapFactoryInst& instance(void);
 
57
    static void destruct (void);
 
58
 
 
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).
 
73
     */
 
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
 
77
     * a byte array.
 
78
     */
 
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.
 
82
    */
 
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. 
 
88
     */
 
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. 
 
96
     *
 
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
 
99
     * transparent.
 
100
     */
 
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.
 
105
     */
 
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.
 
111
     */
 
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.
 
115
     */
 
116
    QPixmap disabled(const QPixmap& p) const;
 
117
    /** Converts a QImage into a SoSFImage to use it inside a SoImage node.
 
118
     */
 
119
    void convert(const QImage& img, SoSFImage& out) const;
 
120
    /** Converts a SoSFImage into a QImage.
 
121
     */
 
122
    void convert(const SoSFImage& img, QImage& out) const;
 
123
 
 
124
private:
 
125
    static BitmapFactoryInst* _pcSingleton;
 
126
    BitmapFactoryInst();
 
127
    ~BitmapFactoryInst();
 
128
 
 
129
    BitmapFactoryInstP* d;
 
130
};
 
131
 
 
132
/// Get the global instance
 
133
inline GuiExport BitmapFactoryInst& BitmapFactory(void)
 
134
{
 
135
    return BitmapFactoryInst::instance();
 
136
}
 
137
 
 
138
} // namespace Gui
 
139
 
 
140
#endif // GUI_BITMAPFACTORY_H