You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
4.0 KiB
165 lines
4.0 KiB
15 years ago
|
/**************************************************************************
|
||
|
|
||
|
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
|
||
15 years ago
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
15 years ago
|
|
||
|
Send comments and bug fixes to larrosa@kde.org
|
||
|
or to Antonio Larrosa, Rio Arnoya, 10 5B, 29006 Malaga, Spain
|
||
|
|
||
13 years ago
|
Note: This widget was based on KButton as found in the tdelibs/tdeui
|
||
15 years ago
|
KButton was originally copyrighted by Torben Weis (weis@kde.org)
|
||
|
and Matthias Ettrich (ettrich@kde.org) on 1997
|
||
|
|
||
|
***************************************************************************/
|
||
|
#include "ktrianglebutton.h"
|
||
15 years ago
|
#include <tqpainter.h>
|
||
|
#include <tqdrawutil.h>
|
||
|
#include <tqstyle.h>
|
||
15 years ago
|
|
||
15 years ago
|
KTriangleButton::KTriangleButton( Direction d,TQWidget *_parent, const char *name )
|
||
|
: TQButton( _parent , name)
|
||
15 years ago
|
{
|
||
|
dir=d;
|
||
|
raised = FALSE;
|
||
14 years ago
|
setFocusPolicy( TQ_NoFocus );
|
||
15 years ago
|
}
|
||
|
|
||
|
KTriangleButton::~KTriangleButton()
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
void KTriangleButton::enterEvent( TQEvent* )
|
||
15 years ago
|
{
|
||
|
if ( isEnabled() )
|
||
|
{
|
||
|
raised = TRUE;
|
||
13 years ago
|
repaint(FALSE);
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KTriangleButton::leaveEvent( TQEvent * )
|
||
15 years ago
|
{
|
||
|
if( raised != FALSE )
|
||
|
{
|
||
|
raised = FALSE;
|
||
13 years ago
|
repaint();
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void KTriangleButton::drawButton( TQPainter *_painter )
|
||
15 years ago
|
{
|
||
|
paint( _painter );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KTriangleButton::drawButtonLabel( TQPainter *_painter )
|
||
15 years ago
|
{
|
||
|
paint( _painter );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KTriangleButton::paint( TQPainter *painter )
|
||
15 years ago
|
{
|
||
|
if ( isDown() || isOn() )
|
||
|
{
|
||
13 years ago
|
if ( style().styleHint(TQStyle::SH_GUIStyle) == WindowsStyle )
|
||
15 years ago
|
qDrawWinButton( painter, 0, 0, width(),
|
||
13 years ago
|
height(), colorGroup(), TRUE );
|
||
15 years ago
|
else
|
||
|
qDrawShadePanel( painter, 0, 0, width(),
|
||
13 years ago
|
height(), colorGroup(), TRUE, 2, 0L );
|
||
15 years ago
|
}
|
||
|
else if ( raised )
|
||
|
{
|
||
13 years ago
|
if ( style().styleHint(TQStyle::SH_GUIStyle) == WindowsStyle )
|
||
15 years ago
|
qDrawWinButton( painter, 0, 0, width(), height(),
|
||
13 years ago
|
colorGroup(), FALSE );
|
||
15 years ago
|
else
|
||
|
qDrawShadePanel( painter, 0, 0, width(), height(),
|
||
13 years ago
|
colorGroup(), FALSE, 2, 0L );
|
||
15 years ago
|
}
|
||
|
|
||
|
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++;
|
||
|
};
|
||
|
|
||
|
};
|
||
|
|
||
|
}
|
||
|
|
||
15 years ago
|
void KTriangleButton::mousePressEvent(TQMouseEvent *e)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQButton::mousePressEvent(e);
|
||
15 years ago
|
usingTimer=true;
|
||
|
startTimer(500);
|
||
|
timeCount=0;
|
||
|
|
||
|
}
|
||
|
|
||
15 years ago
|
void KTriangleButton::mouseReleaseEvent(TQMouseEvent *e)
|
||
15 years ago
|
{
|
||
|
usingTimer=false;
|
||
15 years ago
|
TQButton::mouseReleaseEvent(e);
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KTriangleButton::timerEvent(TQTimerEvent *)
|
||
15 years ago
|
{
|
||
14 years ago
|
if (!usingTimer) {TQT_TQOBJECT(this)->killTimers();return;};
|
||
15 years ago
|
if (timeCount==0)
|
||
|
{
|
||
|
timeCount++;
|
||
14 years ago
|
TQT_TQOBJECT(this)->killTimers();
|
||
15 years ago
|
startTimer(120);
|
||
|
} else
|
||
|
if (timeCount==30)
|
||
|
{
|
||
|
timeCount=-1;
|
||
14 years ago
|
TQT_TQOBJECT(this)->killTimers();
|
||
15 years ago
|
startTimer(80);
|
||
|
}
|
||
|
else if (timeCount>0) timeCount++;
|
||
|
emit clickedQuickly();
|
||
|
|
||
|
}
|
||
|
#include "ktrianglebutton.moc"
|