add a barebone shell executable

used to test painting and containment loading
This commit is contained in:
Marco Martin 2012-12-19 15:42:24 +01:00
parent 5cb3712bc6
commit 627ff32f44
6 changed files with 226 additions and 0 deletions

View File

@ -33,4 +33,5 @@ if(QCA2_FOUND)
target_link_libraries(plasmoidpackagetest ${QCA2_LIBRARIES}) target_link_libraries(plasmoidpackagetest ${QCA2_LIBRARIES})
endif(QCA2_FOUND) endif(QCA2_FOUND)
add_subdirectory(shelltest)

View File

@ -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
)

62
tests/shelltest/main.cpp Normal file
View File

@ -0,0 +1,62 @@
/*
* Copyright 2012 Marco Martin <mart@kde.org>
*
* 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 <QApplication>
#include <QtQuick/QQuickView>
#include <QtCore/QDebug>
#include "svg.h"
#include <KAboutData>
#include <KCmdLineArgs>
#include <KLocalizedString>
#include <Plasma/Corona>
#include <Plasma/Containment>
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<Svg>("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();
}

42
tests/shelltest/main.qml Normal file
View File

@ -0,0 +1,42 @@
/*
* Copyright 2012 Marco Martin <mart@kde.org>
*
* 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
}
}
}

39
tests/shelltest/svg.cpp Normal file
View File

@ -0,0 +1,39 @@
/*
* Copyright 2012 Marco Martin <mart@kde.org>
*
* 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"

40
tests/shelltest/svg.h Normal file
View File

@ -0,0 +1,40 @@
/*
* Copyright 2012 Marco Martin <mart@kde.org>
*
* 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 <QtQuick/QQuickPaintedItem>
#include <Plasma/Svg>
#include <Plasma/FrameSvg>
//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