diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 5558bb305..faae040a1 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -254,6 +254,7 @@ set(SRCS ${SRCS} tools/mactoolbutton.cpp tools/menubar.cpp tools/pagethumbnailer.cpp + tools/progressbar.cpp tools/qztools.cpp tools/removeitemfocusdelegate.cpp tools/scripts.cpp @@ -487,6 +488,7 @@ set(SRCS ${SRCS} tools/mactoolbutton.h tools/menubar.h tools/pagethumbnailer.h + tools/progressbar.h tools/qztools.h tools/removeitemfocusdelegate.h tools/scripts.h diff --git a/src/lib/app/browserwindow.cpp b/src/lib/app/browserwindow.cpp index 81c84b850..fe1a9400b 100644 --- a/src/lib/app/browserwindow.cpp +++ b/src/lib/app/browserwindow.cpp @@ -36,6 +36,7 @@ #include "clickablelabel.h" #include "docktitlebarwidget.h" #include "iconprovider.h" +#include "progressbar.h" #include "closedwindowsmanager.h" #include "statusbar.h" #include "browsinglibrary.h" @@ -71,7 +72,6 @@ #include #include #include -#include #include #include #include @@ -387,7 +387,7 @@ void BrowserWindow::setupUi() m_statusBar->setObjectName(QSL("mainwindow-statusbar")); m_statusBar->setCursor(Qt::ArrowCursor); setStatusBar(m_statusBar); - m_progressBar = new QProgressBar(m_statusBar); + m_progressBar = new ProgressBar(m_statusBar); m_ipLabel = new QLabel(this); m_ipLabel->setObjectName(QSL("statusbar-ip-label")); m_ipLabel->setToolTip(tr("IP Address of current page")); diff --git a/src/lib/app/browserwindow.h b/src/lib/app/browserwindow.h index 75517f343..6cd64f942 100644 --- a/src/lib/app/browserwindow.h +++ b/src/lib/app/browserwindow.h @@ -27,7 +27,6 @@ class QLabel; class QVBoxLayout; -class QProgressBar; class QSplitter; class QWebEngineFrame; class QTimer; @@ -46,6 +45,7 @@ class WebView; class WebPage; class SideBar; class SideBarManager; +class ProgressBar; class StatusBar; class NavigationBar; class NavigationContainer; @@ -214,7 +214,7 @@ private: NavigationBar* m_navigationToolbar; BookmarksToolbar* m_bookmarksToolbar; - QProgressBar* m_progressBar; + ProgressBar* m_progressBar; QLabel* m_ipLabel; QMenu* m_superMenu; diff --git a/src/lib/popupwindow/popupwindow.cpp b/src/lib/popupwindow/popupwindow.cpp index 35e044e6c..77b5b12d4 100644 --- a/src/lib/popupwindow/popupwindow.cpp +++ b/src/lib/popupwindow/popupwindow.cpp @@ -19,6 +19,7 @@ #include "popupwebview.h" #include "webpage.h" #include "popupstatusbarmessage.h" +#include "progressbar.h" #include "searchtoolbar.h" #include "qzsettings.h" #include "popuplocationbar.h" @@ -26,11 +27,10 @@ #include "mainapplication.h" #include "browserwindow.h" +#include +#include #include #include -#include -#include -#include PopupWindow::PopupWindow(PopupWebView* view) : QWidget() @@ -53,7 +53,7 @@ PopupWindow::PopupWindow(PopupWebView* view) m_statusBar = new QStatusBar(this); m_statusBar->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); - m_progressBar = new QProgressBar(m_statusBar); + m_progressBar = new ProgressBar(m_statusBar); m_statusBar->addPermanentWidget(m_progressBar); m_progressBar->hide(); diff --git a/src/lib/popupwindow/popupwindow.h b/src/lib/popupwindow/popupwindow.h index 9aa717142..3cb05d72d 100644 --- a/src/lib/popupwindow/popupwindow.h +++ b/src/lib/popupwindow/popupwindow.h @@ -23,16 +23,16 @@ #include "qzcommon.h" -class QMenu; -class QMenuBar; -class QProgressBar; -class QStatusBar; class QVBoxLayout; +class QStatusBar; +class QMenuBar; +class QMenu; class WebPage; class PopupWebView; class PopupStatusBarMessage; class PopupLocationBar; +class ProgressBar; class SearchToolBar; class FALKON_EXPORT PopupWindow : public QWidget @@ -65,7 +65,7 @@ private: PopupWebView* m_view; PopupLocationBar* m_locationBar; PopupStatusBarMessage* m_statusBarMessage; - QProgressBar* m_progressBar; + ProgressBar* m_progressBar; QVBoxLayout* m_layout; QStatusBar* m_statusBar; diff --git a/src/lib/tools/progressbar.cpp b/src/lib/tools/progressbar.cpp new file mode 100644 index 000000000..b92622ef5 --- /dev/null +++ b/src/lib/tools/progressbar.cpp @@ -0,0 +1,64 @@ +/* ============================================================ +* Falkon - Qt web browser +* Copyright (C) 2010-2016 David Rosca +* +* 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 3 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, see . +* ============================================================ */ +#include "progressbar.h" + +#include +#include + +ProgressBar::ProgressBar(QWidget* parent) + : QWidget(parent) + , m_value(0) + , m_lastPaintedValue(-1) +{ + setMinimumSize(130, 16); + setMaximumSize(150, 16); +} + +void ProgressBar::setValue(int value) +{ + m_value = value; + if (m_lastPaintedValue != m_value) { + update(); + } +} + +void ProgressBar::initStyleOption(QStyleOptionProgressBar* option) +{ + if (!option) { + return; + } + + option->initFrom(this); + option->minimum = 0; + option->maximum = 100; + option->progress = m_value; + option->textAlignment = Qt::AlignLeft; + option->textVisible = false; +} + +void ProgressBar::paintEvent(QPaintEvent*) +{ + QStylePainter paint(this); + + QStyleOptionProgressBar opt; + initStyleOption(&opt); + + paint.drawControl(QStyle::CE_ProgressBar, opt); + + m_lastPaintedValue = m_value; +} diff --git a/src/lib/tools/progressbar.h b/src/lib/tools/progressbar.h new file mode 100644 index 000000000..02c9ccf3f --- /dev/null +++ b/src/lib/tools/progressbar.h @@ -0,0 +1,45 @@ +/* ============================================================ +* Falkon - Qt web browser +* Copyright (C) 2010-2014 David Rosca +* +* 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 3 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, see . +* ============================================================ */ +#ifndef PROGRESSBAR_H +#define PROGRESSBAR_H + +#include + +#include "qzcommon.h" + +class QStyleOptionProgressBar; + +class FALKON_EXPORT ProgressBar : public QWidget +{ + Q_OBJECT +public: + explicit ProgressBar(QWidget* parent = nullptr); + +public Q_SLOTS: + void setValue(int value); + +protected: + void paintEvent(QPaintEvent* e) override; + void initStyleOption(QStyleOptionProgressBar* option); + +private: + int m_value; + int m_lastPaintedValue; +}; + +#endif // PROGRESSBAR_H diff --git a/src/lib/webtab/tabbedwebview.cpp b/src/lib/webtab/tabbedwebview.cpp index ff7f18df4..179ad62eb 100644 --- a/src/lib/webtab/tabbedwebview.cpp +++ b/src/lib/webtab/tabbedwebview.cpp @@ -23,6 +23,7 @@ #include "tabbar.h" #include "webtab.h" #include "statusbar.h" +#include "progressbar.h" #include "navigationbar.h" #include "iconprovider.h" #include "searchenginesmanager.h"