2
* Copyright © 2006-2007 Fredrik Höglund <fredrik@kde.org>
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public
6
* License version 2 or at your option version 3 as published
7
* by the Free Software Foundation.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; see the file COPYING. If not, write to
16
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
27
* This is the abstract base class for all cursor themes stored in a
28
* CursorThemeModel and previewed in a PreviewWidget.
30
* All cursor themes have a title, a description, an icon, and an internal
31
* name, all of which, except for the internal name, CursorThemeModel
32
* supplies to item views.
34
* A cursor theme may also have a path to the directory where the theme
35
* is located in the filesystem. If isWritable() returns true, This directory
36
* may be deleted in order to remove the theme at the users request.
38
* Subclasses must reimplement loadImage() and loadCursor(), which are
39
* called by PreviewWidget to load cursors and cursor images. Subclasses may
40
* optionally reimplement loadPixmap(), which in the default implementation
41
* calls loadImage(), and converts the returned image to a pixmap.
42
* Subclasses may also reimplement the protected function createIcon(),
43
* which creates the icon pixmap that's supplied to item views. The default
44
* implementation calls loadImage() to load the sample cursor, and creates
51
// Note: use printf "0x%08X\n" $(($RANDOM*$RANDOM))
52
// to define additional roles.
53
DisplayDetailRole = 0x24A3DAF8
57
CursorTheme(const QString &title, const QString &description = QString());
58
virtual ~CursorTheme() {}
60
const QString title() const { return m_title; }
61
const QString description() const { return m_description; }
62
const QString sample() const { return m_sample; }
63
const QString name() const { return m_name; }
64
const QString path() const { return m_path; }
65
/** @returns A list of the available sizes in this cursor theme,
66
@warning This list may be empty if the engine doesn't support
67
the recognition of the size. */
68
const QList<int> availableSizes() const
69
{ return m_availableSizes; }
70
bool isWritable() const { return m_writable; }
71
bool isHidden() const { return m_hidden; }
74
/// Hash value for the internal name
75
uint hash() const { return m_hash; }
77
/// Loads the cursor image @p name, with the nominal size @p size.
78
/// The image should be autocropped to the smallest possible size.
79
/// If the theme doesn't have the cursor @p name, it should return a null image.
80
virtual QImage loadImage(const QString &name, int size = 0) const = 0;
82
/// Convenience function. Default implementation calls
83
/// QPixmap::fromImage(loadImage());
84
virtual QPixmap loadPixmap(const QString &name, int size = 0) const;
86
/// Loads the cursor @p name, with the nominal size @p size.
87
/// If the theme doesn't have the cursor @p name, it should return
88
/// the default cursor from the active theme instead.
89
virtual qulonglong loadCursor(const QString &name, int size = 0) const = 0;
91
/** Creates the icon returned by @ref icon(). Don't use this function
92
directly but use @ref icon() instead, because @ref icon() caches
94
@returns A pixmap with a cursor (usually left_ptr) that can
95
be used as icon for this theme. The size is adopted to
96
standard icon sizes.*/
97
virtual QPixmap createIcon() const;
98
/** @returns A pixmap with a cursor (usually left_ptr) that can
99
be used as icon for this theme. */
100
virtual QPixmap createIcon(int size) const;
102
static bool haveXfixes();
105
void setTitle( const QString &title ) { m_title = title; }
106
void setDescription( const QString &desc ) { m_description = desc; }
107
void setSample( const QString &sample ) { m_sample = sample; }
108
inline void setName( const QString &name );
109
void setPath( const QString &path ) { m_path = path; }
110
void setAvailableSizes( const QList<int> &availableSizes )
111
{ m_availableSizes = availableSizes; }
112
void setIcon( const QPixmap &icon ) { m_icon = icon; }
113
void setIsWritable( bool val ) { m_writable = val; }
114
void setIsHidden( bool val ) { m_hidden = val; }
116
/// Convenience function for cropping an image.
117
QImage autoCropImage( const QImage &image ) const;
119
// Convenience function that uses Xfixes to tag a cursor with a name
120
void setCursorName(qulonglong cursor, const QString &name) const;
123
QString m_description;
125
QList<int> m_availableSizes;
127
mutable QPixmap m_icon;
135
friend class CursorThemeModel;
138
void CursorTheme::setName(const QString &name)
141
m_hash = qHash(name);
144
#endif // CURSORTHEME_H