libplasma
template.cpp
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
00020 #include "<name>.h"
00021
00022 #include <<Native>>
00023 #include <QPainter>
00024
00025 #include <KMimeType>
00026
00027 #include "theme.h"
00028 #include "svg.h"
00029
00030 namespace Plasma
00031 {
00032
00033 class <Name>Private
00034 {
00035 public:
00036 <Name>Private()
00037 : svg(0)
00038 {
00039 }
00040
00041 ~<Name>Private()
00042 {
00043 delete svg;
00044 }
00045
00046 void setPixmap(<Name> *q)
00047 {
00048 if (imagePath.isEmpty()) {
00049 return;
00050 }
00051
00052 KMimeType::Ptr mime = KMimeType::findByPath(absImagePath);
00053 QPixmap pm(q->size().toSize());
00054
00055 if (mime->is("image/svg+xml")) {
00056 svg = new Svg();
00057 QPainter p(&pm);
00058 svg->paint(&p, pm.rect());
00059 } else {
00060 pm = QPixmap(absImagePath);
00061 }
00062
00063 //TODO: load image into widget
00064 //static_cast<<Native>*>(q->widget())->setPixmappm(pm);
00065 //static_cast<<Native>*>(q->widget())->setIcon(QIcon(pm));
00066 }
00067
00068 QString imagePath;
00069 QString absImagePath;
00070 Svg *svg;
00071 };
00072
00073 <Name>::<Name>(QGraphicsWidget *parent)
00074 : QGraphicsProxyWidget(parent),
00075 d(new <Name>Private)
00076 {
00077 <Native>* native = new <Native>;
00078 //TODO: forward signals
00079 //connect(native, SIGNAL(()), this, SIGNAL(()));
00080 setWidget(native);
00081 native->setAttribute(Qt::WA_NoSystemBackground);
00082 }
00083
00084 <Name>::~<Name>()
00085 {
00086 delete d;
00087 }
00088
00089 void <Name>::setText(const QString &text)
00090 {
00091 static_cast<<Native>*>(widget())->setText(text);
00092 }
00093
00094 QString <Name>::text() const
00095 {
00096 return static_cast<<Native>*>(widget())->text();
00097 }
00098
00099 void <Name>::setImage(const QString &path)
00100 {
00101 if (d->imagePath == path) {
00102 return;
00103 }
00104
00105 delete d->svg;
00106 d->svg = 0;
00107 d->imagePath = path;
00108
00109 bool absolutePath = !path.isEmpty() &&
00110 #ifdef Q_WS_WIN
00111 !QDir::isRelativePath(path)
00112 #else
00113 (path[0] == '/' || path.startsWith(":/"))
00114 #endif
00115 ;
00116
00117 if (absolutePath) {
00118 d->absImagePath = path;
00119 } else {
00120 //TODO: package support
00121 d->absImagePath = Theme::defaultTheme()->imagePath(path);
00122 }
00123
00124 d->setPixmap(this);
00125 }
00126
00127 QString <Name>::image() const
00128 {
00129 return d->imagePath;
00130 }
00131
00132 void <Name>::setStyleSheet(const QString &stylesheet)
00133 {
00134 widget()->setStyleSheet(stylesheet);
00135 }
00136
00137 QString <Name>::styleSheet()
00138 {
00139 return widget()->styleSheet();
00140 }
00141
00142 <Native>* <Name>::nativeWidget() const
00143 {
00144 return static_cast<<Native>*>(widget());
00145 }
00146
00147 void <Name>::resizeEvent(QGraphicsSceneResizeEvent *event)
00148 {
00149 d->setPixmap(this);
00150 QGraphicsProxyWidget::resizeEvent(event);
00151 }
00152
00153 } // namespace Plasma
00154
00155 #include <<name>.moc>
00156