Commit 21e5673d authored by Timothée Giet's avatar Timothée Giet

colors, T188 optimize layout and calculate item size dynamically

parent fe275ad2
...@@ -90,29 +90,49 @@ ActivityBase { ...@@ -90,29 +90,49 @@ ActivityBase {
id: containerModel id: containerModel
} }
function fitItems(x_, y_, n_) {
var sx
var sy
var px = Math.ceil(Math.sqrt(n_ * x_ / y_));
if (Math.floor(px * y_ / x_) * px < n_) {
sx = y / Math.ceil(px * y_ / x_);
} else {
sx = x_ / px;
}
var py = Math.ceil(Math.sqrt(n_ * y_ / x_));
if (Math.floor(py * x_ / y_) * py < n_) {
sy = x_ / Math.ceil(x_ * py / y_);
} else {
sy = y_ / py;
}
return Math.max(sx, sy);
}
GridView { GridView {
id: container id: container
model: containerModel model: containerModel
x: background.width * 0.2 anchors.top: questionItem.bottom
y: background.height * 0.2 anchors.topMargin: score.height * 0.2
width: background.width * 0.7 anchors.bottom: score.top
height: background.height * 0.6 anchors.horizontalCenter: background.horizontalCenter
width: background.width - score.width * 2
interactive: false interactive: false
cellWidth: itemHeight + 10 cellWidth: itemWidth
cellHeight: itemWidth + 10 cellHeight: itemWidth
keyNavigationWraps: true keyNavigationWraps: true
property int itemWidth: Math.min((parent.width * 0.6) / (count / 2), property int itemWidth: fitItems(container.width, container.height, container.count)
(parent.height * 0.5) / (count / 3))
property int itemHeight: itemWidth
delegate: ColorItem { delegate: ColorItem {
audioVoices: activity.audioVoices audioVoices: activity.audioVoices
source: model.image source: model.image
audioSrc: model.audio ? model.audio : "" audioSrc: model.audio ? model.audio : ""
question: model.text question: model.text
sourceSize.height: container.itemHeight sourceSize.height: container.itemWidth * 0.9
sourceSize.width: container.itemWidth sourceSize.width: container.itemWidth * 0.9
} }
add: Transition { add: Transition {
PathAnimation { PathAnimation {
......
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