Mercurial > minori
diff src/gui/window.cc @ 291:9a88e1725fd2
*: refactor lots of stuff
I forgot to put this into different commits, oops!
anyway, it doesn't really matter *that* much since this is an
unfinished hobby project anyway. once it starts getting stable
commit history will be more important, but for now it's not
that big of a deal
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Sun, 12 May 2024 16:31:07 -0400 |
parents | 657fda1b9cac |
children | bf89fbf7ff38 |
line wrap: on
line diff
--- a/src/gui/window.cc Wed May 08 17:32:28 2024 -0400 +++ b/src/gui/window.cc Sun May 12 16:31:07 2024 -0400 @@ -74,21 +74,32 @@ action_->setEnabled(true); } -MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), async_synchronize_thread_(nullptr, nullptr) { +MainWindow::MainWindow(QWidget* parent) + : QMainWindow(parent) + , async_synchronize_thread_(nullptr, nullptr) { setWindowIcon(QIcon(":/icons/favicon.png")); sidebar_.setFixedWidth(128); sidebar_.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); - connect(&sidebar_, &SideBar::CurrentItemChanged, &stack_, &QStackedWidget::setCurrentIndex); - new QHBoxLayout(&main_widget_); + CreateBars(); + + stack_.addWidget(&now_playing_page_); + /* ---- */ + stack_.addWidget(&anime_list_page_); + stack_.addWidget(&history_page_); + stack_.addWidget(&statistics_page_); + /* ---- */ + stack_.addWidget(&search_page_); + stack_.addWidget(&seasons_page_); + stack_.addWidget(&torrents_page_); + AddMainWidgets(); + sidebar_.SetCurrentItem(static_cast<int>(Pages::ANIME_LIST)); setCentralWidget(&main_widget_); - CreateBars(); - NowPlayingPage* page = reinterpret_cast<NowPlayingPage*>(stack_.widget(static_cast<int>(Pages::NOW_PLAYING))); connect(&playing_thread_, &MainWindowPlayingThread::Done, this, [page](const std::vector<std::string>& files) { @@ -123,8 +134,9 @@ playing_thread_timer_.start(5000); } +/* Does the main part of what Qt's generic "RetranslateUI" function would do */ void MainWindow::AddMainWidgets() { - int page = static_cast<int>(Pages::ANIME_LIST); + int page = sidebar_.GetCurrentItem(); sidebar_.clear(); @@ -138,20 +150,6 @@ sidebar_.AddItem(tr("Seasons"), SideBar::CreateIcon(":/icons/16x16/calendar.png")); sidebar_.AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/16x16/feed.png")); - while (stack_.count()) - stack_.removeWidget(stack_.widget(0)); - - /* can we allocate these on the stack? */ - stack_.addWidget(new NowPlayingPage(&main_widget_)); - /* ---- */ - stack_.addWidget(new AnimeListPage(&main_widget_)); - stack_.addWidget(new HistoryPage(&main_widget_)); - stack_.addWidget(new StatisticsPage(&main_widget_)); - /* ---- */ - stack_.addWidget(new SearchPage(&main_widget_)); - stack_.addWidget(new SeasonsPage(&main_widget_)); - stack_.addWidget(new TorrentsPage(&main_widget_)); - sidebar_.SetCurrentItem(page); main_widget_.layout()->addWidget(&sidebar_); @@ -334,6 +332,8 @@ } /* pain in the ass */ + disconnect(&sidebar_, &SideBar::CurrentItemChanged, nullptr, nullptr); + connect(&sidebar_, &SideBar::CurrentItemChanged, &stack_, &QStackedWidget::setCurrentIndex); connect(&sidebar_, &SideBar::CurrentItemChanged, this, [pages_group](int index) { QAction* checked = pages_group->checkedAction(); @@ -508,8 +508,7 @@ } void MainWindow::RetranslateUI() { - /* This kinda sucks but nobody's really going to be changing - the application language all the time :p */ + /* This sucks a LOT */ setUpdatesEnabled(false); AddMainWidgets(); CreateBars(); @@ -532,14 +531,18 @@ QMainWindow::showEvent(event); #ifdef WIN32 /* Technically this *should* be - session.config.theme.IsInDarkTheme() && win32::IsInDarkTheme() - but I prefer the title bar being black even when light mode - is enabled :/ */ + * session.config.theme.IsInDarkTheme() && win32::IsInDarkTheme() + * but I prefer the title bar being black even when light mode + * is enabled :/ */ win32::SetTitleBarsToBlack(session.config.theme.IsInDarkTheme()); #endif } void MainWindow::closeEvent(QCloseEvent* event) { + playing_thread_timer_.stop(); + playing_thread_.wait(); + async_synchronize_thread_.wait(); + session.config.Save(); Anime::db.SaveDatabaseToDisk(); event->accept();