summaryrefslogtreecommitdiffstats
path: root/src/kbfxspinxtoolbutton.cpp
blob: 3e851e77caf6b65c0a9162943733d6d37db73305 (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
/*
 *   Copyright (C) 2006
 *   Siraj Razick <siraj@kdemail.net>
 *   PhobosK <phobosk@mail.kbfx.net>
 *   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 "kbfxspinxtoolbutton.h"

KbfxSpinxToolButton::KbfxSpinxToolButton ( TQWidget * parent , const char * name ) :TQLabel ( parent,name,TQt::WStaticContents | TQt::WNoAutoErase |TQt::WPaintDesktop )
{
	m_dataSource = 0;
	m_dataGroup  = 0;
	m_fadeTime = ConfigInit().m_fadeTime;

	fade_timer = new TQTimer ( this,"Fade Timer" );
	connect ( fade_timer,TQT_SIGNAL ( timeout() ),this,TQT_SLOT ( fade() ) );
}


KbfxSpinxToolButton::~KbfxSpinxToolButton()
{}

void KbfxSpinxToolButton::fade ( )
{
	if ( m_fadeTime == 0 )
	{
		m_current = m_fadePix;
	}
	else
	{
		TQImage _final = m_fadePix.convertToImage ();
		TQImage _current = m_current.convertToImage ();

		if ( !fade_timer->isActive ())
		{
			m_opacity = 0;
			fade_timer->start( m_fadeTime, false);
		}
		if ( m_opacity > 0.9 )
			fade_timer->stop();
		m_opacity += 0.1;

		KImageEffect::blend   ( _final, _current, m_opacity);
		m_current = TQPixmap ( _current );
 }
	this->resize ( m_current.size() );
	this->update();
}

void
KbfxSpinxToolButton::enterEvent ( TQEvent * e )
{
	e = e;
	m_fadePix = m_hover;
	fade();
	this->setCursor ( TQCursor ( TQt::PointingHandCursor ) );
}

void
KbfxSpinxToolButton::leaveEvent ( TQEvent * e )
{
	e = e;
	m_fadePix = m_normal;
	fade();
	this->setCursor ( TQCursor ( TQt::ArrowCursor ) );
}

void
KbfxSpinxToolButton::setPixmaps ( TQPixmap normal, TQPixmap hover )
{
	TQSize _sizeNormal = normal.size();
	TQImage _tmpHover = hover.convertToImage ();
	_tmpHover = _tmpHover.smoothScale ( _sizeNormal, TQ_ScaleFree );

	m_normal = normal;
	m_hover = TQPixmap ( _tmpHover );
	m_current = m_normal;

	resize ( m_current.size () );
	this->repaint();
	this->update();
}


void
KbfxSpinxToolButton::setDataSource ( KbfxDataSource * src )
{
	m_name = src->name();
	m_icon = src->icon();
	m_exe = src->command();
	m_dataSource = new KbfxDataSource();
	*m_dataSource  = *src; // copy
	TDEIconLoader *iconload = TDEGlobal::iconLoader ();
	TQString m_iconPath =  iconload->iconPath ( m_icon, TDEIcon::Desktop, false );
	m_iconPixmap = TQPixmap ( m_iconPath );
}

void
KbfxSpinxToolButton::paintEvent ( TQPaintEvent * e )
{
	TQRect r = e->rect();
	TQPainter p;
	TQPixmap buffer ( m_current.size() );
	buffer.fill();
	p.begin ( this );
	p.setPen ( TQColor ( 255,255,255 ) );
	p.drawPixmap ( TQRect ( 0, 0, m_current.width(), m_current.height() ), m_current );
	p.end();
}


void
KbfxSpinxToolButton::mouseReleaseEvent ( TQMouseEvent * me )
{
	me = me;
	if ( m_dataSource == 0 )
		return;
	else
		KRun::runCommand ( m_dataSource->command() );

	emit clicked();
}

#include "kbfxspinxtoolbutton.moc"