comparison src/gui/window.cpp @ 46:d0adc4aedfc8

*: update... this commit: 1. consolidates dark theme stuff to dark_theme.cpp 2. creates a new widgets folder to store all of our custom widgets 3. creates the list settings page in the information dialog, although much of it is nonfunctional: it doesn't save, and the status doesn't even get filled in... we'll fix this later!
author Paper <mrpapersonic@gmail.com>
date Sat, 23 Sep 2023 01:02:15 -0400
parents 619cbd6e69f9
children e613772f41d5
comparison
equal deleted inserted replaced
45:4b05bc7668eb 46:d0adc4aedfc8
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/dialog/settings.h" 5 #include "gui/dialog/settings.h"
5 #include "gui/pages/anime_list.h" 6 #include "gui/pages/anime_list.h"
6 #include "gui/pages/now_playing.h" 7 #include "gui/pages/now_playing.h"
7 #include "gui/pages/statistics.h" 8 #include "gui/pages/statistics.h"
8 #include "gui/sidebar.h" 9 #include "gui/widgets/sidebar.h"
9 #include "gui/ui_utils.h"
10 #include "services/services.h" 10 #include "services/services.h"
11 #include <QApplication> 11 #include <QApplication>
12 #include <QFile> 12 #include <QFile>
13 #include <QMainWindow> 13 #include <QMainWindow>
14 #include <QMenuBar> 14 #include <QMenuBar>
15 #include <QPlainTextEdit> 15 #include <QPlainTextEdit>
16 #include <QStackedWidget> 16 #include <QStackedWidget>
17 #include <QTextStream> 17 #include <QTextStream>
18 #if MACOSX 18 #if MACOSX
19 # include "sys/osx/dark_theme.h" 19 # include "sys/osx/dark_theme.h"
20 #elif WIN32 20 #elif defined(WIN32)
21 # include "sys/win32/dark_theme.h" 21 # include "sys/win32/dark_theme.h"
22 #endif 22 #endif
23 23
24 enum class Pages { 24 enum class Pages {
25 NOW_PLAYING, 25 NOW_PLAYING,
155 default: break; 155 default: break;
156 } 156 }
157 }); 157 });
158 158
159 menu = menubar->addMenu("&Help"); 159 menu = menubar->addMenu("&Help");
160 action = menu->addAction("About &Qt", qApp, [this]{ 160 action = menu->addAction("About &Qt", qApp, [this] { qApp->aboutQt(); });
161 qApp->aboutQt();
162 });
163 action->setMenuRole(QAction::AboutQtRole); 161 action->setMenuRole(QAction::AboutQtRole);
164 162
165 setMenuBar(menubar); 163 setMenuBar(menubar);
166 164
167 QHBoxLayout* layout = new QHBoxLayout(main_widget); 165 QHBoxLayout* layout = new QHBoxLayout(main_widget);
168 layout->addWidget(sidebar); 166 layout->addWidget(sidebar);
169 layout->addWidget(stack); 167 layout->addWidget(stack);
170 setCentralWidget(main_widget); 168 setCentralWidget(main_widget);
171 169
172 ThemeChanged(); 170 DarkTheme::SetTheme(session.config.theme);
173 }
174
175 void MainWindow::SetStyleSheet(enum Themes theme) {
176 switch (theme) {
177 case Themes::DARK: {
178 QFile f(":qdarkstyle/dark/darkstyle.qss");
179 if (!f.exists())
180 return; // fail
181 f.open(QFile::ReadOnly | QFile::Text);
182 QTextStream ts(&f);
183 setStyleSheet(ts.readAll());
184 break;
185 }
186 default: setStyleSheet(""); break;
187 }
188 }
189
190 void MainWindow::ThemeChanged() {
191 switch (session.config.theme) {
192 case Themes::LIGHT: {
193 #if MACOSX
194 if (osx::DarkThemeAvailable())
195 osx::SetToLightTheme();
196 else
197 #else
198 SetStyleSheet(Themes::LIGHT);
199 #endif
200 break;
201 }
202 case Themes::DARK: {
203 #if MACOSX
204 if (osx::DarkThemeAvailable())
205 osx::SetToDarkTheme();
206 else
207 #else
208 SetStyleSheet(Themes::DARK);
209 #endif
210 break;
211 }
212 case Themes::OS: {
213 #if MACOSX
214 if (osx::DarkThemeAvailable())
215 osx::SetToAutoTheme();
216 else
217 #elif defined(WIN32)
218 if (win32::DarkThemeAvailable()) {
219 if (win32::IsInDarkTheme()) {
220 SetStyleSheet(Themes::DARK);
221 } else {
222 SetStyleSheet(Themes::LIGHT);
223 }
224 } else
225 #endif
226 /* Currently OS detection only supports Windows and macOS.
227 Please don't be shy if you're willing to port it to other OSes
228 (or desktop environments, or window managers) */
229 SetStyleSheet(Themes::LIGHT);
230 break;
231 }
232 }
233 } 171 }
234 172
235 void MainWindow::SetActivePage(QWidget* page) { 173 void MainWindow::SetActivePage(QWidget* page) {
236 this->setCentralWidget(page); 174 this->setCentralWidget(page);
237 } 175 }