Commit c7fb3d08 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

MediaLibrary: Using newly created SearchLineEdit to filter medias.

parent 3cff3c75
......@@ -186,6 +186,7 @@ ELSE(NOT WITH_GUI)
Gui/timeline/TracksView.cpp
Gui/widgets/ElidableLabel.cpp
Gui/widgets/FramelessButton.cpp
Gui/widgets/SearchLineEdit.cpp
Gui/widgets/TrackControls.cpp
Gui/wizard/GeneralPage.cpp
Gui/wizard/OpenPage.cpp
......@@ -247,6 +248,7 @@ ELSE(NOT WITH_GUI)
Gui/UndoStack.h
Gui/widgets/ElidableLabel.h
Gui/widgets/FramelessButton.h
Gui/widgets/SearchLineEdit.h
Gui/widgets/TrackControls.h
Gui/wizard/GeneralPage.h
Gui/wizard/OpenPage.h
......
......@@ -46,8 +46,6 @@ MediaLibrary::MediaLibrary(QWidget *parent) : QWidget(parent),
this, SIGNAL( clipSelected( Clip* ) ) );
connect( m_ui->filterInput, SIGNAL( textChanged( const QString& ) ),
this, SLOT( filterUpdated( const QString& ) ) );
connect( m_ui->clearButton, SIGNAL( clicked() ),
this, SLOT( clearFilter() ) );
connect( nav, SIGNAL( viewChanged( ViewController* ) ),
this, SLOT( viewChanged( ViewController* ) ) );
connect( m_ui->filterType, SIGNAL( currentIndexChanged( int ) ),
......@@ -70,12 +68,6 @@ MediaLibrary::filterUpdated( const QString &filter )
}
}
void
MediaLibrary::clearFilter()
{
m_ui->filterInput->setText( "" );
}
MediaLibrary::Filter
MediaLibrary::currentFilter()
{
......
......@@ -58,7 +58,6 @@ class MediaLibrary : public QWidget
private slots:
void filterUpdated( const QString &filter );
void clearFilter();
/**
* \brief Used to update the filters when the view is changed.
*
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>280</width>
<height>219</height>
</rect>
</property>
<property name="minimumSize">
......@@ -23,17 +23,16 @@
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="filterLabel">
<property name="text">
<string>Filter:</string>
</property>
</widget>
<widget class="SearchLineEdit" name="filterInput"/>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="filterInput"/>
</item>
<item row="1" column="2">
<widget class="QComboBox" name="filterType">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Name</string>
......@@ -46,23 +45,6 @@
</item>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="filterByLabel">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Filter by</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="clearButton">
<property name="text">
<string>clear</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
......@@ -77,6 +59,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>SearchLineEdit</class>
<extends>QLineEdit</extends>
<header>SearchLineEdit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
/*****************************************************************************
* SearchLineEdit.cpp: A Line edit with a clear button
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzee-Luyssen <beauze.h@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.
*****************************************************************************/
#include "SearchLineEdit.h"
#include "FramelessButton.h"
#include <QStyleOption>
#include <QPainter>
SearchLineEdit::SearchLineEdit( QWidget *parent ) : QLineEdit( parent )
{
m_clearButton = new FramelessButton( this );
m_clearButton->setIcon( QIcon( ":/images/clear" ) );
m_clearButton->setIconSize( QSize( 16, 16 ) );
m_clearButton->setCursor( Qt::ArrowCursor );
m_clearButton->setToolTip( tr( "Clear" ) );
m_clearButton->hide();
connect( m_clearButton, SIGNAL( clicked() ), this, SLOT( 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( m_clearButton->sizeHint().width() + 1 );
setStyleSheet( styleSheet );
setMessageVisible( true );
connect( this, SIGNAL( textEdited( const QString& ) ),
this, SLOT( updateText( const QString& ) ) );
}
void
SearchLineEdit::clear()
{
setText( QString() );
m_clearButton->hide();
setMessageVisible( true );
}
void
SearchLineEdit::setMessageVisible( bool on )
{
m_message = on;
repaint();
return;
}
void
SearchLineEdit::updateText( const QString& text )
{
m_clearButton->setVisible( !text.isEmpty() );
}
void
SearchLineEdit::resizeEvent ( QResizeEvent * event )
{
QLineEdit::resizeEvent( event );
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth,0,this);
m_clearButton->resize( m_clearButton->sizeHint().width(), height() );
m_clearButton->move( width() - m_clearButton->width() - frameWidth, 0 );
}
void
SearchLineEdit::focusInEvent( QFocusEvent *event )
{
if ( m_message )
{
setMessageVisible( false );
}
QLineEdit::focusInEvent( event );
}
void
SearchLineEdit::focusOutEvent( QFocusEvent *event )
{
if ( text().isEmpty() == true )
{
setMessageVisible( true );
}
QLineEdit::focusOutEvent( event );
}
void
SearchLineEdit::paintEvent( QPaintEvent *event )
{
QLineEdit::paintEvent( event );
if( !m_message )
return;
QStyleOption option;
option.initFrom( this );
QRect rect = style()->subElementRect( QStyle::SE_LineEditContents, &option, this )
.adjusted( 3, 0, m_clearButton->width() + 1, 0 );
QPainter painter( this );
painter.setPen( palette().color( QPalette::Disabled, QPalette::Text ) );
painter.drawText( rect, Qt::AlignLeft | Qt::AlignVCenter, tr( "Filter" ) );
}
/*****************************************************************************
* SearchLineEdit.h: A Line edit with a clear button
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzee-Luyssen <beauze.h@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.
*****************************************************************************/
#ifndef SEARCHLINEEDIT_H
#define SEARCHLINEEDIT_H
class FramelessButton;
#include <QLineEdit>
class QLabel;
class SearchLineEdit : public QLineEdit
{
Q_OBJECT
public:
SearchLineEdit( QWidget *parent = NULL );
private:
void resizeEvent ( QResizeEvent * event );
void focusInEvent( QFocusEvent *event );
void focusOutEvent( QFocusEvent *event );
void paintEvent( QPaintEvent *event );
void setMessageVisible( bool on );
private:
FramelessButton *m_clearButton;
bool m_message;
QLabel *m_msg;
public slots:
void clear();
private slots:
void updateText( const QString& );
};
#endif // SEARCHLINEEDIT_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment