slideraction.cpp 2.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/**
 * Copyright (C) 2002-2004 Scott Wheeler <wheeler@kde.org>
 *
 * 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, see <http://www.gnu.org/licenses/>.
 */
16

17 18
#include "slideraction.h"

19
#include <ktoolbar.h>
20
#include <kiconloader.h>
21
#include <kactioncollection.h>
Michael Pyne's avatar
Michael Pyne committed
22
#include <KLocalizedString>
23

Laurent Montel's avatar
Laurent Montel committed
24 25 26 27
#include <QMouseEvent>
#include <QWheelEvent>
#include <QFocusEvent>
#include <QBoxLayout>
28

29 30 31 32
#include "volumepopupbutton.h"
#include "slider.h"
#include "playermanager.h"
#include "juk.h"
33
#include "juk_debug.h"
34 35

TrackPositionAction::TrackPositionAction(const QString &text, QObject *parent) :
36
    QWidgetAction(parent)
37
{
38
    this->setText(text);
39 40
}

41
QWidget *TrackPositionAction::createWidget(QWidget *parent)
42
{
43 44
    Slider *slider = new TimeSlider(parent);
    slider->setObjectName(QLatin1String("timeSlider"));
45

46
    PlayerManager *player = JuK::JuKInstance()->playerManager();
47

48 49 50 51 52 53 54 55 56
    // TODO only connect the tick signal when actually visible
    connect(player, &PlayerManager::tick, slider, &Slider::setValue);
    connect(player, &PlayerManager::seekableChanged, slider, &Slider::setEnabled);
    connect(player, &PlayerManager::seekableChanged, slider, [slider](bool seekable) {
        static const QString noSeekMsg =
            i18n("Seeking is not supported in this file with your audio settings.");
        slider->setToolTip(seekable ? QString() : noSeekMsg);
    });
    connect(player, &PlayerManager::totalTimeChanged, slider, &Slider::setMaximum);
57
    connect(slider, &Slider::sliderReleased, player, &PlayerManager::seek);
58

59
    return slider;
60 61
}

62 63
VolumeAction::VolumeAction(const QString &text, QObject *parent)
    : QWidgetAction(parent)
64
{
65
    this->setText(text);
66 67
}

68
QWidget *VolumeAction::createWidget(QWidget *parent)
69
{
70
    return new VolumePopupButton(parent);
71 72
}

73
// vim: set et sw=4 tw=0 sta: