CTK 0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkPixmapIconEngine.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Library: CTK
4
5 Copyright (c) Kitware Inc.
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0.txt
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18
19=========================================================================*/
20// ctkPixmapIconEngine is based on QPixmapIconEngine in qicon_p.h
21
22#ifndef __ctkPixmapIconEngine_h
23#define __ctkPixmapIconEngine_h
24
25#include <QtGlobal>
26
27#if QT_VERSION >= 0x050000
28# include <QIconEngine>
29#else
30# include <QIconEngineV2>
31#endif
32
33#include <QPixmap>
34#include <QVector>
35
36#include "ctkWidgetsExport.h"
37
40{
41 ctkPixmapIconEngineEntry():mode(QIcon::Normal), state(QIcon::Off){}
42 ctkPixmapIconEngineEntry(const QPixmap &pm, QIcon::Mode m = QIcon::Normal, QIcon::State s = QIcon::Off)
43 :pixmap(pm), size(pm.size()), mode(m), state(s){}
44 ctkPixmapIconEngineEntry(const QString &file, const QSize &sz = QSize(), QIcon::Mode m = QIcon::Normal, QIcon::State s = QIcon::Off)
45 :fileName(file), size(sz), mode(m), state(s){}
46 QPixmap pixmap;
47 QString fileName;
48 QSize size;
49 QIcon::Mode mode;
51 bool isNull() const {return (fileName.isEmpty() && pixmap.isNull()); }
52};
53
55class CTK_WIDGETS_EXPORT ctkPixmapIconEngine
56#if QT_VERSION >= 0x050000
57 : public QIconEngine
58#else
59 : public QIconEngineV2
60#endif
61{
62public:
66 void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state);
67 QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
68 ctkPixmapIconEngineEntry *bestMatch(const QSize &size, QIcon::Mode mode, QIcon::State state, bool sizeOnly);
69 QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state);
70 void addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state);
71 void addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state);
72
73 // v2 functions
74 QString key() const;
75#if QT_VERSION >= 0x050000
76 QIconEngine *clone() const;
77#else
78 QIconEngineV2 *clone() const;
79#endif
80 bool read(QDataStream &in);
81 bool write(QDataStream &out) const;
82 void virtual_hook(int id, void *data);
83
84private:
85 ctkPixmapIconEngineEntry *tryMatch(const QSize &size, QIcon::Mode mode, QIcon::State state);
86 QVector<ctkPixmapIconEngineEntry> pixmaps;
87
88 friend class QIconThemeEngine;
89};
90
91
92#endif
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
void virtual_hook(int id, void *data)
QString key() const
ctkPixmapIconEngineEntry * bestMatch(const QSize &size, QIcon::Mode mode, QIcon::State state, bool sizeOnly)
QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state)
void addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state)
void addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state)
bool read(QDataStream &in)
ctkPixmapIconEngine(const ctkPixmapIconEngine &)
QIconEngineV2 * clone() const
bool write(QDataStream &out) const
void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state)
ctkPixmapIconEngineEntry(const QPixmap &pm, QIcon::Mode m=QIcon::Normal, QIcon::State s=QIcon::Off)
ctkPixmapIconEngineEntry(const QString &file, const QSize &sz=QSize(), QIcon::Mode m=QIcon::Normal, QIcon::State s=QIcon::Off)