]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/util/customwidgets.hpp
Qt: adv settings: Optimize synchronization panel
[vlc] / modules / gui / qt4 / util / customwidgets.hpp
index d1f1f74809fe72f199e58507ea2a52763f1d62e5..0814ca050eda1eb2a573fb0a57397432b22e9e1e 100644 (file)
 #define _CUSTOMWIDGETS_H_
 
 #include <QLineEdit>
+#include <QPushButton>
+#include <QLabel>
+#include <QStackedWidget>
+#include <QSpinBox>
+#include <QList>
+#include <QTimer>
+#include <QToolButton>
 
-/**
-  This class provides a QLineEdit which contains a greyed-out hinting
-  text as long as the user didn't enter any text
+class QPixmap;
 
-  @short LineEdit with customizable "Click here" text
-  @author Daniel Molkentin
-*/
-class ClickLineEdit : public QLineEdit
+class QFramelessButton : public QPushButton
 {
     Q_OBJECT
-    Q_PROPERTY( QString clickMessage READ clickMessage WRITE setClickMessage )
 public:
-    ClickLineEdit( const QString &msg, QWidget *parent );
-    virtual ~ClickLineEdit() {};
-    void setClickMessage( const QString &msg );
-    QString clickMessage() const { return mClickMessage; }
-    virtual void setText( const QString& txt );
+    QFramelessButton( QWidget *parent = NULL );
+    virtual QSize sizeHint() const { return iconSize(); }
 protected:
-    virtual void paintEvent( QPaintEvent *e );
-    virtual void dropEvent( QDropEvent *ev );
-    virtual void focusInEvent( QFocusEvent *ev );
-    virtual void focusOutEvent( QFocusEvent *ev );
-private:
-    QString mClickMessage;
-    bool mDrawClickMsg;
+    virtual void paintEvent( QPaintEvent * event );
 };
 
-class QToolButton;
-class SearchLineEdit : public QFrame
+class QToolButtonExt : public QToolButton
 {
     Q_OBJECT
 public:
-    SearchLineEdit( QWidget *parent );
+    QToolButtonExt( QWidget *parent = 0, int ms = 0 );
+private:
+    bool longClick;
+private slots:
+    void releasedSlot();
+signals:
+    void shortClicked();
+    void longClicked();
+};
 
+class QElidingLabel : public QLabel
+{
+public:
+    QElidingLabel( const QString &s = QString(),
+                      Qt::TextElideMode mode = Qt::ElideRight,
+                      QWidget * parent = NULL );
+    void setElideMode( Qt::TextElideMode );
+protected:
+    virtual void paintEvent( QPaintEvent * event );
 private:
-    ClickLineEdit *searchLine;
-    QToolButton   *clearButton;
+    Qt::TextElideMode elideMode;
+};
 
-private slots:
-    void updateText( const QString& );
 
-signals:
-    void textChanged( const QString& );
+class QVLCStackedWidget : public QStackedWidget
+{
+public:
+    QVLCStackedWidget( QWidget *parent ) : QStackedWidget( parent ) { }
+    QSize minimumSizeHint () const
+    {
+        return currentWidget() ? currentWidget()->minimumSizeHint() : QSize();
+    }
+};
+
+class QVLCDebugLevelSpinBox : public QSpinBox
+{
+    Q_OBJECT
+public:
+    QVLCDebugLevelSpinBox( QWidget *parent ) : QSpinBox( parent ) { };
+protected:
+    virtual QString textFromValue( int ) const;
+    /* QVLCDebugLevelSpinBox is read-only */
+    virtual int valueFromText( const QString& ) const { return -1; }
 };
 
-/*****************************************************************
- * Custom views
- *****************************************************************/
-#include <QMouseEvent>
-#include <QTreeView>
-#include <QCursor>
-#include <QPoint>
-#include <QModelIndex>
-
-/**
-  Special QTreeView that can emit rightClicked()
-  */
-class QVLCTreeView : public QTreeView
+class AnimatedIcon : public QLabel
 {
-    Q_OBJECT;
+    /** An animated pixmap
+     * Use this widget to display an animated icon based on a series of
+     * pixmaps. The pixmaps will be stored in memory and should be kept small.
+     * First, create the widget, add frames and then start playing. Looping
+     * is supported.
+     * Frames #1 to #n are displayed at regular intervals when playing.
+     * Frame #0 is the idle frame, displayed when the icon is not animated.
+     * If not #0 frame has been specified, the last frame will be shown when
+     * idle.
+     **/
+
+    Q_OBJECT
+
 public:
-    void mouseReleaseEvent( QMouseEvent* e )
+    /** Create an empty AnimatedIcon */
+    AnimatedIcon( QWidget *parent );
+    virtual ~AnimatedIcon();
+
+    /** Adds a frame to play in the loop.
+     * @param pixmap The QPixmap to display. Data will be copied internally.
+     * @param index If -1, append the frame. If 0, replace the idle frame.
+     *              Otherwise, insert the frame at the given position.
+     **/
+    void addFrame( const QPixmap &pixmap, int index = -1 );
+
+    /** Play the animation (or restart it)
+     * @param loops Number of times to play the loop. 0 means stop, while -1
+     *              means play forever. When stopped, the frame #0 will be
+     *              displayed until play() is called again.
+     * @param interval Delay between frames, in milliseconds (minimum 20ms)
+     * @note If isPlaying() is true, then restart the animation from frame #1
+     **/
+    void play( int loops = 1, int interval = 200 );
+
+    /** Stop playback. Same as play(0). */
+    inline void stop()
     {
-        if( e->button() & Qt::RightButton )
-        {
-            emit rightClicked( indexAt( QPoint( e->x(), e->y() ) ),
-                               QCursor::pos() );
-        }
-        QTreeView::mouseReleaseEvent( e );
+        play( 0 );
     }
 
-    void mousePressEvent( QMouseEvent* e )
+    /** Is the animation currently running? */
+    inline bool isPlaying()
     {
-        if( e->button() & Qt::LeftButton )
-        {
-            if( !indexAt( QPoint( e->x(), e->y() ) ).isValid() )
-                clearSelection();
-        }
-        QTreeView::mousePressEvent( e );
+        return mTimer.isActive();
     }
 
-signals:
-    void rightClicked( QModelIndex, QPoint  );
+private:
+    QTimer mTimer;
+    QPixmap *mIdleFrame;
+    QList<QPixmap*> mFrames; // Keeps deep copies of all the frames
+    int mCurrentFrame, mRemainingLoops;
+
+private slots:
+    /** Slot connected to the timeout() signal of our internal timer */
+    void onTimerTick();
+};
+
+class SpinningIcon : public AnimatedIcon
+{
+    /** This spinning icon, to the colors of the VLC cone, will show
+     * that there is some background activity running
+     **/
+
+    Q_OBJECT
+
+public:
+    SpinningIcon( QWidget *parent, bool noIdleFrame = false );
 };
 
 /* VLC Key/Wheel hotkeys interactions */
 
 class QKeyEvent;
 class QWheelEvent;
+class QInputEvent;
 
 int qtKeyModifiersToVLC( QInputEvent* e );
 int qtEventToVLCKey( QKeyEvent *e );
 int qtWheelEventToVLCKey( QWheelEvent *e );
-QString VLCKeyToString( int val );
+QString VLCKeyToString( unsigned val );
 
 #endif
-