diff options
author | David Edmundson <davidedmundson@kde.org> | 2014-01-12 20:31:53 +0100 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@digia.com> | 2014-01-12 20:45:37 +0100 |
commit | 48aff7a21dbf9021072d4ed4d2eb702a0fe2941c (patch) | |
tree | d4a6db4896218fe898956e0f7f3921c09ee0153c | |
parent | 8cfe8d2104baa9224586b5f087cb2f12ec74eea3 (diff) | |
download | qtquickcontrols-48aff7a21dbf9021072d4ed4d2eb702a0fe2941c.tar.gz |
Add a Desktop style for Calendar component
Calendar was hardcoded to the base style. This patch changes it to use
the newly created Desktop API which should match QCalendarWidget
Change-Id: Icd34ce781b535cdb5ca6e898626281e1958a7704
Reviewed-by: Mitch Curtis <mitch.curtis@digia.com>
-rw-r--r-- | src/controls/Calendar.qml | 2 | ||||
-rw-r--r-- | src/controls/Styles/Desktop/CalendarStyle.qml | 165 | ||||
-rw-r--r-- | src/controls/Styles/styles.pri | 1 |
3 files changed, 167 insertions, 1 deletions
diff --git a/src/controls/Calendar.qml b/src/controls/Calendar.qml index 779b8b8e..09d28f92 100644 --- a/src/controls/Calendar.qml +++ b/src/controls/Calendar.qml @@ -207,7 +207,7 @@ Control { */ signal escapePressed - style: Qt.createComponent(/*Settings.style*/"Styles/Base" + "/CalendarStyle.qml", calendar) + style: Qt.createComponent(Settings.style + "/CalendarStyle.qml", calendar) Keys.forwardTo: [view] diff --git a/src/controls/Styles/Desktop/CalendarStyle.qml b/src/controls/Styles/Desktop/CalendarStyle.qml new file mode 100644 index 00000000..cb1f9dc7 --- /dev/null +++ b/src/controls/Styles/Desktop/CalendarStyle.qml @@ -0,0 +1,165 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** +** Contact: http://www.qt-project.org/legal +** +** Copyright (C) 2014 by David Edmundson (davidedmundson@kde.org) * +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.1 +import QtQuick.Controls 1.1 +import QtQuick.Controls.Private 1.0 + +Style { + id: calendarStyle + + readonly property int weeksToShow: 6 + + readonly property real navigationBarHeight: 40 + + readonly property real cellWidth: control.width % 2 == 0 + ? control.width / DateUtils.daysInAWeek + : Math.floor(control.width / DateUtils.daysInAWeek) + + readonly property real cellHeight: {control.height - navigationBarHeight % 2 == 0 + ? (parent.height - navigationBarHeight) / (weeksToShow + 1) + : Math.floor((control.height - navigationBarHeight) / (weeksToShow + 1)) + } + + property Calendar control: __control + + property Component background: Rectangle { + color: __syspal.base + } + + property Component navigationBar: Item { + visible: control.navigationBarVisible + anchors.fill: parent + + Rectangle { + anchors.fill: parent + color: __syspal.highlight + } + + KeyNavigation.tab: previousMonth + + Button { + id: previousMonth + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + anchors.leftMargin: (parent.height - height) / 2 + iconName: "go-previous-view" + + onClicked: control.previousMonth() + } + Text { + id: dateText + text: control.selectedDateText + anchors.centerIn: parent + } + Button { + id: nextMonth + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + anchors.rightMargin: (parent.height - height) / 2 + iconName: "go-next-view" + + onClicked: control.nextMonth() + } + } + + property Component dateDelegate: Rectangle { + id: dayDelegate + color: cellDate !== undefined && isCurrentItem ? __syspal.highlight : __syspal.base + + Text { + SystemPalette { + id: pal + colorGroup: cellDate.getMonth() === control.selectedDate.getMonth() ? SystemPalette.Active : SystemPalette.Disabled + } + id: dayDelegateText + text: cellDate.getDate() + anchors.centerIn: parent + color: isCurrentItem ? pal.highlightedText : pal.text + } + } + + property Component headerDelegate: Row { + id: headerRow + Repeater { + id: repeater + model: CalendarHeaderModel { locale: control.locale } + Item { + width: calendarStyle.cellWidth + height: calendarStyle.cellHeight + Rectangle { + color: __syspal.base + anchors.fill: parent + Text { + text: DateUtils.dayNameFromDayOfWeek(control.locale, + control.dayOfWeekFormat, dayOfWeek) + anchors.centerIn: parent + } + } + } + } + } + + property Component panel: Item { + anchors.fill: parent + implicitWidth: 250 + implicitHeight: 250 + + property alias navigationBarItem: navigationBarLoader.item + + Loader { + id: backgroundLoader + anchors.fill: parent + sourceComponent: background + } + + Loader { + id: navigationBarLoader + anchors.left: parent.left + anchors.right: parent.right + anchors.top: parent.top + height: calendarStyle.navigationBarHeight + sourceComponent: navigationBar + } + } +} diff --git a/src/controls/Styles/styles.pri b/src/controls/Styles/styles.pri index a062edc4..ae15eedb 100644 --- a/src/controls/Styles/styles.pri +++ b/src/controls/Styles/styles.pri @@ -32,6 +32,7 @@ STYLES_QML_FILES += \ $$PWD/Desktop/BusyIndicatorStyle.qml \ $$PWD/Desktop/CheckBoxStyle.qml \ $$PWD/Desktop/ComboBoxStyle.qml \ + $$PWD/Desktop/CalendarStyle.qml \ $$PWD/Desktop/FocusFrameStyle.qml \ $$PWD/Desktop/GroupBoxStyle.qml \ $$PWD/Desktop/MenuBarStyle.qml \ |