]> git.sesse.net Git - vlc/blob - modules/gui/qt4/util/qvlcframe.hpp
Beginning of implementation of art fetch when played
[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 #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             *defaul = new QPushButton(0);
78             (*defaul)->setFocus();
79             buttons_layout->addWidget( *defaul );
80             (*defaul)->setText( qfu( psz_default ) );
81         }
82         if( psz_alt )
83         {
84             *alt = new QPushButton(0);
85             buttons_layout->addWidget( *alt );
86             (*alt)->setText( qfu( psz_alt ) );
87         }
88         if( psz_other )
89         {
90             *other = new QPushButton( 0 );
91             buttons_layout->addWidget( *other );
92             (*other)->setText( qfu( psz_other ) );
93         }
94         if( l )
95             l->addLayout( buttons_layout );
96 #endif
97         return buttons_layout;
98     };
99
100     QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL ), p_intf( _p_intf )
101     {
102         fixStyle( this );
103     };
104     virtual ~QVLCFrame()   {};
105
106     void toggleVisible()
107     {
108         if( isVisible() ) hide();
109         else show();
110     }
111 protected:
112     intf_thread_t *p_intf;
113
114     void readSettings( QString name, QSize defSize )
115     {
116         QSettings settings( "VideoLAN", "VLC" );
117         settings.beginGroup( name );
118         resize( settings.value( "size", defSize ).toSize() );
119         move( settings.value( "pos", QPoint( 0,0 ) ).toPoint() );
120         settings.endGroup();
121     }
122     void writeSettings( QString name )
123     {
124         QSettings settings( "VideoLAN", "VLC" );
125         settings.beginGroup( name );
126         settings.setValue ("size", size() );
127         settings.setValue( "pos", pos() );
128         settings.endGroup();
129     }
130 };
131
132 class QVLCMW : public QMainWindow
133 {
134 public:
135     QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf )
136     {
137         QVLCFrame::fixStyle( this );
138     }
139     virtual ~QVLCMW() {};
140     void toggleVisible()
141     {
142         if( isVisible() ) hide();
143         else show();
144     }
145 protected:
146     intf_thread_t *p_intf;
147     QSize mainSize;
148
149     void readSettings( QString name, QSize defSize )
150     {
151         QSettings settings( "VideoLAN", "VLC" );
152         settings.beginGroup( name );
153       QSize s =  settings.value( "size", defSize ).toSize() ;
154       fprintf( stderr, "%i %i ", s.width(), s.height() );
155         move( settings.value( "pos", QPoint( 0,0 ) ).toPoint() );
156         settings.endGroup();
157     }
158     void readSettings( QString name )
159     {
160         QSettings settings( "VideoLAN", "VLC" );
161         settings.beginGroup( name );
162         mainSize = settings.value( "size", QSize( 0,0 ) ).toSize();
163         settings.endGroup();
164     }
165     void writeSettings( QString name )
166     {
167         QSettings settings( "VideoLAN", "VLC" );
168         settings.beginGroup( name );
169         settings.setValue ("size", size() );
170         settings.setValue( "pos", pos() );
171         settings.endGroup();
172     }
173 };
174
175 #endif