add more spacing
[personal-kdebase.git] / workspace / plasma / wallpapers / image / backgroundpackage.h
blob729ec0613e861df6582f307d6f029956ca9be62f
1 /*
2 * Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU Library General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #ifndef BACKGROUNDPACKAGE_H
20 #define BACKGROUNDPACKAGE_H
22 #include <memory>
23 #include <QImage>
24 #include <QPersistentModelIndex>
25 #include <QPixmap>
26 #include <QSize>
27 #include <QThread>
28 #include <QVariant>
29 #include <ThreadWeaver/Job>
30 #include <Plasma/Package>
32 namespace Plasma { class PackageMetadata; }
34 class DummyObject : public QObject
36 Q_OBJECT
37 signals:
38 void done(ThreadWeaver::Job *);
41 class Background : public QObject
43 Q_OBJECT
44 public:
45 enum ResizeMethod {
46 Scale,
47 Center,
48 ScaleCrop,
49 Tiled,
50 CenterTiled,
51 Maxpect
54 static const int SCREENSHOT_HEIGHT = 60;
56 virtual ~Background();
58 virtual QString path() const = 0;
59 virtual QString findBackground(const QSize &resolution,
60 ResizeMethod method) const = 0;
61 virtual QPixmap screenshot() const = 0;
62 virtual bool screenshotGenerationStarted() const = 0;
63 virtual void generateScreenshot(QPersistentModelIndex index) const = 0;
64 virtual QString title() const = 0;
65 virtual QString author() const = 0;
66 virtual QString email() const = 0;
67 virtual QString license() const = 0;
69 virtual bool isValid() const = 0;
71 protected:
72 static QImage defaultScreenshot();
73 static QImage createScreenshot(const QString &path, float ratio);
74 friend class ResizeThread;
77 class BackgroundPackage : public Background,
78 public Plasma::Package
80 Q_OBJECT
81 public:
82 BackgroundPackage(const QString &path, float ratio);
84 virtual QString path() const;
85 virtual QString findBackground(const QSize &resolution,
86 ResizeMethod method) const;
87 virtual QPixmap screenshot() const;
88 virtual bool screenshotGenerationStarted() const;
89 virtual void generateScreenshot(QPersistentModelIndex index) const;
90 virtual QString author() const;
91 virtual QString title() const;
92 virtual QString email() const;
93 virtual QString license() const;
94 virtual bool isValid() const;
95 private:
96 QString resString(const QSize &size) const;
97 QSize resSize(const QString &res) const;
99 float distance(const QSize &size,
100 const QSize &desired,
101 ResizeMethod method) const;
103 QString m_path;
104 float m_ratio;
105 mutable QPixmap m_screenshot;
108 class BackgroundFile : public Background
110 Q_OBJECT
111 public:
112 BackgroundFile(const QString &file, float ratio);
113 virtual ~BackgroundFile();
115 virtual QString path() const;
116 virtual QString findBackground(const QSize &resolution,
117 ResizeMethod method) const;
118 virtual bool screenshotGenerationStarted() const;
119 virtual void generateScreenshot(QPersistentModelIndex index) const;
120 virtual QPixmap screenshot() const;
121 virtual QString author() const;
122 virtual QString title() const;
123 virtual QString email() const;
124 virtual QString license() const;
125 virtual bool isValid() const;
126 private:
127 QString m_file;
128 float m_ratio;
130 mutable bool m_resizer_started;
131 mutable QPixmap m_screenshot;
132 private slots:
133 void updateScreenshot(ThreadWeaver::Job *);
134 signals:
135 void screenshotDone(QPersistentModelIndex index);
138 #endif // BACKGROUNDPACKAGE_H