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