From e2de64d6f1beb9e492daf5b886e19933c1fa41dd Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdemultimedia@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kmid/ktrianglebutton.cpp | 164 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 kmid/ktrianglebutton.cpp (limited to 'kmid/ktrianglebutton.cpp') diff --git a/kmid/ktrianglebutton.cpp b/kmid/ktrianglebutton.cpp new file mode 100644 index 00000000..61e1af96 --- /dev/null +++ b/kmid/ktrianglebutton.cpp @@ -0,0 +1,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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 kdelibs/kdeui + KButton was originally copyrighted by Torben Weis (weis@kde.org) + and Matthias Ettrich (ettrich@kde.org) on 1997 + +***************************************************************************/ +#include "ktrianglebutton.h" +#include +#include +#include + +KTriangleButton::KTriangleButton( Direction d,QWidget *_parent, const char *name ) + : QButton( _parent , name) +{ + dir=d; + raised = FALSE; + setFocusPolicy( NoFocus ); +} + +KTriangleButton::~KTriangleButton() +{ +} + +void KTriangleButton::enterEvent( QEvent* ) +{ + if ( isEnabled() ) + { + raised = TRUE; + repaint(FALSE); + } +} + +void KTriangleButton::leaveEvent( QEvent * ) +{ + if( raised != FALSE ) + { + raised = FALSE; + repaint(); + } +} + + +void KTriangleButton::drawButton( QPainter *_painter ) +{ + paint( _painter ); +} + +void KTriangleButton::drawButtonLabel( QPainter *_painter ) +{ + paint( _painter ); +} + +void KTriangleButton::paint( QPainter *painter ) +{ + if ( isDown() || isOn() ) + { + if ( style().styleHint(QStyle::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 ( style().styleHint(QStyle::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(QMouseEvent *e) +{ + QButton::mousePressEvent(e); + usingTimer=true; + startTimer(500); + timeCount=0; + +} + +void KTriangleButton::mouseReleaseEvent(QMouseEvent *e) +{ + usingTimer=false; + QButton::mouseReleaseEvent(e); +} + +void KTriangleButton::timerEvent(QTimerEvent *) +{ + if (!usingTimer) {killTimers();return;}; + if (timeCount==0) + { + timeCount++; + killTimers(); + startTimer(120); + } else + if (timeCount==30) + { + timeCount=-1; + killTimers(); + startTimer(80); + } + else if (timeCount>0) timeCount++; + emit clickedQuickly(); + +} +#include "ktrianglebutton.moc" -- cgit v1.2.1