[3rdparty] Introduce alignment flag for text
This commit is contained in:
parent
fac8662387
commit
bef6b2fffd
18
3rdparty/waitingspinnerwidget.cpp
vendored
18
3rdparty/waitingspinnerwidget.cpp
vendored
@ -39,6 +39,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
#include <QPainter>
|
||||
#include <QTimer>
|
||||
|
||||
static bool isAlignCenter(Qt::AlignmentFlag a)
|
||||
{
|
||||
return a == Qt::AlignmentFlag::AlignVCenter;
|
||||
}
|
||||
|
||||
WaitingSpinnerWidget::WaitingSpinnerWidget(QWidget *parent,
|
||||
bool centerOnParent,
|
||||
bool disableParentWhenSpinning)
|
||||
@ -120,9 +125,14 @@ void WaitingSpinnerWidget::paintEvent(QPaintEvent *) {
|
||||
|
||||
if (!_text.isEmpty()) {
|
||||
painter.setPen(QPen(_textColor));
|
||||
if (isAlignCenter(alignment())) {
|
||||
painter.drawText(QRect(0, 0, width(), height()),
|
||||
Qt::AlignVCenter | Qt::AlignHCenter, _text);
|
||||
} else {
|
||||
painter.drawText(QRect(0, _imageSize.height(), width(), height() - _imageSize.height()),
|
||||
Qt::AlignBottom | Qt::AlignHCenter, _text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WaitingSpinnerWidget::start() {
|
||||
@ -180,6 +190,12 @@ void WaitingSpinnerWidget::setText(const QString& text) {
|
||||
updateSize();
|
||||
}
|
||||
|
||||
void WaitingSpinnerWidget::setAlignment(Qt::AlignmentFlag align)
|
||||
{
|
||||
_alignment = align;
|
||||
updateSize();
|
||||
}
|
||||
|
||||
QColor WaitingSpinnerWidget::color() const {
|
||||
return _color;
|
||||
}
|
||||
@ -264,7 +280,7 @@ void WaitingSpinnerWidget::rotate() {
|
||||
void WaitingSpinnerWidget::updateSize() {
|
||||
int size = (_innerRadius + _lineLength) * 2;
|
||||
_imageSize = QSize(size, size);
|
||||
if (_text.isEmpty()) {
|
||||
if (_text.isEmpty() || isAlignCenter(alignment())) {
|
||||
setFixedSize(size, size);
|
||||
} else {
|
||||
QFontMetrics fm(font());
|
||||
|
17
3rdparty/waitingspinnerwidget.h
vendored
17
3rdparty/waitingspinnerwidget.h
vendored
@ -72,11 +72,27 @@ public:
|
||||
void setLineLength(int length);
|
||||
void setLineWidth(int width);
|
||||
void setInnerRadius(int radius);
|
||||
|
||||
/** @brief Sets the text displayed in or below the spinner
|
||||
*
|
||||
* If the text is empty, no text is displayed. The text is displayed
|
||||
* in or below the spinner depending on the value of alignment().
|
||||
* With AlignBottom, the text is displayed below the spinner,
|
||||
* centered horizontally relative to the spinner; any other alignment
|
||||
* will put the text in the middle of the spinner itself.
|
||||
*/
|
||||
void setText(const QString& text);
|
||||
/** @brief Sets the alignment of text for the spinner
|
||||
*
|
||||
* The only meaningful values are AlignBottom and AlignVCenter,
|
||||
* for text below the spinner and text in the middle.
|
||||
*/
|
||||
void setAlignment(Qt::AlignmentFlag align);
|
||||
|
||||
QColor color() const;
|
||||
QColor textColor() const;
|
||||
QString text() const;
|
||||
Qt::AlignmentFlag alignment() const { return _alignment; }
|
||||
qreal roundness() const;
|
||||
qreal minimumTrailOpacity() const;
|
||||
qreal trailFadePercentage() const;
|
||||
@ -120,6 +136,7 @@ private:
|
||||
int _lineLength;
|
||||
int _lineWidth;
|
||||
int _innerRadius;
|
||||
Qt::AlignmentFlag _alignment = Qt::AlignmentFlag::AlignBottom;
|
||||
QString _text;
|
||||
QSize _imageSize;
|
||||
QColor _textColor;
|
||||
|
Loading…
Reference in New Issue
Block a user