aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Ui/qsui
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/Ui/qsui')
-rw-r--r--src/plugins/Ui/qsui/mainwindow.cpp94
-rw-r--r--src/plugins/Ui/qsui/mainwindow.h6
-rw-r--r--src/plugins/Ui/qsui/qsui.pro6
-rw-r--r--src/plugins/Ui/qsui/qsuistatusbar.cpp187
-rw-r--r--src/plugins/Ui/qsui/qsuistatusbar.h68
5 files changed, 265 insertions, 96 deletions
diff --git a/src/plugins/Ui/qsui/mainwindow.cpp b/src/plugins/Ui/qsui/mainwindow.cpp
index 63aff4b49..a1347faa0 100644
--- a/src/plugins/Ui/qsui/mainwindow.cpp
+++ b/src/plugins/Ui/qsui/mainwindow.cpp
@@ -58,6 +58,7 @@
#include "qsuitabwidget.h"
#include "qsuiquicksearch.h"
#include "qsuiwaveformseekbar.h"
+#include "qsuistatusbar.h"
#include "equalizer.h"
#define KEY_OFFSET 10000
@@ -83,9 +84,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
//status
connect(m_core, SIGNAL(elapsedChanged(qint64)), SLOT(updatePosition(qint64)));
connect(m_core, SIGNAL(stateChanged(Qmmp::State)), SLOT(showState(Qmmp::State)));
- connect(m_core, SIGNAL(bitrateChanged(int)), SLOT(updateBitrate(int)));
- connect(m_core, SIGNAL(audioParametersChanged(AudioParameters)), SLOT(updateStatus()));
- connect(m_core, SIGNAL(bufferingProgress(int)), SLOT(showBuffering(int)));
connect(m_core, SIGNAL(trackInfoChanged()), SLOT(showMetaData()));
//keyboard manager
m_key_manager = new KeyboardManager(this);
@@ -126,21 +124,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
connect(m_tabWidget, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showTabMenu(QPoint)));
m_tab_menu = new QMenu(m_tabWidget);
//status bar
- m_statusLabel = new QLabel(this);
- m_bitrateLabel = new QLabel(this);
- m_bitrateLabel->setAlignment(Qt::AlignRight);
- m_timeLabel = new QLabel(this);
- m_timeLabel->setAlignment(Qt::AlignRight);
- m_ui.statusbar->addPermanentWidget(m_statusLabel, 0);
- QFrame *l = new QFrame(this);
- l->setFrameStyle(QFrame::VLine | QFrame::Raised);
- m_ui.statusbar->addPermanentWidget(l);
- m_ui.statusbar->addPermanentWidget(m_bitrateLabel, 0);
- l = new QFrame(this);
- l->setFrameStyle(QFrame::VLine | QFrame::Raised);
- m_ui.statusbar->addPermanentWidget(l);
- m_ui.statusbar->addPermanentWidget(m_timeLabel, 0);
- m_ui.statusbar->addPermanentWidget(new QWidget(this), 1); //spacer
+ m_statusBar = new QSUiStatusBar(this);
+ m_ui.statusbar->addPermanentWidget(m_statusBar, 1);
m_ui.statusbar->setStyleSheet("QStatusBar::item { border: 0px solid black; };");
//volume
m_volumeSlider = new VolumeSlider(this);
@@ -174,7 +159,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
createActions();
readSettings();
- updateStatus();
restoreWindowTitle();
}
@@ -209,41 +193,11 @@ void MainWindow::addUrl()
m_uiHelper->addUrl(this);
}
-void MainWindow::updateBitrate(int bitrate)
-{
- QString text = tr("%1 kbps").arg(bitrate);
- if(text.size() > m_bitrateLabel->text().size()) //label width tuning to avoid text jumping
- {
- QString tmp = text;
- tmp.replace(QRegularExpression("\\d"), "4");
- int width = m_bitrateLabel->fontMetrics().horizontalAdvance(tmp);
- m_bitrateLabel->setMinimumWidth(2);
- m_bitrateLabel->setMargin(0);
- m_bitrateLabel->setIndent(0);
- }
- m_bitrateLabel->setText(text);
-}
-
void MainWindow::updatePosition(qint64 pos)
{
m_positionSlider->setMaximum(m_core->duration()/1000);
if(!m_positionSlider->isSliderDown())
m_positionSlider->setValue(pos/1000);
-
- QString text = MetaDataFormatter::formatDuration(pos, false);
- if(m_core->duration() > 1000)
- {
- text.append("/");
- text.append(MetaDataFormatter::formatDuration(m_core->duration()));
- }
- if(text.size() != m_timeLabel->text().size()) //label width tuning to avoid text jumping
- {
- QString tmp = text;
- tmp.replace(QRegularExpression("\\d"), "4");
- int width = m_timeLabel->fontMetrics().horizontalAdvance(tmp);
- m_timeLabel->setMinimumWidth(width);
- }
- m_timeLabel->setText(text);
}
void MainWindow::seek()
@@ -262,7 +216,6 @@ void MainWindow::showState(Qmmp::State state)
{
case Qmmp::Playing:
{
- updateStatus();
m_analyzer->setCover(MetaDataManager::instance()->getCover(m_core->path()));
CoverWidget *cw = qobject_cast<CoverWidget *>(m_ui.coverDockWidget->widget());
cw->setCover(MetaDataManager::instance()->getCover(m_core->path()));
@@ -270,12 +223,8 @@ void MainWindow::showState(Qmmp::State state)
break;
}
case Qmmp::Paused:
- updateStatus();
break;
case Qmmp::Stopped:
- updateStatus();
- m_bitrateLabel->clear();
- m_timeLabel->clear();
m_positionSlider->setValue(0);
m_analyzer->clearCover();
qobject_cast<CoverWidget *>(m_ui.coverDockWidget->widget())->clearCover();
@@ -405,33 +354,6 @@ void MainWindow::playPause()
m_player->play();
}
-void MainWindow::updateStatus()
-{
- int tracks = m_pl_manager->currentPlayList()->trackCount();
- qint64 duration = m_pl_manager->currentPlayList()->totalDuration();
-
- if(m_core->state() == Qmmp::Playing || m_core->state() == Qmmp::Paused)
- {
- AudioParameters ap = m_core->audioParameters();
- m_statusLabel->setText(tr("<b>%1</b>|%2 bit|%3 ch|%4 Hz|tracks: %5|total time: %6|")
- .arg(m_core->state() == Qmmp::Playing ? tr("Playing") : tr("Paused"))
- .arg(ap.validBitsPerSample())
- .arg(ap.channels())
- .arg(ap.sampleRate())
- .arg(tracks)
- .arg(MetaDataFormatter::formatDuration(duration, false)));
- }
- else if(m_core->state() == Qmmp::Stopped)
- {
- m_statusLabel->setText(tr("<b>%1</b>|tracks: %2|total time: %3")
- .arg(tr("Stopped"))
- .arg(tracks)
- .arg(MetaDataFormatter::formatDuration(duration, false)));
- }
- else
- m_statusLabel->clear();
-}
-
void MainWindow::closeEvent(QCloseEvent *)
{
if(!m_hideOnClose || !m_uiHelper->visibilityControl())
@@ -897,12 +819,6 @@ void MainWindow::loadPlayList()
m_uiHelper->loadPlayList(this);
}
-void MainWindow::showBuffering(int percent)
-{
- if(m_core->state() == Qmmp::Buffering)
- m_statusLabel->setText(tr("Buffering: %1%").arg(percent));
-}
-
void MainWindow::showEqualizer()
{
Equalizer equalizer(this);
@@ -987,13 +903,13 @@ void MainWindow::restoreWindowTitle()
void MainWindow::onListChanged(int flags)
{
if(flags & PlayListModel::STRUCTURE)
- updateStatus();
+ m_statusBar->updatePlayListStatus();
}
void MainWindow::onCurrentPlayListChanged(PlayListModel *current, PlayListModel *previous)
{
updateTabs();
- updateStatus();
+ m_statusBar->updatePlayListStatus();
connect(current, SIGNAL(listChanged(int)), SLOT(onListChanged(int)));
if(previous)
disconnect(current, SIGNAL(listChanged(int)), this, SLOT(onListChanged(int)));
diff --git a/src/plugins/Ui/qsui/mainwindow.h b/src/plugins/Ui/qsui/mainwindow.h
index cb78de8b2..0cb5dd53d 100644
--- a/src/plugins/Ui/qsui/mainwindow.h
+++ b/src/plugins/Ui/qsui/mainwindow.h
@@ -26,7 +26,6 @@
#include "ui_mainwindow.h"
class QSlider;
-class QLabel;
class QMenu;
class QToolButton;
class UiHelper;
@@ -63,11 +62,9 @@ private slots:
void playFiles();
void record(bool enabled);
void addUrl();
- void updateBitrate(int bitrate);
void updatePosition(qint64 pos);
void seek();
void showState(Qmmp::State);
- void updateStatus();
void updateTabs();
void removePlaylist();
void removePlaylistWithIndex(int);
@@ -86,7 +83,6 @@ private slots:
void showTabMenu(QPoint pos);
void savePlayList();
void loadPlayList();
- void showBuffering(int percent);
void showEqualizer();
void forward();
void backward();
@@ -110,7 +106,7 @@ private:
MediaPlayer *m_player;
QmmpUiSettings *m_ui_settings;
PositionSlider *m_positionSlider;
- QLabel *m_statusLabel, *m_bitrateLabel, *m_timeLabel;
+ QSUiStatusBar *m_statusBar;
SoundCore *m_core;
VisualMenu *m_visMenu;
UiHelper *m_uiHelper;
diff --git a/src/plugins/Ui/qsui/qsui.pro b/src/plugins/Ui/qsui/qsui.pro
index 53bbf5df6..d30953175 100644
--- a/src/plugins/Ui/qsui/qsui.pro
+++ b/src/plugins/Ui/qsui/qsui.pro
@@ -34,7 +34,8 @@ SOURCES += \
volumeslider.cpp \
qsuiquicksearch.cpp \
qsuivisualization.cpp \
- qsuiwaveformseekbar.cpp
+ qsuiwaveformseekbar.cpp \
+ qsuistatusbar.cpp
HEADERS += mainwindow.h \
listwidget.h \
visualmenu.h \
@@ -67,7 +68,8 @@ HEADERS += mainwindow.h \
volumeslider.h \
qsuiquicksearch.h \
qsuivisualization.h \
- qsuiwaveformseekbar.h
+ qsuiwaveformseekbar.h \
+ qsuistatusbar.h
FORMS += forms/mainwindow.ui \
forms/shortcutdialog.ui \
diff --git a/src/plugins/Ui/qsui/qsuistatusbar.cpp b/src/plugins/Ui/qsui/qsuistatusbar.cpp
new file mode 100644
index 000000000..3d2afae51
--- /dev/null
+++ b/src/plugins/Ui/qsui/qsuistatusbar.cpp
@@ -0,0 +1,187 @@
+/***************************************************************************
+ * Copyright (C) 2020 by Ilya Kotov *
+ * forkotov02@ya.ru *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QFrame>
+#include <QRegularExpression>
+#include <qmmp/soundcore.h>
+#include <qmmpui/metadataformatter.h>
+#include <qmmpui/playlistmanager.h>
+#include "qsuistatusbar.h"
+
+QSUiStatusBar::QSUiStatusBar(QWidget *parent) : QWidget(parent)
+{
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->setMargin(0);
+
+ for(int i = StatusLabel; i <= TimeLabel; ++i)
+ {
+ QLabel *label = new QLabel;
+ m_labels.insert(LabelType(i), label);
+ layout->addWidget(label);
+
+ if(i != TimeLabel)
+ {
+ QFrame *sep = new QFrame(this);
+ sep->setFrameStyle(QFrame::VLine | QFrame::Raised);
+ m_separators.insert(LabelType(i), sep);
+ layout->addWidget(sep);
+ }
+ }
+ m_labels[BitrateLabel]->setAlignment(Qt::AlignRight);
+ m_labels[TimeLabel]->setAlignment(Qt::AlignRight);
+ layout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Preferred));
+ setLayout(layout);
+
+ m_core = SoundCore::instance();
+ m_pl_manager = PlayListManager::instance();
+ connect(m_core, SIGNAL(stateChanged(Qmmp::State)), SLOT(onStateChanged(Qmmp::State)));
+ connect(m_core, SIGNAL(bufferingProgress(int)), SLOT(onBufferingProgress(int)));
+ connect(m_core, SIGNAL(audioParametersChanged(AudioParameters)), SLOT(onAudioParametersChanged(AudioParameters)));
+ connect(m_core, SIGNAL(bitrateChanged(int)), SLOT(onBitrateChanged(int)));
+ connect(m_core, SIGNAL(elapsedChanged(qint64)), SLOT(onElapsedChanged(qint64)));
+ onStateChanged(m_core->state());
+}
+
+void QSUiStatusBar::updatePlayListStatus()
+{
+ int tracks = m_pl_manager->currentPlayList()->trackCount();
+ qint64 duration = m_pl_manager->currentPlayList()->totalDuration();
+ m_labels[TrackCountLabel]->setText(tr("tracks: %1").arg(tracks));
+ m_labels[TotalTimeLabel]->setText(tr("total time: %1").arg(MetaDataFormatter::formatDuration(duration, false)));
+}
+
+void QSUiStatusBar::onStateChanged(Qmmp::State state)
+{
+ if(state == Qmmp::Playing || state == Qmmp::Paused)
+ {
+ for(QLabel *label : m_labels.values())
+ label->show();
+
+ for(QFrame *sep : m_separators.values())
+ sep->show();
+
+ m_labels[BitrateLabel]->setMinimumWidth(0);
+ m_labels[BitrateLabel]->clear();
+ m_labels[TimeLabel]->setMinimumWidth(0);
+ m_labels[TimeLabel]->clear();
+
+ m_labels[StatusLabel]->setText(QString("<b>%1</b>").arg(state == Qmmp::Playing ? tr("Playing") : tr("Paused")));
+ onAudioParametersChanged(m_core->audioParameters());
+ onElapsedChanged(m_core->elapsed());
+ updatePlayListStatus();
+ }
+ else if(state == Qmmp::Buffering)
+ {
+ for(int i = SampleRateLabel; i <= TimeLabel; ++i)
+ m_labels[LabelType(i)]->hide();
+
+ for(QFrame *sep : m_separators.values())
+ sep->hide();
+
+ m_labels[StatusLabel]->show();
+ }
+ else if(state == Qmmp::Stopped)
+ {
+ for(int i = StatusLabel; i <= TimeLabel; ++i)
+ {
+ LabelType t = LabelType(i);
+ if(t == StatusLabel || t == TrackCountLabel)
+ {
+ m_labels[t]->show();
+ m_separators[t]->show();
+ }
+ else if(t == TotalTimeLabel)
+ {
+ m_labels[t]->show();
+ m_separators[t]->hide();
+ }
+ else
+ {
+ m_labels[t]->hide();
+ if(t != TimeLabel)
+ m_separators[t]->hide();
+ }
+ }
+
+ m_labels[StatusLabel]->setText(QString("<b>%1</b>").arg(tr("Stopped")));
+ updatePlayListStatus();
+ }
+ else
+ {
+ for(int i = SampleRateLabel; i <= TimeLabel; ++i)
+ m_labels[LabelType(i)]->hide();
+
+ for(QFrame *sep : m_separators.values())
+ sep->hide();
+
+ m_labels[StatusLabel]->show();
+ m_labels[StatusLabel]->setText(QString("<b>%1</b>").arg(tr("Error")));
+ updatePlayListStatus();
+ }
+}
+
+void QSUiStatusBar::onBufferingProgress(int percent)
+{
+ if(m_core->state() == Qmmp::Buffering)
+ m_labels[StatusLabel]->setText(tr("Buffering: %1%").arg(percent));
+}
+
+void QSUiStatusBar::onAudioParametersChanged(const AudioParameters &ap)
+{
+ m_labels[SampleSizeLabel]->setText(tr("%1 bits").arg(ap.validBitsPerSample()));
+ m_labels[ChannelsLabel]->setText(tr("%1 ch").arg(ap.channels()));
+ m_labels[SampleRateLabel]->setText(tr("%1 Hz").arg(ap.sampleRate()));
+}
+
+void QSUiStatusBar::onBitrateChanged(int bitrate)
+{
+ QString text = tr("%1 kbps").arg(bitrate);
+ QLabel *label = m_labels[BitrateLabel];
+ if(text.size() > label->text().size()) //label width tuning to avoid text jumping
+ {
+ QString tmp = text;
+ tmp.replace(QRegularExpression("\\d"), "4");
+ int width = label->fontMetrics().horizontalAdvance(tmp);
+ label->setMinimumWidth(width);
+ }
+ label->setText(text);
+}
+
+void QSUiStatusBar::onElapsedChanged(qint64 elapsed)
+{
+ QString elapsedText = MetaDataFormatter::formatDuration(elapsed, false);
+ QString plDurationText;
+ QLabel *label = m_labels[TimeLabel];
+ if(m_core->duration() > 1000)
+ {
+ plDurationText.append("/");
+ plDurationText.append(MetaDataFormatter::formatDuration(m_core->duration()));
+ }
+ if((elapsedText.size() + plDurationText.size()) != label->text().size()) //label width tuning to avoid text jumping
+ {
+ QString tmp = elapsedText;
+ tmp.replace(QRegularExpression("\\d"), "4");
+ int width = label->fontMetrics().horizontalAdvance(tmp + plDurationText);
+ label->setMinimumWidth(width);
+ }
+ label->setText(elapsedText + plDurationText);
+}
diff --git a/src/plugins/Ui/qsui/qsuistatusbar.h b/src/plugins/Ui/qsui/qsuistatusbar.h
new file mode 100644
index 000000000..7e3df26ae
--- /dev/null
+++ b/src/plugins/Ui/qsui/qsuistatusbar.h
@@ -0,0 +1,68 @@
+/***************************************************************************
+ * Copyright (C) 2020 by Ilya Kotov *
+ * forkotov02@ya.ru *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef QSUISTATUSBAR_H
+#define QSUISTATUSBAR_H
+
+#include <QWidget>
+#include <QHash>
+#include <qmmp/audioparameters.h>
+#include <qmmp/qmmp.h>
+
+class QLabel;
+class QFrame;
+class SoundCore;
+class PlayListManager;
+
+class QSUiStatusBar : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit QSUiStatusBar(QWidget *parent = nullptr);
+
+ void updatePlayListStatus();
+
+private slots:
+ void onStateChanged(Qmmp::State state);
+ void onBufferingProgress(int percent);
+ void onAudioParametersChanged(const AudioParameters &ap);
+ void onBitrateChanged(int bitrate);
+ void onElapsedChanged(qint64 elapsed);
+
+private:
+ enum LabelType
+ {
+ StatusLabel = 0,
+ SampleSizeLabel,
+ ChannelsLabel,
+ SampleRateLabel,
+ TrackCountLabel,
+ TotalTimeLabel,
+ BitrateLabel,
+ TimeLabel
+ };
+
+ QHash<LabelType, QLabel*> m_labels;
+ QHash<LabelType, QFrame*> m_separators;
+ SoundCore *m_core;
+ PlayListManager *m_pl_manager;
+};
+
+#endif // QSUISTATUSBAR_H