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);
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
bool isWritable() const { return m_writable; }
66
bool isHidden() const { return m_hidden; }
69
/// Hash value for the internal name
70
uint hash() const { return m_hash; }
72
/// Loads the cursor image @p name, with the nominal size @p size.
73
/// The image should be autocropped to the smallest possible size.
74
/// If the theme doesn't have the cursor @p name, it should return a null image.
75
virtual QImage loadImage(const QString &name, int size = -1) const = 0;
77
/// Convenience function. Default implementation calls
78
/// QPixmap::fromImage(loadImage());
79
virtual QPixmap loadPixmap(const QString &name, int size = -1) const;
81
/// Loads the cursor @p name, with the nominal size @p size.
82
/// If the theme doesn't have the cursor @p name, it should return
83
/// the default cursor from the active theme instead.
84
virtual QCursor loadCursor(const QString &name, int size = -1) const = 0;
87
void setTitle( const QString &title ) { m_title = title; }
88
void setDescription( const QString &desc ) { m_description = desc; }
89
void setSample( const QString &sample ) { m_sample = sample; }
90
inline void setName( const QString &name );
91
void setPath( const QString &path ) { m_path = path; }
92
void setIcon( const QPixmap &icon ) { m_icon = icon; }
93
void setIsWritable( bool val ) { m_writable = val; }
94
void setIsHidden( bool val ) { m_hidden = val; }
96
/// Creates the icon returned by @ref icon().
97
virtual QPixmap createIcon() const;
99
/// Convenience function for cropping an image.
100
QImage autoCropImage( const QImage &image ) const;
102
// Convenience function that uses Xfixes to tag a cursor with a name
103
void setCursorName(QCursor &cursor, const QString &name) const;
106
QString m_description;
109
mutable QPixmap m_icon;
117
friend class CursorThemeModel;
120
void CursorTheme::setName(const QString &name)
123
m_hash = qHash(name);
126
#endif // CURSORTHEME_H