Browse Source

added QML time edit

pull/2/head
Skycoder42 7 years ago
parent
commit
7121bc7b05
No known key found for this signature in database GPG Key ID: 8E01AD9EF0578D2B
  1. 38
      examples/mvvmcore/SampleCore/settings.xml
  2. 99
      src/imports/mvvmquick/TimeEdit.qml
  3. 3
      src/imports/mvvmquick/mvvmquick.pro
  4. 1
      src/imports/mvvmquick/qmldir
  5. 19
      src/mvvmquick/TimeEdit.qml
  6. 6
      src/mvvmquick/inputviewfactory.cpp
  7. 1
      src/mvvmquick/qtmvvmquick_module.qrc
  8. 10
      src/mvvmwidgets/inputwidgetfactory.cpp

38
examples/mvvmcore/SampleCore/settings.xml

@ -100,14 +100,6 @@
default="42"> default="42">
<Property key="qtmvvm_preview" type="string" ztr="true">Is set to %n unit(s)</Property> <Property key="qtmvvm_preview" type="string" ztr="true">Is set to %n unit(s)</Property>
</Entry> </Entry>
<Entry key="prop12"
type="range"
title="&amp;Volume"
default="50">
<Property key="minimum" type="int">0</Property>
<Property key="maximum" type="int">100</Property>
<Property key="valueFormat" type="string">%1 %</Property>
</Entry>
<Entry key="prop8" <Entry key="prop8"
type="selection" type="selection"
title="Select a &amp;mode" title="Select a &amp;mode"
@ -127,7 +119,35 @@
<Entry key="prop10" <Entry key="prop10"
type="QFont" type="QFont"
title="Choose a &amp;font" /> title="Choose a &amp;font" />
<Entry key="prop11" <Entry key="prop12"
type="range"
title="&amp;Volume"
default="50">
<Property key="minimum" type="int">0</Property>
<Property key="maximum" type="int">100</Property>
<Property key="valueFormat" type="string">%1 %</Property>
</Entry>
<Entry key="prop13"
type="QTime"
title="Choose a time"
default="14:30">
<Property key="qtmvvm_preview" type="string">Selected time: %1</Property>
<Property key="qtmvvm_dateformat" type="int">1</Property>
</Entry>
<Entry key="prop14"
type="QDate"
title="Choose a date"
default="2018-10-10">
<Property key="qtmvvm_preview" type="string">Selected date: %1</Property>
<Property key="qtmvvm_dateformat" type="string">dd.MM.yyyy</Property>
</Entry>
<Entry key="prop15"
type="QDateTime"
title="Choose a date and time"
default="2018-10-10T14:30">
<Property key="qtmvvm_preview" type="string">Selected date and time: %1</Property>
</Entry>
<Entry key="propErr"
type="non-existant-type" type="non-existant-type"
title="Non existing type" /> title="Non existing type" />
</Category> </Category>

99
src/imports/mvvmquick/TimeEdit.qml

