[kcm-tabbox] Use a QQuickPaintedItem for the ThumbnailItem

This commit is contained in:
Martin Gräßlin 2013-09-30 15:02:58 +02:00
parent ab08d3da9b
commit 2baa345d10
2 changed files with 10 additions and 13 deletions

View file

@ -20,21 +20,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "thumbnailitem.h" #include "thumbnailitem.h"
// Qt // Qt
#include <QtDeclarative/QDeclarativeContext>
#include <QtDeclarative/QDeclarativeEngine>
#include <QtDeclarative/QDeclarativeView>
#include <QtCore/QStandardPaths> #include <QtCore/QStandardPaths>
#include <QPainter>
// KDE // KDE
#include <KDE/KDebug> #include <KDE/KDebug>
namespace KWin namespace KWin
{ {
WindowThumbnailItem::WindowThumbnailItem(QDeclarativeItem* parent) WindowThumbnailItem::WindowThumbnailItem(QQuickPaintedItem* parent)
: QDeclarativeItem(parent) : QQuickPaintedItem(parent)
, m_wId(0) , m_wId(0)
, m_image() , m_image()
{ {
setFlags(flags() & ~QGraphicsItem::ItemHasNoContents);
} }
WindowThumbnailItem::~WindowThumbnailItem() WindowThumbnailItem::~WindowThumbnailItem()
@ -75,11 +72,10 @@ void WindowThumbnailItem::findImage()
} }
} }
void WindowThumbnailItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void WindowThumbnailItem::paint(QPainter *painter)
{ {
if (m_image.isNull()) { if (m_image.isNull()) {
// no image: default behavior return;
QDeclarativeItem::paint(painter, option, widget);
} }
QSizeF difference(boundingRect().width() - m_image.width(), boundingRect().height() - m_image.height()); QSizeF difference(boundingRect().width() - m_image.width(), boundingRect().height() - m_image.height());
const QRectF drawRect(boundingRect().x() + difference.width()/2.0, boundingRect().y(), m_image.width(), m_image.height()); const QRectF drawRect(boundingRect().x() + difference.width()/2.0, boundingRect().y(), m_image.width(), m_image.height());

View file

@ -21,24 +21,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef KWIN_THUMBNAILITEM_H #ifndef KWIN_THUMBNAILITEM_H
#define KWIN_THUMBNAILITEM_H #define KWIN_THUMBNAILITEM_H
#include <QtDeclarative/QDeclarativeItem> #include <QImage>
#include <QQuickPaintedItem>
namespace KWin namespace KWin
{ {
class WindowThumbnailItem : public QDeclarativeItem class WindowThumbnailItem : public QQuickPaintedItem
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(qulonglong wId READ wId WRITE setWId NOTIFY wIdChanged SCRIPTABLE true) Q_PROPERTY(qulonglong wId READ wId WRITE setWId NOTIFY wIdChanged SCRIPTABLE true)
public: public:
explicit WindowThumbnailItem(QDeclarativeItem *parent = 0); explicit WindowThumbnailItem(QQuickPaintedItem *parent = 0);
virtual ~WindowThumbnailItem(); virtual ~WindowThumbnailItem();
qulonglong wId() const { qulonglong wId() const {
return m_wId; return m_wId;
} }
void setWId(qulonglong wId); void setWId(qulonglong wId);
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); virtual void paint(QPainter *painter) override;
enum Thumbnail { enum Thumbnail {
Konqueror = 1, Konqueror = 1,