• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kde-runtime API Reference
  • KDE Home
  • Contact Us
 

PlasmaComponents

  • sources
  • kde-4.14
  • kde-runtime
  • plasma
  • declarativeimports
  • plasmacomponents
  • qml
  • private
DualStateButton.qml
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2011 by Daker Fernandes Pinheiro <dakerfp@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Library General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
20 import QtQuick 1.0
21 import org.kde.plasma.core 0.1 as PlasmaCore
22 
27 Item {
28  id: dualButton
29 
30  // Common API
34  property bool checked
35 
41  property alias pressed: mouseArea.pressed
42 
47  signal clicked()
48 
49  // Plasma API
53  property alias text: label.text // TODO: Not yet part of the common API
54  property alias view: surfaceLoader.sourceComponent
55  property alias shadow: shadowLoader.sourceComponent
56 
57  width: surfaceLoader.width + label.paintedWidth
58  height: theme.defaultFont.mSize.height*1.6
59  // TODO: needs to define if there will be specific graphics for
60  // disabled buttons
61  opacity: dualButton.enabled ? 1.0 : 0.5
62 
63  function released() {
64  if (dualButton.enabled) {
65  dualButton.checked = !dualButton.checked;
66  dualButton.clicked();
67  }
68  }
69 
70  Keys.onReleased: {
71  if(event.key == Qt.Key_Space ||
72  event.key == Qt.Key_Return)
73  released();
74  }
75 
76  Loader {
77  id: shadowLoader
78  anchors.fill: surfaceLoader
79  state: (dualButton.enabled && (dualButton.activeFocus || mouseArea.containsMouse)) ? "hover" : "shadow"
80  }
81 
82  Loader {
83  id: surfaceLoader
84 
85  anchors {
86  verticalCenter: parent.verticalCenter
87  left: text ? parent.left : undefined
88  horizontalCenter: text ? undefined : parent.horizontalCenter
89  }
90  }
91 
92  Text {
93  id: label
94 
95  text: dualButton.text
96  anchors {
97  top: parent.top
98  bottom: parent.bottom
99  left: surfaceLoader.right
100  right: parent.right
101  //FIXME: see how this margin will be set
102  leftMargin: height/4
103  }
104  color: theme.textColor
105  verticalAlignment: Text.AlignVCenter
106  }
107 
108  MouseArea {
109  id: mouseArea
110 
111  anchors.fill: parent
112  hoverEnabled: true
113 
114  onReleased: dualButton.released();
115  onPressed: dualButton.forceActiveFocus();
116  }
117 }
Item
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:08:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

PlasmaComponents

Skip menu "PlasmaComponents"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List

kde-runtime API Reference

Skip menu "kde-runtime API Reference"
  • KCMShell
  • KNotify
  • Plasma Runtime
  •     PlasmaCore
  •     DragAndDrop
  •     PlasmaComponents
  •     PlasmaExtraComponents
  •     QtExtraComponents

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal