-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdlgsongshop.cpp
More file actions
92 lines (80 loc) · 3.43 KB
/
dlgsongshop.cpp
File metadata and controls
92 lines (80 loc) · 3.43 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
#include "dlgsongshop.h"
#include "ui_dlgsongshop.h"
DlgSongShop::DlgSongShop(QWidget *parent):
QDialog(parent),
ui(new Ui::DlgSongShop)
{
QCoreApplication::setOrganizationName("OpenKJ");
QCoreApplication::setOrganizationDomain("OpenKJ.org");
QCoreApplication::setApplicationName("OpenKJ SongShop");
settings = new Settings(this);
ui->setupUi(this);
shop = new SongShop(this);
modelSongs = new SongShopModel(shop, this);
sortFilterModel = new ShopSortFilterProxyModel(this);
sortFilterModel->setSourceModel(modelSongs);
sortFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
sortFilterModel->setSortCaseSensitivity(Qt::CaseInsensitive);
sortFilterModel->sort(0);
sortFilterModel->setFilterKeyColumn(-1);
ui->tableViewSongs->setModel(sortFilterModel);
dlgPurchase = new DlgSongShopPurchase(shop, this);
dlgPurchase->setModal(false);
settings->restoreColumnWidths(ui->tableViewSongs);
connect(modelSongs->getShop(), SIGNAL(karaokeSongDownloaded(QString)), this, SIGNAL(karaokeSongDownloaded(QString)));
connect(shop, SIGNAL(songsUpdated()), this, SLOT(autoSizeView()));
// connect(shop, SIGNAL(songUpdateStarted()), msgLoading, SLOT(show()));
settings->restoreWindowState(this);
}
DlgSongShop::~DlgSongShop()
{
settings->saveWindowState(this);
delete ui;
}
void DlgSongShop::on_btnClose_clicked()
{
settings->saveColumnWidths(ui->tableViewSongs);
close();
}
void DlgSongShop::on_lineEditSearch_textChanged(const QString &arg1)
{
sortFilterModel->setSearchTerms(arg1);
}
void DlgSongShop::on_btnPurchase_clicked()
{
if (ui->tableViewSongs->selectionModel()->selectedIndexes().size() < 1)
return;
QModelIndex idx = ui->tableViewSongs->selectionModel()->selectedIndexes().at(0);
dlgPurchase->setSongId(idx.data(Qt::UserRole).toString());
dlgPurchase->setArtist(idx.sibling(idx.row(), 0).data().toString());
dlgPurchase->setTitle(idx.sibling(idx.row(), 1).data().toString());
dlgPurchase->setPrice(idx.sibling(idx.row(), 5).data().toString());
dlgPurchase->doAuth();
dlgPurchase->show();
}
void DlgSongShop::setVisible(bool visible)
{
settings->restoreColumnWidths(ui->tableViewSongs);
QDialog::setVisible(visible);
}
void DlgSongShop::autoSizeView()
{
// int fH = QFontMetrics(settings->applicationFont()).height();
int priceColSize = QFontMetrics(settings->applicationFont()).width("__$0.00__");
int songidColSize = QFontMetrics(settings->applicationFont()).width("__PY000000__");
int vendorColSize = QFontMetrics(settings->applicationFont()).width("__Party Tyme Karaoke__");
int mediaColSize = QFontMetrics(settings->applicationFont()).width("__mp3+g__");
int remainingSpace = ui->tableViewSongs->width() - priceColSize - songidColSize - vendorColSize - mediaColSize - 20;
int artistColSize = (remainingSpace / 2) - 100;
int titleColSize = (remainingSpace / 2) + 80;
ui->tableViewSongs->horizontalHeader()->resizeSection(0, artistColSize);
ui->tableViewSongs->horizontalHeader()->resizeSection(1, titleColSize);
ui->tableViewSongs->horizontalHeader()->resizeSection(2, songidColSize);
ui->tableViewSongs->horizontalHeader()->resizeSection(3, vendorColSize);
ui->tableViewSongs->horizontalHeader()->resizeSection(4, mediaColSize);
ui->tableViewSongs->horizontalHeader()->resizeSection(5, priceColSize);
}
void DlgSongShop::resizeEvent(QResizeEvent *event)
{
autoSizeView();
}