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

KbfxSpinxScrollBar::KbfxSpinxScrollBar ( TQWidget * parent, const char *name, int type ) :
		TQWidget ( parent, name )
{
    if (type == 0){
	m_normal = ( *KbfxPlasmaPixmapProvider::pixmap ( "scrollnormal" ) );
    } else {
        m_normal = ( *KbfxPlasmaPixmapProvider::pixmap ( "scrollnormalbot" ) );
    }
        TQImage _tmp_img = m_normal.convertToImage();
	_tmp_img = _tmp_img.smoothScale ( ConfigInit().m_itemView_w, m_normal.height (),TQ_ScaleFree );
	m_normal = TQPixmap ( _tmp_img );

	this->resize ( m_normal.width (), m_normal.height () );

	_x = this->x () /40;
	_y = this->y ();
	w = this->width () / 40;
	h = this->height () / 2;
	_x += ( this->width () - w ) / 2;
	_y += ( this->height () - h ) / 2;
	m_triAngle = TQPointArray ( 3 );
	m_dir = DOWN;
	m_timer = new TQTimer ( this,"ScrollTimer" );
	connect ( m_timer,TQT_SIGNAL ( timeout() ),this,TQT_SLOT ( timeoutslot() ) );
	m_pressed = false;

}

KbfxSpinxScrollBar::~KbfxSpinxScrollBar ()
{}

void
KbfxSpinxScrollBar::paintEvent ( TQPaintEvent * pe )
{
	TQRect r = pe->rect();
	TQPainter p;
	p.begin ( this );
	p.drawPixmap ( TQRect ( 0, 0, m_normal.width (), m_normal.height () ),
	               m_normal );
	p.setPen ( TQColor ( 255,255,255 ) );
	if ( m_pressed == false )
		p.setBrush ( TQColor ( 255,255,255 ) );
	else
		p.setBrush ( TQColor ( 0,0,0 ) );

	p.drawPolygon ( m_triAngle );
	p.end ();

}

void
KbfxSpinxScrollBar::setType ( Direction dir )
{
	if ( dir == DOWN )
	{
		m_triAngle.setPoint ( 0, _x, _y );
		m_triAngle.setPoint ( 1, _x + w, _y );
		m_triAngle.setPoint ( 2, _x + w / 2, _y + h );

	}
	else if ( dir == UP )
	{
		m_triAngle.setPoint ( 0, _x, _y + h );
		m_triAngle.setPoint ( 1, _x + w, _y + h );
		m_triAngle.setPoint ( 2, _x + w / 2, _y );
	}
	m_dir = dir;
}


void
KbfxSpinxScrollBar::mousePressEvent ( TQMouseEvent * me )
{
	me = me;
	m_pressed = true;
	m_timer->start ( 50,false );
	update();
}

void
KbfxSpinxScrollBar::mouseReleaseEvent ( TQMouseEvent * me )
{
	me = me;
	m_pressed = false;
	m_timer->stop();
	update();
}


void
KbfxSpinxScrollBar::enterEvent ( TQEvent * e )
{
	e = e;
	m_pressed = true;
	m_timer->start ( 50,false );
	update();
}

void
KbfxSpinxScrollBar::leaveEvent ( TQEvent *e )
{
	e  =e ;
	m_pressed = false;
	m_timer->stop();
	update();

}


void
KbfxSpinxScrollBar::timeoutslot()
{
	if ( m_dir == DOWN )
		emit scroll ( 0,20 );
	else if ( m_dir == UP )
		emit scroll ( 0,-20 );
}

#include "kbfxspinxscrollbar.moc"