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

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • ekos
QProgressIndicator.cpp
Go to the documentation of this file.
1 /*
2 *
3 * This file is part of QProgressIndicator,
4 * an open-source recent files menu widget
5 *
6 * Copyright (C) 2009 - 2010 Morgan Leborgne
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with QRecentFilesMenu. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22 #include "QProgressIndicator.h"
23 
24 #include <QPainter>
25 
26 QProgressIndicator::QProgressIndicator(QWidget* parent)
27  : QWidget(parent),
28  m_angle(0),
29  m_timerId(-1),
30  m_delay(40),
31  m_displayedWhenStopped(false),
32  m_color(Qt::black)
33 {
34  setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
35  setFocusPolicy(Qt::NoFocus);
36 }
37 
38 bool QProgressIndicator::isAnimated () const
39 {
40  return (m_timerId != -1);
41 }
42 
43 void QProgressIndicator::setDisplayedWhenStopped(bool state)
44 {
45  m_displayedWhenStopped = state;
46 
47  update();
48 }
49 
50 bool QProgressIndicator::isDisplayedWhenStopped() const
51 {
52  return m_displayedWhenStopped;
53 }
54 
55 void QProgressIndicator::startAnimation()
56 {
57  m_angle = 0;
58 
59  if (m_timerId == -1)
60  m_timerId = startTimer(m_delay);
61 }
62 
63 void QProgressIndicator::stopAnimation()
64 {
65  if (m_timerId != -1)
66  killTimer(m_timerId);
67 
68  m_timerId = -1;
69 
70  update();
71 }
72 
73 void QProgressIndicator::setAnimationDelay(int delay)
74 {
75  if (m_timerId != -1)
76  killTimer(m_timerId);
77 
78  m_delay = delay;
79 
80  if (m_timerId != -1)
81  m_timerId = startTimer(m_delay);
82 }
83 
84 void QProgressIndicator::setColor(const QColor & color)
85 {
86  m_color = color;
87 
88  update();
89 }
90 
91 QSize QProgressIndicator::sizeHint() const
92 {
93  return QSize(20,20);
94 }
95 
96 int QProgressIndicator::heightForWidth(int w) const
97 {
98  return w;
99 }
100 
101 void QProgressIndicator::timerEvent(QTimerEvent * /*event*/)
102 {
103  m_angle = (m_angle+30)%360;
104 
105  update();
106 }
107 
108 void QProgressIndicator::paintEvent(QPaintEvent * /*event*/)
109 {
110  if (!m_displayedWhenStopped && !isAnimated())
111  return;
112 
113  int width = qMin(this->width(), this->height());
114 
115  QPainter p(this);
116  p.setRenderHint(QPainter::Antialiasing);
117 
118  int outerRadius = (width-1)*0.5;
119  int innerRadius = (width-1)*0.5*0.38;
120 
121  int capsuleHeight = outerRadius - innerRadius;
122  int capsuleWidth = (width > 32 ) ? capsuleHeight *.23 : capsuleHeight *.35;
123  int capsuleRadius = capsuleWidth/2;
124 
125  for (int i=0; i<12; i++)
126  {
127  QColor color = m_color;
128  color.setAlphaF(1.0f - (i/12.0f));
129  p.setPen(Qt::NoPen);
130  p.setBrush(color);
131  p.save();
132  p.translate(rect().center());
133  p.rotate(m_angle - i*30.0f);
134  p.drawRoundedRect(-capsuleWidth*0.5, -(innerRadius+capsuleHeight), capsuleWidth, capsuleHeight, capsuleRadius, capsuleRadius);
135  p.restore();
136  }
137 }
QProgressIndicator::setAnimationDelay
void setAnimationDelay(int delay)
Definition: QProgressIndicator.cpp:73
QProgressIndicator::isDisplayedWhenStopped
bool isDisplayedWhenStopped() const
Definition: QProgressIndicator.cpp:50
QWidget
QProgressIndicator::sizeHint
virtual QSize sizeHint() const
Definition: QProgressIndicator.cpp:91
QProgressIndicator.h
QProgressIndicator::setDisplayedWhenStopped
void setDisplayedWhenStopped(bool state)
Definition: QProgressIndicator.cpp:43
QProgressIndicator::startAnimation
void startAnimation()
Definition: QProgressIndicator.cpp:55
QProgressIndicator::QProgressIndicator
QProgressIndicator(QWidget *parent=0)
Definition: QProgressIndicator.cpp:26
QProgressIndicator::color
const QColor & color() const
Definition: QProgressIndicator.h:65
NaN::f
const float f
Definition: nan.h:36
QProgressIndicator::isAnimated
bool isAnimated() const
Definition: QProgressIndicator.cpp:38
QProgressIndicator::paintEvent
virtual void paintEvent(QPaintEvent *event)
Definition: QProgressIndicator.cpp:108
QProgressIndicator::delay
int delay
Definition: QProgressIndicator.h:38
QProgressIndicator::stopAnimation
void stopAnimation()
Definition: QProgressIndicator.cpp:63
QProgressIndicator::setColor
void setColor(const QColor &color)
Definition: QProgressIndicator.cpp:84
QProgressIndicator::heightForWidth
int heightForWidth(int w) const
Definition: QProgressIndicator.cpp:96
QProgressIndicator::timerEvent
virtual void timerEvent(QTimerEvent *event)
Definition: QProgressIndicator.cpp:101
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

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