slideraction.cpp 5.2 KB
Newer Older
1 2 3 4 5 6
/***************************************************************************
                          slideraction.cpp  -  description
                             -------------------
    begin                : Wed Feb 6 2002
    copyright            : (C) 2002 by Scott Wheeler
    email                : scott@slackorama.net
7
***************************************************************************/
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include <klocale.h>
#include <kdebug.h>

#include <qslider.h>
#include <qlabel.h>
#include <qtooltip.h>

#include "slideraction.h"

////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////

SliderAction::SliderAction(const QString &text, QObject *parent, const char *name)
32
    : CustomAction(text, parent, name)
33
{
34

35 36 37 38
}

SliderAction::~SliderAction()
{
39

40 41
}

42
QSlider *SliderAction::getTrackPositionSlider() const
43
{
44 45 46 47
    if(trackPositionSlider)
        return (trackPositionSlider);
    else
        return(0);
48 49
}

50
QSlider *SliderAction::getVolumeSlider() const
51
{
52 53 54 55
    if(volumeSlider)
        return (volumeSlider);
    else
        return(0);
56 57 58
}

////////////////////////////////////////////////////////////////////////////////
59 60 61 62 63
// public slots
////////////////////////////////////////////////////////////////////////////////

void SliderAction::updateOrientation(QDockWindow *dockWindow)
{
64 65 66 67 68 69 70 71 72 73 74 75
    // if the toolbar is not null and either the dockWindow not defined or is the toolbar
    if(customWidget && toolbar && (!dockWindow || dockWindow == dynamic_cast<QDockWindow *>(toolbar))) {
        if(toolbar->barPos() == KToolBar::Right || toolbar->barPos() == KToolBar::Left) {
            trackPositionSlider->setOrientation(Qt::Vertical);
            volumeSlider->setOrientation(Qt::Vertical);
            layout->setDirection(QBoxLayout::TopToBottom);
        }
        else {
            trackPositionSlider->setOrientation(Qt::Horizontal);
            volumeSlider->setOrientation(Qt::Horizontal);
            layout->setDirection(QBoxLayout::LeftToRight);
        }
76
    }
77
    updateSize();
78 79 80 81
}

////////////////////////////////////////////////////////////////////////////////
// private members
82 83 84 85
////////////////////////////////////////////////////////////////////////////////

QWidget *SliderAction::createWidget(QWidget *parent) // virtual -- used by base class
{
86 87
    if(parent) {
        QWidget *base = new QWidget(parent);
88 89
	base->setName("kde toolbar widget");
//	base->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum));
90

91
	layout = new QBoxLayout(base, QBoxLayout::TopToBottom, 5, 5);
92

93
        trackPositionSlider = new QSlider(base, "trackPositionSlider");
94 95 96 97
        trackPositionSlider->setMaxValue(1000);
        QToolTip::add(trackPositionSlider, i18n("Track Position"));
        layout->addWidget(trackPositionSlider);

98
	volumeSlider = new QSlider(base, "volumeSlider" );
99 100 101 102
        volumeSlider->setMaxValue(100);
        QToolTip::add(volumeSlider, i18n("Volume"));
        layout->addWidget(volumeSlider);

103 104 105
	volumeSlider->setName("kde toolbar widget");
        trackPositionSlider->setName("kde toolbar widget");

106 107 108
        layout->setStretchFactor(trackPositionSlider, 4);
        layout->setStretchFactor(volumeSlider, 1);

109
//        setWidget(base);
110 111 112 113 114

        connect(parent, SIGNAL(modechange()), this, SLOT(updateLabels()));
        connect(parent, SIGNAL(modechange()), this, SLOT(updateSize()));
        return(base);
    }
115
    else
116
        return(0);
117 118 119 120 121 122 123 124 125 126 127 128 129
}

////////////////////////////////////////////////////////////////////////////////
// private slots
////////////////////////////////////////////////////////////////////////////////

void SliderAction::updateLabels()
{

}

void SliderAction::updateSize()
{
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
    static const int offset = 3;
    static const int absoluteMax = 10000;

    if(customWidget && toolbar) {
        if(toolbar->barPos() == KToolBar::Right || toolbar->barPos() == KToolBar::Left) {
            volumeSlider->setMaximumWidth(toolbar->iconSize() - offset);
            volumeSlider->setMaximumHeight(volumeMax);

            trackPositionSlider->setMaximumWidth(toolbar->iconSize() - offset);
            trackPositionSlider->setMaximumHeight(absoluteMax);
        }
        else {
            volumeSlider->setMaximumHeight(toolbar->iconSize() - offset);
            volumeSlider->setMaximumWidth(volumeMax);

            trackPositionSlider->setMaximumHeight(toolbar->iconSize() - offset);
            trackPositionSlider->setMaximumWidth(absoluteMax);
        }
        //    kdDebug() << "SliderAction::updateLabels()" << endl;
        //    kdDebug() << toolbar->iconSize() << endl;
150 151 152
    }

}
153
#include "slideraction.moc"