diff --git a/kfileaudiopreview/kfileaudiopreview.cpp b/kfileaudiopreview/kfileaudiopreview.cpp index d444fe98..8acf17a1 100644 --- a/kfileaudiopreview/kfileaudiopreview.cpp +++ b/kfileaudiopreview/kfileaudiopreview.cpp @@ -1,150 +1,150 @@ /* This file is part of the KDE libraries Copyright (C) 2003 Carsten Pfeiffer Copyright (C) 2006 Matthias Kretz library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation, version 2. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kfileaudiopreview.h" #include #include #include #include #define TRANSLATION_DOMAIN "kfileaudiopreview5" #include #include #include #include #include #include #include #include #include "mediacontrols.h" #include #include K_PLUGIN_FACTORY(KFileAudioPreviewFactory, registerPlugin();) #define ConfigGroup "Audio Preview Settings" /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// using namespace Phonon; class KFileAudioPreview::Private { public: Private() : player(nullptr) , audioOutput(nullptr) , videoWidget(nullptr) { } MediaObject *player; AudioOutput *audioOutput; VideoWidget *videoWidget; MediaControls *controls; }; KFileAudioPreview::KFileAudioPreview(QWidget *parent, const QVariantList &) : KPreviewWidgetBase(parent) , d(new Private) { setSupportedMimeTypes(BackendCapabilities::availableMimeTypes()); d->audioOutput = new AudioOutput(Phonon::NoCategory, this); d->videoWidget = new VideoWidget(this); d->videoWidget->hide(); d->controls = new MediaControls(this); d->controls->setEnabled(false); d->controls->setAudioOutput(d->audioOutput); m_autoPlay = new QCheckBox(i18n("Play &automatically"), this); KConfigGroup config(KSharedConfig::openConfig(), ConfigGroup); m_autoPlay->setChecked(config.readEntry("Autoplay", false)); connect(m_autoPlay, &QCheckBox::toggled, this, &KFileAudioPreview::toggleAuto); QVBoxLayout *layout = new QVBoxLayout(this); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(d->videoWidget); layout->addWidget(d->controls); layout->addWidget(m_autoPlay, 0, Qt::AlignHCenter); layout->addStretch(); } KFileAudioPreview::~KFileAudioPreview() { KConfigGroup config(KSharedConfig::openConfig(), ConfigGroup); config.writeEntry("Autoplay", m_autoPlay->isChecked()); delete d; } void KFileAudioPreview::stateChanged(Phonon::State newstate, Phonon::State oldstate) { if (oldstate == Phonon::LoadingState && newstate != Phonon::ErrorState) { d->controls->setEnabled(true); } } void KFileAudioPreview::showPreview(const QUrl &url) { d->controls->setEnabled(false); if (!d->player) { d->player = new MediaObject(this); Phonon::createPath(d->player, d->videoWidget); Phonon::createPath(d->player, d->audioOutput); connect(d->player, &MediaObject::stateChanged, this, &KFileAudioPreview::stateChanged); d->videoWidget->setVisible(d->player->hasVideo()); connect(d->player, SIGNAL(hasVideoChanged(bool)), d->videoWidget, SLOT(setVisible(bool))); d->controls->setMediaObject(d->player); } d->player->setCurrentSource(url); if (m_autoPlay->isChecked()) { d->player->play(); } } void KFileAudioPreview::clearPreview() { if (d->player) { delete d->player; d->player = nullptr; d->controls->setEnabled(false); } } void KFileAudioPreview::toggleAuto(bool on) { if (!d->player) { return; } if (on && d->controls->isEnabled()) { d->player->play(); } else { d->player->stop(); } } #include "kfileaudiopreview.moc" diff --git a/kfileaudiopreview/mediacontrols_p.h b/kfileaudiopreview/mediacontrols_p.h index 2672bc24..13560363 100644 --- a/kfileaudiopreview/mediacontrols_p.h +++ b/kfileaudiopreview/mediacontrols_p.h @@ -1,89 +1,89 @@ /* This file is part of the KDE project Copyright (C) 2007 Matthias Kretz This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef PHONON_MEDIACONTROLS_P_H #define PHONON_MEDIACONTROLS_P_H #include "mediacontrols.h" #define TRANSLATION_DOMAIN "kfileaudiopreview5" #include #include #include #include #include #include namespace Phonon { class MediaControlsPrivate { Q_DECLARE_PUBLIC(MediaControls) protected: MediaControlsPrivate(MediaControls *parent) : q_ptr(parent), layout(parent), playButton(parent), pauseButton(parent), seekSlider(parent), volumeSlider(parent), media(nullptr) { int size = parent->style()->pixelMetric(QStyle::PM_ToolBarIconSize); QSize iconSize(size, size); playButton.setIconSize(iconSize); playButton.setIcon(QIcon::fromTheme(QStringLiteral("media-playback-start"))); playButton.setToolTip(i18n("start playback")); playButton.setAutoRaise(true); pauseButton.setIconSize(iconSize); pauseButton.setIcon(QIcon::fromTheme(QStringLiteral("media-playback-pause"))); pauseButton.setToolTip(i18n("pause playback")); pauseButton.hide(); pauseButton.setAutoRaise(true); seekSlider.setIconVisible(false); volumeSlider.setOrientation(Qt::Horizontal); volumeSlider.setMaximumWidth(80); volumeSlider.hide(); - layout.setMargin(0); + layout.setContentsMargins(0, 0, 0, 0); layout.setSpacing(0); layout.addWidget(&playButton); layout.addWidget(&pauseButton); layout.addWidget(&seekSlider, 1); layout.addWidget(&volumeSlider); } MediaControls *q_ptr; QHBoxLayout layout; QToolButton playButton; QToolButton pauseButton; SeekSlider seekSlider; VolumeSlider volumeSlider; MediaObject *media; private: void _k_stateChanged(Phonon::State, Phonon::State); void _k_mediaDestroyed(); void updateVolumeSliderVisibility(); }; } // namespace Phonon #endif // PHONON_MEDIACONTROLS_P_H