1 /*****************************************************************************
2 * customwidgets.cpp: Custom widgets
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
5 * Copyright (C) 2004 Daniel Molkentin <molkentin@kde.org>
6 * $Id: qvlcframe.hpp 16283 2006-08-17 18:16:09Z zorglub $
8 * Authors: Clément Stenac <zorglub@videolan.org>
9 * The "ClickLineEdit" control is based on code by Daniel Molkentin
10 * <molkentin@kde.org> for libkdepim
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/
26 #include "customwidgets.hpp"
30 #include <QColorGroup>
33 #include <QWheelEvent>
37 ClickLineEdit::ClickLineEdit( const QString &msg, QWidget *parent) : QLineEdit( parent )
40 setClickMessage( msg );
43 void ClickLineEdit::setClickMessage( const QString &msg )
50 void ClickLineEdit::setText( const QString &txt )
52 mDrawClickMsg = txt.isEmpty();
54 QLineEdit::setText( txt );
57 void ClickLineEdit::paintEvent( QPaintEvent *pe )
60 QLineEdit::paintEvent( pe );
61 if ( mDrawClickMsg == true && !hasFocus() ) {
63 p.setPen( palette().color( QPalette::Disabled, QPalette::Text ) );
64 QRect cr = contentsRect();
65 // Add two pixel margin on the left side
66 cr.setLeft( cr.left() + 3 );
67 p.drawText( cr, Qt::AlignLeft | Qt::AlignVCenter, mClickMessage );
72 void ClickLineEdit::dropEvent( QDropEvent *ev )
74 mDrawClickMsg = false;
75 QLineEdit::dropEvent( ev );
79 void ClickLineEdit::focusInEvent( QFocusEvent *ev )
81 if ( mDrawClickMsg == true ) {
82 mDrawClickMsg = false;
85 QLineEdit::focusInEvent( ev );
89 void ClickLineEdit::focusOutEvent( QFocusEvent *ev )
91 if ( text().isEmpty() ) {
95 QLineEdit::focusOutEvent( ev );
98 /***************************************************************************
100 ***************************************************************************/
101 int qtKeyModifiersToVLC( QInputEvent* e )
103 int i_keyModifiers = 0;
104 if( e->modifiers() & Qt::ShiftModifier ) i_keyModifiers |= KEY_MODIFIER_SHIFT;
105 if( e->modifiers() & Qt::AltModifier ) i_keyModifiers |= KEY_MODIFIER_ALT;
106 if( e->modifiers() & Qt::ControlModifier ) i_keyModifiers |= KEY_MODIFIER_CTRL;
107 if( e->modifiers() & Qt::MetaModifier ) i_keyModifiers |= KEY_MODIFIER_META;
108 return i_keyModifiers;
111 int qtEventToVLCKey( QKeyEvent *e )
114 /* Handle modifiers */
115 i_vlck |= qtKeyModifiersToVLC( e );
118 /* Look for some special keys */
119 #define HANDLE( qt, vk ) case Qt::qt : i_vlck |= vk; found = true;break
122 HANDLE( Key_Left, KEY_LEFT );
123 HANDLE( Key_Right, KEY_RIGHT );
124 HANDLE( Key_Up, KEY_UP );
125 HANDLE( Key_Down, KEY_DOWN );
126 HANDLE( Key_Space, KEY_SPACE );
127 HANDLE( Key_Escape, KEY_ESC );
128 HANDLE( Key_Enter, KEY_ENTER );
129 HANDLE( Key_F1, KEY_F1 );
130 HANDLE( Key_F2, KEY_F2 );
131 HANDLE( Key_F3, KEY_F3 );
132 HANDLE( Key_F4, KEY_F4 );
133 HANDLE( Key_F5, KEY_F5 );
134 HANDLE( Key_F6, KEY_F6 );
135 HANDLE( Key_F7, KEY_F7 );
136 HANDLE( Key_F8, KEY_F8 );
137 HANDLE( Key_F9, KEY_F9 );
138 HANDLE( Key_F10, KEY_F10 );
139 HANDLE( Key_F11, KEY_F11 );
140 HANDLE( Key_F12, KEY_F12 );
141 HANDLE( Key_PageUp, KEY_PAGEUP );
142 HANDLE( Key_PageDown, KEY_PAGEDOWN );
143 HANDLE( Key_Home, KEY_HOME );
144 HANDLE( Key_End, KEY_END );
145 HANDLE( Key_Insert, KEY_INSERT );
146 HANDLE( Key_Delete, KEY_DELETE );
147 HANDLE( Key_VolumeDown, KEY_VOLUME_DOWN);
148 HANDLE( Key_VolumeUp, KEY_VOLUME_UP );
149 HANDLE( Key_MediaPlay, KEY_MEDIA_PLAY_PAUSE );
150 HANDLE( Key_MediaStop, KEY_MEDIA_STOP );
151 HANDLE( Key_MediaPrevious, KEY_MEDIA_PREV_TRACK );
152 HANDLE( Key_MediaNext, KEY_MEDIA_NEXT_TRACK );
157 /* Force lowercase */
158 if( e->key() >= Qt::Key_A && e->key() <= Qt::Key_Z )
159 i_vlck += e->key() + 32;
160 /* Rest of the ascii range */
161 else if( e->key() >= Qt::Key_Space && e->key() <= Qt::Key_AsciiTilde )
167 int qtWheelEventToVLCKey( QWheelEvent *e )
170 /* Handle modifiers */
171 i_vlck |= qtKeyModifiersToVLC( e );
172 if ( e->delta() > 0 )
173 i_vlck |= KEY_MOUSEWHEELUP;
175 i_vlck |= KEY_MOUSEWHEELDOWN;
179 QString VLCKeyToString( int val )
182 if( val & KEY_MODIFIER_CTRL )
184 if( val & KEY_MODIFIER_ALT )
186 if( val & KEY_MODIFIER_SHIFT )
189 unsigned int i_keys = sizeof(vlc_keys)/sizeof(key_descriptor_t);
190 for( unsigned int i = 0; i< i_keys; i++ )
192 if( vlc_keys[i].i_key_code == (val& ~KEY_MODIFIER) )
194 r+= vlc_keys[i].psz_key_string;