Debian Codegraph @

src/board/gatter.cpp

raw symbols SCIP
1 /***************************************************************************
2 * Copyright (C) 2009 by The qGo Project *
3 * *
4 * This file is part of qGo. *
5 * *
6 * qGo is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, see <http://www.gnu.org/licenses/> *
18 * or write to the Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
21
22 #include "gatter.h"cxx . . $ `<file>/src/board/gatter.h`/
23
24 #include <QGraphicsItem>
25
26 /*************************************************************
27 *
28 * Initialises the gatter intersections and hoshis points
29 *
30 *************************************************************/
31 Gattercxx . . $ Gatter#::Gattercxx . . $ Gatter#Gatter(32be5b8e64b3b51b).(QGraphicsScenecxx . . $ QGraphicsScene# *canvas, int size)
32 {
33 board_sizecxx . . $ Gatter#board_size. = size;
34
35 VGattercxx . . $ Gatter#VGatter..reservecxx . . $ QList#reserve(d4f767463ce0a6b3).(board_sizecxx . . $ Gatter#board_size.*board_sizecxx . . $ Gatter#board_size.);
36 HGattercxx . . $ Gatter#HGatter..reservecxx . . $ QList#reserve(d4f767463ce0a6b3).(board_sizecxx . . $ Gatter#board_size.*board_sizecxx . . $ Gatter#board_size.);
37 QGraphicsLineItemcxx . . $ QGraphicsLineItem# *tmp1;
38 for (int i=0; i<board_sizecxx . . $ Gatter#board_size.*board_sizecxx . . $ Gatter#board_size.; i++)
39 {
40 tmp1 = new QGraphicsLineItemcxx . . $ QGraphicsLineItem#QGraphicsLineItem(af50d9c5bfd58279).(0);
41 canvas->addItemcxx . . $ QGraphicsScene#addItem(af50d9c5bfd58279).(tmp1);
42 VGattercxx . . $ Gatter#VGatter..appendcxx . . $ QList#append(77d9f17553126ecb).(tmp1);
43 tmp1 = new QGraphicsLineItemcxx . . $ QGraphicsLineItem#QGraphicsLineItem(af50d9c5bfd58279).(0);
44 canvas->addItemcxx . . $ QGraphicsScene#addItem(af50d9c5bfd58279).(tmp1);
45 HGattercxx . . $ Gatter#HGatter..appendcxx . . $ QList#append(77d9f17553126ecb).(tmp1);
46 }
47
48 int edge_dist = (board_sizecxx . . $ Gatter#board_size. > 12 ? 4 : 3);
49 int low = edge_dist - 1;
50 int middle = (board_sizecxx . . $ Gatter#board_size. + 1) / 2 - 1;
51 int high = board_sizecxx . . $ Gatter#board_size. - edge_dist;
52 if (board_sizecxx . . $ Gatter#board_size. % 2 && board_sizecxx . . $ Gatter#board_size. >= 9)
53 {
54 hoshisListcxx . . $ Gatter#hoshisList..insertcxx . . $ QMap#insert(929a1ed410fe8423).(middle*board_sizecxx . . $ Gatter#board_size. + middle , new QGraphicsEllipseItemcxx . . $ QGraphicsEllipseItem#QGraphicsEllipseItem(af50d9c5bfd58279).(0));
55 }
56 if (board_sizecxx . . $ Gatter#board_size. % 2 && board_sizecxx . . $ Gatter#board_size. > 13)
57 {
58 hoshisListcxx . . $ Gatter#hoshisList..insertcxx . . $ QMap#insert(929a1ed410fe8423).(middle*board_sizecxx . . $ Gatter#board_size. + low , new QGraphicsEllipseItemcxx . . $ QGraphicsEllipseItem#QGraphicsEllipseItem(af50d9c5bfd58279).(0));
59 hoshisListcxx . . $ Gatter#hoshisList..insertcxx . . $ QMap#insert(929a1ed410fe8423).(middle*board_sizecxx . . $ Gatter#board_size. + high , new QGraphicsEllipseItemcxx . . $ QGraphicsEllipseItem#QGraphicsEllipseItem(af50d9c5bfd58279).(0));
60 hoshisListcxx . . $ Gatter#hoshisList..insertcxx . . $ QMap#insert(929a1ed410fe8423).(low*board_sizecxx . . $ Gatter#board_size. + middle , new QGraphicsEllipseItemcxx . . $ QGraphicsEllipseItem#QGraphicsEllipseItem(af50d9c5bfd58279).(0));
61 hoshisListcxx . . $ Gatter#hoshisList..insertcxx . . $ QMap#insert(929a1ed410fe8423).(high*board_sizecxx . . $ Gatter#board_size. + middle , new QGraphicsEllipseItemcxx . . $ QGraphicsEllipseItem#QGraphicsEllipseItem(af50d9c5bfd58279).(0));
62 }
63 hoshisListcxx . . $ Gatter#hoshisList..insertcxx . . $ QMap#insert(929a1ed410fe8423).(low*board_sizecxx . . $ Gatter#board_size. + low , new QGraphicsEllipseItemcxx . . $ QGraphicsEllipseItem#QGraphicsEllipseItem(af50d9c5bfd58279).(0));
64 hoshisListcxx . . $ Gatter#hoshisList..insertcxx . . $ QMap#insert(929a1ed410fe8423).(high*board_sizecxx . . $ Gatter#board_size. + low , new QGraphicsEllipseItemcxx . . $ QGraphicsEllipseItem#QGraphicsEllipseItem(af50d9c5bfd58279).(0));
65 hoshisListcxx . . $ Gatter#hoshisList..insertcxx . . $ QMap#insert(929a1ed410fe8423).(high*board_sizecxx . . $ Gatter#board_size. + high , new QGraphicsEllipseItemcxx . . $ QGraphicsEllipseItem#QGraphicsEllipseItem(af50d9c5bfd58279).(0));
66 hoshisListcxx . . $ Gatter#hoshisList..insertcxx . . $ QMap#insert(929a1ed410fe8423).(low*board_sizecxx . . $ Gatter#board_size. + high , new QGraphicsEllipseItemcxx . . $ QGraphicsEllipseItem#QGraphicsEllipseItem(af50d9c5bfd58279).(0));
67
68
69 QMapIteratorcxx . . $ QMapIterator#<int,QGraphicsEllipseItemcxx . . $ QGraphicsEllipseItem#*> itcxx . . $ QMapIterator#QMapIterator(1d85e448f11cafa).( hoshisListcxx . . $ Gatter#hoshisList. );
70
71 while ( it.hasNextcxx . . $ QMapIterator#hasNext(50ce9a9e25b4a850).() )
72 {
73 it.nextcxx . . $ QMapIterator#next(5c754f5fbc3bb3d6).();
74 it.valuecxx . . $ QMapIterator#value(bdbd05d619d62250).()->setBrushcxx . . $ QAbstractGraphicsShapeItem#setBrush(ffc9f5d0bda78261).(Qtcxx . . $ QBrush#QBrush(15c18aa000f81c3b).::SolidPatterncxx . . $ Qt/SolidPattern.);
75 it.valuecxx . . $ QMapIterator#value(bdbd05d619d62250).()->setPencxx . . $ QAbstractGraphicsShapeItem#setPen(af0a25dfda3214db).(Qtcxx . . $ QPen#QPen(de7d79e7246fa26d).::NoPencxx . . $ Qt/NoPen.);
76 canvas->addItemcxx . . $ QGraphicsScene#addItem(af50d9c5bfd58279).(it.valuecxx . . $ QMapIterator#value(bdbd05d619d62250).());
77 }
78
79 showAllcxx . . $ Gatter#showAll(49f6e7a06ebc5aa8).();
80 }
81
82 /*
83 * Destroys the gatter
84 */
85 Gattercxx . . $ Gatter#::~cxx . . $ Gatter#`~Gatter`(ced63f7c635d850d).Gattercxx . . $ Gatter#()
86 {
87 qDeleteAllcxx . . $ qDeleteAll(77d9f17553126ecb).(HGattercxx . . $ Gatter#HGatter.);
88 qDeleteAllcxx . . $ qDeleteAll(77d9f17553126ecb).(VGattercxx . . $ Gatter#VGatter.);
89 qDeleteAllcxx . . $ qDeleteAll(77d9f17553126ecb).(hoshisListcxx . . $ Gatter#hoshisList.);
90 }
91
92
93 /*
94 * Calculates the gatter intersections and hoshis position
95 */
96 void Gattercxx . . $ Gatter#::resizecxx . . $ Gatter#resize(b1146eedae1e1d0b).(int offsetX, int offsetY, int square_size)
97 {
98 int size = square_size / 5;
99
100 // Round size top be odd (hoshis)
101 if (size % 2 == 0)
102 size--;
103 if ((size < 7) && (size>2))
104 size = 7;
105 else if (size <= 2)
106 size = 3;
107
108
109 // indexOf accepts coordinated between 1 and board_size, FIXME iterator
110 for (int i=0; i<board_sizecxx . . $ Gatter#board_size.; i++)
111 for (int j=0; j<board_sizecxx . . $ Gatter#board_size.; j++)
112 {
113 HGattercxx . . $ Gatter#HGatter.[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).indexOfcxx . . $ Gatter#indexOf(9b79fb6aee4c0440).(i+1,j+1)]->setLinecxx . . $ QGraphicsLineItem#setLine(52a61fa14d44b641).(int(offsetX + square_size * ( i - 0.5*(i!=0))),
114 offsetY + square_size * j,
115 int(offsetX + square_size * ( i + 0.5 * (i+1 != board_sizecxx . . $ Gatter#board_size.))),
116 offsetY + square_size * j );
117
118 VGattercxx . . $ Gatter#VGatter.[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).indexOfcxx . . $ Gatter#indexOf(9b79fb6aee4c0440).(i+1,j+1)]->setLinecxx . . $ QGraphicsLineItem#setLine(52a61fa14d44b641).(offsetX + square_size * i,
119 int(offsetY + square_size * ( j - 0.5*(j!=0))),
120 offsetX + square_size * i,
121 int(offsetY + square_size * ( j + 0.5 * (j+1 != board_sizecxx . . $ Gatter#board_size.))));
122 }
123
124 QMapIteratorcxx . . $ QMapIterator#<int,QGraphicsEllipseItemcxx . . $ QGraphicsEllipseItem#*> itcxx . . $ QMapIterator#QMapIterator(1d85e448f11cafa).( hoshisListcxx . . $ Gatter#hoshisList. );
125
126 while ( it.hasNextcxx . . $ QMapIterator#hasNext(50ce9a9e25b4a850).() )
127 {
128 it.nextcxx . . $ QMapIterator#next(5c754f5fbc3bb3d6).();
129 int x = it.keycxx . . $ QMapIterator#key(ea465e50d690edfe).() / board_sizecxx . . $ Gatter#board_size.;
130 int y = it.keycxx . . $ QMapIterator#key(ea465e50d690edfe).() % board_sizecxx . . $ Gatter#board_size.;
131 it.valuecxx . . $ QMapIterator#value(bdbd05d619d62250).()->setRectcxx . . $ QGraphicsEllipseItem#setRect(52a61fa14d44b641).(offsetX + square_size * x - size/2,
132 offsetY + square_size * y - size/2,
133 size ,
134 size );
135 }
136 }
137
138 /*
139 * Resets all intersections and hoshis to be shown
140 */
141 void Gattercxx . . $ Gatter#::showAllcxx . . $ Gatter#showAll(49f6e7a06ebc5aa8).()
142 {
143 for (int i=0; i<board_sizecxx . . $ Gatter#board_size.*board_sizecxx . . $ Gatter#board_size.; i++)
144 {
145 VGattercxx . . $ Gatter#VGatter.[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).i]->showcxx . . $ QGraphicsItem#show(49f6e7a06ebc5aa8).();
146 HGattercxx . . $ Gatter#HGatter.[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).i]->showcxx . . $ QGraphicsItem#show(49f6e7a06ebc5aa8).();
147 }
148
149 QMapIteratorcxx . . $ QMapIterator#<int,QGraphicsEllipseItemcxx . . $ QGraphicsEllipseItem#*> itcxx . . $ QMapIterator#QMapIterator(1d85e448f11cafa).( hoshisListcxx . . $ Gatter#hoshisList. );
150
151 while ( it.hasNextcxx . . $ QMapIterator#hasNext(50ce9a9e25b4a850).() )
152 {
153 it.nextcxx . . $ QMapIterator#next(5c754f5fbc3bb3d6).();
154 it.valuecxx . . $ QMapIterator#value(bdbd05d619d62250).()->showcxx . . $ QGraphicsItem#show(49f6e7a06ebc5aa8).();
155 }
156
157 }
158
159 /*
160 * Hides an intersection (when placing a letter mark)
161 */
162 void Gattercxx . . $ Gatter#::hidecxx . . $ Gatter#hide(3e454b8ccf442868).(int x, int y)
163 {
164 if (( x<1) || (x > board_sizecxx . . $ Gatter#board_size.) || ( y<1) || (y > board_sizecxx . . $ Gatter#board_size.))
165 return;
166
167 VGattercxx . . $ Gatter#VGatter.[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).indexOfcxx . . $ Gatter#indexOf(9b79fb6aee4c0440).(x,y)]->hidecxx . . $ QGraphicsItem#hide(49f6e7a06ebc5aa8).();
168 HGattercxx . . $ Gatter#HGatter.[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).indexOfcxx . . $ Gatter#indexOf(9b79fb6aee4c0440).(x,y)]->hidecxx . . $ QGraphicsItem#hide(49f6e7a06ebc5aa8).();
169
170 if (hoshisListcxx . . $ Gatter#hoshisList..containscxx . . $ QMap#contains(8877ebe272b9620d).(indexOfcxx . . $ Gatter#indexOf(9b79fb6aee4c0440).(x,y)))
171 hoshisListcxx . . $ Gatter#hoshisList..valuecxx . . $ QMap#value(866b0a4e5fb46e14).(indexOfcxx . . $ Gatter#indexOf(9b79fb6aee4c0440).(x,y))->hidecxx . . $ QGraphicsItem#hide(49f6e7a06ebc5aa8).();
172 }
173
174 /*
175 * shows an intersection (when removing a letter mark)
176 */
177 void Gattercxx . . $ Gatter#::showcxx . . $ Gatter#show(3e454b8ccf442868).(int x, int y)
178 {
179 if (( x<1) || (x > board_sizecxx . . $ Gatter#board_size.) || ( y<1) || (y > board_sizecxx . . $ Gatter#board_size.))
180 return;
181
182 VGattercxx . . $ Gatter#VGatter.[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).indexOfcxx . . $ Gatter#indexOf(9b79fb6aee4c0440).(x,y)]->showcxx . . $ QGraphicsItem#show(49f6e7a06ebc5aa8).();
183 HGattercxx . . $ Gatter#HGatter.[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).indexOfcxx . . $ Gatter#indexOf(9b79fb6aee4c0440).(x,y)]->showcxx . . $ QGraphicsItem#show(49f6e7a06ebc5aa8).();
184
185 if (hoshisListcxx . . $ Gatter#hoshisList..containscxx . . $ QMap#contains(8877ebe272b9620d).(indexOfcxx . . $ Gatter#indexOf(9b79fb6aee4c0440).(x,y)))
186 hoshisListcxx . . $ Gatter#hoshisList..valuecxx . . $ QMap#value(866b0a4e5fb46e14).(indexOfcxx . . $ Gatter#indexOf(9b79fb6aee4c0440).(x,y))->showcxx . . $ QGraphicsItem#show(49f6e7a06ebc5aa8).();
187 }