📄 preferences_widgets.cpp
字号:
/***************************************************************************** * preferences_widgets.cpp : Widgets for preferences displays **************************************************************************** * Copyright (C) 2006-2007 the VideoLAN team * $Id$ * * Authors: Clément Stenac <zorglub@videolan.org> * Antoine Cellerier <dionoea@videolan.org> * Jean-Baptiste Kempf <jb@videolan.org> * * 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. *****************************************************************************//** * Todo: * - Finish implementation (see WX, there might be missing a * i_action handler for IntegerLists, but I don't see any module using it... * - Improvements over WX * - Validator for modulelist */#ifdef HAVE_CONFIG_H# include "config.h"#endif#include "components/preferences_widgets.hpp"#include "util/customwidgets.hpp"#include <vlc_keys.h>#include <QString>#include <QVariant>#include <QGridLayout>#include <QSlider>#include <QFileDialog>#include <QGroupBox>#include <QTreeWidgetItem>#include <QSignalMapper>#include <QDialogButtonBox>#define MINWIDTH_BOX 90#define LAST_COLUMN 10QString formatTooltip(const QString & tooltip){ QString formatted = "<html><head><meta name=\"qrichtext\" content=\"1\" />" "<style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head>" "<body style=\" font-family:'Sans Serif'; font-size:9pt; font-weight:400; " "font-style:normal; text-decoration:none;\">" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; " "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" + tooltip + "</p></body></html>"; return formatted;}ConfigControl *ConfigControl::createControl( vlc_object_t *p_this, module_config_t *p_item, QWidget *parent ){ int i = 0; return createControl( p_this, p_item, parent, NULL, i );}ConfigControl *ConfigControl::createControl( vlc_object_t *p_this, module_config_t *p_item, QWidget *parent, QGridLayout *l, int &line ){ ConfigControl *p_control = NULL; switch( p_item->i_type ) { case CONFIG_ITEM_MODULE: p_control = new ModuleConfigControl( p_this, p_item, parent, false, l, line ); break; case CONFIG_ITEM_MODULE_CAT: p_control = new ModuleConfigControl( p_this, p_item, parent, true, l, line ); break; case CONFIG_ITEM_MODULE_LIST: p_control = new ModuleListConfigControl( p_this, p_item, parent, false, l, line ); break; case CONFIG_ITEM_MODULE_LIST_CAT: p_control = new ModuleListConfigControl( p_this, p_item, parent, true, l, line ); /* Special Hack for a bug in video-filter */ if( qobject_cast<ModuleListConfigControl *>( p_control )->groupBox == NULL ) return NULL; break; case CONFIG_ITEM_STRING: if( !p_item->i_list ) p_control = new StringConfigControl( p_this, p_item, parent, l, line, false ); else p_control = new StringListConfigControl( p_this, p_item, parent, false, l, line ); break; case CONFIG_ITEM_PASSWORD: if( !p_item->i_list ) p_control = new StringConfigControl( p_this, p_item, parent, l, line, true ); else p_control = new StringListConfigControl( p_this, p_item, parent, true, l, line ); break; case CONFIG_ITEM_INTEGER: if( p_item->i_list ) p_control = new IntegerListConfigControl( p_this, p_item, parent, false, l, line ); else if( p_item->min.i || p_item->max.i ) p_control = new IntegerRangeConfigControl( p_this, p_item, parent, l, line ); else p_control = new IntegerConfigControl( p_this, p_item, parent, l, line ); break; case CONFIG_ITEM_FILE: p_control = new FileConfigControl( p_this, p_item, parent, l, line, false ); break; case CONFIG_ITEM_DIRECTORY: p_control = new DirectoryConfigControl( p_this, p_item, parent, l, line, false ); break;#if 0 case CONFIG_ITEM_FONT: p_control = new FontConfigControl( p_this, p_item, parent, l, line, false ); break;#endif case CONFIG_ITEM_KEY: p_control = new KeySelectorControl( p_this, p_item, parent, l, line ); break; case CONFIG_ITEM_BOOL: p_control = new BoolConfigControl( p_this, p_item, parent, l, line ); break; case CONFIG_ITEM_FLOAT: if( p_item->min.f || p_item->max.f ) p_control = new FloatRangeConfigControl( p_this, p_item, parent, l, line ); else p_control = new FloatConfigControl( p_this, p_item, parent, l, line ); break; default: break; } return p_control;}void ConfigControl::doApply( intf_thread_t *p_intf ){ switch( getType() ) { case CONFIG_ITEM_INTEGER: case CONFIG_ITEM_BOOL: { VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this); assert( vicc ); config_PutInt( p_intf, vicc->getName(), vicc->getValue() ); break; } case CONFIG_ITEM_FLOAT: { VFloatConfigControl *vfcc = qobject_cast<VFloatConfigControl *>(this); assert( vfcc ); config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() ); break; } case CONFIG_ITEM_STRING: { VStringConfigControl *vscc = qobject_cast<VStringConfigControl *>(this); assert( vscc ); config_PutPsz( p_intf, vscc->getName(), qtu( vscc->getValue() ) ); break; } case CONFIG_ITEM_KEY: { KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this); assert( ksc ); ksc->doApply(); } }}/************************************************************************** * String-based controls *************************************************************************//*********** String **************/StringConfigControl::StringConfigControl( vlc_object_t *_p_this, module_config_t *_p_item, QWidget *_parent, QGridLayout *l, int &line, bool pwd ) : VStringConfigControl( _p_this, _p_item, _parent ){ label = new QLabel( qtr(p_item->psz_text) ); text = new QLineEdit( qfu(p_item->value.psz) ); if( pwd ) text->setEchoMode( QLineEdit::Password ); finish(); if( !l ) { QHBoxLayout *layout = new QHBoxLayout(); layout->addWidget( label, 0 ); layout->insertSpacing( 1, 10 ); layout->addWidget( text, LAST_COLUMN ); widget->setLayout( layout ); } else { l->addWidget( label, line, 0 ); l->setColumnMinimumWidth( 1, 10 ); l->addWidget( text, line, LAST_COLUMN ); }}StringConfigControl::StringConfigControl( vlc_object_t *_p_this, module_config_t *_p_item, QLabel *_label, QLineEdit *_text, bool pwd ): VStringConfigControl( _p_this, _p_item ){ text = _text; label = _label; finish( );}void StringConfigControl::finish(){ text->setText( qfu(p_item->value.psz) ); text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) ); if( label ) label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );}/*********** File **************/FileConfigControl::FileConfigControl( vlc_object_t *_p_this, module_config_t *_p_item, QWidget *_parent, QGridLayout *l, int &line, bool pwd ) : VStringConfigControl( _p_this, _p_item, _parent ){ label = new QLabel( qtr(p_item->psz_text) ); text = new QLineEdit( qfu(p_item->value.psz) ); browse = new QPushButton( qtr( "Browse..." ) ); QHBoxLayout *textAndButton = new QHBoxLayout(); textAndButton->setMargin( 0 ); textAndButton->addWidget( text, 2 ); textAndButton->addWidget( browse, 0 ); BUTTONACT( browse, updateField() ); finish(); if( !l ) { QHBoxLayout *layout = new QHBoxLayout(); layout->addWidget( label, 0 ); layout->insertSpacing( 1, 10 ); layout->addLayout( textAndButton, LAST_COLUMN ); widget->setLayout( layout ); } else { l->addWidget( label, line, 0 ); l->setColumnMinimumWidth( 1, 10 ); l->addLayout( textAndButton, line, LAST_COLUMN ); }}FileConfigControl::FileConfigControl( vlc_object_t *_p_this, module_config_t *_p_item, QLabel *_label, QLineEdit *_text, QPushButton *_button, bool pwd ): VStringConfigControl( _p_this, _p_item ){ browse = _button; text = _text; label = _label; BUTTONACT( browse, updateField() ); finish( );}void FileConfigControl::updateField(){ QString file = QFileDialog::getOpenFileName( NULL, qtr( "Select File" ), qfu( config_GetHomeDir() ) ); if( file.isNull() ) return; text->setText( file );}void FileConfigControl::finish(){ text->setText( qfu(p_item->value.psz) ); text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) ); if( label ) label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );}/********* String / Directory **********/DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this, module_config_t *_p_item, QWidget *_p_widget, QGridLayout *_p_layout, int& _int, bool _pwd ) : FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd){}DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this, module_config_t *_p_item, QLabel *_p_label, QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ): FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd){}void DirectoryConfigControl::updateField(){ QString dir = QFileDialog::getExistingDirectory( NULL, qtr( "Select Directory" ), text->text().isEmpty() ? qfu( config_GetHomeDir() ) : text->text(), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks ); if( dir.isNull() ) return; text->setText( dir );}#if 0#include <QFontDialog>/********* String / Font **********/FontConfigControl::FontConfigControl( vlc_object_t *_p_this, module_config_t *_p_item, QWidget *_p_widget, QGridLayout *_p_layout, int& _int, bool _pwd ) : FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd){}FontConfigControl::FontConfigControl( vlc_object_t *_p_this, module_config_t *_p_item, QLabel *_p_label, QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ): FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd){}void FontConfigControl::updateField(){ bool ok; QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL ); if( !ok ) return; text->setText( font.family() );}#endif/********* String / choice list **********/StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this, module_config_t *_p_item, QWidget *_parent, bool bycat, QGridLayout *l, int &line) : VStringConfigControl( _p_this, _p_item, _parent ){ label = new QLabel( qtr(p_item->psz_text) ); combo = new QComboBox(); combo->setMinimumWidth( MINWIDTH_BOX ); combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred ); module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name ); if(p_module_config && p_module_config->pf_update_list) { vlc_value_t val; val.psz_string = strdup(p_module_config->value.psz); p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL); // assume in any case that dirty was set to true // because lazy programmes will use the same callback for // this, like the one behind the refresh push button? p_module_config->b_dirty = false; free( val.psz_string ); } finish( p_module_config, bycat ); if( !l ) { l = new QGridLayout(); l->addWidget( label, 0, 0 ); l->addWidget( combo, 0, LAST_COLUMN ); widget->setLayout( l ); } else { l->addWidget( label, line, 0 ); l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight ); } if( p_item->i_action ) { QSignalMapper *signalMapper = new QSignalMapper(this); /* Some stringLists like Capture listings have action associated */ for( int i = 0; i < p_item->i_action; i++ ) { QPushButton *button = new QPushButton( qfu( p_item->ppsz_action_text[i] )); CONNECT( button, clicked(), signalMapper, map() ); signalMapper->setMapping( button, i ); l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i, Qt::AlignRight ); } CONNECT( signalMapper, mapped( int ), this, actionRequested( int ) ); }}void StringListConfigControl::actionRequested( int i_action ){ /* Supplementary check for boundaries */ if( i_action < 0 || i_action >= p_item->i_action ) return; module_config_t *p_module_config = config_FindConfig( p_this, getName() ); if(!p_module_config) return; vlc_value_t val; val.psz_string = qtu( (combo->itemData( combo->currentIndex() ).toString() ) ); p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 ); if( p_module_config->b_dirty ) { combo->clear(); finish( p_module_config, true ); p_module_config->b_dirty = false; }}StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this, module_config_t *_p_item, QLabel *_label, QComboBox *_combo, bool bycat ) : VStringConfigControl( _p_this, _p_item ){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -