diff --git a/src/declarativeimports/plasmacomponents/qml/ComboBox.qml b/src/declarativeimports/plasmacomponents/qml/ComboBox.qml new file mode 100644 index 000000000..84354ad78 --- /dev/null +++ b/src/declarativeimports/plasmacomponents/qml/ComboBox.qml @@ -0,0 +1,33 @@ +/* +* Copyright (C) 2014 by David Edmundson +* +* 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 Library 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 2.010-1301, USA. +*/ + +import QtQuick.Controls 1.1 +import "styles" as Styles + +/** + * This is a combobox which uses the plasma theme. + * + * Properties are the same as the QtQuick Controls ComboBox component + */ +ComboBox { + activeFocusOnPress: true + + style: Styles.ComboBoxStyle{} + +} diff --git a/src/declarativeimports/plasmacomponents/qml/qmldir b/src/declarativeimports/plasmacomponents/qml/qmldir index abf7f7ca7..92eb28329 100644 --- a/src/declarativeimports/plasmacomponents/qml/qmldir +++ b/src/declarativeimports/plasmacomponents/qml/qmldir @@ -7,6 +7,7 @@ ButtonColumn 2.0 ButtonColumn.qml ButtonGroup 2.0 ButtonGroup.js ButtonRow 2.0 ButtonRow.qml CheckBox 2.0 CheckBox.qml +ComboBox 2.0 ComboBox.qml CommonDialog 2.0 CommonDialog.qml ContextMenu 2.0 ContextMenu.qml Dialog 2.0 Dialog.qml diff --git a/src/declarativeimports/plasmacomponents/qml/styles/ComboBoxStyle.qml b/src/declarativeimports/plasmacomponents/qml/styles/ComboBoxStyle.qml new file mode 100644 index 000000000..20caef62f --- /dev/null +++ b/src/declarativeimports/plasmacomponents/qml/styles/ComboBoxStyle.qml @@ -0,0 +1,131 @@ +/* +* Copyright (C) 2014 by David Edmundson +* +* 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 Library 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 2.010-1301, USA. +*/ + +import QtQuick 2.0 +import QtQuick.Controls.Styles 1.1 as QtQuickControlStyle + +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 2.0 as PlasmaComponents + +import "../private" as Private + +QtQuickControlStyle.ComboBoxStyle { + drowDownButtonWidth: units.iconSizes.small + + label: PlasmaComponents.Label { + text: control.currentText + elide: Text.ElideRight + verticalAlignment: Text.AlignTop + } + + background: Item { + + //size copied from Plasma Button + //for some reason the logic there is: + // maximum of + // the calculated height + frame margins + // Or 1.6 letters tall no matter how big the margins are + + //QtQuickControls tries to be helpful and adds on the margin sizes for us + //to compensate, we have to subtract our margins here in order to do the max 1.6 lines high tall feature + implicitHeight: Math.max(theme.mSize(theme.defaultFont).height*1.6 - surfaceNormal.margins.top - surfaceNormal.margins.bottom, + theme.mSize(theme.defaultFont).height) + + implicitWidth: theme.mSize(theme.defaultFont).width*12 + + Private.ButtonShadow { + anchors.fill: parent + state: { + if (control.pressed) { + return "hidden" + } else if (control.hovered) { + return "hover" + } else if (control.activeFocus) { + return "focus" + } else { + return "shadow" + } + } + } + + + //This code is duplicated here and Button and ToolButton + //maybe we can make an AbstractButton class? + PlasmaCore.FrameSvgItem { + id: surfaceNormal + anchors.fill: parent + imagePath: "widgets/button" + prefix: "normal" + } + + PlasmaCore.FrameSvgItem { + id: surfacePressed + anchors.fill: parent + imagePath: "widgets/button" + prefix: "pressed" + opacity: 0 + } + + state: control.pressed ? "pressed" : "normal" + + states: [ + State { name: "normal" }, + State { name: "pressed" + PropertyChanges { + target: surfaceNormal + opacity: 0 + } + PropertyChanges { + target: surfacePressed + opacity: 1 + } + } + ] + + transitions: [ + Transition { + to: "normal" + //Cross fade from pressed to normal + ParallelAnimation { + NumberAnimation { target: surfaceNormal; property: "opacity"; to: 1; duration: 100 } + NumberAnimation { target: surfacePressed; property: "opacity"; to: 0; duration: 100 } + } + } + ] + + PlasmaCore.SvgItem { + width: drowDownButtonWidth + height: drowDownButtonWidth + anchors { + right: parent.right + rightMargin: surfaceNormal.margins.right + verticalCenter: parent.verticalCenter + } + svg: PlasmaCore.Svg { imagePath: "widgets/arrows" } + elementId: "down-arrow" + } + + Component.onCompleted: { + padding.top = surfaceNormal.margins.top + padding.left = surfaceNormal.margins.left + padding.right = surfaceNormal.margins.right + padding.bottom = surfaceNormal.margins.bottom + } + } + }