Mercurial > minori
view src/gui/window.cpp @ 47:d8eb763e6661
information.cpp: add widgets to the list tab, and add an
"optional date" widget like taiga has so users can specify whether to
set the date or not
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 25 Sep 2023 00:43:38 -0400 |
parents | d0adc4aedfc8 |
children | e613772f41d5 |
line wrap: on
line source
#include "gui/window.h" #include "core/config.h" #include "core/session.h" #include "gui/dark_theme.h" #include "gui/dialog/settings.h" #include "gui/pages/anime_list.h" #include "gui/pages/now_playing.h" #include "gui/pages/statistics.h" #include "gui/widgets/sidebar.h" #include "services/services.h" #include <QApplication> #include <QFile> #include <QMainWindow> #include <QMenuBar> #include <QPlainTextEdit> #include <QStackedWidget> #include <QTextStream> #if MACOSX # include "sys/osx/dark_theme.h" #elif defined(WIN32) # include "sys/win32/dark_theme.h" #endif enum class Pages { NOW_PLAYING, ANIME_LIST, HISTORY, STATISTICS, SEARCH, SEASONS, TORRENTS }; MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { main_widget = new QWidget(parent); SideBar* sidebar = new SideBar(main_widget); sidebar->AddItem("Now Playing", SideBar::CreateIcon(":/icons/16x16/film.png")); sidebar->AddSeparator(); sidebar->AddItem("Anime List", SideBar::CreateIcon(":/icons/16x16/document-list.png")); sidebar->AddItem("History", SideBar::CreateIcon(":/icons/16x16/clock-history-frame.png")); sidebar->AddItem("Statistics", SideBar::CreateIcon(":/icons/16x16/chart.png")); sidebar->AddSeparator(); sidebar->AddItem("Search", SideBar::CreateIcon(":/icons/16x16/magnifier.png")); sidebar->AddItem("Seasons", SideBar::CreateIcon(":/icons/16x16/calendar.png")); sidebar->AddItem("Torrents", SideBar::CreateIcon(":/icons/16x16/feed.png")); sidebar->setFixedWidth(128); sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); QStackedWidget* stack = new QStackedWidget(main_widget); stack->addWidget(new NowPlayingWidget(main_widget)); stack->addWidget(new AnimeListWidget(main_widget)); stack->addWidget(new StatisticsWidget(main_widget)); connect(sidebar, &SideBar::CurrentItemChanged, stack, [stack](int index) { switch (index) { case 0: case 1: stack->setCurrentIndex(index); break; case 3: stack->setCurrentIndex(2); break; default: break; } }); sidebar->setCurrentRow(2); /* Menu Bar */ QAction* action; QMenuBar* menubar = new QMenuBar(parent); QMenu* menu = menubar->addMenu("&File"); QMenu* submenu = menu->addMenu("&Library folders"); action = submenu->addAction("&Add new folder..."); action = menu->addAction("&Scan available episodes"); menu->addSeparator(); action = menu->addAction("Play &next episode"); action = menu->addAction("Play &random episode"); menu->addSeparator(); action = menu->addAction("E&xit", qApp, &QApplication::quit); menu = menubar->addMenu("&Services"); action = menu->addAction("Synchronize &list", [this, stack] { Services::Synchronize(); ((AnimeListWidget*)stack->widget((int)Pages::ANIME_LIST))->Refresh(); }); menu->addSeparator(); submenu = menu->addMenu("&AniList"); action = submenu->addAction("Go to my &profile"); action = submenu->addAction("Go to my &stats"); submenu = menu->addMenu("&Kitsu"); action = submenu->addAction("Go to my &feed"); action = submenu->addAction("Go to my &library"); action = submenu->addAction("Go to my &profile"); submenu = menu->addMenu("&MyAnimeList"); action = submenu->addAction("Go to my p&anel"); action = submenu->addAction("Go to my &profile"); action = submenu->addAction("Go to my &history"); menu = menubar->addMenu("&Tools"); submenu = menu->addMenu("&Export anime list"); action = submenu->addAction("Export as &Markdown..."); action = submenu->addAction("Export as MyAnimeList &XML..."); menu->addSeparator(); action = menu->addAction("Enable anime &recognition"); action->setCheckable(true); action = menu->addAction("Enable auto &sharing"); action->setCheckable(true); action = menu->addAction("Enable &auto synchronization"); action->setCheckable(true); menu->addSeparator(); action = menu->addAction("&Settings", [this] { SettingsDialog dialog(this); dialog.exec(); }); action->setMenuRole(QAction::PreferencesRole); menu = menubar->addMenu("&View"); std::map<QAction*, int> page_to_index_map = {}; QActionGroup* pages_group = new QActionGroup(this); pages_group->setExclusive(true); action = pages_group->addAction(menu->addAction("&Now Playing")); page_to_index_map[action] = 0; action = pages_group->addAction(menu->addAction("&Anime List")); page_to_index_map[action] = 1; action->setChecked(true); action = pages_group->addAction(menu->addAction("&History")); page_to_index_map[action] = 2; action = pages_group->addAction(menu->addAction("&Statistics")); page_to_index_map[action] = 3; action = pages_group->addAction(menu->addAction("S&earch")); page_to_index_map[action] = 4; action = pages_group->addAction(menu->addAction("Se&asons")); page_to_index_map[action] = 5; action = pages_group->addAction(menu->addAction("&Torrents")); page_to_index_map[action] = 6; connect(pages_group, &QActionGroup::triggered, this, [page_to_index_map, stack](QAction* action) { int index = page_to_index_map.at(action); switch (index) { case 0: case 1: stack->setCurrentIndex(index); break; case 3: stack->setCurrentIndex(2); default: break; } }); menu = menubar->addMenu("&Help"); action = menu->addAction("About &Qt", qApp, [this] { qApp->aboutQt(); }); action->setMenuRole(QAction::AboutQtRole); setMenuBar(menubar); QHBoxLayout* layout = new QHBoxLayout(main_widget); layout->addWidget(sidebar); layout->addWidget(stack); setCentralWidget(main_widget); DarkTheme::SetTheme(session.config.theme); } void MainWindow::SetActivePage(QWidget* page) { this->setCentralWidget(page); } void MainWindow::closeEvent(QCloseEvent* event) { session.config.Save(); event->accept(); } #include "gui/moc_window.cpp"