Mercurial > minori
comparison src/gui/window.cpp @ 51:75c804f713b2
window: add about window,
*: use tr() when applicable (useful for i18n)
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Mon, 25 Sep 2023 20:29:26 -0400 |
| parents | e613772f41d5 |
| children | 466ac9870df9 |
comparison
equal
deleted
inserted
replaced
| 50:10868c3fb2be | 51:75c804f713b2 |
|---|---|
| 1 #include "gui/window.h" | 1 #include "gui/window.h" |
| 2 #include "core/config.h" | 2 #include "core/config.h" |
| 3 #include "core/session.h" | 3 #include "core/session.h" |
| 4 #include "gui/dark_theme.h" | 4 #include "gui/dark_theme.h" |
| 5 #include "gui/dialog/settings.h" | 5 #include "gui/dialog/settings.h" |
| 6 #include "gui/dialog/about.h" | |
| 6 #include "gui/pages/anime_list.h" | 7 #include "gui/pages/anime_list.h" |
| 7 #include "gui/pages/now_playing.h" | 8 #include "gui/pages/now_playing.h" |
| 8 #include "gui/pages/statistics.h" | 9 #include "gui/pages/statistics.h" |
| 9 #include "gui/widgets/sidebar.h" | 10 #include "gui/widgets/sidebar.h" |
| 10 #include "services/services.h" | 11 #include "services/services.h" |
| 35 | 36 |
| 36 MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { | 37 MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { |
| 37 main_widget = new QWidget(parent); | 38 main_widget = new QWidget(parent); |
| 38 | 39 |
| 39 SideBar* sidebar = new SideBar(main_widget); | 40 SideBar* sidebar = new SideBar(main_widget); |
| 40 sidebar->AddItem("Now Playing", SideBar::CreateIcon(":/icons/16x16/film.png")); | 41 sidebar->AddItem(tr("Now Playing"), SideBar::CreateIcon(":/icons/16x16/film.png")); |
| 41 sidebar->AddSeparator(); | 42 sidebar->AddSeparator(); |
| 42 sidebar->AddItem("Anime List", SideBar::CreateIcon(":/icons/16x16/document-list.png")); | 43 sidebar->AddItem(tr("Anime List"), SideBar::CreateIcon(":/icons/16x16/document-list.png")); |
| 43 sidebar->AddItem("History", SideBar::CreateIcon(":/icons/16x16/clock-history-frame.png")); | 44 sidebar->AddItem(tr("History"), SideBar::CreateIcon(":/icons/16x16/clock-history-frame.png")); |
| 44 sidebar->AddItem("Statistics", SideBar::CreateIcon(":/icons/16x16/chart.png")); | 45 sidebar->AddItem(tr("Statistics"), SideBar::CreateIcon(":/icons/16x16/chart.png")); |
| 45 sidebar->AddSeparator(); | 46 sidebar->AddSeparator(); |
| 46 sidebar->AddItem("Search", SideBar::CreateIcon(":/icons/16x16/magnifier.png")); | 47 sidebar->AddItem(tr("Search"), SideBar::CreateIcon(":/icons/16x16/magnifier.png")); |
| 47 sidebar->AddItem("Seasons", SideBar::CreateIcon(":/icons/16x16/calendar.png")); | 48 sidebar->AddItem(tr("Seasons"), SideBar::CreateIcon(":/icons/16x16/calendar.png")); |
| 48 sidebar->AddItem("Torrents", SideBar::CreateIcon(":/icons/16x16/feed.png")); | 49 sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/16x16/feed.png")); |
| 49 sidebar->setFixedWidth(128); | 50 sidebar->setFixedWidth(128); |
| 50 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); | 51 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
| 51 | 52 |
| 52 QStackedWidget* stack = new QStackedWidget(main_widget); | 53 QStackedWidget* stack = new QStackedWidget(main_widget); |
| 53 stack->addWidget(new NowPlayingWidget(main_widget)); | 54 stack->addWidget(new NowPlayingWidget(main_widget)); |
| 65 sidebar->setCurrentRow(2); | 66 sidebar->setCurrentRow(2); |
| 66 | 67 |
| 67 /* Menu Bar */ | 68 /* Menu Bar */ |
| 68 QAction* action; | 69 QAction* action; |
| 69 QMenuBar* menubar = new QMenuBar(parent); | 70 QMenuBar* menubar = new QMenuBar(parent); |
| 70 QMenu* menu = menubar->addMenu("&File"); | 71 QMenu* menu = menubar->addMenu(tr("&File")); |
| 71 | 72 |
| 72 QMenu* submenu = menu->addMenu("&Library folders"); | 73 QMenu* submenu = menu->addMenu(tr("&Library folders")); |
| 73 action = submenu->addAction("&Add new folder..."); | 74 action = submenu->addAction(tr("&Add new folder...")); |
| 74 | 75 |
| 75 action = menu->addAction("&Scan available episodes"); | 76 action = menu->addAction(tr("&Scan available episodes")); |
| 76 | 77 |
| 77 menu->addSeparator(); | 78 menu->addSeparator(); |
| 78 | 79 |
| 79 action = menu->addAction("Play &next episode"); | 80 action = menu->addAction(tr("Play &next episode")); |
| 80 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N)); | 81 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N)); |
| 81 action = menu->addAction("Play &random episode"); | 82 action = menu->addAction(tr("Play &random episode")); |
| 82 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R)); | 83 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R)); |
| 83 | 84 |
| 84 menu->addSeparator(); | 85 menu->addSeparator(); |
| 85 | 86 |
| 86 action = menu->addAction("E&xit", qApp, &QApplication::quit); | 87 action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit); |
| 87 | 88 |
| 88 menu = menubar->addMenu("&Services"); | 89 menu = menubar->addMenu(tr("&Services")); |
| 89 action = menu->addAction("Synchronize &list", [this, stack] { | 90 action = menu->addAction(tr("Synchronize &list"), [this, stack] { |
| 90 Services::Synchronize(); | 91 Services::Synchronize(); |
| 91 ((AnimeListWidget*)stack->widget((int)Pages::ANIME_LIST))->Refresh(); | 92 ((AnimeListWidget*)stack->widget((int)Pages::ANIME_LIST))->Refresh(); |
| 92 }); | 93 }); |
| 93 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); | 94 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); |
| 94 | 95 |
| 95 menu->addSeparator(); | 96 menu->addSeparator(); |
| 96 | 97 |
| 97 submenu = menu->addMenu("&AniList"); | 98 submenu = menu->addMenu(tr("&AniList")); |
| 98 action = submenu->addAction("Go to my &profile"); | 99 action = submenu->addAction(tr("Go to my &profile")); |
| 99 action = submenu->addAction("Go to my &stats"); | 100 action = submenu->addAction(tr("Go to my &stats")); |
| 100 | 101 |
| 101 submenu = menu->addMenu("&Kitsu"); | 102 submenu = menu->addMenu(tr("&Kitsu")); |
| 102 action = submenu->addAction("Go to my &feed"); | 103 action = submenu->addAction(tr("Go to my &feed")); |
| 103 action = submenu->addAction("Go to my &library"); | 104 action = submenu->addAction(tr("Go to my &library")); |
| 104 action = submenu->addAction("Go to my &profile"); | 105 action = submenu->addAction(tr("Go to my &profile")); |
| 105 | 106 |
| 106 submenu = menu->addMenu("&MyAnimeList"); | 107 submenu = menu->addMenu(tr("&MyAnimeList")); |
| 107 action = submenu->addAction("Go to my p&anel"); | 108 action = submenu->addAction(tr("Go to my p&anel")); |
| 108 action = submenu->addAction("Go to my &profile"); | 109 action = submenu->addAction(tr("Go to my &profile")); |
| 109 action = submenu->addAction("Go to my &history"); | 110 action = submenu->addAction(tr("Go to my &history")); |
| 110 | 111 |
| 111 menu = menubar->addMenu("&Tools"); | 112 menu = menubar->addMenu(tr("&Tools")); |
| 112 submenu = menu->addMenu("&Export anime list"); | 113 submenu = menu->addMenu(tr("&Export anime list")); |
| 113 action = submenu->addAction("Export as &Markdown..."); | 114 action = submenu->addAction(tr("Export as &Markdown...")); |
| 114 action = submenu->addAction("Export as MyAnimeList &XML..."); | 115 action = submenu->addAction(tr("Export as MyAnimeList &XML...")); |
| 115 | 116 |
| 116 menu->addSeparator(); | 117 menu->addSeparator(); |
| 117 | 118 |
| 118 action = menu->addAction("Enable anime &recognition"); | 119 action = menu->addAction(tr("Enable anime &recognition")); |
| 119 action->setCheckable(true); | 120 action->setCheckable(true); |
| 120 action = menu->addAction("Enable auto &sharing"); | 121 action = menu->addAction(tr("Enable auto &sharing")); |
| 121 action->setCheckable(true); | 122 action->setCheckable(true); |
| 122 action = menu->addAction("Enable &auto synchronization"); | 123 action = menu->addAction(tr("Enable &auto synchronization")); |
| 123 action->setCheckable(true); | 124 action->setCheckable(true); |
| 124 | 125 |
| 125 menu->addSeparator(); | 126 menu->addSeparator(); |
| 126 | 127 |
| 127 action = menu->addAction("&Settings", [this] { | 128 action = menu->addAction(tr("&Settings"), [this] { |
| 128 SettingsDialog dialog(this); | 129 SettingsDialog dialog(this); |
| 129 dialog.exec(); | 130 dialog.exec(); |
| 130 }); | 131 }); |
| 131 action->setMenuRole(QAction::PreferencesRole); | 132 action->setMenuRole(QAction::PreferencesRole); |
| 132 | 133 |
| 133 menu = menubar->addMenu("&View"); | 134 menu = menubar->addMenu(tr("&View")); |
| 134 | 135 |
| 135 std::map<QAction*, int> page_to_index_map = {}; | 136 std::map<QAction*, int> page_to_index_map = {}; |
| 136 | 137 |
| 137 QActionGroup* pages_group = new QActionGroup(this); | 138 QActionGroup* pages_group = new QActionGroup(this); |
| 138 pages_group->setExclusive(true); | 139 pages_group->setExclusive(true); |
| 139 | 140 |
| 140 action = pages_group->addAction(menu->addAction("&Now Playing")); | 141 action = pages_group->addAction(menu->addAction(tr("&Now Playing"))); |
| 141 action->setCheckable(true); | 142 action->setCheckable(true); |
| 142 page_to_index_map[action] = 0; | 143 page_to_index_map[action] = 0; |
| 143 | 144 |
| 144 action = pages_group->addAction(menu->addAction("&Anime List")); | 145 action = pages_group->addAction(menu->addAction(tr("&Anime List"))); |
| 145 page_to_index_map[action] = 1; | 146 page_to_index_map[action] = 1; |
| 146 | 147 |
| 147 action->setCheckable(true); | 148 action->setCheckable(true); |
| 148 action->setChecked(true); | 149 action->setChecked(true); |
| 149 action = pages_group->addAction(menu->addAction("&History")); | 150 action = pages_group->addAction(menu->addAction(tr("&History"))); |
| 150 action->setCheckable(true); | 151 action->setCheckable(true); |
| 151 page_to_index_map[action] = 2; | 152 page_to_index_map[action] = 2; |
| 152 | 153 |
| 153 action = pages_group->addAction(menu->addAction("&Statistics")); | 154 action = pages_group->addAction(menu->addAction(tr("&Statistics"))); |
| 154 action->setCheckable(true); | 155 action->setCheckable(true); |
| 155 page_to_index_map[action] = 3; | 156 page_to_index_map[action] = 3; |
| 156 | 157 |
| 157 action = pages_group->addAction(menu->addAction("S&earch")); | 158 action = pages_group->addAction(menu->addAction(tr("S&earch"))); |
| 158 action->setCheckable(true); | 159 action->setCheckable(true); |
| 159 page_to_index_map[action] = 4; | 160 page_to_index_map[action] = 4; |
| 160 | 161 |
| 161 action = pages_group->addAction(menu->addAction("Se&asons")); | 162 action = pages_group->addAction(menu->addAction(tr("Se&asons"))); |
| 162 action->setCheckable(true); | 163 action->setCheckable(true); |
| 163 page_to_index_map[action] = 5; | 164 page_to_index_map[action] = 5; |
| 164 | 165 |
| 165 action = pages_group->addAction(menu->addAction("&Torrents")); | 166 action = pages_group->addAction(menu->addAction(tr("&Torrents"))); |
| 166 action->setCheckable(true); | 167 action->setCheckable(true); |
| 167 page_to_index_map[action] = 6; | 168 page_to_index_map[action] = 6; |
| 168 | 169 |
| 169 connect(pages_group, &QActionGroup::triggered, this, [page_to_index_map, stack](QAction* action) { | 170 connect(pages_group, &QActionGroup::triggered, this, [page_to_index_map, stack](QAction* action) { |
| 170 int index = page_to_index_map.at(action); | 171 int index = page_to_index_map.at(action); |
| 174 case 3: stack->setCurrentIndex(2); | 175 case 3: stack->setCurrentIndex(2); |
| 175 default: break; | 176 default: break; |
| 176 } | 177 } |
| 177 }); | 178 }); |
| 178 menu->addSeparator(); | 179 menu->addSeparator(); |
| 179 menu->addAction("Show sidebar"); | 180 menu->addAction(tr("Show sidebar")); |
| 180 | 181 |
| 181 menu = menubar->addMenu("&Help"); | 182 menu = menubar->addMenu(tr("&Help")); |
| 182 action = menu->addAction("About &Qt", qApp, [this] { qApp->aboutQt(); }); | 183 action = menu->addAction(tr("About Minori"), this, [this] { |
| 184 AboutWindow dialog(this); | |
| 185 dialog.exec(); | |
| 186 }); | |
| 187 action = menu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); | |
| 183 action->setMenuRole(QAction::AboutQtRole); | 188 action->setMenuRole(QAction::AboutQtRole); |
| 184 | 189 |
| 185 setMenuBar(menubar); | 190 setMenuBar(menubar); |
| 186 | 191 |
| 187 QHBoxLayout* layout = new QHBoxLayout(main_widget); | 192 QHBoxLayout* layout = new QHBoxLayout(main_widget); |
