2013-07-10 17:57:23 -04:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 RetroShare Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QWidget>
|
|
|
|
#include <QLineEdit>
|
2014-08-01 14:54:55 -04:00
|
|
|
#include <QProgressBar>
|
2013-07-10 17:57:23 -04:00
|
|
|
|
|
|
|
#include "UIStateHelper.h"
|
|
|
|
#include "RSTreeWidget.h"
|
2013-09-23 15:53:26 -04:00
|
|
|
#include "RSTextBrowser.h"
|
2014-12-14 12:05:43 -05:00
|
|
|
#include "ElidedLabel.h"
|
2013-07-10 17:57:23 -04:00
|
|
|
|
|
|
|
class UIStateHelperObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UIStateHelperObject(QLabel *widget)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
mLabel = widget;
|
|
|
|
}
|
2014-12-14 12:05:43 -05:00
|
|
|
UIStateHelperObject(ElidedLabel *widget)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
mElidedLabel = widget;
|
|
|
|
}
|
2013-07-10 17:57:23 -04:00
|
|
|
UIStateHelperObject(QLineEdit *widget)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
mLineEdit = widget;
|
|
|
|
}
|
|
|
|
UIStateHelperObject(RSTreeWidget *widget)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
mTreeWidget = widget;
|
|
|
|
}
|
2013-09-23 15:53:26 -04:00
|
|
|
UIStateHelperObject(RSTextBrowser *widget)
|
2013-07-10 17:57:23 -04:00
|
|
|
{
|
|
|
|
init();
|
2013-09-23 15:53:26 -04:00
|
|
|
mRSTextBrowser = widget;
|
2013-07-10 17:57:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void setPlaceholder(bool loading, const QString &text, bool clear) const
|
|
|
|
{
|
|
|
|
if (mLabel) {
|
|
|
|
mLabel->setText(text);
|
|
|
|
}
|
|
|
|
|
2014-12-14 12:05:43 -05:00
|
|
|
if (mElidedLabel) {
|
|
|
|
mElidedLabel->setText(text);
|
|
|
|
}
|
|
|
|
|
2013-07-10 17:57:23 -04:00
|
|
|
if (mLineEdit) {
|
|
|
|
if (loading && clear) {
|
|
|
|
mLineEdit->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK (4, 8, 0)
|
|
|
|
mLineEdit->setPlaceholderText(text);
|
|
|
|
#else
|
|
|
|
mLineEdit->setText(text);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mTreeWidget) {
|
|
|
|
if (loading && clear) {
|
|
|
|
mTreeWidget->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
mTreeWidget->setPlaceholderText(text);
|
|
|
|
}
|
|
|
|
|
2013-09-23 15:53:26 -04:00
|
|
|
if (mRSTextBrowser) {
|
2013-07-10 17:57:23 -04:00
|
|
|
if (loading && clear) {
|
2013-09-23 15:53:26 -04:00
|
|
|
mRSTextBrowser->clear();
|
2013-07-10 17:57:23 -04:00
|
|
|
}
|
|
|
|
|
2013-09-23 15:53:26 -04:00
|
|
|
mRSTextBrowser->setPlaceholderText(text);
|
2013-07-10 17:57:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
if (mLabel) {
|
|
|
|
mLabel->clear();
|
|
|
|
}
|
|
|
|
|
2014-12-14 12:05:43 -05:00
|
|
|
if (mElidedLabel) {
|
|
|
|
mElidedLabel->clear();
|
|
|
|
}
|
|
|
|
|
2013-07-10 17:57:23 -04:00
|
|
|
if (mLineEdit) {
|
|
|
|
mLineEdit->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mTreeWidget) {
|
|
|
|
mTreeWidget->clear();
|
|
|
|
}
|
|
|
|
|
2013-09-23 15:53:26 -04:00
|
|
|
if (mRSTextBrowser) {
|
|
|
|
mRSTextBrowser->clear();
|
2013-07-10 17:57:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-12 13:24:11 -04:00
|
|
|
QWidget *widget() const
|
|
|
|
{
|
|
|
|
if (mLabel) {
|
|
|
|
return mLabel;
|
|
|
|
}
|
|
|
|
|
2014-12-14 12:05:43 -05:00
|
|
|
if (mElidedLabel) {
|
|
|
|
return mElidedLabel;
|
|
|
|
}
|
|
|
|
|
2013-07-12 13:24:11 -04:00
|
|
|
if (mLineEdit) {
|
|
|
|
return mLineEdit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mTreeWidget) {
|
|
|
|
return mTreeWidget;
|
|
|
|
}
|
|
|
|
|
2013-09-23 15:53:26 -04:00
|
|
|
if (mRSTextBrowser) {
|
|
|
|
return mRSTextBrowser;
|
2013-07-12 13:24:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isWidget(QWidget *widget) const
|
|
|
|
{
|
|
|
|
if (mLabel == widget) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-14 12:05:43 -05:00
|
|
|
if (mElidedLabel == widget) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-12 13:24:11 -04:00
|
|
|
if (mLineEdit == widget) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mTreeWidget == widget) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-23 15:53:26 -04:00
|
|
|
if (mRSTextBrowser == widget) {
|
2013-07-12 13:24:11 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-10 17:57:23 -04:00
|
|
|
bool operator ==(const UIStateHelperObject &data) const
|
|
|
|
{
|
|
|
|
if (mLabel == data.mLabel &&
|
2014-12-14 12:05:43 -05:00
|
|
|
mElidedLabel == data.mElidedLabel &&
|
|
|
|
mLineEdit == data.mLineEdit &&
|
|
|
|
mTreeWidget == data.mTreeWidget &&
|
|
|
|
mRSTextBrowser == data.mRSTextBrowser) {
|
2013-07-10 17:57:23 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator <(const UIStateHelperObject &data) const
|
|
|
|
{
|
|
|
|
if (mLabel < data.mLabel ||
|
2014-12-14 12:05:43 -05:00
|
|
|
mElidedLabel < data.mElidedLabel ||
|
|
|
|
mLineEdit < data.mLineEdit ||
|
|
|
|
mTreeWidget < data.mTreeWidget ||
|
|
|
|
mRSTextBrowser < data.mRSTextBrowser) {
|
2013-07-10 17:57:23 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void init()
|
|
|
|
{
|
|
|
|
mLabel = NULL;
|
2014-12-14 12:05:43 -05:00
|
|
|
mElidedLabel = NULL;
|
2013-07-10 17:57:23 -04:00
|
|
|
mLineEdit = NULL;
|
|
|
|
mTreeWidget = NULL;
|
2013-09-23 15:53:26 -04:00
|
|
|
mRSTextBrowser = NULL;
|
2013-07-10 17:57:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QLabel *mLabel;
|
2014-12-14 12:05:43 -05:00
|
|
|
ElidedLabel *mElidedLabel;
|
2013-07-10 17:57:23 -04:00
|
|
|
QLineEdit *mLineEdit;
|
|
|
|
RSTreeWidget *mTreeWidget;
|
2013-09-23 15:53:26 -04:00
|
|
|
RSTextBrowser *mRSTextBrowser;
|
2013-07-10 17:57:23 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class UIStateHelperData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UIStateHelperData()
|
|
|
|
{
|
|
|
|
mLoading = false;
|
|
|
|
mActive = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool mLoading;
|
|
|
|
bool mActive;
|
|
|
|
QMap<QWidget*, UIStates> mWidgets;
|
|
|
|
QMap<UIStateHelperObject, QPair<QString, bool> > mLoad;
|
|
|
|
QList<UIStateHelperObject> mClear;
|
|
|
|
};
|
|
|
|
|
|
|
|
UIStateHelper::UIStateHelper(QObject *parent) :
|
|
|
|
QObject(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UIStateHelper::~UIStateHelper()
|
|
|
|
{
|
|
|
|
QMap<long, UIStateHelperData*>::iterator it;
|
|
|
|
for (it = mData.begin(); it != mData.end(); ++it) {
|
|
|
|
delete(it.value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UIStateHelperData *UIStateHelper::findData(int index, bool create)
|
|
|
|
{
|
|
|
|
UIStateHelperData *data = NULL;
|
|
|
|
|
|
|
|
QMap<long, UIStateHelperData*>::iterator it = mData.find(index);
|
|
|
|
if (it == mData.end()) {
|
|
|
|
if (create) {
|
|
|
|
data = new UIStateHelperData;
|
|
|
|
mData[index] = data;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
data = it.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIStateHelper::addWidget(int index, QWidget *widget, UIStates states)
|
|
|
|
{
|
|
|
|
UIStateHelperData *data = findData(index, true);
|
|
|
|
data->mWidgets.insert(widget, states);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIStateHelper::addLoadPlaceholder(int index, QLabel *widget, bool clear, const QString &text)
|
2014-12-14 12:05:43 -05:00
|
|
|
{
|
|
|
|
UIStateHelperData *data = findData(index, true);
|
|
|
|
data->mLoad.insert(UIStateHelperObject(widget), QPair<QString, bool>(text.isEmpty() ? tr("Loading") : text, clear));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIStateHelper::addLoadPlaceholder(int index, ElidedLabel *widget, bool clear, const QString &text)
|
2013-07-10 17:57:23 -04:00
|
|
|
{
|
|
|
|
UIStateHelperData *data = findData(index, true);
|
|
|
|
data->mLoad.insert(UIStateHelperObject(widget), QPair<QString, bool>(text.isEmpty() ? tr("Loading") : text, clear));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIStateHelper::addLoadPlaceholder(int index, QLineEdit *widget, bool clear, const QString &text)
|
|
|
|
{
|
|
|
|
UIStateHelperData *data = findData(index, true);
|
|
|
|
data->mLoad.insert(UIStateHelperObject(widget), QPair<QString, bool>(text.isEmpty() ? tr("Loading") : text, clear));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIStateHelper::addLoadPlaceholder(int index, RSTreeWidget *widget, bool clear, const QString &text)
|
|
|
|
{
|
|
|
|
UIStateHelperData *data = findData(index, true);
|
|
|
|
data->mLoad.insert(UIStateHelperObject(widget), QPair<QString, bool>(text.isEmpty() ? tr("Loading") : text, clear));
|
|
|
|
}
|
|
|
|
|
2013-09-23 15:53:26 -04:00
|
|
|
void UIStateHelper::addLoadPlaceholder(int index, RSTextBrowser *widget, bool clear, const QString &text)
|
2013-07-10 17:57:23 -04:00
|
|
|
{
|
|
|
|
UIStateHelperData *data = findData(index, true);
|
|
|
|
data->mLoad.insert(UIStateHelperObject(widget), QPair<QString, bool>(text.isEmpty() ? tr("Loading") : text, clear));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIStateHelper::addClear(int index, QLabel *widget)
|
|
|
|
{
|
|
|
|
UIStateHelperData *data = findData(index, true);
|
|
|
|
if (data->mClear.contains(widget)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
data->mClear.push_back(UIStateHelperObject(widget));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIStateHelper::addClear(int index, QLineEdit *widget)
|
|
|
|
{
|
|
|
|
UIStateHelperData *data = findData(index, true);
|
|
|
|
if (data->mClear.contains(widget)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
data->mClear.push_back(UIStateHelperObject(widget));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIStateHelper::addClear(int index, RSTreeWidget *widget)
|
|
|
|
{
|
|
|
|
UIStateHelperData *data = findData(index, true);
|
|
|
|
if (data->mClear.contains(widget)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
data->mClear.push_back(UIStateHelperObject(widget));
|
|
|
|
}
|
|
|
|
|
2013-09-23 15:53:26 -04:00
|
|
|
void UIStateHelper::addClear(int index, RSTextBrowser *widget)
|
2013-07-10 17:57:23 -04:00
|
|
|
{
|
|
|
|
UIStateHelperData *data = findData(index, true);
|
|
|
|
if (data->mClear.contains(widget)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
data->mClear.push_back(UIStateHelperObject(widget));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UIStateHelper::isWidgetVisible(QWidget *widget)
|
|
|
|
{
|
|
|
|
bool visible = true;
|
|
|
|
|
|
|
|
QMap<QWidget*, bool>::iterator itVisible = mWidgetVisible.find(widget);
|
|
|
|
if (itVisible != mWidgetVisible.end()) {
|
|
|
|
visible = itVisible.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visible) {
|
2014-08-06 13:41:22 -04:00
|
|
|
int visibleCount = 0;
|
|
|
|
int invisibleCount = 0;
|
|
|
|
|
2013-07-10 17:57:23 -04:00
|
|
|
QMap<long, UIStateHelperData*>::iterator dataIt;
|
|
|
|
for (dataIt = mData.begin(); dataIt != mData.end(); ++dataIt) {
|
|
|
|
UIStateHelperData *data = dataIt.value();
|
|
|
|
QMap<QWidget*, UIStates>::iterator it = data->mWidgets.find(widget);
|
|
|
|
if (it == data->mWidgets.end()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
UIStates states = it.value();
|
|
|
|
|
|
|
|
if (states & (UISTATE_LOADING_VISIBLE | UISTATE_LOADING_INVISIBLE)) {
|
|
|
|
if (states & UISTATE_LOADING_VISIBLE) {
|
2014-08-06 13:41:22 -04:00
|
|
|
if (data->mLoading) {
|
|
|
|
++visibleCount;
|
|
|
|
} else {
|
|
|
|
++invisibleCount;
|
2013-07-10 17:57:23 -04:00
|
|
|
}
|
|
|
|
} else if (states & UISTATE_LOADING_INVISIBLE) {
|
|
|
|
if (data->mLoading) {
|
2014-08-06 13:41:22 -04:00
|
|
|
++invisibleCount;
|
|
|
|
} else {
|
|
|
|
++visibleCount;
|
2013-07-10 17:57:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (states & (UISTATE_ACTIVE_VISIBLE | UISTATE_ACTIVE_INVISIBLE)) {
|
|
|
|
if (states & UISTATE_ACTIVE_VISIBLE) {
|
2014-08-06 13:41:22 -04:00
|
|
|
if (data->mActive) {
|
|
|
|
++visibleCount;
|
|
|
|
} else {
|
|
|
|
++invisibleCount;
|
2013-07-10 17:57:23 -04:00
|
|
|
}
|
|
|
|
} else if (states & UISTATE_ACTIVE_INVISIBLE) {
|
|
|
|
if (data->mActive) {
|
2014-08-06 13:41:22 -04:00
|
|
|
++invisibleCount;
|
|
|
|
} else {
|
|
|
|
++visibleCount;
|
2013-07-10 17:57:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-06 13:41:22 -04:00
|
|
|
|
|
|
|
if (visibleCount + invisibleCount) {
|
|
|
|
if (!visibleCount) {
|
|
|
|
visible = false;
|
|
|
|
}
|
|
|
|
}
|
2013-07-10 17:57:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UIStateHelper::isWidgetEnabled(QWidget *widget)
|
|
|
|
{
|
|
|
|
bool enabled = true;
|
|
|
|
|
|
|
|
QMap<QWidget*, bool>::iterator itEnabled = mWidgetEnabled.find(widget);
|
|
|
|
if (itEnabled != mWidgetEnabled.end()) {
|
|
|
|
enabled = itEnabled.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enabled) {
|
|
|
|
QMap<long, UIStateHelperData*>::iterator dataIt;
|
|
|
|
for (dataIt = mData.begin(); dataIt != mData.end(); ++dataIt) {
|
|
|
|
UIStateHelperData *data = dataIt.value();
|
|
|
|
QMap<QWidget*, UIStates>::iterator it = data->mWidgets.find(widget);
|
|
|
|
if (it == data->mWidgets.end()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
UIStates states = it.value();
|
|
|
|
|
|
|
|
if (states & (UISTATE_LOADING_ENABLED | UISTATE_LOADING_DISABLED)) {
|
|
|
|
if (states & UISTATE_LOADING_ENABLED) {
|
|
|
|
if (!data->mLoading) {
|
|
|
|
enabled = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (states & UISTATE_LOADING_DISABLED) {
|
|
|
|
if (data->mLoading) {
|
|
|
|
enabled = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (states & (UISTATE_ACTIVE_ENABLED | UISTATE_ACTIVE_DISABLED)) {
|
|
|
|
if (states & UISTATE_ACTIVE_ENABLED) {
|
|
|
|
if (!data->mActive) {
|
|
|
|
enabled = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (states & UISTATE_ACTIVE_DISABLED) {
|
|
|
|
if (data->mActive) {
|
|
|
|
enabled = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
2013-07-12 13:24:11 -04:00
|
|
|
bool UIStateHelper::isWidgetLoading(QWidget *widget, QString &text)
|
|
|
|
{
|
|
|
|
bool loading = false;
|
|
|
|
text.clear();
|
|
|
|
|
|
|
|
QMap<long, UIStateHelperData*>::iterator dataIt;
|
|
|
|
for (dataIt = mData.begin(); dataIt != mData.end(); ++dataIt) {
|
|
|
|
UIStateHelperData *data = dataIt.value();
|
|
|
|
QMap<UIStateHelperObject, QPair<QString, bool> >::iterator it;
|
|
|
|
for (it = data->mLoad.begin(); it != data->mLoad.end(); ++it) {
|
|
|
|
if (it.key().isWidget(widget)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (it != data->mLoad.end()) {
|
|
|
|
if (dataIt.value()->mLoading) {
|
|
|
|
loading = true;
|
|
|
|
text = it.value().first;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return loading;
|
|
|
|
}
|
|
|
|
|
2013-07-10 17:57:23 -04:00
|
|
|
void UIStateHelper::updateData(UIStateHelperData *data)
|
|
|
|
{
|
|
|
|
QMap<QWidget*, UIStates>::iterator it;
|
|
|
|
for (it = data->mWidgets.begin(); it != data->mWidgets.end(); ++it) {
|
|
|
|
QWidget *widget = it.key();
|
|
|
|
UIStates states = it.value();
|
|
|
|
|
|
|
|
if (states & (UISTATE_LOADING_VISIBLE | UISTATE_LOADING_INVISIBLE | UISTATE_ACTIVE_VISIBLE | UISTATE_ACTIVE_INVISIBLE)) {
|
2014-08-01 14:54:55 -04:00
|
|
|
bool visible = isWidgetVisible(widget);
|
|
|
|
widget->setVisible(visible);
|
|
|
|
|
|
|
|
if (!visible) {
|
|
|
|
/* Reset progressbar */
|
|
|
|
QProgressBar *progressBar = dynamic_cast<QProgressBar*>(widget);
|
|
|
|
if (progressBar) {
|
|
|
|
progressBar->setValue(0);
|
|
|
|
}
|
|
|
|
}
|
2013-07-10 17:57:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (states & (UISTATE_LOADING_ENABLED | UISTATE_LOADING_DISABLED | UISTATE_ACTIVE_ENABLED | UISTATE_ACTIVE_DISABLED)) {
|
|
|
|
widget->setEnabled(isWidgetEnabled(widget));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIStateHelper::setLoading(int index, bool loading)
|
|
|
|
{
|
|
|
|
UIStateHelperData *data = findData(index, false);
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
data->mLoading = loading;
|
|
|
|
|
|
|
|
updateData(data);
|
|
|
|
|
|
|
|
QMap<UIStateHelperObject, QPair<QString, bool> >::iterator it;
|
|
|
|
for (it = data->mLoad.begin(); it != data->mLoad.end(); ++it) {
|
2013-07-12 13:24:11 -04:00
|
|
|
const UIStateHelperObject &object = it.key();
|
|
|
|
|
2013-07-10 17:57:23 -04:00
|
|
|
if (loading) {
|
2013-07-12 13:24:11 -04:00
|
|
|
object.setPlaceholder(loading, it.value().first, it.value().second);
|
2013-07-10 17:57:23 -04:00
|
|
|
} else {
|
2013-07-12 13:24:11 -04:00
|
|
|
QString text;
|
|
|
|
if (isWidgetLoading(object.widget(), text)) {
|
|
|
|
object.setPlaceholder(true, text, it.value().second);
|
|
|
|
} else {
|
|
|
|
object.setPlaceholder(loading, "", it.value().second);
|
|
|
|
}
|
2013-07-10 17:57:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIStateHelper::setActive(int index, bool active)
|
|
|
|
{
|
|
|
|
UIStateHelperData *data = findData(index, false);
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
data->mActive = active;
|
|
|
|
|
|
|
|
updateData(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIStateHelper::clear(int index)
|
|
|
|
{
|
|
|
|
UIStateHelperData *data = findData(index, false);
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QList<UIStateHelperObject>::iterator it;
|
|
|
|
for (it = data->mClear.begin(); it != data->mClear.end(); ++it) {
|
|
|
|
it->clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UIStateHelper::isLoading(int index)
|
|
|
|
{
|
|
|
|
UIStateHelperData *data = findData(index, false);
|
|
|
|
if (data) {
|
|
|
|
return data->mLoading;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UIStateHelper::isActive(int index)
|
|
|
|
{
|
|
|
|
UIStateHelperData *data = findData(index, false);
|
|
|
|
if (data) {
|
|
|
|
return data->mActive;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIStateHelper::setWidgetVisible(QWidget *widget, bool visible)
|
|
|
|
{
|
|
|
|
mWidgetVisible[widget] = visible;
|
|
|
|
|
|
|
|
QMap<long, UIStateHelperData*>::iterator dataIt;
|
|
|
|
for (dataIt = mData.begin(); dataIt != mData.end(); ++dataIt) {
|
|
|
|
updateData(*dataIt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIStateHelper::setWidgetEnabled(QWidget *widget, bool enabled)
|
|
|
|
{
|
|
|
|
mWidgetEnabled[widget] = enabled;
|
|
|
|
|
|
|
|
QMap<long, UIStateHelperData*>::iterator dataIt;
|
|
|
|
for (dataIt = mData.begin(); dataIt != mData.end(); ++dataIt) {
|
|
|
|
updateData(*dataIt);
|
|
|
|
}
|
|
|
|
}
|