]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/util/customwidgets.cpp
Qt: it's Qt::Key_Backspace not Qt::Key_Back
[vlc] / modules / gui / qt4 / util / customwidgets.cpp
index 1fbaec2abc66639cccaf5ce47b2ae12c21394bce..3ccfbf001dbb09d519e32b700eedbb4c467ba4e5 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
  * 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>
 
@@ -57,9 +66,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();
@@ -67,6 +76,7 @@ void ClickLineEdit::paintEvent( QPaintEvent *pe )
         cr.setLeft( cr.left() + 3 );
         p.drawText( cr, Qt::AlignLeft | Qt::AlignVCenter, mClickMessage );
         p.setPen( tmp );
+        p.end();
     }
 }
 
@@ -94,6 +104,111 @@ void ClickLineEdit::focusOutEvent( QFocusEvent *ev )
     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
  ***************************************************************************/
@@ -122,8 +237,9 @@ int qtEventToVLCKey( QKeyEvent *e )
         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 );
@@ -145,6 +261,7 @@ int qtEventToVLCKey( QKeyEvent *e )
         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 );
@@ -177,22 +294,23 @@ int qtWheelEventToVLCKey( QWheelEvent *e )
 
 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;
 }