Commit 79358acb authored by Stefan Majewsky's avatar Stefan Majewsky

Move libpala example to kdeexamples.

svn path=/trunk/KDE/kdegames/palapeli/; revision=1064745
parent 1d48f0cb
project(myslicer)
find_package(KDE4 REQUIRED)
find_package(LibPala REQUIRED)
include(KDE4Defaults)
include_directories(${KDE4_INCLUDES} ${pala_INCLUDE_DIRS})
kde4_add_plugin(myslicer myslicer.cpp)
target_link_libraries(myslicer pala ${QT_QTGUI_LIBRARY} ${KDE4_KDECORE_LIBS})
install(TARGETS myslicer DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES myslicer.desktop DESTINATION ${SERVICES_INSTALL_DIR})
This is an example of how to write an external slicer plugin for libpala. For documentation, see:
http://techbase.kde.org/Development/Tutorials/Games/Palapeli_Slicers
/***************************************************************************
* Copyright 2009 Stefan Majewsky <majewsky@gmx.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
***************************************************************************/
#include "myslicer.h"
#include <KLocalizedString>
#include <KPluginFactory>
#include <KPluginLoader>
K_PLUGIN_FACTORY(MySlicerFactory, registerPlugin<MySlicer>();)
K_EXPORT_PLUGIN(MySlicerFactory("myslicer"))
MySlicer::MySlicer(QObject* parent, const QVariantList& args)
: Pala::Slicer(parent, args)
{
Pala::IntegerProperty* prop;
prop = new Pala::IntegerProperty(i18n("Piece count in horizontal direction"));
prop->setRange(3, 100);
prop->setDefaultValue(10);
addProperty("XCount", prop);
prop = new Pala::IntegerProperty(i18n("Piece count in vertical direction"));
prop->setRange(3, 100);
prop->setDefaultValue(10);
addProperty("YCount", prop);
}
bool MySlicer::run(Pala::SlicerJob* job)
{
//read job
const int xCount = job->argument("XCount").toInt();
const int yCount = job->argument("YCount").toInt();
const QImage image = job->image();
//calculate some metrics
const int pieceWidth = image.width() / xCount;
const int pieceHeight = image.height() / yCount;
const QSize pieceSize(pieceWidth, pieceHeight);
//create pieces
for (int x = 0; x < xCount; ++x)
{
for (int y = 0; y < yCount; ++y)
{
//calculate more metrics
const QPoint offset(x * pieceWidth, y * pieceHeight);
const QRect pieceBounds(offset, pieceSize);
//copy image part to piece
const QImage pieceImage = image.copy(pieceBounds);
job->addPiece(x + y * xCount, pieceImage, offset);
}
}
//create relations
for (int x = 0; x < xCount; ++x)
{
for (int y = 0; y < yCount; ++y)
{
//along X axis (pointing left)
if (x != 0)
job->addRelation(x + y * xCount, (x - 1) + y * xCount);
//along Y axis (pointing up)
if (y != 0)
job->addRelation(x + y * xCount, x + (y - 1) * xCount);
}
}
return true;
}
#include "myslicer.moc"
[Desktop Entry]
Name=My very first slicer
Name[ca]=El meu primer tallador
Name[en_GB]=My very first slicer
Name[et]=Minu esimene tükeldaja
Name[pt]=O meu primeiro divisor
Name[pt_BR]=Meu primeiro fatiador
Name[sv]=Mitt allra första delningsprogram
Name[uk]=Мій найперший інструмент розрізання
Name[x-test]=xxMy very first slicerxx
Name[zh_TW]=我的第一個切割器
Comment=It is quite simple, actually.
Comment[ca]=És molt simple, actual.
Comment[en_GB]=It is quite simple, actually.
Comment[et]=See on tegelikult päris lihtne.
Comment[pt]=É muito simples, de facto.
Comment[pt_BR]=Ele é muito simples, realmente.
Comment[sv]=Det är faktiskt ganska enkelt.
Comment[uk]=Насправді, дуже простий.
Comment[x-test]=xxIt is quite simple, actually.xx
Comment[zh_TW]=真的是很簡單的。
Type=Service
Icon=myslicer
X-KDE-Library=myslicer
X-KDE-ServiceTypes=Libpala/SlicerPlugin
X-KDE-PluginInfo-Author=Kandalf
X-KDE-PluginInfo-Email=kandalf@kde-hackers.example.org
X-KDE-PluginInfo-Name=myslicer
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Website=http://kde-hackers.example.org/myslicer
X-KDE-PluginInfo-Category=
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
/***************************************************************************
* Copyright 2009 Stefan Majewsky <majewsky@gmx.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
***************************************************************************/
#ifndef MYSLICER_H
#define MYSLICER_H
#include <Pala/Slicer>
#include <Pala/SlicerJob>
#include <Pala/SlicerProperty>
class MySlicer : public Pala::Slicer
{
Q_OBJECT
public:
explicit MySlicer(QObject* parent = 0, const QVariantList& args = QVariantList());
virtual bool run(Pala::SlicerJob* job);
};
#endif // MYSLICER_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment