Commit cf6e31e3 authored by Julius Künzel's avatar Julius Künzel
Browse files

[Monitors] Improve audio volume widget

parent 937ff419
Pipeline #139802 passed with stage
in 10 minutes and 45 seconds
......@@ -107,6 +107,43 @@ bool QuickEventEater::eventFilter(QObject *obj, QEvent *event)
return QObject::eventFilter(obj, event);
}
VolumeAction::VolumeAction(QObject *parent)
: QWidgetAction(parent)
{
}
QWidget *VolumeAction::createWidget(QWidget *parent)
{
auto *hlay = new QHBoxLayout(parent);
auto *iconLabel = new QLabel();
iconLabel->setToolTip(i18n("Audio volume"));
auto *slider = new QSlider(Qt::Horizontal, parent);
slider->setRange(0, 100);
auto *percentLabel = new QLabel(parent);
connect(slider, &QSlider::valueChanged, this, [percentLabel, iconLabel](int value){
percentLabel->setText(i18n("%1%", value));
int h = 16;
QString iconName(QStringLiteral("audio-volume-high"));
if (value == 0) {
iconName = QStringLiteral("audio-volume-muted");
} else if (value < 33) {
iconName = QStringLiteral("audio-volume-low");
} else if (value < 66) {
iconName = QStringLiteral("audio-volume-medium");
}
iconLabel->setPixmap(QIcon::fromTheme(iconName).pixmap(h, h));
});
slider->setValue(KdenliveSettings::volume());
connect(slider, &QSlider::valueChanged, this, &VolumeAction::volumeChanged);
hlay->addWidget(iconLabel);
hlay->addWidget(slider);
hlay->addWidget(percentLabel);
auto w = new QWidget(parent);
w->setLayout(hlay);
return w;
}
Monitor::Monitor(Kdenlive::MonitorId id, MonitorManager *manager, QWidget *parent)
: AbstractMonitor(id, manager, parent)
, m_controller(nullptr)
......@@ -358,7 +395,9 @@ Monitor::Monitor(Kdenlive::MonitorId id, MonitorManager *manager, QWidget *paren
playButton->setDefaultAction(m_playAction);
m_configMenu = new QMenu(i18n("Misc…"), this);
auto *volumeAction = new VolumeAction(this);
connect(volumeAction, &VolumeAction::volumeChanged, this, &Monitor::slotSetVolume);
m_configMenu->addAction(volumeAction);
if (id == Kdenlive::ClipMonitor) {
m_markerMenu = new QMenu(i18n("Go to Marker…"), this);
......@@ -379,19 +418,6 @@ Monitor::Monitor(Kdenlive::MonitorId id, MonitorManager *manager, QWidget *paren
m_forceSize->setCurrentAction(freeAction);
connect(m_forceSize, static_cast<void (KSelectAction::*)(QAction *)>(&KSelectAction::triggered), this, &Monitor::slotForceSize);
// Create Volume slider popup
m_audioSlider = new QSlider(Qt::Vertical);
m_audioSlider->setRange(0, 100);
m_audioSlider->setValue(KdenliveSettings::volume());
connect(m_audioSlider, &QSlider::valueChanged, this, &Monitor::slotSetVolume);
auto *widgetslider = new QWidgetAction(this);
widgetslider->setText(i18n("Audio volume"));
widgetslider->setDefaultWidget(m_audioSlider);
auto *menu = new QMenu(i18n("Volume"), this);
menu->setIcon(QIcon::fromTheme(QStringLiteral("audio-volume-medium")));
menu->addAction(widgetslider);
m_configMenu->addMenu(menu);
if (m_id == Kdenlive::ClipMonitor) {
m_background = new KSelectAction(QIcon::fromTheme(QStringLiteral("paper-color")), i18n("Background Color"), this);
QAction *blackAction = m_background->addAction(QIcon(), i18n("Black"));
......@@ -414,14 +440,6 @@ Monitor::Monitor(Kdenlive::MonitorId id, MonitorManager *manager, QWidget *paren
});
}
/*QIcon icon;
if (KdenliveSettings::volume() == 0) {
icon = QIcon::fromTheme(QStringLiteral("audio-volume-muted"));
} else {
icon = QIcon::fromTheme(QStringLiteral("audio-volume-medium"));
}
m_audioButton->setIcon(icon);*/
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
setLayout(layout);
setMinimumHeight(200);
......
......@@ -16,6 +16,7 @@ SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#include <QTimer>
#include <QToolBar>
#include <QWidgetAction>
#include <memory>
#include <unordered_set>
......@@ -55,6 +56,17 @@ signals:
void doKeyPressEvent(QKeyEvent *);
};
class VolumeAction : public QWidgetAction
{
Q_OBJECT
public:
explicit VolumeAction(QObject *parent);
QWidget *createWidget(QWidget *parent) override;
signals:
void volumeChanged(int volume);
};
class Monitor : public AbstractMonitor
{
......@@ -212,7 +224,6 @@ private:
QAction *m_fiveLess;
QAction *m_fiveMore;
QLabel *m_trimmingOffset;
QSlider *m_audioSlider;
QAction *m_editMarker;
KMessageWidget *m_infoMessage;
int m_forceSizeFactor;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment