From 853c95b921f4fc3beb8daf71d79b44aa1ab06c92 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Mon, 10 Jun 2019 16:43:39 -0400 Subject: added new statusbar class, moved refresh progress bar to it --- src/CMakeLists.txt | 3 +++ src/mainwindow.cpp | 20 ++++---------------- src/mainwindow.h | 5 +++-- src/statusbar.cpp | 27 +++++++++++++++++++++++++++ src/statusbar.h | 20 ++++++++++++++++++++ 5 files changed, 57 insertions(+), 18 deletions(-) create mode 100644 src/statusbar.cpp create mode 100644 src/statusbar.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 93597d62..71f87a8a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -116,6 +116,7 @@ SET(organizer_SRCS forcedloaddialog.cpp forcedloaddialogwidget.cpp filterwidget.cpp + statusbar.cpp shared/windows_error.cpp shared/error_report.cpp @@ -213,6 +214,7 @@ SET(organizer_HDRS forcedloaddialog.h forcedloaddialogwidget.h filterwidget.h + statusbar.h shared/windows_error.h shared/error_report.h @@ -277,6 +279,7 @@ set(application moshortcut selfupdater singleinstance + statusbar ) set(browser diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 911d0ff1..67d0f2ff 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -77,6 +77,7 @@ along with Mod Organizer. If not, see . #include "nxmaccessmanager.h" #include "appconfig.h" #include "eventfilter.h" +#include "statusbar.h" #include #include #include @@ -242,13 +243,7 @@ MainWindow::MainWindow(QSettings &initSettings connect(ui->logList->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), ui->logList, SLOT(scrollToBottom())); - m_RefreshProgress = new QProgressBar(statusBar()); - m_RefreshProgress->setTextVisible(true); - m_RefreshProgress->setRange(0, 100); - m_RefreshProgress->setValue(0); - m_RefreshProgress->setVisible(false); - statusBar()->addWidget(m_RefreshProgress, 1000); - statusBar()->clearMessage(); + m_statusBar.reset(new StatusBar(statusBar())); updateProblemsButton(); @@ -2534,15 +2529,8 @@ void MainWindow::setESPListSorting(int index) void MainWindow::refresher_progress(int percent) { - if (percent == 100) { - m_RefreshProgress->setVisible(false); - this->setEnabled(true); - } else if (!m_RefreshProgress->isVisible()) { - this->setEnabled(false); - m_RefreshProgress->setVisible(true); - m_RefreshProgress->setRange(0, 100); - m_RefreshProgress->setValue(percent); - } + setEnabled(percent == 100); + m_statusBar->setProgress(percent); } void MainWindow::directory_refreshed() diff --git a/src/mainwindow.h b/src/mainwindow.h index b8d9f49f..734ece88 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -37,6 +37,7 @@ struct Executable; class CategoryFactory; class LockedDialogBase; class OrganizerCore; +class StatusBar; #include "plugincontainer.h" //class PluginContainer; class PluginListSortProxy; namespace BSA { class Archive; } @@ -75,7 +76,6 @@ class QListWidgetItem; class QMenu; class QModelIndex; class QPoint; -class QProgressBar; class QProgressDialog; class QTranslator; class QTreeWidgetItem; @@ -329,6 +329,8 @@ private: // the window is closed and the menubar is hidden bool m_menuBarVisible; + std::unique_ptr m_statusBar; + // last separator on the toolbar, used to add spacer for right-alignment and // as an insert point for executables QAction* m_linksSeparator; @@ -338,7 +340,6 @@ private: int m_OldProfileIndex; std::vector m_ModNameList; // the mod-list to go with the directory structure - QProgressBar *m_RefreshProgress; bool m_Refreshing; QStringList m_DefaultArchives; diff --git a/src/statusbar.cpp b/src/statusbar.cpp new file mode 100644 index 00000000..7370662a --- /dev/null +++ b/src/statusbar.cpp @@ -0,0 +1,27 @@ +#include "statusbar.h" + +StatusBar::StatusBar(QStatusBar* bar) + : m_bar(bar), m_nexusAPI(new QLabel), m_progress(new QProgressBar) +{ + m_progress->setTextVisible(true); + m_progress->setRange(0, 100); + m_progress->setValue(0); + m_progress->setVisible(false); + + m_bar->addPermanentWidget(m_nexusAPI); + m_bar->addPermanentWidget(m_progress); + + m_bar->clearMessage(); +} + +void StatusBar::setProgress(int percent) +{ + qDebug().nospace() << "progress: " << percent; + + if (percent < 0 || percent >= 100) { + m_progress->setVisible(false); + } else if (!m_progress->isVisible()) { + m_progress->setVisible(true); + m_progress->setValue(percent); + } +} diff --git a/src/statusbar.h b/src/statusbar.h new file mode 100644 index 00000000..f3ad3081 --- /dev/null +++ b/src/statusbar.h @@ -0,0 +1,20 @@ +#ifndef MO_STATUSBAR_H +#define MO_STATUSBAR_H + +#include +#include + +class StatusBar +{ +public: + StatusBar(QStatusBar* bar); + + void setProgress(int percent); + +private: + QStatusBar* m_bar; + QLabel* m_api; + QProgressBar* m_progress; +}; + +#endif // MO_STATUSBAR_H -- cgit v1.3.1