comparison src/main.cpp @ 7:07a9095eaeed

Update Refactored some code, moved some around
author Paper <mrpapersonic@gmail.com>
date Thu, 24 Aug 2023 23:11:38 -0400
parents 1d82f6e04d7d
children b1f73678ef61
comparison
equal deleted inserted replaced
6:1d82f6e04d7d 7:07a9095eaeed
1 #include <QApplication>
2 #include <QMainWindow>
3 #include <QMenuBar>
4 #include <QPlainTextEdit>
5 #include <QStackedWidget>
6 #include <QFile>
7 #include <QTextStream>
8 #include <QMessageBox>
1 #include "window.h" 9 #include "window.h"
2 #include "config.h" 10 #include "config.h"
3 #include "anime.h" 11 #include "anime_list.h"
12 #include "now_playing.h"
13 #include "statistics.h"
4 #include "sidebar.h" 14 #include "sidebar.h"
5 #include "ui_utils.h" 15 #include "ui_utils.h"
6 #include "settings.h" 16 #include "settings.h"
17 #include "session.h"
7 #if MACOSX 18 #if MACOSX
8 #include "sys/osx/dark_theme.h" 19 #include "sys/osx/dark_theme.h"
9 #elif WIN32 20 #elif WIN32
10 #include "sys/win32/dark_theme.h" 21 #include "sys/win32/dark_theme.h"
11 #endif 22 #endif
12 23
13 Session session = { 24 Session session;
14 .config = Config()
15 };
16 25
17 /* note that this code was originally created for use in 26 /* note that this code was originally created for use in
18 wxWidgets, but I thought the API was a little meh, so 27 wxWidgets, but I thought the API was a little meh, so
19 I switched to Qt. */ 28 I switched to Qt. */
20 29
77 SettingsDialog dialog(this); 86 SettingsDialog dialog(this);
78 dialog.exec(); 87 dialog.exec();
79 }); 88 });
80 89
81 setMenuBar(menubar); 90 setMenuBar(menubar);
82 91
83 /* Side toolbar */
84 SideBar* sidebar = new SideBar(main_widget); 92 SideBar* sidebar = new SideBar(main_widget);
85 sidebar->AddItem("Now Playing", UiUtils::CreateSideBarIcon(":/icons/16x16/film.png")); 93 sidebar->AddItem("Now Playing", UiUtils::CreateSideBarIcon(":/icons/16x16/film.png"));
86 sidebar->AddSeparator(); 94 sidebar->AddSeparator();
87 sidebar->AddItem("Anime List", UiUtils::CreateSideBarIcon(":/icons/16x16/document-list.png")); 95 sidebar->AddItem("Anime List", UiUtils::CreateSideBarIcon(":/icons/16x16/document-list.png"));
88 sidebar->AddItem("History", UiUtils::CreateSideBarIcon(":/icons/16x16/clock-history-frame.png")); 96 sidebar->AddItem("History", UiUtils::CreateSideBarIcon(":/icons/16x16/clock-history-frame.png"));
92 sidebar->AddItem("Seasons", UiUtils::CreateSideBarIcon(":/icons/16x16/calendar.png")); 100 sidebar->AddItem("Seasons", UiUtils::CreateSideBarIcon(":/icons/16x16/calendar.png"));
93 sidebar->AddItem("Torrents", UiUtils::CreateSideBarIcon(":/icons/16x16/feed.png")); 101 sidebar->AddItem("Torrents", UiUtils::CreateSideBarIcon(":/icons/16x16/feed.png"));
94 sidebar->setFixedWidth(128); 102 sidebar->setFixedWidth(128);
95 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); 103 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
96 104
97 anime_list_page = new AnimeListPage(parent); 105 QStackedWidget* stack = new QStackedWidget(main_widget);
106 stack->addWidget(new NowPlayingWidget(parent));
107 AnimeListWidget* list_widget = new AnimeListWidget(parent);
108 list_widget->SyncAnimeList();
109 stack->addWidget(list_widget);
110 stack->addWidget(new StatisticsWidget(list_widget, parent));
111
112 connect(sidebar, &SideBar::CurrentItemChanged, stack, [stack](int index){
113 switch (index) {
114 case 0:
115 case 1:
116 case 2:
117 stack->setCurrentIndex(index);
118 break;
119 default:
120 break;
121 }
122 });
123 sidebar->setCurrentRow(2);
98 124
99 QHBoxLayout* layout = new QHBoxLayout(main_widget); 125 QHBoxLayout* layout = new QHBoxLayout(main_widget);
100 layout->addWidget(sidebar, 0, Qt::AlignLeft | Qt::AlignTop); 126 layout->addWidget(sidebar, 0, Qt::AlignLeft | Qt::AlignTop);
101 layout->addWidget(anime_list_page); 127 layout->addWidget(stack);
102 SetActivePage(main_widget); 128 setCentralWidget(main_widget);
103 /* 129
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);
142 toolbar->setMinimumSize(QSize(140, 0));
143 toolbar->setObjectName("sidebar");
144 toolbar->setStyleSheet("QToolBar#sidebar{margin: 6px;}");
145 //toolbar->setFrameShape(QFrame::NoFrame);
146 toolbar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Maximum);
147
148 addToolBar(Qt::LeftToolBarArea, toolbar);
149 */
150 ThemeChanged(); 130 ThemeChanged();
151 } 131 }
152 132
153 void MainWindow::SetStyleSheet(enum Themes theme) { 133 void MainWindow::SetStyleSheet(enum Themes theme) {
154 switch (theme) { 134 switch (theme) {