-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
as title Log: unit test plugin
- Loading branch information
Showing
56 changed files
with
4,118 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#include "spinnerpainter.h" | ||
|
||
#include <QtMath> | ||
Check warning on line 7 in src/common/util/spinnerpainter.cpp GitHub Actions / cppcheck
|
||
#include <QPainterPath> | ||
Check warning on line 8 in src/common/util/spinnerpainter.cpp GitHub Actions / cppcheck
|
||
|
||
SpinnerPainter::SpinnerPainter() | ||
{ | ||
refreshTimer.setInterval(30); | ||
QObject::connect(&refreshTimer, &QTimer::timeout, &refreshTimer, | ||
[=]() { | ||
currentDegree += 14; | ||
callback(); | ||
}); | ||
} | ||
|
||
void SpinnerPainter::paint(QPainter &painter, const QColor &color, const QRect &rect) | ||
{ | ||
painter.save(); | ||
if (currentColor != color) { | ||
currentColor = color; | ||
indicatorColors.clear(); | ||
} | ||
|
||
if (indicatorColors.isEmpty()) { | ||
for (int i = 0; i < 3; ++i) | ||
indicatorColors << createDefaultIndicatorColorList(color); | ||
} | ||
|
||
painter.setRenderHints(QPainter::Antialiasing); | ||
auto center = QRectF(rect).center(); | ||
auto radius = qMin(rect.width(), rect.height()) / 2.0; | ||
auto indicatorRadius = radius / 2 / 2 * 1.1; | ||
auto indicatorDegreeDelta = 360 / indicatorColors.count(); | ||
|
||
for (int i = 0; i < indicatorColors.count(); ++i) { | ||
auto colors = indicatorColors.value(i); | ||
for (int j = 0; j < colors.count(); ++j) { | ||
double degreeCurrent = currentDegree - j * indicatorShadowOffset + indicatorDegreeDelta * i; | ||
auto x = (radius - indicatorRadius) * qCos(qDegreesToRadians(degreeCurrent)); | ||
auto y = (radius - indicatorRadius) * qSin(qDegreesToRadians(degreeCurrent)); | ||
|
||
x = center.x() + x; | ||
y = center.y() + y; | ||
auto tl = QPointF(x - 1 * indicatorRadius, y - 1 * indicatorRadius); | ||
QRectF rf(tl.x(), tl.y(), indicatorRadius * 2, indicatorRadius * 2); | ||
|
||
QPainterPath path; | ||
path.addEllipse(rf); | ||
|
||
painter.fillPath(path, colors.value(j)); | ||
} | ||
} | ||
painter.restore(); | ||
} | ||
|
||
void SpinnerPainter::setUpdateCallback(const UpdateCallback &cb) | ||
{ | ||
callback = cb; | ||
} | ||
|
||
void SpinnerPainter::startAnimation() | ||
{ | ||
refreshTimer.start(); | ||
} | ||
|
||
void SpinnerPainter::stopAnimation() | ||
Check warning on line 70 in src/common/util/spinnerpainter.cpp GitHub Actions / cppcheck
|
||
{ | ||
refreshTimer.stop(); | ||
} | ||
|
||
QList<QColor> SpinnerPainter::createDefaultIndicatorColorList(QColor color) | ||
{ | ||
QList<QColor> colors; | ||
QList<int> opacitys; | ||
opacitys << 100 << 30 << 15 << 10 << 5 << 4 << 3 << 2 << 1; | ||
for (int i = 0; i < opacitys.count(); ++i) { | ||
color.setAlpha(255 * opacitys.value(i) / 100); | ||
colors << color; | ||
} | ||
return colors; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#ifndef SPINNERPAINTER_H | ||
#define SPINNERPAINTER_H | ||
|
||
#include <QPainter> | ||
Check warning on line 8 in src/common/util/spinnerpainter.h GitHub Actions / cppcheck
|
||
#include <QTimer> | ||
Check warning on line 9 in src/common/util/spinnerpainter.h GitHub Actions / cppcheck
|
||
|
||
#include <functional> | ||
Check warning on line 11 in src/common/util/spinnerpainter.h GitHub Actions / cppcheck
|
||
|
||
class SpinnerPainter | ||
{ | ||
public: | ||
SpinnerPainter(); | ||
|
||
void paint(QPainter &painter, const QColor &color, const QRect &rect); | ||
|
||
using UpdateCallback = std::function<void()>; | ||
void setUpdateCallback(const UpdateCallback &cb); | ||
|
||
void startAnimation(); | ||
void stopAnimation(); | ||
|
||
protected: | ||
QList<QColor> createDefaultIndicatorColorList(QColor color); | ||
|
||
private: | ||
QTimer refreshTimer; | ||
|
||
double indicatorShadowOffset = 10; | ||
double currentDegree = 0.0; | ||
|
||
QList<QList<QColor>> indicatorColors; | ||
QColor currentColor; | ||
UpdateCallback callback; | ||
}; | ||
|
||
#endif // SPINNERPAINTER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.