[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-panel-devel
Subject:    Re: Review Request: Add a Plasma::Slider widget
From:       Alex Merry <huntedhacker () tiscali ! co ! uk>
Date:       2008-07-28 23:27:02
Message-ID: 200807290027.06995.huntedhacker () tiscali ! co ! uk
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


On Monday 28 July 2008 23:25:21 Aaron J. Seigo wrote:
> On Monday 28 July 2008, Alex Merry wrote:
> > -----------------------------------------------------------
> > This is an automatically generated e-mail. To reply, visit:
> > http://reviewboard.vidsolbach.de/r/115/
> > -----------------------------------------------------------
> >
> > Review request for Plasma.
> >
> >
> > Summary
> > -------
> >
> > Wraps the QSlider widget.
> >
> > Design decisions (or what I left out):
> >
> > Didn't bother with any of the "inverted" stuff, stepping or
> > enabling/disabling tracking. Also, no simulating user interaction with
> > the slider (setSliderDown(), etc). No action interface
> > No rangeChanged() signal (since the user can't change it directly)
> > No tick interface, but that can be added later if there's need
> > Made setMinimum() and setMaximum() slots, since I have an immediate use
> > for setMaximum as a slot.
> >
> >
> > Diffs
> > -----
> >
> >   KDE/kdebase/workspace/libs/plasma/CMakeLists.txt
> >   KDE/kdebase/workspace/libs/plasma/includes/Slider
> >   KDE/kdebase/workspace/libs/plasma/widgets/slider.h
> >   KDE/kdebase/workspace/libs/plasma/widgets/slider.cpp
> >
> > Diff: http://reviewboard.vidsolbach.de/r/115/diff
>
> hrm.. review-board seems broken, or at least this patch upload is =((

Hmm... I updated the patch before publishing.  Maybe that was it.

>
> do you want to post the slider.h here?
>
> > Added sliders to the nowplaying applet actually do something when
> > dragged.

Done.  As you might imagine, the .cpp file is somewhat uninteresting.  But 
I've attached the diff as well in case you want to check I haven't done 
anything stupid.

Alex


-- 
KDE: http://www.kde.org
Ubuntu/Kubuntu: http://www.ubuntu.org http://www.kubuntu.org


["plasma-widgets-slider.diff" (text/x-patch)]

Index: includes/Slider
===================================================================
--- includes/Slider	(revision 0)
+++ includes/Slider	(revision 0)
@@ -0,0 +1 @@
+#include "../../plasma/widgets/slider.h"
Index: widgets/slider.cpp
===================================================================
--- widgets/slider.cpp	(revision 0)
+++ widgets/slider.cpp	(revision 0)
@@ -0,0 +1,145 @@
+/*
+ *   Copyright 2008 Aaron Seigo <aseigo@kde.org>
+ *
+ *   This program 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; either version 2, 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 Library 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 "slider.h"
+
+#include <QSlider>
+#include <QPainter>
+
+#include <KMimeType>
+
+#include "theme.h"
+#include "svg.h"
+
+namespace Plasma
+{
+
+class SliderPrivate
+{
+public:
+    SliderPrivate()
+    {
+    }
+
+    ~SliderPrivate()
+    {
+    }
+};
+
+
+Slider::Slider(Qt::Orientation orientation, QGraphicsWidget *parent)
+    : QGraphicsProxyWidget(parent),
+      d(0)
+{
+    QSlider* native = new QSlider;
+
+    connect(native, SIGNAL(sliderPressed()), this, SIGNAL(sliderPressed()));
+    connect(native, SIGNAL(sliderReleased()), this, SIGNAL(sliderReleased()));
+    connect(native, SIGNAL(sliderMoved(int)), this, SIGNAL(sliderMoved(int)));
+    connect(native, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
+
+    setWidget(native);
+    native->setAttribute(Qt::WA_NoSystemBackground);
+    native->setOrientation(orientation);
+}
+
+Slider::Slider(QGraphicsWidget *parent)
+    : QGraphicsProxyWidget(parent),
+      d(0)
+{
+    QSlider* native = new QSlider;
+
+    connect(native, SIGNAL(sliderPressed()), this, SIGNAL(sliderPressed()));
+    connect(native, SIGNAL(sliderReleased()), this, SIGNAL(sliderReleased()));
+    connect(native, SIGNAL(sliderMoved(int)), this, SIGNAL(sliderMoved(int)));
+    connect(native, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
+
+    setWidget(native);
+    native->setAttribute(Qt::WA_NoSystemBackground);
+}
+
+Slider::~Slider()
+{
+    delete d;
+}
+
+void Slider::setMaximum(int max)
+{
+    static_cast<QSlider*>(widget())->setMaximum(max);
+}
+
+int Slider::maximum() const
+{
+    return static_cast<QSlider*>(widget())->maximum();
+}
+
+void Slider::setMinimum(int min)
+{
+    static_cast<QSlider*>(widget())->setMinimum(min);
+}
+
+int Slider::minimum() const
+{
+    return static_cast<QSlider*>(widget())->minimum();
+}
+
+void Slider::setRange(int min, int max)
+{
+    static_cast<QSlider*>(widget())->setRange(min, max);
+}
+
+void Slider::setValue(int value)
+{
+    static_cast<QSlider*>(widget())->setValue(value);
+}
+
+int Slider::value() const
+{
+    return static_cast<QSlider*>(widget())->value();
+}
+
+void Slider::setOrientation(Qt::Orientation orientation)
+{
+    static_cast<QSlider*>(widget())->setOrientation(orientation);
+}
+
+Qt::Orientation Slider::orientation() const
+{
+    return static_cast<QSlider*>(widget())->orientation();
+}
+
+void Slider::setStyleSheet(const QString &stylesheet)
+{
+    widget()->setStyleSheet(stylesheet);
+}
+
+QString Slider::styleSheet()
+{
+    return widget()->styleSheet();
+}
+
+QSlider* Slider::nativeWidget() const
+{
+    return static_cast<QSlider*>(widget());
+}
+
+} // namespace Plasma
+
+#include <slider.moc>
+
Index: widgets/slider.h
===================================================================
--- widgets/slider.h	(revision 0)
+++ widgets/slider.h	(revision 0)
@@ -0,0 +1,155 @@
+/*
+ *   Copyright 2008 Aaron Seigo <aseigo@kde.org>
+ *
+ *   This program 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; either version 2, 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 Library 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 PLASMA_SLIDER_H
+#define PLASMA_SLIDER_H
+
+#include <QtGui/QGraphicsProxyWidget>
+
+#include <plasma/plasma_export.h>
+
+class QSlider;
+
+namespace Plasma
+{
+
+class SliderPrivate;
+
+class PLASMA_EXPORT Slider : public QGraphicsProxyWidget
+{
+    Q_OBJECT
+
+    Q_PROPERTY(QGraphicsWidget* parentWidget READ parentWidget)
+    Q_PROPERTY(int maximum READ maximum WRITE setMinimum)
+    Q_PROPERTY(int minimum READ minimum WRITE setMinimum)
+    Q_PROPERTY(int value READ value WRITE setValue)
+    Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
+    Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
+    Q_PROPERTY(QSlider* nativeWidget READ nativeWidget)
+
+public:
+    explicit Slider(Qt::Orientation orientation = Qt::Vertical,
+                    QGraphicsWidget *parent = 0);
+    explicit Slider(QGraphicsWidget *parent = 0);
+    ~Slider();
+
+    /**
+     * @return the maximum value
+     */
+    int maximum() const;
+
+    /**
+     * @return the minimum value
+     */
+    int minimum() const;
+
+    /**
+     * @return the current value
+     */
+    int value() const;
+
+    /**
+     * @return the orientation of the slider
+     */
+    Qt::Orientation orientation() const;
+
+    /**
+     * Sets the stylesheet used to control the visual display of this Slider
+     *
+     * @arg stylesheet a CSS string
+     */
+    void setStyleSheet(const QString &stylesheet);
+
+    /**
+     * @return the stylesheet currently used with this widget
+     */
+    QString styleSheet();
+
+    /**
+     * @return the native widget wrapped by this Slider
+     */
+    QSlider* nativeWidget() const;
+
+public Q_SLOTS:
+    /**
+     * Sets the maximum value the slider can take.
+     */
+    void setMaximum(int maximum);
+
+    /**
+     * Sets the minimum value the slider can take.
+     */
+    void setMinimum(int minimum);
+
+    /**
+     * Sets the minimum and maximum values the slider can take.
+     */
+    void setRange(int minimum, int maximum);
+
+    /**
+     * Sets the value of the slider.
+     *
+     * If it is outside the range specified by minimum() and maximum(),
+     * it will be adjusted to fit.
+     */
+    void setValue(int value);
+
+    /**
+     * Sets the orientation of the slider.
+     */
+    void setOrientation(Qt::Orientation orientation);
+
+Q_SIGNALS:
+    /**
+     * This signal is emitted when the user presses the slider with the mouse.
+     *
+     * It is also emitted when setSliderDown(true) is called on the native widget.
+     */
+    void sliderPressed();
+
+    /**
+     * This signal is emitted when the user releases the slider with the mouse.
+     *
+     * It is also emitted when setSliderDown(false) is called on the native widget.
+     */
+    void sliderReleased();
+
+    /**
+     * This signal is emitted when the user drags the slider.
+     *
+     * In fact, it is emitted whenever the sliderMoved(int) signal
+     * of QSlider would be emitted.  See the Qt documentation for
+     * more information.
+     */
+    void sliderMoved(int value);
+
+    /**
+     * This signal is emitted when the slider value has changed,
+     * with the new slider value as argument.
+     */
+    void valueChanged(int value);
+
+private:
+    SliderPrivate * const d;
+};
+
+} // namespace Plasma
+
+#endif // multiple inclusion guard
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 838628)
+++ CMakeLists.txt	(working copy)
@@ -74,6 +74,7 @@ set(plasma_LIB_SRCS
     widgets/pushbutton.cpp
     widgets/radiobutton.cpp
     widgets/signalplotter.cpp
+    widgets/slider.cpp
     widgets/textedit.cpp
     widgets/webcontent.cpp
 )
@@ -173,6 +174,7 @@ install(FILES
     widgets/pushbutton.h
     widgets/radiobutton.h
     widgets/signalplotter.h
+    widgets/slider.h
     widgets/textedit.h
     widgets/webcontent.h
     DESTINATION ${INCLUDE_INSTALL_DIR}/plasma/widgets COMPONENT Devel)
@@ -231,6 +233,7 @@ includes/ScriptEngine
 includes/Service
 includes/ServiceJob
 includes/SignalPlotter
+includes/Slider
 includes/Svg
 includes/TextEdit
 includes/ToolTipManager

["slider.h" (text/x-chdr)]

/*
 *   Copyright 2008 Aaron Seigo <aseigo@kde.org>
 *
 *   This program 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; either version 2, 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 Library 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 PLASMA_SLIDER_H
#define PLASMA_SLIDER_H

#include <QtGui/QGraphicsProxyWidget>

#include <plasma/plasma_export.h>

class QSlider;

namespace Plasma
{

class SliderPrivate;

class PLASMA_EXPORT Slider : public QGraphicsProxyWidget
{
    Q_OBJECT

    Q_PROPERTY(QGraphicsWidget* parentWidget READ parentWidget)
    Q_PROPERTY(int maximum READ maximum WRITE setMinimum)
    Q_PROPERTY(int minimum READ minimum WRITE setMinimum)
    Q_PROPERTY(int value READ value WRITE setValue)
    Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
    Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
    Q_PROPERTY(QSlider* nativeWidget READ nativeWidget)

public:
    explicit Slider(Qt::Orientation orientation = Qt::Vertical,
                    QGraphicsWidget *parent = 0);
    explicit Slider(QGraphicsWidget *parent = 0);
    ~Slider();

    /**
     * @return the maximum value
     */
    int maximum() const;

    /**
     * @return the minimum value
     */
    int minimum() const;

    /**
     * @return the current value
     */
    int value() const;

    /**
     * @return the orientation of the slider
     */
    Qt::Orientation orientation() const;

    /**
     * Sets the stylesheet used to control the visual display of this Slider
     *
     * @arg stylesheet a CSS string
     */
    void setStyleSheet(const QString &stylesheet);

    /**
     * @return the stylesheet currently used with this widget
     */
    QString styleSheet();

    /**
     * @return the native widget wrapped by this Slider
     */
    QSlider* nativeWidget() const;

public Q_SLOTS:
    /**
     * Sets the maximum value the slider can take.
     */
    void setMaximum(int maximum);

    /**
     * Sets the minimum value the slider can take.
     */
    void setMinimum(int minimum);

    /**
     * Sets the minimum and maximum values the slider can take.
     */
    void setRange(int minimum, int maximum);

    /**
     * Sets the value of the slider.
     *
     * If it is outside the range specified by minimum() and maximum(),
     * it will be adjusted to fit.
     */
    void setValue(int value);

    /**
     * Sets the orientation of the slider.
     */
    void setOrientation(Qt::Orientation orientation);

Q_SIGNALS:
    /**
     * This signal is emitted when the user presses the slider with the mouse.
     *
     * It is also emitted when setSliderDown(true) is called on the native widget.
     */
    void sliderPressed();

    /**
     * This signal is emitted when the user releases the slider with the mouse.
     *
     * It is also emitted when setSliderDown(false) is called on the native widget.
     */
    void sliderReleased();

    /**
     * This signal is emitted when the user drags the slider.
     *
     * In fact, it is emitted whenever the sliderMoved(int) signal
     * of QSlider would be emitted.  See the Qt documentation for
     * more information.
     */
    void sliderMoved(int value);

    /**
     * This signal is emitted when the slider value has changed,
     * with the new slider value as argument.
     */
    void valueChanged(int value);

private:
    SliderPrivate * const d;
};

} // namespace Plasma

#endif // multiple inclusion guard

["signature.asc" (application/pgp-signature)]

_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic