Mercurial > minori
annotate src/gui/window.cpp @ 51:75c804f713b2
window: add about window,
*: use tr() when applicable (useful for i18n)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 25 Sep 2023 20:29:26 -0400 |
parents | e613772f41d5 |
children | 466ac9870df9 |
rev | line source |
---|---|
9 | 1 #include "gui/window.h" |
2 #include "core/config.h" | |
3 #include "core/session.h" | |
46 | 4 #include "gui/dark_theme.h" |
9 | 5 #include "gui/dialog/settings.h" |
51 | 6 #include "gui/dialog/about.h" |
9 | 7 #include "gui/pages/anime_list.h" |
8 #include "gui/pages/now_playing.h" | |
9 #include "gui/pages/statistics.h" | |
46 | 10 #include "gui/widgets/sidebar.h" |
15 | 11 #include "services/services.h" |
7 | 12 #include <QApplication> |
9 | 13 #include <QFile> |
7 | 14 #include <QMainWindow> |
15 #include <QMenuBar> | |
16 #include <QPlainTextEdit> | |
17 #include <QStackedWidget> | |
18 #include <QTextStream> | |
5 | 19 #if MACOSX |
15 | 20 # include "sys/osx/dark_theme.h" |
46 | 21 #elif defined(WIN32) |
15 | 22 # include "sys/win32/dark_theme.h" |
2 | 23 #endif |
24 | |
10 | 25 enum class Pages { |
26 NOW_PLAYING, | |
27 | |
28 ANIME_LIST, | |
29 HISTORY, | |
30 STATISTICS, | |
31 | |
32 SEARCH, | |
33 SEASONS, | |
34 TORRENTS | |
35 }; | |
36 | |
9 | 37 MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
38 main_widget = new QWidget(parent); |
10 | 39 |
40 SideBar* sidebar = new SideBar(main_widget); | |
51 | 41 sidebar->AddItem(tr("Now Playing"), SideBar::CreateIcon(":/icons/16x16/film.png")); |
10 | 42 sidebar->AddSeparator(); |
51 | 43 sidebar->AddItem(tr("Anime List"), SideBar::CreateIcon(":/icons/16x16/document-list.png")); |
44 sidebar->AddItem(tr("History"), SideBar::CreateIcon(":/icons/16x16/clock-history-frame.png")); | |
45 sidebar->AddItem(tr("Statistics"), SideBar::CreateIcon(":/icons/16x16/chart.png")); | |
10 | 46 sidebar->AddSeparator(); |
51 | 47 sidebar->AddItem(tr("Search"), SideBar::CreateIcon(":/icons/16x16/magnifier.png")); |
48 sidebar->AddItem(tr("Seasons"), SideBar::CreateIcon(":/icons/16x16/calendar.png")); | |
49 sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/16x16/feed.png")); | |
10 | 50 sidebar->setFixedWidth(128); |
36 | 51 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
10 | 52 |
53 QStackedWidget* stack = new QStackedWidget(main_widget); | |
54 stack->addWidget(new NowPlayingWidget(main_widget)); | |
55 stack->addWidget(new AnimeListWidget(main_widget)); | |
56 stack->addWidget(new StatisticsWidget(main_widget)); | |
57 | |
58 connect(sidebar, &SideBar::CurrentItemChanged, stack, [stack](int index) { | |
59 switch (index) { | |
60 case 0: | |
61 case 1: stack->setCurrentIndex(index); break; | |
62 case 3: stack->setCurrentIndex(2); break; | |
63 default: break; | |
64 } | |
65 }); | |
66 sidebar->setCurrentRow(2); | |
67 | |
2 | 68 /* Menu Bar */ |
69 QAction* action; | |
70 QMenuBar* menubar = new QMenuBar(parent); | |
51 | 71 QMenu* menu = menubar->addMenu(tr("&File")); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
72 |
51 | 73 QMenu* submenu = menu->addMenu(tr("&Library folders")); |
74 action = submenu->addAction(tr("&Add new folder...")); | |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
75 |
51 | 76 action = menu->addAction(tr("&Scan available episodes")); |
2 | 77 |
78 menu->addSeparator(); | |
79 | |
51 | 80 action = menu->addAction(tr("Play &next episode")); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
81 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N)); |
51 | 82 action = menu->addAction(tr("Play &random episode")); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
83 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R)); |
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
84 |
2 | 85 menu->addSeparator(); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
86 |
51 | 87 action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit); |
2 | 88 |
51 | 89 menu = menubar->addMenu(tr("&Services")); |
90 action = menu->addAction(tr("Synchronize &list"), [this, stack] { | |
10 | 91 Services::Synchronize(); |
15 | 92 ((AnimeListWidget*)stack->widget((int)Pages::ANIME_LIST))->Refresh(); |
10 | 93 }); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
94 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); |
2 | 95 |
96 menu->addSeparator(); | |
97 | |
51 | 98 submenu = menu->addMenu(tr("&AniList")); |
99 action = submenu->addAction(tr("Go to my &profile")); | |
100 action = submenu->addAction(tr("Go to my &stats")); | |
2 | 101 |
51 | 102 submenu = menu->addMenu(tr("&Kitsu")); |
103 action = submenu->addAction(tr("Go to my &feed")); | |
104 action = submenu->addAction(tr("Go to my &library")); | |
105 action = submenu->addAction(tr("Go to my &profile")); | |
2 | 106 |
51 | 107 submenu = menu->addMenu(tr("&MyAnimeList")); |
108 action = submenu->addAction(tr("Go to my p&anel")); | |
109 action = submenu->addAction(tr("Go to my &profile")); | |
110 action = submenu->addAction(tr("Go to my &history")); | |
2 | 111 |
51 | 112 menu = menubar->addMenu(tr("&Tools")); |
113 submenu = menu->addMenu(tr("&Export anime list")); | |
114 action = submenu->addAction(tr("Export as &Markdown...")); | |
115 action = submenu->addAction(tr("Export as MyAnimeList &XML...")); | |
2 | 116 |
117 menu->addSeparator(); | |
118 | |
51 | 119 action = menu->addAction(tr("Enable anime &recognition")); |
2 | 120 action->setCheckable(true); |
51 | 121 action = menu->addAction(tr("Enable auto &sharing")); |
2 | 122 action->setCheckable(true); |
51 | 123 action = menu->addAction(tr("Enable &auto synchronization")); |
2 | 124 action->setCheckable(true); |
125 | |
126 menu->addSeparator(); | |
127 | |
51 | 128 action = menu->addAction(tr("&Settings"), [this] { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
129 SettingsDialog dialog(this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
130 dialog.exec(); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
131 }); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
132 action->setMenuRole(QAction::PreferencesRole); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
133 |
51 | 134 menu = menubar->addMenu(tr("&View")); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
135 |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
136 std::map<QAction*, int> page_to_index_map = {}; |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
137 |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
138 QActionGroup* pages_group = new QActionGroup(this); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
139 pages_group->setExclusive(true); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
140 |
51 | 141 action = pages_group->addAction(menu->addAction(tr("&Now Playing"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
142 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
143 page_to_index_map[action] = 0; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
144 |
51 | 145 action = pages_group->addAction(menu->addAction(tr("&Anime List"))); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
146 page_to_index_map[action] = 1; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
147 |
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
148 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
149 action->setChecked(true); |
51 | 150 action = pages_group->addAction(menu->addAction(tr("&History"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
151 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
152 page_to_index_map[action] = 2; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
153 |
51 | 154 action = pages_group->addAction(menu->addAction(tr("&Statistics"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
155 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
156 page_to_index_map[action] = 3; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
157 |
51 | 158 action = pages_group->addAction(menu->addAction(tr("S&earch"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
159 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
160 page_to_index_map[action] = 4; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
161 |
51 | 162 action = pages_group->addAction(menu->addAction(tr("Se&asons"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
163 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
164 page_to_index_map[action] = 5; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
165 |
51 | 166 action = pages_group->addAction(menu->addAction(tr("&Torrents"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
167 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
168 page_to_index_map[action] = 6; |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
169 |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
170 connect(pages_group, &QActionGroup::triggered, this, [page_to_index_map, stack](QAction* action) { |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
171 int index = page_to_index_map.at(action); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
172 switch (index) { |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
173 case 0: |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
174 case 1: stack->setCurrentIndex(index); break; |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
175 case 3: stack->setCurrentIndex(2); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
176 default: break; |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
177 } |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
178 }); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
179 menu->addSeparator(); |
51 | 180 menu->addAction(tr("Show sidebar")); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
181 |
51 | 182 menu = menubar->addMenu(tr("&Help")); |
183 action = menu->addAction(tr("About Minori"), this, [this] { | |
184 AboutWindow dialog(this); | |
185 dialog.exec(); | |
186 }); | |
187 action = menu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); | |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
188 action->setMenuRole(QAction::AboutQtRole); |
2 | 189 |
190 setMenuBar(menubar); | |
7 | 191 |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
192 QHBoxLayout* layout = new QHBoxLayout(main_widget); |
37
9ae9365dd4ea
window.cpp: fix sidebar on Linux
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
193 layout->addWidget(sidebar); |
7 | 194 layout->addWidget(stack); |
195 setCentralWidget(main_widget); | |
2 | 196 |
46 | 197 DarkTheme::SetTheme(session.config.theme); |
2 | 198 } |
199 | |
200 void MainWindow::SetActivePage(QWidget* page) { | |
201 this->setCentralWidget(page); | |
202 } | |
203 | |
204 void MainWindow::closeEvent(QCloseEvent* event) { | |
205 session.config.Save(); | |
206 event->accept(); | |
207 } | |
208 | |
9 | 209 #include "gui/moc_window.cpp" |