20
Developing Device-Adaptive Apps Sebastian Kügler & Daker Fernandes Pinheiro Using KDE Plasma Technologies

Plasmaquick Workshop - FISL 13

Embed Size (px)

Citation preview

Page 1: Plasmaquick Workshop - FISL 13

Developing

Device-Adaptive Apps

Sebastian Kügler & Daker Fernandes Pinheiro

Using KDE Plasma Technologies

Page 2: Plasmaquick Workshop - FISL 13

Overview

● Conceptual Intro

● Qt Quick / QML Introduction

● Extending Qt Quick using C++

● Plasma Quick

● Tools, Tips & Tricks

● Hacking / Discussion / Hands-on / Help

Developing Device-Adaptive Apps – Overview

Page 3: Plasmaquick Workshop - FISL 13

Adapt instead of dumbing down

● Different interfaces for different devices

● UI as thin layer

● Switchable input profiles (part of the platform, “for free”)

● Switchable layouts (per app, usually one file per device)

● Work with different input methods

● Reusable components

Developing Device-Adaptive Apps – General

Page 4: Plasmaquick Workshop - FISL 13

Technologies

● Qt / QML

● KDE libraries

● UI profile switchable by env var

● Reusable components

Developing Device-Adaptive Apps – General

Page 5: Plasmaquick Workshop - FISL 13

Developing Device-Adaptive Apps – General

Developer Story

● Chad – casual hacker, familiar with web technologies● Plasmate introduces Chad to Plasma

● Lwing – experienced C++ developer, own codebase● Lwing ports, develops and packages her applications using the Mer SDK

● Brian – KDE Hacker● Brian is part of the KDE team and regularly contributes patches

Page 6: Plasmaquick Workshop - FISL 13

Developing Device-Adaptive Apps – QtQuick Intro

Qt Quick: Intro

● Declarative UI – not procedural but “object tree”

● JSON + JavaScript

● Interpreted at runtime

● Dynamic types

● Reusable components

• http://qt-project.org/doc/qt-4.8/qdeclarativeintroduction.html

• https://developer.mozilla.org/en/JavaScript/Guide

Page 7: Plasmaquick Workshop - FISL 13

Developing Device-Adaptive Apps – QtQuick Intro

Qt Quick: Concepts

● Property binding vs. value assignment

● Extensible using modules

● Layouting using anchors

● Reusable components

• http://qt-project.org/doc/qt-4.8/qdeclarativeintroduction.html

• https://developer.mozilla.org/en/JavaScript/Guide

Page 8: Plasmaquick Workshop - FISL 13

Developing Device-Adaptive Apps – QtQuick Intro

Qt Quick Example

import QtQuick 1.1

Rectangle {

width: 200

height: 200

color: "blue"

Image {

source: "pics/logo.png"

anchors.centerIn: parent

}

}

Page 9: Plasmaquick Workshop - FISL 13

Developing Device-Adaptive Apps – QtQuick Intro

Qt Quick Anchor Layouts

• Align objects to each other

• Useful for flexible layouts

• Dynamic sizing of objects: Scales well

• Surprisingly painless and logical

• Very powerful

Page 10: Plasmaquick Workshop - FISL 13

Developing Device-Adaptive Apps – QtQuick Intro

QML Lists & Models import QtQuick 1.1

Item { width: 200; height: 250

ListModel { id: myModel ListElement { type: "Dog"; age: 8 } ListElement { type: "Cat"; age: 5 } }

Component { id: myDelegate Text { text: type + ", " + age } }

ListView { anchors.fill: parent model: myModel delegate: myDelegate } }

Page 11: Plasmaquick Workshop - FISL 13

Developing Device-Adaptive Apps – Advanced QML

QML & C++ Hybrids: Basics

● QML can be extended using C++

● Getting data from C++ to QML:

● setContextProperty()

● qmlRegisterType()

● Creating new imports (careful, public API!)

● QObject as base class

● Q_PROPERTY() for getter, setter, notify

● Q_INVOKABLE() for methods

Page 12: Plasmaquick Workshop - FISL 13

Developing Device-Adaptive Apps – Advanced QML

QML & C++ Hybrids: Models

● QStringList – really basic, “modelData” holds your string

● QList<QObject*> – useful for smallish lists

● QAbstractItemModel – Full power, full control, full pain

• http://qt-project.org/doc/qt-4.8/qdeclarativemodels.html

• http://qt-project.org/doc/qt-4.8/qdeclarativemodels.html#qml-c-models

http://steveire.wordpress.com/2010/02/19/qml-with-akonadi-or-how-to-use-your-existing-model-view-design-with-qml/

• http://sf2011.meego.com/program/sessions/data-models-qml

Page 13: Plasmaquick Workshop - FISL 13

Developing Device-Adaptive Apps – Plasma Quick

Plasma Quick: Basics

● QtQuick + Plasma / KDE libraries

● i18n() for translation

● Plasma Components

● PlasmaCore, QtExtras, PlasmaExtras, ...

• http://techbase.kde.org/Development/Tutorials/Plasma/QML/API

• http://api.kde.org/4.x-api/plasma-qml-apidocs/

Page 14: Plasmaquick Workshop - FISL 13

Developing Device-Adaptive Apps – Plasma Quick

Plasma Quick: Classes

● PlasmaCore.Theme

● PlasmaCore.{SvgItem,FrameSvg,...}

● PlasmaCore.DataSource to use dataengines

● PlasmaCore.Dialog

● PlasmaCore.SortFilterModel

● QIconItem, QPixmapItem, QImageItem, ...

• http://techbase.kde.org/Development/Tutorials/Plasma/QML/API

Page 15: Plasmaquick Workshop - FISL 13

Developing Device-Adaptive Apps – Tips & Tricks

Tools

● QtCreator

● qmlviewer● qmlviewer -I `kde4-config --prefix`/lib/kde4/imports/

● Plasmoidviewer

plasmoidviewer --list

● plasmoidviewer [pluginname]

● Qt Assistant (try searching for QML!)

Page 16: Plasmaquick Workshop - FISL 13

Developing Device-Adaptive Apps – Tips & Tricks

Tips & Tricks

● git clone kde:kdeexamples plasma/declarative/*→

● Use PlasmaComponents.Label instead of Text

● Think about splitting into reusable components

● grep in kde:declarative-plasmoids and kde:plasma-mobile

● Rectangle { color: “orange”; opacity: 0.3; anchors.fill: parent; }

inside your Item helps finding sizing problems

Page 17: Plasmaquick Workshop - FISL 13

Developing Device-Adaptive Apps – SDK “light”

Plasmate

Workflow-driven IDE for Plasmoids:

● Create – Hack – Test – Deploy – Publish

● 1.0 end of summer

● Clone from git://anongit.kde.org/plasmate

● Build using cmake (needs kdelibs-devel)

● Start hacking

Page 18: Plasmaquick Workshop - FISL 13

Developing Device-Adaptive Apps – Limitless SDK

Mer SDK

Chroot environment with everything pre-setup

● Work in progress: involves a bit of manual setup

● Easy way to cross-compile

● Easy way to build packages for $DEVICE

● Takes complexity away big time

Page 19: Plasmaquick Workshop - FISL 13

Help!

Sebastian Kügler

• #plasma on Freenode

[email protected]

Page 20: Plasmaquick Workshop - FISL 13

Happy hacking!

Sebastian Kügler

Interesting blogs:

• http://codecereal.blogspot.com.br/ (Daker)

• http://vizZzion.org (sebas)

• http://notmart.org (Marco Martin)