refactored progress
This commit is contained in:
parent
566fc1f2fb
commit
f3515f1104
5 changed files with 149 additions and 48 deletions
84
ui/utils/progress.cpp
Normal file
84
ui/utils/progress.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Squawk messenger.
|
||||
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "progress.h"
|
||||
|
||||
Progress::Progress(quint16 p_size, QWidget* parent):
|
||||
QWidget(parent),
|
||||
pixmap(new QGraphicsPixmapItem(Shared::icon("view-refresh", true).pixmap(p_size))),
|
||||
scene(),
|
||||
label(&scene),
|
||||
progress(false),
|
||||
animation(),
|
||||
size(p_size)
|
||||
{
|
||||
scene.addItem(pixmap);
|
||||
label.setMaximumSize(size, size);
|
||||
label.setMinimumSize(size, size);
|
||||
label.setSceneRect(0, 0, size, size);
|
||||
label.setFrameStyle(0);
|
||||
label.setContentsMargins(0, 0, 0, 0);
|
||||
label.setInteractive(false);
|
||||
pixmap->setTransformOriginPoint(size / 2, size / 2);
|
||||
pixmap->setTransformationMode(Qt::SmoothTransformation);
|
||||
pixmap->setOffset(0, 0);;
|
||||
|
||||
animation.setDuration(500);
|
||||
animation.setStartValue(0.0f);
|
||||
animation.setEndValue(180.0f);
|
||||
animation.setLoopCount(-1);
|
||||
connect(&animation, &QVariantAnimation::valueChanged, this, &Progress::onValueChanged);
|
||||
|
||||
QGridLayout* layout = new QGridLayout();
|
||||
setLayout(layout);
|
||||
layout->setMargin(0);
|
||||
layout->setVerticalSpacing(0);
|
||||
layout->setHorizontalSpacing(0);
|
||||
|
||||
setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
layout->addWidget(&label, 0, 0, 1, 1);
|
||||
label.hide();
|
||||
}
|
||||
|
||||
Progress::~Progress()
|
||||
{
|
||||
}
|
||||
|
||||
void Progress::onValueChanged(const QVariant& value)
|
||||
{
|
||||
pixmap->setRotation(value.toReal());
|
||||
}
|
||||
|
||||
void Progress::start()
|
||||
{
|
||||
if (!progress) {
|
||||
label.show();
|
||||
animation.start();
|
||||
progress = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Progress::stop()
|
||||
{
|
||||
if (progress) {
|
||||
label.hide();
|
||||
animation.stop();
|
||||
progress = false;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue