]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/util/customwidgets.cpp
Delete the "QPainter::begin: A paint device can only be painted by one painter at...
[vlc] / modules / gui / qt4 / util / customwidgets.cpp
index b59ac6c971097e3cba5729bfc921e12f62e484c3..ba58004ae9520e00ba6752e4ccf39924e72056f1 100644 (file)
@@ -3,7 +3,7 @@
  ****************************************************************************
  * Copyright (C) 2006 the VideoLAN team
  * Copyright (C) 2004 Daniel Molkentin <molkentin@kde.org>
- * $Id: qvlcframe.hpp 16283 2006-08-17 18:16:09Z zorglub $
+ * $Id$
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
  * The "ClickLineEdit" control is based on code by  Daniel Molkentin
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include "customwidgets.hpp"
 #include <QPainter>
 #include <QLineEdit>
-#include <QPainter>
 #include <QColorGroup>
 #include <QRect>
+#include <QKeyEvent>
+#include <QWheelEvent>
+
+#include <vlc_keys.h>
 
 ClickLineEdit::ClickLineEdit( const QString &msg, QWidget *parent) : QLineEdit( parent )
 {
@@ -52,9 +59,9 @@ void ClickLineEdit::setText( const QString &txt )
 
 void ClickLineEdit::paintEvent( QPaintEvent *pe )
 {
-    QPainter p( this );
     QLineEdit::paintEvent( pe );
     if ( mDrawClickMsg == true && !hasFocus() ) {
+        QPainter p( this );
         QPen tmp = p.pen();
         p.setPen( palette().color( QPalette::Disabled, QPalette::Text ) );
         QRect cr = contentsRect();
@@ -62,6 +69,7 @@ void ClickLineEdit::paintEvent( QPaintEvent *pe )
         cr.setLeft( cr.left() + 3 );
         p.drawText( cr, Qt::AlignLeft | Qt::AlignVCenter, mClickMessage );
         p.setPen( tmp );
+        p.end();
     }
 }
 
@@ -71,7 +79,6 @@ void ClickLineEdit::dropEvent( QDropEvent *ev )
     QLineEdit::dropEvent( ev );
 }
 
-
 void ClickLineEdit::focusInEvent( QFocusEvent *ev )
 {
     if ( mDrawClickMsg == true ) {
@@ -81,7 +88,6 @@ void ClickLineEdit::focusInEvent( QFocusEvent *ev )
     QLineEdit::focusInEvent( ev );
 }
 
-
 void ClickLineEdit::focusOutEvent( QFocusEvent *ev )
 {
     if ( text().isEmpty() ) {
@@ -90,3 +96,101 @@ void ClickLineEdit::focusOutEvent( QFocusEvent *ev )
     }
     QLineEdit::focusOutEvent( ev );
 }
+
+/***************************************************************************
+ * Hotkeys converters
+ ***************************************************************************/
+int qtKeyModifiersToVLC( QInputEvent* e )
+{
+    int i_keyModifiers = 0;
+    if( e->modifiers() & Qt::ShiftModifier ) i_keyModifiers |= KEY_MODIFIER_SHIFT;
+    if( e->modifiers() & Qt::AltModifier ) i_keyModifiers |= KEY_MODIFIER_ALT;
+    if( e->modifiers() & Qt::ControlModifier ) i_keyModifiers |= KEY_MODIFIER_CTRL;
+    if( e->modifiers() & Qt::MetaModifier ) i_keyModifiers |= KEY_MODIFIER_META;
+    return i_keyModifiers;
+}
+
+int qtEventToVLCKey( QKeyEvent *e )
+{
+    int i_vlck = 0;
+    /* Handle modifiers */
+    i_vlck |= qtKeyModifiersToVLC( e );
+
+    bool found = false;
+    /* Look for some special keys */
+#define HANDLE( qt, vk ) case Qt::qt : i_vlck |= vk; found = true;break
+    switch( e->key() )
+    {
+        HANDLE( Key_Left, KEY_LEFT );
+        HANDLE( Key_Right, KEY_RIGHT );
+        HANDLE( Key_Up, KEY_UP );
+        HANDLE( Key_Down, KEY_DOWN );
+        HANDLE( Key_Space, KEY_SPACE );
+        HANDLE( Key_Escape, KEY_ESC );
+        HANDLE( Key_Enter, KEY_ENTER );
+        HANDLE( Key_F1, KEY_F1 );
+        HANDLE( Key_F2, KEY_F2 );
+        HANDLE( Key_F3, KEY_F3 );
+        HANDLE( Key_F4, KEY_F4 );
+        HANDLE( Key_F5, KEY_F5 );
+        HANDLE( Key_F6, KEY_F6 );
+        HANDLE( Key_F7, KEY_F7 );
+        HANDLE( Key_F8, KEY_F8 );
+        HANDLE( Key_F9, KEY_F9 );
+        HANDLE( Key_F10, KEY_F10 );
+        HANDLE( Key_F11, KEY_F11 );
+        HANDLE( Key_F12, KEY_F12 );
+        HANDLE( Key_PageUp, KEY_PAGEUP );
+        HANDLE( Key_PageDown, KEY_PAGEDOWN );
+        HANDLE( Key_Home, KEY_HOME );
+        HANDLE( Key_End, KEY_END );
+        HANDLE( Key_Insert, KEY_INSERT );
+        HANDLE( Key_Delete, KEY_DELETE );
+        HANDLE( Key_VolumeDown, KEY_VOLUME_DOWN);
+        HANDLE( Key_VolumeUp, KEY_VOLUME_UP );
+        HANDLE( Key_VolumeMute, KEY_VOLUME_MUTE );
+        HANDLE( Key_MediaPlay, KEY_MEDIA_PLAY_PAUSE );
+        HANDLE( Key_MediaStop, KEY_MEDIA_STOP );
+        HANDLE( Key_MediaPrevious, KEY_MEDIA_PREV_TRACK );
+        HANDLE( Key_MediaNext, KEY_MEDIA_NEXT_TRACK );
+
+    }
+    if( !found )
+    {
+        /* Force lowercase */
+        if( e->key() >= Qt::Key_A && e->key() <= Qt::Key_Z )
+            i_vlck += e->key() + 32;
+        /* Rest of the ascii range */
+        else if( e->key() >= Qt::Key_Space && e->key() <= Qt::Key_AsciiTilde )
+            i_vlck += e->key();
+    }
+    return i_vlck;
+}
+
+int qtWheelEventToVLCKey( QWheelEvent *e )
+{
+    int i_vlck = 0;
+    /* Handle modifiers */
+    i_vlck |= qtKeyModifiersToVLC( e );
+    if ( e->delta() > 0 )
+        i_vlck |= KEY_MOUSEWHEELUP;
+    else
+        i_vlck |= KEY_MOUSEWHEELDOWN;
+    return i_vlck;
+}
+
+QString VLCKeyToString( int val )
+{
+    const char *base = KeyToString (val & ~KEY_MODIFIER);
+
+    QString r = "";
+    if( val & KEY_MODIFIER_CTRL )
+        r+= "Ctrl+";
+    if( val & KEY_MODIFIER_ALT )
+        r+= "Alt+";
+    if( val & KEY_MODIFIER_SHIFT )
+        r+= "Shift+";
+
+    return r + (base ? base : "Unset");
+}
+