]> git.sesse.net Git - vlc/blob - modules/gui/qt4/util/qvlcframe.hpp
qt4: i really like readable debug output
[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 #include <charset.h>
37
38 class QVLCFrame : public QWidget
39 {
40 public:
41     static void fixStyle( QWidget *w)
42     {
43          QStyle *style = qApp->style();
44 #if 0
45         // Plastique is too dark.
46         /// theming ? getting KDE data ? ?
47         if( qobject_cast<QPlastiqueStyle *>(style) )
48         {
49             QPalette plt( w->palette() );
50             plt.setColor( QPalette::Active, QPalette::Highlight, Qt::gray );
51             QColor vlg = (Qt::lightGray);
52             vlg = vlg.toHsv();
53             vlg.setHsv( vlg.hue(), vlg.saturation(), 235  );
54             plt.setColor( QPalette::Active, QPalette::Window, vlg );
55             plt.setColor( QPalette::Inactive, QPalette::Window, vlg );
56             plt.setColor( QPalette::Inactive, QPalette::Button, vlg );
57             plt.setColor( QPalette::Active, QPalette::Button, vlg );
58             plt.setColor( QPalette::Active, QPalette::Text, Qt::yellow );
59             w->setPalette( plt );
60         }
61 #endif
62     }
63     static QHBoxLayout* doButtons( QWidget *w, QBoxLayout *l,
64                                QPushButton **defaul, char *psz_default,
65                                QPushButton **alt, char *psz_alt,
66                                QPushButton **other, char *psz_other )
67     {
68 #ifdef QT42
69         fprintf( stderr, "Gra\n" );
70 #else
71         QHBoxLayout *buttons_layout = new QHBoxLayout;
72         QSpacerItem *spacerItem = new QSpacerItem( 40, 20,
73                                QSizePolicy::Expanding, QSizePolicy::Minimum);
74         buttons_layout->addItem( spacerItem );
75
76         if( psz_default )
77         {
78             utf8_fprintf( stderr, "Creating default button %s\n", psz_default );
79             *defaul = new QPushButton(0);
80             (*defaul)->setFocus();
81             buttons_layout->addWidget( *defaul );
82             (*defaul)->setText( qfu( psz_default ) );
83         }
84         if( psz_alt )
85         {
86             *alt = new QPushButton(0);
87             buttons_layout->addWidget( *alt );
88             (*alt)->setText( qfu( psz_alt ) );
89         }
90         if( psz_other )
91         {
92             *other = new QPushButton( 0 );
93             buttons_layout->addWidget( *other );
94             (*other)->setText( qfu( psz_other ) );
95         }
96         if( l )
97             l->addLayout( buttons_layout );
98 #endif
99         return buttons_layout;
100     };
101
102     QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL ), p_intf( _p_intf )
103     {
104         fixStyle( this );
105     };
106     virtual ~QVLCFrame()   {};
107
108     void toggleVisible()
109     {
110         if( isVisible() ) hide();
111         else show();
112     }
113 protected:
114     intf_thread_t *p_intf;
115
116     void readSettings( QString name, QSize defSize )
117     {
118         QSettings settings( "VideoLAN", "VLC" );
119         settings.beginGroup( name );
120         resize( settings.value( "size", defSize ).toSize() );
121         move( settings.value( "pos", QPoint( 0,0 ) ).toPoint() );
122         settings.endGroup();
123     }
124     void writeSettings( QString name )
125     {
126         QSettings settings( "VideoLAN", "VLC" );
127         settings.beginGroup( name );
128         settings.setValue ("size", size() );
129         settings.setValue( "pos", pos() );
130         settings.endGroup();
131     }
132 };
133
134 class QVLCMW : public QMainWindow
135 {
136 public:
137     QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf )
138     {
139         QVLCFrame::fixStyle( this );
140     }
141     virtual ~QVLCMW() {};
142     void toggleVisible()
143     {
144         if( isVisible() ) hide();
145         else show();
146     }
147 protected:
148     intf_thread_t *p_intf;
149     QSize mainSize;
150
151     void readSettings( QString name, QSize defSize )
152     {
153         QSettings settings( "VideoLAN", "VLC" );
154         settings.beginGroup( name );
155       QSize s =  settings.value( "size", defSize ).toSize() ;
156       fprintf( stderr, "%i %i ", s.width(), s.height() );
157         move( settings.value( "pos", QPoint( 0,0 ) ).toPoint() );
158         settings.endGroup();
159     }
160     void readSettings( QString name )
161     {
162         QSettings settings( "VideoLAN", "VLC" );
163         settings.beginGroup( name );
164         mainSize = settings.value( "size", QSize( 0,0 ) ).toSize();
165         settings.endGroup();
166     }
167     void writeSettings( QString name )
168     {
169         QSettings settings( "VideoLAN", "VLC" );
170         settings.beginGroup( name );
171         settings.setValue ("size", size() );
172         settings.setValue( "pos", pos() );
173         settings.endGroup();
174     }
175 };
176
177 #endif