summaryrefslogtreecommitdiffstats
path: root/src/app/videoSettings.cpp
blob: 945e4d3f74c5858d0841ad07a891bc99a640f6e3 (plain)
1
2
3
4
5
6
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// (C) 2005 Max Howell ([email protected])
// See COPYING file for licensing information

#include <kwin.h>
#include "mxcl.library.h"
#include <qlabel.h>
#include <qlayout.h>
#include <qslider.h>
#include "videoSettings.h"
#include <xine.h>
#include "xineEngine.h"

extern "C"
{
   // #include <X11/Xlib.h> is just dangerous! Here, there is a macro for Below that conflicts
   // with QSlider::Below. Stupid X11 people.
   typedef unsigned long XID;
   typedef XID Window;
   extern int XSetTransientForHint( Display*, Window, Window );
}


//TODO update from engine when new video is played
//TODO show a warning that when paused the changes aren't updated to the display, show an unpause button too


class SnapSlider : public QSlider
{
   int m_offset;

public:
   SnapSlider( const int value, QWidget *parent, const char *name )
         : QSlider( (65536/4)-1, (3*(65536/4))-1, 1000, value, Qt::Horizontal, parent, name )
         , m_offset( 0 )
   {
      setTickmarks( QSlider::Below );
      setTickInterval( 65536 / 4 );
      setMinimumWidth( fontMetrics().width( name ) * 3 );
      connect( this, SIGNAL(valueChanged( int )), Codeine::engine(), SLOT(setStreamParameter( int )) );
   }

   virtual void mousePressEvent( QMouseEvent *e )
   {
      m_offset = e->pos().x() - (sliderStart() + (sliderRect().width()/2));
      QSlider::mousePressEvent( e );
   }

   virtual void mouseMoveEvent( QMouseEvent *e )
   {
      const int MIDDLE = width() / 2;
      const int x = e->pos().x() - m_offset;
      const int F = sliderRect().width() / 2;

      if( x > MIDDLE - F && x < MIDDLE + F ) {
         QMouseEvent e2( e->type(), QPoint( MIDDLE + m_offset, e->pos().y() ), e->button(), e->state() );
         QSlider::mouseMoveEvent( &e2 );
         QRangeControl::setValue( 65536 / 2 - 1 ); // to ensure we are absolutely exact
      }
      else
         QSlider::mouseMoveEvent( e );
   }
};


Codeine::VideoSettingsDialog::VideoSettingsDialog( QWidget *parent )
      : KDialog( parent, "video_settings_dialog", false, WType_TopLevel | WDestructiveClose )
{
   XSetTransientForHint( x11Display(), winId(), parent->winId() );
   KWin::setType( winId(), NET::Utility );
   KWin::setState( winId(), NET::SkipTaskbar );

   QFrame *frame = new QFrame( this );
   (new QVBoxLayout( this, 10 ))->addWidget( frame );
   frame->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
   frame->setPaletteBackgroundColor( backgroundColor().dark( 102 ) );

   QGridLayout *grid = new QGridLayout( frame, 4, 2, 15, 10 );
   grid->setAutoAdd( true );

   #define makeSlider( PARAM, name ) \
            new QLabel( name, frame ); \
            new SnapSlider( xine_get_param( *Codeine::engine(), PARAM ), frame, name );

   makeSlider( XINE_PARAM_VO_BRIGHTNESS, "brightness" );
   makeSlider( XINE_PARAM_VO_CONTRAST, "contrast" );
   makeSlider( XINE_PARAM_VO_SATURATION, "saturation" );
   makeSlider( XINE_PARAM_VO_HUE, "hue" );

   #undef makeSlider

   setCaption( i18n("Video Settings") );
   setMaximumSize( sizeHint().width() * 5, sizeHint().height() );

   KDialog::show();
}

void
Codeine::VideoSettingsDialog::stateChanged( QWidget *parent, Engine::State state ) //static
{
   QWidget *me = (QWidget*)parent->child( "video_settings_dialog" );

   if( !me )
      return;

   switch( state )
   {
   case Engine::Playing:
   case Engine::Paused:
      me->setEnabled( true );
      break;

   case Engine::Loaded:
      #define update( param, name ) static_cast<QSlider*>(me->child( name ))->setValue( xine_get_param( *Codeine::engine(), param ) );
      update( XINE_PARAM_VO_BRIGHTNESS, "brightness" );
      update( XINE_PARAM_VO_CONTRAST, "contrast" );
      update( XINE_PARAM_VO_SATURATION, "saturation" );
      update( XINE_PARAM_VO_HUE, "hue" );
      #undef update

   default:
      me->setEnabled( false );
      break;
   }
}

namespace Codeine
{
   void showVideoSettingsDialog( QWidget *parent )
   {
      // ensure that the dialog is shown by deleting the old one
      delete parent->child( "video_settings_dialog" );

      new VideoSettingsDialog( parent );
   }
}