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.h>
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 };
00052
00053 static const int SCREENSHOT_HEIGHT = 60;
00054
00055 virtual ~Background();
00056
00057 virtual QString path() const = 0;
00058 virtual QString findBackground(const QSize &resolution,
00059 ResizeMethod method) const = 0;
00060 virtual QPixmap screenshot() const = 0;
00061 virtual bool screenshotGenerationStarted() const = 0;
00062 virtual void generateScreenshot(QPersistentModelIndex index) const = 0;
00063 virtual QString title() const = 0;
00064 virtual QString author() const = 0;
00065 virtual QString email() const = 0;
00066 virtual QString license() const = 0;
00067
00068 virtual bool isValid() const = 0;
00069
00070 protected:
00071 static QImage defaultScreenshot();
00072 static QImage createScreenshot(const QString &path, float ratio);
00073 friend class ResizeThread;
00074 };
00075
00076 class BackgroundPackage : public Background,
00077 public Plasma::Package
00078 {
00079 Q_OBJECT
00080 public:
00081 BackgroundPackage(const QString &path, float ratio);
00082
00083 virtual QString path() const;
00084 virtual QString findBackground(const QSize &resolution,
00085 ResizeMethod method) const;
00086 virtual QPixmap screenshot() const;
00087 virtual bool screenshotGenerationStarted() const;
00088 virtual void generateScreenshot(QPersistentModelIndex index) const;
00089 virtual QString author() const;
00090 virtual QString title() const;
00091 virtual QString email() const;
00092 virtual QString license() const;
00093 virtual bool isValid() const;
00094 private:
00095 QString resString(const QSize &size) const;
00096 QSize resSize(const QString &res) const;
00097
00098 float distance(const QSize &size,
00099 const QSize &desired,
00100 ResizeMethod method) const;
00101
00102 QString m_path;
00103 float m_ratio;
00104 mutable QPixmap m_screenshot;
00105 };
00106
00107 class BackgroundFile : public Background
00108 {
00109 Q_OBJECT
00110 public:
00111 BackgroundFile(const QString &file, float ratio);
00112 virtual ~BackgroundFile();
00113
00114 virtual QString path() const;
00115 virtual QString findBackground(const QSize &resolution,
00116 ResizeMethod method) const;
00117 virtual bool screenshotGenerationStarted() const;
00118 virtual void generateScreenshot(QPersistentModelIndex index) const;
00119 virtual QPixmap screenshot() const;
00120 virtual QString author() const;
00121 virtual QString title() const;
00122 virtual QString email() const;
00123 virtual QString license() const;
00124 virtual bool isValid() const;
00125 private:
00126 QString m_file;
00127 float m_ratio;
00128
00129 mutable bool m_resizer_started;
00130 mutable QPixmap m_screenshot;
00131 private slots:
00132 void updateScreenshot(ThreadWeaver::Job *);
00133 signals:
00134 void screenshotDone(QPersistentModelIndex index);
00135 };
00136
00137 #endif // BACKGROUNDPACKAGE_H