Plasma
backgroundpackage.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef BACKGROUNDPACKAGE_H
00020 #define BACKGROUNDPACKAGE_H
00021
00022 #include <memory>
00023 #include <QImage>
00024 #include <QPersistentModelIndex>
00025 #include <QPixmap>
00026 #include <QSize>
00027 #include <QThread>
00028 #include <QVariant>
00029 #include <ThreadWeaver/Job>
00030 #include <Plasma/Package>
00031
00032 namespace Plasma { class PackageMetadata; }
00033
00034 class DummyObject : public QObject
00035 {
00036 Q_OBJECT
00037 signals:
00038 void done(ThreadWeaver::Job *);
00039 };
00040
00041 class Background : public QObject
00042 {
00043 Q_OBJECT
00044 public:
00045 enum ResizeMethod {
00046 Scale,
00047 Center,
00048 ScaleCrop,
00049 Tiled,
00050 CenterTiled,
00051 Maxpect
00052 };
00053
00054 static const int SCREENSHOT_HEIGHT = 60;
00055
00056 virtual ~Background();
00057
00058 virtual QString path() const = 0;
00059 virtual QString findBackground(const QSize &resolution,
00060 ResizeMethod method) const = 0;
00061 virtual QPixmap screenshot() const = 0;
00062 virtual bool screenshotGenerationStarted() const = 0;
00063 virtual void generateScreenshot(QPersistentModelIndex index) const = 0;
00064 virtual QString title() const = 0;
00065 virtual QString author() const = 0;
00066 virtual QString email() const = 0;
00067 virtual QString license() const = 0;
00068
00069 virtual bool isValid() const = 0;
00070
00071 protected:
00072 static QImage defaultScreenshot();
00073 static QImage createScreenshot(const QString &path, float ratio);
00074 friend class ResizeThread;
00075 };
00076
00077 class BackgroundPackage : public Background,
00078 public Plasma::Package
00079 {
00080 Q_OBJECT
00081 public:
00082 BackgroundPackage(const QString &path, float ratio);
00083
00084 virtual QString path() const;
00085 virtual QString findBackground(const QSize &resolution,
00086 ResizeMethod method) const;
00087 virtual QPixmap screenshot() const;
00088 virtual bool screenshotGenerationStarted() const;
00089 virtual void generateScreenshot(QPersistentModelIndex index) const;
00090 virtual QString author() const;
00091 virtual QString title() const;
00092 virtual QString email() const;
00093 virtual QString license() const;
00094 virtual bool isValid() const;
00095 private:
00096 QString resString(const QSize &size) const;
00097 QSize resSize(const QString &res) const;
00098
00099 float distance(const QSize &size,
00100 const QSize &desired,
00101 ResizeMethod method) const;
00102
00103 QString m_path;
00104 float m_ratio;
00105 mutable QPixmap m_screenshot;
00106 };
00107
00108 class BackgroundFile : public Background
00109 {
00110 Q_OBJECT
00111 public:
00112 BackgroundFile(const QString &file, float ratio);
00113 virtual ~BackgroundFile();
00114
00115 virtual QString path() const;
00116 virtual QString findBackground(const QSize &resolution,
00117 ResizeMethod method) const;
00118 virtual bool screenshotGenerationStarted() const;
00119 virtual void generateScreenshot(QPersistentModelIndex index) const;
00120 virtual QPixmap screenshot() const;
00121 virtual QString author() const;
00122 virtual QString title() const;
00123 virtual QString email() const;
00124 virtual QString license() const;
00125 virtual bool isValid() const;
00126 private:
00127 QString m_file;
00128 float m_ratio;
00129
00130 mutable bool m_resizer_started;
00131 mutable QPixmap m_screenshot;
00132 private slots:
00133 void updateScreenshot(ThreadWeaver::Job *);
00134 signals:
00135 void screenshotDone(QPersistentModelIndex index);
00136 };
00137
00138 #endif // BACKGROUNDPACKAGE_H