~blue-shell/blue-shell/sddm-kcm

« back to all changes in this revision

Viewing changes to src/cursortheme/cursortheme.h

  • Committer: David Edmundson
  • Date: 2014-10-04 21:21:55 UTC
  • Revision ID: git-v1:a9cdde9b19e3f8e7edf50581d8c44a611a908992
All code has moved to https://projects.kde.org/projects/kdereview/sddm-kcm/repository

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 = QString());
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
 
        /** @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; }
72
 
        QPixmap icon() const;
73
 
 
74
 
        /// Hash value for the internal name
75
 
        uint hash() const                  { return m_hash; }
76
 
 
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;
81
 
 
82
 
        /// Convenience function. Default implementation calls
83
 
        /// QPixmap::fromImage(loadImage());
84
 
        virtual QPixmap loadPixmap(const QString &name, int size = 0) const;
85
 
 
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;
90
 
 
91
 
        /** Creates the icon returned by @ref icon(). Don't use this function
92
 
            directly but use @ref icon() instead, because @ref icon() caches
93
 
            the icon.
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;
101
 
 
102
 
        static bool haveXfixes();
103
 
 
104
 
    protected:
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; }
115
 
 
116
 
        /// Convenience function for cropping an image.
117
 
        QImage autoCropImage( const QImage &image ) const;
118
 
 
119
 
        // Convenience function that uses Xfixes to tag a cursor with a name
120
 
        void setCursorName(qulonglong cursor, const QString &name) const;
121
 
 
122
 
        QString m_title;
123
 
        QString m_description;
124
 
        QString m_path;
125
 
        QList<int> m_availableSizes;
126
 
        QString m_sample;
127
 
        mutable QPixmap m_icon;
128
 
        bool m_writable:1;
129
 
        bool m_hidden:1;
130
 
 
131
 
    private:
132
 
        QString m_name;
133
 
        uint m_hash;
134
 
 
135
 
        friend class CursorThemeModel;
136
 
};
137
 
 
138
 
void CursorTheme::setName(const QString &name)
139
 
{
140
 
    m_name = name;
141
 
    m_hash = qHash(name);
142
 
}
143
 
 
144
 
#endif // CURSORTHEME_H
145