Mercurial > minori
diff src/gui/window.cpp @ 79:c489dd4434af
*: what did I do again?
I really forgot what I did here :)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 12 Oct 2023 11:31:39 -0400 |
parents | 6f7385bd334c |
children | 825506f0e221 |
line wrap: on
line diff
--- a/src/gui/window.cpp Wed Oct 11 12:16:15 2023 -0400 +++ b/src/gui/window.cpp Thu Oct 12 11:31:39 2023 -0400 @@ -59,7 +59,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { main_widget = new QWidget(parent); - SideBar* sidebar = new SideBar(main_widget); + sidebar = new SideBar(main_widget); sidebar->AddItem(tr("Now Playing"), SideBar::CreateIcon(":/icons/16x16/film.png")); sidebar->AddSeparator(); sidebar->AddItem(tr("Anime List"), SideBar::CreateIcon(":/icons/16x16/document-list.png")); @@ -72,7 +72,7 @@ sidebar->setFixedWidth(128); sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); - QStackedWidget* stack = new QStackedWidget(main_widget); + stack = new QStackedWidget(main_widget); stack->addWidget(new NowPlayingPage(main_widget)); stack->addWidget(new AnimeListPage(main_widget)); stack->addWidget(new HistoryPage(main_widget)); @@ -84,9 +84,36 @@ connect(sidebar, &SideBar::CurrentItemChanged, stack, &QStackedWidget::setCurrentIndex); sidebar->SetCurrentItem(static_cast<int>(Pages::ANIME_LIST)); + QHBoxLayout* layout = new QHBoxLayout(main_widget); + layout->addWidget(sidebar); + layout->addWidget(stack); + setCentralWidget(main_widget); + + CreateBars(); + + QTimer* timer = new QTimer(this); + connect(timer, &QTimer::timeout, this, [this] { + NowPlayingPage* page = reinterpret_cast<NowPlayingPage*>(stack->widget(static_cast<int>(Pages::NOW_PLAYING))); + + Filesystem::Path p = Track::Media::GetCurrentPlaying(); + std::string title = Track::Media::GetFileTitle(p); + int id = Anime::db.GetAnimeFromTitle(title); + if (id == 0) { + page->SetDefault(); + return; + } + + page->SetPlaying(id, -1); + }); + timer->start(5000); + + DarkTheme::SetTheme(session.config.theme); +} + +void MainWindow::CreateBars() { /* Menu Bar */ QAction* action; - QMenuBar* menubar = new QMenuBar(parent); + QMenuBar* menubar = new QMenuBar(this); QMenu* menu = menubar->addMenu(tr("&File")); QMenu* submenu = menu->addMenu(tr("&Library folders")); @@ -106,7 +133,7 @@ action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit); menu = menubar->addMenu(tr("&Services")); - action = menu->addAction(tr("Synchronize &list"), [stack] { AsyncSynchronize(stack); }); + action = menu->addAction(tr("Synchronize &list"), [this] { AsyncSynchronize(stack); }); action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); menu->addSeparator(); @@ -187,7 +214,7 @@ [pages_group](int index) { pages_group->actions()[index]->setChecked(true); }); connect(pages_group, &QActionGroup::triggered, this, - [page_to_index_map, sidebar](QAction* action) { sidebar->SetCurrentItem(page_to_index_map.at(action)); }); + [this, page_to_index_map](QAction* action) { sidebar->SetCurrentItem(page_to_index_map.at(action)); }); menu->addSeparator(); menu->addAction(tr("Show sidebar")); @@ -203,9 +230,14 @@ setMenuBar(menubar); /* Toolbar */ + /* remove old toolbar(s) */ + QList<QToolBar*> toolbars = findChildren<QToolBar*>(); + for (auto& t : toolbars) + removeToolBar(t); + QToolBar* toolbar = new QToolBar(this); toolbar->addAction(QIcon(":/icons/24x24/arrow-circle-double-135.png"), tr("&Synchronize"), - [stack] { AsyncSynchronize(stack); }); + [this] { AsyncSynchronize(stack); }); toolbar->addSeparator(); QToolButton* button = new QToolButton(toolbar); @@ -235,28 +267,6 @@ }); addToolBar(toolbar); - QHBoxLayout* layout = new QHBoxLayout(main_widget); - layout->addWidget(sidebar); - layout->addWidget(stack); - setCentralWidget(main_widget); - - QTimer* timer = new QTimer(this); - connect(timer, &QTimer::timeout, this, [stack] { - NowPlayingPage* page = reinterpret_cast<NowPlayingPage*>(stack->widget(static_cast<int>(Pages::NOW_PLAYING))); - - Filesystem::Path p = Track::Media::GetCurrentPlaying(); - std::string title = Track::Media::GetFileTitle(p); - int id = Anime::db.GetAnimeFromTitle(title); - if (id == 0) { - page->SetDefault(); - return; - } - - page->SetPlaying(id); - }); - timer->start(5000); - - DarkTheme::SetTheme(session.config.theme); } void MainWindow::SetActivePage(QWidget* page) {