⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 preferenceswindow.cpp

📁 VLC媒体播放程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * PreferencesWindow::ReallyQuit *****************************************************************************/void PreferencesWindow::ReallyQuit(){    Lock();    Hide();    Quit();}/***************************************************************************** * PreferencesWindow::BuildConfigView *****************************************************************************/void PreferencesWindow::BuildConfigView( StringItemWithView * stringItem,                                         module_config_t ** pp_item,                                         bool stop_after_category ){    /* Build the BBox */    BRect rect = fDummyView->Bounds();    stringItem->fConfigBox = new BBox( rect, "config box", B_FOLLOW_ALL );    stringItem->fConfigBox->SetLabel( stringItem->fText );    /* Build the BView */    rect = stringItem->fConfigBox->Bounds();    rect.InsetBy( 10,10 );    rect.top += 10;    rect.right -= B_V_SCROLL_BAR_WIDTH + 5;    stringItem->fConfigView = new BView( rect, "config view",                                         B_FOLLOW_NONE, B_WILL_DRAW );    stringItem->fConfigView->SetViewColor(            ui_color( B_PANEL_BACKGROUND_COLOR ) );    /* Add all the settings options */    rect = stringItem->fConfigView->Bounds();    rect.InsetBy( 10, 10 );    ConfigTextControl * textControl;    ConfigCheckBox    * checkBox;    ConfigMenuField   * menuField;    ConfigSlider      * slider;    ConfigKey         * keyConfig;    for( ; (*pp_item)->i_type != CONFIG_HINT_END; (*pp_item)++ )    {        if( stop_after_category &&            (*pp_item)->i_type == CONFIG_HINT_CATEGORY )        {            break;        }        switch( (*pp_item)->i_type )        {            case CONFIG_ITEM_STRING:            case CONFIG_ITEM_FILE:            case CONFIG_ITEM_MODULE:            case CONFIG_ITEM_DIRECTORY:                if( (*pp_item)->ppsz_list && (*pp_item)->ppsz_list[0] )                {                    menuField = new ConfigMenuField( rect,                            (*pp_item)->i_type, (*pp_item)->psz_text,                            (*pp_item)->psz_name, (*pp_item)->ppsz_list );                    stringItem->fConfigView->AddChild( menuField );                    rect.top += menuField->Bounds().Height();                }                else                {                    textControl = new ConfigTextControl( rect,                            (*pp_item)->i_type, (*pp_item)->psz_text,                            (*pp_item)->psz_name );                    stringItem->fConfigView->AddChild( textControl );                    rect.top += textControl->Bounds().Height();                }                break;            case CONFIG_ITEM_INTEGER:                if( (*pp_item)->i_min == (*pp_item)->i_max )                {                    textControl = new ConfigTextControl( rect,                            CONFIG_ITEM_INTEGER, (*pp_item)->psz_text,                            (*pp_item)->psz_name );                    stringItem->fConfigView->AddChild( textControl );                    rect.top += textControl->Bounds().Height();                }                else                {                    slider = new ConfigSlider( rect, CONFIG_ITEM_INTEGER,                            (*pp_item)->psz_text, (*pp_item)->psz_name,                            (*pp_item)->i_min, (*pp_item)->i_max );                    stringItem->fConfigView->AddChild( slider );                    rect.top += slider->Bounds().Height();                }                break;            case CONFIG_ITEM_FLOAT:                if( (*pp_item)->f_min == (*pp_item)->f_max )                {                    textControl = new ConfigTextControl( rect,                            CONFIG_ITEM_FLOAT, (*pp_item)->psz_text,                            (*pp_item)->psz_name );                    stringItem->fConfigView->AddChild( textControl );                    rect.top += textControl->Bounds().Height();                }                else                {                    slider = new ConfigSlider( rect, CONFIG_ITEM_FLOAT,                            (*pp_item)->psz_text, (*pp_item)->psz_name,                            100 * (*pp_item)->f_min, 100 * (*pp_item)->f_max );                    stringItem->fConfigView->AddChild( slider );                    rect.top += slider->Bounds().Height();                }                break;            case CONFIG_ITEM_BOOL:                checkBox = new ConfigCheckBox( rect,                        CONFIG_ITEM_BOOL, (*pp_item)->psz_text,                        (*pp_item)->psz_name );                stringItem->fConfigView->AddChild( checkBox );                rect.top += checkBox->Bounds().Height();                break;            case CONFIG_ITEM_KEY:                keyConfig = new ConfigKey( rect, CONFIG_ITEM_KEY,                        (*pp_item)->psz_text, (*pp_item)->psz_name );                stringItem->fConfigView->AddChild( keyConfig );                rect.top += keyConfig->Bounds().Height();        }    }    /* Put the BView into a BScrollView */    stringItem->fConfigScroll =        new BScrollView( "config scroll", stringItem->fConfigView,                         B_FOLLOW_ALL, 0, false, true, B_FANCY_BORDER );    stringItem->fConfigScroll->SetViewColor(            ui_color( B_PANEL_BACKGROUND_COLOR ) );    stringItem->fConfigBox->AddChild( stringItem->fConfigScroll );    /* Adjust the configView size */    stringItem->fConfigView->ResizeTo(        stringItem->fConfigView->Bounds().Width(), rect.top );}ConfigWidget::ConfigWidget( BRect rect, int type, char * configName )    : BView( rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW ){    fConfigType = type;    fConfigName = strdup( configName );    SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );}ConfigTextControl::ConfigTextControl( BRect rect, int type, char * label,                                      char * configName )    : ConfigWidget( BRect( rect.left, rect.top,                           rect.right, rect.top + 25 ),                    type, configName ){    fTextControl = new BTextControl( Bounds(), NULL, label, NULL,                                     new BMessage() );    AddChild( fTextControl );}void ConfigTextControl::Apply( intf_thread_t * p_intf, bool doIt ){    char string[1024];    switch( fConfigType )    {        case CONFIG_ITEM_STRING:        case CONFIG_ITEM_FILE:        case CONFIG_ITEM_MODULE:        case CONFIG_ITEM_DIRECTORY:            if( doIt )            {                config_PutPsz( p_intf, fConfigName, fTextControl->Text() );            }            else            {                fTextControl->SetText( config_GetPsz( p_intf, fConfigName ) );            }            break;        case CONFIG_ITEM_INTEGER:            if( doIt )            {                config_PutInt( p_intf, fConfigName,                               atoi( fTextControl->Text() ) );            }            else            {                memset( string, 0, 1024 );                snprintf( string, 1023, "%d",                          config_GetInt( p_intf, fConfigName ) );                fTextControl->SetText( string );            }            break;        case CONFIG_ITEM_FLOAT:            if( doIt )            {                config_PutFloat( p_intf, fConfigName,                                 strtod( fTextControl->Text(), NULL ) );            }            else            {                memset( string, 0, 1024 );                snprintf( string, 1023, "%f",                          config_GetFloat( p_intf, fConfigName ) );                fTextControl->SetText( string );            }            break;    }}ConfigCheckBox::ConfigCheckBox( BRect rect, int type, char * label,                                char * configName )    : ConfigWidget( BRect( rect.left, rect.top,                           rect.right, rect.top + 25 ),                    type, configName ){    fCheckBox = new BCheckBox( Bounds(), NULL, label, new BMessage() );    AddChild( fCheckBox );}void ConfigCheckBox::Apply( intf_thread_t * p_intf, bool doIt ){    if( doIt )    {        config_PutInt( p_intf, fConfigName, fCheckBox->Value() );    }    else    {        fCheckBox->SetValue( config_GetInt( p_intf, fConfigName ) );    }}ConfigMenuField::ConfigMenuField( BRect rect, int type, char * label,                                  char * configName, char ** list )    : ConfigWidget( BRect( rect.left, rect.top,                           rect.right, rect.top + 25 ),                    type, configName ){    BMenuItem * menuItem;    fPopUpMenu = new BPopUpMenu( "" );    fMenuField = new BMenuField( Bounds(), NULL, label, fPopUpMenu );    for( int i = 0; list[i]; i++ )    {        menuItem = new BMenuItem( list[i], new BMessage() );        fPopUpMenu->AddItem( menuItem );    }    AddChild( fMenuField );}void ConfigMenuField::Apply( intf_thread_t * p_intf, bool doIt ){    BMenuItem * menuItem;    if( doIt )    {        menuItem = fPopUpMenu->FindMarked();        if( menuItem )        {            config_PutPsz( p_intf, fConfigName, menuItem->Label() );        }    }    else    {        char * value = config_GetPsz( p_intf, fConfigName );        if( !value )        {            value = "";        }        for( int i = 0; i < fPopUpMenu->CountItems(); i++ )        {            menuItem = fPopUpMenu->ItemAt( i );            if( !strcmp( value, menuItem->Label() ) )            {                menuItem->SetMarked( true );                break;            }        }    }}ConfigSlider::ConfigSlider( BRect rect, int type, char * label,                            char * configName, int min, int max )    : ConfigWidget( BRect( rect.left, rect.top,                           rect.right, rect.top + 40 ),                    type, configName ){    fSlider = new BSlider( Bounds(), NULL, label, new BMessage(),                           min, max, B_TRIANGLE_THUMB );    AddChild( fSlider );}void ConfigSlider::Apply( intf_thread_t * p_intf, bool doIt ){    switch( fConfigType )    {        case CONFIG_ITEM_INTEGER:            if( doIt )            {                config_PutInt( p_intf, fConfigName, fSlider->Value() );            }            else            {                fSlider->SetValue( config_GetInt( p_intf, fConfigName ) );            }            break;        case CONFIG_ITEM_FLOAT:            if( doIt )            {                config_PutFloat( p_intf, fConfigName,                                 (float) fSlider->Value() / 100.0 );            }            else            {                fSlider->SetValue( 100 *                        config_GetFloat( p_intf, fConfigName ) );            }            break;    }}ConfigKey::ConfigKey( BRect rect, int type, char * label,                            char * configName )    : ConfigWidget( BRect( rect.left, rect.top,                           rect.right, rect.top + 25 ),                    type, configName ){    BRect r = Bounds();    BMenuItem * menuItem;    r.left = r.right - 60;    fPopUpMenu = new BPopUpMenu( "" );    fMenuField = new BMenuField( r, NULL, NULL, fPopUpMenu );    for( unsigned i = 0;         i < sizeof( vlc_keys ) / sizeof( key_descriptor_t ); i++ )    {        menuItem = new BMenuItem( vlc_keys[i].psz_key_string, NULL );        fPopUpMenu->AddItem( menuItem );    }    r.right = r.left - 10; r.left = r.left - 60;    fShiftCheck = new BCheckBox( r, NULL, "Shift", new BMessage );    r.right = r.left - 10; r.left = r.left - 60;    fCtrlCheck = new BCheckBox( r, NULL, "Ctrl", new BMessage );    r.right = r.left - 10; r.left = r.left - 60;    fAltCheck = new BCheckBox( r, NULL, "Alt", new BMessage );    /* Can someone tell me how we're supposed to get GUI items aligned ? */    r.right = r.left - 10; r.left = 0;    r.bottom -= 10;    fStringView = new BStringView( r, NULL, label );    AddChild( fStringView );    AddChild( fAltCheck );    AddChild( fCtrlCheck );    AddChild( fShiftCheck );    AddChild( fMenuField );}void ConfigKey::Apply( intf_thread_t * p_intf, bool doIt ){    BMenuItem * menuItem;    if( doIt )    {        menuItem = fPopUpMenu->FindMarked();        if( menuItem )        {            int value = vlc_keys[fPopUpMenu->IndexOf( menuItem )].i_key_code;            if( fAltCheck->Value() )            {                value |= KEY_MODIFIER_ALT;            }            if( fCtrlCheck->Value() )            {                value |= KEY_MODIFIER_CTRL;            }            if( fShiftCheck->Value() )            {                value |= KEY_MODIFIER_SHIFT;            }            config_PutInt( p_intf, fConfigName, value );        }    }    else    {        int value = config_GetInt( p_intf, fConfigName );        fAltCheck->SetValue( value & KEY_MODIFIER_ALT );        fCtrlCheck->SetValue( value & KEY_MODIFIER_CTRL );        fShiftCheck->SetValue( value & KEY_MODIFIER_SHIFT );        for( unsigned i = 0;             i < sizeof( vlc_keys ) / sizeof( key_descriptor_t ); i++ )        {            if( (unsigned) vlc_keys[i].i_key_code ==                    ( value & ~KEY_MODIFIER ) )            {                menuItem = fPopUpMenu->ItemAt( i );                menuItem->SetMarked( true );                break;            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -