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