Commit 9d2e74f4 authored by Karel Slaný's avatar Karel Slaný Committed by Martin Straka

Added a calendar QML dialogue to make date selection easier.

parent 606f12d6
/*
* Copyright (C) 2014-2018 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
import QtQuick.Controls 1.4
/*
* Provides a calendar interface.
* It is defined as a separate component in order not to pollute the namespace
* with the import of QtQuick.Controls 1.
*/
Calendar {
id: root
}
......@@ -22,6 +22,7 @@
*/
import QtGraphicalEffects 1.0
import QtQml 2.0 // Date
import QtQuick 2.7
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2
......@@ -50,6 +51,17 @@ ScrollableListView {
width: parent.width
enabled: gsUserInput
color: enabled ? datovkaPalette.base : readBgColor
/* Makes date selection easier. */
CalendarDialogue {
id: calendarDialogue
onFinished: {
var locale = Qt.locale()
textField.text = selectedDate.toLocaleDateString(locale, "yyyy-MM-dd")
}
}
Item {
anchors.fill: parent
anchors.margins: defaultMargin
......@@ -65,29 +77,50 @@ ScrollableListView {
width: parent.width
wrapMode: Text.Wrap
}
AccessibleTextField {
id: textField
height: inputItemHeight
//maximumLength: 8
font.pointSize: defaultTextFont.font.pointSize
text: gsVal
placeholderText: gsPlacehold
width: parent.width
InputLineMenu {
id: icox
inputTextControl: textField
isPassword: false
}
onPressAndHold: {
if (settings.useExplicitClipboardOperations()) {
icox.implicitWidth = computeMenuWidth(icox)
icox.open()
Row {
anchors.right: parent.right
anchors.left: parent.left
AccessibleTextField {
id: textField
height: inputItemHeight
//maximumLength: 8
font.pointSize: defaultTextFont.font.pointSize
text: gsVal
placeholderText: gsPlacehold
width: actionButton.visible ? (parent.width - actionButton.width) : parent.width
InputLineMenu {
id: icox
inputTextControl: textField
isPassword: false
}
onPressAndHold: {
if (settings.useExplicitClipboardOperations()) {
icox.implicitWidth = computeMenuWidth(icox)
icox.open()
}
}
onTextChanged: { onTextEdited and onEditingFinished cannot be used here
root.model.setProperty(index, "gsVal", textField.text)
}
}
onTextEdited: { // onEditingFinished ?
root.model.setProperty(index, "gsVal", textField.text)
AccessibleOverlaidImageButton {
id: actionButton
anchors.verticalCenter: parent.verticalCenter
anchors.rightMargin: defaultMargin
image.sourceSize.height: imgHeightHeader
image.source: "qrc:/ui/calendar.svg"
accessibleName: qsTr("Open calendar")
visible: gsDate
onClicked: {
var locale = Qt.locale()
var today = new Date()
var tomorow = new Date(new Date().getTime() + 24 * 60 * 60 * 1000)
var filledDate = Date.fromLocaleDateString(locale, textField.text, "yyyy-MM-dd")
calendarDialogue.openCalendarDialogue(filledDate, today, "Select date", gsDescr)
}
}
}
} // Row
}
} // Item
} // Rectangle
......
/*
* Copyright (C) 2014-2018 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
import QtQuick 2.7
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.1
import cz.nic.mobileDatovka 1.0
/*
* Date input dialogue.
*/
Dialog {
id: root
signal finished(date selectedDate)
property int minimumInputSize: parent.width / 2
function isValidDate(d) {
return d instanceof Date && !isNaN(d);
}
function openCalendarDialogue(selDate, maxDate, title, text) {
root.title = title
rootText.text = text
root.open()
if (isValidDate(maxDate)) {
calendar.maximumDate = maxDate
}
if (isValidDate(selDate)) {
calendar.selectedDate = selDate
}
}
// center dialogue
x: parent.width / 2 - width / 2
y: parent.height / 2 - height / 1.2
width: parent.width - 4*defaultMargin
focus: true
modal: true
title: qsTr("QML input dialog")
standardButtons: Dialog.Ok | Dialog.Cancel
contentItem: ColumnLayout {
AccessibleText {
id: rootText
Layout.fillWidth: true
Layout.minimumWidth: minimumInputSize
Layout.alignment: Qt.AlignLeft | Qt.AlignBaseline
wrapMode: Text.WordWrap
}
Calendar {
id: calendar
}
} // ColumnLayout
onAccepted: finished(calendar.selectedDate)
// onRejected:
}
......@@ -45,6 +45,7 @@
<file>ui/bookmark-check.svg</file>
<file>ui/book-open.svg</file>
<file>ui/briefcase.svg</file>
<file>ui/calendar.svg</file>
<file>ui/call-split.svg</file>
<file>ui/close-octagon.svg</file>
<file>ui/content-save.svg</file>
......@@ -115,6 +116,7 @@
<file>../qml/components/AccessibleText.qml</file>
<file>../qml/components/AccessibleTextButton.qml</file>
<file>../qml/components/AccessibleTextField.qml</file>
<file>../qml/components/Calendar.qml</file>
<file>../qml/components/DataboxList.qml</file>
<file>../qml/components/FilterBar.qml</file>
<file>../qml/components/GovFormList.qml</file>
......@@ -126,8 +128,9 @@
<file>../qml/components/PageHeader.qml</file>
<file>../qml/components/ProgressBar.qml</file>
<file>../qml/components/ScrollableListView.qml</file>
<file>../qml/dialogues/InputDialogue.qml</file>
<file>../qml/dialogues/CalendarDialogue.qml</file>
<file>../qml/dialogues/FileDialogue.qml</file>
<file>../qml/dialogues/InputDialogue.qml</file>
<file>../qml/dialogues/MessageDialogue.qml</file>
<file>../qml/dialogues/PasteInputDialogue.qml</file>
<file>../qml/pages/PageAboutApp.qml</file>
......
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 26 26" version="1.1" width="24px" height="24px">
<g id="surface1">
<path style=" " d="M 7 0 C 6.449219 0 6 0.449219 6 1 L 6 4 C 6 4.550781 6.449219 5 7 5 C 7.550781 5 8 4.550781 8 4 L 8 1 C 8 0.449219 7.550781 0 7 0 Z M 19 0 C 18.449219 0 18 0.449219 18 1 L 18 4 C 18 4.550781 18.449219 5 19 5 C 19.550781 5 20 4.550781 20 4 L 20 1 C 20 0.449219 19.550781 0 19 0 Z M 3 2 C 1.34375 2 0 3.34375 0 5 L 0 23 C 0 24.65625 1.34375 26 3 26 L 23 26 C 24.65625 26 26 24.65625 26 23 L 26 5 C 26 3.34375 24.65625 2 23 2 L 21 2 L 21 4 C 21 5.105469 20.105469 6 19 6 C 17.894531 6 17 5.105469 17 4 L 17 2 L 9 2 L 9 4 C 9 5.105469 8.105469 6 7 6 C 5.894531 6 5 5.105469 5 4 L 5 2 Z M 2 9 L 24 9 L 24 23 C 24 23.550781 23.550781 24 23 24 L 3 24 C 2.449219 24 2 23.550781 2 23 Z M 9 12 L 9 14.3125 L 13.8125 14.3125 L 10.03125 21.96875 L 13.5 21.96875 L 16.96875 13.53125 L 16.96875 12 Z "/>
</g>
</svg>
......@@ -57,6 +57,7 @@ int GovFormListModel::rowCount(const QModelIndex &parent) const
#define PROP_MANDATORY "gsMandatory"
#define PROP_USER_INPUT "gsUserInput"
#define PROP_BOX_INPUT "gsBoxInput"
#define PROP_DATE "gsDate"
QHash<int, QByteArray> GovFormListModel::roleNames(void) const
{
......@@ -69,6 +70,7 @@ QHash<int, QByteArray> GovFormListModel::roleNames(void) const
roles[ROLE_GOV_SRVC_MANDATORY] = PROP_MANDATORY;
roles[ROLE_GOV_SRVC_USER_INPUT] = PROP_USER_INPUT;
roles[ROLE_GOV_SRVC_BOX_INPUT] = PROP_BOX_INPUT;
roles[ROLE_GOV_SRVC_DATE] = PROP_DATE;
}
return roles;
}
......@@ -105,6 +107,9 @@ QVariant GovFormListModel::data(const QModelIndex &index, int role) const
case ROLE_GOV_SRVC_BOX_INPUT:
return ri.boxInput;
break;
case ROLE_GOV_SRVC_DATE:
return ri.date;
break;
default:
/* Do nothing. */
break;
......
......@@ -46,7 +46,8 @@ public:
ROLE_GOV_SRVC_PLACEHOLD,
ROLE_GOV_SRVC_MANDATORY,
ROLE_GOV_SRVC_USER_INPUT,
ROLE_GOV_SRVC_BOX_INPUT
ROLE_GOV_SRVC_BOX_INPUT,
ROLE_GOV_SRVC_DATE
};
Q_ENUM(Roles)
......
......@@ -178,6 +178,7 @@ QList<Gov::RequiredInput> Gov::SrvcMvCrrVbh::requiredFields(void) const
ri.mandatory = true;
ri.userInput = false;
ri.boxInput = true;
ri.date = true;
formList.append(ri);
}
......
......@@ -49,13 +49,14 @@ namespace Gov {
public:
RequiredInput(void)
: key(), val(), descr(), placeholder(), mandatory(false),
userInput(false), boxInput(false)
userInput(false), boxInput(false), date(false)
{ }
RequiredInput(const QString &k, const QString &v,
const QString &d, const QString &p, bool m, bool u, bool b)
: key(k), val(v), descr(d), placeholder(p), mandatory(m),
userInput(u), boxInput(b)
const QString &de, const QString &p, bool m, bool u, bool b,
bool da)
: key(k), val(v), descr(de), placeholder(p), mandatory(m),
userInput(u), boxInput(b), date(da)
{ }
QString key; /*!< Internal value identifier. */
......@@ -66,6 +67,7 @@ namespace Gov {
bool mandatory; /*!< True if the value must be supplied. */
bool userInput; /*!< True if the value is provided by user input. */
bool boxInput; /*!< True if the value is derived from the data-box information. */
bool date; /*! True if the value is a date. */
};
/*!
......
......@@ -147,6 +147,7 @@ QList<Gov::RequiredInput> Gov::SrvcSzrRobVvu::requiredFields(void) const
ri.mandatory = true;
ri.userInput = true;
ri.boxInput = false;
ri.date = true;
formList.append(ri);
}
{
......@@ -158,6 +159,7 @@ QList<Gov::RequiredInput> Gov::SrvcSzrRobVvu::requiredFields(void) const
ri.mandatory = true;
ri.userInput = true;
ri.boxInput = false;
ri.date = true;
formList.append(ri);
}
......
......@@ -164,6 +164,7 @@ const struct QmlTypeEntry qmlComponents[] = {
{ "AccessibleText", 1, 0 },
{ "AccessibleTextButton", 1, 0 },
{ "AccessibleTextField", 1, 0 },
{ "Calendar", 1, 0 },
{ "DataboxList", 1, 0 },
{ "FilterBar", 1, 0 },
{ "GovFormList", 1, 0 },
......@@ -184,6 +185,7 @@ const struct QmlTypeEntry qmlComponents[] = {
*/
static
const struct QmlTypeEntry qmlDialogues[] = {
{ "CalendarDialogue", 1, 0 },
{ "FileDialogue", 1, 0 },
{ "InputDialogue", 1, 0},
{ "MessageDialogue", 1, 0},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment