~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to kmid/ktrianglebutton.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************************
 
2
 
 
3
    ktrianglebutton.cpp  - The KTriangleButton widget (button with an arrow)
 
4
    Copyright (C) 1998  Antonio Larrosa Jimenez
 
5
 
 
6
    This program is free software; you can redistribute it and/or modify
 
7
    it under the terms of the GNU General Public License as published by
 
8
    the Free Software Foundation; either version 2 of the License, or
 
9
    (at your option) any later version.
 
10
 
 
11
    This program is distributed in the hope that it will be useful,
 
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
    GNU General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU General Public License
 
17
    along with this program; if not, write to the Free Software
 
18
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 
 
20
    Send comments and bug fixes to larrosa@kde.org
 
21
    or to Antonio Larrosa, Rio Arnoya, 10 5B, 29006 Malaga, Spain
 
22
 
 
23
    Note: This widget was based on KButton as found in the kdelibs/kdeui
 
24
    KButton was originally copyrighted by Torben Weis (weis@kde.org)
 
25
    and Matthias Ettrich (ettrich@kde.org) on 1997
 
26
     
 
27
***************************************************************************/
 
28
#include "ktrianglebutton.h"
 
29
#include <qpainter.h>
 
30
#include <qdrawutil.h>
 
31
 
 
32
KTriangleButton::KTriangleButton( Direction d,QWidget *_parent, const char *name )
 
33
    : QButton( _parent , name)
 
34
{
 
35
    dir=d;
 
36
    raised = FALSE;
 
37
    setFocusPolicy( NoFocus );
 
38
}
 
39
 
 
40
KTriangleButton::~KTriangleButton()
 
41
{
 
42
}
 
43
 
 
44
void KTriangleButton::enterEvent( QEvent* )
 
45
{
 
46
  if ( isEnabled() )
 
47
    {
 
48
      raised = TRUE;
 
49
      repaint(FALSE);
 
50
    }
 
51
}
 
52
 
 
53
void KTriangleButton::leaveEvent( QEvent * )
 
54
{
 
55
  if( raised != FALSE )
 
56
    {
 
57
      raised = FALSE;
 
58
      repaint();
 
59
    }
 
60
}
 
61
    
 
62
 
 
63
void KTriangleButton::drawButton( QPainter *_painter )
 
64
{
 
65
  paint( _painter );
 
66
}
 
67
 
 
68
void KTriangleButton::drawButtonLabel( QPainter *_painter )
 
69
{
 
70
  paint( _painter );
 
71
}
 
72
 
 
73
void KTriangleButton::paint( QPainter *painter )
 
74
{
 
75
  if ( isDown() || isOn() )
 
76
    {
 
77
      if ( style().guiStyle() == WindowsStyle )
 
78
        qDrawWinButton( painter, 0, 0, width(), 
 
79
                        height(), colorGroup(), TRUE );
 
80
      else
 
81
        qDrawShadePanel( painter, 0, 0, width(), 
 
82
                         height(), colorGroup(), TRUE, 2, 0L );
 
83
    }
 
84
  else if ( raised )
 
85
    {
 
86
      if ( style().guiStyle() == WindowsStyle )
 
87
        qDrawWinButton( painter, 0, 0, width(), height(), 
 
88
                        colorGroup(), FALSE );
 
89
      else
 
90
        qDrawShadePanel( painter, 0, 0, width(), height(), 
 
91
                         colorGroup(), FALSE, 2, 0L );
 
92
    }
 
93
  
 
94
  if (dir==Right)
 
95
  {
 
96
      int x=width()/4;
 
97
      int y=height()/6;
 
98
      int l=height()-y*2;
 
99
      int i=0;
 
100
      int maxi=width()-2*x;
 
101
      double m=(double)(l/2)/maxi;
 
102
      while (i<=maxi)
 
103
      {
 
104
          painter->drawLine(x,y+(int)(i*m),x,y+l-(int)(i*m));
 
105
          x++;
 
106
          i++;
 
107
      };
 
108
  }
 
109
  else if (dir==Left)
 
110
  {
 
111
      int x=width()/4;
 
112
      int y=height()/6;
 
113
      int l=height()-y*2;
 
114
      int i=0;
 
115
      int maxi=width()-2*x;
 
116
      x=width()-x;
 
117
      double m=(double)(l/2)/maxi;
 
118
      while (i<=maxi)
 
119
      {
 
120
          painter->drawLine(x,y+(int)(i*m),x,y+l-(int)(i*m));
 
121
          x--;
 
122
          i++;
 
123
      };
 
124
 
 
125
  };
 
126
  
 
127
}
 
128
 
 
129
void KTriangleButton::mousePressEvent(QMouseEvent *e)
 
130
{
 
131
    QButton::mousePressEvent(e);
 
132
    usingTimer=true;
 
133
    startTimer(500);
 
134
    timeCount=0;
 
135
 
 
136
}
 
137
 
 
138
void KTriangleButton::mouseReleaseEvent(QMouseEvent *e)
 
139
{
 
140
    usingTimer=false;
 
141
    QButton::mouseReleaseEvent(e);
 
142
};
 
143
 
 
144
void KTriangleButton::timerEvent(QTimerEvent *)
 
145
{
 
146
    if (!usingTimer) {killTimers();return;};
 
147
    if (timeCount==0)
 
148
    {
 
149
        timeCount++;
 
150
        killTimers();
 
151
        startTimer(120);
 
152
    } else
 
153
        if (timeCount==30)
 
154
        {
 
155
            timeCount=-1;
 
156
            killTimers();
 
157
            startTimer(80);
 
158
        }
 
159
    else if (timeCount>0) timeCount++;
 
160
    emit clickedQuickly();
 
161
    
 
162
}
 
163
#include "ktrianglebutton.moc"