summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2017-05-29 14:57:07 +0200
committerMitch Curtis <mitch.curtis@qt.io>2017-06-16 12:15:29 +0000
commitd13e4db9d74aefc0bd08ca946b789155a11361fb (patch)
treebd99878b498975662042c51a0ee7b9fdaf9245c1
parent9f085b889524a80d4064d6ac01dbdc817bb31060 (diff)
downloadqtquickcontrols-d13e4db9d74aefc0bd08ca946b789155a11361fb.tar.gz
Calendar: make locale property public
This is useful to set a locale on a specific calendar, as opposed to using the application-wide default. plugins.qmltypes was also updated. [ChangeLog][Calendar] Added locale property, which affects which day is shown as the first day of the week, as well as date and day name localization. Task-number: QTBUG-60217 Change-Id: I113298a3f3b6dd407d26f3f55ed6973e73ab6a4c Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
-rw-r--r--src/controls/Calendar.qml25
-rw-r--r--src/controls/Styles/Android/CalendarStyle.qml2
-rw-r--r--src/controls/Styles/Base/CalendarStyle.qml8
-rw-r--r--src/controls/plugin.cpp1
-rw-r--r--src/extras/Styles/Flat/CalendarStyle.qml4
-rw-r--r--tests/auto/controls/data/tst_calendar.qml18
6 files changed, 33 insertions, 25 deletions
diff --git a/src/controls/Calendar.qml b/src/controls/Calendar.qml
index 96896480..b18a8b47 100644
--- a/src/controls/Calendar.qml
+++ b/src/controls/Calendar.qml
@@ -37,8 +37,8 @@
**
****************************************************************************/
-import QtQuick 2.2
-import QtQuick.Controls 1.2
+import QtQuick 2.9
+import QtQuick.Controls 1.5
import QtQuick.Controls.Styles 1.1
import QtQuick.Controls.Private 1.0
@@ -195,20 +195,27 @@ Control {
property int dayOfWeekFormat: Locale.ShortFormat
/*!
- The locale that this calendar should use to display itself.
+ \qmlproperty object Calendar::locale
+ \since QtQuick.Controls 1.6
- Affects how dates and day names are localized, as well as which
- day is considered the first in a week.
+ This property controls the locale that this calendar uses to display
+ itself.
- To set an Australian locale, for example:
+ The locale affects how dates and day names are localized, as well as
+ which day is considered the first in a week.
+
+ The following example sets an Australian locale:
\code
locale: Qt.locale("en_AU")
\endcode
- The default locale is \c Qt.locale().
+ The default value is equivalent to \c Qt.locale().
*/
- property var __locale: Qt.locale()
+ property var locale: Qt.locale()
+
+ // left for compatibility reasons; can be removed in next minor version/Qt 6
+ property alias __locale: calendar.locale
/*!
\internal
@@ -217,7 +224,7 @@ Control {
populate the dates available to the user.
*/
property CalendarModel __model: CalendarModel {
- locale: calendar.__locale
+ locale: calendar.locale
// TODO: don't set the hour when QTBUG-56787 is fixed
visibleDate: new Date(visibleYear, visibleMonth, 1, 12)
diff --git a/src/controls/Styles/Android/CalendarStyle.qml b/src/controls/Styles/Android/CalendarStyle.qml
index 449cc497..52b02bff 100644
--- a/src/controls/Styles/Android/CalendarStyle.qml
+++ b/src/controls/Styles/Android/CalendarStyle.qml
@@ -83,7 +83,7 @@ CalendarStyle {
LabelStyle {
id: dayOfWeek
anchors.centerIn: parent
- text: control.__locale.dayName(styleData.dayOfWeek, control.dayOfWeekFormat)
+ text: control.locale.dayName(styleData.dayOfWeek, control.dayOfWeekFormat)
focused: control.activeFocus
window_focused: control.Window.active
styleDef: AndroidStyle.styleDef.calendarViewStyle.CalendarView_weekDayTextAppearance
diff --git a/src/controls/Styles/Base/CalendarStyle.qml b/src/controls/Styles/Base/CalendarStyle.qml
index 862c5f43..12cb3a4b 100644
--- a/src/controls/Styles/Base/CalendarStyle.qml
+++ b/src/controls/Styles/Base/CalendarStyle.qml
@@ -320,7 +320,7 @@ Style {
color: gridVisible ? "#fcfcfc" : "transparent"
implicitHeight: Math.round(TextSingleton.implicitHeight * 2.25)
Label {
- text: control.__locale.dayName(styleData.dayOfWeek, control.dayOfWeekFormat)
+ text: control.locale.dayName(styleData.dayOfWeek, control.dayOfWeekFormat)
anchors.centerIn: parent
}
}
@@ -397,8 +397,8 @@ Style {
active: control.navigationBarVisible
property QtObject styleData: QtObject {
- readonly property string title: control.__locale.standaloneMonthName(control.visibleMonth)
- + new Date(control.visibleYear, control.visibleMonth, 1).toLocaleDateString(control.__locale, " yyyy")
+ readonly property string title: control.locale.standaloneMonthName(control.visibleMonth)
+ + new Date(control.visibleYear, control.visibleMonth, 1).toLocaleDateString(control.locale, " yyyy")
}
}
@@ -413,7 +413,7 @@ Style {
Repeater {
id: repeater
model: CalendarHeaderModel {
- locale: control.__locale
+ locale: control.locale
}
Loader {
id: dayOfWeekDelegateLoader
diff --git a/src/controls/plugin.cpp b/src/controls/plugin.cpp
index 2abd906e..257b1381 100644
--- a/src/controls/plugin.cpp
+++ b/src/controls/plugin.cpp
@@ -124,6 +124,7 @@ static const struct {
{ "TextArea", 1, 5 },
{ "TreeView", 1, 5 },
+ { "Calendar", 1, 6 },
{ "Slider", 1, 6 }
};
diff --git a/src/extras/Styles/Flat/CalendarStyle.qml b/src/extras/Styles/Flat/CalendarStyle.qml
index 2598ce78..ece0548d 100644
--- a/src/extras/Styles/Flat/CalendarStyle.qml
+++ b/src/extras/Styles/Flat/CalendarStyle.qml
@@ -190,7 +190,7 @@ Base.CalendarStyle {
Label {
text: localeDayName.length == 0 || localeDayName.length > 1
- ? control.__locale.dayName(styleData.dayOfWeek, Locale.ShortFormat)[0]
+ ? control.locale.dayName(styleData.dayOfWeek, Locale.ShortFormat)[0]
: localeDayName
color: !control.enabled ? FlatStyle.disabledColor : FlatStyle.styleColor
opacity: !control.enabled ? FlatStyle.disabledOpacity : 1
@@ -202,7 +202,7 @@ Base.CalendarStyle {
font.pixelSize: control.height * __headerFontRatio
renderType: FlatStyle.__renderType
- property string localeDayName: control.__locale.dayName(styleData.dayOfWeek, Locale.NarrowFormat)
+ property string localeDayName: control.locale.dayName(styleData.dayOfWeek, Locale.NarrowFormat)
}
}
}
diff --git a/tests/auto/controls/data/tst_calendar.qml b/tests/auto/controls/data/tst_calendar.qml
index 1185aca9..814a361a 100644
--- a/tests/auto/controls/data/tst_calendar.qml
+++ b/tests/auto/controls/data/tst_calendar.qml
@@ -132,7 +132,7 @@ Item {
compare(calendar.selectedDate, new Date(new Date().setHours(0, 0, 0, 0)));
compare(calendar.frameVisible, true);
compare(calendar.dayOfWeekFormat, Locale.ShortFormat);
- compare(calendar.__locale, Qt.locale());
+ compare(calendar.locale, Qt.locale());
}
function test_setAfterConstructed() {
@@ -141,13 +141,13 @@ Item {
calendar.selectedDate = new Date(1980, 0, 1);
calendar.frameVisible = false;
calendar.dayOfWeekFormat = Locale.NarrowFormat;
- calendar.__locale = Qt.locale("de_DE");
+ calendar.locale = Qt.locale("de_DE");
compare(calendar.minimumDate, new Date(1900, 0, 1));
compare(calendar.maximumDate, new Date(1999, 11, 31));
compare(calendar.selectedDate, new Date(1980, 0, 1));
compare(calendar.frameVisible, false);
- compare(calendar.__locale, Qt.locale("de_DE"));
+ compare(calendar.locale, Qt.locale("de_DE"));
}
function test_selectedDate() {
@@ -205,7 +205,7 @@ Item {
calendar.selectedDate = new Date(2013, 0, 1);
// Set this to a certain locale, because days will be in different
// places depending on the system locale of the host machine.
- calendar.__locale = Qt.locale("en_GB");
+ calendar.locale = Qt.locale("en_GB");
/* January 2013 December 2012
M T W T F S S M T W T F S S
@@ -371,7 +371,7 @@ Item {
var startDate = new Date(2013, 0, 1);
calendar.selectedDate = startDate;
- calendar.__locale = Qt.locale("en_US");
+ calendar.locale = Qt.locale("en_US");
compare(calendar.selectedDate, startDate);
pressedSignalSpy.target = calendar;
@@ -457,7 +457,7 @@ Item {
calendar.minimumDate = new Date(2013, 0, 1);
calendar.selectedDate = new Date(startDate);
calendar.maximumDate = new Date(2013, 1, 5);
- calendar.__locale = Qt.locale("no_NO");
+ calendar.locale = Qt.locale("no_NO");
pressedSignalSpy.target = calendar;
pressedSignalSpy.signalName = "pressed";
@@ -531,7 +531,7 @@ Item {
22 23 24 25 26 27 28
29 30 31 1 2 3 4 */
- calendar.__locale = Qt.locale("en_GB");
+ calendar.locale = Qt.locale("en_GB");
calendar.selectedDate = new Date(2014, 11, 1);
mousePress(calendar, toPixelsX(0), toPixelsY(0), Qt.LeftButton);
compare(calendar.selectedDate, new Date(2014, 10, 24));
@@ -602,7 +602,7 @@ Item {
calendar.minimumDate = new Date(2014, 1, 1);
calendar.selectedDate = new Date(2014, 1, 28);
calendar.maximumDate = new Date(2014, 2, 31);
- calendar.__locale = Qt.locale("en_GB");
+ calendar.locale = Qt.locale("en_GB");
pressedSignalSpy.target = calendar;
pressedSignalSpy.signalName = "pressed";
@@ -875,7 +875,7 @@ Item {
function test_pressAndHold() {
calendar.selectedDate = new Date(2013, 0, 1);
- calendar.__locale = Qt.locale("en_GB");
+ calendar.locale = Qt.locale("en_GB");
pressedSignalSpy.target = calendar;
pressedSignalSpy.signalName = "pressed";