File indexing completed on 2024-05-12 04:58:09
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #include "reloadstopbutton.h" 0019 0020 #include <QTimer> 0021 #include <QStyle> 0022 0023 ReloadStopButton::ReloadStopButton(QWidget* parent) 0024 : ToolButton(parent) 0025 , m_loadInProgress(false) 0026 { 0027 setToolButtonStyle(Qt::ToolButtonIconOnly); 0028 setToolbarButtonLook(true); 0029 setAutoRaise(true); 0030 setFocusPolicy(Qt::NoFocus); 0031 0032 m_updateTimer = new QTimer(this); 0033 m_updateTimer->setInterval(50); 0034 m_updateTimer->setSingleShot(true); 0035 connect(m_updateTimer, &QTimer::timeout, this, &ReloadStopButton::updateButton); 0036 0037 connect(this, &QAbstractButton::clicked, this, &ReloadStopButton::buttonClicked); 0038 0039 updateButton(); 0040 } 0041 0042 void ReloadStopButton::showStopButton() 0043 { 0044 m_loadInProgress = true; 0045 m_updateTimer->start(); 0046 } 0047 0048 void ReloadStopButton::showReloadButton() 0049 { 0050 m_loadInProgress = false; 0051 m_updateTimer->start(); 0052 } 0053 0054 void ReloadStopButton::updateButton() 0055 { 0056 if (m_loadInProgress) { 0057 setToolTip(tr("Stop")); 0058 setObjectName(QSL("navigation-button-stop")); 0059 } 0060 else { 0061 setToolTip(tr("Reload")); 0062 setObjectName(QSL("navigation-button-reload")); 0063 } 0064 0065 // Update the stylesheet for the changed object name 0066 style()->unpolish(this); 0067 style()->polish(this); 0068 } 0069 0070 void ReloadStopButton::buttonClicked() 0071 { 0072 if (m_loadInProgress) 0073 Q_EMIT stopClicked(); 0074 else 0075 Q_EMIT reloadClicked(); 0076 }