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
|
/**************************************************************************
ktrianglebutton.cpp - The KTriangleButton widget (button with an arrow)
Copyright (C) 1998 Antonio Larrosa Jimenez
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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 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.
Send comments and bug fixes to larrosa@kde.org
or to Antonio Larrosa, Rio Arnoya, 10 5B, 29006 Malaga, Spain
Note: This widget was based on KButton as found in the tdelibs/tdeui
KButton was originally copyrighted by Torben Weis (weis@kde.org)
and Matthias Ettrich (ettrich@kde.org) on 1997
***************************************************************************/
#include "ktrianglebutton.h"
#include <tqpainter.h>
#include <tqdrawutil.h>
#include <tqstyle.h>
KTriangleButton::KTriangleButton( Direction d,TQWidget *_parent, const char *name )
: TQButton( _parent , name)
{
dir=d;
raised = FALSE;
setFocusPolicy( TQ_NoFocus );
}
KTriangleButton::~KTriangleButton()
{
}
void KTriangleButton::enterEvent( TQEvent* )
{
if ( isEnabled() )
{
raised = TRUE;
repaint(FALSE);
}
}
void KTriangleButton::leaveEvent( TQEvent * )
{
if( raised != FALSE )
{
raised = FALSE;
repaint();
}
}
void KTriangleButton::drawButton( TQPainter *_painter )
{
paint( _painter );
}
void KTriangleButton::drawButtonLabel( TQPainter *_painter )
{
paint( _painter );
}
void KTriangleButton::paint( TQPainter *painter )
{
if ( isDown() || isOn() )
{
if ( tqstyle().styleHint(TQStyle::SH_GUIStyle) == WindowsStyle )
qDrawWinButton( painter, 0, 0, width(),
height(), colorGroup(), TRUE );
else
qDrawShadePanel( painter, 0, 0, width(),
height(), colorGroup(), TRUE, 2, 0L );
}
else if ( raised )
{
if ( tqstyle().styleHint(TQStyle::SH_GUIStyle) == WindowsStyle )
qDrawWinButton( painter, 0, 0, width(), height(),
colorGroup(), FALSE );
else
qDrawShadePanel( painter, 0, 0, width(), height(),
colorGroup(), FALSE, 2, 0L );
}
if (dir==Right)
{
int x=width()/4;
int y=height()/6;
int l=height()-y*2;
int i=0;
int maxi=width()-2*x;
double m=(double)(l/2)/maxi;
while (i<=maxi)
{
painter->drawLine(x,y+(int)(i*m),x,y+l-(int)(i*m));
x++;
i++;
};
}
else if (dir==Left)
{
int x=width()/4;
int y=height()/6;
int l=height()-y*2;
int i=0;
int maxi=width()-2*x;
x=width()-x;
double m=(double)(l/2)/maxi;
while (i<=maxi)
{
painter->drawLine(x,y+(int)(i*m),x,y+l-(int)(i*m));
x--;
i++;
};
};
}
void KTriangleButton::mousePressEvent(TQMouseEvent *e)
{
TQButton::mousePressEvent(e);
usingTimer=true;
startTimer(500);
timeCount=0;
}
void KTriangleButton::mouseReleaseEvent(TQMouseEvent *e)
{
usingTimer=false;
TQButton::mouseReleaseEvent(e);
}
void KTriangleButton::timerEvent(TQTimerEvent *)
{
if (!usingTimer) {TQT_TQOBJECT(this)->killTimers();return;};
if (timeCount==0)
{
timeCount++;
TQT_TQOBJECT(this)->killTimers();
startTimer(120);
} else
if (timeCount==30)
{
timeCount=-1;
TQT_TQOBJECT(this)->killTimers();
startTimer(80);
}
else if (timeCount>0) timeCount++;
emit clickedQuickly();
}
#include "ktrianglebutton.moc"
|