Falkon Develop
Cross-platform Qt-based web browser
reloadstopbutton.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "reloadstopbutton.h"
19
20#include <QTimer>
21#include <QStyle>
22
24 : ToolButton(parent)
25 , m_loadInProgress(false)
26{
27 setToolButtonStyle(Qt::ToolButtonIconOnly);
29 setAutoRaise(true);
30 setFocusPolicy(Qt::NoFocus);
31
32 m_updateTimer = new QTimer(this);
33 m_updateTimer->setInterval(50);
34 m_updateTimer->setSingleShot(true);
35 connect(m_updateTimer, &QTimer::timeout, this, &ReloadStopButton::updateButton);
36
37 connect(this, &QAbstractButton::clicked, this, &ReloadStopButton::buttonClicked);
38
39 updateButton();
40}
41
43{
44 m_loadInProgress = true;
45 m_updateTimer->start();
46}
47
49{
50 m_loadInProgress = false;
51 m_updateTimer->start();
52}
53
54void ReloadStopButton::updateButton()
55{
56 if (m_loadInProgress) {
57 setToolTip(tr("Stop"));
58 setObjectName(QSL("navigation-button-stop"));
59 }
60 else {
61 setToolTip(tr("Reload"));
62 setObjectName(QSL("navigation-button-reload"));
63 }
64
65 // Update the stylesheet for the changed object name
66 style()->unpolish(this);
67 style()->polish(this);
68}
69
70void ReloadStopButton::buttonClicked()
71{
72 if (m_loadInProgress)
73 Q_EMIT stopClicked();
74 else
75 Q_EMIT reloadClicked();
76}
ReloadStopButton(QWidget *parent=nullptr)
void setToolbarButtonLook(bool enable)
Definition: toolbutton.cpp:138
#define QSL(x)
Definition: qzcommon.h:40