Mercurial > minori
comparison 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 |
comparison
equal
deleted
inserted
replaced
78:1ce00c1c8ddc | 79:c489dd4434af |
---|---|
57 } | 57 } |
58 | 58 |
59 MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { | 59 MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { |
60 main_widget = new QWidget(parent); | 60 main_widget = new QWidget(parent); |
61 | 61 |
62 SideBar* sidebar = new SideBar(main_widget); | 62 sidebar = new SideBar(main_widget); |
63 sidebar->AddItem(tr("Now Playing"), SideBar::CreateIcon(":/icons/16x16/film.png")); | 63 sidebar->AddItem(tr("Now Playing"), SideBar::CreateIcon(":/icons/16x16/film.png")); |
64 sidebar->AddSeparator(); | 64 sidebar->AddSeparator(); |
65 sidebar->AddItem(tr("Anime List"), SideBar::CreateIcon(":/icons/16x16/document-list.png")); | 65 sidebar->AddItem(tr("Anime List"), SideBar::CreateIcon(":/icons/16x16/document-list.png")); |
66 sidebar->AddItem(tr("History"), SideBar::CreateIcon(":/icons/16x16/clock-history-frame.png")); | 66 sidebar->AddItem(tr("History"), SideBar::CreateIcon(":/icons/16x16/clock-history-frame.png")); |
67 sidebar->AddItem(tr("Statistics"), SideBar::CreateIcon(":/icons/16x16/chart.png")); | 67 sidebar->AddItem(tr("Statistics"), SideBar::CreateIcon(":/icons/16x16/chart.png")); |
70 sidebar->AddItem(tr("Seasons"), SideBar::CreateIcon(":/icons/16x16/calendar.png")); | 70 sidebar->AddItem(tr("Seasons"), SideBar::CreateIcon(":/icons/16x16/calendar.png")); |
71 sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/16x16/feed.png")); | 71 sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/16x16/feed.png")); |
72 sidebar->setFixedWidth(128); | 72 sidebar->setFixedWidth(128); |
73 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); | 73 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
74 | 74 |
75 QStackedWidget* stack = new QStackedWidget(main_widget); | 75 stack = new QStackedWidget(main_widget); |
76 stack->addWidget(new NowPlayingPage(main_widget)); | 76 stack->addWidget(new NowPlayingPage(main_widget)); |
77 stack->addWidget(new AnimeListPage(main_widget)); | 77 stack->addWidget(new AnimeListPage(main_widget)); |
78 stack->addWidget(new HistoryPage(main_widget)); | 78 stack->addWidget(new HistoryPage(main_widget)); |
79 stack->addWidget(new StatisticsPage(main_widget)); | 79 stack->addWidget(new StatisticsPage(main_widget)); |
80 stack->addWidget(new SearchPage(main_widget)); | 80 stack->addWidget(new SearchPage(main_widget)); |
82 stack->addWidget(new TorrentsPage(main_widget)); | 82 stack->addWidget(new TorrentsPage(main_widget)); |
83 | 83 |
84 connect(sidebar, &SideBar::CurrentItemChanged, stack, &QStackedWidget::setCurrentIndex); | 84 connect(sidebar, &SideBar::CurrentItemChanged, stack, &QStackedWidget::setCurrentIndex); |
85 sidebar->SetCurrentItem(static_cast<int>(Pages::ANIME_LIST)); | 85 sidebar->SetCurrentItem(static_cast<int>(Pages::ANIME_LIST)); |
86 | 86 |
87 /* Menu Bar */ | |
88 QAction* action; | |
89 QMenuBar* menubar = new QMenuBar(parent); | |
90 QMenu* menu = menubar->addMenu(tr("&File")); | |
91 | |
92 QMenu* submenu = menu->addMenu(tr("&Library folders")); | |
93 action = submenu->addAction(tr("&Add new folder...")); | |
94 | |
95 action = menu->addAction(tr("&Scan available episodes")); | |
96 | |
97 menu->addSeparator(); | |
98 | |
99 action = menu->addAction(tr("Play &next episode")); | |
100 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N)); | |
101 action = menu->addAction(tr("Play &random episode")); | |
102 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R)); | |
103 | |
104 menu->addSeparator(); | |
105 | |
106 action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit); | |
107 | |
108 menu = menubar->addMenu(tr("&Services")); | |
109 action = menu->addAction(tr("Synchronize &list"), [stack] { AsyncSynchronize(stack); }); | |
110 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); | |
111 | |
112 menu->addSeparator(); | |
113 | |
114 submenu = menu->addMenu(tr("&AniList")); | |
115 action = submenu->addAction(tr("Go to my &profile")); | |
116 action = submenu->addAction(tr("Go to my &stats")); | |
117 | |
118 submenu = menu->addMenu(tr("&Kitsu")); | |
119 action = submenu->addAction(tr("Go to my &feed")); | |
120 action = submenu->addAction(tr("Go to my &library")); | |
121 action = submenu->addAction(tr("Go to my &profile")); | |
122 | |
123 submenu = menu->addMenu(tr("&MyAnimeList")); | |
124 action = submenu->addAction(tr("Go to my p&anel")); | |
125 action = submenu->addAction(tr("Go to my &profile")); | |
126 action = submenu->addAction(tr("Go to my &history")); | |
127 | |
128 menu = menubar->addMenu(tr("&Tools")); | |
129 submenu = menu->addMenu(tr("&Export anime list")); | |
130 action = submenu->addAction(tr("Export as &Markdown...")); | |
131 action = submenu->addAction(tr("Export as MyAnimeList &XML...")); | |
132 | |
133 menu->addSeparator(); | |
134 | |
135 action = menu->addAction(tr("Enable anime &recognition")); | |
136 action->setCheckable(true); | |
137 action = menu->addAction(tr("Enable auto &sharing")); | |
138 action->setCheckable(true); | |
139 action = menu->addAction(tr("Enable &auto synchronization")); | |
140 action->setCheckable(true); | |
141 | |
142 menu->addSeparator(); | |
143 | |
144 action = menu->addAction(tr("&Settings"), [this] { | |
145 SettingsDialog dialog(this); | |
146 dialog.exec(); | |
147 }); | |
148 action->setMenuRole(QAction::PreferencesRole); | |
149 | |
150 menu = menubar->addMenu(tr("&View")); | |
151 | |
152 std::map<QAction*, int> page_to_index_map = {}; | |
153 | |
154 QActionGroup* pages_group = new QActionGroup(this); | |
155 pages_group->setExclusive(true); | |
156 | |
157 action = pages_group->addAction(menu->addAction(tr("&Now Playing"))); | |
158 action->setCheckable(true); | |
159 page_to_index_map[action] = 0; | |
160 | |
161 action = pages_group->addAction(menu->addAction(tr("&Anime List"))); | |
162 page_to_index_map[action] = 1; | |
163 action->setCheckable(true); | |
164 action->setChecked(true); | |
165 | |
166 action = pages_group->addAction(menu->addAction(tr("&History"))); | |
167 action->setCheckable(true); | |
168 page_to_index_map[action] = 2; | |
169 | |
170 action = pages_group->addAction(menu->addAction(tr("&Statistics"))); | |
171 action->setCheckable(true); | |
172 page_to_index_map[action] = 3; | |
173 | |
174 action = pages_group->addAction(menu->addAction(tr("S&earch"))); | |
175 action->setCheckable(true); | |
176 page_to_index_map[action] = 4; | |
177 | |
178 action = pages_group->addAction(menu->addAction(tr("Se&asons"))); | |
179 action->setCheckable(true); | |
180 page_to_index_map[action] = 5; | |
181 | |
182 action = pages_group->addAction(menu->addAction(tr("&Torrents"))); | |
183 action->setCheckable(true); | |
184 page_to_index_map[action] = 6; | |
185 | |
186 connect(sidebar, &SideBar::CurrentItemChanged, this, | |
187 [pages_group](int index) { pages_group->actions()[index]->setChecked(true); }); | |
188 | |
189 connect(pages_group, &QActionGroup::triggered, this, | |
190 [page_to_index_map, sidebar](QAction* action) { sidebar->SetCurrentItem(page_to_index_map.at(action)); }); | |
191 | |
192 menu->addSeparator(); | |
193 menu->addAction(tr("Show sidebar")); | |
194 | |
195 menu = menubar->addMenu(tr("&Help")); | |
196 action = menu->addAction(tr("&About Minori"), this, [this] { | |
197 AboutWindow dialog(this); | |
198 dialog.exec(); | |
199 }); | |
200 action = menu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); | |
201 action->setMenuRole(QAction::AboutQtRole); | |
202 | |
203 setMenuBar(menubar); | |
204 | |
205 /* Toolbar */ | |
206 QToolBar* toolbar = new QToolBar(this); | |
207 toolbar->addAction(QIcon(":/icons/24x24/arrow-circle-double-135.png"), tr("&Synchronize"), | |
208 [stack] { AsyncSynchronize(stack); }); | |
209 toolbar->addSeparator(); | |
210 | |
211 QToolButton* button = new QToolButton(toolbar); | |
212 | |
213 menu = new QMenu(button); | |
214 action = menu->addAction(tr("Add new folder...")); | |
215 | |
216 button->setMenu(menu); | |
217 button->setIcon(QIcon(":/icons/24x24/folder-open.png")); | |
218 button->setPopupMode(QToolButton::InstantPopup); | |
219 toolbar->addWidget(button); | |
220 | |
221 button = new QToolButton(toolbar); | |
222 | |
223 menu = new QMenu(button); | |
224 action = menu->addAction(tr("Placeholder")); | |
225 | |
226 button->setMenu(menu); | |
227 button->setIcon(QIcon(":/icons/24x24/application-export.png")); | |
228 button->setPopupMode(QToolButton::InstantPopup); | |
229 toolbar->addWidget(button); | |
230 | |
231 toolbar->addSeparator(); | |
232 toolbar->addAction(QIcon(":/icons/24x24/gear.png"), tr("S&ettings"), [this] { | |
233 SettingsDialog dialog(this); | |
234 dialog.exec(); | |
235 }); | |
236 addToolBar(toolbar); | |
237 | |
238 QHBoxLayout* layout = new QHBoxLayout(main_widget); | 87 QHBoxLayout* layout = new QHBoxLayout(main_widget); |
239 layout->addWidget(sidebar); | 88 layout->addWidget(sidebar); |
240 layout->addWidget(stack); | 89 layout->addWidget(stack); |
241 setCentralWidget(main_widget); | 90 setCentralWidget(main_widget); |
242 | 91 |
92 CreateBars(); | |
93 | |
243 QTimer* timer = new QTimer(this); | 94 QTimer* timer = new QTimer(this); |
244 connect(timer, &QTimer::timeout, this, [stack] { | 95 connect(timer, &QTimer::timeout, this, [this] { |
245 NowPlayingPage* page = reinterpret_cast<NowPlayingPage*>(stack->widget(static_cast<int>(Pages::NOW_PLAYING))); | 96 NowPlayingPage* page = reinterpret_cast<NowPlayingPage*>(stack->widget(static_cast<int>(Pages::NOW_PLAYING))); |
246 | 97 |
247 Filesystem::Path p = Track::Media::GetCurrentPlaying(); | 98 Filesystem::Path p = Track::Media::GetCurrentPlaying(); |
248 std::string title = Track::Media::GetFileTitle(p); | 99 std::string title = Track::Media::GetFileTitle(p); |
249 int id = Anime::db.GetAnimeFromTitle(title); | 100 int id = Anime::db.GetAnimeFromTitle(title); |
250 if (id == 0) { | 101 if (id == 0) { |
251 page->SetDefault(); | 102 page->SetDefault(); |
252 return; | 103 return; |
253 } | 104 } |
254 | 105 |
255 page->SetPlaying(id); | 106 page->SetPlaying(id, -1); |
256 }); | 107 }); |
257 timer->start(5000); | 108 timer->start(5000); |
258 | 109 |
259 DarkTheme::SetTheme(session.config.theme); | 110 DarkTheme::SetTheme(session.config.theme); |
111 } | |
112 | |
113 void MainWindow::CreateBars() { | |
114 /* Menu Bar */ | |
115 QAction* action; | |
116 QMenuBar* menubar = new QMenuBar(this); | |
117 QMenu* menu = menubar->addMenu(tr("&File")); | |
118 | |
119 QMenu* submenu = menu->addMenu(tr("&Library folders")); | |
120 action = submenu->addAction(tr("&Add new folder...")); | |
121 | |
122 action = menu->addAction(tr("&Scan available episodes")); | |
123 | |
124 menu->addSeparator(); | |
125 | |
126 action = menu->addAction(tr("Play &next episode")); | |
127 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N)); | |
128 action = menu->addAction(tr("Play &random episode")); | |
129 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R)); | |
130 | |
131 menu->addSeparator(); | |
132 | |
133 action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit); | |
134 | |
135 menu = menubar->addMenu(tr("&Services")); | |
136 action = menu->addAction(tr("Synchronize &list"), [this] { AsyncSynchronize(stack); }); | |
137 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); | |
138 | |
139 menu->addSeparator(); | |
140 | |
141 submenu = menu->addMenu(tr("&AniList")); | |
142 action = submenu->addAction(tr("Go to my &profile")); | |
143 action = submenu->addAction(tr("Go to my &stats")); | |
144 | |
145 submenu = menu->addMenu(tr("&Kitsu")); | |
146 action = submenu->addAction(tr("Go to my &feed")); | |
147 action = submenu->addAction(tr("Go to my &library")); | |
148 action = submenu->addAction(tr("Go to my &profile")); | |
149 | |
150 submenu = menu->addMenu(tr("&MyAnimeList")); | |
151 action = submenu->addAction(tr("Go to my p&anel")); | |
152 action = submenu->addAction(tr("Go to my &profile")); | |
153 action = submenu->addAction(tr("Go to my &history")); | |
154 | |
155 menu = menubar->addMenu(tr("&Tools")); | |
156 submenu = menu->addMenu(tr("&Export anime list")); | |
157 action = submenu->addAction(tr("Export as &Markdown...")); | |
158 action = submenu->addAction(tr("Export as MyAnimeList &XML...")); | |
159 | |
160 menu->addSeparator(); | |
161 | |
162 action = menu->addAction(tr("Enable anime &recognition")); | |
163 action->setCheckable(true); | |
164 action = menu->addAction(tr("Enable auto &sharing")); | |
165 action->setCheckable(true); | |
166 action = menu->addAction(tr("Enable &auto synchronization")); | |
167 action->setCheckable(true); | |
168 | |
169 menu->addSeparator(); | |
170 | |
171 action = menu->addAction(tr("&Settings"), [this] { | |
172 SettingsDialog dialog(this); | |
173 dialog.exec(); | |
174 }); | |
175 action->setMenuRole(QAction::PreferencesRole); | |
176 | |
177 menu = menubar->addMenu(tr("&View")); | |
178 | |
179 std::map<QAction*, int> page_to_index_map = {}; | |
180 | |
181 QActionGroup* pages_group = new QActionGroup(this); | |
182 pages_group->setExclusive(true); | |
183 | |
184 action = pages_group->addAction(menu->addAction(tr("&Now Playing"))); | |
185 action->setCheckable(true); | |
186 page_to_index_map[action] = 0; | |
187 | |
188 action = pages_group->addAction(menu->addAction(tr("&Anime List"))); | |
189 page_to_index_map[action] = 1; | |
190 action->setCheckable(true); | |
191 action->setChecked(true); | |
192 | |
193 action = pages_group->addAction(menu->addAction(tr("&History"))); | |
194 action->setCheckable(true); | |
195 page_to_index_map[action] = 2; | |
196 | |
197 action = pages_group->addAction(menu->addAction(tr("&Statistics"))); | |
198 action->setCheckable(true); | |
199 page_to_index_map[action] = 3; | |
200 | |
201 action = pages_group->addAction(menu->addAction(tr("S&earch"))); | |
202 action->setCheckable(true); | |
203 page_to_index_map[action] = 4; | |
204 | |
205 action = pages_group->addAction(menu->addAction(tr("Se&asons"))); | |
206 action->setCheckable(true); | |
207 page_to_index_map[action] = 5; | |
208 | |
209 action = pages_group->addAction(menu->addAction(tr("&Torrents"))); | |
210 action->setCheckable(true); | |
211 page_to_index_map[action] = 6; | |
212 | |
213 connect(sidebar, &SideBar::CurrentItemChanged, this, | |
214 [pages_group](int index) { pages_group->actions()[index]->setChecked(true); }); | |
215 | |
216 connect(pages_group, &QActionGroup::triggered, this, | |
217 [this, page_to_index_map](QAction* action) { sidebar->SetCurrentItem(page_to_index_map.at(action)); }); | |
218 | |
219 menu->addSeparator(); | |
220 menu->addAction(tr("Show sidebar")); | |
221 | |
222 menu = menubar->addMenu(tr("&Help")); | |
223 action = menu->addAction(tr("&About Minori"), this, [this] { | |
224 AboutWindow dialog(this); | |
225 dialog.exec(); | |
226 }); | |
227 action = menu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); | |
228 action->setMenuRole(QAction::AboutQtRole); | |
229 | |
230 setMenuBar(menubar); | |
231 | |
232 /* Toolbar */ | |
233 /* remove old toolbar(s) */ | |
234 QList<QToolBar*> toolbars = findChildren<QToolBar*>(); | |
235 for (auto& t : toolbars) | |
236 removeToolBar(t); | |
237 | |
238 QToolBar* toolbar = new QToolBar(this); | |
239 toolbar->addAction(QIcon(":/icons/24x24/arrow-circle-double-135.png"), tr("&Synchronize"), | |
240 [this] { AsyncSynchronize(stack); }); | |
241 toolbar->addSeparator(); | |
242 | |
243 QToolButton* button = new QToolButton(toolbar); | |
244 | |
245 menu = new QMenu(button); | |
246 action = menu->addAction(tr("Add new folder...")); | |
247 | |
248 button->setMenu(menu); | |
249 button->setIcon(QIcon(":/icons/24x24/folder-open.png")); | |
250 button->setPopupMode(QToolButton::InstantPopup); | |
251 toolbar->addWidget(button); | |
252 | |
253 button = new QToolButton(toolbar); | |
254 | |
255 menu = new QMenu(button); | |
256 action = menu->addAction(tr("Placeholder")); | |
257 | |
258 button->setMenu(menu); | |
259 button->setIcon(QIcon(":/icons/24x24/application-export.png")); | |
260 button->setPopupMode(QToolButton::InstantPopup); | |
261 toolbar->addWidget(button); | |
262 | |
263 toolbar->addSeparator(); | |
264 toolbar->addAction(QIcon(":/icons/24x24/gear.png"), tr("S&ettings"), [this] { | |
265 SettingsDialog dialog(this); | |
266 dialog.exec(); | |
267 }); | |
268 addToolBar(toolbar); | |
269 | |
260 } | 270 } |
261 | 271 |
262 void MainWindow::SetActivePage(QWidget* page) { | 272 void MainWindow::SetActivePage(QWidget* page) { |
263 this->setCentralWidget(page); | 273 this->setCentralWidget(page); |
264 } | 274 } |