1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-14 02:14:21 +01:00

Make the multi loading indicator shrinkable so it doesn't make the window bigger when lots of things are loading. Fixes issue #967

This commit is contained in:
David Sansome 2010-11-20 14:57:02 +00:00
parent ed1a25693c
commit 287f073127
5 changed files with 51 additions and 73 deletions

View File

@ -404,7 +404,6 @@ set(UI
widgets/equalizerslider.ui
widgets/errordialog.ui
widgets/fileview.ui
widgets/multiloadingindicator.ui
widgets/osdpretty.ui
widgets/trackslider.ui
)

View File

@ -24,6 +24,7 @@ BusyIndicator::BusyIndicator(QWidget* parent)
movie_(new QMovie(":spinner.gif"))
{
setMovie(movie_);
setMinimumSize(16, 16);
}
BusyIndicator::~BusyIndicator() {

View File

@ -16,18 +16,29 @@
*/
#include "multiloadingindicator.h"
#include "ui_multiloadingindicator.h"
#include "core/taskmanager.h"
#include "widgets/busyindicator.h"
#include <QHBoxLayout>
#include <QPainter>
const int MultiLoadingIndicator::kVerticalPadding = 4;
const int MultiLoadingIndicator::kHorizontalPadding = 6;
const int MultiLoadingIndicator::kSpacing = 6;
MultiLoadingIndicator::MultiLoadingIndicator(QWidget *parent)
: QWidget(parent),
ui_(new Ui_MultiLoadingIndicator)
spinner_(new BusyIndicator(this))
{
ui_->setupUi(this);
spinner_->move(kHorizontalPadding, kVerticalPadding);
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
}
MultiLoadingIndicator::~MultiLoadingIndicator() {
delete ui_;
QSize MultiLoadingIndicator::sizeHint() const {
const int width = kHorizontalPadding*2 + spinner_->sizeHint().width() + kSpacing + fontMetrics().width(text_);
const int height = kVerticalPadding*2 + qMax(spinner_->sizeHint().height(), fontMetrics().height());
return QSize(width, height);
}
void MultiLoadingIndicator::SetTaskManager(TaskManager* task_manager) {
@ -51,11 +62,24 @@ void MultiLoadingIndicator::UpdateText() {
strings << task_text;
}
QString text(strings.join(", "));
if (!text.isEmpty()) {
text[0] = text[0].toUpper();
text_ = strings.join(", ");
if (!text_.isEmpty()) {
text_[0] = text_[0].toUpper();
text_ += "...";
}
ui_->text->setText(text + "...");
emit TaskCountChange(tasks.count());
update();
updateGeometry();
}
void MultiLoadingIndicator::paintEvent(QPaintEvent*) {
QPainter p(this);
const QRect text_rect(
kHorizontalPadding + spinner_->sizeHint().width() + kSpacing,
kVerticalPadding,
width() - kHorizontalPadding*2 - spinner_->sizeHint().width() - kSpacing,
height() - kVerticalPadding*2);
p.drawText(text_rect, fontMetrics().elidedText(text_, Qt::ElideRight, text_rect.width()));
}

View File

@ -20,27 +20,37 @@
#include <QWidget>
class BusyIndicator;
class TaskManager;
class Ui_MultiLoadingIndicator;
class MultiLoadingIndicator : public QWidget {
Q_OBJECT
public:
public:
MultiLoadingIndicator(QWidget* parent = 0);
~MultiLoadingIndicator();
static const int kVerticalPadding;
static const int kHorizontalPadding;
static const int kSpacing;
void SetTaskManager(TaskManager* task_manager);
signals:
QSize sizeHint() const;
signals:
void TaskCountChange(int tasks);
private slots:
protected:
void paintEvent(QPaintEvent*);
private slots:
void UpdateText();
private:
Ui_MultiLoadingIndicator* ui_;
private:
TaskManager* task_manager_;
BusyIndicator* spinner_;
QString text_;
};
#endif // MULTILOADINGINDICATOR_H

View File

@ -1,56 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MultiLoadingIndicator</class>
<widget class="QWidget" name="MultiLoadingIndicator">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>191</width>
<height>24</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="BusyIndicator" name="spinner">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="text"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BusyIndicator</class>
<extends>QLabel</extends>
<header>widgets/busyindicator.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>