-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
142 lines (114 loc) · 4.21 KB
/
mainwindow.cpp
File metadata and controls
142 lines (114 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QKeyEvent>
#include <QAction>
#include <QList>
#include <QMenu>
#include "mediadatabase.h"
#include "user.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
_player(new mediaPlayerTabWidget),
_videoWidget(new videoWidget),
_controlPanel(new controlPanel),
_lyricsBox(new lyricBox),
_progressBar(new progressBar),
_menu(new QMenuBar),
_user(new User),
_mainWindowIcon(":/resources/icons/mainWindowIcon.png"),
_previousButtonIcon(":/resources/icons/Button-Prev-icon.png"),
_nextButtonIcon(":/resources/icons/Button-Next-icon.png"),
_playButtonIcon(":/resources/icons/Button-Play-icon.png"),
_pauseButtonIcon(":/resources/icons/Button-Pause-icon.png")
{
ui->setupUi(this);
setWindowIcon(_mainWindowIcon);
setWindowTitle(tr("Music Player"));
setupPlayer();
setupLyricsAndControlPanel();
setWidgetPositions();
setupMenuBar();
mediaDatabase * db = new mediaDatabase;
_player->setMediaDatabase(db);
_player->setUser(_user);
_user->setMediaDatabase(db);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::setupPlayer()
{
if(QCoreApplication::arguments().size())
{
QStringList * args = new QStringList(QCoreApplication::arguments());
args->removeFirst();
_player->addMedia(args);
}
_player->setVideoWidget(_videoWidget);
_player->setControlPanel(_controlPanel);
_player->setLyricBox(_lyricsBox);
_player->setProgressBar(_progressBar);
}
void MainWindow::setupLyricsAndControlPanel()
{
_lyricsBox->setFont(QFont("Comic Sans MS"));
_controlPanel->setPlayButtonIcon(_playButtonIcon);
_controlPanel->setPauseButtonIcon(_pauseButtonIcon);
_controlPanel->setNextButtonIcon(_nextButtonIcon);
_controlPanel->setPreviousButtonIcon(_previousButtonIcon);
}
void MainWindow::setWidgetPositions()
{
QWidget * centralWidget = new QWidget;
QHBoxLayout * playerAndLyricsLayout = new QHBoxLayout;
QVBoxLayout * centralLayout = new QVBoxLayout;
playerAndLyricsLayout->addWidget(_videoWidget);
playerAndLyricsLayout->addWidget(_player);
playerAndLyricsLayout->addWidget(_lyricsBox);
centralLayout->addLayout(playerAndLyricsLayout);
centralLayout->addWidget(_progressBar);
centralLayout->addWidget(_controlPanel);
centralLayout->setContentsMargins(2,2,2,2);
centralWidget->setLayout(centralLayout);
this->setCentralWidget(centralWidget);
}
void MainWindow::setupMenuBar()
{
//File menu
QMenu * fileMenu = new QMenu(tr("File"));
QList<QAction *> fileMenuActions;
QAction * openMedia = new QAction(tr("Open Media"), this);
QAction * addMedia = new QAction(tr("Add Media"), this);
openMedia->setShortcut(QKeySequence("CTRL+O"));
addMedia->setShortcut(QKeySequence("CTRL+A"));
connect (openMedia, SIGNAL(triggered()), _player, SLOT(openMedia()));
connect (addMedia, SIGNAL(triggered()), _player, SLOT(addMedia()));
fileMenuActions.push_back(addMedia);
fileMenuActions.push_back(openMedia);
fileMenu->addActions(fileMenuActions);
//User menu
QMenu * userMenu = new QMenu(tr("User"));
QList<QAction *> userMenuActions;
QAction * login = new QAction(tr("Login"), this);
QAction * create = new QAction(tr("Create User"), this);
QAction * info = new QAction(tr("User Information"), this);
login->setShortcut(QKeySequence("CTRL+L"));
info->setShortcut(QKeySequence("CTRL+I"));
connect(login, SIGNAL(triggered()), _user, SLOT(presentLoginWindow()));
connect(create, SIGNAL(triggered()), _user, SLOT(presentCreateUserWindow()));
connect(info, SIGNAL(triggered()), _user, SLOT(presentUserInformationWindow()));
userMenuActions.push_back(login);
userMenuActions.push_back(create);
userMenuActions.push_back(info);
userMenu->addActions(userMenuActions);
//Add menus
_menu->addMenu(fileMenu);
_menu->addMenu(userMenu);
this->setMenuBar(_menu);
}