Add basic plasmoid as example for developerguide

This commit is contained in:
Sebastian Kügler 2015-08-25 18:08:27 +02:00
parent 94070a6aec
commit b2d4f3a6bc
4 changed files with 118 additions and 0 deletions

View File

@ -9,3 +9,4 @@ add_subdirectory(containments)
add_subdirectory(wallpapers)
add_subdirectory(dataengines)
add_subdirectory(testcontainmentactionsplugin)
add_subdirectory(developerguide)

View File

@ -0,0 +1,2 @@
plasma_install_package(basic org.kde.example.developerguide.basic)

View File

@ -0,0 +1,96 @@
/*
* Copyright 2015 Sebastian Kügler <sebas@kde.org>
*
* 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.
*/
import QtQuick 2.3
import QtQuick.Layouts 1.1
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
Item {
// Initial size of the window in gridUnits
width: units.gridUnit * 28
height: units.gridUnit * 20
// We use a ColumnLayout to position and size the individual items
ColumnLayout {
// Our ColumnLayout is fills the parent item with a bit of margin
anchors {
fill: parent
margins: units.largeSpacing
}
spacing: units.gridUnit
// A title on top
PlasmaExtras.Title {
text: i18n("Hello Plasma World!")
}
// The central area is a rectangle
Rectangle {
// The id is used to reference this item from the
// button's onClicked function
id: colorRect
// It's supposed to grow in both direction
Layout.fillWidth: true
Layout.fillHeight: true
}
// A button to change the color to blue or green
PlasmaComponents.Button {
// The button is aligned to the right
Layout.alignment: Qt.AlignRight
// The button's label, ready for translations
text: i18n("Change Color")
onClicked: {
// Simply switch colors of the rectangle around
if (colorRect.color != "#b0c4de") {
colorRect.color = "#b0c4de"; // lightsteelblue
} else {
colorRect.color = "lightgreen";
}
// This message will end up being printed to the terminal
print("Color is now " + colorRect.color);
}
}
}
// Overlay everything with a decorative, large, translucent icon
PlasmaCore.IconItem {
// We use an anchor layout and dpi-corrected sizing
width: units.iconSizes.large * 4
height: width
anchors {
left: parent.left
bottom: parent.bottom
}
source: "akregator"
opacity: 0.1
}
}

View File

@ -0,0 +1,19 @@
[Desktop Entry]
Comment=Basic App
Name=Bug
Icon=kbugbuster
Type=Application
Exec=kpackagelauncherqml -a org.kde.example.developerguide.basic %u
X-KDE-PluginInfo-Author=Sebastian Kügler
X-KDE-PluginInfo-Category=Development
X-KDE-PluginInfo-Email=sebas@kde.org
X-KDE-PluginInfo-License=LGPLv2+
X-KDE-PluginInfo-Name=org.kde.example.developerguide.basic
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Website=http://www.kde.org
X-KDE-ServiceTypes=KPackage/GenericQML
X-Plasma-API=declarativeappletscript
X-Plasma-MainScript=ui/main.qml