summaryrefslogtreecommitdiffstats
path: root/src/kbfxtooltip.cpp
blob: 20c1d9ddca2c4958356a79e944747f65f31966e3 (plain)
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*
 *   Copyright (C) 2006
 *   Siraj Razick <[email protected]>
 *   PhobosK <[email protected]>
 *   see Also AUTHORS
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License version 2 as
 *   published by the Free Software Foundation
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "config.h"

#include "kbfxtooltip.h"

KbfxToolTip::KbfxToolTip ( TQWidget * parent, const char *name, WFlags fl ) :
		TQWidget ( parent, name,
		          fl | WStyle_Customize | WRepaintNoErase | WStyle_NoBorder |
		          WDestructiveClose | TQt::WPaintDesktop | TQt::WType_Popup | TQt::
		          WPaintClever | TQt::WNoAutoErase | TQt::WResizeNoErase | TQt::
		          WStaticContents | TQt::WNoAutoErase )
{
	_animate = ConfigInit ().m_ToolTipAnimation;
	m_fontTooltipFont = ConfigInit ().m_fontTooltipFont;

	logo = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit().m_SpinxTooltipLogo ) ) ?
		TQImage ( ConfigInit().m_SpinxTooltipLogo )
		: TQImage ( ConfigInit().m_SpinxTooltipLogoDefault );

	tooltip_win = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit ().m_SpinxTooltipWindow ) ) ?
		TQImage ( ConfigInit ().m_SpinxTooltipWindow )
		: TQImage ( ConfigInit ().m_SpinxTooltipWindowDefault );

	tooltip_mask = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit().m_SpinxTooltipMask ) ) ?
		TQImage ( ConfigInit().m_SpinxTooltipMask )
		: TQImage ( ConfigInit().m_SpinxTooltipMaskDefault );

	dude_img = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit ().m_SpinxDudeImage ) ) ?
		TQImage ( ConfigInit ().m_SpinxDudeImage )
		: TQImage ( ConfigInit ().m_SpinxDudeImageDefault );

	setUserImage ();
	setBoundBox ();
	setBackground ( TQPixmap () );
	setWindow ( TQPixmap () );
	KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit ().m_ToolTipAvatar ) ?
		setAnimationImage ( ConfigInit ().m_ToolTipAvatar )
		: setAnimationImage ( ConfigInit ().m_ToolTipAvatarDefault );

	_hide_timer = new TQTimer ( this );
	_update_timer = new TQTimer ( this );
	_move_timer = new TQTimer ( this );

	connect ( _hide_timer, TQT_SIGNAL ( timeout () ), this, TQT_SLOT ( hide () ) );
	connect ( _hide_timer, TQT_SIGNAL ( timeout () ), _agent, TQT_SLOT ( hide () ) );
	connect ( _update_timer, TQT_SIGNAL ( timeout () ), this, TQT_SLOT ( logoMove () ) );

	TQCursor kbfxCursor;
	kbfxCursor.setShape ( Qt::PointingHandCursor );
	this->setCursor ( ( const TQCursor ) kbfxCursor );
}

KbfxToolTip::~KbfxToolTip ()
{
	delete _hide_timer;
	delete _move_timer;
	delete _update_timer;
	delete _window;
	delete _agent;
	delete _agent_anim;
}

void
KbfxToolTip::setWindow ( TQPixmap win )
{
	TQImage m_win_img;

	( win.isNull () ) ?
		m_win_img = tooltip_win
		: m_win_img = win.convertToImage ();

	m_win_img = m_win_img.smoothScale ( _bg.width (), 13 );
//  _window = new TQLabel (this, "", TQt::WStaticContents | TQt::WNoAutoErase);
	_window = new TQLabel ( this, "" );
	_window->resize ( _bg.width (), 13 );
	TQPixmap pm;
	pm.convertFromImage(m_win_img);
	_window->setBackgroundPixmap ( pm );
	if ( _animate )
		_window->show ();
	else
		_window->hide ();
}

void
KbfxToolTip::setAnimationImage ( TQString path )
{
	/*
	  _agent = new TQLabel (this, "",
			       TQt::WStaticContents |
			       TQt::WNoAutoErase | TQt::WPaintDesktop);
	*/
	_agent = new TQLabel ( this,"" );
	_agent->resize ( 100, 100 );

	_agent_anim = new TQMovie ( path );
	TQPixmap agent_mask = _agent_anim->framePixmap ();
	_agent->setBackgroundPixmap ( agent_mask );
	if ( agent_mask.mask () )
		_agent->setMask ( *agent_mask.mask () );
	_agent->repaint ();

	/*FIXME:Need to remove Hard Coded Values */
	_agent->move ( 200, 0 );

	if ( _animate )
		_agent->show ();
	else
		_agent->close ();
}


void
KbfxToolTip::setBackground ( TQPixmap bg )
{

	( bg.isNull () ) ?
		_bg = tooltip_mask
		: _bg = bg.convertToImage ();

	/* animation check : Auto streatch */
	if ( _animate )
	{
		TQImage m_tmp = _bg;
		_bg = m_tmp.smoothScale ( _bg.width () + 100, _bg.height () );
	}

	TQPixmap pm;
	pm.convertFromImage(_bg);
	this->setBackgroundPixmap ( pm );

	TQPixmap m_tmp ( _bg );
	if ( m_tmp.mask () )
		this->setMask ( ( *m_tmp.mask () ) );
	this->resize ( _bg.width (), _bg.height () );
	_maxW = _bg.width ();
}

void
KbfxToolTip::setStartPos ( int _x_, int _y_ )
{
	_x = _x_;
	_y = _y_;
	_logo_move_x = 100;
	if ( _animate )
	{
		_logo_move_x = 0;
		_hide_timer->start ( 10000, TRUE );
		_move_timer->start ( _agent_anim->speed (), FALSE );
		_update_timer->start ( 2, FALSE );
	}

	move ( _x, _y );
}

void
KbfxToolTip::logoMove ()
{
	TQPainter p;

	if ( _logo_move_x < _bg.width () - 68 )
	{
		_logo_move_x += 1;
		_window->repaint ();

		p.begin ( _window );
		p.drawPixmap ( TQRect ( _logo_move_x, 0, logo.width (), logo.height () ),
		               TQPixmap ( logo ) );
		p.end ();
	}
	else
	{
		p.begin ( _window );
		p.drawPixmap ( TQRect ( _bg.width () - 68, 0, logo.width (), logo.height () ),
		               TQPixmap ( logo ) );
		p.end ();
	}

	TQPixmap agent_mask = _agent_anim->framePixmap ();
	_agent->setBackgroundPixmap ( agent_mask );
	if ( agent_mask.mask () )
		_agent->setMask ( *agent_mask.mask () );
	_agent->repaint ();
}

void
KbfxToolTip::setAnimated ( bool b )
{
	_animate = b;
}


void
KbfxToolTip::setLabelText ( TQString str )
{
	_label_text = str;
}

void
KbfxToolTip::setHeadingText ( TQString str )
{
	_heading_text = str;
}

void
KbfxToolTip::setVersionText ( TQString str )
{
	_version_text = str;
}

void
KbfxToolTip::hideToolTip ()
{
	_move_timer->stop ();
	_hide_timer->stop ();

	_agent->close ();
	this->hide ();
	this->close ();
}


void
KbfxToolTip::setUserImage ()
{
	TQImage userimage = dude_img;
	userimage = userimage.smoothScale ( 48, 48 );
	_dude = TQPixmap ( userimage );
}

void
KbfxToolTip::setBoundBox ()
{
	_dude_box = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit ().m_SpinxTooltipDudebox ) ) ?
		TQPixmap ( ConfigInit ().m_SpinxTooltipDudebox )
		: TQPixmap ( ConfigInit ().m_SpinxTooltipDudeboxDefault );
}


void
KbfxToolTip::paintEvent ( TQPaintEvent * pe )
{

	const TQRect r = pe->rect ();
	TQFont *let = new TQFont (m_fontTooltipFont);

	TQPainter p;
	p.begin ( this );
	p.setBackgroundMode ( Qt::TransparentMode );
	p.drawPixmap ( TQRect ( 7, 16, _dude_box.width (), _dude_box.height () ),
	               _dude_box );
	int _paddingX = ( ( _dude_box.height () - _dude.height () ) / 2 ) + 16;
	p.drawPixmap ( TQRect
	               ( _paddingX - ( 55 - 48 ), _paddingX, _dude.width (),
	                 _dude.height () ), _dude );

	if ( _animate )
	{}
	else
	{

		p.drawPixmap ( TQRect ( 126, 0, logo.width (), logo.height () ),
		               TQPixmap ( TQImage (ConfigInit ().m_SpinxTooltipLogo ) ) );
	}

	let->setBold ( TRUE );
	let->setPointSize ( 10 );
	p.setFont ( *let );
	p.setPen ( TQColor ( 61, 94, 129 ) );
	p.drawText ( _dude_box.width () + 15, 30, TQString("KBFX") );

	p.setPen ( TQColor ( 0, 0, 0 ) );
	let->setBold ( FALSE );
	let->setPointSize ( 8 );
	p.setFont ( *let );
	p.drawText ( ( _animate ) ? _dude_box.width () + 50 : _dude_box.width () + 4,
	             _dude_box.height () + 30, TQString ( "Version " ).append ( APPLICATION_VERSION ) );

	p.setPen ( ConfigInit ().m_fontTooltipColor );
	let->setBold ( TRUE );
	let->setPointSize ( 8 );
	p.setFont ( *let );


	p.drawText ( _dude_box.width () + 15, 43, ConfigInit ().m_ToolTipText );
	p.end ();
	delete let;
}

#include "kbfxtooltip.moc"