Mercurial > minori
comparison 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 |
comparison
equal
deleted
inserted
replaced
290:9347e2eaf6e5 | 291:9a88e1725fd2 |
---|---|
72 Services::Synchronize(); | 72 Services::Synchronize(); |
73 page_->Refresh(); | 73 page_->Refresh(); |
74 action_->setEnabled(true); | 74 action_->setEnabled(true); |
75 } | 75 } |
76 | 76 |
77 MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), async_synchronize_thread_(nullptr, nullptr) { | 77 MainWindow::MainWindow(QWidget* parent) |
78 : QMainWindow(parent) | |
79 , async_synchronize_thread_(nullptr, nullptr) { | |
78 setWindowIcon(QIcon(":/icons/favicon.png")); | 80 setWindowIcon(QIcon(":/icons/favicon.png")); |
79 | 81 |
80 sidebar_.setFixedWidth(128); | 82 sidebar_.setFixedWidth(128); |
81 sidebar_.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); | 83 sidebar_.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
82 | 84 |
83 connect(&sidebar_, &SideBar::CurrentItemChanged, &stack_, &QStackedWidget::setCurrentIndex); | |
84 | |
85 new QHBoxLayout(&main_widget_); | 85 new QHBoxLayout(&main_widget_); |
86 | 86 |
87 CreateBars(); | |
88 | |
89 stack_.addWidget(&now_playing_page_); | |
90 /* ---- */ | |
91 stack_.addWidget(&anime_list_page_); | |
92 stack_.addWidget(&history_page_); | |
93 stack_.addWidget(&statistics_page_); | |
94 /* ---- */ | |
95 stack_.addWidget(&search_page_); | |
96 stack_.addWidget(&seasons_page_); | |
97 stack_.addWidget(&torrents_page_); | |
98 | |
87 AddMainWidgets(); | 99 AddMainWidgets(); |
100 sidebar_.SetCurrentItem(static_cast<int>(Pages::ANIME_LIST)); | |
88 setCentralWidget(&main_widget_); | 101 setCentralWidget(&main_widget_); |
89 | |
90 CreateBars(); | |
91 | 102 |
92 NowPlayingPage* page = reinterpret_cast<NowPlayingPage*>(stack_.widget(static_cast<int>(Pages::NOW_PLAYING))); | 103 NowPlayingPage* page = reinterpret_cast<NowPlayingPage*>(stack_.widget(static_cast<int>(Pages::NOW_PLAYING))); |
93 | 104 |
94 connect(&playing_thread_, &MainWindowPlayingThread::Done, this, [page](const std::vector<std::string>& files) { | 105 connect(&playing_thread_, &MainWindowPlayingThread::Done, this, [page](const std::vector<std::string>& files) { |
95 for (const auto& file : files) { | 106 for (const auto& file : files) { |
121 #endif | 132 #endif |
122 | 133 |
123 playing_thread_timer_.start(5000); | 134 playing_thread_timer_.start(5000); |
124 } | 135 } |
125 | 136 |
137 /* Does the main part of what Qt's generic "RetranslateUI" function would do */ | |
126 void MainWindow::AddMainWidgets() { | 138 void MainWindow::AddMainWidgets() { |
127 int page = static_cast<int>(Pages::ANIME_LIST); | 139 int page = sidebar_.GetCurrentItem(); |
128 | 140 |
129 sidebar_.clear(); | 141 sidebar_.clear(); |
130 | 142 |
131 sidebar_.AddItem(tr("Now Playing"), SideBar::CreateIcon(":/icons/16x16/film.png")); | 143 sidebar_.AddItem(tr("Now Playing"), SideBar::CreateIcon(":/icons/16x16/film.png")); |
132 sidebar_.AddSeparator(); | 144 sidebar_.AddSeparator(); |
135 sidebar_.AddItem(tr("Statistics"), SideBar::CreateIcon(":/icons/16x16/chart.png")); | 147 sidebar_.AddItem(tr("Statistics"), SideBar::CreateIcon(":/icons/16x16/chart.png")); |
136 sidebar_.AddSeparator(); | 148 sidebar_.AddSeparator(); |
137 sidebar_.AddItem(tr("Search"), SideBar::CreateIcon(":/icons/16x16/magnifier.png")); | 149 sidebar_.AddItem(tr("Search"), SideBar::CreateIcon(":/icons/16x16/magnifier.png")); |
138 sidebar_.AddItem(tr("Seasons"), SideBar::CreateIcon(":/icons/16x16/calendar.png")); | 150 sidebar_.AddItem(tr("Seasons"), SideBar::CreateIcon(":/icons/16x16/calendar.png")); |
139 sidebar_.AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/16x16/feed.png")); | 151 sidebar_.AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/16x16/feed.png")); |
140 | |
141 while (stack_.count()) | |
142 stack_.removeWidget(stack_.widget(0)); | |
143 | |
144 /* can we allocate these on the stack? */ | |
145 stack_.addWidget(new NowPlayingPage(&main_widget_)); | |
146 /* ---- */ | |
147 stack_.addWidget(new AnimeListPage(&main_widget_)); | |
148 stack_.addWidget(new HistoryPage(&main_widget_)); | |
149 stack_.addWidget(new StatisticsPage(&main_widget_)); | |
150 /* ---- */ | |
151 stack_.addWidget(new SearchPage(&main_widget_)); | |
152 stack_.addWidget(new SeasonsPage(&main_widget_)); | |
153 stack_.addWidget(new TorrentsPage(&main_widget_)); | |
154 | 152 |
155 sidebar_.SetCurrentItem(page); | 153 sidebar_.SetCurrentItem(page); |
156 | 154 |
157 main_widget_.layout()->addWidget(&sidebar_); | 155 main_widget_.layout()->addWidget(&sidebar_); |
158 main_widget_.layout()->addWidget(&stack_); | 156 main_widget_.layout()->addWidget(&stack_); |
332 action->setCheckable(true); | 330 action->setCheckable(true); |
333 connect(action, &QAction::toggled, this, [this] { sidebar_.SetCurrentItem(6); }); | 331 connect(action, &QAction::toggled, this, [this] { sidebar_.SetCurrentItem(6); }); |
334 } | 332 } |
335 | 333 |
336 /* pain in the ass */ | 334 /* pain in the ass */ |
335 disconnect(&sidebar_, &SideBar::CurrentItemChanged, nullptr, nullptr); | |
336 connect(&sidebar_, &SideBar::CurrentItemChanged, &stack_, &QStackedWidget::setCurrentIndex); | |
337 connect(&sidebar_, &SideBar::CurrentItemChanged, this, [pages_group](int index) { | 337 connect(&sidebar_, &SideBar::CurrentItemChanged, this, [pages_group](int index) { |
338 QAction* checked = pages_group->checkedAction(); | 338 QAction* checked = pages_group->checkedAction(); |
339 | 339 |
340 const QList<QAction*>& actions = pages_group->actions(); | 340 const QList<QAction*>& actions = pages_group->actions(); |
341 if (index > actions.size()) | 341 if (index > actions.size()) |
506 async_synchronize_thread_.start(); | 506 async_synchronize_thread_.start(); |
507 } | 507 } |
508 } | 508 } |
509 | 509 |
510 void MainWindow::RetranslateUI() { | 510 void MainWindow::RetranslateUI() { |
511 /* This kinda sucks but nobody's really going to be changing | 511 /* This sucks a LOT */ |
512 the application language all the time :p */ | |
513 setUpdatesEnabled(false); | 512 setUpdatesEnabled(false); |
514 AddMainWidgets(); | 513 AddMainWidgets(); |
515 CreateBars(); | 514 CreateBars(); |
516 setUpdatesEnabled(true); | 515 setUpdatesEnabled(true); |
517 } | 516 } |
530 | 529 |
531 void MainWindow::showEvent(QShowEvent* event) { | 530 void MainWindow::showEvent(QShowEvent* event) { |
532 QMainWindow::showEvent(event); | 531 QMainWindow::showEvent(event); |
533 #ifdef WIN32 | 532 #ifdef WIN32 |
534 /* Technically this *should* be | 533 /* Technically this *should* be |
535 session.config.theme.IsInDarkTheme() && win32::IsInDarkTheme() | 534 * session.config.theme.IsInDarkTheme() && win32::IsInDarkTheme() |
536 but I prefer the title bar being black even when light mode | 535 * but I prefer the title bar being black even when light mode |
537 is enabled :/ */ | 536 * is enabled :/ */ |
538 win32::SetTitleBarsToBlack(session.config.theme.IsInDarkTheme()); | 537 win32::SetTitleBarsToBlack(session.config.theme.IsInDarkTheme()); |
539 #endif | 538 #endif |
540 } | 539 } |
541 | 540 |
542 void MainWindow::closeEvent(QCloseEvent* event) { | 541 void MainWindow::closeEvent(QCloseEvent* event) { |
542 playing_thread_timer_.stop(); | |
543 playing_thread_.wait(); | |
544 async_synchronize_thread_.wait(); | |
545 | |
543 session.config.Save(); | 546 session.config.Save(); |
544 Anime::db.SaveDatabaseToDisk(); | 547 Anime::db.SaveDatabaseToDisk(); |
545 event->accept(); | 548 event->accept(); |
546 } | 549 } |