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

filelight

  • sources
  • kde-4.14
  • kdeutils
  • filelight
  • src
  • part
progressBox.cpp
Go to the documentation of this file.
1 /***********************************************************************
2 * Copyright 2003-2004 Max Howell <max.howell@methylblue.com>
3 * Copyright 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License or (at your option) version 3 or any later version
9 * accepted by the membership of KDE e.V. (or its successor approved
10 * by the membership of KDE e.V.), which shall act as a proxy
11 * defined in Section 14 of version 3 of the license.
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 General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ***********************************************************************/
21 
22 #include "progressBox.h"
23 
24 #include "scan.h"
25 
26 #include <KGlobal>
27 #include <KGlobalSettings>
28 #include <KColorScheme>
29 #include <KIO/Job>
30 #include <KLocale>
31 
32 #include <QtGui/QLabel>
33 #include <QPainter>
34 #include <QtCore/QDebug>
35 
36 #include <math.h>
37 
38 
39 ProgressBox::ProgressBox(QWidget *parent, QObject *part, Filelight::ScanManager *m)
40  : QWidget(parent)
41  , m_manager(m)
42 {
43  hide();
44 
45  setObjectName(QLatin1String( "ProgressBox" ));
46 
47  setFont(KGlobalSettings::fixedFont());
48  setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
49 
50  setText(999999);
51  setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
52  setMinimumSize(200, 200);
53 
54  connect(&m_timer, SIGNAL(timeout()), SLOT(report()));
55  connect(part, SIGNAL(started(KIO::Job*)), SLOT(start()));
56  connect(part, SIGNAL(completed()), SLOT(stop()));
57  connect(part, SIGNAL(canceled(QString)), SLOT(halt()));
58 }
59 
60 void
61 ProgressBox::start() //slot
62 {
63  m_timer.start(50); //20 times per second - very smooth
64  report();
65  show();
66 }
67 
68 void
69 ProgressBox::report() //slot
70 {
71  setText(m_manager->files());
72  repaint();
73 }
74 
75 void
76 ProgressBox::stop()
77 {
78  m_timer.stop();
79 }
80 
81 void
82 ProgressBox::halt()
83 {
84  // canceled by stop button
85  m_timer.stop();
86  QTimer::singleShot(2000, this, SLOT(hide()));
87 }
88 
89 void
90 ProgressBox::setText(int files)
91 {
92  m_text = i18np("%1 File", "%1 Files", files);
93  m_textWidth = fontMetrics().width(m_text);
94  m_textHeight = fontMetrics().height();
95 }
96 
97 static const int pieces = 4;
98 static const float angleFactor[] = { -0.75, 0.5, 1.0, -0.3 };
99 static const int length[] = { 30, 40, 50, 60 };
100 static const int angleOffset[] = { 5760, 0, 0, -5760 };
101 static const int aLength[] = { 300, 2000, 200, 2000 };
102 
103 void ProgressBox::paintEvent(QPaintEvent*)
104 {
105  KColorScheme view = KColorScheme(QPalette::Active, KColorScheme::Tooltip);
106 
107  QPainter paint(this);
108  paint.setRenderHint(QPainter::Antialiasing);
109  static int tick = 0;
110  tick+=16;
111 
112  for (int i=0; i<pieces; i++) {
113  const QRect rect(length[i]/2, length[i]/2, 200- length[i], 200-length[i]);
114  int angle = angleFactor[i] + tick*angleFactor[i];
115  QRadialGradient gradient(rect.center(), sin(angle/160.0f) * 100);
116  gradient.setColorAt(0, QColor::fromHsv(abs(angle/16) % 360 , 160, 255));
117  gradient.setColorAt(1, QColor::fromHsv(abs(angle/16) % 360 , 160, 128));
118  QBrush brush(gradient);
119  paint.setBrush(brush);
120  paint.drawPie(QRect(rect), angle, aLength[i]);
121  }
122 
123  paint.setBrush(view.background(KColorScheme::ActiveBackground));
124  paint.setPen(view.foreground().color());
125  paint.translate(0.5, 0.5);
126  paint.drawRoundedRect(95-m_textWidth/2, 85, m_textWidth+10, m_textHeight+10, 5, 5);
127  paint.translate(-0.5, -0.5);
128  paint.drawText(100 - m_textWidth/2, 100, m_text);
129 }
130 
131 
132 #include "progressBox.moc"
progressBox.h
QWidget
QPainter::setRenderHint
void setRenderHint(RenderHint hint, bool on)
QGradient::setColorAt
void setColorAt(qreal position, const QColor &color)
ProgressBox::halt
void halt()
Definition: progressBox.cpp:82
ProgressBox::stop
void stop()
Definition: progressBox.cpp:76
QBrush
QColor::fromHsv
QColor fromHsv(int h, int s, int v, int a)
QWidget::setMinimumSize
void setMinimumSize(const QSize &)
QRect
Filelight::ScanManager::files
uint files() const
Definition: scan.h:49
ProgressBox::ProgressBox
ProgressBox(QWidget *, QObject *, Filelight::ScanManager *)
Definition: progressBox.cpp:39
QObject
QPainter::setPen
void setPen(const QColor &color)
pieces
static const int pieces
Definition: progressBox.cpp:97
QPainter::drawRoundedRect
void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
QPainter
QObject::setObjectName
void setObjectName(const QString &name)
QPainter::setBrush
void setBrush(const QBrush &brush)
QPainter::drawText
void drawText(const QPointF &position, const QString &text)
QRect::center
QPoint center() const
QString
QWidget::hide
void hide()
QWidget::setSizePolicy
void setSizePolicy(QSizePolicy)
QWidget::rect
QRect rect() const
Filelight::parent
http QObject * parent
Definition: part.cpp:74
QWidget::setFont
void setFont(const QFont &)
QFontMetrics::width
int width(const QString &text, int len) const
QTimer::stop
void stop()
angleFactor
static const float angleFactor[]
Definition: progressBox.cpp:98
QPainter::drawPie
void drawPie(const QRectF &rectangle, int startAngle, int spanAngle)
QWidget::repaint
void repaint()
ProgressBox::start
void start()
Definition: progressBox.cpp:61
scan.h
QWidget::fontMetrics
QFontMetrics fontMetrics() const
QLatin1String
QRadialGradient
QFontMetrics::height
int height() const
QPainter::translate
void translate(const QPointF &offset)
aLength
static const int aLength[]
Definition: progressBox.cpp:101
QTimer::start
void start(int msec)
ProgressBox::paintEvent
void paintEvent(QPaintEvent *event)
Definition: progressBox.cpp:103
QWidget::show
void show()
Filelight::ScanManager
Definition: scan.h:35
QPaintEvent
angleOffset
static const int angleOffset[]
Definition: progressBox.cpp:100
length
static const int length[]
Definition: progressBox.cpp:99
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
ProgressBox::report
void report()
Definition: progressBox.cpp:69
ProgressBox::setText
void setText(int)
Definition: progressBox.cpp:90
QTimer::singleShot
singleShot
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:32 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

filelight

Skip menu "filelight"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • sweeper

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