Skip to content

Commit 3de5abc

Browse files
committed
Drop static members from MainWindow
Given UIUtils::getMainWindow() is a thing.
1 parent 80b7cd0 commit 3de5abc

18 files changed

Lines changed: 166 additions & 134 deletions

application/src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "qttubeapplication.h"
22
#include "mainwindow.h"
33
#include "ui/forms/livechatwindow.h"
4+
#include <QCommandLineParser>
45

56
int main(int argc, char *argv[])
67
{

application/src/mainwindow.cpp

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
#include "ui/forms/plugins/pluginbrowserview.h"
66
#include "ui/views/viewcontroller.h"
77
#include "ui/widgets/accountmenu/accountcontrollerwidget.h"
8+
#include "ui/widgets/findbar.h"
9+
#include "ui/widgets/topbar/topbar.h"
810
#include "utils/uiutils.h"
911
#include <QAction>
12+
#include <QCommandLineParser>
1013
#include <QLineEdit>
1114
#include <QMessageBox>
1215

@@ -18,18 +21,16 @@ MainWindow::MainWindow(const QCommandLineParser& parser, QWidget* parent)
1821
ui->setupUi(this);
1922
setWindowTitle(QTTUBE_APP_NAME);
2023

21-
m_centralWidget = ui->centralwidget;
22-
m_size = geometry().size();
2324
m_topbar = new TopBar(this);
2425

25-
notificationMenu = new ContinuableListWidget(this);
26-
notificationMenu->hide();
27-
notificationMenu->setContinuationThreshold(5);
26+
m_notificationMenu = new ContinuableListWidget(this);
27+
m_notificationMenu->hide();
28+
m_notificationMenu->setContinuationThreshold(5);
2829

29-
findbar = new FindBar(this);
30+
m_findbar = new FindBar(this);
3031
connect(ui->centralwidget, &QStackedWidget::currentChanged, this, [this] {
31-
if (findbar->isVisible())
32-
findbar->setReveal(false);
32+
if (m_findbar->isVisible())
33+
m_findbar->setReveal(false);
3334
});
3435

3536
connect(m_topbar, &TopBar::signInStatusChanged, this, [this] { if (ui->centralwidget->currentIndex() == 0) browse(); });
@@ -42,21 +43,21 @@ MainWindow::MainWindow(const QCommandLineParser& parser, QWidget* parent)
4243
ui->tabWidget->setCurrentIndex(5); // just some blank tab so you can pick one
4344
connect(ui->tabWidget, &QTabWidget::currentChanged, this, &MainWindow::browse);
4445

45-
connect(notificationMenu, &ContinuableListWidget::continuationReady, this, [this] {
46-
if (notificationMenu->continuationData.has_value())
47-
BrowseHelper::instance()->browseNotificationMenu(notificationMenu);
46+
connect(m_notificationMenu, &ContinuableListWidget::continuationReady, this, [this] {
47+
if (m_notificationMenu->continuationData.has_value())
48+
BrowseHelper::instance()->browseNotificationMenu(m_notificationMenu);
4849
});
4950
connect(ui->historyWidget, &ContinuableListWidget::continuationReady, this, [this] {
5051
if (ui->historyWidget->continuationData.has_value())
51-
BrowseHelper::instance()->browseHistory(ui->historyWidget, lastSearchQuery);
52+
BrowseHelper::instance()->browseHistory(ui->historyWidget, m_lastSearchQuery);
5253
});
5354
connect(ui->homeWidget, &ContinuableListWidget::continuationReady, this, [this] {
5455
if (ui->homeWidget->continuationData.has_value())
5556
BrowseHelper::instance()->browseHome(ui->homeWidget);
5657
});
5758
connect(ui->searchWidget, &ContinuableListWidget::continuationReady, this, [this] {
5859
if (ui->searchWidget->continuationData.has_value())
59-
BrowseHelper::instance()->search(ui->searchWidget, nullptr, lastSearchQuery);
60+
BrowseHelper::instance()->search(ui->searchWidget, nullptr, m_lastSearchQuery);
6061
});
6162
connect(ui->subscriptionsWidget, &ContinuableListWidget::continuationReady, this, [this] {
6263
if (ui->subscriptionsWidget->continuationData.has_value())
@@ -117,7 +118,7 @@ void MainWindow::activePluginChanged(PluginData* activePlugin)
117118
}
118119

119120
connect(authStore, &QtTubePlugin::AuthStoreBase::authenticateSuccess, m_topbar, &TopBar::postSignInSetup);
120-
connect(authStore, &QtTubePlugin::AuthStoreBase::updateFail, this, [] {
121+
connect(authStore, &QtTubePlugin::AuthStoreBase::updateFail, this, [this] {
121122
QMessageBox::critical(nullptr, "Invalid Login", "Your session has expired or your credentials are invalid. You will be logged out. Try logging in again.");
122123
m_topbar->signOut();
123124
});
@@ -130,7 +131,7 @@ void MainWindow::activePluginChanged(PluginData* activePlugin)
130131

131132
void MainWindow::browse()
132133
{
133-
if (doNotBrowse)
134+
if (m_doNotBrowse)
134135
return;
135136

136137
UIUtils::clearLayout(ui->additionalWidgets);
@@ -166,11 +167,16 @@ void MainWindow::browse()
166167
}
167168
}
168169

170+
QStackedWidget* MainWindow::centralWidget()
171+
{
172+
return ui->centralwidget;
173+
}
174+
169175
void MainWindow::keyPressEvent(QKeyEvent* event)
170176
{
171177
bool ctrlPressed = event->modifiers() & Qt::ControlModifier;
172-
if ((ctrlPressed && event->key() == Qt::Key_F) || (findbar->isVisible() && event->key() == Qt::Key_Escape))
173-
findbar->setReveal(findbar->isHidden());
178+
if ((ctrlPressed && event->key() == Qt::Key_F) || (m_findbar->isVisible() && event->key() == Qt::Key_Escape))
179+
m_findbar->setReveal(m_findbar->isHidden());
174180

175181
QMainWindow::keyPressEvent(event);
176182
}
@@ -191,7 +197,7 @@ void MainWindow::reloadCurrentTab()
191197
else if (ui->tabWidget->currentIndex() == 4)
192198
{
193199
ui->searchWidget->clear();
194-
BrowseHelper::instance()->search(ui->searchWidget, ui->additionalWidgets, lastSearchQuery);
200+
BrowseHelper::instance()->search(ui->searchWidget, ui->additionalWidgets, m_lastSearchQuery);
195201
}
196202
else
197203
{
@@ -201,11 +207,10 @@ void MainWindow::reloadCurrentTab()
201207

202208
void MainWindow::resizeEvent(QResizeEvent* event)
203209
{
204-
m_size = event->size();
205-
notificationMenu->setFixedSize(width() >= 800 ? 600 : 600 - (800 - width()), height() / 2);
210+
m_notificationMenu->setFixedSize(width() >= 800 ? 600 : 600 - (800 - width()), height() / 2);
206211
m_topbar->resize(width(), 35);
207212
m_topbar->scaleAppropriately();
208-
notificationMenu->move(m_topbar->notificationBell->x() - notificationMenu->width() + 20, 34);
213+
m_notificationMenu->move(m_topbar->notificationBell->x() - m_notificationMenu->width() + 20, 34);
209214

210215
if (AccountControllerWidget* accountController = findChild<AccountControllerWidget*>())
211216
accountController->move(m_topbar->avatarButton->x() - accountController->width() + 20, 35);
@@ -216,22 +221,22 @@ void MainWindow::resizeEvent(QResizeEvent* event)
216221
void MainWindow::returnFromSearch()
217222
{
218223
UIUtils::clearLayout(ui->additionalWidgets);
219-
doNotBrowse = true;
224+
m_doNotBrowse = true;
220225
disconnect(m_topbar->logo, &TubeLabel::clicked, this, &MainWindow::returnFromSearch);
221226
ui->tabWidget->setTabEnabled(4, false);
222227
UIUtils::setTabsEnabled(ui->tabWidget, true, {0, 1, 2, 3});
223-
doNotBrowse = false;
228+
m_doNotBrowse = false;
224229
ui->tabWidget->setCurrentIndex(0);
225230
ui->searchWidget->clear();
226231
}
227232

228233
void MainWindow::returnFromWatchHistorySearch()
229234
{
230-
doNotBrowse = true;
235+
m_doNotBrowse = true;
231236
disconnect(m_topbar->logo, &TubeLabel::clicked, this, &MainWindow::returnFromWatchHistorySearch);
232237
ui->tabWidget->setTabEnabled(5, false);
233238
UIUtils::setTabsEnabled(ui->tabWidget, true, {0, 1, 2, 3});
234-
doNotBrowse = false;
239+
m_doNotBrowse = false;
235240
ui->tabWidget->setCurrentIndex(3);
236241
ui->historySearchWidget->clear();
237242
}
@@ -260,37 +265,37 @@ void MainWindow::searchByQuery(const QString& query)
260265
}
261266
else
262267
{
263-
doNotBrowse = true;
268+
m_doNotBrowse = true;
264269
connect(m_topbar->logo, &TubeLabel::clicked, this, &MainWindow::returnFromSearch);
265270
ui->tabWidget->setTabEnabled(4, true);
266271
UIUtils::setTabsEnabled(ui->tabWidget, false, {0, 1, 2, 3, 5});
267-
doNotBrowse = false;
272+
m_doNotBrowse = false;
268273
ui->tabWidget->setCurrentIndex(4);
269274
}
270275

271-
lastSearchQuery = query;
272-
BrowseHelper::instance()->search(ui->searchWidget, ui->additionalWidgets, lastSearchQuery);
276+
m_lastSearchQuery = query;
277+
BrowseHelper::instance()->search(ui->searchWidget, ui->additionalWidgets, m_lastSearchQuery);
273278
}
274279

275280
void MainWindow::searchWatchHistory()
276281
{
277282
if (ui->tabWidget->currentIndex() == 5)
278283
{
279284
ui->historySearchWidget->clear();
280-
lastSearchQuery = qobject_cast<QLineEdit*>(ui->additionalWidgets->itemAt(0)->widget())->text();
281-
BrowseHelper::instance()->browseHistory(ui->historySearchWidget, lastSearchQuery);
285+
m_lastSearchQuery = qobject_cast<QLineEdit*>(ui->additionalWidgets->itemAt(0)->widget())->text();
286+
BrowseHelper::instance()->browseHistory(ui->historySearchWidget, m_lastSearchQuery);
282287
return;
283288
}
284289

285-
doNotBrowse = true;
290+
m_doNotBrowse = true;
286291
connect(m_topbar->logo, &TubeLabel::clicked, this, &MainWindow::returnFromWatchHistorySearch);
287292
ui->tabWidget->setTabEnabled(5, true);
288293
UIUtils::setTabsEnabled(ui->tabWidget, false, {0, 1, 2, 3});
289-
doNotBrowse = false;
294+
m_doNotBrowse = false;
290295
ui->tabWidget->setCurrentIndex(5);
291296

292-
lastSearchQuery = qobject_cast<QLineEdit*>(ui->additionalWidgets->itemAt(0)->widget())->text();
293-
BrowseHelper::instance()->browseHistory(ui->historySearchWidget, lastSearchQuery);
297+
m_lastSearchQuery = qobject_cast<QLineEdit*>(ui->additionalWidgets->itemAt(0)->widget())->text();
298+
BrowseHelper::instance()->browseHistory(ui->historySearchWidget, m_lastSearchQuery);
294299
}
295300

296301
void MainWindow::showAccountMenu()
@@ -318,15 +323,20 @@ void MainWindow::showAccountMenu()
318323

319324
void MainWindow::showNotifications()
320325
{
321-
if (notificationMenu->isVisible())
326+
if (m_notificationMenu->isVisible())
322327
{
323328
m_topbar->setAlwaysShow(ui->centralwidget->currentIndex() == 0);
324-
notificationMenu->clear();
325-
notificationMenu->hide();
329+
m_notificationMenu->clear();
330+
m_notificationMenu->hide();
326331
return;
327332
}
328333

329334
m_topbar->setAlwaysShow(true);
330-
notificationMenu->show();
331-
BrowseHelper::instance()->browseNotificationMenu(notificationMenu);
335+
m_notificationMenu->show();
336+
BrowseHelper::instance()->browseNotificationMenu(m_notificationMenu);
337+
}
338+
339+
TopBar* MainWindow::topbar()
340+
{
341+
return m_topbar;
332342
}

application/src/mainwindow.h

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
#pragma once
2-
#include "ui/widgets/continuablelistwidget.h"
3-
#include "ui/widgets/findbar.h"
4-
#include "ui/widgets/topbar/topbar.h"
5-
#include <QCommandLineParser>
6-
#include <QKeyEvent>
2+
#include "ui/widgets/topbar/searchbox.h"
73
#include <QMainWindow>
8-
#include <QResizeEvent>
9-
#include <QStackedWidget>
104

115
QT_BEGIN_NAMESPACE
126
namespace Ui { class MainWindow; }
137
QT_END_NAMESPACE
148

9+
class ContinuableListWidget;
10+
class FindBar;
11+
class QCommandLineParser;
12+
class QKeyEvent;
13+
class QResizeEvent;
14+
class QStackedWidget;
15+
class TopBar;
16+
1517
class MainWindow : public QMainWindow
1618
{
1719
Q_OBJECT
1820
public:
1921
explicit MainWindow(const QCommandLineParser& parser, QWidget* parent = nullptr);
2022
~MainWindow();
2123

22-
static QStackedWidget* centralWidget() { return m_centralWidget; }
23-
static QSize size() { return m_size; }
24-
static TopBar* topbar() { return m_topbar; }
24+
QStackedWidget* centralWidget();
25+
TopBar* topbar();
2526
public slots:
2627
void showAccountMenu();
2728
void showNotifications();
@@ -39,13 +40,10 @@ private slots:
3940
void browse();
4041
void searchByQuery(const QString& query);
4142

42-
static inline QStackedWidget* m_centralWidget;
43-
static inline QSize m_size;
44-
static inline TopBar* m_topbar;
45-
46-
bool doNotBrowse = false;
47-
FindBar* findbar;
48-
QString lastSearchQuery;
49-
ContinuableListWidget* notificationMenu;
43+
bool m_doNotBrowse = false;
44+
FindBar* m_findbar;
45+
QString m_lastSearchQuery;
46+
ContinuableListWidget* m_notificationMenu;
47+
TopBar* m_topbar;
5048
Ui::MainWindow* ui;
5149
};

application/src/qttubeapplication.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include "qttubeapplication.h"
22
#include "mainwindow.h"
33
#include "ui/views/viewcontroller.h"
4+
#include "ui/widgets/topbar/topbar.h"
45
#include "utils/uiutils.h"
56
#include <QDesktopServices>
67
#include <QMessageBox>
8+
#include <QStyle>
79

810
#ifdef Q_OS_WIN
911
#define WIN32_LEAN_AND_MEAN
@@ -42,7 +44,7 @@ void QtTubeApplication::handleUrlOrID(const QString& in)
4244
ViewController::loadChannel(data.data, plugin);
4345
break;
4446
case QtTubePlugin::ResolveUrlTarget::Search:
45-
emit MainWindow::topbar()->searchBox->searchRequested(data.data, SearchBox::SearchType::ByQuery);
47+
emit UIUtils::getMainWindow()->topbar()->searchBox->searchRequested(data.data, SearchBox::SearchType::ByQuery);
4648
break;
4749
case QtTubePlugin::ResolveUrlTarget::Video:
4850
ViewController::loadVideo(data.data, plugin, data.videoProgress, nullptr, data.continuePlayback);
@@ -66,6 +68,6 @@ void QtTubeApplication::handleUrlOrID(const QString& in)
6668
bool QtTubeApplication::notify(QObject* receiver, QEvent* event)
6769
{
6870
if (m_settings.autoHideTopBar && event->type() == QEvent::MouseMove && receiver->objectName() == "MainWindowWindow")
69-
MainWindow::topbar()->handleMouseEvent(static_cast<QMouseEvent*>(event));
71+
UIUtils::getMainWindow()->topbar()->handleMouseEvent(static_cast<QMouseEvent*>(event));
7072
return QApplication::notify(receiver, event);
7173
}

application/src/ui/browsehelper.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "browsehelper.h"
22
#include "mainwindow.h"
33
#include "qttubeapplication.h"
4+
#include "ui/widgets/topbar/topbar.h"
45
#include "utils/uiutils.h"
56
#include <QBoxLayout>
67
#include <QComboBox>
@@ -316,8 +317,8 @@ void BrowseHelper::setupNotifications(
316317
}
317318

318319
widget->continuationData = reply->continuationData;
319-
MainWindow::topbar()->updateNotificationCount(0);
320320
widget->setPopulatingFlag(false);
321+
UIUtils::getMainWindow()->topbar()->updateNotificationCount(0);
321322
}
322323

323324
void BrowseHelper::setupSearch(

application/src/ui/forms/settings/settingsform.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "termfilterview.h"
66
#include "ui/forms/plugins/addplugindialog.h"
77
#include "ui/forms/plugins/pluginbrowserview.h"
8+
#include "ui/widgets/topbar/topbar.h"
89
#include "utils/uiutils.h"
910
#include <QButtonGroup>
1011
#include <QFileDialog>
@@ -194,7 +195,7 @@ void SettingsForm::saveSettings()
194195

195196
// force show top bar if auto hiding has been turned off
196197
if (store.autoHideTopBar && !ui->autoHideTopBar->isChecked())
197-
MainWindow::topbar()->show();
198+
UIUtils::getMainWindow()->topbar()->show();
198199

199200
// general
200201
store.appStyle = ui->appStyle->currentText();

0 commit comments

Comments
 (0)