Mercurial > minori
annotate src/gui/window.cpp @ 9:5c0397762b53
INCOMPLETE: megacommit :)
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Sun, 10 Sep 2023 03:59:16 -0400 |
| parents | src/main.cpp@b1f73678ef61 |
| children | 4b198a111713 |
| rev | line source |
|---|---|
| 9 | 1 #include "gui/window.h" |
| 2 #include "core/config.h" | |
| 3 #include "core/session.h" | |
| 4 #include "gui/dialog/settings.h" | |
| 5 #include "gui/pages/anime_list.h" | |
| 6 #include "gui/pages/now_playing.h" | |
| 7 #include "gui/pages/statistics.h" | |
| 8 #include "gui/sidebar.h" | |
| 9 #include "gui/ui_utils.h" | |
| 7 | 10 #include <QApplication> |
| 9 | 11 #include <QFile> |
| 7 | 12 #include <QMainWindow> |
| 13 #include <QMenuBar> | |
| 14 #include <QPlainTextEdit> | |
| 15 #include <QStackedWidget> | |
| 16 #include <QTextStream> | |
| 5 | 17 #if MACOSX |
| 2 | 18 #include "sys/osx/dark_theme.h" |
| 19 #elif WIN32 | |
| 20 #include "sys/win32/dark_theme.h" | |
| 21 #endif | |
| 22 | |
| 9 | 23 /* note that this code was originally created for use in |
| 2 | 24 wxWidgets, but I thought the API was a little meh, so |
| 25 I switched to Qt. */ | |
| 26 | |
| 9 | 27 MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { |
|
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
28 main_widget = new QWidget(parent); |
| 2 | 29 /* Menu Bar */ |
| 30 QAction* action; | |
| 31 QMenuBar* menubar = new QMenuBar(parent); | |
| 32 QMenu* menu = menubar->addMenu("&File"); | |
| 33 QMenu* submenu = menu->addMenu("&Library folders"); | |
| 34 action = new QAction("&Add new folder..."); | |
| 35 submenu->addAction(action); | |
| 36 action = new QAction("&Scan available episodes"); | |
| 37 menu->addAction(action); | |
| 38 | |
| 39 menu->addSeparator(); | |
| 40 | |
| 41 action = menu->addAction("Play &next episode"); | |
| 42 action = menu->addAction("Play &random episode"); | |
| 43 menu->addSeparator(); | |
| 44 action = menu->addAction("E&xit", qApp, &QApplication::quit); | |
| 45 | |
| 46 menu = menubar->addMenu("&Services"); | |
| 47 action = new QAction("Synchronize &list"); | |
| 48 | |
| 49 menu->addSeparator(); | |
| 50 | |
| 51 submenu = menu->addMenu("&AniList"); | |
|
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
52 action = submenu->addAction("Go to my &profile"); |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
53 action = submenu->addAction("Go to my &stats"); |
| 2 | 54 |
| 55 submenu = menu->addMenu("&Kitsu"); | |
| 56 action = submenu->addAction("Go to my &feed"); | |
| 57 action = submenu->addAction("Go to my &library"); | |
| 58 action = submenu->addAction("Go to my &profile"); | |
| 59 | |
| 60 submenu = menu->addMenu("&MyAnimeList"); | |
| 61 action = submenu->addAction("Go to my p&anel"); | |
| 62 action = submenu->addAction("Go to my &profile"); | |
| 63 action = submenu->addAction("Go to my &history"); | |
| 64 | |
| 65 menu = menubar->addMenu("&Tools"); | |
| 66 submenu = menu->addMenu("&Export anime list"); | |
| 67 action = submenu->addAction("Export as &Markdown..."); | |
| 68 action = submenu->addAction("Export as MyAnimeList &XML..."); | |
| 69 | |
| 70 menu->addSeparator(); | |
| 71 | |
| 72 action = menu->addAction("Enable anime &recognition"); | |
| 73 action->setCheckable(true); | |
| 74 action = menu->addAction("Enable auto &sharing"); | |
| 75 action->setCheckable(true); | |
| 76 action = menu->addAction("Enable &auto synchronization"); | |
| 77 action->setCheckable(true); | |
| 78 | |
| 79 menu->addSeparator(); | |
| 80 | |
| 9 | 81 action = menu->addAction("&Settings", [this] { |
|
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
82 SettingsDialog dialog(this); |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
83 dialog.exec(); |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
84 }); |
| 2 | 85 |
| 86 setMenuBar(menubar); | |
| 7 | 87 |
|
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
88 SideBar* sidebar = new SideBar(main_widget); |
| 9 | 89 sidebar->AddItem("Now Playing", SideBar::CreateIcon(":/icons/16x16/film.png")); |
|
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
90 sidebar->AddSeparator(); |
| 9 | 91 sidebar->AddItem("Anime List", SideBar::CreateIcon(":/icons/16x16/document-list.png")); |
| 92 sidebar->AddItem("History", SideBar::CreateIcon(":/icons/16x16/clock-history-frame.png")); | |
| 93 sidebar->AddItem("Statistics", SideBar::CreateIcon(":/icons/16x16/chart.png")); | |
|
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
94 sidebar->AddSeparator(); |
| 9 | 95 sidebar->AddItem("Search", SideBar::CreateIcon(":/icons/16x16/magnifier.png")); |
| 96 sidebar->AddItem("Seasons", SideBar::CreateIcon(":/icons/16x16/calendar.png")); | |
| 97 sidebar->AddItem("Torrents", SideBar::CreateIcon(":/icons/16x16/feed.png")); | |
|
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
98 sidebar->setFixedWidth(128); |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
99 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
100 |
| 7 | 101 QStackedWidget* stack = new QStackedWidget(main_widget); |
| 102 stack->addWidget(new NowPlayingWidget(parent)); | |
| 9 | 103 stack->addWidget(new AnimeListWidget(parent)); |
| 104 stack->addWidget(new StatisticsWidget(parent)); | |
| 7 | 105 |
| 9 | 106 connect(sidebar, &SideBar::CurrentItemChanged, stack, [stack](int index) { |
| 7 | 107 switch (index) { |
| 108 case 0: | |
| 9 | 109 case 1: stack->setCurrentIndex(index); break; |
| 110 case 3: stack->setCurrentIndex(2); break; | |
| 111 default: break; | |
| 7 | 112 } |
| 113 }); | |
| 114 sidebar->setCurrentRow(2); | |
|
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
115 |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
116 QHBoxLayout* layout = new QHBoxLayout(main_widget); |
|
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
117 layout->addWidget(sidebar, 0, Qt::AlignLeft | Qt::AlignTop); |
| 7 | 118 layout->addWidget(stack); |
| 119 setCentralWidget(main_widget); | |
| 2 | 120 |
| 121 ThemeChanged(); | |
| 122 } | |
| 123 | |
| 124 void MainWindow::SetStyleSheet(enum Themes theme) { | |
| 125 switch (theme) { | |
| 9 | 126 case Themes::DARK: { |
| 2 | 127 QFile f(":qdarkstyle/dark/darkstyle.qss"); |
| 128 if (!f.exists()) | |
| 129 return; // fail | |
| 130 f.open(QFile::ReadOnly | QFile::Text); | |
| 131 QTextStream ts(&f); | |
| 132 setStyleSheet(ts.readAll()); | |
| 133 break; | |
| 134 } | |
| 9 | 135 default: setStyleSheet(""); break; |
| 2 | 136 } |
| 137 } | |
| 138 | |
| 139 void MainWindow::ThemeChanged() { | |
| 140 switch (session.config.theme) { | |
| 9 | 141 case Themes::LIGHT: { |
| 5 | 142 #if MACOSX |
| 2 | 143 if (osx::DarkThemeAvailable()) |
| 144 osx::SetToLightTheme(); | |
| 145 else | |
| 146 #else | |
| 9 | 147 SetStyleSheet(Themes::LIGHT); |
| 2 | 148 #endif |
| 9 | 149 break; |
| 2 | 150 } |
| 9 | 151 case Themes::DARK: { |
| 5 | 152 #if MACOSX |
| 2 | 153 if (osx::DarkThemeAvailable()) |
| 154 osx::SetToDarkTheme(); | |
| 155 else | |
| 156 #else | |
| 9 | 157 SetStyleSheet(Themes::DARK); |
| 2 | 158 #endif |
| 9 | 159 break; |
| 2 | 160 } |
| 9 | 161 case Themes::OS: { |
| 5 | 162 #if MACOSX |
| 2 | 163 if (osx::DarkThemeAvailable()) |
| 164 osx::SetToAutoTheme(); | |
| 165 else | |
| 166 #elif defined(WIN32) | |
| 167 if (win32::DarkThemeAvailable()) { | |
| 168 if (win32::IsInDarkTheme()) { | |
| 9 | 169 SetStyleSheet(Themes::DARK); |
| 2 | 170 } else { |
| 9 | 171 SetStyleSheet(Themes::LIGHT); |
| 2 | 172 } |
| 9 | 173 } else |
| 2 | 174 #endif |
| 9 | 175 /* Currently OS detection only supports Windows and macOS. |
| 176 Please don't be shy if you're willing to port it to other OSes | |
| 177 (or desktop environments, or window managers) */ | |
| 178 SetStyleSheet(Themes::LIGHT); | |
| 2 | 179 break; |
| 180 } | |
| 181 } | |
| 182 } | |
| 183 | |
| 184 void MainWindow::SetActivePage(QWidget* page) { | |
| 185 this->setCentralWidget(page); | |
| 186 } | |
| 187 | |
| 188 void MainWindow::closeEvent(QCloseEvent* event) { | |
| 189 session.config.Save(); | |
| 190 event->accept(); | |
| 191 } | |
| 192 | |
| 9 | 193 #include "gui/moc_window.cpp" |
