1/**************************************************************************** 2** 3** Copyright (C) 2016 The Qt Company Ltd. 4** Contact: https://www.qt.io/licensing/ 5** 6** This file is part of the Qt Quick Controls module of the Qt Toolkit. 7** 8** $QT_BEGIN_LICENSE:BSD$ 9** Commercial License Usage 10** Licensees holding valid commercial Qt licenses may use this file in 11** accordance with the commercial license agreement provided with the 12** Software or, alternatively, in accordance with the terms contained in 13** a written agreement between you and The Qt Company. For licensing terms 14** and conditions see https://www.qt.io/terms-conditions. For further 15** information use the contact form at https://www.qt.io/contact-us. 16** 17** BSD License Usage 18** Alternatively, you may use this file under the terms of the BSD license 19** as follows: 20** 21** "Redistribution and use in source and binary forms, with or without 22** modification, are permitted provided that the following conditions are 23** met: 24** * Redistributions of source code must retain the above copyright 25** notice, this list of conditions and the following disclaimer. 26** * Redistributions in binary form must reproduce the above copyright 27** notice, this list of conditions and the following disclaimer in 28** the documentation and/or other materials provided with the 29** distribution. 30** * Neither the name of The Qt Company Ltd nor the names of its 31** contributors may be used to endorse or promote products derived 32** from this software without specific prior written permission. 33** 34** 35** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46** 47** $QT_END_LICENSE$ 48** 49****************************************************************************/ 50 51import QtQuick 2.1 52import QtQuick.Controls 1.1 53import QtQuick.Controls.Private 1.0 54 55/*! 56 \qmltype SpinBoxStyle 57 \inqmlmodule QtQuick.Controls.Styles 58 \since 5.2 59 \ingroup controlsstyling 60 \brief Provides custom styling for SpinBox 61 62 Example: 63 \qml 64 SpinBox { 65 style: SpinBoxStyle{ 66 background: Rectangle { 67 implicitWidth: 100 68 implicitHeight: 20 69 border.color: "gray" 70 radius: 2 71 } 72 } 73 } 74 \endqml 75*/ 76 77Style { 78 id: spinboxStyle 79 80 /*! The \l SpinBox attached to this style. */ 81 readonly property SpinBox control: __control 82 83 /*! \internal */ 84 property var __syspal: SystemPalette { 85 colorGroup: control.enabled ? 86 SystemPalette.Active : SystemPalette.Disabled 87 } 88 89 /*! The content margins of the text field. */ 90 padding { top: 1 ; left: Math.round(TextSingleton.implicitHeight/2) ; right: Math.round(TextSingleton.implicitHeight) ; bottom: 0 } 91 92 /*! \qmlproperty enumeration horizontalAlignment 93 94 This property defines the default text aligment. 95 96 The supported values are: 97 \list 98 \li Qt.AlignLeft 99 \li Qt.AlignHCenter 100 \li Qt.AlignRight 101 \endlist 102 103 The default value is Qt.AlignRight 104 */ 105 property int horizontalAlignment: Qt.AlignRight 106 107 /*! The text color. */ 108 property color textColor: __syspal.text 109 110 /*! The text highlight color, used behind selections. */ 111 property color selectionColor: __syspal.highlight 112 113 /*! The highlighted text color, used in selections. */ 114 property color selectedTextColor: __syspal.highlightedText 115 116 /*! 117 \qmlproperty enumeration renderType 118 119 Override the default rendering type for the control. 120 121 Supported render types are: 122 \list 123 \li Text.QtRendering 124 \li Text.NativeRendering - the default 125 \endlist 126 127 \sa Text::renderType 128 */ 129 property int renderType: Text.NativeRendering 130 131 /*! The button used to increment the value. */ 132 property Component incrementControl: Item { 133 implicitWidth: padding.right 134 Image { 135 source: "images/arrow-up.png" 136 anchors.centerIn: parent 137 anchors.verticalCenterOffset: 1 138 opacity: control.enabled ? (styleData.upPressed ? 1 : 0.6) : 0.5 139 } 140 } 141 142 /*! The button used to decrement the value. */ 143 property Component decrementControl: Item { 144 implicitWidth: padding.right 145 Image { 146 source: "images/arrow-down.png" 147 anchors.centerIn: parent 148 anchors.verticalCenterOffset: -2 149 opacity: control.enabled ? (styleData.downPressed ? 1 : 0.6) : 0.5 150 } 151 } 152 153 /*! The background of the SpinBox. */ 154 property Component background: Item { 155 implicitHeight: Math.max(25, Math.round(TextSingleton.implicitHeight * 1.2)) 156 implicitWidth: styleData.contentWidth + 26 157 Rectangle { 158 anchors.fill: parent 159 anchors.bottomMargin: -1 160 color: "#44ffffff" 161 radius: baserect.radius 162 } 163 Rectangle { 164 id: baserect 165 gradient: Gradient { 166 GradientStop {color: "#eee" ; position: 0} 167 GradientStop {color: "#fff" ; position: 0.1} 168 GradientStop {color: "#fff" ; position: 1} 169 } 170 radius: TextSingleton.implicitHeight * 0.16 171 anchors.fill: parent 172 border.color: control.activeFocus ? "#47b" : "#999" 173 } 174 } 175 176 /*! \internal */ 177 property Component panel: Item { 178 id: styleitem 179 implicitWidth: backgroundLoader.implicitWidth 180 implicitHeight: backgroundLoader.implicitHeight 181 182 property color foregroundColor: spinboxStyle.textColor 183 property color selectionColor: spinboxStyle.selectionColor 184 property color selectedTextColor: spinboxStyle.selectedTextColor 185 186 property var margins: spinboxStyle.padding 187 188 property rect upRect: Qt.rect(width - incrementControlLoader.implicitWidth, 0, incrementControlLoader.implicitWidth, height / 2 + 1) 189 property rect downRect: Qt.rect(width - decrementControlLoader.implicitWidth, height / 2, decrementControlLoader.implicitWidth, height / 2) 190 191 property int horizontalAlignment: spinboxStyle.horizontalAlignment 192 property int verticalAlignment: Qt.AlignVCenter 193 194 Loader { 195 id: backgroundLoader 196 anchors.fill: parent 197 sourceComponent: background 198 } 199 200 Loader { 201 id: incrementControlLoader 202 x: upRect.x 203 y: upRect.y 204 width: upRect.width 205 height: upRect.height 206 sourceComponent: incrementControl 207 } 208 209 Loader { 210 id: decrementControlLoader 211 x: downRect.x 212 y: downRect.y 213 width: downRect.width 214 height: downRect.height 215 sourceComponent: decrementControl 216 } 217 } 218} 219