Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / plasma / containments / desktop / backgroundpackage.h
blob86545e746def78347eb5d37c8270384fce5ddd7c
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.h>
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
53 static const int SCREENSHOT_HEIGHT = 60;
55 virtual ~Background();
57 virtual QString path() const = 0;
58 virtual QString findBackground(const QSize &resolution,
59 ResizeMethod method) const = 0;
60 virtual QPixmap screenshot() const = 0;
61 virtual bool screenshotGenerationStarted() const = 0;
62 virtual void generateScreenshot(QPersistentModelIndex index) const = 0;
63 virtual QString title() const = 0;
64 virtual QString author() const = 0;
65 virtual QString email() const = 0;
66 virtual QString license() const = 0;
68 virtual bool isValid() const = 0;
70 protected:
71 static QImage defaultScreenshot();
72 static QImage createScreenshot(const QString &path, float ratio);
73 friend class ResizeThread;
76 class BackgroundPackage : public Background,
77 public Plasma::Package
79 Q_OBJECT
80 public:
81 BackgroundPackage(const QString &path, float ratio);
83 virtual QString path() const;
84 virtual QString findBackground(const QSize &resolution,
85 ResizeMethod method) const;
86 virtual QPixmap screenshot() const;
87 virtual bool screenshotGenerationStarted() const;
88 virtual void generateScreenshot(QPersistentModelIndex index) const;
89 virtual QString author() const;
90 virtual QString title() const;
91 virtual QString email() const;
92 virtual QString license() const;
93 virtual bool isValid() const;
94 private:
95 QString resString(const QSize &size) const;
96 QSize resSize(const QString &res) const;
98 float distance(const QSize &size,
99 const QSize &desired,
100 ResizeMethod method) const;
102 QString m_path;
103 float m_ratio;
104 mutable QPixmap m_screenshot;
107 class BackgroundFile : public Background
109 Q_OBJECT
110 public:
111 BackgroundFile(const QString &file, float ratio);
112 virtual ~BackgroundFile();
114 virtual QString path() const;
115 virtual QString findBackground(const QSize &resolution,
116 ResizeMethod method) const;
117 virtual bool screenshotGenerationStarted() const;
118 virtual void generateScreenshot(QPersistentModelIndex index) const;
119 virtual QPixmap screenshot() const;
120 virtual QString author() const;
121 virtual QString title() const;
122 virtual QString email() const;
123 virtual QString license() const;
124 virtual bool isValid() const;
125 private:
126 QString m_file;
127 float m_ratio;
129 mutable bool m_resizer_started;
130 mutable QPixmap m_screenshot;
131 private slots:
132 void updateScreenshot(ThreadWeaver::Job *);
133 signals:
134 void screenshotDone(QPersistentModelIndex index);
137 #endif // BACKGROUNDPACKAGE_H