| 
									
										
										
										
											2011-07-06 15:48:52 +00:00
										 |  |  | /************************************************************************** | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-01-26 18:33:46 +01:00
										 |  |  | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). | 
					
						
							| 
									
										
										
										
											2011-07-06 15:48:52 +00:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-11-02 15:59:12 +01:00
										 |  |  | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
					
						
							| 
									
										
										
										
											2011-07-06 15:48:52 +00:00
										 |  |  | ** | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** GNU Lesser General Public License Usage | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file may be used under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  | ** License version 2.1 as published by the Free Software Foundation and | 
					
						
							|  |  |  | ** appearing in the file LICENSE.LGPL included in the packaging of this file. | 
					
						
							|  |  |  | ** Please review the following information to ensure the GNU Lesser General | 
					
						
							|  |  |  | ** Public License version 2.1 requirements will be met: | 
					
						
							|  |  |  | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** In addition, as a special exception, Nokia gives you certain additional | 
					
						
							|  |  |  | ** rights. These rights are described in the Nokia Qt LGPL Exception | 
					
						
							|  |  |  | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Other Usage | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Alternatively, this file may be used in accordance with the terms and | 
					
						
							|  |  |  | ** conditions contained in a signed written agreement between you and Nokia. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** If you have questions regarding the use of this file, please contact | 
					
						
							| 
									
										
										
										
											2011-11-02 15:59:12 +01:00
										 |  |  | ** Nokia at qt-info@nokia.com. | 
					
						
							| 
									
										
										
										
											2011-07-06 15:48:52 +00:00
										 |  |  | ** | 
					
						
							|  |  |  | **************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-11 16:49:17 +01:00
										 |  |  | import QtQuick 1.0 | 
					
						
							|  |  |  | import "custom" as Components | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Item { | 
					
						
							|  |  |  |     id: scrollbar | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     property int orientation : Qt.Horizontal | 
					
						
							|  |  |  |     property alias minimumValue: slider.minimumValue | 
					
						
							|  |  |  |     property alias maximumValue: slider.maximumValue | 
					
						
							| 
									
										
										
										
											2011-07-12 15:51:27 +02:00
										 |  |  |     property int pageStep: styleitem.horizontal ? width : height | 
					
						
							|  |  |  |     property int singleStep: 20 | 
					
						
							| 
									
										
										
										
											2010-11-11 16:49:17 +01:00
										 |  |  |     property alias value: slider.value | 
					
						
							| 
									
										
										
										
											2011-07-12 15:51:27 +02:00
										 |  |  |     property bool scrollToClickposition: styleitem.styleHint("scrollToClickPosition") | 
					
						
							| 
									
										
										
										
											2010-11-11 16:49:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     width: orientation == Qt.Horizontal ? 200 : internal.scrollbarExtent | 
					
						
							|  |  |  |     height: orientation == Qt.Horizontal ? internal.scrollbarExtent : 200 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     onValueChanged: internal.updateHandle() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     MouseArea { | 
					
						
							|  |  |  |         id: internal | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         anchors.fill: parent | 
					
						
							| 
									
										
										
										
											2011-07-12 15:51:27 +02:00
										 |  |  |         property bool upPressed | 
					
						
							|  |  |  |         property bool downPressed | 
					
						
							|  |  |  |         property bool pageUpPressed | 
					
						
							|  |  |  |         property bool pageDownPressed | 
					
						
							| 
									
										
										
										
											2010-11-11 16:49:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         property bool autoincrement: false | 
					
						
							|  |  |  |         property int scrollbarExtent : styleitem.pixelMetric("scrollbarExtent"); | 
					
						
							| 
									
										
										
										
											2011-07-12 15:51:27 +02:00
										 |  |  |         property bool handlePressed | 
					
						
							| 
									
										
										
										
											2010-11-11 16:49:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // Update hover item
 | 
					
						
							|  |  |  |         onEntered: styleitem.activeControl = styleitem.hitTest(mouseX, mouseY) | 
					
						
							|  |  |  |         onExited: styleitem.activeControl = "none" | 
					
						
							|  |  |  |         onMouseXChanged: styleitem.activeControl = styleitem.hitTest(mouseX, mouseY) | 
					
						
							|  |  |  |         hoverEnabled: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-12 15:51:27 +02:00
										 |  |  |         property variant control | 
					
						
							|  |  |  |         property variant pressedX | 
					
						
							|  |  |  |         property variant pressedY | 
					
						
							|  |  |  |         property int oldPosition | 
					
						
							|  |  |  |         property int grooveSize | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-11 16:49:17 +01:00
										 |  |  |         Timer { | 
					
						
							| 
									
										
										
										
											2011-07-12 15:51:27 +02:00
										 |  |  |             running: internal.upPressed || internal.downPressed || internal.pageUpPressed || internal.pageDownPressed | 
					
						
							| 
									
										
										
										
											2010-11-11 16:49:17 +01:00
										 |  |  |             interval: 350 | 
					
						
							|  |  |  |             onTriggered: internal.autoincrement = true | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Timer { | 
					
						
							|  |  |  |             running: internal.autoincrement | 
					
						
							|  |  |  |             interval: 60 | 
					
						
							|  |  |  |             repeat: true | 
					
						
							| 
									
										
										
										
											2011-07-12 15:51:27 +02:00
										 |  |  |             onTriggered: internal.upPressed ? internal.decrement() : internal.downPressed ? internal.increment() : | 
					
						
							|  |  |  |                                                                      internal.pageUpPressed ? internal.decrementPage() : | 
					
						
							|  |  |  |                                                                                               internal.incrementPage() | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         onMousePositionChanged: { | 
					
						
							|  |  |  |             if (pressed && control === "handle") { | 
					
						
							|  |  |  |                 //slider.positionAtMaximum = grooveSize
 | 
					
						
							|  |  |  |                 if (!styleitem.horizontal) | 
					
						
							|  |  |  |                     slider.position = oldPosition + (mouseY - pressedY) | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                     slider.position = oldPosition + (mouseX - pressedX) | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2010-11-11 16:49:17 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         onPressed: { | 
					
						
							| 
									
										
										
										
											2011-07-12 15:51:27 +02:00
										 |  |  |             control = styleitem.hitTest(mouseX,mouseY) | 
					
						
							|  |  |  |             scrollToClickposition = styleitem.styleHint("scrollToClickPosition") | 
					
						
							|  |  |  |             grooveSize =  styleitem.horizontal? styleitem.subControlRect("groove").width - | 
					
						
							|  |  |  |                                                 styleitem.subControlRect("handle").width: | 
					
						
							|  |  |  |                                                     styleitem.subControlRect("groove").height - | 
					
						
							|  |  |  |                                                     styleitem.subControlRect("handle").height; | 
					
						
							|  |  |  |             if (control == "handle") { | 
					
						
							|  |  |  |                 pressedX = mouseX | 
					
						
							|  |  |  |                 pressedY = mouseY | 
					
						
							|  |  |  |                 oldPosition = slider.position | 
					
						
							|  |  |  |             } else if (control == "up") { | 
					
						
							|  |  |  |                 decrement(); | 
					
						
							| 
									
										
										
										
											2010-11-11 16:49:17 +01:00
										 |  |  |                 upPressed = true | 
					
						
							|  |  |  |             } else if (control == "down") { | 
					
						
							| 
									
										
										
										
											2011-07-12 15:51:27 +02:00
										 |  |  |                 increment(); | 
					
						
							| 
									
										
										
										
											2010-11-11 16:49:17 +01:00
										 |  |  |                 downPressed = true | 
					
						
							| 
									
										
										
										
											2011-07-12 15:51:27 +02:00
										 |  |  |             } else if (!scrollToClickposition){ | 
					
						
							|  |  |  |                 if (control == "upPage") { | 
					
						
							|  |  |  |                     decrementPage(); | 
					
						
							|  |  |  |                     pageUpPressed = true | 
					
						
							|  |  |  |                 } else if (control == "downPage") { | 
					
						
							|  |  |  |                     incrementPage(); | 
					
						
							|  |  |  |                     pageDownPressed = true | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 slider.position = styleitem.horizontal ? mouseX - handleRect.width/2 | 
					
						
							|  |  |  |                                                        : mouseY - handleRect.height/2 | 
					
						
							| 
									
										
										
										
											2010-11-11 16:49:17 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         onReleased: { | 
					
						
							|  |  |  |             autoincrement = false; | 
					
						
							| 
									
										
										
										
											2011-07-12 15:51:27 +02:00
										 |  |  |             upPressed = false; | 
					
						
							|  |  |  |             downPressed = false; | 
					
						
							|  |  |  |             pageUpPressed = false | 
					
						
							|  |  |  |             pageDownPressed = false | 
					
						
							|  |  |  |             control = "" | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         function incrementPage() { | 
					
						
							|  |  |  |             value += pageStep | 
					
						
							|  |  |  |             if (value > maximumValue) | 
					
						
							|  |  |  |                 value = maximumValue | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         function decrementPage() { | 
					
						
							|  |  |  |             value -= pageStep | 
					
						
							|  |  |  |             if (value < minimumValue) | 
					
						
							|  |  |  |                 value = minimumValue | 
					
						
							| 
									
										
										
										
											2010-11-11 16:49:17 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         function increment() { | 
					
						
							| 
									
										
										
										
											2011-07-12 15:51:27 +02:00
										 |  |  |             value += singleStep | 
					
						
							| 
									
										
										
										
											2010-11-11 16:49:17 +01:00
										 |  |  |             if (value > maximumValue) | 
					
						
							|  |  |  |                 value = maximumValue | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         function decrement() { | 
					
						
							| 
									
										
										
										
											2011-07-12 15:51:27 +02:00
										 |  |  |             value -= singleStep | 
					
						
							| 
									
										
										
										
											2010-11-11 16:49:17 +01:00
										 |  |  |             if (value < minimumValue) | 
					
						
							|  |  |  |                 value = minimumValue | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         QStyleItem { | 
					
						
							|  |  |  |             id: styleitem | 
					
						
							|  |  |  |             anchors.fill:parent | 
					
						
							|  |  |  |             elementType: "scrollbar" | 
					
						
							|  |  |  |             hover: activeControl != "none" | 
					
						
							|  |  |  |             activeControl: "none" | 
					
						
							| 
									
										
										
										
											2011-07-12 15:51:27 +02:00
										 |  |  |             sunken: internal.upPressed | internal.downPressed | 
					
						
							| 
									
										
										
										
											2010-11-11 16:49:17 +01:00
										 |  |  |             minimum: slider.minimumValue | 
					
						
							|  |  |  |             maximum: slider.maximumValue | 
					
						
							|  |  |  |             value: slider.value | 
					
						
							|  |  |  |             horizontal: orientation == Qt.Horizontal | 
					
						
							|  |  |  |             enabled: parent.enabled | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         property variant handleRect: Qt.rect(0,0,0,0) | 
					
						
							| 
									
										
										
										
											2011-07-12 15:51:27 +02:00
										 |  |  |         property variant grooveRect: Qt.rect(0,0,0,0) | 
					
						
							| 
									
										
										
										
											2010-11-11 16:49:17 +01:00
										 |  |  |         function updateHandle() { | 
					
						
							|  |  |  |             internal.handleRect = styleitem.subControlRect("handle") | 
					
						
							| 
									
										
										
										
											2011-07-12 15:51:27 +02:00
										 |  |  |             grooveRect = styleitem.subControlRect("groove"); | 
					
						
							| 
									
										
										
										
											2010-11-11 16:49:17 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-12 15:51:27 +02:00
										 |  |  |         RangeModel { | 
					
						
							| 
									
										
										
										
											2010-11-11 16:49:17 +01:00
										 |  |  |             id: slider | 
					
						
							| 
									
										
										
										
											2011-07-12 15:51:27 +02:00
										 |  |  |             minimumValue: 0.0 | 
					
						
							|  |  |  |             maximumValue: 1.0 | 
					
						
							|  |  |  |             value: 0 | 
					
						
							|  |  |  |             stepSize: 0.0 | 
					
						
							|  |  |  |             inverted: false | 
					
						
							|  |  |  |             positionAtMaximum: internal.grooveSize | 
					
						
							| 
									
										
										
										
											2010-11-11 16:49:17 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |