Adding rubberband zoom to ChartView via MouseArea - qt

I have a ChartView item declared in QML and I need a rubberband-like zoom functionality. This can be achieved with semi-transparent rectangle and MouseArea item. The problem is with one rectangle it's only possible to select area from top-left to bottom-right due to the fact that Rectangle item with negative dim-s is either invisible or disabled. Although it's possible to apply transform to Rectangle
transform: Scale { origin.x: 0; origin.y: 0; xScale: -1}
I failed to find how to manipulate xScale/yScale properties from the outside.
Right now I draw 4 rectangles, one per each quadrant, with correct xScale/yScale and dims (code in the end).
So I wonder is there more elegant/easy solution to the problem?
ChartView {
id: chartViewTop
...
Rectangle{
id: rubberBandRec1
border.color: "black"
border.width: 1
opacity: 0.3
visible: false
transform: Scale { origin.x: 0; origin.y: 0; yScale: -1}
}
Rectangle{
id: rubberBandRec2
border.color: "black"
border.width: 1
opacity: 0.3
visible: false
transform: Scale { origin.x: 0; origin.y: 0; yScale: -1; xScale: -1}
}
Rectangle{
id: rubberBandRec3
border.color: "black"
border.width: 1
opacity: 0.3
visible: false
transform: Scale { origin.x: 0; origin.y: 0; xScale: -1}
}
Rectangle{
id: rubberBandRec4
border.color: "black"
border.width: 1
opacity: 0.3
visible: false
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onPressed: {
rubberBandRec1.x = mouseX; rubberBandRec1.y = mouseY; rubberBandRec1.visible = true;
rubberBandRec2.x = mouseX; rubberBandRec2.y = mouseY; rubberBandRec2.visible = true;
rubberBandRec3.x = mouseX; rubberBandRec3.y = mouseY; rubberBandRec3.visible = true;
rubberBandRec4.x = mouseX; rubberBandRec4.y = mouseY; rubberBandRec4.visible = true;
}
onMouseXChanged: {
rubberBandRec1.width = mouseX - rubberBandRec1.x;
rubberBandRec2.width = rubberBandRec2.x-mouseX;
rubberBandRec3.width = rubberBandRec3.x-mouseX;
rubberBandRec4.width = mouseX - rubberBandRec4.x;
}
onMouseYChanged: {
rubberBandRec1.height = rubberBandRec1.y - mouseY;
rubberBandRec2.height = rubberBandRec2.y - mouseY;
rubberBandRec3.height = mouseY - rubberBandRec3.y;
rubberBandRec4.height = mouseY - rubberBandRec4.y;
}
onReleased: {
var x = rubberBandRec4.x-(rubberBandRec4.width<0)*Math.abs(rubberBandRec4.width);
var y = rubberBandRec4.y-(rubberBandRec4.height<0)*Math.abs(rubberBandRec4.height);
if (Math.abs(rubberBandRec4.width*rubberBandRec4.height)>100)
chartViewTop.zoomIn(Qt.rect(x, y, Math.abs(rubberBandRec4.width),
Math.abs(rubberBandRec4.height)));
rubberBandRec1.visible = false;
rubberBandRec2.visible = false;
rubberBandRec3.visible = false;
rubberBandRec4.visible = false;
}
}
}

Set external properties for the scaling, and then just change these in the onMouseXChanged and onMouseYChanged events as follows. This appears to be working for me:
property int xScaleZoom: 0
property int yScaleZoom: 0
Rectangle{
id: recZoom
border.color: "steelblue"
border.width: 1
color: "steelblue"
opacity: 0.3
visible: false
transform: Scale { origin.x: 0; origin.y: 0; xScale: xScaleZoom; yScale: yScaleZoom}
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onPressed: {
recZoom.x = mouseX;
recZoom.y = mouseY;
recZoom.visible = true;
}
onMouseXChanged: {
if (mouseX - recZoom.x >= 0) {
xScaleZoom = 1;
recZoom.width = mouseX - recZoom.x;
} else {
xScaleZoom = -1;
recZoom.width = recZoom.x - mouseX;
}
}
onMouseYChanged: {
if (mouseY - recZoom.y >= 0) {
yScaleZoom = 1;
recZoom.height = mouseY - recZoom.y;
} else {
yScaleZoom = -1;
recZoom.height = recZoom.y - mouseY;
}
}
onReleased: {
var x = (mouseX >= recZoom.x) ? recZoom.x : mouseX
var y = (mouseY >= recZoom.y) ? recZoom.y : mouseY
chartView.zoomIn(Qt.rect(x, y, recZoom.width, recZoom.height));
recZoom.visible = false;
}
}

Related

Canvas Drawing in QML - Qt

I have a written a simple program. I am able to see two minor spokes between the angles I am drawing, and I am not sure why.
import QtQuick 2.0
Rectangle {
width: 360
height: 360
Canvas
{
width: 360
height: 360
onPaint:
{
var x = 140
var y = 140
var radius = 140;
var startangle = -90
var endangle = 30
var context = getContext("2d");
for(var j=0; j < 3; j++)
{
context.beginPath();
context.moveTo(x, y);
context.arc(x, y, radius, (startangle)*(Math.PI/180), (endangle)*(Math.PI/180), false) //x, y, radius, startAngle, endAngle, anticlockwise
context.fillStyle = "blue"
context.fill();
startangle += 120
endangle += 120
context.closePath();
}
}
}
}
output:
The expected drawing should not have spokes (stroke lines).

Ext5 : Pie chart being cut off when hovering

I am using Ext5 pie chart.
When I mouse hover the pie chart it is being cut off.
The code for the pie chart is given below.
{
type: 'pie',
field: 'item1',
renderer: function(sprite, config, rendererData, index) {
var record = rendererData.store.getAt(rendererData.series.sprites.indexOf(sprite));
var name = record.get('name');
if(chartObj.baseThemeColors[name]){
var color = chartObj.baseThemeColors[name];
} else {
color = chartObj.getRandomColor();
chartObj.baseThemeColors[name] = color;
}
return Ext.apply(rendererData, {
fill: color
});
return rendererData;
},
subStyle: {
strokeStyle: 'white',
insertPadding: '50',
lineWidth: '0.5'
},
highlight: {
segment: {
margin: 20
}
},
tooltip: {
trackMouse: true,
width: 'auto',
height: 40,
renderer: function(storeItem, item) {
//calculate percentage.
var total = 0;
var idType = storeItem.get('type');
chartStore.each(function(rec) {
total += rec.get('item1');
});
if(storeItem.get('item1') == 0){
this.setTitle('');
}else {
var pct = ((storeItem.get('item1')/total) * 100).toFixed(0);
var tipText = pct + '% (' + storeItem.get('item1') + ' of ' + total + ')<br/>' + storeItem.get('name')
this.setTitle(tipText);
}
}
},
label: {
field: 'name',
display: 'rotate',
font: '14px Arial',
renderer: function(text, sprite, config, rendererData, index){
var item = rendererData.store.getAt(index);
var total = 0,
idType = item.get('type'),
labelText = "";
chartStore.each(function(rec) {
total += rec.get('item1');
});
if(item.get('item1') == 0){
labelText = '';
} else {
var pct = ((item.get('item1') / total) * 100).toFixed(0);
if(pct>1){
labelText = text + ' ' + pct+'%';
} else {
labelText = '';
}
}
return labelText;
}
}
}
Here is the image of the issue.
As you can see top of the 'negative' slice is being cut off when mouse hovering. And I cannot remove that slice moving animation when hovering.
Is there any solution for this?
Thanks in advance.
Try setting
trackMouse: false
Instead of
trackMouse: true

famo.us lightbox demo transition

I'm trying to get a transition that is similar to the lightbox demo that famous has put out. I have a grid layout, when I click a surface in the grid, Id like to have the surface transition, grow in size and be centered in the browser window.
--edit
Here is the demo, what I would like to nail is the flyout of the clicked image from its location to the center of the screen. http://demo.famo.us/lightbox/
I have the following code that I've been using as a basis. http://codepen.io/heyimlance/pen/JooQMX
var Engine = famous.core.Engine;
var Surface = famous.core.Surface;
var GridLayout = famous.views.GridLayout;
var StateModifier = famous.modifiers.StateModifier;
var Transform = famous.core.Transform;
var RenderNode = famous.core.RenderNode;
var Easing = famous.transitions.Easing;
var mainContext = Engine.createContext();
var grid = new GridLayout({
dimensions: [8, 8],
});
var surfaces = [];
grid.sequenceFrom(surfaces);
function newSurface(id) {
var surface = new Surface({
content: id + 1,
properties: {
backgroundColor: "hsl(" + (id * 70 / 64) + ", 60%, 70%)",
lineHeight: '50px',
textAlign: 'center'
}
});
var smod = new StateModifier({
size: [50,50],
transform: Transform.translate(0,0,1),
origin: [.5,.5]
});
var rnode = new RenderNode();
rnode.add(smod).add(surface);
surfaces.push(rnode);
surface.on('click', function() {
console.log(smod)
var zpos = (this.up || this.up == undefined) ? 0 : -180;
if (!zpos) {
this.up = false;
smod.setTransform(Transform.translate(0,0,2000), { curve:Easing.outElastic, duration: 1000 })
gridModifier.setTransform(Transform.translate(0,0,-2000), { curve:Easing.outElastic, duration: 500 })
} else {
this.up = true;
gridModifier.setTransform(Transform.translate(0,0,0), { curve:Easing.outElastic, duration: 400 })
smod.setTransform(Transform.translate(0,0,0), { curve:Easing.outElastic, duration: 1000 })
}
});
}
for(var i = 0; i < 64; i++) {
newSurface(i);
}
var gridModifier = new StateModifier({
size: [400, 400],
align: [.5, .5],
origin: [.5, .5],
transform : Transform.translate(0,0,0),
});
var gridRotate = new StateModifier({
transform : Transform.rotate(0,0,0),
});
mainContext.add(gridModifier).add(grid);
mainContext.setPerspective(1000);
Using your code, I made a few changes to use the Lightbox render contoller at the time of the click. Not sure what transition you would like for the grid and surface, this should give you options to transition as you like.
Here is a codepen of the example
The code:
var Engine = famous.core.Engine;
var Surface = famous.core.Surface;
var GridLayout = famous.views.GridLayout;
var StateModifier = famous.modifiers.StateModifier;
var Transform = famous.core.Transform;
var RenderNode = famous.core.RenderNode;
var RenderController = famous.views.RenderController;
var Lightbox = famous.views.Lightbox;
var Easing = famous.transitions.Easing;
var mainContext = Engine.createContext();
var grid = new GridLayout({
dimensions: [8, 8],
});
var surfaces = [];
var showing;
grid.sequenceFrom(surfaces);
var cmod = new StateModifier({
origin: [0.5, 0.5],
align: [0.5, 0.5]
});
var controller = new Lightbox({
inTransition: true,
outTransition: false,
overlap: true
});
controller.hide();
function newSurface(id) {
var surface = new Surface({
size: [undefined, undefined],
content: id + 1,
properties: {
backgroundColor: "hsl(" + (id * 70 / 64) + ", 60%, 70%)",
lineHeight: '50px',
textAlign: 'center',
cursor: 'pointer'
}
});
surface._smod = new StateModifier({
size: [420,420],
origin: [0.5, 0.5],
align: [0.5, 0.5]
});
surface._rnode = new RenderNode();
surface._rnode.add(surface._smod).add(surface);
surfaces.push(surface);
surface.on('click', function(context, e) {
if (this === showing) {
controller.hide({ curve:Easing.inElastic, duration: 1000 }, function(){
gridModifier.setTransform(Transform.scale(1,1,1),
{ curve:Easing.outElastic, duration: 1000 });
});
showing = null;
} else {
showing = this;
gridModifier.setTransform(Transform.scale(0.001, 0.001, 0.001),
{ curve:Easing.outCurve, duration: 300 });
cmod.setTransform(Transform.translate(0, 0, 0.0001));
controller.show(this._rnode, { curve:Easing.outElastic, duration: 2400 });
}
}.bind(surface, mainContext));
}
for(var i = 0; i < 64; i++) {
newSurface(i);
}
var gridModifier = new StateModifier({
size: [400, 400],
align: [0.5, 0.5],
origin: [0.5, 0.5]
});
mainContext.add(gridModifier).add(grid);
mainContext.add(cmod).add(controller);
mainContext.setPerspective(1000);
I think the best way is to follow "StateModifier" example that you can find in famo.us university : http://famo.us/university/lessons/#/famous-102/transitionables/2
Do a scale :
// animates x- and y-scale to 1
stateModifier.setTransform(
Transform.scale(1, 1, 1),
{ duration : 2000, curve: Easing.outBack }
);
and then a align [0.5, 0.5] :
var alignModifier = new Modifier({
align: [0.5, 0.5]
});
and if you want background to be minified, you have to apply 'scale' modifier too to make all other surfaces smaller.

Random in a memory game with javafx

i'm making a memory game with javafx but i have a little problem, it all works but the random function it chooses random colors but sometimes it chooses three the same colors. I've already started a variable to make it work but please help me!
the part i've already done:
for (aantalkaarten in [1..16]){
var choice = RANDOM.nextInt(
sizeof mogelijkewaarde);
gekozenwaarde[aantalkaarten] = mogelijkewaarde[choice];
for(x in [1..16]){
if (gekozenkaart[aantalkaarten] == gekozenkaart[x]){
counter ++;
}
if (counter == 2){
//HIER MOET IETS KOMEN WAARMEE JE DIE KAART DIE ALS
//DERDE DIE KLEUR KRIJGT WEER OPNIEUW RANDOM EEN KLEUR KRIJGT
}
}
}
And the whole code:
package newpackage;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.control.Button;
import java.util.Random;
var backColor = "lightblue";
var rectangle1: Rectangle;
var rectangle2: Rectangle;
var rectangle3: Rectangle;
var rectangle4: Rectangle;
var rectangle5: Rectangle;
var rectangle6: Rectangle;
var rectangle7: Rectangle;
var rectangle8: Rectangle;
var rectangle9: Rectangle;
var rectangle10: Rectangle;
var rectangle11: Rectangle;
var rectangle12: Rectangle;
var rectangle13: Rectangle;
var rectangle14: Rectangle;
var rectangle15: Rectangle;
var rectangle16: Rectangle;
var kaarten = ["", "red", "red", "red", "red", "red", "red", "red", "red", "red", "red", "red", "red", "red", "red", "red", "red",];
var kaartzichtbaar = [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true];
var gekozenkaart = [0, 0, 0];
var tekst = "beginnen maar";
var aantalclicks = 0;
var kaartkeuze = ["", ""];
var scene: Scene;
var button: Button;
var score = 0;
var gekozenwaarde = ["","","","","","","","","","","","","","","","",""];
var mogelijkewaarde = ["yellow","blue","white","grey","green","pink","magenta","orange"];
var RANDOM = Random{};
var counter =0;
for (aantalkaarten in [1..16]){
var choice = RANDOM.nextInt(
sizeof mogelijkewaarde);
gekozenwaarde[aantalkaarten] = mogelijkewaarde[choice];
for(x in [1..16]){
if (gekozenkaart[aantalkaarten] == gekozenkaart[x]){
counter ++;
}
if (counter == 2){
//HIER MOET IETS KOMEN WAARMEE JE DIE KAART DIE ALS
//DERDE DIE KLEUR KRIJGT WEER OPNIEUW RANDOM EEN KLEUR KRIJGT
}
}
}
function KaartControle() {
if (aantalclicks == 2) {
if (kaartkeuze[0] == kaartkeuze[1]) {
tekst = "goed bezig!";
kaartzichtbaar[gekozenkaart[0]] = false;
kaartzichtbaar[gekozenkaart[1]] = false;
aantalclicks = 0;
score++;
}
}
else if (aantalclicks == 3) {
tekst = "jammer!";
kaarten[gekozenkaart[0]] = "red";
kaarten[gekozenkaart[1]] = "red";
kaarten[gekozenkaart[2]] = "red";
aantalclicks = 0;
score--;
}
if (score == 8) {
tekst = "Hoera!! Het spel is voltooid";
}
}
Stage {
title: "Memory"
scene: Scene {
width: 500
height: 300
fill: bind Color.web(backColor)
content: [
Text {
font: Font {
size: 16
}
x: 10
y: 30
content: bind tekst;
}
Text {
font: Font {
size: 16
}
x: 250
y: 30
content: bind score.toString();
}
button = Button {
translateX: 300
translateY: 150
text: "reset"
visible: true
action: function() {
kaartzichtbaar = [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true];
kaarten = ["", "red", "red", "red", "red", "red", "red", "red", "red", "red", "red", "red", "red", "red", "red", "red", "red",];
aantalclicks = 0;
score = 0;
for (aantalkaarten in [1..16]){
var choice = RANDOM.nextInt(
sizeof mogelijkewaarde);
gekozenwaarde[aantalkaarten] = mogelijkewaarde[choice];
}
}
}
//Kaart 1
rectangle1 = Rectangle {
visible: bind kaartzichtbaar[1]
width: 50
height: 50
x: 10
y: 50
arcWidth: 10
arcHeight: 10
fill: bind Color.web(kaarten[1])
onMouseClicked: function(event) {
if (kaarten[1] == "red") {
kaarten[1] = gekozenwaarde[1];
kaartkeuze[aantalclicks] = gekozenwaarde[1];
gekozenkaart[aantalclicks] = 1;
aantalclicks++;
KaartControle()
}
}
}
//Kaart 2
rectangle2 = Rectangle {
visible: bind kaartzichtbaar[2]
width: 50
height: 50
x: 10
y: 110
arcWidth: 10
arcHeight: 10
fill: bind Color.web(kaarten[2])
onMouseClicked: function(event) {
if (kaarten[2] == "red") {
kaarten[2] = gekozenwaarde[2];
kaartkeuze[aantalclicks] = gekozenwaarde[2];
gekozenkaart[aantalclicks] = 2;
aantalclicks++;
KaartControle()
}
}
}
//Kaart 3
rectangle3 = Rectangle {
visible: bind kaartzichtbaar[3]
width: 50
height: 50
x: 10
y: 170
arcWidth: 10
arcHeight: 10
fill: bind Color.web(kaarten[3])
onMouseClicked: function(event) {
if (kaarten[3] == "red") {
kaarten[3] = gekozenwaarde[3];
kaartkeuze[aantalclicks] = gekozenwaarde[3];
gekozenkaart[aantalclicks] = 3;
aantalclicks++;
KaartControle()
}
}
}
//Kaart 4
rectangle4 = Rectangle {
visible: bind kaartzichtbaar[4]
width: 50
height: 50
x: 10
y: 230
arcWidth: 10
arcHeight: 10
fill: bind Color.web(kaarten[4])
onMouseClicked: function(event) {
if (kaarten[4] == "red") {
kaarten[4] = gekozenwaarde[4];
kaartkeuze[aantalclicks] = gekozenwaarde[4];
gekozenkaart[aantalclicks] = 4;
aantalclicks++;
KaartControle()
}
}
}
//Kaart 5
rectangle5 = Rectangle {
visible: bind kaartzichtbaar[5]
width: 50
height: 50
x: 70
y: 50
arcWidth: 10
arcHeight: 10
fill: bind Color.web(kaarten[5])
onMouseClicked: function(event) {
if (kaarten[5] == "red") {
kaarten[5] = gekozenwaarde[5];
kaartkeuze[aantalclicks] = gekozenwaarde[5];
gekozenkaart[aantalclicks] = 5;
aantalclicks++;
KaartControle()
}
}
}
//Kaart 6
rectangle6 = Rectangle {
visible: bind kaartzichtbaar[6]
width: 50
height: 50
x: 70
y: 110
arcWidth: 10
arcHeight: 10
fill: bind Color.web(kaarten[6])
onMouseClicked: function(event) {
if (kaarten[6] == "red") {
kaarten[6] = gekozenwaarde[6];
kaartkeuze[aantalclicks] = gekozenwaarde[6];
gekozenkaart[aantalclicks] = 6;
aantalclicks++;
KaartControle()
}
}
}
//Kaart 7
rectangle7 = Rectangle {
visible: bind kaartzichtbaar[7]
width: 50
height: 50
x: 70
y: 170
arcWidth: 10
arcHeight: 10
fill: bind Color.web(kaarten[7])
onMouseClicked: function(event) {
if (kaarten[7] == "red") {
kaarten[7] = gekozenwaarde[7];
kaartkeuze[aantalclicks] = gekozenwaarde[7];
gekozenkaart[aantalclicks] = 7;
aantalclicks++;
KaartControle()
}
}
}
//Kaart 8
rectangle8 = Rectangle {
visible: bind kaartzichtbaar[8]
width: 50
height: 50
x: 70
y: 230
arcWidth: 10
arcHeight: 10
fill: bind Color.web(kaarten[8])
onMouseClicked: function(event) {
if (kaarten[8] == "red") {
kaarten[8] = gekozenwaarde[8];
kaartkeuze[aantalclicks] = gekozenwaarde[8];
gekozenkaart[aantalclicks] = 8;
aantalclicks++;
KaartControle()
}
}
}
//Kaart 9
rectangle9 = Rectangle {
visible: bind kaartzichtbaar[9]
width: 50
height: 50 x: 130
y: 50
arcWidth: 10
arcHeight: 10
fill: bind Color.web(kaarten[9])
onMouseClicked: function(event) {
if (kaarten[9] == "red") {
kaarten[9] = gekozenwaarde[9];
kaartkeuze[aantalclicks] = gekozenwaarde[9];
gekozenkaart[aantalclicks] = 9;
aantalclicks++;
KaartControle()
}
}
}
//Kaart 10
rectangle10 = Rectangle {
visible: bind kaartzichtbaar[10]
width: 50
height: 50
x: 130
y: 110
arcWidth: 10
arcHeight: 10
fill: bind Color.web(kaarten[10])
onMouseClicked: function(event) {
if (kaarten[10] == "red") {
kaarten[10] = gekozenwaarde[10];
kaartkeuze[aantalclicks] = gekozenwaarde[10];
gekozenkaart[aantalclicks] = 10;
aantalclicks++;
KaartControle()
}
}
}
//Kaart 11
rectangle11 = Rectangle {
visible: bind kaartzichtbaar[11]
width: 50
height: 50
x: 130
y: 170
arcWidth: 10
arcHeight: 10
fill: bind Color.web(kaarten[11])
onMouseClicked: function(event) {
if (kaarten[11] == "red") {
kaarten[11] = gekozenwaarde[11];
kaartkeuze[aantalclicks] = gekozenwaarde[11];
gekozenkaart[aantalclicks] = 11;
aantalclicks++;
KaartControle()
}
}
}
//Kaart 12
rectangle12 = Rectangle {
visible: bind kaartzichtbaar[12]
width: 50
height: 50
x: 130
y: 230
arcWidth: 10
arcHeight: 10
fill: bind Color.web(kaarten[12])
onMouseClicked: function(event) {
if (kaarten[12] == "red") {
kaarten[12] = gekozenwaarde[12];
kaartkeuze[aantalclicks] = gekozenwaarde[12];
gekozenkaart[aantalclicks] = 12;
aantalclicks++;
KaartControle()
}
}
}
//Kaart 13
rectangle13 = Rectangle {
visible: bind kaartzichtbaar[13]
width: 50
height: 50
x: 190
y: 50
arcWidth: 10
arcHeight: 10
fill: bind Color.web(kaarten[13])
onMouseClicked: function(event) {
if (kaarten[13] == "red") {
kaarten[13] = gekozenwaarde[13];
kaartkeuze[aantalclicks] = gekozenwaarde[13];
gekozenkaart[aantalclicks] = 13;
aantalclicks++;
KaartControle()
}
}
}
//Kaart 14
rectangle14 = Rectangle {
visible: bind kaartzichtbaar[14]
width: 50
height: 50
x: 190
y: 110
arcWidth: 10
arcHeight: 10
fill: bind Color.web(kaarten[14])
onMouseClicked: function(event) {
if (kaarten[14] == "red") {
kaarten[14] = gekozenwaarde[14];
kaartkeuze[aantalclicks] = gekozenwaarde[14];
gekozenkaart[aantalclicks] = 14;
aantalclicks++;
KaartControle()
}
}
}
//Kaart 15
rectangle15 = Rectangle {
visible: bind kaartzichtbaar[15]
width: 50
height: 50
x: 190
y: 170
arcWidth: 10
arcHeight: 10
fill: bind Color.web(kaarten[15])
onMouseClicked: function(event) {
if (kaarten[15] == "red") {
kaarten[15] = gekozenwaarde[15];
kaartkeuze[aantalclicks] = gekozenwaarde[15];
gekozenkaart[aantalclicks] = 15;
aantalclicks++;
KaartControle()
}
}
}
//Kaart 16
rectangle16 = Rectangle {
visible: bind kaartzichtbaar[16]
width: 50
height: 50
x: 190
y: 230
arcWidth: 10
arcHeight: 10
fill: bind Color.web(kaarten[16])
onMouseClicked: function(event) {
if (kaarten[16] == "red") {
kaarten[16] = gekozenwaarde[16];
kaartkeuze[aantalclicks] = gekozenwaarde[16];
gekozenkaart[aantalclicks] = 16;
aantalclicks++; KaartControle()
}
}
}
]
}
}
Hee,
Ik zie dat je ook nederlands bent en mn engels is niet zo goed :)
Maar moet je die memorie voor school maken? Ik moet namelijk precies hetzelfde maken!
Alleen ik heb het op een iets andere manier dan jij gedaan met plaatjes en jij met gekleurde vakjes, maar ik heb het iets anders met plaatjes gedaan maar het komt wel ongeveer op hetzelfde neer. Ik heb het met de shuffle functie gedaan en dan de namen van de plaatjes en bij mij komen ze geen 2keer.
Ik weet niet of je via dit berichtjes kan sturen of dat je je mail wilt geven dan mail ik de code wel eventjes, want mijn leraar is erg goed in google en vind dat als het op internet staat ik het waarschijnlijk niet zelf gemaakt hebt:P
looks this piece of code, may be it's helpful:
// Draws a random 100x100 rectangle in a random color.
import java.awt.*;
import java.util.*;
public class RandomRectangle {
public static void main(String[] args) {
DrawingPanel panel = new DrawingPanel(500, 500);
Graphics g = panel.getGraphics();
Random rand = new Random();
// choose random location
Point rectPoint = new Point();
rectPoint.x = rand.nextInt(500);
rectPoint.y = rand.nextInt(500);
// choose random color
int randomColor = rand.nextInt(3);
if (randomColor == 0) {
g.setColor(Color.RED);
} else if (randomColor == 1) {
g.setColor(Color.GREEN);
} else {
g.setColor(Color.BLUE);
}
g.fillRect(rectPoint.x, rectPoint.y, 100, 100);
}
}

