1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

[ReloadStopButton] It is now only one button

Instead of hiding and showing two buttons (reload and stop), use
only one ToolButton and change the object name accordingly.
This commit is contained in:
David Rosca 2014-04-19 14:40:54 +02:00
parent 927c8b2a17
commit f21be271b2
2 changed files with 33 additions and 42 deletions

View File

@ -16,47 +16,27 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "reloadstopbutton.h"
#include "toolbutton.h"
#include <QHBoxLayout>
#include <QTimer>
#include <QStyle>
ReloadStopButton::ReloadStopButton(QWidget* parent)
: QWidget(parent)
: ToolButton(parent)
, m_loadInProgress(false)
{
QHBoxLayout* lay = new QHBoxLayout(this);
setLayout(lay);
m_buttonStop = new ToolButton(this);
m_buttonStop->setObjectName("navigation-button-stop");
m_buttonStop->setToolTip(ToolButton::tr("Stop"));
m_buttonStop->setToolButtonStyle(Qt::ToolButtonIconOnly);
m_buttonStop->setToolbarButtonLook(true);
m_buttonStop->setVisible(false);
m_buttonStop->setAutoRaise(true);
m_buttonStop->setFocusPolicy(Qt::NoFocus);
m_buttonReload = new ToolButton(this);
m_buttonReload->setObjectName("navigation-button-reload");
m_buttonReload->setToolTip(ToolButton::tr("Reload"));
m_buttonReload->setToolButtonStyle(Qt::ToolButtonIconOnly);
m_buttonReload->setToolbarButtonLook(true);
m_buttonReload->setAutoRaise(true);
m_buttonReload->setFocusPolicy(Qt::NoFocus);
lay->addWidget(m_buttonStop);
lay->addWidget(m_buttonReload);
lay->setContentsMargins(0, 0, 0, 0);
lay->setSpacing(0);
setToolButtonStyle(Qt::ToolButtonIconOnly);
setToolbarButtonLook(true);
setAutoRaise(true);
setFocusPolicy(Qt::NoFocus);
m_updateTimer = new QTimer(this);
m_updateTimer->setInterval(100);
m_updateTimer->setInterval(50);
m_updateTimer->setSingleShot(true);
connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateButton()));
connect(m_buttonStop, SIGNAL(clicked()), this, SIGNAL(stopClicked()));
connect(m_buttonReload, SIGNAL(clicked()), this, SIGNAL(reloadClicked()));
connect(this, SIGNAL(clicked()), this, SLOT(buttonClicked()));
updateButton();
}
void ReloadStopButton::showStopButton()
@ -73,8 +53,24 @@ void ReloadStopButton::showReloadButton()
void ReloadStopButton::updateButton()
{
setUpdatesEnabled(false);
m_buttonStop->setVisible(m_loadInProgress);
m_buttonReload->setVisible(!m_loadInProgress);
setUpdatesEnabled(true);
if (m_loadInProgress) {
setToolTip(tr("Stop"));
setObjectName(QSL("navigation-button-stop"));
}
else {
setToolTip(tr("Reload"));
setObjectName(QSL("navigation-button-reload"));
}
// Update the stylesheet for the changed object name
style()->unpolish(this);
style()->polish(this);
}
void ReloadStopButton::buttonClicked()
{
if (m_loadInProgress)
emit stopClicked();
else
emit reloadClicked();
}

View File

@ -18,15 +18,12 @@
#ifndef RELOADSTOPBUTTON_H
#define RELOADSTOPBUTTON_H
#include <QWidget>
#include "qzcommon.h"
#include "toolbutton.h"
class QTimer;
class ToolButton;
class QUPZILLA_EXPORT ReloadStopButton : public QWidget
class QUPZILLA_EXPORT ReloadStopButton : public ToolButton
{
Q_OBJECT
@ -42,13 +39,11 @@ signals:
private slots:
void updateButton();
void buttonClicked();
private:
bool m_loadInProgress;
QTimer* m_updateTimer;
ToolButton* m_buttonStop;
ToolButton* m_buttonReload;
};
#endif // RELOADSTOPBUTTON_H