@ -0,0 +1,99 @@
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
RowLayout {
id: _edit
spacing: 0
property date time: new Date()
onTimeChanged: {
if(!_skipChange)
_forceTime = time
}
property var _forceTime: new Date()
readonly property bool is24Hours: {
var fmStr = Qt.locale().timeFormat(Locale.LongFormat);
var isApPm = false;
["A", "AP", "a", "ap"].forEach(function(text){
if(fmStr.indexOf(text) !== -1)
isApPm = true;
});
return !isApPm;
}
readonly property int hours: _hourTumbler.currentIndex + (!is24Hours && _amPmTumbler.currentIndex === 1 ? 12 : 0);
readonly property int minutes: _minuteTumbler.currentIndex;
property bool _skipChange: false
function recalcTime() {
var hours = _hourTumbler.currentIndex + (!is24Hours && _amPmTumbler.currentIndex === 1 ? 12 : 0);
var minutes = _minuteTumbler.currentIndex;
if(_forceTime.getHours() !== hours ||
_forceTime.getMinutes() !== minutes) {
_skipChange = true;
time = new Date(0, 0, 0, hours, minutes);
_skipChange = false;
}
}
Item {
id: _spacer1
Layout.fillHeight: true
Layout.fillWidth: true
Layout.preferredWidth: 0
}
Tumbler {
id: _hourTumbler
model: {
var model = new Array(is24Hours ? 24 : 12);
for(var i = 0; i < model.length; i++)
model[i] = i.toString();
if(!is24Hours)
model[0] = 12;
return model;
}
currentIndex: is24Hours ? _forceTime.getHours() : (_forceTime.getHours() % 12)
onCurrentIndexChanged: Qt.callLater(recalcTime)
}
Label {
text: qsTr(":")
Layout.minimumWidth: implicitWidth
}
Tumbler {
id: _minuteTumbler
model: {
var mod = new Array(60)
for(var i = 0; i < mod.length; i++) {
var data = i.toString();
mod[i] = data.length < 2 ? Qt.locale().zeroDigit + data : data;
}
return mod;
}
currentIndex: _forceTime.getMinutes()
onCurrentIndexChanged: Qt.callLater(recalcTime)
}
Tumbler {
id: _amPmTumbler
visible: !is24Hours
model: [
Qt.locale().amText,
Qt.locale().pmText,
]
currentIndex: _forceTime.getHours() >= 12 ? 1 : 0
onCurrentIndexChanged: Qt.callLater(recalcTime)
}
Item {
id: _spacer2
Layout.fillHeight: true
Layout.fillWidth: true
Layout.preferredWidth: 0
}
}

3
src/imports/mvvmquick/mvvmquick.pro

@ -53,7 +53,8 @@ QML_FILES += \
SearchBar.qml \ SearchBar.qml \
RoundMenuButton.qml \ RoundMenuButton.qml \
DecorLabel.qml \ DecorLabel.qml \
MsgDelegate.qml MsgDelegate.qml \
TimeEdit.qml
RESOURCES += \ RESOURCES += \
qtmvvmquick_plugin.qrc qtmvvmquick_plugin.qrc

1
src/imports/mvvmquick/qmldir

@ -27,6 +27,7 @@ SearchBar 1.1 SearchBar.qml
RoundMenuButton 1.1 RoundMenuButton.qml RoundMenuButton 1.1 RoundMenuButton.qml
DecorLabel 1.1 DecorLabel.qml DecorLabel 1.1 DecorLabel.qml
MsgDelegate 1.1 MsgDelegate.qml MsgDelegate 1.1 MsgDelegate.qml
TimeEdit 1.1 TimeEdit.qml
PresenterProgress 1.0 PresenterProgress.qml PresenterProgress 1.0 PresenterProgress.qml
PresentingStackView 1.0 PresentingStackView.qml PresentingStackView 1.0 PresentingStackView.qml

19
src/mvvmquick/TimeEdit.qml

@ -0,0 +1,19 @@
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import de.skycoder42.QtMvvm.Quick 1.1 as QtMvvm
QtMvvm.TimeEdit {
id: _edit
property var inputValue: new Date()
onInputValueChanged: {
var realTime = typeof inputValue == "string" ? new Date("2000-01-01T" + inputValue) : inputValue
if(realTime.getHours() !== time.getHours() ||
realTime.getMinutes() !== time.getMinutes()) {
time = realTime
}
}
onTimeChanged: inputValue = time
}

6
src/mvvmquick/inputviewfactory.cpp

