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

KNewStuff

  • sources
  • kde-4.12
  • kdelibs
  • knewstuff
  • knewstuff2
  • ui
qprogressindicator.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KNewStuff2.
3  Copyright (c) 2007 Josef Spillner <spillner@kde.org>
4  Copyright (c) 2007 Jeremy Whiting <jpwhiting@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library 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 GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "qprogressindicator.h"
21 
22 #include <QtGui/QProgressBar>
23 #include <QtGui/QPushButton>
24 #include <QtGui/QLabel>
25 #include <QtGui/QLayout>
26 
27 #include <kiconloader.h>
28 
29 QProgressIndicator::QProgressIndicator(QWidget *parent)
30  : QFrame(parent)
31 {
32  setFrameStyle(QFrame::NoFrame);
33  m_pb = new QProgressBar();
34  m_pb->setMinimum(0);
35  m_pb->setMaximum(100);
36 
37  m_pbdetails = new QPushButton();
38  m_pbdetails->setFixedWidth(32); // FIXME: I want a squared button
39  m_pbdetails->setIcon(SmallIcon("go-up"));
40  m_pbdetails->setEnabled(false);
41 
42  QHBoxLayout *hbox = new QHBoxLayout(this);
43  hbox->setMargin(0);
44  hbox->addWidget(m_pbdetails);
45  hbox->addWidget(m_pb);
46 
47  m_details = new QWidget(this);
48  m_details->setWindowFlags(Qt::Popup);
49  m_details->hide();
50 
51  m_detailsvbox = new QVBoxLayout(m_details);
52 
53  connect(m_pbdetails, SIGNAL(clicked()), SLOT(slotClicked()));
54 }
55 
56 void QProgressIndicator::slotClicked()
57 {
58  QPoint indicatorpos = mapToGlobal(pos());
59  m_details->move(indicatorpos.x(), indicatorpos.y());
60 
61  if (m_details->isVisible())
62  m_details->hide();
63  else
64  m_details->show();
65 }
66 
67 void QProgressIndicator::addProgress(const QString & message, int percentage)
68 {
69  QProgressBar *pb;
70 
71  m_progress[message] = percentage;
72 
73  if (!m_progresswidgets.contains(message)) {
74  QWidget *pbcontainer = new QWidget();
75 
76  // make a label to show the url
77  QLabel * urlLabel = new QLabel(pbcontainer);
78  urlLabel->setText(message);
79 
80  // make a progress bar
81  pb = new QProgressBar(pbcontainer);
82  pb->setMinimum(0);
83  pb->setMaximum(100);
84  m_progresswidgets.insert(message, pb);
85 
86  // make a cancel button
87  QPushButton *pbcancel = new QPushButton();
88  pbcancel->setFixedWidth(32); // FIXME: I want a squared button
89  pbcancel->setIcon(SmallIcon("dialog-cancel"));
90 
91  QGridLayout *layout = new QGridLayout(pbcontainer);
92  layout->addWidget(urlLabel, 0, 0, 1, 2);
93  layout->addWidget(pbcancel, 1, 0);
94  layout->addWidget(pb, 1, 1);
95 
96  m_detailsvbox->addWidget(pbcontainer);
97 
98  pbcontainer->show();
99  } else {
100  pb = m_progresswidgets[message];
101  }
102 
103  pb->setValue(percentage);
104 
105  if (m_progress.count() > 0)
106  m_pbdetails->setEnabled(true);
107 
108  if (percentage == 100)
109  removeProgress(message);
110 
111  calculateAverage();
112 }
113 
114 void QProgressIndicator::removeProgress(const QString & message)
115 {
116  m_progress.remove(message);
117 
118  if (m_progresswidgets[message]) {
119  delete m_progresswidgets[message]->parentWidget();
120  m_progresswidgets.remove(message);
121  }
122 
123  if (m_progress.count() == 0) {
124  m_pbdetails->setEnabled(false);
125  m_details->hide();
126  }
127 
128  calculateAverage();
129 }
130 
131 void QProgressIndicator::calculateAverage()
132 {
133  if (m_progress.count() == 0) {
134  m_pb->reset();
135  return;
136  }
137 
138  int average = 0;
139  QHashIterator<QString, int> it(m_progress);
140  while (it.hasNext()) {
141  it.next();
142  average += it.value();
143  }
144  average = (average / m_progress.count());
145 
146  m_pb->setValue(average);
147 }
148 
149 #include "qprogressindicator.moc"
QWidget
QPushButton
kiconloader.h
QString
QProgressIndicator::QProgressIndicator
QProgressIndicator(QWidget *parent)
Definition: qprogressindicator.cpp:29
QProgressIndicator::addProgress
void addProgress(const QString &message, int percentage)
Definition: qprogressindicator.cpp:67
qprogressindicator.h
QProgressIndicator::slotClicked
void slotClicked()
Definition: qprogressindicator.cpp:56
QPoint
QLabel
SmallIcon
QPixmap SmallIcon(const QString &name, int force_size, int state, const QStringList &overlays)
QProgressIndicator::removeProgress
void removeProgress(const QString &message)
Definition: qprogressindicator.cpp:114
QFrame
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:50:49 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KNewStuff

Skip menu "KNewStuff"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • 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