diff options
author | Anne Jan Brouwer <brouwer@annejan.com> | 2015-05-26 03:22:59 +0200 |
---|---|---|
committer | Anne Jan Brouwer <brouwer@annejan.com> | 2015-05-26 03:22:59 +0200 |
commit | 271b3da56d76bad669d14547ca499a64000c8a3c (patch) | |
tree | 17c4b541eda2e28c3ca967521e6b969b43fb8842 | |
parent | 825c9eb7b546c51fcb6e3c4dee2250a7d15c6208 (diff) |
Added waiting animation widget from https://github.com/mojocorp/QProgressIndicator
-rw-r--r-- | keygendialog.cpp | 27 | ||||
-rw-r--r-- | keygendialog.ui | 2 | ||||
-rw-r--r-- | mainwindow.cpp | 7 | ||||
-rw-r--r-- | progressindicator.cpp | 116 | ||||
-rw-r--r-- | progressindicator.h | 87 | ||||
-rw-r--r-- | qtpass.pro | 11 |
6 files changed, 228 insertions, 22 deletions
diff --git a/keygendialog.cpp b/keygendialog.cpp index a04ed77d..640ee069 100644 --- a/keygendialog.cpp +++ b/keygendialog.cpp @@ -1,5 +1,6 @@ #include "keygendialog.h" #include "ui_keygendialog.h" +#include "progressindicator.h" #include <QDebug> #include <QMessageBox> @@ -116,17 +117,23 @@ void KeygenDialog::done(int r) ui->buttonBox->setEnabled(false); ui->checkBox->setEnabled(false); ui->plainTextEdit->setEnabled(false); - // some kind of animation or at-least explanation needed here - // people don't like wating :D + + QProgressIndicator* pi = new QProgressIndicator(); + pi->startAnimation(); + pi->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + this->layout()->removeWidget(ui->widget); + this->layout()->removeWidget(ui->buttonBox); + this->layout()->removeWidget(ui->checkBox); + this->layout()->removeWidget(ui->plainTextEdit); + this->layout()->removeWidget(ui->label); + this->layout()->removeWidget(ui->labelExpertInfo); + this->layout()->removeWidget(ui->labelPassphraseInfo); + + this->layout()->addWidget(pi); + + this->show(); dialog->genKey(ui->plainTextEdit->toPlainText(), this); -// QMessageBox::critical(this, tr("GPG gen-key error"), -// tr("Something went wrong, I guess")); -// ui->widget->setEnabled(true); -// ui->buttonBox->setEnabled(true); -// ui->checkBox->setEnabled(true); -// on_checkBox_stateChanged(ui->checkBox->isChecked()); -// // something went wrong, explain things? -// return; } else // cancel, close or exc was pressed { diff --git a/keygendialog.ui b/keygendialog.ui index ef9a2aea..1c29c3fa 100644 --- a/keygendialog.ui +++ b/keygendialog.ui @@ -125,7 +125,7 @@ Expire-Date: 0 </widget> </item> <item> - <widget class="QLabel" name="label_2"> + <widget class="QLabel" name="labelExpertInfo"> <property name="text"> <string>For expert options check out the <a href="https://www.gnupg.org/documentation/manuals/gnupg/Unattended-GPG-key-generation.html">GnuPG manual</a></string> </property> diff --git a/mainwindow.cpp b/mainwindow.cpp index 4ba874ca..324f14f3 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -426,7 +426,7 @@ void MainWindow::readyRead(bool finished = false) { qDebug() << "Keygen Done"; keygen->close(); keygen = 0; - // TODO some sanity checking ! + // TODO some sanity checking ? } } @@ -995,9 +995,4 @@ void MainWindow::genKey(QString batch, QDialog *keygenWindow) ui->statusBar->showMessage(tr("Generating GPG key pair"), 60000); currentAction = GPG_INTERNAL; executeWrapper(gpgExecutable , "--gen-key --no-tty --batch", batch); -// process->waitForFinished(600000); // ten minutes enough ? -// if (process->exitStatus() != QProcess::NormalExit) { -// return true; -// } -// return false; } diff --git a/progressindicator.cpp b/progressindicator.cpp new file mode 100644 index 00000000..b3835f66 --- /dev/null +++ b/progressindicator.cpp @@ -0,0 +1,116 @@ +#include "progressindicator.h" + +#include <QPainter> + +QProgressIndicator::QProgressIndicator(QWidget* parent) + : QWidget(parent), + m_angle(0), + m_timerId(-1), + m_delay(40), + m_displayedWhenStopped(false), + m_color(Qt::black) +{ + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setFocusPolicy(Qt::NoFocus); +} + +bool QProgressIndicator::isAnimated () const +{ + return (m_timerId != -1); +} + +void QProgressIndicator::setDisplayedWhenStopped(bool state) +{ + m_displayedWhenStopped = state; + + update(); +} + +bool QProgressIndicator::isDisplayedWhenStopped() const +{ + return m_displayedWhenStopped; +} + +void QProgressIndicator::startAnimation() +{ + m_angle = 0; + + if (m_timerId == -1) + m_timerId = startTimer(m_delay); +} + +void QProgressIndicator::stopAnimation() +{ + if (m_timerId != -1) + killTimer(m_timerId); + + m_timerId = -1; + + update(); +} + +void QProgressIndicator::setAnimationDelay(int delay) +{ + if (m_timerId != -1) + killTimer(m_timerId); + + m_delay = delay; + + if (m_timerId != -1) + m_timerId = startTimer(m_delay); +} + +void QProgressIndicator::setColor(const QColor & color) +{ + m_color = color; + + update(); +} + +QSize QProgressIndicator::sizeHint() const +{ + return QSize(20,20); +} + +int QProgressIndicator::heightForWidth(int w) const +{ + return w; +} + +void QProgressIndicator::timerEvent(QTimerEvent * /*event*/) +{ + m_angle = (m_angle+30)%360; + + update(); +} + +void QProgressIndicator::paintEvent(QPaintEvent * /*event*/) +{ + if (!m_displayedWhenStopped && !isAnimated()) + return; + + int width = qMin(this->width(), this->height()); + + QPainter p(this); + p.setRenderHint(QPainter::Antialiasing); + + int outerRadius = (width-1)*0.5; + int innerRadius = (width-1)*0.5*0.38; + + int capsuleHeight = outerRadius - innerRadius; + int capsuleWidth = (width > 32 ) ? capsuleHeight *.23 : capsuleHeight *.35; + int capsuleRadius = capsuleWidth/2; + + for (int i=0; i<12; i++) + { + QColor color = m_color; + color.setAlphaF(1.0f - (i/12.0f)); + p.setPen(Qt::NoPen); + p.setBrush(color); + p.save(); + p.translate(rect().center()); + p.rotate(m_angle - i*30.0f); + p.drawRoundedRect(-capsuleWidth*0.5, -(innerRadius+capsuleHeight), capsuleWidth, capsuleHeight, capsuleRadius, capsuleRadius); + p.restore(); + } +} diff --git a/progressindicator.h b/progressindicator.h new file mode 100644 index 00000000..65d80f76 --- /dev/null +++ b/progressindicator.h @@ -0,0 +1,87 @@ +#ifndef QPROGRESSINDICATOR_H +#define QPROGRESSINDICATOR_H + +#include <QWidget> +#include <QColor> + +/*! + \class QProgressIndicator + \brief The QProgressIndicator class lets an application display a progress indicator to show that a lengthy task is under way. + + Progress indicators are indeterminate and do nothing more than spin to show that the application is busy. + \sa QProgressBar +*/ +class QProgressIndicator : public QWidget +{ + Q_OBJECT + Q_PROPERTY(int delay READ animationDelay WRITE setAnimationDelay) + Q_PROPERTY(bool displayedWhenStopped READ isDisplayedWhenStopped WRITE setDisplayedWhenStopped) + Q_PROPERTY(QColor color READ color WRITE setColor) +public: + QProgressIndicator(QWidget* parent = 0); + + /*! Returns the delay between animation steps. + \return The number of milliseconds between animation steps. By default, the animation delay is set to 40 milliseconds. + \sa setAnimationDelay + */ + int animationDelay() const { return m_delay; } + + /*! Returns a Boolean value indicating whether the component is currently animated. + \return Animation state. + \sa startAnimation stopAnimation + */ + bool isAnimated () const; + + /*! Returns a Boolean value indicating whether the receiver shows itself even when it is not animating. + \return Return true if the progress indicator shows itself even when it is not animating. By default, it returns false. + \sa setDisplayedWhenStopped + */ + bool isDisplayedWhenStopped() const; + + /*! Returns the color of the component. + \sa setColor + */ + const QColor & color() const { return m_color; } + + virtual QSize sizeHint() const; + int heightForWidth(int w) const; +public slots: + /*! Starts the spin animation. + \sa stopAnimation isAnimated + */ + void startAnimation(); + + /*! Stops the spin animation. + \sa startAnimation isAnimated + */ + void stopAnimation(); + + /*! Sets the delay between animation steps. + Setting the \a delay to a value larger than 40 slows the animation, while setting the \a delay to a smaller value speeds it up. + \param delay The delay, in milliseconds. + \sa animationDelay + */ + void setAnimationDelay(int delay); + + /*! Sets whether the component hides itself when it is not animating. + \param state The animation state. Set false to hide the progress indicator when it is not animating; otherwise true. + \sa isDisplayedWhenStopped + */ + void setDisplayedWhenStopped(bool state); + + /*! Sets the color of the components to the given color. + \sa color + */ + void setColor(const QColor & color); +protected: + virtual void timerEvent(QTimerEvent * event); + virtual void paintEvent(QPaintEvent * event); +private: + int m_angle; + int m_timerId; + int m_delay; + bool m_displayedWhenStopped; + QColor m_color; +}; + +#endif // QPROGRESSINDICATOR_H @@ -7,7 +7,7 @@ # #------------------------------------------------- -QT += core gui +QT += core gui widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets @@ -28,20 +28,21 @@ SOURCES += main.cpp\ storemodel.cpp \ util.cpp \ usersdialog.cpp \ - keygendialog.cpp + keygendialog.cpp \ + progressindicator.cpp HEADERS += mainwindow.h \ dialog.h \ storemodel.h \ util.h \ usersdialog.h \ - wizarddialog.h \ - keygendialog.h + keygendialog.h \ + progressindicator.h FORMS += mainwindow.ui \ dialog.ui \ usersdialog.ui \ - keygendialog.ui + keygendialog.ui *-g++* { QMAKE_CXXFLAGS += -std=c++11 |