File: flagobj.cpp

package info (click to toggle)
vym 1.8.1-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,000 kB
  • ctags: 1,599
  • sloc: cpp: 14,723; sh: 373; xml: 277; perl: 89; makefile: 16
file content (214 lines) | stat: -rw-r--r-- 3,186 bytes parent folder | download
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
#include "flagobj.h"

/////////////////////////////////////////////////////////////////
// FlagObj
/////////////////////////////////////////////////////////////////
FlagObj::FlagObj()
{
//	cout << "Const FlagObj ()\n";
    init ();
}

FlagObj::FlagObj(QCanvas* c):MapObj(c) 
{
//	cout << "Const FlagObj  canvas="<<c<<endl;
    init ();
}

FlagObj::FlagObj (FlagObj* io)
{
    copy (io);
}

FlagObj::~FlagObj()
{
//    cout << "Destr FlagObj  " << name << "\n";
	if (icon) delete (icon);
}


void FlagObj::init ()
{
	name="undefined";
	group="undefined";

	icon=new ImageObj (canvas);
	icon->move (absPos.x(), absPos.y() );
	button=NULL;
	state=false;
}

void FlagObj::copy (FlagObj* other)
{
    MapObj::copy(other);
	name=other->name;
	group=other->group;
	tooltip=other->tooltip;
	state=other->state;
	icon->copy(other->icon);
	setVisibility (other->isVisibleObj() );
	// button is not copied, because
	// we won't copy to a parentRow and
	// all others don't need a button
}

void FlagObj::move(double x, double y)
{
    MapObj::move(x,y);
	icon->move(x,y);
	positionBBox();
}

void FlagObj::moveBy(double x, double y)
{
    move (x+absPos.x(),y+absPos.y() );
}

void FlagObj::setVisibility (bool v)
{
    MapObj::setVisibility(v);
	if (v && state)
	    icon->setVisibility(true);
	else
	    icon->setVisibility(false);
}

void FlagObj::load (const QString &fn)
{
	icon->load(fn);
	calcBBoxSize();
	positionBBox();
}

void FlagObj::load (const QPixmap &pm)
{
	icon->load(pm);
	calcBBoxSize();
	positionBBox();
}

void FlagObj::setName(const QString &n)
{
	name=n;
}

const QString FlagObj::getName()
{
	return name;
}

void FlagObj::setGroup (const QString &n)
{
	group=n;
}

const QString FlagObj::getGroup()
{
	return group;
}

void FlagObj::setToolTip(const QString &n)
{
	tooltip=n;
}

const QString FlagObj::getToolTip()
{
	return tooltip;
}

void FlagObj::setButton(QAction* b)
{
    button=b;
}

void FlagObj::updateButton()
{
	if (button)
		button->setOn(state);
	else
		qWarning ("FlagObj::updateButton  no button defined");
}

QPixmap FlagObj::getPixmap()
{
	return icon->getPixmap();
}

bool FlagObj::isActive()
{
	return state;
}

void FlagObj::toggle()
{
	if (state)
		deactivate();
	else
		activate();
}

void FlagObj::activate()
{
	state=true;
	// only show icon, if flag itself is visible 
	if (visible) 
	{
		icon->setVisibility (true);
		calcBBoxSize();
	}	
}

void FlagObj::deactivate()
{
	state=false;
	// if flag itself is invisible we don't need to call 
	if (visible) 
	{
		icon->setVisibility (false);
		calcBBoxSize();
	}	
}

void FlagObj::setEnabled(bool b)
{
	button->setEnabled (b);
}	
	

void FlagObj::setUsed (bool b)
{
	used=b;
}

bool FlagObj::isUsed()
{
	return used;
}

void FlagObj::saveToDir (const QString &tmpdir, const QString &prefix)
{
	QString fn=tmpdir + prefix + name + ".png";
	icon->save (fn,"PNG");
}

void FlagObj::positionBBox()
{
    bbox.moveTopLeft (absPos );
    clickBox.moveTopLeft (absPos );
}

void FlagObj::calcBBoxSize()
{
	if (visible && state)
	{
		bbox.setSize (	QSize(
			icon->boundingRect().width(), 
			icon->boundingRect().height() ) );
	} else
	{
		bbox.setSize (QSize(0,0));
	}
	clickBox.setSize (bbox.size());
}