@ -115,9 +115,9 @@ InputViewFactoryPrivate::InputViewFactoryPrivate() :
{QMetaType::typeName(QMetaType::Double), QStringLiteral("qrc:/qtmvvm/inputs/DoubleSpinBox.qml")}, {QMetaType::typeName(QMetaType::Double), QStringLiteral("qrc:/qtmvvm/inputs/DoubleSpinBox.qml")},
{"number", QStringLiteral("qrc:/qtmvvm/inputs/DoubleSpinBox.qml")}, {"number", QStringLiteral("qrc:/qtmvvm/inputs/DoubleSpinBox.qml")},
{"range", QStringLiteral("qrc:/qtmvvm/inputs/Slider.qml")}, {"range", QStringLiteral("qrc:/qtmvvm/inputs/Slider.qml")},
// {QMetaType::typeName(QMetaType::QDate), QStringLiteral("qrc:/qtmvvm/inputs/.qml")}, // {QMetaType::typeName(QMetaType::QDate), QStringLiteral("qrc:/qtmvvm/inputs/")},
// {QMetaType::typeName(QMetaType::QTime), QStringLiteral("qrc:/qtmvvm/inputs/.qml")}, {QMetaType::typeName(QMetaType::QTime), QStringLiteral("qrc:/qtmvvm/inputs/TimeEdit.qml")},
// {QMetaType::typeName(QMetaType::QDateTime), QStringLiteral("qrc:/qtmvvm/inputs/.qml")}, // {QMetaType::typeName(QMetaType::QDateTime), QStringLiteral("qrc:/qtmvvm/inputs/")},
// {"date", QStringLiteral("qrc:/qtmvvm/inputs/.qml")}, // {"date", QStringLiteral("qrc:/qtmvvm/inputs/.qml")},
{QMetaType::typeName(QMetaType::QFont), QStringLiteral("qrc:/qtmvvm/inputs/FontEdit.qml")}, {QMetaType::typeName(QMetaType::QFont), QStringLiteral("qrc:/qtmvvm/inputs/FontEdit.qml")},
{QMetaType::typeName(QMetaType::QUrl), QStringLiteral("qrc:/qtmvvm/inputs/UrlField.qml")}, {QMetaType::typeName(QMetaType::QUrl), QStringLiteral("qrc:/qtmvvm/inputs/UrlField.qml")},

1
src/mvvmquick/qtmvvmquick_module.qrc

@ -10,6 +10,7 @@
<file>Switch.qml</file> <file>Switch.qml</file>
<file>RadioListEdit.qml</file> <file>RadioListEdit.qml</file>
<file>Slider.qml</file> <file>Slider.qml</file>
<file>TimeEdit.qml</file>
</qresource> </qresource>
<qresource prefix="/qtmvvm/delegates"> <qresource prefix="/qtmvvm/delegates">
<file>BoolDelegate.qml</file> <file>BoolDelegate.qml</file>

10
src/mvvmwidgets/inputwidgetfactory.cpp

@ -54,13 +54,15 @@ QWidget *InputWidgetFactory::createInput(const QByteArray &type, QWidget *parent
widget = new QDoubleSpinBox(parent); widget = new QDoubleSpinBox(parent);
else if(type == "range") else if(type == "range")
widget = new ToolTipSlider(parent); widget = new ToolTipSlider(parent);
else if(type == QMetaType::typeName(QMetaType::QDate)) else if(type == QMetaType::typeName(QMetaType::QDate)) {
widget = new QDateEdit(parent); widget = new QDateEdit(parent);
else if(type == QMetaType::typeName(QMetaType::QTime)) static_cast<QDateEdit*>(widget)->setCalendarPopup(true);
} else if(type == QMetaType::typeName(QMetaType::QTime))
widget = new QTimeEdit(parent); widget = new QTimeEdit(parent);
else if(type == QMetaType::typeName(QMetaType::QDateTime) || type == "date") else if(type == QMetaType::typeName(QMetaType::QDateTime) || type == "date") {
widget = new QDateTimeEdit(parent); widget = new QDateTimeEdit(parent);
else if(type == QMetaType::typeName(QMetaType::QFont)) static_cast<QDateEdit*>(widget)->setCalendarPopup(true);
} else if(type == QMetaType::typeName(QMetaType::QFont))
widget = new FontComboBox(parent); widget = new FontComboBox(parent);
else if(type == QMetaType::typeName(QMetaType::QKeySequence)) else if(type == QMetaType::typeName(QMetaType::QKeySequence))
widget = new QKeySequenceEdit(parent); widget = new QKeySequenceEdit(parent);

Loading…
Cancel
Save