]> git.sesse.net Git - vlc/blob - modules/gui/qt4/util/qvlcframe.hpp
Fix a number of problems with interaction dialogs
[vlc] / modules / gui / qt4 / util / qvlcframe.hpp
1 /*****************************************************************************
2  * qvlcframe.hpp : A few helpers
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/
22
23 #ifndef _QVLCFRAME_H_
24 #define _QVLCFRAME_H_
25
26 #include <QWidget>
27 #include <QSpacerItem>
28 #include <QHBoxLayout>
29 #include <QApplication>
30 #include <QSettings>
31 #include <QMainWindow>
32 #include <QPlastiqueStyle>
33 #include <QPushButton>
34 #include "qt4.hpp"
35 #include <vlc/vlc.h>
36
37 class QVLCFrame : public QWidget
38 {
39 public:
40     static void fixStyle( QWidget *w)
41     {
42          QStyle *style = qApp->style();
43 #if 0
44         // Plastique is too dark.
45         /// theming ? getting KDE data ? ?
46         if( qobject_cast<QPlastiqueStyle *>(style) )
47         {
48             QPalette plt( w->palette() );
49             plt.setColor( QPalette::Active, QPalette::Highlight, Qt::gray );
50             QColor vlg = (Qt::lightGray);
51             vlg = vlg.toHsv();
52             vlg.setHsv( vlg.hue(), vlg.saturation(), 235  );
53             plt.setColor( QPalette::Active, QPalette::Window, vlg );
54             plt.setColor( QPalette::Inactive, QPalette::Window, vlg );
55             plt.setColor( QPalette::Inactive, QPalette::Button, vlg );
56             plt.setColor( QPalette::Active, QPalette::Button, vlg );
57             plt.setColor( QPalette::Active, QPalette::Text, Qt::yellow );
58             w->setPalette( plt );
59         }
60 #endif
61     }
62     static QHBoxLayout* doButtons( QWidget *w, QBoxLayout *l,
63                                QPushButton **defaul, char *psz_default,
64                                QPushButton **alt, char *psz_alt,
65                                QPushButton **other, char *psz_other )
66     {
67 #ifdef QT42
68         fprintf( stderr, "Gra\n" );
69 #else
70         QHBoxLayout *buttons_layout = new QHBoxLayout;
71         QSpacerItem *spacerItem = new QSpacerItem( 40, 20,
72                                QSizePolicy::Expanding, QSizePolicy::Minimum);
73         buttons_layout->addItem( spacerItem );
74
75         if( psz_default )
76         {
77             fprintf( stderr, "Creating default button %s\n", psz_default );
78             *defaul = new QPushButton(0);
79             (*defaul)->setFocus();
80             buttons_layout->addWidget( *defaul );
81             (*defaul)->setText( qfu( psz_default ) );
82         }
83         if( psz_alt )
84         {
85             *alt = new QPushButton(0);
86             buttons_layout->addWidget( *alt );
87             (*alt)->setText( qfu( psz_alt ) );
88         }
89         if( psz_other )
90         {
91             *other = new QPushButton( 0 );
92             buttons_layout->addWidget( *other );
93             (*other)->setText( qfu( psz_other ) );
94         }
95         if( l )
96             l->addLayout( buttons_layout );
97 #endif
98         return buttons_layout;
99     };
100
101     QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL ), p_intf( _p_intf )
102     {
103         fixStyle( this );
104     };
105     virtual ~QVLCFrame()   {};
106
107     void toggleVisible()
108     {
109         if( isVisible() ) hide();
110         else show();
111     }
112 protected:
113     intf_thread_t *p_intf;
114
115     void readSettings( QString name, QSize defSize )
116     {
117         QSettings settings( "VideoLAN", "VLC" );
118         settings.beginGroup( name );
119         resize( settings.value( "size", defSize ).toSize() );
120         move( settings.value( "pos", QPoint( 0,0 ) ).toPoint() );
121         settings.endGroup();
122     }
123     void writeSettings( QString name )
124     {
125         QSettings settings( "VideoLAN", "VLC" );
126         settings.beginGroup( name );
127         settings.setValue ("size", size() );
128         settings.setValue( "pos", pos() );
129         settings.endGroup();
130     }
131 };
132
133 class QVLCMW : public QMainWindow
134 {
135 public:
136     QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf )
137     {
138         QVLCFrame::fixStyle( this );
139     }
140     virtual ~QVLCMW() {};
141     void toggleVisible()
142     {
143         if( isVisible() ) hide();
144         else show();
145     }
146 protected:
147     intf_thread_t *p_intf;
148     QSize mainSize;
149
150     void readSettings( QString name, QSize defSize )
151     {
152         QSettings settings( "VideoLAN", "VLC" );
153         settings.beginGroup( name );
154       QSize s =  settings.value( "size", defSize ).toSize() ;
155       fprintf( stderr, "%i %i ", s.width(), s.height() );
156         move( settings.value( "pos", QPoint( 0,0 ) ).toPoint() );
157         settings.endGroup();
158     }
159     void readSettings( QString name )
160     {
161         QSettings settings( "VideoLAN", "VLC" );
162         settings.beginGroup( name );
163         mainSize = settings.value( "size", QSize( 0,0 ) ).toSize();
164         settings.endGroup();
165     }
166     void writeSettings( QString name )
167     {
168         QSettings settings( "VideoLAN", "VLC" );
169         settings.beginGroup( name );
170         settings.setValue ("size", size() );
171         settings.setValue( "pos", pos() );
172         settings.endGroup();
173     }
174 };
175
176 #endif