]> git.sesse.net Git - vlc/blob - modules/gui/qt4/qt4.hpp
QT4 wineventfilter for Win32, allows WM_APPCOMMAND stuff
[vlc] / modules / gui / qt4 / qt4.hpp
1 /*****************************************************************************
2  * qt4.hpp : QT4 interface
3  ****************************************************************************
4  * Copyright (C) 2006-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifndef _QVLC_H_
26 #define _QVLC_H_
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc_common.h>
33 #include <vlc_interface.h>
34 #include <vlc_playlist.h>
35
36 #include <QEvent>
37
38 #define HAS_QT43 ( QT_VERSION >= 0x040300 )
39
40 #define QT_NORMAL_MODE 0
41 #define QT_ALWAYS_VIDEO_MODE 1
42 #define QT_MINIMAL_MODE 2
43
44 class QApplication;
45 class QMenu;
46 class MainInterface;
47 class DialogsProvider;
48 class VideoWidget;
49 class QSettings;
50
51 #if defined(Q_WS_WIN)
52 #include <QApplication>
53
54 class WinQtApp : public QApplication
55 {
56 public:
57     WinQtApp ( int & argc, char ** argv, bool GUIenabled ) : QApplication( argc, argv, GUIenabled ) {}
58     ~WinQtApp() {}
59 protected:
60     bool winEventFilter(MSG *msg, long *result);
61 };
62 #endif /* Q_WS_WIN */
63
64 struct intf_sys_t
65 {
66     QApplication *p_app;
67     MainInterface *p_mi;
68
69     QSettings *mainSettings;
70
71     bool b_isDialogProvider;
72
73     playlist_t *p_playlist;
74     msg_subscription_t *p_sub; ///< Subscription to the message bank
75
76     VideoWidget *p_video;
77
78     const char *psz_filepath;
79     QMenu * p_popup_menu;
80 };
81
82 #define THEPL p_intf->p_sys->p_playlist
83 #define QPL_LOCK vlc_object_lock( THEPL );
84 #define QPL_UNLOCK vlc_object_unlock( THEPL );
85
86 #define THEDP DialogsProvider::getInstance()
87 #define THEMIM MainInputManager::getInstance( p_intf )
88
89 #define qfu( i ) QString::fromUtf8( i )
90 #define qtr( i ) QString::fromUtf8( _(i) )
91 #define qtu( i ) (i).toUtf8().data()
92 #define qta( i ) (i).toAscii().data()
93
94 #define CONNECT( a, b, c, d ) connect( a, SIGNAL( b ), c, SLOT(d) )
95 #define BUTTONACT( b, a ) connect( b, SIGNAL( clicked() ), this, SLOT(a) )
96 #define ON_TIMEOUT( act ) CONNECT( THEDP->fixed_timer, timeout(), this, act )
97
98 #define BUTTON_SET( button, text, tooltip )  \
99     button->setText( text );                 \
100     button->setToolTip( tooltip );
101
102 #define BUTTON_SET_ACT( button, text, tooltip, thisslot ) \
103     BUTTON_SET( button, text, tooltip );                  \
104     BUTTONACT( button, thisslot );
105
106 #define BUTTON_SET_IMG( button, text, image, tooltip )    \
107     BUTTON_SET( button, text, tooltip );                  \
108     button->setIcon( QIcon( ":/"#image ) );
109
110 #define BUTTON_SET_ACT_I( button, text, image, tooltip, thisslot ) \
111     BUTTON_SET_IMG( button, text, image, tooltip );                \
112     BUTTONACT( button, thisslot );
113
114 #define VISIBLE(i) (i && i->isVisible())
115
116 #define TOGGLEV( x ) { if( x->isVisible() ) x->hide();          \
117             else  x->show(); }
118
119 #if HAS_QT43
120     #define setLayoutMargins( a, b, c, d, e) setContentsMargins( a, b, c, d )
121 #else
122     #define setLayoutMargins( a, b, c, d, e) setMargin( e )
123 #endif
124
125 #define getSettings() p_intf->p_sys->mainSettings
126
127 enum {
128     DialogEventType = 0,
129     IMEventType     = 100,
130     PLEventType     = 200
131 };
132
133
134 #include <QString>
135 /* Replace separators on Windows because Qt is always using / */
136 static inline QString toNativeSeparators( QString s )
137 {
138 #ifdef WIN32
139     for (int i=0; i<(int)s.length(); i++)
140     {
141         if (s[i] == QLatin1Char('/'))
142             s[i] = QLatin1Char('\\');
143     }
144 #endif
145     return s;
146 }
147
148 static inline QString removeTrailingSlash( QString s )
149 {
150     if( ( s.length() > 1 ) && ( s[s.length()-1] == QLatin1Char( '/' ) ) )
151         s.remove( s.length() - 1, 1 );
152     return s;
153 }
154
155 #define toNativeSepNoSlash( a ) toNativeSeparators( removeTrailingSlash( a ) )
156
157 static const int DialogEvent_Type = QEvent::User + DialogEventType + 1;
158 //static const int PLUndockEvent_Type = QEvent::User + DialogEventType + 2;
159 //static const int PLDockEvent_Type = QEvent::User + DialogEventType + 3;
160 static const int SetVideoOnTopEvent_Type = QEvent::User + DialogEventType + 4;
161
162 class DialogEvent : public QEvent
163 {
164 public:
165     DialogEvent( int _i_dialog, int _i_arg, intf_dialog_args_t *_p_arg ) :
166                  QEvent( (QEvent::Type)(DialogEvent_Type) )
167     {
168         i_dialog = _i_dialog;
169         i_arg = _i_arg;
170         p_arg = _p_arg;
171     };
172     virtual ~DialogEvent() {};
173
174     int i_arg, i_dialog;
175     intf_dialog_args_t *p_arg;
176 };
177
178 #endif