• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
karrowbutton.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2001 Frerich Raabe <raabe@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "karrowbutton.h"
20 
21 #include <tqstyle.h>
22 #include <tqpainter.h>
23 
24 class KArrowButtonPrivate
25 {
26  public:
27  Qt::ArrowType arrow;
28 };
29 
30 KArrowButton::KArrowButton(TQWidget *parent, Qt::ArrowType arrow,
31  const char *name)
32  : TQPushButton(parent, name)
33 {
34  d = new KArrowButtonPrivate();
35  d->arrow = arrow;
36 }
37 
38 KArrowButton::~KArrowButton()
39 {
40  delete d;
41 }
42 
43 TQSize KArrowButton::sizeHint() const
44 {
45  return TQSize( 12, 12 );
46 }
47 
48 void KArrowButton::setArrowType(Qt::ArrowType a)
49 {
50  if (d->arrow != a) {
51  d->arrow = a;
52  repaint();
53  }
54 }
55 Qt::ArrowType KArrowButton::arrowType() const
56 {
57  return d->arrow;
58 }
59 
60 void KArrowButton::drawButton(TQPainter *p)
61 {
62  const unsigned int arrowSize = 8;
63  const unsigned int margin = 2;
64 
65  p->fillRect( rect(), colorGroup().brush( TQColorGroup::Background ) );
66  style().tqdrawPrimitive( TQStyle::PE_Panel, p, TQRect( 0, 0, width(), height() ),
67  colorGroup(),
68  isDown() ? TQStyle::Style_Sunken : TQStyle::Style_Default,
69  TQStyleOption( 2, 0 ) );
70 
71  if (static_cast<unsigned int>(width()) < arrowSize + margin ||
72  static_cast<unsigned int>(height()) < arrowSize + margin)
73  return; // don't draw arrows if we are too small
74 
75  unsigned int x = 0, y = 0;
76  if (d->arrow == DownArrow) {
77  x = (width() - arrowSize) / 2;
78  y = height() - (arrowSize + margin);
79  } else if (d->arrow == UpArrow) {
80  x = (width() - arrowSize) / 2;
81  y = margin;
82  } else if (d->arrow == RightArrow) {
83  x = width() - (arrowSize + margin);
84  y = (height() - arrowSize) / 2;
85  } else { // arrowType == LeftArrow
86  x = margin;
87  y = (height() - arrowSize) / 2;
88  }
89 
90  if (isDown()) {
91  x++;
92  y++;
93  }
94 
95  TQStyle::PrimitiveElement e = TQStyle::PE_ArrowLeft;
96  switch (d->arrow)
97  {
98  case Qt::LeftArrow: e = TQStyle::PE_ArrowLeft; break;
99  case Qt::RightArrow: e = TQStyle::PE_ArrowRight; break;
100  case Qt::UpArrow: e = TQStyle::PE_ArrowUp; break;
101  case Qt::DownArrow: e = TQStyle::PE_ArrowDown; break;
102  }
103  int flags = TQStyle::Style_Enabled;
104  if ( isDown() )
105  flags |= TQStyle::Style_Down;
106  style().tqdrawPrimitive( e, p, TQRect( TQPoint( x, y ), TQSize( arrowSize, arrowSize ) ),
107  colorGroup(), flags );
108 }
109 
110 void KArrowButton::virtual_hook( int, void* )
111 { /*BASE::virtual_hook( id, data );*/ }
112 
113 #include "karrowbutton.moc"
KArrowButton::sizeHint
virtual TQSize sizeHint() const
Reimplemented from TQPushButton.
Definition: karrowbutton.cpp:43
KArrowButton::setArrowType
void setArrowType(Qt::ArrowType a)
Defines in what direction the arrow is pointing to.
Definition: karrowbutton.cpp:48
KArrowButton::~KArrowButton
virtual ~KArrowButton()
Destructor.
Definition: karrowbutton.cpp:38
KArrowButton::drawButton
virtual void drawButton(TQPainter *)
Reimplemented from TQPushButton.
Definition: karrowbutton.cpp:60
KArrowButton::arrowType
Qt::ArrowType arrowType() const
Returns the arrow type.
Definition: karrowbutton.cpp:55
KArrowButton::KArrowButton
KArrowButton(TQWidget *parent=0, Qt::ArrowType arrow=Qt::UpArrow, const char *name=0)
Constructs an arrow button.
Definition: karrowbutton.cpp:30

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.8
This website is maintained by Timothy Pearson.