~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kcontrol/input/xcursor/cursortheme.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2006-2007 Fredrik Höglund <fredrik@kde.org>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
#ifndef CURSORTHEME_H
 
21
#define CURSORTHEME_H
 
22
 
 
23
#include <QPixmap>
 
24
#include <QHash>
 
25
 
 
26
/**
 
27
 * This is the abstract base class for all cursor themes stored in a
 
28
 * CursorThemeModel and previewed in a PreviewWidget.
 
29
 *
 
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.
 
33
 *
 
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.
 
37
 *
 
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.
 
46
 */
 
47
class CursorTheme
 
48
{
 
49
    public:
 
50
        enum ItemDataRole {
 
51
            // Note: use   printf "0x%08X\n" $(($RANDOM*$RANDOM))
 
52
            // to define additional roles.
 
53
            DisplayDetailRole = 0x24A3DAF8
 
54
        };
 
55
 
 
56
        CursorTheme() {}
 
57
        CursorTheme(const QString &title, const QString &description);
 
58
        virtual ~CursorTheme() {}
 
59
 
 
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; }
 
67
        QPixmap icon() const;
 
68
 
 
69
        /// Hash value for the internal name
 
70
        uint hash() const                  { return m_hash; }
 
71
 
 
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;
 
76
 
 
77
        /// Convenience function. Default implementation calls
 
78
        /// QPixmap::fromImage(loadImage());
 
79
        virtual QPixmap loadPixmap(const QString &name, int size = -1) const;
 
80
 
 
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;       
 
85
 
 
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; }
 
95
 
 
96
        /// Creates the icon returned by @ref icon().
 
97
        virtual QPixmap createIcon() const;
 
98
 
 
99
        /// Convenience function for cropping an image.
 
100
        QImage autoCropImage( const QImage &image ) const;
 
101
 
 
102
        // Convenience function that uses Xfixes to tag a cursor with a name
 
103
        void setCursorName(QCursor &cursor, const QString &name) const;
 
104
 
 
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;
 
112
 
 
113
    private:
 
114
        QString m_name;
 
115
        uint m_hash;
 
116
 
 
117
        friend class CursorThemeModel;
 
118
};
 
119
 
 
120
void CursorTheme::setName(const QString &name)
 
121
{
 
122
    m_name = name;
 
123
    m_hash = qHash(name);
 
124
}
 
125
 
 
126
#endif // CURSORTHEME_H
 
127