****************************************************************************
* 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 "qt4.hpp" /*needed for qtr and CONNECT, but not necessary */
+
#include <QPainter>
#include <QColorGroup>
#include <QRect>
#include <QKeyEvent>
+#include <QWheelEvent>
+#include <QHBoxLayout>
+#include <QStyle>
+#include <QStyleOption>
+#include <vlc_intf_strings.h>
+
#include <vlc_keys.h>
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();
cr.setLeft( cr.left() + 3 );
p.drawText( cr, Qt::AlignLeft | Qt::AlignVCenter, mClickMessage );
p.setPen( tmp );
+ p.end();
}
}
QLineEdit::dropEvent( ev );
}
-
void ClickLineEdit::focusInEvent( QFocusEvent *ev )
{
if ( mDrawClickMsg == true ) {
QLineEdit::focusInEvent( ev );
}
-
void ClickLineEdit::focusOutEvent( QFocusEvent *ev )
{
if ( text().isEmpty() ) {
QLineEdit::focusOutEvent( ev );
}
+QVLCFramelessButton::QVLCFramelessButton( QWidget *parent )
+ : QPushButton( parent )
+{
+ setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
+}
+
+void QVLCFramelessButton::paintEvent( QPaintEvent * event )
+{
+ QPainter painter( this );
+ QPixmap pix = icon().pixmap( size() );
+ QPoint pos( (width() - pix.width()) / 2, (height() - pix.height()) / 2 );
+ painter.drawPixmap( QRect( pos.x(), pos.y(), pix.width(), pix.height() ), pix );
+}
+
+QSize QVLCFramelessButton::sizeHint() const
+{
+ return iconSize();
+}
+
+SearchLineEdit::SearchLineEdit( QWidget *parent ) : QLineEdit( parent )
+{
+ clearButton = new QVLCFramelessButton( this );
+ clearButton->setIcon( QIcon( ":/toolbar/clear" ) );
+ clearButton->setIconSize( QSize( 16, 16 ) );
+ clearButton->setCursor( Qt::ArrowCursor );
+ clearButton->setToolTip( qfu(vlc_pgettext("Tooltip|Clear", "Clear")) );
+ clearButton->hide();
+
+ CONNECT( clearButton, clicked(), this, clear() );
+
+ int frameWidth = style()->pixelMetric( QStyle::PM_DefaultFrameWidth, 0, this );
+
+ QFontMetrics metrics( font() );
+ QString styleSheet = QString( "min-height: %1px; "
+ "padding-top: 1px; "
+ "padding-bottom: 1px; "
+ "padding-right: %2px;" )
+ .arg( metrics.height() + ( 2 * frameWidth ) )
+ .arg( clearButton->sizeHint().width() + 1 );
+ setStyleSheet( styleSheet );
+
+ setMessageVisible( true );
+
+ CONNECT( this, textEdited( const QString& ),
+ this, updateText( const QString& ) );
+}
+
+void SearchLineEdit::clear()
+{
+ QLineEdit::clear();
+ clearButton->hide();
+ setMessageVisible( true );
+}
+
+void SearchLineEdit::setMessageVisible( bool on )
+{
+ message = on;
+ repaint();
+ return;
+}
+
+void SearchLineEdit::updateText( const QString& text )
+{
+ clearButton->setVisible( !text.isEmpty() );
+}
+
+void SearchLineEdit::resizeEvent ( QResizeEvent * event )
+{
+ QLineEdit::resizeEvent( event );
+ int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth,0,this);
+ clearButton->resize( clearButton->sizeHint().width(), height() );
+ clearButton->move( width() - clearButton->width() - frameWidth, 0 );
+}
+
+void SearchLineEdit::focusInEvent( QFocusEvent *event )
+{
+ if( message )
+ {
+ setMessageVisible( false );
+ }
+ QLineEdit::focusInEvent( event );
+}
+
+void SearchLineEdit::focusOutEvent( QFocusEvent *event )
+{
+ if( text().isEmpty() )
+ {
+ setMessageVisible( true );
+ }
+ QLineEdit::focusOutEvent( event );
+}
+
+void SearchLineEdit::paintEvent( QPaintEvent *event )
+{
+ QLineEdit::paintEvent( event );
+ if( !message ) return;
+ QStyleOption option;
+ option.initFrom( this );
+ QRect rect = style()->subElementRect( QStyle::SE_LineEditContents, &option, this )
+ .adjusted( 3, 0, clearButton->width() + 1, 0 );
+ QPainter painter( this );
+ painter.setPen( palette().color( QPalette::Disabled, QPalette::Text ) );
+ painter.drawText( rect, Qt::AlignLeft | Qt::AlignVCenter, qtr( I_PL_FILTER ) );
+}
+
/***************************************************************************
* Hotkeys converters
***************************************************************************/
HANDLE( Key_Right, KEY_RIGHT );
HANDLE( Key_Up, KEY_UP );
HANDLE( Key_Down, KEY_DOWN );
- HANDLE( Key_Space, KEY_SPACE );
+ HANDLE( Key_Space, ' ' );
HANDLE( Key_Escape, KEY_ESC );
+ HANDLE( Key_Return, KEY_ENTER );
HANDLE( Key_Enter, KEY_ENTER );
HANDLE( Key_F1, KEY_F1 );
HANDLE( Key_F2, KEY_F2 );
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 )
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 )
{
+ char *base = KeyToString (val & ~KEY_MODIFIER);
+
QString r = "";
if( val & KEY_MODIFIER_CTRL )
- r+= "Ctrl+";
+ r+= qfu( "Ctrl+" );
if( val & KEY_MODIFIER_ALT )
- r+= "Alt+";
+ r+= qfu( "Alt+" );
if( val & KEY_MODIFIER_SHIFT )
- r+= "Shift+";
+ r+= qfu( "Shift+" );
- unsigned int i_keys = sizeof(vlc_keys)/sizeof(key_descriptor_t);
- for( unsigned int i = 0; i< i_keys; i++ )
+ if (base)
{
- if( vlc_keys[i].i_key_code == (val& ~KEY_MODIFIER) )
- {
- r+= vlc_keys[i].psz_key_string;
- }
+ r += qfu( base );
+ free( base );
}
+ else
+ r += qtr( "Unset" );
return r;
}
+