StringWidget.cpp 1.81 KB
Newer Older
1
/*****************************************************************************
2
 * StringWidget.h: Handle text settings.
3
 *****************************************************************************
4
 * Copyright (C) 2008-2014 VideoLAN
5
 *
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
6
 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * 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 "StringWidget.h"
24
#include "Settings/SettingValue.h"
25 26 27 28

#include <QLineEdit>

StringWidget::StringWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
29
        ISettingsCategoryWidget( parent, s )
30
{
31
    m_lineEdit = new QLineEdit( this );
32 33
    if ( ( s->flags() & SettingValue::Password ) != 0 )
        m_lineEdit->setEchoMode( QLineEdit::Password );
34
    layout()->addWidget( m_lineEdit );
35
    changed( s->get() );
36 37
}

38
bool
39 40
StringWidget::save()
{
41 42 43 44 45
    if ( ( m_setting->flags() & SettingValue::NotEmpty ) != 0 )
    {
        if ( m_lineEdit->text().length() == 0 )
            return false;
    }
46
    m_setting->set( m_lineEdit->text() );
47
    return true;
48
}
49 50 51 52 53
void
StringWidget::changed( const QVariant &val )
{
    m_lineEdit->setText( val.toString() );
}