diff --git a/declarativeimports/CMakeLists.txt b/declarativeimports/CMakeLists.txt index c113b603f..45b732160 100644 --- a/declarativeimports/CMakeLists.txt +++ b/declarativeimports/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(core) add_subdirectory(graphicslayouts) add_subdirectory(graphicswidgets) +add_subdirectory(qtextracomponents) diff --git a/declarativeimports/qtextracomponents/CMakeLists.txt b/declarativeimports/qtextracomponents/CMakeLists.txt new file mode 100644 index 000000000..3264ae8e2 --- /dev/null +++ b/declarativeimports/qtextracomponents/CMakeLists.txt @@ -0,0 +1,26 @@ +project(qtextracomponents) + +include(KDE4Defaults) + +set(qtextracomponents_SRCS + qtextracomponentsplugin.cpp + qpixmapitem.cpp + qimageitem.cpp + qiconitem.cpp + ) + +INCLUDE_DIRECTORIES( + ${CMAKE_SOURCE_DIR} + ${CMAKE_BINARY_DIR} + ${KDE4_INCLUDES} +) + +qt4_automoc(${qtextracomponents_SRCS}) + + +add_library(qtextracomponentsplugin SHARED ${qtextracomponents_SRCS}) +target_link_libraries(qtextracomponentsplugin ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY}) + +install(TARGETS qtextracomponentsplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/qtextracomponents) + +install(FILES qmldir DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/qtextracomponents) diff --git a/declarativeimports/qtextracomponents/qiconitem.cpp b/declarativeimports/qtextracomponents/qiconitem.cpp new file mode 100644 index 000000000..e54c49b33 --- /dev/null +++ b/declarativeimports/qtextracomponents/qiconitem.cpp @@ -0,0 +1,82 @@ +/* + * Copyright 2011 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "qiconitem.h" + +#include + + +QIconItem::QIconItem(QDeclarativeItem *parent) + : QDeclarativeItem(parent), + m_smooth(false) +{ + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + + +QIconItem::~QIconItem() +{ +} + +void QIconItem::setIcon(const QIcon &icon) +{ + m_icon = icon; + update(); +} + +QIcon QIconItem::icon() const +{ + return m_icon; +} + +void QIconItem::setSmooth(const bool smooth) +{ + if (smooth == m_smooth) { + return; + } + m_smooth = smooth; + update(); +} + +bool QIconItem::smooth() const +{ + return m_smooth; +} + +void QIconItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(option); + Q_UNUSED(widget); + + if (m_icon.isNull()) { + return; + } + //do without painter save, faster and the support can be compiled out + const bool wasAntiAlias = painter->testRenderHint(QPainter::Antialiasing); + const bool wasSmoothTransform = painter->testRenderHint(QPainter::SmoothPixmapTransform); + painter->setRenderHint(QPainter::Antialiasing, m_smooth); + painter->setRenderHint(QPainter::SmoothPixmapTransform, m_smooth); + + m_icon.paint(painter, boundingRect().toRect()); + painter->setRenderHint(QPainter::Antialiasing, wasAntiAlias); + painter->setRenderHint(QPainter::SmoothPixmapTransform, wasSmoothTransform); +} + + +#include "qiconitem.moc" diff --git a/declarativeimports/qtextracomponents/qiconitem.h b/declarativeimports/qtextracomponents/qiconitem.h new file mode 100644 index 000000000..9972a98fe --- /dev/null +++ b/declarativeimports/qtextracomponents/qiconitem.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright 2011 Marco Martin * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ +#ifndef QICONITEM_H +#define QICONITEM_H + +#include +#include + +class QIconItem : public QDeclarativeItem +{ + Q_OBJECT + + Q_PROPERTY(QIcon icon READ icon WRITE setIcon) + Q_PROPERTY(bool smooth READ smooth WRITE setSmooth) + +public: + QIconItem(QDeclarativeItem *parent=0); + ~QIconItem(); + + void setIcon(const QIcon &icon); + QIcon icon() const; + + void setSmooth(const bool smooth); + bool smooth() const; + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + +private: + QIcon m_icon; + bool m_smooth; +}; + +#endif diff --git a/declarativeimports/qtextracomponents/qimageitem.cpp b/declarativeimports/qtextracomponents/qimageitem.cpp new file mode 100644 index 000000000..086449d19 --- /dev/null +++ b/declarativeimports/qtextracomponents/qimageitem.cpp @@ -0,0 +1,94 @@ +/* + * Copyright 2011 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "qimageitem.h" + +#include + + +QImageItem::QImageItem(QDeclarativeItem *parent) + : QDeclarativeItem(parent), + m_smooth(false) +{ + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + + +QImageItem::~QImageItem() +{ +} + +void QImageItem::setImage(const QImage &image) +{ + m_image = image; + update(); + emit nativeWidthChanged(); + emit nativeHeightChanged(); +} + +QImage QImageItem::image() const +{ + return m_image; +} + +void QImageItem::setSmooth(const bool smooth) +{ + if (smooth == m_smooth) { + return; + } + m_smooth = smooth; + update(); +} + +bool QImageItem::smooth() const +{ + return m_smooth; +} + +int QImageItem::nativeWidth() const +{ + return m_image.size().width(); +} + +int QImageItem::nativeHeight() const +{ + return m_image.size().height(); +} + +void QImageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(option); + Q_UNUSED(widget); + + if (m_image.isNull()) { + return; + } + //do without painter save, faster and the support can be compiled out + const bool wasAntiAlias = painter->testRenderHint(QPainter::Antialiasing); + const bool wasSmoothTransform = painter->testRenderHint(QPainter::SmoothPixmapTransform); + painter->setRenderHint(QPainter::Antialiasing, m_smooth); + painter->setRenderHint(QPainter::SmoothPixmapTransform, m_smooth); + + painter->drawImage(boundingRect(), m_image, m_image.rect()); + painter->setRenderHint(QPainter::Antialiasing, wasAntiAlias); + painter->setRenderHint(QPainter::SmoothPixmapTransform, wasSmoothTransform); +} + + +#include "qimageitem.moc" diff --git a/declarativeimports/qtextracomponents/qimageitem.h b/declarativeimports/qtextracomponents/qimageitem.h new file mode 100644 index 000000000..a4365b5dc --- /dev/null +++ b/declarativeimports/qtextracomponents/qimageitem.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright 2011 Marco Martin * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ +#ifndef QIMAGEITEM_H +#define QIMAGEITEM_H + +#include +#include + +class QImageItem : public QDeclarativeItem +{ + Q_OBJECT + + Q_PROPERTY(QImage image READ image WRITE setImage) + Q_PROPERTY(bool smooth READ smooth WRITE setSmooth) + Q_PROPERTY(int nativeWidth READ nativeWidth NOTIFY nativeWidthChanged) + Q_PROPERTY(int nativeHeight READ nativeHeight NOTIFY nativeHeightChanged) + +public: + QImageItem(QDeclarativeItem *parent=0); + ~QImageItem(); + + void setImage(const QImage &image); + QImage image() const; + + void setSmooth(const bool smooth); + bool smooth() const; + + int nativeWidth() const; + int nativeHeight() const; + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + +Q_SIGNALS: + void nativeWidthChanged(); + void nativeHeightChanged(); + +private: + QImage m_image; + bool m_smooth; +}; + +#endif diff --git a/declarativeimports/qtextracomponents/qmldir b/declarativeimports/qtextracomponents/qmldir new file mode 100644 index 000000000..b2452e3fc --- /dev/null +++ b/declarativeimports/qtextracomponents/qmldir @@ -0,0 +1,3 @@ +plugin qtextracomponentsplugin + + diff --git a/declarativeimports/qtextracomponents/qpixmapitem.cpp b/declarativeimports/qtextracomponents/qpixmapitem.cpp new file mode 100644 index 000000000..3c09efec1 --- /dev/null +++ b/declarativeimports/qtextracomponents/qpixmapitem.cpp @@ -0,0 +1,94 @@ +/* + * Copyright 2011 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "qpixmapitem.h" + +#include + + +QPixmapItem::QPixmapItem(QDeclarativeItem *parent) + : QDeclarativeItem(parent), + m_smooth(false) +{ + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + + +QPixmapItem::~QPixmapItem() +{ +} + +void QPixmapItem::setPixmap(const QPixmap &pixmap) +{ + m_pixmap = pixmap; + update(); + emit nativeWidthChanged(); + emit nativeHeightChanged(); +} + +QPixmap QPixmapItem::pixmap() const +{ + return m_pixmap; +} + +void QPixmapItem::setSmooth(const bool smooth) +{ + if (smooth == m_smooth) { + return; + } + m_smooth = smooth; + update(); +} + +bool QPixmapItem::smooth() const +{ + return m_smooth; +} + +int QPixmapItem::nativeWidth() const +{ + return m_pixmap.size().width(); +} + +int QPixmapItem::nativeHeight() const +{ + return m_pixmap.size().height(); +} + +void QPixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(option); + Q_UNUSED(widget); + + if (m_pixmap.isNull()) { + return; + } + //do without painter save, faster and the support can be compiled out + const bool wasAntiAlias = painter->testRenderHint(QPainter::Antialiasing); + const bool wasSmoothTransform = painter->testRenderHint(QPainter::SmoothPixmapTransform); + painter->setRenderHint(QPainter::Antialiasing, m_smooth); + painter->setRenderHint(QPainter::SmoothPixmapTransform, m_smooth); + + painter->drawPixmap(boundingRect(), m_pixmap, m_pixmap.rect()); + painter->setRenderHint(QPainter::Antialiasing, wasAntiAlias); + painter->setRenderHint(QPainter::SmoothPixmapTransform, wasSmoothTransform); +} + + +#include "qpixmapitem.moc" diff --git a/declarativeimports/qtextracomponents/qpixmapitem.h b/declarativeimports/qtextracomponents/qpixmapitem.h new file mode 100644 index 000000000..af2cc9ef0 --- /dev/null +++ b/declarativeimports/qtextracomponents/qpixmapitem.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright 2011 Marco Martin * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ +#ifndef QPIXMAPITEM_H +#define QPIXMAPITEM_H + +#include +#include + +class QPixmapItem : public QDeclarativeItem +{ + Q_OBJECT + + Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap) + Q_PROPERTY(bool smooth READ smooth WRITE setSmooth) + Q_PROPERTY(int nativeWidth READ nativeWidth NOTIFY nativeWidthChanged) + Q_PROPERTY(int nativeHeight READ nativeHeight NOTIFY nativeHeightChanged) + +public: + QPixmapItem(QDeclarativeItem *parent=0); + ~QPixmapItem(); + + void setPixmap(const QPixmap &pixmap); + QPixmap pixmap() const; + + void setSmooth(const bool smooth); + bool smooth() const; + + int nativeWidth() const; + int nativeHeight() const; + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + +Q_SIGNALS: + void nativeWidthChanged(); + void nativeHeightChanged(); + +private: + QPixmap m_pixmap; + bool m_smooth; +}; + +#endif diff --git a/declarativeimports/qtextracomponents/qtextracomponentsplugin.cpp b/declarativeimports/qtextracomponents/qtextracomponentsplugin.cpp new file mode 100644 index 000000000..7d6b61f82 --- /dev/null +++ b/declarativeimports/qtextracomponents/qtextracomponentsplugin.cpp @@ -0,0 +1,41 @@ +/* + * Copyright 2009 by Alan Alpert + * Copyright 2010 by Ménard Alexis + * Copyright 2010 by Marco Martin + + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "qtextracomponentsplugin.h" + +#include + +#include "qpixmapitem.h" +#include "qimageitem.h" +#include "qiconitem.h" + +void QtExtraComponentsPlugin::registerTypes(const char *uri) +{ + Q_ASSERT(uri == QLatin1String("org.kde.qtextracomponents")); + + qmlRegisterType(uri, 0, 1, "QPixmapItem"); + qmlRegisterType(uri, 0, 1, "QImageItem"); + qmlRegisterType(uri, 0, 1, "QIconItem"); +} + + +#include "qtextracomponentsplugin.moc" + diff --git a/declarativeimports/qtextracomponents/qtextracomponentsplugin.h b/declarativeimports/qtextracomponents/qtextracomponentsplugin.h new file mode 100644 index 000000000..8b1353ce7 --- /dev/null +++ b/declarativeimports/qtextracomponents/qtextracomponentsplugin.h @@ -0,0 +1,38 @@ +/* + * Copyright 2009 by Alan Alpert + * Copyright 2010 by Ménard Alexis + * Copyright 2011 by Marco Martin + + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef QTEXTRACOMPONENTSPLUGIN_H +#define QTEXTRACOMPONENTSPLUGIN_H + +#include + + +class QtExtraComponentsPlugin : public QDeclarativeExtensionPlugin +{ + Q_OBJECT + +public: + void registerTypes(const char *uri); +}; + +Q_EXPORT_PLUGIN2(qtextracomponentsplugin, QtExtraComponentsPlugin); + +#endif