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
131132void 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+
169175void 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
202208void 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)
216221void 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
228233void 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
275280void 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
296301void MainWindow::showAccountMenu ()
@@ -318,15 +323,20 @@ void MainWindow::showAccountMenu()
318323
319324void 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}
0 commit comments