Skip to content

Commit

Permalink
Progress FollowMyVote#19: Get contestant creation/editing working
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielhourt committed Feb 10, 2016
1 parent 4479e36 commit 9c799c0
Show file tree
Hide file tree
Showing 7 changed files with 882 additions and 25 deletions.
1 change: 1 addition & 0 deletions VotingApp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ int main(int argc, char *argv[])
REGISTER_WRAPPER(PurchaseContestRequest);
REGISTER_WRAPPER(Purchase);
#undef REGISTER_WRAPPER
qmlRegisterType<swv::PurchaseContestContestantWrapper>("FollowMyVote.StakeWeightedVoting.ContestPurchase", 1, 0, "Contestant");

// Register enum wrappers
#define REGISTER_ENUM(name) \
Expand Down
97 changes: 87 additions & 10 deletions VotingApp/qml/CreateContestPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import QtQuick.Controls 1.4 as Controls
import QtQuick.Controls.Styles 1.4 as ControlStyles
import QtQuick.Extras 1.4 as Extras
import Qt.labs.controls 1.0
import QtQml 2.2

import VPlayApps 1.0

Expand Down Expand Up @@ -45,6 +46,8 @@ Page {
width: parent.width
placeholderText: qsTr("Contest Name")
maximumLength: contestCreator.contestLimits[ContestLimits.NameLength]
Component.onCompleted: forceActiveFocus()
KeyNavigation.tab: contestDescription

Binding {
target: purchaseRequest
Expand Down Expand Up @@ -83,22 +86,46 @@ Page {
width: parent.width
Repeater {
model: purchaseRequest.contestants
delegate: Row {
delegate: RowLayout {
width: parent.width

IconButton {
icon: IconType.remove
onClicked: purchaseRequest.contestants.remove(index)
}
IconButton {
icon: IconType.edit
Row {
// This row works around the fact that IconButton does not properly set implicitWidth
IconButton {
icon: IconType.remove
onClicked: purchaseRequest.contestants.remove(index)
implicitWidth: minim
}
IconButton {
icon: IconType.edit
onClicked: {
var dialog = contestantDialog.createObject(createContestPage,
{"contestantName": name,
"contestantDescription":
description})

dialog.accepted.connect(function() {
name = dialog.contestantName
description = dialog.contestantDescription
dialog.close()
})
dialog.canceled.connect(dialog.close)

dialog.open()
}
}
}
ColumnLayout {
Layout.fillWidth: true
AppText {
text: modelData.name
text: name
Layout.fillWidth: true
elide: Text.ElideRight
}
AppText {
text: modelData.description
text: description
Layout.fillWidth: true
elide: Text.ElideRight
}
}
}
Expand All @@ -107,7 +134,24 @@ Page {
AppButton {
text: qsTr("Add Contestant")

onClicked: purchaseRequest.contestants.append({"name": "Joe", "description": "Joe is a candidate."})
onClicked: {
// Create a new dialog as defined by the contestDialog component
var dialog = contestantDialog.createObject(createContestPage)

// Handle dialog accepted/canceled signals
dialog.accepted.connect(function() {
var contestant = Qt.createQmlObject("import FollowMyVote.StakeWeightedVoting." +
"ContestPurchase 1.0; Contestant{}",
createContestPage, "ContestantCreation")
contestant.name = dialog.contestantName;
contestant.description = dialog.contestantDescription
purchaseRequest.contestants.append(contestant)
dialog.close()
})
dialog.canceled.connect(dialog.close)

dialog.open()
}
}
Row {
spacing: window.dp(8)
Expand Down Expand Up @@ -152,4 +196,37 @@ Page {
pages: swiper.count
currentPage: swiper.currentIndex
}

Component {
id: contestantDialog

Dialog {
title: qsTr("Edit Contestant")
contentHeight: window.dp(200)
contentWidth: window.dp(250)

property alias contestantName: contestantName.text
property alias contestantDescription: contestantDescription.text

ColumnLayout {
anchors.fill: parent
anchors.margins: window.dp(8)

AppTextField {
id: contestantName
placeholderText: qsTr("Name")
maximumLength: contestCreator.contestLimits[ContestLimits.ContestantNameLength]
Layout.fillWidth: true
KeyNavigation.tab: contestantDescription
Component.onCompleted: forceActiveFocus(Qt.Popup)
}
ScrollingTextEdit {
id: contestantDescription
Layout.fillHeight: true
Layout.fillWidth: true
textEdit.placeholderText: qsTr("Description")
}
}
}
}
}
45 changes: 45 additions & 0 deletions VotingApp/qml/ScrollingTextEdit.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import QtQuick 2.5
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.4 as Controls
import QtQuick.Controls.Styles 1.4 as ControlStyles
import QtQuick.Extras 1.4 as Extras
import Qt.labs.controls 1.0
import QtQml 2.2

import VPlayApps 1.0

import FollowMyVote.StakeWeightedVoting 1.0

FocusScope {
property alias textEdit: textEdit
property alias text: textEdit.text

Flickable {
id: scroller
anchors.fill: parent
contentWidth: textEdit.paintedWidth
contentHeight: contestDescription.paintedHeight
clip: true

function ensureVisible(r)
{
if (contentX >= r.x)
contentX = r.x;
else if (contentX+width <= r.x+r.width)
contentX = r.x+r.width-width;
if (contentY >= r.y)
contentY = r.y;
else if (contentY+height <= r.y+r.height)
contentY = r.y+r.height-height;
}

AppTextEdit {
id: textEdit
width: scroller.width
height: scroller.height
wrapMode: TextEdit.Wrap
onCursorPositionChanged: scroller.ensureVisible(cursorRectangle)
focus: true
}
}
}
Loading

0 comments on commit 9c799c0

Please sign in to comment.