add more spacing
[personal-kdebase.git] / workspace / kcontrol / input / xcursor / cursortheme.h
blobf1f6b438181eea65b70b5ac45b46c3d703d848b7
1 /*
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.
20 #ifndef CURSORTHEME_H
21 #define CURSORTHEME_H
23 #include <QPixmap>
24 #include <QHash>
26 /**
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
45 * the icon from that.
47 class CursorTheme
49 public:
50 enum ItemDataRole {
51 // Note: use printf "0x%08X\n" $(($RANDOM*$RANDOM))
52 // to define additional roles.
53 DisplayDetailRole = 0x24A3DAF8
56 CursorTheme() {}
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 const bool isWritable() const { return m_writable; }
66 const bool isHidden() const { return m_hidden; }
67 QPixmap icon() const;
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;
86 protected:
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;
105 QString m_title;
106 QString m_description;
107 QString m_path;
108 QString m_sample;
109 mutable QPixmap m_icon;
110 bool m_writable:1;
111 bool m_hidden:1;
113 private:
114 QString m_name;
115 uint m_hash;
117 friend class CursorThemeModel;
120 void CursorTheme::setName(const QString &name)
122 m_name = name;
123 m_hash = qHash(name);
126 #endif // CURSORTHEME_H