qvlcframe.hpp 5.09 KB
Newer Older
zorglub's avatar
zorglub committed
1
2
/*****************************************************************************
 * qvlcframe.hpp : A few helpers
3
4
 *****************************************************************************
 * Copyright (C) 2006-2007 the VideoLAN team
5
 * $Id$
zorglub's avatar
zorglub committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
21
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/
zorglub's avatar
zorglub committed
23
24
25
26
27

#ifndef _QVLCFRAME_H_
#define _QVLCFRAME_H_

#include <QWidget>
zorglub's avatar
zorglub committed
28
#include <QDialog>
zorglub's avatar
zorglub committed
29
30
#include <QSpacerItem>
#include <QHBoxLayout>
zorglub's avatar
zorglub committed
31
#include <QApplication>
zorglub's avatar
zorglub committed
32
33
#include <QSettings>
#include <QMainWindow>
zorglub's avatar
zorglub committed
34
#include <QPushButton>
35
#include <QKeyEvent>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
36

zorglub's avatar
zorglub committed
37
#include "qt4.hpp"
zorglub's avatar
zorglub committed
38
#include <vlc/vlc.h>
zorglub's avatar
zorglub committed
39
#include <vlc_charset.h>
zorglub's avatar
zorglub committed
40
41
42
43

class QVLCFrame : public QWidget
{
public:
44
    QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL ), p_intf( _p_intf )
zorglub's avatar
zorglub committed
45
    {    };
zorglub's avatar
zorglub committed
46
47
48
49
50
51
52
53
54
    virtual ~QVLCFrame()   {};

    void toggleVisible()
    {
        if( isVisible() ) hide();
        else show();
    }
protected:
    intf_thread_t *p_intf;
zorglub's avatar
zorglub committed
55

56
    void readSettings( QString name, QSize defSize, QPoint defPos )
zorglub's avatar
zorglub committed
57
    {
58
        QSettings settings( "vlc", "vlc-qt-interface" );
zorglub's avatar
zorglub committed
59
        settings.beginGroup( name );
60
61
62
63
        /* never trust any saved size ;-) */
        QSize newSize = settings.value( "size", defSize ).toSize();
        if( newSize.isValid() )
           resize( newSize );
64
        move( settings.value( "pos", defPos ).toPoint() );
zorglub's avatar
zorglub committed
65
66
67
68
        settings.endGroup();
    }
    void writeSettings( QString name )
    {
69
        QSettings settings( "vlc", "vlc-qt-interface" );
zorglub's avatar
zorglub committed
70
        settings.beginGroup( name );
71
72
73
74
        /* only save valid sizes ... */
        QSize currentsize = size();
        if( currentsize.isValid() )
           settings.setValue ("size", currentsize );
zorglub's avatar
zorglub committed
75
76
77
        settings.setValue( "pos", pos() );
        settings.endGroup();
    }
78
    virtual void cancel()
79
80
81
    {
        hide();
    }
82
    virtual void close()
83
84
85
    {
        hide();
    }
86
    virtual void keyPressEvent( QKeyEvent *keyEvent )
87
88
89
    {
        if( keyEvent->key() == Qt::Key_Escape )
        {
90
            msg_Dbg( p_intf, "Escp Key pressed" );
91
92
            cancel();
        }
93
        else if( keyEvent->key() == Qt::Key_Return )
94
        {
95
96
97
             msg_Dbg( p_intf, "Enter Key pressed" );
             close();
         }
98
    }
zorglub's avatar
zorglub committed
99
};
zorglub's avatar
zorglub committed
100

zorglub's avatar
zorglub committed
101
class QVLCDialog : public QDialog
zorglub's avatar
zorglub committed
102
103
{
public:
zorglub's avatar
zorglub committed
104
105
106
107
108
    QVLCDialog( QWidget* parent, intf_thread_t *_p_intf ) :
                                    QDialog( parent ), p_intf( _p_intf )
    {}
    virtual ~QVLCDialog() {};
    void toggleVisible()
zorglub's avatar
zorglub committed
109
    {
zorglub's avatar
zorglub committed
110
111
        if( isVisible() ) hide();
        else show();
zorglub's avatar
zorglub committed
112
    }
zorglub's avatar
zorglub committed
113
114
115

protected:
    intf_thread_t *p_intf;
116

117
118
119
120
121
    virtual void cancel()
    {
        hide();
    }
    virtual void close()
122
123
124
    {
        hide();
    }
125
    virtual void keyPressEvent( QKeyEvent *keyEvent )
126
127
128
    {
        if( keyEvent->key() == Qt::Key_Escape )
        {
129
            msg_Dbg( p_intf, "Escp Key pressed" );
130
131
            cancel();
        }
132
        else if( keyEvent->key() == Qt::Key_Return )
133
        {
134
135
             msg_Dbg( p_intf, "Enter Key pressed" );
             close();
136
        }
137
    }
zorglub's avatar
zorglub committed
138
139
140
141
142
143
144
};

class QVLCMW : public QMainWindow
{
public:
    QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf )
    {    }
zorglub's avatar
zorglub committed
145
    virtual ~QVLCMW() {};
zorglub's avatar
zorglub committed
146
147
148
149
150
    void toggleVisible()
    {
        if( isVisible() ) hide();
        else show();
    }
zorglub's avatar
zorglub committed
151
152
153
154
155
156
protected:
    intf_thread_t *p_intf;
    QSize mainSize;

    void readSettings( QString name, QSize defSize )
    {
157
        QSettings settings( "vlc", "vlc-qt-interface" );
zorglub's avatar
zorglub committed
158
        settings.beginGroup( name );
159
160
        QSize s =  settings.value( "size", defSize ).toSize() ;
        fprintf( stderr, "%i %i ", s.width(), s.height() );
zorglub's avatar
zorglub committed
161
        move( settings.value( "pos", QPoint( 0,0 ) ).toPoint() );
zorglub's avatar
zorglub committed
162
163
        settings.endGroup();
    }
164

zorglub's avatar
zorglub committed
165
166
    void readSettings( QString name )
    {
167
        QSettings settings( "vlc", "vlc-qt-interface" );
zorglub's avatar
zorglub committed
168
169
        settings.beginGroup( name );
        mainSize = settings.value( "size", QSize( 0,0 ) ).toSize();
170
171
172
173
        if( !mainSize.isValid() )
        {
           mainSize = QSize(0,0);
        }
zorglub's avatar
zorglub committed
174
175
        settings.endGroup();
    }
176

zorglub's avatar
zorglub committed
177
178
    void writeSettings( QString name )
    {
179
        QSettings settings( "vlc", "vlc-qt-interface" );
zorglub's avatar
zorglub committed
180
        settings.beginGroup( name );
181
182
183
184
        /* only save valid sizes ... */
        QSize currentsize = size();
        if( currentsize.isValid() )
            settings.setValue ("size", currentsize );
zorglub's avatar
zorglub committed
185
186
187
188
189
        settings.setValue( "pos", pos() );
        settings.endGroup();
    }
};

zorglub's avatar
zorglub committed
190
#endif