Gui optimize and folder handling player

This commit is contained in:
hawkeyexp 2018-09-20 17:56:03 +02:00
parent b84aed1f55
commit e26022190e
10 changed files with 813 additions and 675 deletions

BIN
assets/next-hot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
assets/nextbig-hot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

BIN
assets/pause-hot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
assets/play-hot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
assets/prev-hot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
assets/prevbig-hot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

View File

@ -27,6 +27,12 @@
<file>eye-hot.png</file>
<file>skin-hot.png</file>
<file>mp3-hot.png</file>
<file>play-hot.png</file>
<file>prev-hot.png</file>
<file>next-hot.png</file>
<file>pause-hot.png</file>
<file>prevbig-hot.png</file>
<file>nextbig-hot.png</file>
<file>coverlogo.png</file>
<file>black.png</file>
<file>Roboto-Regular.ttf</file>

View File

@ -108,7 +108,6 @@ private slots:
void customButtonPressed5();
void customButtonPressed6();
void customButtonPressed7();
void customButtonPressed8();
void playerShow();
void playerHide();
@ -121,12 +120,13 @@ private slots:
void on_durationChanged(qint64 position);
void on_mp3List_itemClicked(QListWidgetItem *item);
void metaDataChanged();
void stateChanged();
void on_pushButtonScanFolder_clicked();
void on_pushButtonSelectFolder_clicked();
void on_pushButtonPlayerPlayList_clicked();
void on_pushButtonPlayerPrev_clicked();
void on_pushButtonPlayerNext_clicked();
void on_pushButtonNextBig_clicked();
void on_pushButtonPrevBig_clicked();
void on_comboBoxAlbum_currentIndexChanged(const QString &arg1);
void on_mp3List_currentRowChanged(int currentRow);
void scanFolders();
void scanFiles();
private:
Ui::MainWindow* ui_;
@ -147,7 +147,6 @@ private:
QString custom_button_file_c5 = "/boot/crankshaft/button_5";
QString custom_button_file_c6 = "/boot/crankshaft/button_6";
QString custom_button_file_c7 = "/boot/crankshaft/button_7";
QString custom_button_file_c8 = "/boot/crankshaft/button_8";
QString custom_button_command_c1;
QString custom_button_command_c2;
@ -156,7 +155,6 @@ private:
QString custom_button_command_c5;
QString custom_button_command_c6;
QString custom_button_command_c7;
QString custom_button_command_c8;
QString custom_button_color_c1 = "186,189,192";
QString custom_button_color_c2 = "186,189,192";
@ -165,10 +163,10 @@ private:
QString custom_button_color_c5 = "186,189,192";
QString custom_button_color_c6 = "186,189,192";
QString custom_button_color_c7 = "186,189,192";
QString custom_button_color_c8 = "186,189,192";
QString selectedMp3file;
QString musicfolder = "/media/CSSTORAGE/Music";
QString albumfolder = "/";
QMediaPlaylist *playlist;
bool customBrightnessControl = false;
@ -209,9 +207,10 @@ private:
bool c5ButtonForce = false;
bool c6ButtonForce = false;
bool c7ButtonForce = false;
bool c8ButtonForce = false;
bool hotspotActive = false;
int currentPlaylistIndex = 0;
};
}

View File

@ -30,6 +30,7 @@
#include <QScreen>
#include <QRect>
#include <string>
#include <qmediaplayer.h>
namespace f1x
{
@ -93,9 +94,6 @@ MainWindow::MainWindow(configuration::IConfiguration::Pointer configuration, QWi
QFileInfo c7ButtonFile(this->custom_button_file_c7);
this->c7ButtonForce = c7ButtonFile.exists();
QFileInfo c8ButtonFile(this->custom_button_file_c8);
this->c8ButtonForce = c8ButtonFile.exists();
// wallpaper stuff
QFileInfo wallpaperDayFile("wallpaper.png");
this->wallpaperDayFileExists = wallpaperDayFile.exists();
@ -167,6 +165,7 @@ MainWindow::MainWindow(configuration::IConfiguration::Pointer configuration, QWi
connect(ui_->pushButtonMusic, &QPushButton::clicked, this, &MainWindow::playerShow);
connect(ui_->pushButtonMusic2, &QPushButton::clicked, this, &MainWindow::playerShow);
connect(ui_->pushButtonBack, &QPushButton::clicked, this, &MainWindow::playerHide);
connect(ui_->pushButtonPlayerBack, &QPushButton::clicked, this, &MainWindow::playerHide);
// by default hide bluetooth button on init
ui_->pushButtonBluetooth->hide();
@ -242,11 +241,6 @@ MainWindow::MainWindow(configuration::IConfiguration::Pointer configuration, QWi
ui_->pushButtonBrightness->hide();
}
// hide dummy if debug is shown
if (this->systemDebugmode) {
ui_->pushButtonDummy->hide();
}
// as default hide brightness slider
ui_->BrightnessSliderControl->hide();
@ -397,23 +391,6 @@ MainWindow::MainWindow(configuration::IConfiguration::Pointer configuration, QWi
connect(ui_->pushButton_c7, &QPushButton::clicked, this, &MainWindow::customButtonPressed7);
}
if (!this->c8ButtonForce) {
ui_->pushButton_c8->hide();
} else {
// read button config 8
QFile paramFile(this->custom_button_file_c8);
paramFile.open(QIODevice::ReadOnly);
QTextStream data(&paramFile);
QStringList params = data.readAll().split("#");
paramFile.close();
ui_->pushButton_c8->setText(params[0].simplified());
this->custom_button_command_c8 = params[1].simplified();
if (params[2] != "") {
this->custom_button_color_c8 = params[2].simplified();
}
connect(ui_->pushButton_c8, &QPushButton::clicked, this, &MainWindow::customButtonPressed8);
}
// as default hide camera controls
ui_->cameraWidget->hide();
ui_->pushButtonRecordActive->hide();
@ -441,9 +418,6 @@ MainWindow::MainWindow(configuration::IConfiguration::Pointer configuration, QWi
ui_->pushButtonDummy3->hide();
}
if (this->c8ButtonForce || this->systemDebugmode) {
ui_->pushButtonDummy->hide();
}
// show dev labels if dev mode activated
if (!this->devModeEnabled) {
ui_->devlabel_left->hide();
@ -574,10 +548,12 @@ MainWindow::MainWindow(configuration::IConfiguration::Pointer configuration, QWi
connect(player, &QMediaPlayer::positionChanged, this, &MainWindow::on_positionChanged);
connect(player, &QMediaPlayer::durationChanged, this, &MainWindow::on_durationChanged);
connect(player, &QMediaPlayer::metaDataAvailableChanged, this, &MainWindow::metaDataChanged);
connect(player, &QMediaPlayer::stateChanged, this, &MainWindow::stateChanged);
ui_->id3TagInfo->hide();
MainWindow::on_pushButtonScanFolder_clicked();
MainWindow::scanFolders();
MainWindow::scanFiles();
ui_->labelFolderpath->hide();
ui_->pushButtonPlayerPlay->hide();
ui_->PlayerPlayingWidget->hide();
}
MainWindow::~MainWindow()
@ -625,11 +601,6 @@ void f1x::openauto::autoapp::ui::MainWindow::customButtonPressed7()
system(qPrintable(this->custom_button_command_c7 + " &"));
}
void f1x::openauto::autoapp::ui::MainWindow::customButtonPressed8()
{
system(qPrintable(this->custom_button_command_c8 + " &"));
}
void f1x::openauto::autoapp::ui::MainWindow::on_pushButtonBrightness_clicked()
{
this->brightnessFile = new QFile(this->brightnessFilename);
@ -792,8 +763,6 @@ void f1x::openauto::autoapp::ui::MainWindow::on_horizontalSliderAlpha_valueChang
ui_->pushButton_c5->setStyleSheet( "background-color: rgba(" + this->custom_button_color_c5 + ", " + alp + " ); border-radius: 4px; border: 2px solid rgba(255,255,255,0.5); color: rgb(255,255,255);");
ui_->pushButton_c6->setStyleSheet( "background-color: rgba(" + this->custom_button_color_c6 + ", " + alp + " ); border-radius: 4px; border: 2px solid rgba(255,255,255,0.5); color: rgb(255,255,255);");
ui_->pushButton_c7->setStyleSheet( "background-color: rgba(" + this->custom_button_color_c7 + ", " + alp + " ); border-radius: 4px; border: 2px solid rgba(255,255,255,0.5); color: rgb(255,255,255);");
ui_->pushButton_c8->setStyleSheet( "background-color: rgba(" + this->custom_button_color_c8 + ", " + alp + " ); border-radius: 4px; border: 2px solid rgba(255,255,255,0.5); color: rgb(255,255,255);");
ui_->pushButtonDummy->setStyleSheet( "background-color: rgba(52, 101, 164, " + alp + " ); border-radius: 4px; border: 2px solid rgba(255,255,255,0.5);");
ui_->pushButtonDummy1->setStyleSheet( "background-color: rgba(186, 189, 182, " + alp + " ); border-radius: 4px; border: 2px solid rgba(255,255,255,0.5);");
ui_->pushButtonDummy2->setStyleSheet( "background-color: rgba(186, 189, 182, " + alp + " ); border-radius: 4px; border: 2px solid rgba(255,255,255,0.5);");
ui_->pushButtonDummy3->setStyleSheet( "background-color: rgba(186, 189, 182, " + alp + " ); border-radius: 4px; border: 2px solid rgba(255,255,255,0.5);");
@ -1228,17 +1197,24 @@ void f1x::openauto::autoapp::ui::MainWindow::on_horizontalSliderVolumePlayer_sli
void f1x::openauto::autoapp::ui::MainWindow::on_pushButtonPlayerPlay_clicked()
{
QString path = this->musicfolder + "/" + this->selectedMp3file;
ui_->labelFolderpath->setText(path);
QString path = this->musicfolder + "/" + this->albumfolder + "/" + this->selectedMp3file;
player->setMedia(QMediaContent(QUrl::fromLocalFile(path)));
player->play();
//qDebug() << player->errorString();
ui_->pushButtonPlayerPause->setStyleSheet( "background-color: rgb(233, 185, 110); border-radius: 4px; border: 2px solid rgba(255,255,255,0.5); color: rgb(0,0,0);");
ui_->mp3selectWidget->hide();
ui_->PlayerPlayingWidget->show();
}
void f1x::openauto::autoapp::ui::MainWindow::on_pushButtonPlayerStop_clicked()
{
player->stop();
ui_->pushButtonBack->setIcon(QPixmap("://coverlogo.png"));
ui_->pushButtonPlayerPause->setStyleSheet( "background-color: rgb(233, 185, 110); border-radius: 4px; border: 2px solid rgba(255,255,255,0.5); color: rgb(0,0,0);");
ui_->mp3selectWidget->show();
ui_->PlayerPlayingWidget->hide();
ui_->playerPositionTime->setText("00:00 / 00:00");
ui_->labelCurrentPlaying->setText("");
}
void f1x::openauto::autoapp::ui::MainWindow::on_pushButtonPlayerPause_clicked()
@ -1247,10 +1223,14 @@ void f1x::openauto::autoapp::ui::MainWindow::on_pushButtonPlayerPause_clicked()
if(player->state() == QMediaPlayer::PlayingState){
player->pause();
ui_->pushButtonPlayerPause->setStyleSheet( "background-color: rgb(218, 143, 143); border-radius: 4px; border: 2px solid rgba(255,255,255,0.5); color: rgb(0,0,0);");
ui_->mp3selectWidget->show();
ui_->PlayerPlayingWidget->hide();
}else{
ui_->pushButtonPlayerPause->setStyleSheet( "background-color: rgb(186, 189, 182); border-radius: 4px; border: 2px solid rgba(255,255,255,0.5); color: rgb(0,0,0);");
ui_->pushButtonPlayerPause->setStyleSheet( "background-color: rgb(233, 185, 110); border-radius: 4px; border: 2px solid rgba(255,255,255,0.5); color: rgb(0,0,0);");
player->play();
player->setPosition(player->position());
ui_->mp3selectWidget->hide();
ui_->PlayerPlayingWidget->show();
}
}
@ -1307,26 +1287,64 @@ void f1x::openauto::autoapp::ui::MainWindow::on_mp3List_itemClicked(QListWidgetI
void f1x::openauto::autoapp::ui::MainWindow::metaDataChanged()
{
ui_->valueId3Title->setText(player->metaData(QMediaMetaData::Title).toString());
ui_->valueId3Artist->setText(player->metaData(QMediaMetaData::Author).toString());
ui_->valueId3Album->setText(player->metaData(QMediaMetaData::AlbumTitle).toString());
ui_->valueId3Track->setText(player->metaData(QMediaMetaData::TrackNumber).toString());
ui_->valueId3Genre->setText(player->metaData(QMediaMetaData::Genre).toString());
ui_->valueId3Year->setText(player->metaData(QMediaMetaData::Year).toString());
QImage img = player->metaData(QMediaMetaData::CoverArtImage).value<QImage>();
QImage imgscaled = img.scaled(270,270,Qt::IgnoreAspectRatio);
if (!imgscaled.isNull()) {
ui_->pushButtonBack->setIcon(QPixmap::fromImage(imgscaled));
ui_->labelCurrentPlaying->setText(player->metaData(QMediaMetaData::Title).toString() + " - " + player->metaData(QMediaMetaData::AlbumArtist).toString());
}
void f1x::openauto::autoapp::ui::MainWindow::stateChanged()
{
if (player->StoppedState) {
ui_->pushButtonBack->setIcon(QPixmap("://coverlogo.png"));
} else {
ui_->pushButtonBack->setIcon(QPixmap("://coverlogo.png"));
}
QString Title = player->metaData(QMediaMetaData::Title).toString();
QString AlbumInterpret = player->metaData(QMediaMetaData::AlbumArtist).toString();
QString currentPlaying = "";
if (AlbumInterpret != "") {
currentPlaying.append(AlbumInterpret);
}
if (Title != "" && AlbumInterpret != "") {
currentPlaying.append(" - ");
}
if (Title != "") {
currentPlaying.append(Title);
}
ui_->labelCurrentPlaying->setText(currentPlaying);
QString fullpathplaying = player->currentMedia().canonicalUrl().toString();
QString filename = QFileInfo(fullpathplaying).fileName();
}
void f1x::openauto::autoapp::ui::MainWindow::on_pushButtonScanFolder_clicked()
void f1x::openauto::autoapp::ui::MainWindow::on_pushButtonPlayerPlayList_clicked()
{
player->setPlaylist(this->playlist);
playlist->setCurrentIndex(this->currentPlaylistIndex);
player->play();
ui_->mp3selectWidget->hide();
ui_->PlayerPlayingWidget->show();
ui_->pushButtonPlayerPause->setStyleSheet( "background-color: rgb(233, 185, 110); border-radius: 4px; border: 2px solid rgba(255,255,255,0.5); color: rgb(0,0,0);");
}
void f1x::openauto::autoapp::ui::MainWindow::on_comboBoxAlbum_currentIndexChanged(const QString &arg1)
{
this->albumfolder = arg1;
f1x::openauto::autoapp::ui::MainWindow::scanFiles();
}
void f1x::openauto::autoapp::ui::MainWindow::scanFolders()
{
int cleaner = ui_->comboBoxAlbum->count();
while (cleaner > -1) {
ui_->comboBoxAlbum->removeItem(cleaner);
cleaner--;
}
QDir directory(this->musicfolder);
QStringList folders = directory.entryList(QStringList() << "*", QDir::AllDirs, QDir::Name);
foreach (QString foldername, folders) {
if (foldername != "..") {
ui_->comboBoxAlbum->addItem(foldername);
}
}
this->currentPlaylistIndex = 0;
}
void f1x::openauto::autoapp::ui::MainWindow::scanFiles()
{
int cleaner = ui_->mp3List->count();
while (cleaner > -1) {
@ -1335,39 +1353,31 @@ void f1x::openauto::autoapp::ui::MainWindow::on_pushButtonScanFolder_clicked()
}
this->playlist->clear();
QDirIterator dir(this->musicfolder, QStringList() << "*.mp3", QDir::NoFilter, QDirIterator::Subdirectories);
QList<QMediaContent> content;
while (dir.hasNext()) {
QFile f(dir.next());
QString filename = f.fileName();
// make path relative to musicfolder
ui_->mp3List->addItem(filename.replace(this->musicfolder + "/",""));
content.push_back(QMediaContent(QUrl::fromLocalFile(f.fileName())));
QDir directory(this->musicfolder + "/" + this->albumfolder);
QStringList mp3s = directory.entryList(QStringList() << "*.mp3",QDir::Files, QDir::Name);
foreach (QString filename, mp3s) {
// add to mediacontent
content.push_back(QMediaContent(QUrl::fromLocalFile(this->musicfolder + "/" + this->albumfolder + "/" + filename)));
// add items to gui
ui_->mp3List->addItem(filename);
}
// set playlist
this->playlist->addMedia(content);
}
void f1x::openauto::autoapp::ui::MainWindow::on_pushButtonSelectFolder_clicked()
void f1x::openauto::autoapp::ui::MainWindow::on_mp3List_currentRowChanged(int currentRow)
{
this->musicfolder = QFileDialog::getExistingDirectory(this, tr("Select Album"), this->musicfolder, QFileDialog::ShowDirsOnly);
f1x::openauto::autoapp::ui::MainWindow::on_pushButtonScanFolder_clicked();
ui_->labelFolderpath->setText(QString::number(currentRow));
this->currentPlaylistIndex = currentRow;
}
void f1x::openauto::autoapp::ui::MainWindow::on_pushButtonPlayerPlayList_clicked()
{
QString path = this->musicfolder + "/" + this->selectedMp3file;
ui_->labelFolderpath->setText(path);
player->setPlaylist(this->playlist);
player->play();
}
void f1x::openauto::autoapp::ui::MainWindow::on_pushButtonPlayerPrev_clicked()
{
playlist->previous();
}
void f1x::openauto::autoapp::ui::MainWindow::on_pushButtonPlayerNext_clicked()
void f1x::openauto::autoapp::ui::MainWindow::on_pushButtonNextBig_clicked()
{
playlist->next();
}
void f1x::openauto::autoapp::ui::MainWindow::on_pushButtonPrevBig_clicked()
{
playlist->previous();
}

File diff suppressed because it is too large Load Diff