From c2f1d3dbe77e12ab8a26753948273bdc78583e1a Mon Sep 17 00:00:00 2001 From: nowrep Date: Mon, 25 Apr 2011 15:06:59 +0200 Subject: [PATCH] Fixed unneeded cpu usage by making ProgressBar class --- src/QupZilla.pro | 6 ++++-- src/app/appui.cpp | 4 ++-- src/app/qupzilla.cpp | 9 ++++---- src/app/qupzilla.h | 6 ++++-- src/main.cpp | 1 + src/navigation/locationbar.cpp | 1 + src/other/aboutdialog.cpp | 1 - src/other/updater.cpp | 15 +++++++++---- src/other/updater.h | 4 ++-- src/tools/progressbar.cpp | 39 ++++++++++++++++++++++++++++++++++ src/tools/progressbar.h | 29 +++++++++++++++++++++++++ 11 files changed, 98 insertions(+), 17 deletions(-) create mode 100644 src/tools/progressbar.cpp create mode 100644 src/tools/progressbar.h diff --git a/src/QupZilla.pro b/src/QupZilla.pro index 564c17d1a..d26adfca1 100644 --- a/src/QupZilla.pro +++ b/src/QupZilla.pro @@ -114,7 +114,8 @@ SOURCES += main.cpp\ bookmarks/bookmarkicon.cpp \ sidebar/historysidebar.cpp \ desktopnotifications/desktopnotification.cpp \ - desktopnotifications/desktopnotificationsfactory.cpp + desktopnotifications/desktopnotificationsfactory.cpp \ + tools/progressbar.cpp HEADERS += 3rdparty/squeezelabel.h \ 3rdparty/qtwin.h \ @@ -187,7 +188,8 @@ HEADERS += 3rdparty/squeezelabel.h \ bookmarks/bookmarkicon.h \ sidebar/historysidebar.h \ desktopnotifications/desktopnotification.h \ - desktopnotifications/desktopnotificationsfactory.h + desktopnotifications/desktopnotificationsfactory.h \ + tools/progressbar.h FORMS += \ preferences/autofillmanager.ui \ diff --git a/src/app/appui.cpp b/src/app/appui.cpp index f3c95379b..7c63e2580 100644 --- a/src/app/appui.cpp +++ b/src/app/appui.cpp @@ -21,6 +21,7 @@ #include "locationbar.h" #include "clickablelabel.h" #include "adblockicon.h" +#include "progressbar.h" void QupZilla::postLaunch() { @@ -142,8 +143,7 @@ void QupZilla::setupUi() m_navigation->addWidget(new QLabel()); //Elegant spacer -,- m_navigation->setContextMenuPolicy(Qt::CustomContextMenu); - m_progressBar = new QProgressBar(this); - m_progressBar->setMaximumSize(QSize(150, 16)); + m_progressBar = new ProgressBar(statusBar()); m_privateBrowsing = new QLabel(this); m_privateBrowsing->setPixmap(QPixmap(":/icons/locationbar/privatebrowsing.png")); m_privateBrowsing->setVisible(false); diff --git a/src/app/qupzilla.cpp b/src/app/qupzilla.cpp index a601c897f..d4a62e1b5 100644 --- a/src/app/qupzilla.cpp +++ b/src/app/qupzilla.cpp @@ -48,6 +48,7 @@ #include "clickablelabel.h" #include "docktitlebarwidget.h" #include "sidebar.h" +#include "progressbar.h" const QString QupZilla::VERSION = "1.0.0-b1"; //const QString QupZilla::BUILDTIME = QLocale(QLocale::English).toDateTime(__DATE__" "__TIME__, "MMM d yyyy hh:mm:ss").toString("MM/dd/yyyy hh:ss"); @@ -58,7 +59,7 @@ const QString QupZilla::WWWADDRESS = "http://qupzilla.ic.cz"; const QString QupZilla::WEBKITVERSION = qWebKitVersion(); QupZilla::QupZilla(bool tryRestore, QUrl startUrl) : - QMainWindow() + QMainWindow(0) ,m_tryRestore(tryRestore) ,m_startingUrl(startUrl) ,m_actionPrivateBrowsing(0) @@ -93,7 +94,7 @@ void QupZilla::loadSettings() m_newtab = settings.value("newTabUrl","").toUrl(); settings.endGroup(); - QWebSettings* websettings=mApp->webSettings(); + QWebSettings* websettings = mApp->webSettings(); websettings->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true); //Browser Window settings @@ -179,13 +180,13 @@ void QupZilla::refreshHistory(int index) if (history->canGoBack()) { m_buttonBack->setEnabled(true); - }else{ + } else { m_buttonBack->setEnabled(false); } if (history->canGoForward()) { m_buttonNext->setEnabled(true); - }else{ + } else { m_buttonNext->setEnabled(false); } } diff --git a/src/app/qupzilla.h b/src/app/qupzilla.h index 7b0979dd4..bfdabdb0a 100644 --- a/src/app/qupzilla.h +++ b/src/app/qupzilla.h @@ -72,6 +72,7 @@ class MainApplication; class WebTab; class AdBlockIcon; class SideBar; +class ProgressBar; class QupZilla : public QMainWindow { Q_OBJECT @@ -103,7 +104,7 @@ public: inline QAction* buttonStop(){ return m_buttonStop; } inline QAction* buttonReload(){ return m_buttonReload; } - inline QProgressBar* progressBar(){ return m_progressBar; } + inline ProgressBar* progressBar(){ return m_progressBar; } inline QToolBar* navigationToolbar(){ return m_navigation; } inline QString activeProfil(){ return m_activeProfil; } inline QString activeLanguage(){ return m_activeLanguage; } @@ -111,6 +112,7 @@ public: inline QLabel* ipLabel(){ return m_ipLabel; } inline QColor menuTextColor() { return m_menuTextColor; } inline QAction* acShowBookmarksToolbar() { return m_actionShowBookmarksToolbar; } + inline QMenu* menuHelp() { return m_menuHelp; } signals: void loadHistory(); @@ -242,7 +244,7 @@ private: QAction* m_buttonStop; QAction* m_buttonReload; QAction* m_actionExitFullscreen; - QProgressBar* m_progressBar; + ProgressBar* m_progressBar; QLabel* m_ipLabel; QToolBar* m_navigation; diff --git a/src/main.cpp b/src/main.cpp index e986c38bf..de27ad82b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,6 +37,7 @@ int main(int argc, char *argv[]) std::cout << "QupZilla already running - activating existing window" << std::endl; return 1; } + int result = app.exec(); return result; } diff --git a/src/navigation/locationbar.cpp b/src/navigation/locationbar.cpp index 98ea3f943..1b2c07a7c 100644 --- a/src/navigation/locationbar.cpp +++ b/src/navigation/locationbar.cpp @@ -26,6 +26,7 @@ #include "rsswidget.h" #include "webpage.h" #include "bookmarkicon.h" +#include "progressbar.h" LocationBar::LocationBar(QupZilla* mainClass, QWidget* parent) : LineEdit(parent) diff --git a/src/other/aboutdialog.cpp b/src/other/aboutdialog.cpp index 4b6ba3620..4dafd3c65 100644 --- a/src/other/aboutdialog.cpp +++ b/src/other/aboutdialog.cpp @@ -44,7 +44,6 @@ AboutDialog::AboutDialog(QWidget* parent) : void AboutDialog::buttonClicked() { - mApp->desktopNotifications()->notify(QPixmap(":qupzilla.png"), "heading","text"); if (ui->authorsButton->text() == tr("Authors and Contributors")) showAuthors(); else if (ui->authorsButton->text() == tr("< About QupZilla")) diff --git a/src/other/updater.cpp b/src/other/updater.cpp index 7cac19f93..ba60908db 100644 --- a/src/other/updater.cpp +++ b/src/other/updater.cpp @@ -27,7 +27,6 @@ Updater::Updater(QupZilla* mainClass, QObject* parent) : #ifndef DEVELOPING QTimer::singleShot(60*1000, this, SLOT(start()) ); //Start checking after 1 minute #endif - QTimer::singleShot(1000, this, SLOT(start())); } void Updater::start() @@ -49,13 +48,21 @@ void Updater::downCompleted(QNetworkReply* reply) QString html = QString(reply->readAll()); if (html.startsWith("Version:")){ html.remove("Version:"); - if (html != QupZilla::VERSION) - mApp->desktopNotifications()->notify(QPixmap(":icons/qupzillaupdate.png"), tr("Update is available"), tr("Newer version of QupZilla is ready to download.")); - + if (html != QupZilla::VERSION) { + mApp->desktopNotifications()->notify(QPixmap(":icons/qupzillaupdate.png"), tr("Update available"), tr("New version of QupZilla is ready to download.")); + QAction* action = new QAction(QIcon(":icons/qupzillaupdate.png"), "Update", this); + connect(action, SIGNAL(triggered()), this, SLOT(downloadNewVersion())); + p_QupZilla->menuBar()->addAction(action); + } } reply->manager()->deleteLater(); } +void Updater::downloadNewVersion() +{ + p_QupZilla->tabWidget()->addView(QUrl(QupZilla::WWWADDRESS + "/download.php"), tr("Update"), TabWidget::NewSelectedTab); +} + Updater::~Updater() { } diff --git a/src/other/updater.h b/src/other/updater.h index 0440272fb..98ea1893f 100644 --- a/src/other/updater.h +++ b/src/other/updater.h @@ -33,15 +33,15 @@ public: signals: -public slots: +private slots: void downCompleted(QNetworkReply* reply); void start(); + void downloadNewVersion(); private: void startDownloadingUpdateInfo(const QUrl &url); QupZilla* p_QupZilla; - }; #endif // UPDATER_H diff --git a/src/tools/progressbar.cpp b/src/tools/progressbar.cpp new file mode 100644 index 000000000..c31bb20fd --- /dev/null +++ b/src/tools/progressbar.cpp @@ -0,0 +1,39 @@ +#include "progressbar.h" + +ProgressBar::ProgressBar(QWidget* parent) + : QWidget(parent) + , m_value(0) + , m_lastPaintedValue(-1) +{ + setMinimumSize(QSize(130,16)); + setMaximumSize(QSize(150,16)); +} + +void ProgressBar::setValue(int value) +{ + m_value = value; + if (m_lastPaintedValue != m_value) + repaint(); +} + +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); + QStyleOptionProgressBarV2 opt; + initStyleOption(&opt); + paint.drawControl(QStyle::CE_ProgressBar, opt); + m_lastPaintedValue = m_value; +} diff --git a/src/tools/progressbar.h b/src/tools/progressbar.h new file mode 100644 index 000000000..3b5aad79e --- /dev/null +++ b/src/tools/progressbar.h @@ -0,0 +1,29 @@ +#ifndef PROGRESSBAR_H +#define PROGRESSBAR_H + +#include +#include +#include + +class ProgressBar : public QWidget +{ + Q_OBJECT +public: + explicit ProgressBar(QWidget* parent = 0); + +signals: + +public slots: + void setValue(int value); + +protected: + void paintEvent(QPaintEvent* e); + void initStyleOption(QStyleOptionProgressBar* option); + +private: + int m_value; + int m_lastPaintedValue; + +}; + +#endif // PROGRESSBAR_H