Commit 27b5e28a authored by Denis Kuplyakov's avatar Denis Kuplyakov
Browse files

Converted indirect methods to set values with QML property bindings

Converted function calls to property bindings for QML interface.
Also renamed ReversiChip to Chip.
parent a6ac1e7e
......@@ -100,8 +100,7 @@ void KReversiView::setAnimationSpeed(int speed)
m_delay = value;
QMetaObject::invokeMethod(m_qml_root, "setAnimationTime",
Q_ARG(QVariant, value));
m_qml_root->setProperty("chipsAnimationTime", value);
}
KReversiView::~KReversiView()
......@@ -157,10 +156,13 @@ void KReversiView::updateBoard()
}
}
QMetaObject::invokeMethod(m_qml_root, "setLabels",
Q_ARG(QVariant, m_showLabels));
m_qml_root->setProperty("isBoardShowingLabels", m_showLabels);
if (m_hint.isValid()) {
QMetaObject::invokeMethod(m_qml_root, "setChipState",
Q_ARG(QVariant, m_hint.row),
Q_ARG(QVariant, m_hint.col),
Q_ARG(QVariant, "Black"));
QMetaObject::invokeMethod(m_qml_root, "setHint",
Q_ARG(QVariant, m_hint.row),
Q_ARG(QVariant, m_hint.col),
......
......@@ -20,47 +20,32 @@ import org.kde.games.core 0.1 as KgCore
import "globals.js" as Globals
Item {
id: container
id: boardContainer
property bool isShowingLabels: parent.isBoardShowingLabels
property string chipsImagePrefix: parent.chipsImagePrefix
property int chipsAnimationTime: parent.chipsAnimationTime
signal cellClicked(int row, int column)
function setHint(row, column, value) {
cells.itemAt(row * Globals.COLUMN_COUNT + column).setHint(value)
cells.itemAt(row * Globals.COLUMN_COUNT + column).isHint = value
}
function setLegal(row, column, value) {
cells.itemAt(row * Globals.COLUMN_COUNT + column).setLegal(value)
cells.itemAt(row * Globals.COLUMN_COUNT + column).isLegal = value
}
function setChipState(row, column, value) {
cells.itemAt(row * Globals.COLUMN_COUNT + column).setChipState(
value)
}
function setLabels(show) {
board_labels.visible = show;
}
function setChipsPrefix(prefix) {
for (var i = 0; i < Globals.ROW_COUNT; i++)
for (var j = 0; j < Globals.COLUMN_COUNT; j++)
cells.itemAt(i * Globals.COLUMN_COUNT + j).setChipPrefix(
prefix)
cells.itemAt(row * Globals.COLUMN_COUNT + column).chipState = value
}
function setLastMove(row, column, value) {
cells.itemAt(row * Globals.COLUMN_COUNT + column).setLastMove(value)
cells.itemAt(row * Globals.COLUMN_COUNT + column).isLastMove = value
}
function setAnimationTime(value) {
for (var i = 0; i < Globals.ROW_COUNT; i++)
for (var j = 0; j < Globals.COLUMN_COUNT; j++)
cells.itemAt(i * Globals.COLUMN_COUNT + j).setAnimationTime(
value)
}
KgCore.KgItem {
id: board_background
id: boardBackground
z: 0
anchors.fill: parent
provider: themeProvider
......@@ -68,10 +53,10 @@ Item {
}
KgCore.KgItem {
id: board_labels
id: boardLabels
z: 0
anchors.fill: parent
visible: false
visible: isShowingLabels
provider: themeProvider
spriteKey: "board_numbers"
}
......@@ -80,11 +65,11 @@ Item {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
x: Globals.GRID_OFFSET_X_PERCENT * container.width
y: Globals.GRID_OFFSET_Y_PERCENT * container.height
x: Globals.GRID_OFFSET_X_PERCENT * boardContainer.width
y: Globals.GRID_OFFSET_Y_PERCENT * boardContainer.height
width: Globals.GRID_WIDTH_PERCENT * container.width
height: Globals.GRID_HEIGHT_PERCENT * container.height
width: Globals.GRID_WIDTH_PERCENT * boardContainer.width
height: Globals.GRID_HEIGHT_PERCENT * boardContainer.height
Repeater {
id: cells
......@@ -93,19 +78,19 @@ Item {
Cell {
x: (index % Globals.COLUMN_COUNT)
* Globals.GRID_WIDTH_PERCENT
* container.width
* boardContainer.width
/ Globals.COLUMN_COUNT;
y: Math.floor(index / Globals.COLUMN_COUNT)
* Globals.GRID_HEIGHT_PERCENT
* container.height
* boardContainer.height
/ Globals.ROW_COUNT;
width: Globals.GRID_WIDTH_PERCENT * container.width
width: Globals.GRID_WIDTH_PERCENT * boardContainer.width
/ Globals.COLUMN_COUNT
height: Globals.GRID_HEIGHT_PERCENT * container.height
height: Globals.GRID_HEIGHT_PERCENT * boardContainer.height
/ Globals.ROW_COUNT
onClicked: container.cellClicked(index / Globals.COLUMN_COUNT,
onClicked: boardContainer.cellClicked(index / Globals.COLUMN_COUNT,
index % Globals.COLUMN_COUNT)
}
}
......
......@@ -19,61 +19,39 @@ import QtQuick 1.1
import org.kde.games.core 0.1 as KgCore
Item {
id: container
id: cellContainer
signal clicked
function setChipState(new_state) {
reversi_chip.state = new_state
}
function setHint(new_state) {
if (new_state)
reversi_chip.state = "Black_blinking"
else {
if (reversi_chip.state == "Black_blinking")
reversi_chip.state = "Black";
else if (reversi_chip.state == "White_blinking")
reversi_chip.state = "White";
}
}
function setLegal(new_state) {
cell_legal_image.visible = new_state
}
function setChipPrefix(prefix) {
reversi_chip.image_prefix = prefix + "_";
}
function setLastMove(value) {
cell_last_move_marker.visible = value;
}
function setAnimationTime(value) {
reversi_chip.animation_time = value;
}
property bool isLastMove: false
property bool isLegal: false
property bool isHint: false
property string chipImagePrefix: boardContainer.chipsImagePrefix
property int chipAnimationTime: boardContainer.chipsAnimationTime
property string chipState: ""
KgCore.KgItem {
id: cell_legal_image
id: cellLegalImage
z: 1
anchors.fill: parent
visible: false
visible: isLegal
provider: themeProvider
spriteKey: "move_hint"
}
Rectangle {
id: cell_last_move_marker;
id: cellLastMoveMarker;
z: 1
visible: false
visible: isLastMove
anchors.fill: parent
color: "#AAAAAA"
}
ReversiChip {
id: reversi_chip
Chip {
id: reversiChip
z: 2
anchors.fill: parent
onClicked: container.clicked()
state: chipState + (isHint ? "_blinking" : "")
onClicked: cellContainer.clicked()
}
}
......@@ -19,11 +19,11 @@ import QtQuick 1.1
import org.kde.games.core 0.1 as KgCore
Item {
id: container
property int frames_count: 12
property int current_frame: 1
property string image_prefix: "chip_bw_"
property int animation_time: 300
id: chipContainer
property int framesCount: 12
property int currentFrame: 1
property string imagePrefix: parent.chipImagePrefix + "_"
property int animationTime: parent.chipAnimationTime
signal clicked
......@@ -33,17 +33,17 @@ Item {
anchors.fill: parent
visible: false
provider: themeProvider
spriteKey: image_prefix + current_frame
spriteKey: imagePrefix + currentFrame
}
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: container.clicked()
onClicked: chipContainer.clicked()
}
Timer {
id: blinking_timer
id: blinkingTimer
interval: 500
running: false
repeat: true
......@@ -60,12 +60,12 @@ Item {
}
PropertyChanges {
target: container
current_frame: 1
target: chipContainer
currentFrame: 1
}
PropertyChanges {
target: blinking_timer
target: blinkingTimer
running: false
}
},
......@@ -79,12 +79,12 @@ Item {
}
PropertyChanges {
target: container
current_frame: 1
target: chipContainer
currentFrame: 1
}
PropertyChanges {
target: blinking_timer
target: blinkingTimer
running: true
}
},
......@@ -98,12 +98,12 @@ Item {
}
PropertyChanges {
target: container
current_frame: frames_count
target: chipContainer
currentFrame: framesCount
}
PropertyChanges {
target: blinking_timer
target: blinkingTimer
running: false
}
},
......@@ -117,20 +117,20 @@ Item {
}
PropertyChanges {
target: container
current_frame: frames_count
target: chipContainer
currentFrame: framesCount
}
PropertyChanges {
target: blinking_timer
target: blinkingTimer
running: true
}
}
]
Behavior on current_frame {
Behavior on currentFrame {
NumberAnimation {
duration: animation_time
duration: animationTime
easing.type: Easing.InOutQuad
}
}
......
......@@ -20,7 +20,7 @@ import org.kde.games.core 0.1 as KgCore
import org.kde.plasma.core 0.1 as PlasmaCore
Rectangle {
id: container
id: popupContainer
height: row.height + 30
width: row.width + 30
anchors.bottom: undefined
......@@ -76,8 +76,8 @@ Rectangle {
name: "Showing"
AnchorChanges {
target: container
anchors.bottom: container.parent.bottom
target: popupContainer
anchors.bottom: popupContainer.parent.bottom
anchors.top: undefined
}
}
......
......@@ -21,7 +21,11 @@ import "globals.js" as Globals
Item {
anchors.fill: parent
id: container
id: tableContainer
property bool isBoardShowingLabels: false
property string chipsImagePrefix: "chip_bw"
property int chipsAnimationTime: 25 * 12
signal cellClicked(int row, int column)
......@@ -33,26 +37,14 @@ Item {
board.setChipState(row, column, value);
}
function setLabels(show) {
board.setLabels(show);
}
function setHint(row, col, show) {
board.setHint(row, col, show);
}
function setChipsPrefix(prefix) {
board.setChipsPrefix(prefix);
}
function setLastMove(row, column, value) {
board.setLastMove(row, column, value)
}
function setAnimationTime(value) {
board.setAnimationTime(value)
}
function showPopup(text) {
popup.show(text);
}
......@@ -73,7 +65,7 @@ Item {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
onCellClicked: container.cellClicked(row, column)
onCellClicked: tableContainer.cellClicked(row, column)
}
Popup {
......
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