-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
66 lines (57 loc) · 2.05 KB
/
mainwindow.cpp
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
#include <QMessageBox>
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect (&mytApp, &MYTApp::searchFinished, this, &MainWindow::receiveSearch);
ui->videoList->setEditTriggers(QAbstractItemView::NoEditTriggers); // Stops the user from editing the search results.
ui->videoList->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->videoList->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::receiveSearch(QList<videoData> _videoList)
{
videoList = _videoList;
ui->searchBar->setText(curSearch);
ui->searchBar->setEnabled(true);
ui->searchButton->setEnabled(true);
// First we clear the table using a for loop so that we don't lose the column labels
for (int i = ui->videoList->rowCount() - 1; i > 0; i--)
{
ui->videoList->removeRow(i);
}
ui->videoList->setRowCount(videoList.size());
for (int i = 0; i < videoList.size(); i++)
{
ui->videoList->setItem(i, 0, &videoList[i].thumbnail);
ui->videoList->setItem(i, 1, &videoList[i].title);
ui->videoList->setItem(i, 2, &videoList[i].channel);
ui->videoList->setItem(i, 3, &videoList[i].uploadDate);
ui->videoList->setItem(i, 4, &videoList[i].views);
}
}
void MainWindow::on_searchButton_clicked()
{
curSearch = ui->searchBar->text();
mytApp.getSearch(curSearch);
ui->searchBar->setText(tr("Please wait..."));
ui->searchBar->setEnabled(false);
ui->searchButton->setEnabled(false);
}
void MainWindow::on_searchBar_returnPressed()
{
on_searchButton_clicked();
}
void MainWindow::on_videoList_cellDoubleClicked(int row, int column)
{
column >>= 2; //! Get rid of unused variable warning
QWidget::setWindowTitle ("myt - MPV is now playing \"" + videoList[row].title.text() + "\"");
mytApp.playVideo(videoList[row].videoUrl.text());
QWidget::setWindowTitle ("myt");
}