Fix qml item behavior

I have code on qml, which should divide it on 4 squares by click.
import QtQuick 2.0
Rectangle {
Component {
id: squareComponent
Rectangle {
property int sideLenght: 500
width: sideLenght
height: sideLenght
color: "orange"
MouseArea {
anchors.fill: parent
onClicked: {
var first = squareComponent.createObject(parent)
var second = squareComponent.createObject(parent)
var third = squareComponent.createObject(parent)
var fourth = squareComponent.createObject(parent)
var sideLenght = parent.sideLenght / 2
first.sideLenght = sideLenght
second.sideLenght = sideLenght
third.sideLenght = sideLenght
fourth.sideLenght = sideLenght
var x = parent.x
var y = parent.y
console.log(x, y)
first.x = x
first.y = y
first.color = "red"
console.log("first", first.x, first.y)
second.x = first.x + sideLenght
second.y = first.y
second.color = "orange"
console.log("second", second.x, second.y)
third.x = first.x
third.y = first.y + sideLenght
third.color = "blue"
console.log("third", third.x, third.y)
fourth.x = first.x + sideLenght
fourth.y = first.y + sideLenght
fourth.color = "black"
console.log("fourth", fourth.x, fourth.y, "\n\n")
parent.sideLenght = 0
}
}
}
}
Component.onCompleted: squareComponent.createObject(parent)
}
They are divided, but divided only correct square (0, 0), others are with an offset for x or y by the amount of the parent. Qt 5.0.1. How do I fix this behavior, is it a bug?
Logging says that the elements are right, but they are not in fact.
This is what I get as the output with QtQuick 1.1. Is this different in Qt 5.0.1?

Resources