Mercurial > minori
annotate src/main.cpp @ 6:1d82f6e04d7d
Update: add first parts to the settings dialog
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 16 Aug 2023 00:49:17 -0400 |
parents | 51ae25154b70 |
children | 07a9095eaeed |
rev | line source |
---|---|
2 | 1 #include "window.h" |
2 #include "config.h" | |
3 #include "anime.h" | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
4 #include "sidebar.h" |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
5 #include "ui_utils.h" |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
6 #include "settings.h" |
5 | 7 #if MACOSX |
2 | 8 #include "sys/osx/dark_theme.h" |
9 #elif WIN32 | |
10 #include "sys/win32/dark_theme.h" | |
11 #endif | |
12 | |
13 Session session = { | |
14 .config = Config() | |
15 }; | |
16 | |
17 /* note that this code was originally created for use in | |
18 wxWidgets, but I thought the API was a little meh, so | |
19 I switched to Qt. */ | |
20 | |
21 MainWindow::MainWindow(QWidget* parent) : | |
22 QMainWindow(parent) { | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
23 main_widget = new QWidget(parent); |
2 | 24 /* Menu Bar */ |
25 QAction* action; | |
26 QMenuBar* menubar = new QMenuBar(parent); | |
27 QMenu* menu = menubar->addMenu("&File"); | |
28 QMenu* submenu = menu->addMenu("&Library folders"); | |
29 action = new QAction("&Add new folder..."); | |
30 submenu->addAction(action); | |
31 action = new QAction("&Scan available episodes"); | |
32 menu->addAction(action); | |
33 | |
34 menu->addSeparator(); | |
35 | |
36 action = menu->addAction("Play &next episode"); | |
37 action = menu->addAction("Play &random episode"); | |
38 menu->addSeparator(); | |
39 action = menu->addAction("E&xit", qApp, &QApplication::quit); | |
40 | |
41 menu = menubar->addMenu("&Services"); | |
42 action = new QAction("Synchronize &list"); | |
43 | |
44 menu->addSeparator(); | |
45 | |
46 submenu = menu->addMenu("&AniList"); | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
47 action = submenu->addAction("Go to my &profile"); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
48 action = submenu->addAction("Go to my &stats"); |
2 | 49 |
50 submenu = menu->addMenu("&Kitsu"); | |
51 action = submenu->addAction("Go to my &feed"); | |
52 action = submenu->addAction("Go to my &library"); | |
53 action = submenu->addAction("Go to my &profile"); | |
54 | |
55 submenu = menu->addMenu("&MyAnimeList"); | |
56 action = submenu->addAction("Go to my p&anel"); | |
57 action = submenu->addAction("Go to my &profile"); | |
58 action = submenu->addAction("Go to my &history"); | |
59 | |
60 menu = menubar->addMenu("&Tools"); | |
61 submenu = menu->addMenu("&Export anime list"); | |
62 action = submenu->addAction("Export as &Markdown..."); | |
63 action = submenu->addAction("Export as MyAnimeList &XML..."); | |
64 | |
65 menu->addSeparator(); | |
66 | |
67 action = menu->addAction("Enable anime &recognition"); | |
68 action->setCheckable(true); | |
69 action = menu->addAction("Enable auto &sharing"); | |
70 action->setCheckable(true); | |
71 action = menu->addAction("Enable &auto synchronization"); | |
72 action->setCheckable(true); | |
73 | |
74 menu->addSeparator(); | |
75 | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
76 action = menu->addAction("&Settings", [this]{ |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
77 SettingsDialog dialog(this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
78 dialog.exec(); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
79 }); |
2 | 80 |
81 setMenuBar(menubar); | |
82 | |
83 /* Side toolbar */ | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
84 SideBar* sidebar = new SideBar(main_widget); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
85 sidebar->AddItem("Now Playing", UiUtils::CreateSideBarIcon(":/icons/16x16/film.png")); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
86 sidebar->AddSeparator(); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
87 sidebar->AddItem("Anime List", UiUtils::CreateSideBarIcon(":/icons/16x16/document-list.png")); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
88 sidebar->AddItem("History", UiUtils::CreateSideBarIcon(":/icons/16x16/clock-history-frame.png")); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
89 sidebar->AddItem("Statistics", UiUtils::CreateSideBarIcon(":/icons/16x16/chart.png")); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
90 sidebar->AddSeparator(); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
91 sidebar->AddItem("Search", UiUtils::CreateSideBarIcon(":/icons/16x16/magnifier.png")); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
92 sidebar->AddItem("Seasons", UiUtils::CreateSideBarIcon(":/icons/16x16/calendar.png")); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
93 sidebar->AddItem("Torrents", UiUtils::CreateSideBarIcon(":/icons/16x16/feed.png")); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
94 sidebar->setFixedWidth(128); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
95 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
96 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
97 anime_list_page = new AnimeListPage(parent); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
98 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
99 QHBoxLayout* layout = new QHBoxLayout(main_widget); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
100 layout->addWidget(sidebar, 0, Qt::AlignLeft | Qt::AlignTop); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
101 layout->addWidget(anime_list_page); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
102 SetActivePage(main_widget); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
103 /* |
2 | 104 QToolBar* toolbar = new QToolBar(parent); |
105 QActionGroup* tb_action_group = new QActionGroup(toolbar); | |
106 | |
107 action = toolbar->addAction("Now Playing"); | |
108 action->setActionGroup(tb_action_group); | |
109 action->setCheckable(true); | |
110 | |
111 toolbar->addSeparator(); | |
112 | |
113 action = toolbar->addAction("Anime List", [this]() { | |
114 setCentralWidget(anime_list_page); | |
115 }); | |
116 action->setActionGroup(tb_action_group); | |
117 action->setCheckable(true); | |
118 action->setChecked(true); | |
119 anime_list_page = new AnimeListPage(parent); | |
120 SetActivePage(anime_list_page); | |
121 action = toolbar->addAction("History"); | |
122 action->setActionGroup(tb_action_group); | |
123 action->setCheckable(true); | |
124 action = toolbar->addAction("Statistics"); | |
125 action->setActionGroup(tb_action_group); | |
126 action->setCheckable(true); | |
127 | |
128 toolbar->addSeparator(); | |
129 | |
130 action = toolbar->addAction("Search"); | |
131 action->setActionGroup(tb_action_group); | |
132 action->setCheckable(true); | |
133 action = toolbar->addAction("Seasons"); | |
134 action->setActionGroup(tb_action_group); | |
135 action->setCheckable(true); | |
136 action = toolbar->addAction("Torrents"); | |
137 action->setActionGroup(tb_action_group); | |
138 action->setCheckable(true); | |
139 | |
140 toolbar->setMovable(false); | |
141 toolbar->setFloatable(false); | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
142 toolbar->setMinimumSize(QSize(140, 0)); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
143 toolbar->setObjectName("sidebar"); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
144 toolbar->setStyleSheet("QToolBar#sidebar{margin: 6px;}"); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
145 //toolbar->setFrameShape(QFrame::NoFrame); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
146 toolbar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Maximum); |
2 | 147 |
148 addToolBar(Qt::LeftToolBarArea, toolbar); | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
149 */ |
2 | 150 ThemeChanged(); |
151 } | |
152 | |
153 void MainWindow::SetStyleSheet(enum Themes theme) { | |
154 switch (theme) { | |
155 case DARK: { | |
156 QFile f(":qdarkstyle/dark/darkstyle.qss"); | |
157 if (!f.exists()) | |
158 return; // fail | |
159 f.open(QFile::ReadOnly | QFile::Text); | |
160 QTextStream ts(&f); | |
161 setStyleSheet(ts.readAll()); | |
162 break; | |
163 } | |
164 default: | |
165 setStyleSheet(""); | |
166 break; | |
167 } | |
168 } | |
169 | |
170 void MainWindow::ThemeChanged() { | |
171 switch (session.config.theme) { | |
172 case LIGHT: { | |
5 | 173 #if MACOSX |
2 | 174 if (osx::DarkThemeAvailable()) |
175 osx::SetToLightTheme(); | |
176 else | |
177 SetStyleSheet(LIGHT); | |
178 #else | |
179 SetStyleSheet(LIGHT); | |
180 #endif | |
181 break; | |
182 } | |
183 case DARK: { | |
5 | 184 #if MACOSX |
2 | 185 if (osx::DarkThemeAvailable()) |
186 osx::SetToDarkTheme(); | |
187 else | |
188 SetStyleSheet(DARK); | |
189 #else | |
190 SetStyleSheet(DARK); | |
191 #endif | |
192 break; | |
193 } | |
194 case OS: { | |
5 | 195 #if MACOSX |
2 | 196 if (osx::DarkThemeAvailable()) |
197 osx::SetToAutoTheme(); | |
198 else | |
199 SetStyleSheet(LIGHT); | |
200 #elif defined(WIN32) | |
201 if (win32::DarkThemeAvailable()) { | |
202 if (win32::IsInDarkTheme()) { | |
203 SetStyleSheet(DARK); | |
204 } else { | |
205 SetStyleSheet(LIGHT); | |
206 } | |
207 } | |
208 #else | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
209 /* Currently OS detection only supports Windows and macOS. |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
210 Please don't be shy if you're willing to port it to other OSes |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
211 (or desktop environments, or window managers) */ |
2 | 212 SetStyleSheet(LIGHT); |
213 #endif | |
214 break; | |
215 } | |
216 } | |
217 } | |
218 | |
219 void MainWindow::SetActivePage(QWidget* page) { | |
220 this->setCentralWidget(page); | |
221 } | |
222 | |
223 void MainWindow::closeEvent(QCloseEvent* event) { | |
224 session.config.Save(); | |
225 event->accept(); | |
226 } | |
227 | |
228 int main(int argc, char** argv) { | |
229 QApplication app(argc, argv); | |
230 | |
231 session.config.Load(); | |
232 | |
233 MainWindow window; | |
234 | |
235 window.resize(941, 750); | |
236 window.setWindowTitle("Weeaboo"); | |
237 window.show(); | |
238 | |
239 return app.exec(); | |
240 } |