1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
//
// C++ Implementation: leitnersystemview
//
// Description:
//
//
// Author: Martin Pfeiffer <martin-pfeiffer-bensheim@web.de>, (C) 2005
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "leitnersystemview.h"
#include "leitnersystem.h"
//#include "kwordquiz.h"
#include <stdlib.h>
#include <kiconloader.h>
#include <tqpainter.h>
#include <kdebug.h>
LeitnerSystemView::LeitnerSystemView(TQWidget * parent, const char* name, WFlags f)
: TQScrollView(parent, name, f)
{
m_highlightedBox = -1;
}
LeitnerSystemView::~LeitnerSystemView()
{
}
void LeitnerSystemView::drawSystem(TQPainter* p)
{
kdDebug() << "drawSystem( )" << endl;
//einarbeiten von m_selectedBox... aus prefLeitner
m_imageY = height() / 2 - 32;
//draw the boxes' icons
for(int i = 0; i < m_leitnerSystem->getNumberOfBoxes(); i++)
{
if(i == m_highlightedBox)
{
//p->drawPixmap(12 + i * 64 + i*10, m_imageY, TDEGlobal::iconLoader()->loadIcon("leitnerbox", TDEIcon::Panel));
p->drawRect(12 + i * 64 + i*10, m_imageY,64,64);
p->fillRect(12 + i * 64 + i*10, m_imageY,64,64, TQBrush(red));
}
else
{ //for each box 74 = 64(pixmap) + 10(distance between two boxes)
//p->drawPixmap(12 + i * 74, m_imageY, TDEGlobal::iconLoader()->loadIcon("leitnerbox", TDEIcon::Panel));
p->drawRect(12 + i * 64 + i*10, m_imageY,64,64);
}
}
}
void LeitnerSystemView::drawConnections(TQPainter* p)
{
//dist = number of boxes that are in between the two boxes
//width = width of the rect for the arc
int dist, width = 0;
int numberOfBoxes = m_leitnerSystem->getNumberOfBoxes();
p->setPen( TQPen(green, 2) );
//paint the connections for the correct word boxes, above the boxes
for(int i = 0; i < numberOfBoxes; i++)
{
dist = m_leitnerSystem->getCorrectBoxNumber( i ) - i;
if(dist <= 0)
{
// (dist*(-1) -1)*64 == for each box in between take 64
// dist*(-1)*10 == the gaps in between
// 2*22; 2*21 == the distances of the endings on the picture
width = (dist*(-1) -1)*64 + dist*(-1)*10 + 2*22 + 2*21;
p->drawArc( 12 + (dist+i)*74 + 21, m_imageY-(width/3), width, /*(height()/2 - 12-32) *2*/ width/3*2, 0, 180*16);
}
else
{
width = (dist-1)*64 + dist*10 + 2*21;
p->drawArc(12 + i*74 + 21+22 ,m_imageY-(width/3) , width, /*(height()/2 - 12-32) *2*/width/3*2, 0, 180*16);
}
}
//paint the connections for the wrong word boxes, below the boxes
p->setPen(TQPen(red, 2));
for(int i = 0; i < numberOfBoxes; i++)
{
dist = m_leitnerSystem->getWrongBoxNumber( i ) - i;
if(dist <= 0)
{
width = (dist*(-1) -1)*64 + dist*(-1)*10 + 2*22 + 2*21;
p->drawArc(12+ (dist+i)*74 + 21 ,m_imageY+64-width/3 , width, width/3*2 , 180*16, 180*16);
}
else
{
width = (dist-1)*64 + dist*10 + 2*21;
p->drawArc(12 + i*74 + 21+22 ,m_imageY+64-width/3 , width, width/3*2, 180*16, 180*16);
}
}
}
void LeitnerSystemView::setSystem(LeitnerSystem* leitnersystem)
{
m_leitnerSystem = leitnersystem;
//calculate the new sizes
calculateSize();
updateContents();
//repaint
//update();
//TQPainter* p = new TQPainter(this);
//drawContents( p, 0, 0, 0, 0 );
}
void LeitnerSystemView::highlightBox(int box)
{
m_highlightedBox = box;
updateContents();
}
void LeitnerSystemView::drawContents(TQPainter* p, int clipx, int clipy, int clipw, int cliph)
{
kdDebug() << "drawContents" << endl;
p->eraseRect(0,0,width(),height());
drawSystem( p );
drawConnections( p );
}
void LeitnerSystemView::calculateSize()
{
//margin = 12
//distance between boxes = 10
//boxes = 64*64
int numberOfBoxes = m_leitnerSystem->getNumberOfBoxes();
TQString x;
int height, dist, tmpMaxC, tmpMaxW;
tmpMaxC = 0;
tmpMaxW = 0;
height = 0;
for(int i = 0; i < numberOfBoxes; i++)
{
dist = m_leitnerSystem->getCorrectBoxNumber( i ) - i;
if( abs(dist) >= abs(tmpMaxC) )
tmpMaxC = dist;
dist = m_leitnerSystem->getWrongBoxNumber( i ) - i;
if( abs(dist) >= abs(tmpMaxW) )
tmpMaxW = dist;
}
if( tmpMaxC <= 0 )
height += (( abs(tmpMaxC) -1)*64 + abs(tmpMaxC)*10 + 2*22 + 2*21)/3;
else
height += (( tmpMaxC-1)*64 + tmpMaxC*10 + 2*21)/3;
if( tmpMaxW <= 0 )
height += (( abs(tmpMaxW) -1)*64 + abs(tmpMaxW)*10 + 2*22 + 2*21)/3;
else
height += (( tmpMaxW-1)*64 + tmpMaxW*10 + 2*21)/3;
height += 24+64;
resizeContents( numberOfBoxes * 64 + (numberOfBoxes - 1)*10 + 2 * 12, height );
setMinimumSize( numberOfBoxes * 64 + (numberOfBoxes - 1)*10 + 2 * 12, height );
}
void LeitnerSystemView::mousePressEvent(TQMouseEvent* e)
{
kdDebug() << "mouseClick" << endl;
//if the user has clicked into a box
if(e->y() > m_imageY && e->y() < m_imageY + 64 && e->x() < width()-13)
{
int d = (e->x()-12)/74;
if((e->x()-12-74*d) <= 64)
{
//signal for prefLeitner to set the comboboxes to the clicked box
emit boxClicked( d );
m_highlightedBox = d;
updateContents();
}
else
{
emit boxClicked( -1 );
m_highlightedBox = -1;
updateContents();
}
}
else
{
emit boxClicked( -1 );
m_highlightedBox = -1;
updateContents();
}
}
#include "leitnersystemview.moc"
|