summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Gottfried <sebastiangottfried@web.de>2015-07-10 09:45:45 (GMT)
committerSebastian Gottfried <sebastiangottfried@web.de>2015-07-10 09:45:45 (GMT)
commit69db84d929577877a25035ad01e4a6c8c565bbc2 (patch)
tree003838ee057d35ef1536e868f8351f089d69354f
parent9345e9d58aa55f1692c365b1a4a8d063ca17a110 (diff)
Qt5: Port TrainingWidget
With this KTouch has regained once more its core competency, the training part. Yay!
-rw-r--r--src/qml/TrainingScreen.qml2
-rw-r--r--src/qml/TrainingWidget.qml227
2 files changed, 115 insertions, 114 deletions
diff --git a/src/qml/TrainingScreen.qml b/src/qml/TrainingScreen.qml
index 3808f05..997ee69 100644
--- a/src/qml/TrainingScreen.qml
+++ b/src/qml/TrainingScreen.qml
@@ -181,7 +181,6 @@ FocusScope {
source: utils.findImage("trainingscreen-viewport.png")
cache: false
- /*
TrainingWidget {
id: trainingWidget
anchors.fill: parent
@@ -199,7 +198,6 @@ FocusScope {
screen.trainingFinished = true
}
}
- */
BorderImage {
anchors.fill: parent
diff --git a/src/qml/TrainingWidget.qml b/src/qml/TrainingWidget.qml
index bbe1258..90ce60c 100644
--- a/src/qml/TrainingWidget.qml
+++ b/src/qml/TrainingWidget.qml
@@ -15,9 +15,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import QtQuick 1.1
+import QtQuick 2.4
+import QtQuick.Controls 1.3
import ktouch 1.0
-import org.kde.plasma.components 0.1 as PlasmaComponents
FocusScope {
id: trainingWidget
@@ -41,6 +41,10 @@ FocusScope {
trainingLine.active = true
}
+ function forceActiveFocus() {
+ trainingLine.forceActiveFocus()
+ }
+
Timer {
id: stopTimer
interval: 5000
@@ -49,137 +53,140 @@ FocusScope {
}
}
- Flickable
- {
- id: sheetFlick
+ ScrollView {
anchors.fill: parent
- contentWidth: parent.width
- contentHeight: sheet.height + 60
- clip: true
- flickableDirection: Flickable.VerticalFlick
-
- function currentLineY() {
- var cursorRect = lessonPainter.cursorRectangle
- var y = cursorRect.y + sheet.y + (cursorRect.height / 2)
- return Math.max(Math.min((y - (height / 2)), contentHeight - height), 0)
- }
-
- function scrollToCurrentLine() {
- scrollAnimation.to = currentLineY()
- scrollAnimation.start()
- }
-
- onHeightChanged: {
- contentY = currentLineY()
- }
+ Flickable
+ {
+ id: sheetFlick
+ anchors.fill: parent
+ contentWidth: parent.width
+ contentHeight: sheet.height + 60
+ clip: true
+ flickableDirection: Flickable.VerticalFlick
+
+ function currentLineY() {
+ var cursorRect = lessonPainter.cursorRectangle
+ var y = cursorRect.y + sheet.y + (cursorRect.height / 2)
+ return Math.max(Math.min((y - (height / 2)), contentHeight - height), 0)
+ }
- NumberAnimation {
- target: sheetFlick
- id: scrollAnimation
- duration: 150
- property: "contentY"
- }
+ function scrollToCurrentLine() {
+ scrollAnimation.to = currentLineY()
+ scrollAnimation.start()
+ }
- Rectangle {
- id: sheet
- color: "#fff"
- anchors.centerIn: parent
- width: parent.width - 60
- height: lessonPainter.height
+ onHeightChanged: {
+ contentY = currentLineY()
+ }
- border {
- width: 1
- color: "#000"
+ NumberAnimation {
+ target: sheetFlick
+ id: scrollAnimation
+ duration: 150
+ property: "contentY"
}
- LessonPainter {
- id: lessonPainter
- anchors.centerIn: sheet
- lesson: trainingWidget.lesson
- maximumWidth: parent.width
- trainingLineCore: trainingLine
-
- onDone: {
- trainingLine.active = false
- trainingWidget.finished();
- stats.stopTraining();
+ Rectangle {
+ id: sheet
+ color: "#fff"
+ anchors.centerIn: parent
+ width: parent.width - 60
+ height: lessonPainter.height
+
+ border {
+ width: 1
+ color: "#000"
}
- TrainingLineCore {
- id: trainingLine
- anchors.fill: parent
- focus: true
- trainingStats: stats
- cursorItem: cursor
+ LessonPainter {
+ id: lessonPainter
+ anchors.centerIn: sheet
+ lesson: trainingWidget.lesson
+ maximumWidth: parent.width
+ trainingLineCore: trainingLine
+
+ onDone: {
+ trainingLine.active = false
+ trainingWidget.finished();
+ stats.stopTraining();
+ }
- onFocusChanged: {
- if (!trainingLine.activeFocus) {
- trainingStats.stopTraining()
+ TrainingLineCore {
+ id: trainingLine
+ anchors.fill: parent
+ focus: true
+ trainingStats: stats
+ cursorItem: cursor
+
+ onFocusChanged: {
+ if (!trainingLine.activeFocus) {
+ trainingStats.stopTraining()
+ }
}
- }
- Keys.onPressed: {
- if (!trainingLine.active)
- return
+ Keys.onPressed: {
+ if (!trainingLine.active)
+ return
- cursorAnimation.restart()
- trainingStats.startTraining()
- stopTimer.restart()
+ cursorAnimation.restart()
+ trainingStats.startTraining()
+ stopTimer.restart()
- if (!event.isAutoRepeat) {
- trainingWidget.keyPressed(event)
+ if (!event.isAutoRepeat) {
+ trainingWidget.keyPressed(event)
+ }
}
- }
- Keys.onReleased: {
- if (!trainingLine.active)
- return
+ Keys.onReleased: {
+ if (!trainingLine.active)
+ return
- if (!event.isAutoRepeat) {
- trainingWidget.keyReleased(event)
+ if (!event.isAutoRepeat) {
+ trainingWidget.keyReleased(event)
+ }
}
}
- }
- Rectangle {
- id: cursor
- color: "#000"
- x: Math.floor(lessonPainter.cursorRectangle.x)
- y: lessonPainter.cursorRectangle.y
- width: lessonPainter.cursorRectangle.width
- height: lessonPainter.cursorRectangle.height
-
- onYChanged: sheetFlick.scrollToCurrentLine()
-
- SequentialAnimation {
- id: cursorAnimation
- running: trainingLine.active && trainingLine.activeFocus && Qt.application.active
- loops: Animation.Infinite
- PropertyAction {
- target: cursor
- property: "opacity"
- value: 1
- }
- PauseAnimation {
- duration: 500
- }
- PropertyAction {
- target: cursor
- property: "opacity"
- value: 0
- }
- PauseAnimation {
- duration: 500
+ Rectangle {
+ id: cursor
+ color: "#000"
+ x: Math.floor(lessonPainter.cursorRectangle.x)
+ y: lessonPainter.cursorRectangle.y
+ width: lessonPainter.cursorRectangle.width
+ height: lessonPainter.cursorRectangle.height
+
+ onYChanged: sheetFlick.scrollToCurrentLine()
+
+ SequentialAnimation {
+ id: cursorAnimation
+ running: trainingLine.active && trainingLine.activeFocus && Qt.application.active
+ loops: Animation.Infinite
+ PropertyAction {
+ target: cursor
+ property: "opacity"
+ value: 1
+ }
+ PauseAnimation {
+ duration: 500
+ }
+ PropertyAction {
+ target: cursor
+ property: "opacity"
+ value: 0
+ }
+ PauseAnimation {
+ duration: 500
+ }
}
}
}
}
}
+ }
- MouseArea {
- anchors.fill: parent
- onClicked: trainingLine.forceActiveFocus()
- }
+ MouseArea {
+ anchors.fill: parent
+ onClicked: trainingLine.forceActiveFocus()
}
KeyItem {
@@ -229,9 +236,5 @@ FocusScope {
NumberAnimation { duration: 150 }
}
}
-
- PlasmaComponents.ScrollBar {
- flickableItem: sheetFlick
- }
}