Make the BusyIndicator contain a label too

This commit is contained in:
David Sansome 2011-08-27 15:00:49 +01:00
parent 72198db1ba
commit 143bbb4019
13 changed files with 101 additions and 103 deletions

View File

@ -393,7 +393,7 @@
</customwidget>
<customwidget>
<class>BusyIndicator</class>
<extends>QLabel</extends>
<extends>QWidget</extends>
<header>widgets/busyindicator.h</header>
</customwidget>
</customwidgets>

View File

@ -239,7 +239,7 @@
<customwidgets>
<customwidget>
<class>BusyIndicator</class>
<extends>QLabel</extends>
<extends>QWidget</extends>
<header>widgets/busyindicator.h</header>
</customwidget>
</customwidgets>
@ -253,5 +253,38 @@
<tabstop>scrobble_button</tabstop>
</tabstops>
<resources/>
<connections/>
<connections>
<connection>
<sender>username</sender>
<signal>returnPressed()</signal>
<receiver>login</receiver>
<slot>click()</slot>
<hints>
<hint type="sourcelabel">
<x>332</x>
<y>104</y>
</hint>
<hint type="destinationlabel">
<x>706</x>
<y>103</y>
</hint>
</hints>
</connection>
<connection>
<sender>password</sender>
<signal>returnPressed()</signal>
<receiver>login</receiver>
<slot>click()</slot>
<hints>
<hint type="sourcelabel">
<x>719</x>
<y>137</y>
</hint>
<hint type="destinationlabel">
<x>725</x>
<y>108</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -200,7 +200,7 @@
<customwidgets>
<customwidget>
<class>BusyIndicator</class>
<extends>QLabel</extends>
<extends>QWidget</extends>
<header>widgets/busyindicator.h</header>
</customwidget>
</customwidgets>

View File

@ -240,7 +240,7 @@
<customwidgets>
<customwidget>
<class>BusyIndicator</class>
<extends>QLabel</extends>
<extends>QWidget</extends>
<header>widgets/busyindicator.h</header>
</customwidget>
</customwidgets>

View File

@ -198,7 +198,7 @@
<customwidgets>
<customwidget>
<class>BusyIndicator</class>
<extends>QLabel</extends>
<extends>QWidget</extends>
<header>widgets/busyindicator.h</header>
</customwidget>
</customwidgets>

View File

@ -87,7 +87,7 @@
</customwidget>
<customwidget>
<class>BusyIndicator</class>
<extends>QLabel</extends>
<extends>QWidget</extends>
<header>widgets/busyindicator.h</header>
</customwidget>
<customwidget>

View File

@ -34,14 +34,7 @@
</widget>
</item>
<item>
<widget class="BusyIndicator" name="busy">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="BusyIndicator" name="busy"/>
</item>
</layout>
</item>
@ -80,7 +73,7 @@
<customwidgets>
<customwidget>
<class>BusyIndicator</class>
<extends>QLabel</extends>
<extends>QWidget</extends>
<header>widgets/busyindicator.h</header>
</customwidget>
</customwidgets>

View File

@ -75,7 +75,7 @@ EditTagDialog::EditTagDialog(CoverProviders* cover_providers, QWidget* parent)
ui_->setupUi(this);
ui_->splitter->setSizes(QList<int>() << 200 << width() - 200);
ui_->loading_container->hide();
ui_->loading_label->hide();
// An editable field is one that has a label as a buddy. The label is
// important because it gets turned bold when the field is changed.
@ -178,12 +178,12 @@ bool EditTagDialog::SetLoading(const QString& message) {
return false;
loading_ = loading;
ui_->loading_container->setVisible(loading);
ui_->button_box->setEnabled(!loading);
ui_->tab_widget->setEnabled(!loading);
ui_->song_list->setEnabled(!loading);
ui_->fetch_tag->setEnabled(!loading);
ui_->loading_label->setText(message);
ui_->loading_label->setVisible(loading);
ui_->loading_label->set_text(message);
return true;
}

View File

