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>
<customwidget> <customwidget>
<class>BusyIndicator</class> <class>BusyIndicator</class>
<extends>QLabel</extends> <extends>QWidget</extends>
<header>widgets/busyindicator.h</header> <header>widgets/busyindicator.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>

View File

@ -239,7 +239,7 @@
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>BusyIndicator</class> <class>BusyIndicator</class>
<extends>QLabel</extends> <extends>QWidget</extends>
<header>widgets/busyindicator.h</header> <header>widgets/busyindicator.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
@ -253,5 +253,38 @@
<tabstop>scrobble_button</tabstop> <tabstop>scrobble_button</tabstop>
</tabstops> </tabstops>
<resources/> <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> </ui>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -75,7 +75,7 @@ EditTagDialog::EditTagDialog(CoverProviders* cover_providers, QWidget* parent)
ui_->setupUi(this); ui_->setupUi(this);
ui_->splitter->setSizes(QList<int>() << 200 << width() - 200); 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 // 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. // important because it gets turned bold when the field is changed.
@ -178,12 +178,12 @@ bool EditTagDialog::SetLoading(const QString& message) {
return false; return false;
loading_ = loading; loading_ = loading;
ui_->loading_container->setVisible(loading);
ui_->button_box->setEnabled(!loading); ui_->button_box->setEnabled(!loading);
ui_->tab_widget->setEnabled(!loading); ui_->tab_widget->setEnabled(!loading);
ui_->song_list->setEnabled(!loading); ui_->song_list->setEnabled(!loading);
ui_->fetch_tag->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; return true;
} }

View File

@ -841,39 +841,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QWidget" name="loading_container" native="true"> <widget class="BusyIndicator" name="loading_label"/>
<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>
</item> </item>
<item> <item>
<widget class="QDialogButtonBox" name="button_box"> <widget class="QDialogButtonBox" name="button_box">
@ -885,6 +853,11 @@
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget>
<class>BusyIndicator</class>
<extends>QWidget</extends>
<header>widgets/busyindicator.h</header>
</customwidget>
<customwidget> <customwidget>
<class>LineEdit</class> <class>LineEdit</class>
<extends>QLineEdit</extends> <extends>QLineEdit</extends>
@ -906,11 +879,6 @@
<extends>QSpinBox</extends> <extends>QSpinBox</extends>
<header>widgets/lineedit.h</header> <header>widgets/lineedit.h</header>
</customwidget> </customwidget>
<customwidget>
<class>BusyIndicator</class>
<extends>QLabel</extends>
<header>widgets/busyindicator.h</header>
</customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../../data/data.qrc"/> <include location="../../data/data.qrc"/>

View File

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

View File

@ -69,14 +69,7 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="BusyIndicator" name="label_2"/> <widget class="BusyIndicator" name="progress"/>
</item>
<item>
<widget class="QLabel" name="progress_label">
<property name="text">
<string/>
</property>
</widget>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_2">
@ -223,33 +216,7 @@
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<widget class="QWidget" name="loading_container" native="true"> <widget class="BusyIndicator" name="loading_label"/>
<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>
</item> </item>
<item> <item>
<widget class="QDialogButtonBox" name="button_box"> <widget class="QDialogButtonBox" name="button_box">
@ -274,7 +241,7 @@
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>BusyIndicator</class> <class>BusyIndicator</class>
<extends>QLabel</extends> <extends>QWidget</extends>
<header>widgets/busyindicator.h</header> <header>widgets/busyindicator.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>

View File

@ -17,14 +17,36 @@
#include "busyindicator.h" #include "busyindicator.h"
#include <QHBoxLayout>
#include <QMovie> #include <QMovie>
BusyIndicator::BusyIndicator(const QString& text, QWidget* parent)
: QWidget(parent) {
Init(text);
}
BusyIndicator::BusyIndicator(QWidget* parent) BusyIndicator::BusyIndicator(QWidget* parent)
: QLabel(parent), : QWidget(parent) {
movie_(new QMovie(":spinner.gif")) Init(QString::null);
{ }
setMovie(movie_);
setMinimumSize(16, 16); 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() { BusyIndicator::~BusyIndicator() {
@ -38,3 +60,10 @@ void BusyIndicator::showEvent(QShowEvent*) {
void BusyIndicator::hideEvent(QHideEvent*) { void BusyIndicator::hideEvent(QHideEvent*) {
movie_->stop(); 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 QMovie;
class BusyIndicator : public QLabel { class BusyIndicator : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
BusyIndicator(QWidget* parent = 0); explicit BusyIndicator(const QString& text, QWidget* parent = 0);
explicit BusyIndicator(QWidget* parent = 0);
~BusyIndicator(); ~BusyIndicator();
QString text() const;
void set_text(const QString& text);
protected: protected:
void showEvent(QShowEvent* event); void showEvent(QShowEvent* event);
void hideEvent(QHideEvent* event); void hideEvent(QHideEvent* event);
private:
void Init(const QString& text);
private: private:
QMovie* movie_; QMovie* movie_;
QLabel* label_;
}; };
#endif // BUSYINDICATOR_H #endif // BUSYINDICATOR_H