Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeInput UI #435

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions source/qml_v2/AdaptiveCardQmlEngine/AdaptiveCardQmlTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ namespace AdaptiveCardQmlEngine
qmlRegisterType(QUrl("qrc:qml/InputErrorMessage.qml"), "AdaptiveCardQmlEngine", 1, 0, "InputErrorMessage");
qmlRegisterType(QUrl("qrc:qml/InputFieldClearIcon.qml"), "AdaptiveCardQmlEngine", 1, 0, "InputFieldClearIcon");
qmlRegisterType(QUrl("qrc:qml/MultiLineTextInputRender.qml"), "AdaptiveCardQmlEngine", 1, 0, "MultiLineTextInputRender");
qmlRegisterType(QUrl("qrc:qml/TimeInputRender.qml"), "AdaptiveCardQmlEngine", 1, 0, "TimeInputRender");
qmlRegisterType(QUrl("qrc:qml/TimeInputPopout.qml"), "AdaptiveCardQmlEngine", 1, 0, "TimeInputPopout");
qmlRegisterType(QUrl("qrc:qml/TimeInputTextField.qml"), "AdaptiveCardQmlEngine", 1, 0, "TimeInputTextField");
qmlRegisterType(QUrl("qrc:qml/TimePickerListView.qml"), "AdaptiveCardQmlEngine", 1, 0, "TimePickerListView");
}
} // namespace RendererQml
2 changes: 2 additions & 0 deletions source/qml_v2/AdaptiveCardQmlEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ file(GLOB_RECURSE SOURCES
"ImageModel.cpp"
"RichTextBlockModel.cpp"
"TextInputModel.cpp"
"TimeInputModel.cpp"

"AdaptiveCardQmlTypes.h"
"AdaptiveCardUtils.cpp"
Expand All @@ -82,6 +83,7 @@ file(GLOB_RECURSE SOURCES
"TextBlockModel.h"
"RichTextBlockModel.h"
"TextInputModel.h"
"TimeInputModel.h"
)

# Setup Library
Expand Down
11 changes: 11 additions & 0 deletions source/qml_v2/AdaptiveCardQmlEngine/models/CollectionItemModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ImageModel.h"
#include "RichTextBlockModel.h"
#include "TextInputModel.h"
#include "TimeInputModel.h"
#include "AdaptiveCardEnums.h"

CollectionItemModel::CollectionItemModel(std::vector<std::shared_ptr<AdaptiveCards::BaseCardElement>> elements, QObject* parent) :
Expand Down Expand Up @@ -45,6 +46,7 @@ QHash<int, QByteArray> CollectionItemModel::roleNames() const
cardListModel[ImageRole] = "imageRole";
cardListModel[RichTextBlockRole] = "richTextBlockRole";
cardListModel[TextInputRole] = "textInputRole";
cardListModel[TimeInputRole] = "timeInputRole";
cardListModel[FillHeightRole] = "fillHeightRole";

return cardListModel;
Expand All @@ -69,6 +71,9 @@ void CollectionItemModel::populateRowData(std::shared_ptr<AdaptiveCards::BaseCar
case AdaptiveCards::CardElementType::TextInput:
populateTextInputModel(std::dynamic_pointer_cast<AdaptiveCards::TextInput>(element), rowContent);
break;
case AdaptiveCards::CardElementType::TimeInput:
populateTimeInputModel(std::dynamic_pointer_cast<AdaptiveCards::TimeInput>(element), rowContent);
break;
default:
break;
}
Expand Down Expand Up @@ -97,3 +102,9 @@ void CollectionItemModel::populateTextInputModel(std::shared_ptr<AdaptiveCards::
rowContent[CollectionModelRole::DelegateType] = QVariant::fromValue(AdaptiveCardEnums::CardElementType::TextInput);
rowContent[CollectionModelRole::TextInputRole] = QVariant::fromValue(new TextInputModel(input, nullptr));
}

void CollectionItemModel::populateTimeInputModel(std::shared_ptr<AdaptiveCards::TimeInput> input, RowContent& rowContent)
{
rowContent[CollectionModelRole::DelegateType] = QVariant::fromValue(AdaptiveCardEnums::CardElementType::TimeInput);
rowContent[CollectionModelRole::TimeInputRole] = QVariant::fromValue(new TimeInputModel(input, nullptr));
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
#include <RichTextBlock.h>
#include <Image.h>
#include <TextInput.h>
#include <TimeInput.h>
#include "Enums.h"

class TextBlockModel;
class RichTextBlockModel;
class ImageModel;
class TextInputModel;
class TimeInputModel;

class CollectionItemModel : public QAbstractListModel
{
Expand All @@ -25,6 +27,7 @@ class CollectionItemModel : public QAbstractListModel
ImageRole,
RichTextBlockRole,
TextInputRole,
TimeInputRole,
FillHeightRole
};

Expand All @@ -48,4 +51,5 @@ class CollectionItemModel : public QAbstractListModel
void populateImageModel(std::shared_ptr<AdaptiveCards::Image> image, RowContent& rowContent);
void populateRichTextBlockModel(std::shared_ptr<AdaptiveCards::RichTextBlock> rightTextBlock, RowContent& rowContent);
void populateTextInputModel(std::shared_ptr<AdaptiveCards::TextInput> input, RowContent& rowContent);
void populateTimeInputModel(std::shared_ptr<AdaptiveCards::TimeInput> input, RowContent& rowContent);
};
13 changes: 13 additions & 0 deletions source/qml_v2/AdaptiveCardQmlEngine/models/TimeInputModel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "TimeInputModel.h"
#include "SharedAdaptiveCard.h"
#include <QDebug.h>
#include "Utils.h"
#include "MarkDownParser.h"

TimeInputModel::TimeInputModel(std::shared_ptr<AdaptiveCards::TimeInput> input, QObject* parent) :
QObject(parent)
{
}

TimeInputModel::~TimeInputModel()
{}
19 changes: 19 additions & 0 deletions source/qml_v2/AdaptiveCardQmlEngine/models/TimeInputModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <QObject>
#include <QColor>
#include <QFont>

#include "AdaptiveCardContext.h"
#include "TimeInput.h"

class TimeInputModel : public QObject
{
Q_OBJECT

public:
explicit TimeInputModel(std::shared_ptr<AdaptiveCards::TimeInput> input, QObject* parent = nullptr);
~TimeInputModel();
};


Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Loader {
else if (model.delegateType == AdaptiveCardEnums.CardElementType.RichTextBlock)
source = "RichTextBlockRender.qml";
else if (model.delegateType == AdaptiveCardEnums.CardElementType.TextInput)
source = "TextInputRender.qml"
source = "TextInputRender.qml";
else if (model.delegateType == AdaptiveCardEnums.CardElementType.TimeInput)
source = "TimeInputRender.qml"
}
}
24 changes: 12 additions & 12 deletions source/qml_v2/AdaptiveCardQmlEngine/qml/InputErrorMessage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "JSUtils/AdaptiveCardUtils.js" as AdaptiveCardUtils
Rectangle {
id: errorMessage

property string errorMessage
property string isErrorMessage

width: parent.width
height: errorMessageLabel.implicitHeight
Expand All @@ -16,17 +16,17 @@ Rectangle {
Button {
id: errorIcon

width: cardConst.inputFieldConstants.errorIconWidth
width: CardConstants.inputFieldConstants.errorIconWidth
anchors.left: parent.left
anchors.leftMargin: cardConst.inputFieldConstants.errorIconLeftMargin
anchors.topMargin: cardConst.inputFieldConstants.errorIconTopMargin
anchors.leftMargin: CardConstants.inputFieldConstants.errorIconLeftMargin
anchors.topMargin: CardConstants.inputFieldConstants.errorIconTopMargin
horizontalPadding: 0
verticalPadding: 0
icon.width: cardConst.inputFieldConstants.errorIconWidth
icon.height: cardConst.inputFieldConstants.errorIconHeight
icon.color: cardConst.toggleButtonConstants.errorMessageColor
icon.width: CardConstants.inputFieldConstants.errorIconWidth
icon.height: CardConstants.inputFieldConstants.errorIconHeight
icon.color: CardConstants.toggleButtonConstants.errorMessageColor
anchors.top: parent.top
icon.source: cardConst.errorIcon
icon.source: CardConstants.errorIcon
enabled: false

background: Rectangle {
Expand All @@ -38,12 +38,12 @@ Rectangle {
id: errorMessageLabel

wrapMode: Text.Wrap
font.pixelSize: cardConst.inputFieldConstants.labelPixelSize
font.pixelSize: CardConstants.inputFieldConstants.labelPixelSize
Accessible.ignored: true
color: cardConst.toggleButtonConstants.errorMessageColor
color: CardConstants.toggleButtonConstants.errorMessageColor
anchors.left: errorIcon.right
anchors.leftMargin: cardConst.inputFieldConstants.errorIconLeftMargin
anchors.leftMargin: CardConstants.inputFieldConstants.errorIconLeftMargin
anchors.right: parent.right
text: textInputModel.errorMessage//_errorMessage
text: isErrorMessage
}
}
12 changes: 6 additions & 6 deletions source/qml_v2/AdaptiveCardQmlEngine/qml/InputFieldClearIcon.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import "JSUtils/AdaptiveCardUtils.js" as AdaptiveCardUtils
Button {
id: inputFieldClearIcon

width: cardConst.inputFieldConstants.clearIconSize
width: CardConstants.inputFieldConstants.clearIconSize
horizontalPadding: 0
verticalPadding: 0
icon.width: cardConst.inputFieldConstants.clearIconSize
icon.height: cardConst.inputFieldConstants.clearIconSize
icon.color: cardConst.inputFieldConstants.clearIconColorNormal
icon.source: cardConst.clearIconImage
icon.width: CardConstants.inputFieldConstants.clearIconSize
icon.height: CardConstants.inputFieldConstants.clearIconSize
icon.color: CardConstants.inputFieldConstants.clearIconColorNormal
icon.source: CardConstants.clearIconImage
Accessible.name: qsTr("Clear Input")
Accessible.role: Accessible.Button

background: Rectangle {
color: 'transparent'
radius: cardConst.inputFieldConstants.borderRadius
radius: CardConstants.inputFieldConstants.borderRadius

WCustomFocusItem {
isRectangle: true
Expand Down
7 changes: 4 additions & 3 deletions source/qml_v2/AdaptiveCardQmlEngine/qml/InputLabel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ Label {
id: inputLabel

property bool required
property string label

wrapMode: Text.Wrap
width: parent.width
color: cardConst.toggleButtonConstants.textColor
font.pixelSize: cardConst.inputFieldConstants.labelPixelSize
color: CardConstants.toggleButtonConstants.textColor
font.pixelSize: CardConstants.inputFieldConstants.labelPixelSize
Accessible.ignored: true
text: textInputModel.isRequired ? AdaptiveCardUtils.escapeHtml(textInputModel.label) + " " + "<font color='" + cardConst.inputFieldConstants.errorMessageColor + "'>*</font>" : AdaptiveCardUtils.escapeHtml(textInputModel.label)
text: required ? AdaptiveCardUtils.escapeHtml(label) + " " + "<font color='" + CardConstants.inputFieldConstants.errorMessageColor + "'>*</font>" : AdaptiveCardUtils.escapeHtml(label)
}
3 changes: 2 additions & 1 deletion source/qml_v2/AdaptiveCardQmlEngine/qml/TextInputRender.qml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Column {
InputLabel {
id: inputTextLabel

label: textInputModel.label
required: textInputModel.isRequired
visible: textInputModel.label
}
Expand Down Expand Up @@ -118,7 +119,7 @@ Column {
InputErrorMessage {
id: inputtextErrorMessage

errorMessage: textInputModel.errorMessage
isErrorMessage: textInputModel.errorMessage
visible: showErrorMessage
}
}
82 changes: 82 additions & 0 deletions source/qml_v2/AdaptiveCardQmlEngine/qml/TimeInputPopout.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import QtQuick 2.15
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.15
import AdaptiveCardQmlEngine 1.0
import "JSUtils/AdaptiveCardUtils.js" as AdaptiveCardUtils

Popup {
id: timeInputPopout

property var timeInputField
property var timeInputElement
property bool is12Hour: timeInputElement.is12Hour
property var inputFieldConstants: CardConstants.inputFieldConstants
property var inputTimeConstants: CardConstants.inputTimeConstants


width: contentWidth + (2 * inputFieldConstants.clearIconHorizontalPadding)
height: inputTimeConstants.timePickerHeight
y: timeInputField.height + inputTimeConstants.timePickerSpacing
x: -inputFieldConstants.clearIconSize - inputFieldConstants.clearIconHorizontalPadding
onOpened: {
timeHours.forceActiveFocus();
}
onClosed: {
updateTime();
timeInputField.forceActiveFocus();
}

background: Rectangle {
anchors.fill: parent
border.color: inputTimeConstants.timePickerBorderColor
radius: inputTimeConstants.timePickerBorderRadius
color: inputTimeConstants.timePickerBackgroundColor
}

contentItem: Rectangle {
id: timePickerRectangle

height: parent.height
implicitWidth: timePickerRLayout.implicitWidth
color: 'transparent'
Accessible.name: "Time Picker"

RowLayout {
id: timePickerRLayout

height: parent.height
spacing: inputTimeConstants.timePickerMargins

TimePickerListView {
id: timeHours

listType: "hours"
model: is12Hour ? 12 : 24
}

TimePickerListView {
id: timeMinutes

listType: "minutes"
model: 60
}

TimePickerListView {
id: timeAMPM

listType: "AMPM"
visible: is12Hour

model: ListModel {
ListElement {
name: "AM"
}

ListElement {
name: "PM"
}
}
}
}
}
}
Loading