@ -841,39 +841,7 @@
</widget>
</item>
<item>
<widget class="QWidget" name="loading_container" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="BusyIndicator" name="label_2">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="loading_label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="BusyIndicator" name="loading_label"/>
</item>
<item>
<widget class="QDialogButtonBox" name="button_box">
@ -885,6 +853,11 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BusyIndicator</class>
<extends>QWidget</extends>
<header>widgets/busyindicator.h</header>
</customwidget>
<customwidget>
<class>LineEdit</class>
<extends>QLineEdit</extends>
@ -906,11 +879,6 @@
<extends>QSpinBox</extends>
<header>widgets/lineedit.h</header>
</customwidget>
<customwidget>
<class>BusyIndicator</class>
<extends>QLabel</extends>
<header>widgets/busyindicator.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../../data/data.qrc"/>

View File

@ -149,7 +149,7 @@ void TrackSelectionDialog::UpdateStack() {
if (data.pending_) {
ui_->stack->setCurrentWidget(ui_->loading_page);
ui_->progress_label->setText(data.progress_string_ + "...");
ui_->progress->set_text(data.progress_string_ + "...");
return;
} else if (data.results_.isEmpty()) {
ui_->stack->setCurrentWidget(ui_->error_page);
@ -220,10 +220,10 @@ void TrackSelectionDialog::ResultSelected() {
void TrackSelectionDialog::SetLoading(const QString& message) {
const bool loading = !message.isEmpty();
ui_->loading_container->setVisible(loading);
ui_->button_box->setEnabled(!loading);
ui_->splitter->setEnabled(!loading);
ui_->loading_label->setText(message);
ui_->loading_label->setVisible(loading);
ui_->loading_label->set_text(message);
}
void TrackSelectionDialog::SaveData(const QList<Data>& data) {

View File

@ -69,14 +69,7 @@
</spacer>
</item>
<item>
<widget class="BusyIndicator" name="label_2"/>
</item>
<item>
<widget class="QLabel" name="progress_label">
<property name="text">
<string/>
</property>
</widget>
<widget class="BusyIndicator" name="progress"/>
</item>
<item>
<spacer name="horizontalSpacer_2">
@ -223,33 +216,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QWidget" name="loading_container" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="BusyIndicator" name="label_6">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="loading_label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="BusyIndicator" name="loading_label"/>
</item>
<item>
<widget class="QDialogButtonBox" name="button_box">
@ -274,7 +241,7 @@
<customwidgets>
<customwidget>
<class>BusyIndicator</class>
<extends>QLabel</extends>
<extends>QWidget</extends>
<header>widgets/busyindicator.h</header>
</customwidget>
</customwidgets>

View File

@ -17,14 +17,36 @@
#include "busyindicator.h"
#include <QHBoxLayout>
#include <QMovie>
BusyIndicator::BusyIndicator(const QString& text, QWidget* parent)
: QWidget(parent) {
Init(text);
}
BusyIndicator::BusyIndicator(QWidget* parent)
: QLabel(parent),
movie_(new QMovie(":spinner.gif"))
{
setMovie(movie_);
setMinimumSize(16, 16);
: QWidget(parent) {
Init(QString::null);
}
void BusyIndicator::Init(const QString& text) {
movie_ = new QMovie(":spinner.gif"),
label_ = new QLabel;
QLabel* icon = new QLabel;
icon->setMovie(movie_);
icon->setMinimumSize(16, 16);
label_->setWordWrap(true);
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(icon);
layout->addSpacing(6);
layout->addWidget(label_);
set_text(text);
}
BusyIndicator::~BusyIndicator() {
@ -38,3 +60,10 @@ void BusyIndicator::showEvent(QShowEvent*) {
void BusyIndicator::hideEvent(QHideEvent*) {
movie_->stop();
}
void BusyIndicator::set_text(const QString& text) {
label_->setText(text);
if (text.isEmpty())
label_->hide();
}

View File

@ -22,19 +22,27 @@
class QMovie;
class BusyIndicator : public QLabel {
class BusyIndicator : public QWidget {
Q_OBJECT
public:
BusyIndicator(QWidget* parent = 0);
explicit BusyIndicator(const QString& text, QWidget* parent = 0);
explicit BusyIndicator(QWidget* parent = 0);
~BusyIndicator();
QString text() const;
void set_text(const QString& text);
protected:
void showEvent(QShowEvent* event);
void hideEvent(QHideEvent* event);
private:
void Init(const QString& text);
private:
QMovie* movie_;
QLabel* label_;
};
#endif // BUSYINDICATOR_H