Port of Plastik decoration to QML

The Plastik decoration buttons are provided by a declarative
extension plugin as the canvas drawing API would be needed to
draw these buttons. This should be changed with Qt 5.

But it's also a nice example to show how a QML based decoration
can have an extension in C++.
This commit is contained in:
Martin Gräßlin 2012-07-28 14:39:40 +02:00
parent ce2b251c9b
commit 459da3ea44
12 changed files with 1132 additions and 0 deletions

View file

@ -3,3 +3,4 @@ project(aurorae)
add_subdirectory(src)
#add_subdirectory(themes/example-deco)
add_subdirectory(themes)

View file

@ -0,0 +1 @@
add_subdirectory(plastik)

View file

@ -0,0 +1,8 @@
add_subdirectory(code)
install(DIRECTORY package/
DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/decorations/kwin4_decoration_qml_plastik)
install(FILES package/metadata.desktop
DESTINATION ${SERVICES_INSTALL_DIR}/${KWIN_NAME}
RENAME kwin4_decoration_qml_plastik.desktop)

View file

@ -0,0 +1,11 @@
set(plastik_plugin_SRCS
plastikbutton.cpp
plastikplugin.cpp
)
qt4_automoc(${plastik_plugin_SRCS})
add_library(plastikplugin SHARED ${plastik_plugin_SRCS})
target_link_libraries(plastikplugin ${QT_QTCORE_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY} ${KDE4_KDEUI_LIBRARY} kdecorations)
install(TARGETS plastikplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/kwin/decorations/plastik)
install(FILES qmldir DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/kwin/decorations/plastik)

View file

@ -0,0 +1,445 @@
/********************************************************************
Copyright (C) 2012 Martin Gräßlin <mgraesslin@kde.org>
Copyright (C) 2003-2005 Sandro Giessl <sandro@giessl.com>
based on the window decoration "Web":
Copyright (C) 2001 Rik Hemsley (rikkus) <rik@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, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "plastikbutton.h"
#include <kdecoration.h>
#include <KDE/KColorScheme>
#include <QPainter>
namespace KWin
{
PlastikButtonProvider::PlastikButtonProvider()
: QDeclarativeImageProvider(Pixmap)
{
}
QPixmap PlastikButtonProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
{
int origSize = requestedSize.isValid() ? qMin(requestedSize.width(), requestedSize.height()) : 10;
if (size) {
*size = QSize(origSize, origSize);
}
QStringList idParts = id.split('/');
if (idParts.isEmpty()) {
// incorrect id
return QDeclarativeImageProvider::requestPixmap(id, size, requestedSize);
}
bool active = false;
bool toggled = false;
bool shadow = false;
if (idParts.length() > 1 && idParts.at(1) == "true") {
active = true;
}
if (idParts.length() > 2 && idParts.at(2) == "true") {
toggled = true;
}
if (idParts.length() > 3 && idParts.at(3) == "true") {
shadow = true;
}
ButtonIcon button;
if (idParts[0] == "X") {
button = CloseIcon;
} else if (idParts[0] == "A") {
if (toggled) {
button = MaxRestoreIcon;
} else {
button = MaxIcon;
}
} else if (idParts[0] == "I") {
button = MinIcon;
} else if (idParts[0] == "H") {
button = HelpIcon;
} else if (idParts[0] == "S") {
if (toggled) {
button = NotOnAllDesktopsIcon;
} else {
button = OnAllDesktopsIcon;
}
} else if (idParts[0] == "F") {
if (toggled) {
button = NoKeepAboveIcon;
} else {
button = KeepAboveIcon;
}
} else if (idParts[0] == "B") {
if (toggled) {
button = NoKeepBelowIcon;
} else {
button = KeepBelowIcon;
}
} else if (idParts[0] == "L") {
if (toggled) {
button = UnShadeIcon;
} else {
button = ShadeIcon;
}
} else {
// not recognized icon
return QDeclarativeImageProvider::requestPixmap(id, size, requestedSize);
}
return icon(button, origSize, active, shadow);
}
QPixmap PlastikButtonProvider::icon(ButtonIcon icon, int size, bool active, bool shadow)
{
if (size%2 == 0)
--size;
QPixmap image(size, size);
image.fill(Qt::transparent);
QPainter p(&image);
const QColor color = KDecoration::options()->color(KDecoration::ColorFont, active);
if (shadow) {
p.setPen(KColorScheme::shade(color, KColorScheme::ShadowShade));
} else {
p.setPen(color);
}
const QRect r = image.rect();
// line widths
int lwTitleBar = 1;
if (r.width() > 16) {
lwTitleBar = 4;
} else if (r.width() > 4) {
lwTitleBar = 2;
}
int lwArrow = 1;
if (r.width() > 16) {
lwArrow = 4;
} else if (r.width() > 7) {
lwArrow = 2;
}
switch(icon) {
case CloseIcon:
{
int lineWidth = 1;
if (r.width() > 16) {
lineWidth = 3;
} else if (r.width() > 4) {
lineWidth = 2;
}
drawObject(p, DiagonalLine, r.x(), r.y(), r.width(), lineWidth);
drawObject(p, CrossDiagonalLine, r.x(), r.bottom(), r.width(), lineWidth);
break;
}
case MaxIcon:
{
int lineWidth2 = 1; // frame
if (r.width() > 16) {
lineWidth2 = 2;
} else if (r.width() > 4) {
lineWidth2 = 1;
}
drawObject(p, HorizontalLine, r.x(), r.top(), r.width(), lwTitleBar);
drawObject(p, HorizontalLine, r.x(), r.bottom()-(lineWidth2-1), r.width(), lineWidth2);
drawObject(p, VerticalLine, r.x(), r.top(), r.height(), lineWidth2);
drawObject(p, VerticalLine, r.right()-(lineWidth2-1), r.top(), r.height(), lineWidth2);
break;
}
case MaxRestoreIcon:
{
int lineWidth2 = 1; // frame
if (r.width() > 16) {
lineWidth2 = 2;
} else if (r.width() > 4) {
lineWidth2 = 1;
}
int margin1, margin2;
margin1 = margin2 = lineWidth2*2;
if (r.width() < 8)
margin1 = 1;
// background window
drawObject(p, HorizontalLine, r.x()+margin1, r.top(), r.width()-margin1, lineWidth2);
drawObject(p, HorizontalLine, r.right()-margin2, r.bottom()-(lineWidth2-1)-margin1, margin2, lineWidth2);
drawObject(p, VerticalLine, r.x()+margin1, r.top(), margin2, lineWidth2);
drawObject(p, VerticalLine, r.right()-(lineWidth2-1), r.top(), r.height()-margin1, lineWidth2);
// foreground window
drawObject(p, HorizontalLine, r.x(), r.top()+margin2, r.width()-margin2, lwTitleBar);
drawObject(p, HorizontalLine, r.x(), r.bottom()-(lineWidth2-1), r.width()-margin2, lineWidth2);
drawObject(p, VerticalLine, r.x(), r.top()+margin2, r.height(), lineWidth2);
drawObject(p, VerticalLine, r.right()-(lineWidth2-1)-margin2, r.top()+margin2, r.height(), lineWidth2);
break;
}
case MinIcon:
{
drawObject(p, HorizontalLine, r.x(), r.bottom()-(lwTitleBar-1), r.width(), lwTitleBar);
break;
}
case HelpIcon:
{
int center = r.x()+r.width()/2 -1;
int side = r.width()/4;
// paint a question mark... code is quite messy, to be cleaned up later...! :o
if (r.width() > 16) {
int lineWidth = 3;
// top bar
drawObject(p, HorizontalLine, center-side+3, r.y(), 2*side-3-1, lineWidth);
// top bar rounding
drawObject(p, CrossDiagonalLine, center-side-1, r.y()+5, 6, lineWidth);
drawObject(p, DiagonalLine, center+side-3, r.y(), 5, lineWidth);
// right bar
drawObject(p, VerticalLine, center+side+2-lineWidth, r.y()+3, r.height()-(2*lineWidth+side+2+1), lineWidth);
// bottom bar
drawObject(p, CrossDiagonalLine, center, r.bottom()-2*lineWidth, side+2, lineWidth);
drawObject(p, HorizontalLine, center, r.bottom()-3*lineWidth+2, lineWidth, lineWidth);
// the dot
drawObject(p, HorizontalLine, center, r.bottom()-(lineWidth-1), lineWidth, lineWidth);
} else if (r.width() > 8) {
int lineWidth = 2;
// top bar
drawObject(p, HorizontalLine, center-(side-1), r.y(), 2*side-1, lineWidth);
// top bar rounding
if (r.width() > 9) {
drawObject(p, CrossDiagonalLine, center-side-1, r.y()+3, 3, lineWidth);
} else {
drawObject(p, CrossDiagonalLine, center-side-1, r.y()+2, 3, lineWidth);
}
drawObject(p, DiagonalLine, center+side-1, r.y(), 3, lineWidth);
// right bar
drawObject(p, VerticalLine, center+side+2-lineWidth, r.y()+2, r.height()-(2*lineWidth+side+1), lineWidth);
// bottom bar
drawObject(p, CrossDiagonalLine, center, r.bottom()-2*lineWidth+1, side+2, lineWidth);
// the dot
drawObject(p, HorizontalLine, center, r.bottom()-(lineWidth-1), lineWidth, lineWidth);
} else {
int lineWidth = 1;
// top bar
drawObject(p, HorizontalLine, center-(side-1), r.y(), 2*side, lineWidth);
// top bar rounding
drawObject(p, CrossDiagonalLine, center-side-1, r.y()+1, 2, lineWidth);
// right bar
drawObject(p, VerticalLine, center+side+1, r.y(), r.height()-(side+2+1), lineWidth);
// bottom bar
drawObject(p, CrossDiagonalLine, center, r.bottom()-2, side+2, lineWidth);
// the dot
drawObject(p, HorizontalLine, center, r.bottom(), 1, 1);
}
break;
}
case NotOnAllDesktopsIcon:
{
int lwMark = r.width()-lwTitleBar*2-2;
if (lwMark < 1)
lwMark = 3;
drawObject(p, HorizontalLine, r.x()+(r.width()-lwMark)/2, r.y()+(r.height()-lwMark)/2, lwMark, lwMark);
// Fall through to OnAllDesktopsIcon intended!
}
case OnAllDesktopsIcon:
{
// horizontal bars
drawObject(p, HorizontalLine, r.x()+lwTitleBar, r.y(), r.width()-2*lwTitleBar, lwTitleBar);
drawObject(p, HorizontalLine, r.x()+lwTitleBar, r.bottom()-(lwTitleBar-1), r.width()-2*lwTitleBar, lwTitleBar);
// vertical bars
drawObject(p, VerticalLine, r.x(), r.y()+lwTitleBar, r.height()-2*lwTitleBar, lwTitleBar);
drawObject(p, VerticalLine, r.right()-(lwTitleBar-1), r.y()+lwTitleBar, r.height()-2*lwTitleBar, lwTitleBar);
break;
}
case NoKeepAboveIcon:
{
int center = r.x()+r.width()/2;
// arrow
drawObject(p, CrossDiagonalLine, r.x(), center+2*lwArrow, center-r.x(), lwArrow);
drawObject(p, DiagonalLine, r.x()+center, r.y()+1+2*lwArrow, center-r.x(), lwArrow);
if (lwArrow>1)
drawObject(p, HorizontalLine, center-(lwArrow-2), r.y()+2*lwArrow, (lwArrow-2)*2, lwArrow);
// Fall through to KeepAboveIcon intended!
}
case KeepAboveIcon:
{
int center = r.x()+r.width()/2;
// arrow
drawObject(p, CrossDiagonalLine, r.x(), center, center-r.x(), lwArrow);
drawObject(p, DiagonalLine, r.x()+center, r.y()+1, center-r.x(), lwArrow);
if (lwArrow>1)
drawObject(p, HorizontalLine, center-(lwArrow-2), r.y(), (lwArrow-2)*2, lwArrow);
break;
}
case NoKeepBelowIcon:
{
int center = r.x()+r.width()/2;
// arrow
drawObject(p, DiagonalLine, r.x(), center-2*lwArrow, center-r.x(), lwArrow);
drawObject(p, CrossDiagonalLine, r.x()+center, r.bottom()-1-2*lwArrow, center-r.x(), lwArrow);
if (lwArrow>1)
drawObject(p, HorizontalLine, center-(lwArrow-2), r.bottom()-(lwArrow-1)-2*lwArrow, (lwArrow-2)*2, lwArrow);
// Fall through to KeepBelowIcon intended!
}
case KeepBelowIcon:
{
int center = r.x()+r.width()/2;
// arrow
drawObject(p, DiagonalLine, r.x(), center, center-r.x(), lwArrow);
drawObject(p, CrossDiagonalLine, r.x()+center, r.bottom()-1, center-r.x(), lwArrow);
if (lwArrow>1)
drawObject(p, HorizontalLine, center-(lwArrow-2), r.bottom()-(lwArrow-1), (lwArrow-2)*2, lwArrow);
break;
}
case ShadeIcon:
{
drawObject(p, HorizontalLine, r.x(), r.y(), r.width(), lwTitleBar);
break;
}
case UnShadeIcon:
{
int lw1 = 1;
int lw2 = 1;
if (r.width() > 16) {
lw1 = 4;
lw2 = 2;
} else if (r.width() > 7) {
lw1 = 2;
lw2 = 1;
}
int h = qMax( (r.width()/2), (lw1+2*lw2) );
// horizontal bars
drawObject(p, HorizontalLine, r.x(), r.y(), r.width(), lw1);
drawObject(p, HorizontalLine, r.x(), r.x()+h-(lw2-1), r.width(), lw2);
// vertical bars
drawObject(p, VerticalLine, r.x(), r.y(), h, lw2);
drawObject(p, VerticalLine, r.right()-(lw2-1), r.y(), h, lw2);
break;
}
default:
break;
}
p.end();
return image;
}
void PlastikButtonProvider::drawObject(QPainter &p, Object object, int x, int y, int length, int lineWidth)
{
switch(object) {
case DiagonalLine:
if (lineWidth <= 1) {
for (int i = 0; i < length; ++i) {
p.drawPoint(x+i,y+i);
}
} else if (lineWidth <= 2) {
for (int i = 0; i < length; ++i) {
p.drawPoint(x+i,y+i);
}
for (int i = 0; i < (length-1); ++i) {
p.drawPoint(x+1+i,y+i);
p.drawPoint(x+i,y+1+i);
}
} else {
for (int i = 1; i < (length-1); ++i) {
p.drawPoint(x+i,y+i);
}
for (int i = 0; i < (length-1); ++i) {
p.drawPoint(x+1+i,y+i);
p.drawPoint(x+i,y+1+i);
}
for (int i = 0; i < (length-2); ++i) {
p.drawPoint(x+2+i,y+i);
p.drawPoint(x+i,y+2+i);
}
}
break;
case CrossDiagonalLine:
if (lineWidth <= 1) {
for (int i = 0; i < length; ++i) {
p.drawPoint(x+i,y-i);
}
} else if (lineWidth <= 2) {
for (int i = 0; i < length; ++i) {
p.drawPoint(x+i,y-i);
}
for (int i = 0; i < (length-1); ++i) {
p.drawPoint(x+1+i,y-i);
p.drawPoint(x+i,y-1-i);
}
} else {
for (int i = 1; i < (length-1); ++i) {
p.drawPoint(x+i,y-i);
}
for (int i = 0; i < (length-1); ++i) {
p.drawPoint(x+1+i,y-i);
p.drawPoint(x+i,y-1-i);
}
for (int i = 0; i < (length-2); ++i) {
p.drawPoint(x+2+i,y-i);
p.drawPoint(x+i,y-2-i);
}
}
break;
case HorizontalLine:
for (int i = 0; i < lineWidth; ++i) {
p.drawLine(x,y+i, x+length-1, y+i);
}
break;
case VerticalLine:
for (int i = 0; i < lineWidth; ++i) {
p.drawLine(x+i,y, x+i, y+length-1);
}
break;
default:
break;
}
}
} // namespace

View file

@ -0,0 +1,60 @@
/********************************************************************
Copyright (C) 2012 Martin Gräßlin <mgraesslin@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, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_PLASTIK_BUTTON_H
#define KWIN_PLASTIK_BUTTON_H
#include <QDeclarativeImageProvider>
namespace KWin
{
class PlastikButtonProvider : public QDeclarativeImageProvider
{
public:
explicit PlastikButtonProvider();
virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize);
private:
enum ButtonIcon {
CloseIcon = 0,
MaxIcon,
MaxRestoreIcon,
MinIcon,
HelpIcon,
OnAllDesktopsIcon,
NotOnAllDesktopsIcon,
KeepAboveIcon,
NoKeepAboveIcon,
KeepBelowIcon,
NoKeepBelowIcon,
ShadeIcon,
UnShadeIcon,
NumButtonIcons
};
enum Object {
HorizontalLine,
VerticalLine,
DiagonalLine,
CrossDiagonalLine
};
QPixmap icon(ButtonIcon icon, int size, bool active, bool shadow);
void drawObject(QPainter &p, Object object, int x, int y, int length, int lineWidth);
};
} // namespace
#endif // KWIN_PLASTIK_BUTTON_H

View file

@ -0,0 +1,34 @@
/********************************************************************
Copyright (C) 2012 Martin Gräßlin <mgraesslin@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, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "plastikplugin.h"
#include "plastikbutton.h"
#include <QDeclarativeEngine>
Q_EXPORT_PLUGIN2(plastikplugin, PlastikPlugin)
void PlastikPlugin::registerTypes(const char *uri)
{
Q_UNUSED(uri)
}
void PlastikPlugin::initializeEngine(QDeclarativeEngine *engine, const char *uri)
{
Q_ASSERT(uri == QLatin1String("org.kde.kwin.decorations.plastik"));
engine->addImageProvider(QLatin1String("plastik"), new KWin::PlastikButtonProvider());
QDeclarativeExtensionPlugin::initializeEngine(engine, uri);
}
#include "plastikplugin.moc"

View file

@ -0,0 +1,30 @@
/********************************************************************
Copyright (C) 2012 Martin Gräßlin <mgraesslin@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, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef PLASTIK_PLUGIN_H
#define PLASTIK_PLUGIN_H
#include <QDeclarativeExtensionPlugin>
class PlastikPlugin : public QDeclarativeExtensionPlugin
{
Q_OBJECT
public:
virtual void registerTypes(const char *uri);
virtual void initializeEngine(QDeclarativeEngine *engine, const char *uri);
};
#endif // PLASTIK_PLUGIN_H

View file

@ -0,0 +1,4 @@
plugin plastikplugin
# we need to have at least one element of Qt is not able to find the plugin *shrug*
Foo 1.0 Foo.qml

View file

@ -0,0 +1,153 @@
/********************************************************************
Copyright (C) 2012 Martin Gräßlin <mgraesslin@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, see <http://www.gnu.org/licenses/>.
*********************************************************************/
import QtQuick 1.1
import org.kde.kwin.decoration 0.1
import org.kde.kwin.decorations.plastik 1.0
DecorationButton {
id: button
function colorize() {
var highlightColor = null;
if (button.pressed) {
if (button.buttonType == "X") {
highlightColor = colorHelper.foreground(decoration.active, ColorHelper.NegativeText);
} else {
highlightColor = options.titleBarColor;
}
highlightColor = colorHelper.shade(highlightColor, ColorHelper.ShadowShade);
highlightColor = colorHelper.multiplyAlpha(highlightColor, 0.3);
} else if (button.hovered) {
if (button.buttonType == "X") {
highlightColor = colorHelper.foreground(decoration.active, ColorHelper.NegativeText);
} else {
highlightColor = options.titleBarColor;
}
highlightColor = colorHelper.shade(highlightColor, ColorHelper.LightShade, Math.min(1.0, colorHelper.contrast + 0.4));
highlightColor = colorHelper.multiplyAlpha(highlightColor, 0.6);
}
if (highlightColor) {
button.surfaceTop = Qt.tint(button.baseSurfaceTop, highlightColor);
button.surfaceBottom = Qt.tint(button.baseSurfaceBottom, highlightColor);
highlightColor = colorHelper.multiplyAlpha(highlightColor, 0.4);
button.conturTop = Qt.tint(button.baseConturTop, highlightColor);
button.conturBottom = Qt.tint(button.baseConturBottom, highlightColor);
} else {
button.conturTop = button.baseConturTop;
button.conturBottom = button.baseConturBottom;
button.surfaceTop = button.baseSurfaceTop;
button.surfaceBottom = button.baseSurfaceBottom;
}
}
property real size
property color conturTop
property color conturBottom
property color surfaceTop
property color surfaceBottom
property color baseConturTop: colorHelper.shade(options.titleBarColor, ColorHelper.DarkShade, colorHelper.contrast - 0.4)
property color baseConturBottom: colorHelper.shade(options.titleBarColor, ColorHelper.MidShade)
property color baseSurfaceTop: colorHelper.shade(options.titleBarColor, ColorHelper.MidlightShade, colorHelper.contrast - 0.4)
property color baseSurfaceBottom: colorHelper.shade(options.titleBarColor, ColorHelper.LightShade, colorHelper.contrast - 0.4)
Behavior on conturTop {
ColorAnimation { duration: root.animationDuration }
}
Behavior on conturBottom {
ColorAnimation { duration: root.animationDuration }
}
Behavior on surfaceTop {
ColorAnimation { duration: root.animationDuration }
}
Behavior on surfaceBottom {
ColorAnimation { duration: root.animationDuration }
}
width: size
height: size
Rectangle {
radius: 2
smooth: true
anchors.fill: parent
gradient: Gradient {
GradientStop {
position: 0.0
color: button.conturTop
}
GradientStop {
position: 1.0
color: button.conturBottom
}
}
Rectangle {
radius: 2
smooth: true
anchors {
fill: parent
leftMargin: 1
rightMargin: 1
topMargin: 1
bottomMargin: 1
}
gradient: Gradient {
GradientStop {
position: 0.0
color: button.surfaceTop
}
GradientStop {
position: 1.0
color: button.surfaceBottom
}
}
}
}
Item {
property int imageWidth: button.width > 14 ? button.width - 2 * Math.floor(button.width/3.5) : button.width - 6
property int imageHeight: button.height > 14 ? button.height - 2 * Math.floor(button.height/3.5) : button.height - 6
property string source: "image://plastik/" + button.buttonType + "/" + decoration.active + "/" + ((buttonType == "A") ? decoration.maximized : button.toggled)
anchors.fill: parent
Image {
id: shadowImage
x: button.x + button.width / 2 - width / 2 + 1
y: button.y + button.height / 2 - height / 2 + 1
source: parent.source + "/true"
width: parent.imageWidth
height: parent.imageHeight
sourceSize.width: width
sourceSize.height: height
visible: !button.pressed
}
Image {
id: image
x: button.x + button.width / 2 - width / 2
y: button.y + button.height / 2 - height / 2 + (button.pressed ? 1 : 0)
source: parent.source
width: parent.imageWidth
height: parent.imageHeight
sourceSize.width: width
sourceSize.height: height
}
}
Component.onCompleted: {
colorize();
if (buttonType == "H") {
visible = decoration.providesContextHelp;
}
}
onHoveredChanged: colorize()
onPressedChanged: colorize()
Connections {
target: decoration
onActiveChanged: button.colorize()
}
}

