Mercurial > minori
comparison src/gui/window.cc @ 223:84e0a3c4737a
library: implement menu bar buttons
I also went ahead and put the links from Taiga in so I don't have to
worry about it later...
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 08 Jan 2024 16:54:16 -0500 |
parents | 975a3f0965e2 |
children | f784b5b1914c |
comparison
equal
deleted
inserted
replaced
222:b9f111d84d95 | 223:84e0a3c4737a |
---|---|
14 #include "gui/pages/statistics.h" | 14 #include "gui/pages/statistics.h" |
15 #include "gui/pages/torrents.h" | 15 #include "gui/pages/torrents.h" |
16 #include "gui/widgets/sidebar.h" | 16 #include "gui/widgets/sidebar.h" |
17 #include "services/services.h" | 17 #include "services/services.h" |
18 #include "track/media.h" | 18 #include "track/media.h" |
19 #include "library/library.h" | |
19 | 20 |
20 #include "anitomy/anitomy.h" | 21 #include "anitomy/anitomy.h" |
21 | 22 |
22 #include <QActionGroup> | 23 #include <QActionGroup> |
23 #include <QApplication> | 24 #include <QApplication> |
24 #include <QDebug> | 25 #include <QDebug> |
26 #include <QDesktopServices> | |
25 #include <QFile> | 27 #include <QFile> |
28 #include <QFileDialog> | |
26 #include <QHBoxLayout> | 29 #include <QHBoxLayout> |
27 #include <QMainWindow> | 30 #include <QMainWindow> |
28 #include <QMenuBar> | 31 #include <QMenuBar> |
29 #include <QMessageBox> | 32 #include <QMessageBox> |
30 #include <QPlainTextEdit> | 33 #include <QPlainTextEdit> |
152 main_widget->layout()->addWidget(sidebar.get()); | 155 main_widget->layout()->addWidget(sidebar.get()); |
153 main_widget->layout()->addWidget(stack.get()); | 156 main_widget->layout()->addWidget(stack.get()); |
154 } | 157 } |
155 | 158 |
156 void MainWindow::CreateBars() { | 159 void MainWindow::CreateBars() { |
157 /* Menu Bar | |
158 The notation of these might seem ugly at first, but it's actually very nice | |
159 (just trust me). It makes it much easier to edit the lists and makes it clear | |
160 if you're in submenu or not. */ | |
161 QMenuBar* menubar = new QMenuBar(this); | 160 QMenuBar* menubar = new QMenuBar(this); |
161 QMenu* folder_menu; /* this is used twice, so we declare it here */ | |
162 | 162 |
163 { | 163 { |
164 /* File */ | 164 /* File */ |
165 QMenu* menu = menubar->addMenu(tr("&File")); | 165 QMenu* menu = menubar->addMenu(tr("&File")); |
166 | 166 |
167 { | 167 { |
168 QMenu* submenu = menu->addMenu(tr("&Library folders")); | 168 folder_menu = menu->addMenu(tr("&Library folders")); |
169 { | 169 |
170 QAction* action = submenu->addAction(tr("&Add new folder...")); | 170 /* add in all of our existing folders... */ |
171 } | 171 for (std::size_t i = 0; i < session.config.library.paths.size(); i++) { |
172 } | 172 const QString folder = Strings::ToQString(session.config.library.paths[i]); |
173 | 173 QAction* action = folder_menu->addAction(folder, [folder]{ |
174 { | 174 QDesktopServices::openUrl(QUrl::fromLocalFile(folder)); |
175 QAction* action = menu->addAction(tr("&Scan available episodes")); | 175 }); |
176 if (i < 9) | |
177 action->setShortcut(QKeySequence(Qt::ALT | (Qt::Key_1 + i))); | |
178 else if (i == 9) | |
179 action->setShortcut(QKeySequence(Qt::ALT | Qt::Key_0)); | |
180 } | |
181 | |
182 folder_menu->addSeparator(); | |
183 | |
184 { | |
185 folder_menu->addAction(tr("&Add new folder..."), [this]{ | |
186 const QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), | |
187 "/home", | |
188 QFileDialog::ShowDirsOnly | |
189 | QFileDialog::DontResolveSymlinks); | |
190 if (dir.isEmpty()) | |
191 return; | |
192 session.config.library.paths.push_back(Strings::ToUtf8String(dir)); | |
193 /* we have to recreate the menu bar to add the new folder */ | |
194 CreateBars(); | |
195 }); | |
196 } | |
197 } | |
198 | |
199 { | |
200 menu->addAction(tr("&Scan available episodes"), []{ | |
201 Library::SearchLibraryFolders(); | |
202 }); | |
176 } | 203 } |
177 | 204 |
178 menu->addSeparator(); | 205 menu->addSeparator(); |
179 | 206 |
180 // { | 207 // { |
189 | 216 |
190 menu->addSeparator(); | 217 menu->addSeparator(); |
191 | 218 |
192 { | 219 { |
193 QAction* action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit); | 220 QAction* action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit); |
221 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q)); | |
194 } | 222 } |
195 } | 223 } |
196 | 224 |
197 { | 225 { |
198 /* Services */ | 226 /* Services */ |
382 toolbar->addSeparator(); | 410 toolbar->addSeparator(); |
383 | 411 |
384 { | 412 { |
385 QToolButton* button = new QToolButton(toolbar); | 413 QToolButton* button = new QToolButton(toolbar); |
386 { | 414 { |
387 QMenu* menu = new QMenu(button); | 415 button->setMenu(folder_menu); |
388 QAction* action = menu->addAction(tr("...")); | |
389 | |
390 button->setMenu(menu); | |
391 } | 416 } |
392 button->setIcon(QIcon(":/icons/24x24/folder-open.png")); | 417 button->setIcon(QIcon(":/icons/24x24/folder-open.png")); |
393 button->setPopupMode(QToolButton::InstantPopup); | 418 button->setPopupMode(QToolButton::InstantPopup); |
394 toolbar->addWidget(button); | 419 toolbar->addWidget(button); |
395 } | 420 } |
396 | 421 |
397 { | 422 { |
398 QToolButton* button = new QToolButton(toolbar); | 423 QToolButton* button = new QToolButton(toolbar); |
399 | 424 |
400 { | 425 { |
426 /* links */ | |
401 QMenu* menu = new QMenu(button); | 427 QMenu* menu = new QMenu(button); |
402 QAction* action = menu->addAction(tr("...")); | 428 menu->addAction("Hibari", []{ |
429 QDesktopServices::openUrl(QUrl("https://hb.wopian.me/")); | |
430 }); | |
431 menu->addAction("MALgraph", []{ | |
432 QDesktopServices::openUrl(QUrl("https://graph.anime.plus/")); | |
433 }); | |
434 menu->addSeparator(); | |
435 menu->addAction("AniChart", []{ | |
436 QDesktopServices::openUrl(QUrl("https://anichart.net/airing")); | |
437 }); | |
438 menu->addAction("Monthly.moe", []{ | |
439 QDesktopServices::openUrl(QUrl("https://www.monthly.moe/weekly")); | |
440 }); | |
441 menu->addAction("Senpai Anime Charts", []{ | |
442 QDesktopServices::openUrl(QUrl("https://www.senpai.moe/?mode=calendar")); | |
443 }); | |
444 menu->addSeparator(); | |
445 menu->addAction("Anime Streaming Search Engine", []{ | |
446 QDesktopServices::openUrl(QUrl("https://because.moe/")); | |
447 }); | |
448 menu->addAction("The Fansub Database", []{ | |
449 QDesktopServices::openUrl(QUrl("https://fansubdb.com")); | |
450 }); | |
403 | 451 |
404 button->setMenu(menu); | 452 button->setMenu(menu); |
405 } | 453 } |
406 | 454 |
407 button->setIcon(QIcon(":/icons/24x24/application-export.png")); | 455 button->setIcon(QIcon(":/icons/24x24/application-export.png")); |