Mercurial > minori
annotate src/gui/window.cpp @ 58:b7a1c0010ffd
sidebar: link view menu and sidebar together
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 28 Sep 2023 13:32:21 -0400 |
parents | 466ac9870df9 |
children | 4c6dd5999b39 |
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" | |
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
10 #include "gui/pages/seasons.h" |
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
11 #include "gui/pages/search.h" |
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
12 #include "gui/pages/torrents.h" |
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
13 #include "gui/pages/history.h" |
46 | 14 #include "gui/widgets/sidebar.h" |
15 | 15 #include "services/services.h" |
7 | 16 #include <QApplication> |
9 | 17 #include <QFile> |
7 | 18 #include <QMainWindow> |
19 #include <QMenuBar> | |
20 #include <QPlainTextEdit> | |
21 #include <QStackedWidget> | |
22 #include <QTextStream> | |
5 | 23 #if MACOSX |
15 | 24 # include "sys/osx/dark_theme.h" |
46 | 25 #elif defined(WIN32) |
15 | 26 # include "sys/win32/dark_theme.h" |
2 | 27 #endif |
28 | |
10 | 29 enum class Pages { |
30 NOW_PLAYING, | |
31 | |
32 ANIME_LIST, | |
33 HISTORY, | |
34 STATISTICS, | |
35 | |
36 SEARCH, | |
37 SEASONS, | |
38 TORRENTS | |
39 }; | |
40 | |
9 | 41 MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
42 main_widget = new QWidget(parent); |
10 | 43 |
44 SideBar* sidebar = new SideBar(main_widget); | |
51 | 45 sidebar->AddItem(tr("Now Playing"), SideBar::CreateIcon(":/icons/16x16/film.png")); |
10 | 46 sidebar->AddSeparator(); |
51 | 47 sidebar->AddItem(tr("Anime List"), SideBar::CreateIcon(":/icons/16x16/document-list.png")); |
48 sidebar->AddItem(tr("History"), SideBar::CreateIcon(":/icons/16x16/clock-history-frame.png")); | |
49 sidebar->AddItem(tr("Statistics"), SideBar::CreateIcon(":/icons/16x16/chart.png")); | |
10 | 50 sidebar->AddSeparator(); |
51 | 51 sidebar->AddItem(tr("Search"), SideBar::CreateIcon(":/icons/16x16/magnifier.png")); |
52 sidebar->AddItem(tr("Seasons"), SideBar::CreateIcon(":/icons/16x16/calendar.png")); | |
53 sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/16x16/feed.png")); | |
10 | 54 sidebar->setFixedWidth(128); |
36 | 55 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
10 | 56 |
57 QStackedWidget* stack = new QStackedWidget(main_widget); | |
58 stack->addWidget(new NowPlayingWidget(main_widget)); | |
59 stack->addWidget(new AnimeListWidget(main_widget)); | |
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
60 stack->addWidget(new HistoryWidget(main_widget)); |
10 | 61 stack->addWidget(new StatisticsWidget(main_widget)); |
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
62 stack->addWidget(new SearchWidget(main_widget)); |
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
63 stack->addWidget(new SeasonsWidget(main_widget)); |
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
64 stack->addWidget(new TorrentsWidget(main_widget)); |
10 | 65 |
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
66 connect(sidebar, &SideBar::CurrentItemChanged, stack, &QStackedWidget::setCurrentIndex); |
58
b7a1c0010ffd
sidebar: link view menu and sidebar together
Paper <mrpapersonic@gmail.com>
parents:
54
diff
changeset
|
67 sidebar->SetCurrentItem((int)Pages::ANIME_LIST); |
10 | 68 |
2 | 69 /* Menu Bar */ |
70 QAction* action; | |
71 QMenuBar* menubar = new QMenuBar(parent); | |
51 | 72 QMenu* menu = menubar->addMenu(tr("&File")); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
73 |
51 | 74 QMenu* submenu = menu->addMenu(tr("&Library folders")); |
75 action = submenu->addAction(tr("&Add new folder...")); | |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
76 |
51 | 77 action = menu->addAction(tr("&Scan available episodes")); |
2 | 78 |
79 menu->addSeparator(); | |
80 | |
51 | 81 action = menu->addAction(tr("Play &next episode")); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
82 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N)); |
51 | 83 action = menu->addAction(tr("Play &random episode")); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
84 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R)); |
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
85 |
2 | 86 menu->addSeparator(); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
87 |
51 | 88 action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit); |
2 | 89 |
51 | 90 menu = menubar->addMenu(tr("&Services")); |
91 action = menu->addAction(tr("Synchronize &list"), [this, stack] { | |
10 | 92 Services::Synchronize(); |
15 | 93 ((AnimeListWidget*)stack->widget((int)Pages::ANIME_LIST))->Refresh(); |
10 | 94 }); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
95 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); |
2 | 96 |
97 menu->addSeparator(); | |
98 | |
51 | 99 submenu = menu->addMenu(tr("&AniList")); |
100 action = submenu->addAction(tr("Go to my &profile")); | |
101 action = submenu->addAction(tr("Go to my &stats")); | |
2 | 102 |
51 | 103 submenu = menu->addMenu(tr("&Kitsu")); |
104 action = submenu->addAction(tr("Go to my &feed")); | |
105 action = submenu->addAction(tr("Go to my &library")); | |
106 action = submenu->addAction(tr("Go to my &profile")); | |
2 | 107 |
51 | 108 submenu = menu->addMenu(tr("&MyAnimeList")); |
109 action = submenu->addAction(tr("Go to my p&anel")); | |
110 action = submenu->addAction(tr("Go to my &profile")); | |
111 action = submenu->addAction(tr("Go to my &history")); | |
2 | 112 |
51 | 113 menu = menubar->addMenu(tr("&Tools")); |
114 submenu = menu->addMenu(tr("&Export anime list")); | |
115 action = submenu->addAction(tr("Export as &Markdown...")); | |
116 action = submenu->addAction(tr("Export as MyAnimeList &XML...")); | |
2 | 117 |
118 menu->addSeparator(); | |
119 | |
51 | 120 action = menu->addAction(tr("Enable anime &recognition")); |
2 | 121 action->setCheckable(true); |
51 | 122 action = menu->addAction(tr("Enable auto &sharing")); |
2 | 123 action->setCheckable(true); |
51 | 124 action = menu->addAction(tr("Enable &auto synchronization")); |
2 | 125 action->setCheckable(true); |
126 | |
127 menu->addSeparator(); | |
128 | |
51 | 129 action = menu->addAction(tr("&Settings"), [this] { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
130 SettingsDialog dialog(this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
131 dialog.exec(); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
132 }); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
133 action->setMenuRole(QAction::PreferencesRole); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
134 |
51 | 135 menu = menubar->addMenu(tr("&View")); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
136 |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
137 std::map<QAction*, int> page_to_index_map = {}; |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
138 |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
139 QActionGroup* pages_group = new QActionGroup(this); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
140 pages_group->setExclusive(true); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
141 |
51 | 142 action = pages_group->addAction(menu->addAction(tr("&Now Playing"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
143 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
144 page_to_index_map[action] = 0; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
145 |
51 | 146 action = pages_group->addAction(menu->addAction(tr("&Anime List"))); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
147 page_to_index_map[action] = 1; |
48
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); |
58
b7a1c0010ffd
sidebar: link view menu and sidebar together
Paper <mrpapersonic@gmail.com>
parents:
54
diff
changeset
|
150 |
51 | 151 action = pages_group->addAction(menu->addAction(tr("&History"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
152 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
153 page_to_index_map[action] = 2; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
154 |
51 | 155 action = pages_group->addAction(menu->addAction(tr("&Statistics"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
156 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
157 page_to_index_map[action] = 3; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
158 |
51 | 159 action = pages_group->addAction(menu->addAction(tr("S&earch"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
160 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
161 page_to_index_map[action] = 4; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
162 |
51 | 163 action = pages_group->addAction(menu->addAction(tr("Se&asons"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
164 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
165 page_to_index_map[action] = 5; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
166 |
51 | 167 action = pages_group->addAction(menu->addAction(tr("&Torrents"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
168 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
169 page_to_index_map[action] = 6; |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
170 |
58
b7a1c0010ffd
sidebar: link view menu and sidebar together
Paper <mrpapersonic@gmail.com>
parents:
54
diff
changeset
|
171 connect(sidebar, &SideBar::CurrentItemChanged, this, [pages_group](int index){ |
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
172 pages_group->actions()[index]->setChecked(true); |
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
173 }); |
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
174 |
58
b7a1c0010ffd
sidebar: link view menu and sidebar together
Paper <mrpapersonic@gmail.com>
parents:
54
diff
changeset
|
175 connect(pages_group, &QActionGroup::triggered, this, [page_to_index_map, sidebar](QAction* action) { |
b7a1c0010ffd
sidebar: link view menu and sidebar together
Paper <mrpapersonic@gmail.com>
parents:
54
diff
changeset
|
176 sidebar->SetCurrentItem(page_to_index_map.at(action)); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
177 }); |
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
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" |