interface_widgets.hpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*****************************************************************************
  2. * interface_widgets.hpp : Custom widgets for the main interface
  3. ****************************************************************************
  4. * Copyright (C) 2006-2008 the VideoLAN team
  5. * $Id$
  6. *
  7. * Authors: Clément Stenac <zorglub@videolan.org>
  8. * Jean-Baptiste Kempf <jb@videolan.org>
  9. * Rafaël Carré <funman@videolanorg>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  24. *****************************************************************************/
  25. #ifndef VLC_QT_INTERFACE_WIDGETS_HPP_
  26. #define VLC_QT_INTERFACE_WIDGETS_HPP_
  27. #ifdef HAVE_CONFIG_H
  28. # include "config.h"
  29. #endif
  30. #include "main_interface.hpp" /* Interface integration */
  31. #include "input_manager.hpp" /* Speed control */
  32. #include "components/controller.hpp"
  33. #include "components/controller_widget.hpp"
  34. #include "dialogs_provider.hpp"
  35. #include "components/info_panels.hpp"
  36. #include <QWidget>
  37. #include <QFrame>
  38. #include <QLabel>
  39. #include <QMouseEvent>
  40. #include <QPropertyAnimation>
  41. #include <QLinkedList>
  42. class QMenu;
  43. class QSlider;
  44. class QWidgetAction;
  45. class SpeedControlWidget;
  46. struct vout_window_t;
  47. /******************** Video Widget ****************/
  48. class VideoWidget : public QFrame
  49. {
  50. Q_OBJECT
  51. public:
  52. VideoWidget( intf_thread_t * );
  53. virtual ~VideoWidget();
  54. WId request( struct vout_window_t *, unsigned int *, unsigned int *, bool );
  55. void release( void );
  56. void sync( void );
  57. protected:
  58. QPaintEngine *paintEngine() const Q_DECL_OVERRIDE
  59. {
  60. return NULL;
  61. }
  62. virtual void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
  63. void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
  64. void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;
  65. void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE;
  66. void mouseDoubleClickEvent(QMouseEvent *) Q_DECL_OVERRIDE;
  67. private:
  68. int qtMouseButton2VLC( Qt::MouseButton );
  69. intf_thread_t *p_intf;
  70. vout_window_t *p_window;
  71. QWidget *stable;
  72. QLayout *layout;
  73. signals:
  74. void sizeChanged( int, int );
  75. public slots:
  76. void setSize( unsigned int, unsigned int );
  77. };
  78. /******************** Background Widget ****************/
  79. class BackgroundWidget : public QWidget
  80. {
  81. Q_OBJECT
  82. public:
  83. BackgroundWidget( intf_thread_t * );
  84. void setExpandstoHeight( bool b_expand ) { b_expandPixmap = b_expand; }
  85. void setWithArt( bool b_withart_ ) { b_withart = b_withart_; };
  86. private:
  87. intf_thread_t *p_intf;
  88. QString pixmapUrl;
  89. bool b_expandPixmap;
  90. bool b_withart;
  91. QPropertyAnimation *fadeAnimation;
  92. void contextMenuEvent( QContextMenuEvent *event ) Q_DECL_OVERRIDE;
  93. protected:
  94. void paintEvent( QPaintEvent *e ) Q_DECL_OVERRIDE;
  95. void showEvent( QShowEvent * e ) Q_DECL_OVERRIDE;
  96. static const int MARGIN = 5;
  97. QString defaultArt;
  98. public slots:
  99. void toggle(){ TOGGLEV( this ); }
  100. void updateArt( const QString& );
  101. };
  102. class EasterEggBackgroundWidget : public BackgroundWidget
  103. {
  104. Q_OBJECT
  105. public:
  106. EasterEggBackgroundWidget( intf_thread_t * );
  107. virtual ~EasterEggBackgroundWidget();
  108. public slots:
  109. void animate();
  110. protected:
  111. void paintEvent( QPaintEvent *e ) Q_DECL_OVERRIDE;
  112. void showEvent( QShowEvent *e ) Q_DECL_OVERRIDE;
  113. void hideEvent( QHideEvent * ) Q_DECL_OVERRIDE;
  114. void resizeEvent( QResizeEvent * ) Q_DECL_OVERRIDE;
  115. private slots:
  116. void spawnFlakes();
  117. void reset();
  118. private:
  119. struct flake
  120. {
  121. QPoint point;
  122. bool b_fat;
  123. };
  124. QTimer *timer;
  125. QLinkedList<flake *> *flakes;
  126. int i_rate;
  127. int i_speed;
  128. bool b_enabled;
  129. static const int MAX_FLAKES = 1000;
  130. };
  131. #if 0
  132. class VisualSelector : public QFrame
  133. {
  134. Q_OBJECT
  135. public:
  136. VisualSelector( intf_thread_t *);
  137. virtual ~VisualSelector();
  138. private:
  139. intf_thread_t *p_intf;
  140. QLabel *current;
  141. private slots:
  142. void prev();
  143. void next();
  144. };
  145. #endif
  146. class ClickableQLabel : public QLabel
  147. {
  148. Q_OBJECT
  149. public:
  150. void mouseDoubleClickEvent( QMouseEvent *event ) Q_DECL_OVERRIDE
  151. {
  152. Q_UNUSED( event );
  153. emit doubleClicked();
  154. }
  155. signals:
  156. void doubleClicked();
  157. };
  158. class TimeLabel : public ClickableQLabel
  159. {
  160. Q_OBJECT
  161. public:
  162. enum Display
  163. {
  164. Elapsed,
  165. Remaining,
  166. Both
  167. };
  168. TimeLabel( intf_thread_t *_p_intf, TimeLabel::Display _displayType = TimeLabel::Both );
  169. protected:
  170. void mousePressEvent( QMouseEvent *event ) Q_DECL_OVERRIDE
  171. {
  172. if( displayType == TimeLabel::Elapsed ) return;
  173. toggleTimeDisplay();
  174. event->accept();
  175. }
  176. void mouseDoubleClickEvent( QMouseEvent *event ) Q_DECL_OVERRIDE
  177. {
  178. if( displayType != TimeLabel::Both ) return;
  179. event->accept();
  180. toggleTimeDisplay();
  181. ClickableQLabel::mouseDoubleClickEvent( event );
  182. }
  183. private:
  184. intf_thread_t *p_intf;
  185. bool b_remainingTime;
  186. int cachedLength;
  187. TimeLabel::Display displayType;
  188. char psz_length[MSTRTIME_MAX_SIZE];
  189. char psz_time[MSTRTIME_MAX_SIZE];
  190. void toggleTimeDisplay();
  191. private slots:
  192. void setRemainingTime( bool );
  193. void setDisplayPosition( float pos, int64_t time, int length );
  194. void setDisplayPosition( float pos );
  195. signals:
  196. void broadcastRemainingTime( bool );
  197. };
  198. class SpeedLabel : public QLabel
  199. {
  200. Q_OBJECT
  201. public:
  202. SpeedLabel( intf_thread_t *, QWidget * );
  203. virtual ~SpeedLabel();
  204. protected:
  205. void mousePressEvent ( QMouseEvent * event ) Q_DECL_OVERRIDE
  206. {
  207. showSpeedMenu( event->pos() );
  208. }
  209. private slots:
  210. void showSpeedMenu( QPoint );
  211. void setRate( float );
  212. private:
  213. intf_thread_t *p_intf;
  214. QMenu *speedControlMenu;
  215. QString tooltipStringPattern;
  216. SpeedControlWidget *speedControl;
  217. QWidgetAction *widgetAction;
  218. };
  219. /******************** Speed Control Widgets ****************/
  220. class SpeedControlWidget : public QFrame
  221. {
  222. Q_OBJECT
  223. public:
  224. SpeedControlWidget( intf_thread_t *, QWidget * );
  225. void updateControls( float );
  226. private:
  227. intf_thread_t* p_intf;
  228. QSlider* speedSlider;
  229. QDoubleSpinBox* spinBox;
  230. int lastValue;
  231. public slots:
  232. void activateOnState();
  233. private slots:
  234. void updateRate( int );
  235. void updateSpinBoxRate( double );
  236. void resetRate();
  237. };
  238. class CoverArtLabel : public QLabel
  239. {
  240. Q_OBJECT
  241. public:
  242. CoverArtLabel( QWidget *parent, intf_thread_t * );
  243. void setItem( input_item_t * );
  244. virtual ~CoverArtLabel();
  245. protected:
  246. void mouseDoubleClickEvent( QMouseEvent *event ) Q_DECL_OVERRIDE
  247. {
  248. if( ! p_item && qobject_cast<MetaPanel *>(this->window()) == NULL )
  249. {
  250. THEDP->mediaInfoDialog();
  251. }
  252. event->accept();
  253. }
  254. private:
  255. intf_thread_t *p_intf;
  256. input_item_t *p_item;
  257. public slots:
  258. void showArtUpdate( const QString& );
  259. void showArtUpdate( input_item_t * );
  260. void askForUpdate();
  261. void setArtFromFile();
  262. void clear();
  263. };
  264. #endif