• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • sources
  • kde-4.12
  • kdelibs
  • kdeui
  • widgets
karrowbutton.cpp
Go to the documentation of this file.
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 <QStyle>
22 #include <QStyleOptionFrame>
23 #include <QPainter>
24 
25 #include <assert.h>
26 
27 class KArrowButtonPrivate
28 {
29  public:
30  Qt::ArrowType arrow;
31 };
32 
33 KArrowButton::KArrowButton(QWidget *parent, Qt::ArrowType arrow)
34  : QPushButton(parent),d(new KArrowButtonPrivate())
35 {
36  d->arrow = arrow;
37 }
38 
39 KArrowButton::~KArrowButton()
40 {
41  delete d;
42 }
43 
44 QSize KArrowButton::sizeHint() const
45 {
46  return QSize( 12, 12 );
47 }
48 
49 void KArrowButton::setArrowType(Qt::ArrowType a)
50 {
51  if (d->arrow != a) {
52  d->arrow = a;
53  repaint();
54  }
55 }
56 Qt::ArrowType KArrowButton::arrowType() const
57 {
58  return d->arrow;
59 }
60 
61 void KArrowButton::paintEvent(QPaintEvent*)
62 {
63  QPainter p(this);
64  const unsigned int arrowSize = 8;
65  const unsigned int margin = 2;
66 
67  QStyleOptionFrame opt;
68  opt.init(this);
69  opt.lineWidth = 2;
70  opt.midLineWidth = 0;
71 
72  p.fillRect( rect(), palette().brush( QPalette::Background ) );
73 
74  style()->drawPrimitive( QStyle::PE_Frame, &opt, &p, this);
75 
76  if (d->arrow == Qt::NoArrow)
77  return;
78 
79  if (static_cast<unsigned int>(width()) < arrowSize + margin ||
80  static_cast<unsigned int>(height()) < arrowSize + margin)
81  return; // don't draw arrows if we are too small
82 
83  unsigned int x = 0, y = 0;
84  if (d->arrow == Qt::DownArrow) {
85  x = (width() - arrowSize) / 2;
86  y = height() - (arrowSize + margin);
87  } else if (d->arrow == Qt::UpArrow) {
88  x = (width() - arrowSize) / 2;
89  y = margin;
90  } else if (d->arrow == Qt::RightArrow) {
91  x = width() - (arrowSize + margin);
92  y = (height() - arrowSize) / 2;
93  } else { // arrowType == LeftArrow
94  x = margin;
95  y = (height() - arrowSize) / 2;
96  }
97 
98  if (isDown()) {
99  x++;
100  y++;
101  }
102 
103  QStyle::PrimitiveElement e = QStyle::PE_IndicatorArrowLeft;
104  switch (d->arrow)
105  {
106  case Qt::LeftArrow: e = QStyle::PE_IndicatorArrowLeft; break;
107  case Qt::RightArrow: e = QStyle::PE_IndicatorArrowRight; break;
108  case Qt::UpArrow: e = QStyle::PE_IndicatorArrowUp; break;
109  case Qt::DownArrow: e = QStyle::PE_IndicatorArrowDown; break;
110  case Qt::NoArrow: assert( 0 ); break;
111  }
112 
113  opt.state |= QStyle::State_Enabled;
114  opt.rect = QRect( x, y, arrowSize, arrowSize);
115 
116  style()->drawPrimitive( e, &opt, &p, this );
117 }
118 
119 #include "karrowbutton.moc"
KArrowButton::paintEvent
virtual void paintEvent(QPaintEvent *)
Reimplemented from QPushButton.
Definition: karrowbutton.cpp:61
karrowbutton.h
KArrowButton::KArrowButton
KArrowButton(QWidget *parent=0, Qt::ArrowType arrow=Qt::UpArrow)
Constructs an arrow button.
Definition: karrowbutton.cpp:33
QWidget
QPushButton
KArrowButton::setArrowType
void setArrowType(Qt::ArrowType a)
Defines in what direction the arrow is pointing to.
Definition: karrowbutton.cpp:49
KArrowButton::~KArrowButton
virtual ~KArrowButton()
Destructor.
Definition: karrowbutton.cpp:39
QRect
QSize
KArrowButton::arrowType
Qt::ArrowType arrowType() const
Returns the arrow type.
KArrowButton::sizeHint
virtual QSize sizeHint() const
Reimplemented from QPushButton.
Definition: karrowbutton.cpp:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:49:13 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal