Mercurial > minori
diff src/gui/window.cc @ 114:ab191e28e69d
*: add initial torrent stuff
WOAH!
these checkboxes are a pain in my fucking ass
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 07 Nov 2023 08:03:42 -0500 |
parents | 32afe0e940bf |
children | c72b907b9bef |
line wrap: on
line diff
--- a/src/gui/window.cc Mon Nov 06 13:48:11 2023 -0500 +++ b/src/gui/window.cc Tue Nov 07 08:03:42 2023 -0500 @@ -53,12 +53,12 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { setWindowIcon(QIcon(":/favicon.png")); - main_widget = new QWidget(this); - /*QHBoxLayout* layout = */new QHBoxLayout(main_widget); + main_widget.reset(new QWidget(this)); + /*QHBoxLayout* layout = */new QHBoxLayout(main_widget.get()); AddMainWidgets(); - setCentralWidget(main_widget); + setCentralWidget(main_widget.get()); CreateBars(); @@ -81,18 +81,17 @@ void MainWindow::AddMainWidgets() { int page = static_cast<int>(Pages::ANIME_LIST); - if (sidebar) { - main_widget->layout()->removeWidget(sidebar); - delete sidebar; + if (sidebar.get()) { + main_widget->layout()->removeWidget(sidebar.get()); + sidebar.reset(); } - if (stack) { + if (stack.get()) { page = stack->currentIndex(); - main_widget->layout()->removeWidget(stack); - delete stack; + main_widget->layout()->removeWidget(stack.get()); } - sidebar = new SideBar(main_widget); + sidebar.reset(new SideBar(main_widget.get())); sidebar->setFixedWidth(128); sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); @@ -106,182 +105,284 @@ sidebar->AddItem(tr("Seasons"), SideBar::CreateIcon(":/icons/16x16/calendar.png")); sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/16x16/feed.png")); - stack = new QStackedWidget(main_widget); - 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)); + stack.reset(new QStackedWidget(main_widget.get())); + stack->addWidget(new NowPlayingPage(main_widget.get())); + stack->addWidget(new AnimeListPage(main_widget.get())); + stack->addWidget(new HistoryPage(main_widget.get())); + stack->addWidget(new StatisticsPage(main_widget.get())); + stack->addWidget(new SearchPage(main_widget.get())); + stack->addWidget(new SeasonsPage(main_widget.get())); + stack->addWidget(new TorrentsPage(main_widget.get())); - connect(sidebar, &SideBar::CurrentItemChanged, stack, &QStackedWidget::setCurrentIndex); + connect(sidebar.get(), &SideBar::CurrentItemChanged, stack.get(), &QStackedWidget::setCurrentIndex); sidebar->SetCurrentItem(page); - main_widget->layout()->addWidget(sidebar); - main_widget->layout()->addWidget(stack); + main_widget->layout()->addWidget(sidebar.get()); + main_widget->layout()->addWidget(stack.get()); } void MainWindow::CreateBars() { - /* Menu Bar */ - QAction* action; + /* Menu Bar + The notation of these might seem ugly at first, but it's actually very nice + (just trust me). It makes it much easier to edit the lists and makes it clear + if you're in submenu or not. */ QMenuBar* menubar = new QMenuBar(this); - QMenu* menu = menubar->addMenu(tr("&File")); - QMenu* submenu = menu->addMenu(tr("&Library folders")); - action = submenu->addAction(tr("&Add new folder...")); + { + /* File */ + QMenu* menu = menubar->addMenu(tr("&File")); - action = menu->addAction(tr("&Scan available episodes")); - - menu->addSeparator(); + { + QMenu* submenu = menu->addMenu(tr("&Library folders")); + { + QAction* action = submenu->addAction(tr("&Add new folder...")); + } + } - action = menu->addAction(tr("Play &next episode")); - action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N)); - action = menu->addAction(tr("Play &random episode")); - action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R)); + { + QAction* action = menu->addAction(tr("&Scan available episodes")); + } - menu->addSeparator(); + menu->addSeparator(); - action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit); +// { +// QAction* action = menu->addAction(tr("Play &next episode")); +// action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N)); +// } +// +// { +// QAction* action = menu->addAction(tr("Play &random episode")); +// action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R)); +// } - menu = menubar->addMenu(tr("&Services")); - action = menu->addAction(tr("Synchronize &list"), [this] { AsyncSynchronize(stack); }); - action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); - - menu->addSeparator(); + menu->addSeparator(); - submenu = menu->addMenu(tr("&AniList")); - action = submenu->addAction(tr("Go to my &profile")); - action = submenu->addAction(tr("Go to my &stats")); + { + QAction* action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit); + } + } - submenu = menu->addMenu(tr("&Kitsu")); - action = submenu->addAction(tr("Go to my &feed")); - action = submenu->addAction(tr("Go to my &library")); - action = submenu->addAction(tr("Go to my &profile")); - - submenu = menu->addMenu(tr("&MyAnimeList")); - action = submenu->addAction(tr("Go to my p&anel")); - action = submenu->addAction(tr("Go to my &profile")); - action = submenu->addAction(tr("Go to my &history")); + { + /* Services */ + QMenu* menu = menubar->addMenu(tr("&Services")); + { + { + QAction* action = menu->addAction(tr("Synchronize &list"), [this] { AsyncSynchronize(stack.get()); }); + action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); + } - menu = menubar->addMenu(tr("&Tools")); - submenu = menu->addMenu(tr("&Export anime list")); - action = submenu->addAction(tr("Export as &Markdown...")); - action = submenu->addAction(tr("Export as MyAnimeList &XML...")); - - menu->addSeparator(); - - action = menu->addAction(tr("Enable anime &recognition")); - action->setCheckable(true); - action = menu->addAction(tr("Enable auto &sharing")); - action->setCheckable(true); - action = menu->addAction(tr("Enable &auto synchronization")); - action->setCheckable(true); - - menu->addSeparator(); +// menu->addSeparator(); +// +// { +// /* AniList */ +// QMenu* submenu = menu->addMenu(tr("&AniList")); +// QAction* action = submenu->addAction(tr("Go to my &profile")); +// action = submenu->addAction(tr("Go to my &stats")); +// } +// +// { +// /* Kitsu */ +// QMenu* submenu = menu->addMenu(tr("&Kitsu")); +// QAction* action = submenu->addAction(tr("Go to my &feed")); +// action = submenu->addAction(tr("Go to my &library")); +// action = submenu->addAction(tr("Go to my &profile")); +// } +// { +// QMenu* submenu = menu->addMenu(tr("&MyAnimeList")); +// QAction* action = submenu->addAction(tr("Go to my p&anel")); +// action = submenu->addAction(tr("Go to my &profile")); +// action = submenu->addAction(tr("Go to my &history")); +// } + } + } - action = menu->addAction(tr("&Settings"), [this] { - SettingsDialog dialog(this); - dialog.exec(); - }); - action->setMenuRole(QAction::PreferencesRole); - - menu = menubar->addMenu(tr("&View")); - - std::map<QAction*, int> page_to_index_map = {}; - - QActionGroup* pages_group = new QActionGroup(this); - pages_group->setExclusive(true); + { + /* Tools */ + QMenu* menu = menubar->addMenu(tr("&Tools")); +// { +// /* Export anime list */ +// QMenu* submenu = menu->addMenu(tr("&Export anime list")); +// +// { +// /* Markdown export */ +// QAction* action = submenu->addAction(tr("Export as &Markdown...")); +// } +// +// { +// /* XML export */ +// QAction* action = submenu->addAction(tr("Export as MyAnimeList &XML...")); +// } +// } +// menu->addSeparator(); +// +// { +// QAction* action = menu->addAction(tr("Enable anime &recognition")); +// action->setCheckable(true); +// } +// +// { +// QAction* action = menu->addAction(tr("Enable auto &sharing")); +// action->setCheckable(true); +// } +// +// { +// QAction* action = menu->addAction(tr("Enable &auto synchronization")); +// action->setCheckable(true); +// } +// +// menu->addSeparator(); - action = pages_group->addAction(menu->addAction(tr("&Now Playing"))); - action->setCheckable(true); - page_to_index_map[action] = 0; + { + QAction* action = menu->addAction(tr("&Settings"), [this] { + SettingsDialog dialog(this); + dialog.exec(); + }); + action->setMenuRole(QAction::PreferencesRole); + } + } + + { + /* View */ + QMenu* menu = menubar->addMenu(tr("&View")); - action = pages_group->addAction(menu->addAction(tr("&Anime List"))); - page_to_index_map[action] = 1; - action->setCheckable(true); - action->setChecked(true); + { + /* Pages... */ + std::map<QAction*, int> page_to_index_map = {}; - action = pages_group->addAction(menu->addAction(tr("&History"))); - action->setCheckable(true); - page_to_index_map[action] = 2; + QActionGroup* pages_group = new QActionGroup(this); + pages_group->setExclusive(true); - action = pages_group->addAction(menu->addAction(tr("&Statistics"))); - action->setCheckable(true); - page_to_index_map[action] = 3; + { + QAction* action = pages_group->addAction(menu->addAction(tr("&Now Playing"))); + action->setCheckable(true); + page_to_index_map[action] = 0; + } - action = pages_group->addAction(menu->addAction(tr("S&earch"))); - action->setCheckable(true); - page_to_index_map[action] = 4; + { + QAction* action = pages_group->addAction(menu->addAction(tr("&Anime List"))); + action->setCheckable(true); + action->setChecked(true); + page_to_index_map[action] = 1; + } + + { + QAction* action = pages_group->addAction(menu->addAction(tr("&History"))); + action->setCheckable(true); + page_to_index_map[action] = 2; + } - action = pages_group->addAction(menu->addAction(tr("Se&asons"))); - action->setCheckable(true); - page_to_index_map[action] = 5; + { + QAction* action = pages_group->addAction(menu->addAction(tr("&Statistics"))); + action->setCheckable(true); + page_to_index_map[action] = 3; + } - action = pages_group->addAction(menu->addAction(tr("&Torrents"))); - action->setCheckable(true); - page_to_index_map[action] = 6; + { + QAction* action = pages_group->addAction(menu->addAction(tr("S&earch"))); + action->setCheckable(true); + page_to_index_map[action] = 4; + } - connect(sidebar, &SideBar::CurrentItemChanged, this, - [pages_group](int index) { pages_group->actions()[index]->setChecked(true); }); + { + QAction* action = pages_group->addAction(menu->addAction(tr("Se&asons"))); + action->setCheckable(true); + page_to_index_map[action] = 5; + } - connect(pages_group, &QActionGroup::triggered, this, - [this, page_to_index_map](QAction* action) { sidebar->SetCurrentItem(page_to_index_map.at(action)); }); + { + QAction* action = pages_group->addAction(menu->addAction(tr("&Torrents"))); + action->setCheckable(true); + page_to_index_map[action] = 6; + } - menu->addSeparator(); - menu->addAction(tr("Show sidebar")); + /* pain in my ass */ + connect(sidebar.get(), &SideBar::CurrentItemChanged, this, + [pages_group](int index) { pages_group->actions()[index]->setChecked(true); }); + + connect(pages_group, &QActionGroup::triggered, this, + [this, page_to_index_map](QAction* action) { sidebar->SetCurrentItem(page_to_index_map.at(action)); }); + } + + menu->addSeparator(); - menu = menubar->addMenu(tr("&Help")); - action = menu->addAction(tr("&About Minori"), this, [this] { - AboutWindow dialog(this); - dialog.exec(); - }); - action = menu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); - action->setMenuRole(QAction::AboutQtRole); +// { +// QAction* action = menu->addAction(tr("Show sidebar")); +// } + } + + { + /* Help */ + QMenu* menu = menubar->addMenu(tr("&Help")); + { + /* About Minori */ + menu->addAction(tr("&About Minori"), this, [this] { + AboutWindow dialog(this); + dialog.exec(); + }); + } + + { + /* About Qt */ + QAction* action = menu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); + action->setMenuRole(QAction::AboutQtRole); + } + } /* QMainWindow will delete the old one for us, according to the docs */ setMenuBar(menubar); /* Toolbar */ + /* remove old toolbar(s) */ - QList<QToolBar*> toolbars = findChildren<QToolBar*>(); - for (auto& t : toolbars) { + for (QToolBar*& t : findChildren<QToolBar*>(Qt::FindDirectChildrenOnly)) { removeToolBar(t); delete t; } - QToolBar* toolbar = new QToolBar(this); - toolbar->addAction(QIcon(":/icons/24x24/arrow-circle-double-135.png"), tr("&Synchronize"), - [this] { AsyncSynchronize(stack); }); - toolbar->addSeparator(); + { + /* Toolbar */ + QToolBar* toolbar = new QToolBar(this); + toolbar->addAction(QIcon(":/icons/24x24/arrow-circle-double-135.png"), tr("&Synchronize"), + [this] { AsyncSynchronize(stack.get()); }); - QToolButton* button = new QToolButton(toolbar); + toolbar->addSeparator(); - menu = new QMenu(button); - action = menu->addAction(tr("Add new folder...")); + { + QToolButton* button = new QToolButton(toolbar); + { + QMenu* menu = new QMenu(button); + QAction* action = menu->addAction(tr("...")); - button->setMenu(menu); - button->setIcon(QIcon(":/icons/24x24/folder-open.png")); - button->setPopupMode(QToolButton::InstantPopup); - toolbar->addWidget(button); + button->setMenu(menu); + } + button->setIcon(QIcon(":/icons/24x24/folder-open.png")); + button->setPopupMode(QToolButton::InstantPopup); + toolbar->addWidget(button); + } - button = new QToolButton(toolbar); + { + QToolButton* button = new QToolButton(toolbar); - menu = new QMenu(button); - action = menu->addAction(tr("Placeholder")); + { + QMenu* menu = new QMenu(button); + QAction* action = menu->addAction(tr("...")); + + button->setMenu(menu); + } - button->setMenu(menu); - button->setIcon(QIcon(":/icons/24x24/application-export.png")); - button->setPopupMode(QToolButton::InstantPopup); - toolbar->addWidget(button); + button->setIcon(QIcon(":/icons/24x24/application-export.png")); + button->setPopupMode(QToolButton::InstantPopup); + toolbar->addWidget(button); + } - toolbar->addSeparator(); - toolbar->addAction(QIcon(":/icons/24x24/gear.png"), tr("S&ettings"), [this] { - SettingsDialog dialog(this); - dialog.exec(); - }); - addToolBar(toolbar); + toolbar->addSeparator(); + toolbar->addAction(QIcon(":/icons/24x24/gear.png"), tr("S&ettings"), [this] { + SettingsDialog dialog(this); + dialog.exec(); + }); + addToolBar(toolbar); + } } void MainWindow::SetActivePage(QWidget* page) {