View file

@ -0,0 +1,370 @@
/********************************************************************
Copyright (C) 2012 Martin Gräßlin <mgraesslin@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, see <http://www.gnu.org/licenses/>.
*********************************************************************/
import QtQuick 1.1
import org.kde.kwin.decoration 0.1
import org.kde.kwin.decorations.plastik 1.0
Decoration {
function readConfig() {
switch (decoration.readConfig("BorderSize", DecorationOptions.BorderNormal)) {
case DecorationOptions.BorderTiny:
root.borderSize = 3;
break;
case DecorationOptions.BorderLarge:
root.borderSize = 8;
break;
case DecorationOptions.BorderVeryLarge:
root.borderSize = 12;
break;
case DecorationOptions.BorderHuge:
root.borderSize = 18;
break;
case DecorationOptions.BorderVeryHuge:
root.borderSize = 27;
break;
case DecorationOptions.BorderOversized:
root.borderSize = 40;
break;
case DecorationOptions.BorderNormal: // fall through to default
default:
root.borderSize = 4;
break;
}
}
ColorHelper {
id: colorHelper
}
DecorationOptions {
id: options
deco: decoration
}
property alias buttonSize: titleRow.captionHeight
property color titleBarColor: options.titleBarColor
property int animationDuration: 150
Behavior on titleBarColor {
ColorAnimation {
duration: root.animationDuration
}
}
property int borderSize: 4
id: root
borderLeft: borderSize
borderRight: borderSize
borderTop: top.normalHeight
borderBottom: borderSize
borderLeftMaximized: 0
borderRightMaximized: 0
borderBottomMaximized: 0
borderTopMaximized: top.maximizedHeight
paddingLeft: 0
paddingRight: 0
paddingBottom: 0
paddingTop: 0
Rectangle {
color: root.titleBarColor
anchors {
fill: parent
}
border {
width: decoration.maximized ? 0 : 2
color: colorHelper.shade(root.titleBarColor, ColorHelper.DarkShade)
}
Rectangle {
id: borderLeft
anchors {
left: parent.left
top: parent.top
bottom: parent.bottom
leftMargin: 1
bottomMargin: 1
topMargin: 1
}
visible: !decoration.maximized
width: root.borderLeft
color: root.titleBarColor
Rectangle {
width: 1
anchors {
left: parent.left
top: parent.top
bottom: parent.bottom
}
color: colorHelper.shade(root.titleBarColor, ColorHelper.LightShade, colorHelper.contrast - (decoration.active ? 0.4 : 0.8))
}
}
Rectangle {
id: borderRight
anchors {
right: parent.right
top: parent.top
bottom: parent.bottom
rightMargin: 1
bottomMargin: 1
topMargin: 1
}
visible: !decoration.maximzied
width: root.borderRight -1
color: root.titleBarColor
Rectangle {
width: 1
anchors {
bottom: parent.bottom
top: parent.top
}
x: parent.x + parent.width - 1
color: colorHelper.shade(root.titleBarColor, ColorHelper.DarkShade, colorHelper.contrast - (decoration.active ? 0.4 : 0.8))
}
}
Rectangle {
id: borderBottom
anchors {
left: parent.right
right: parent.left
bottom: parent.bottom
leftMargin: 1
rightMargin: 1
}
height: root.borderBottom
visible: !decoration.maximzied
color: root.titleBarColor
Rectangle {
height: 1
anchors {
left: parent.left
right: parent.right
}
y: parent.y + parent.height - 1
color: colorHelper.shade(root.titleBarColor, ColorHelper.DarkShade, colorHelper.contrast - (decoration.active ? 0.4 : 0.8))
}
}
Rectangle {
id: top
property int topMargin: 1
property real normalHeight: titleRow.normalHeight + topMargin + 1
property real maximizedHeight: titleRow.maximizedHeight
height: decoration.maximized ? maximizedHeight : normalHeight
anchors {
left: parent.left
right: parent.right
top: parent.top
topMargin: decoration.maximized ? 0 : top.topMargin
leftMargin: decoration.maximized ? 0 : 2
rightMargin: decoration.maximized ? 0 : 2
}
gradient: Gradient {
id: topGradient
GradientStop {
position: 0.0
color: colorHelper.shade(root.titleBarColor, ColorHelper.MidlightShade, colorHelper.contrast - 0.4)
}
GradientStop {
id: middleGradientStop
position: 4.0/(decoration.maximized ? top.maximizedHeight : top.normalHeight)
color: colorHelper.shade(root.titleBarColor, ColorHelper.MidShade, colorHelper.contrast - 0.4)
}
GradientStop {
position: 1.0
color: root.titleBarColor
}
}
Rectangle {
height: 1
anchors {
top: top.top
left: top.left
right: top.right
}
visible: !decoration.maximized
color: colorHelper.shade(root.titleBarColor, ColorHelper.LightShade, colorHelper.contrast - (decoration.active ? 0.4 : 0.8))
}
MouseArea {
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
anchors.fill: parent
onDoubleClicked: decoration.titlebarDblClickOperation()
onPressed: {
if (mouse.button == Qt.LeftButton) {
mouse.accepted = false;
} else {
decoration.titlePressed(mouse.button, mouse.buttons);
}
}
onReleased: decoration.titleReleased(mouse.button, mouse.buttons)
}
Item {
id: titleRow
property real captionHeight: caption.implicitHeight + 4
property int topMargin: 4
property int bottomMargin: 2
property real normalHeight: captionHeight + bottomMargin + topMargin
property real maximizedHeight: captionHeight + bottomMargin
anchors {
left: parent.left
right: parent.right
top: parent.top
topMargin: decoration.maximized ? 0 : titleRow.topMargin
leftMargin: decoration.maximized ? 0 : 6
rightMargin: decoration.maximized ? 0 : 6
bottomMargin: titleRow.bottomMargin
}
ButtonGroup {
id: leftButtonGroup
spacing: 1
explicitSpacer: root.buttonSize
menuButton: menuButtonComponent
minimizeButton: minimizeButtonComponent
maximizeButton: maximizeButtonComponent
keepBelowButton: keepBelowButtonComponent
keepAboveButton: keepAboveButtonComponent
helpButton: helpButtonComponent
shadeButton: shadeButtonComponent
allDesktopsButton: stickyButtonComponent
closeButton: closeButtonComponent
buttons: options.titleButtonsLeft
anchors {
top: parent.top
left: parent.left
}
}
Text {
id: caption
anchors {
top: parent.top
left: leftButtonGroup.right
right: rightButtonGroup.left
rightMargin: 5
leftMargin: 5
}
color: options.fontColor
Behavior on color {
ColorAnimation { duration: root.animationDuration }
}
text: decoration.caption
font: options.titleFont
style: Text.Raised
styleColor: colorHelper.shade(color, ColorHelper.ShadowShade)
elide: Text.ElideMiddle
}
ButtonGroup {
id: rightButtonGroup
spacing: 1
explicitSpacer: root.buttonSize
menuButton: menuButtonComponent
minimizeButton: minimizeButtonComponent
maximizeButton: maximizeButtonComponent
keepBelowButton: keepBelowButtonComponent
keepAboveButton: keepAboveButtonComponent
helpButton: helpButtonComponent
shadeButton: shadeButtonComponent
allDesktopsButton: stickyButtonComponent
closeButton: closeButtonComponent
buttons: options.titleButtonsRight
anchors {
top: parent.top
right: parent.right
}
}
}
}
Rectangle {
id: innerBorder
anchors {
fill: parent
leftMargin: root.borderLeft - 1
rightMargin: root.borderRight
topMargin: root.borderTop - 1
bottomMargin: root.borderBottom
}
border {
width: 1
color: colorHelper.shade(root.titleBarColor, ColorHelper.MidShade)
}
color: root.titleBarColor
}
}
Component {
id: maximizeButtonComponent
PlastikButton {
buttonType: "A"
size: root.buttonSize
}
}
Component {
id: keepBelowButtonComponent
PlastikButton {
buttonType: "B"
size: root.buttonSize
}
}
Component {
id: keepAboveButtonComponent
PlastikButton {
buttonType: "F"
size: root.buttonSize
}
}
Component {
id: helpButtonComponent
PlastikButton {
buttonType: "H"
size: root.buttonSize
}
}
Component {
id: minimizeButtonComponent
PlastikButton {
buttonType: "I"
size: root.buttonSize
}
}
Component {
id: shadeButtonComponent
PlastikButton {
buttonType: "L"
size: root.buttonSize
}
}
Component {
id: stickyButtonComponent
PlastikButton {
buttonType: "S"
size: root.buttonSize
}
}
Component {
id: closeButtonComponent
PlastikButton {
buttonType: "X"
size: root.buttonSize
}
}
Component {
id: menuButtonComponent
MenuButton {
width: root.buttonSize
height: root.buttonSize
}
}
Component.onCompleted: readConfig()
Connections {
target: decoration
onConfigChanged: readConfig()
}
}

View file

@ -0,0 +1,15 @@
[Desktop Entry]
Name=Plastik QML
Comment=The classic theme known from KDE 3
X-Plasma-MainScript=ui/main.qml
X-KDE-PluginInfo-Author=Martin Gräßlin
X-KDE-PluginInfo-Email=mgraesslin@kde.org
X-KDE-PluginInfo-Name=kwin4_decoration_qml_plastik
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-ServiceTypes=KWin/Decoration
Type=Service