diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fc2b40c1c..19e04892d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -33,4 +33,5 @@ if(QCA2_FOUND) target_link_libraries(plasmoidpackagetest ${QCA2_LIBRARIES}) endif(QCA2_FOUND) +add_subdirectory(shelltest) diff --git a/tests/shelltest/CMakeLists.txt b/tests/shelltest/CMakeLists.txt new file mode 100644 index 000000000..5e6b6206a --- /dev/null +++ b/tests/shelltest/CMakeLists.txt @@ -0,0 +1,42 @@ +project(testplasma2) + + + +# Tell CMake to run moc when necessary: +set(CMAKE_AUTOMOC ON) +# As moc files are generated in the binary dir, tell CMake +# to always look for includes there: +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH}) + + +find_path(KDE_MODULES_DIR NAMES KDE4Macros.cmake PATH_SUFFIXES share/cmake/modules) + + +add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS}) + + +find_package(Qt5Transitional REQUIRED Core) + +# The Qt5Widgets_INCLUDES also includes the include directories for +# dependencies QtCore and QtGui +include_directories(${Qt5Widgets_DEFINITIONS} ${Qt5Quick_DEFINITIONS} ${QT_INCLUDES} ${KDE4_INCLUDES}) + +# We need add -DQT_WIDGETS_LIB when using QtWidgets in Qt 5. +add_definitions(${Qt5Widgets_DEFINITIONS} ${Qt5Quick_DEFINITIONS}) + +# Executables fail to build with Qt 5 in the default configuration +# without -fPIE. We add that here. +set(CMAKE_CXX_FLAGS "${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") + +add_executable(testplasma2 main.cpp svg.cpp) + +# The Qt5Widgets_LIBRARIES variable also includes QtGui and QtCore +target_link_libraries(testplasma2 + ${Qt5Widgets_LIBRARIES} + ${Qt5Quick_LIBRARIES} + ${kcoreaddons} + ${KDE4_PLASMA_LIBS} + #plasma +) \ No newline at end of file diff --git a/tests/shelltest/main.cpp b/tests/shelltest/main.cpp new file mode 100644 index 000000000..50e744cec --- /dev/null +++ b/tests/shelltest/main.cpp @@ -0,0 +1,62 @@ +/* + * Copyright 2012 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. + */ + +#include +#include +#include +#include "svg.h" + +#include +#include +#include + +#include +#include + +static const char description[] = "Plasma2 library tests"; +static const char version[] = "1.0"; + +int main(int argc, char** argv) +{ + + KAboutData aboutData("testplasma2", 0, ki18n("Plasma2 test app"), + version, ki18n(description), KAboutData::License_GPL, + ki18n("Copyright 2012, The KDE Team")); + aboutData.addAuthor(ki18n("Marco Martin"), + ki18n("Author and maintainer"), + "mart@kde.org"); + KCmdLineArgs::init(argc, argv, &aboutData); + + QApplication app(argc, argv); + + qmlRegisterType("org.kde.plasma", 2, 0, "Svg"); + + + + QQuickView view; + view.setResizeMode(QQuickView::SizeRootObjectToView); + view.setSource(QUrl::fromLocalFile("../main.qml")); + view.show(); + + Plasma::Corona *corona = new Plasma::Corona(); + Plasma::Containment *cont = corona->addContainment("desktop"); + Plasma::Applet *appl = cont->addApplet("foo"); + qDebug() << "Applet:" << appl->name() << appl; + + return app.exec(); +} diff --git a/tests/shelltest/main.qml b/tests/shelltest/main.qml new file mode 100644 index 000000000..4fe82a3a4 --- /dev/null +++ b/tests/shelltest/main.qml @@ -0,0 +1,42 @@ +/* + * Copyright 2012 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. + */ + +import QtQuick 2.0 +import org.kde.plasma 2.0 + +Rectangle { + color: "red" + width: 640 + height: 480 + Svg { + width: 100 + height: 100 + MouseArea { + anchors.fill: parent + drag.target: parent + } + } + Svg { + width: 100 + height: 100 + MouseArea { + anchors.fill: parent + drag.target: parent + } + } +} \ No newline at end of file diff --git a/tests/shelltest/svg.cpp b/tests/shelltest/svg.cpp new file mode 100644 index 000000000..c6899d4ca --- /dev/null +++ b/tests/shelltest/svg.cpp @@ -0,0 +1,39 @@ +/* + * Copyright 2012 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. + */ + +#include "svg.h" + +Svg::Svg(QQuickItem *parent) + : QQuickPaintedItem(parent) +{ + m_svg = new Plasma::FrameSvg(this); + m_svg->setImagePath("widgets/background"); +} + +Svg::~Svg() +{ + +} + +void Svg::paint(QPainter *painter) +{ + m_svg->resizeFrame(QSize(width(), height())); + m_svg->paintFrame(painter, QPointF(0, 0)); +} + +#include "moc_svg.cpp" diff --git a/tests/shelltest/svg.h b/tests/shelltest/svg.h new file mode 100644 index 000000000..f172248d9 --- /dev/null +++ b/tests/shelltest/svg.h @@ -0,0 +1,40 @@ +/* + * Copyright 2012 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 Svg_H +#define Svg_H + +#include + +#include +#include + +//TODO: this will be replaced by PlasmaCore.SvgItem +class Svg : public QQuickPaintedItem +{ +Q_OBJECT +public: + Svg(QQuickItem *parent = 0); + virtual ~Svg(); + + void paint(QPainter *painter); +private: + Plasma::FrameSvg *m_svg; +}; + +#endif // Svg_H