X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fqt4%2Fdialogs%2Ftoolbar.cpp;h=72cf40776d95eb5474e25412a1159e55be9aacc1;hb=5b86425b762dab1f6b5bc3e0d6776188c8d927af;hp=f585542712be76b005f369827376a4316192c262;hpb=2f7f4a7456878a16c0b37df916be545c9ef22273;p=vlc diff --git a/modules/gui/qt4/dialogs/toolbar.cpp b/modules/gui/qt4/dialogs/toolbar.cpp index f585542712..72cf40776d 100644 --- a/modules/gui/qt4/dialogs/toolbar.cpp +++ b/modules/gui/qt4/dialogs/toolbar.cpp @@ -1,7 +1,7 @@ /***************************************************************************** - * ToolbarEdit.cpp : ToolbarEdit and About dialogs + * ToolbarEdit.cpp : ToolbarEdit dialog **************************************************************************** - * Copyright (C) 2008 the VideoLAN team + * Copyright (C) 2008-2009 the VideoLAN team * $Id$ * * Authors: Jean-Baptiste Kempf @@ -36,18 +36,22 @@ #include #include #include +#include #include #include +#include -ToolbarEditDialog *ToolbarEditDialog::instance = NULL; +#include -ToolbarEditDialog::ToolbarEditDialog( intf_thread_t *_p_intf) - : QVLCFrame( _p_intf ) +ToolbarEditDialog::ToolbarEditDialog( QWidget *_w, intf_thread_t *_p_intf) + : QVLCDialog( _w, _p_intf ) { setWindowTitle( qtr( "Toolbars Editor" ) ); + setWindowRole( "vlc-toolbars-editor" ); QGridLayout *mainLayout = new QGridLayout( this ); setMinimumWidth( 600 ); + setAttribute( Qt::WA_DeleteOnClose ); /* main GroupBox */ QGroupBox *widgetBox = new QGroupBox( qtr( "Toolbar Elements") , this ); @@ -55,16 +59,17 @@ ToolbarEditDialog::ToolbarEditDialog( intf_thread_t *_p_intf) QSizePolicy::MinimumExpanding ); QGridLayout *boxLayout = new QGridLayout( widgetBox ); + QLabel *styleLabel = new QLabel( qtr( "Next widget style:" ) ); flatBox = new QCheckBox( qtr( "Flat Button" ) ); bigBox = new QCheckBox( qtr( "Big Button" ) ); shinyBox = new QCheckBox( qtr( "Native Slider" ) ); - shinyBox->setChecked( true ); boxLayout->addWidget( new WidgetListing( p_intf, this ), 0, 0, 1, -1); - boxLayout->addWidget( flatBox, 1, 0 ); - boxLayout->addWidget( bigBox, 1, 1 ); - boxLayout->addWidget( shinyBox, 1, 2 ); - mainLayout->addWidget( widgetBox, 0, 0, 1, -1 ); + boxLayout->addWidget( styleLabel, 1, 0 ); + boxLayout->addWidget( flatBox, 1, 1 ); + boxLayout->addWidget( bigBox, 1, 2 ); + boxLayout->addWidget( shinyBox, 2, 1 ); + mainLayout->addWidget( widgetBox, 0, 0, 5, 1 ); /* Main ToolBar */ @@ -81,7 +86,7 @@ ToolbarEditDialog::ToolbarEditDialog( intf_thread_t *_p_intf) getSettings()->value( "MainWindow/ToolbarPos", 0 ).toInt() ) ); mainTboxLayout->addWidget( positionCombo, 0, 2, 1, 1 ); - QLabel *line1Label = new QLabel( "Line 1:" ); + QLabel *line1Label = new QLabel( qtr("Line 1:") ); QString line1 = getSettings()->value( "MainWindow/MainToolbar1", MAIN_TB1_DEFAULT ).toString(); controller1 = new DroppingController( p_intf, line1, @@ -89,7 +94,7 @@ ToolbarEditDialog::ToolbarEditDialog( intf_thread_t *_p_intf) mainTboxLayout->addWidget( line1Label, 1, 0, 1, 1 ); mainTboxLayout->addWidget( controller1, 1, 1, 1, 2 ); - QLabel *line2Label = new QLabel( "Line 2:" ); + QLabel *line2Label = new QLabel( qtr("Line 2:") ); QString line2 = getSettings()->value( "MainWindow/MainToolbar2", MAIN_TB2_DEFAULT ).toString(); controller2 = new DroppingController( p_intf, line2, @@ -106,7 +111,7 @@ ToolbarEditDialog::ToolbarEditDialog( intf_thread_t *_p_intf) mainTboxLayout->addWidget( advLabel, 3, 0, 1, 2 ); mainTboxLayout->addWidget( controllerA, 3, 2, 1, 1 ); - mainLayout->addWidget( mainToolbarBox, 1, 0, 1, -1 ); + mainLayout->addWidget( mainToolbarBox, 0, 1, 1, -1 ); /* TimeToolBar */ QGroupBox *timeToolbarBox = new QGroupBox( qtr( "Time Toolbar" ) , this ); @@ -118,7 +123,7 @@ ToolbarEditDialog::ToolbarEditDialog( intf_thread_t *_p_intf) this ); timeTboxLayout->addWidget( controller, 0, 0, 1, -1 ); - mainLayout->addWidget( timeToolbarBox, 2, 0, 1, -1 ); + mainLayout->addWidget( timeToolbarBox, 1, 1, 1, -1 ); /* FSCToolBar */ QGroupBox *FSCToolbarBox = new QGroupBox( qtr( "Fullscreen Controller" ), @@ -131,7 +136,51 @@ ToolbarEditDialog::ToolbarEditDialog( intf_thread_t *_p_intf) lineFSC, this ); FSCTboxLayout->addWidget( controllerFSC, 0, 0, 1, -1 ); - mainLayout->addWidget( FSCToolbarBox, 3, 0, 1, -1 ); + mainLayout->addWidget( FSCToolbarBox, 2, 1, 1, -1 ); + + /* Profile */ + QGroupBox *profileBox = new QGroupBox( qtr( "Profile" ), this ); + QGridLayout *profileBoxLayout = new QGridLayout( profileBox ); + + profileCombo = new QComboBox; + QLabel *profileLabel = new QLabel( qtr( "Select profile:" ), this ); + + QToolButton *newButton = new QToolButton; + newButton->setIcon( QIcon( ":/new" ) ); + QToolButton *deleteButton = new QToolButton; + deleteButton->setIcon( QIcon( ":/toolbar/clear" ) ); + deleteButton->setToolTip( qtr( "Delete the current profile" ) ); + + profileBoxLayout->addWidget( profileLabel, 0, 0 ); + profileBoxLayout->addWidget( profileCombo, 0, 1 ); + profileBoxLayout->addWidget( newButton, 0, 2 ); + profileBoxLayout->addWidget( deleteButton, 0, 3 ); + + mainLayout->addWidget( profileBox, 3, 1, 1, -1 ); + + /* Fill combos */ + int i_size = getSettings()->beginReadArray( "ToolbarProfiles" ); + for( int i = 0; i < i_size; i++ ) + { + getSettings()->setArrayIndex(i); + profileCombo->addItem( getSettings()->value( "ProfileName" ).toString(), + getSettings()->value( "Value" ).toString() ); + } + getSettings()->endArray(); + + /* Load defaults ones if we have no combos */ + /* We could decide that we load defaults on first launch of the dialog + or when the combo is back to 0. I choose the second solution, because some clueless + user might hit on delete a bit too much, but discussion is opened. -- jb */ + if( i_size == 0 ) + { + profileCombo->addItem( PROFILE_NAME_1, QString( VALUE_1 ) ); + profileCombo->addItem( PROFILE_NAME_2, QString( VALUE_2 ) ); + profileCombo->addItem( PROFILE_NAME_3, QString( VALUE_3 ) ); + profileCombo->addItem( PROFILE_NAME_4, QString( VALUE_4 ) ); + profileCombo->addItem( PROFILE_NAME_5, QString( VALUE_5 ) ); + } + profileCombo->setCurrentIndex( -1 ); /* Buttons */ QDialogButtonBox *okCancel = new QDialogButtonBox; @@ -141,20 +190,67 @@ ToolbarEditDialog::ToolbarEditDialog( intf_thread_t *_p_intf) okCancel->addButton( okButton, QDialogButtonBox::AcceptRole ); okCancel->addButton( cancelButton, QDialogButtonBox::RejectRole ); + BUTTONACT( deleteButton, deleteProfile() ); + BUTTONACT( newButton, newProfile() ); + CONNECT( profileCombo, currentIndexChanged( int ), this, changeProfile( int ) ); BUTTONACT( okButton, close() ); BUTTONACT( cancelButton, cancel() ); - mainLayout->addWidget( okCancel, 4, 2 ); + mainLayout->addWidget( okCancel, 5, 2 ); } ToolbarEditDialog::~ToolbarEditDialog() { + getSettings()->beginWriteArray( "ToolbarProfiles" ); + for( int i = 0; i < profileCombo->count(); i++ ) + { + getSettings()->setArrayIndex(i); + getSettings()->setValue( "ProfileName", profileCombo->itemText( i ) ); + getSettings()->setValue( "Value", profileCombo->itemData( i ) ); + } + getSettings()->endArray(); +} + +void ToolbarEditDialog::newProfile() +{ + bool ok; + QString name = QInputDialog::getText( this, qtr( "Profile Name" ), + qtr( "Please enter the new profile name." ), QLineEdit::Normal, 0, &ok ); + if( !ok ) return; + + QString temp = QString::number( positionCombo->currentIndex() ); + temp += "|" + controller1->getValue(); + temp += "|" + controller2->getValue(); + temp += "|" + controllerA->getValue(); + temp += "|" + controller->getValue(); + temp += "|" + controllerFSC->getValue(); + + profileCombo->addItem( name, temp ); + profileCombo->setCurrentIndex( profileCombo->count() - 1 ); +} + +void ToolbarEditDialog::deleteProfile() +{ + profileCombo->removeItem( profileCombo->currentIndex() ); +} + +void ToolbarEditDialog::changeProfile( int i ) +{ + QStringList qs_list = profileCombo->itemData( i ).toString().split( "|" ); + if( qs_list.count() < 6 ) + return; + + positionCombo->setCurrentIndex( positionCombo->findData( qs_list[0].toInt() ) ); + controller1->resetLine( qs_list[1] ); + controller2->resetLine( qs_list[2] ); + controllerA->resetLine( qs_list[3] ); + controller->resetLine( qs_list[4] ); + controllerFSC->resetLine( qs_list[5] ); } void ToolbarEditDialog::close() { msg_Dbg( p_intf, "Close and save" ); - hide(); getSettings()->setValue( "MainWindow/ToolbarPos", positionCombo->itemData( positionCombo->currentIndex() ).toInt() ); getSettings()->setValue( "MainWindow/MainToolbar1", controller1->getValue() ); @@ -162,11 +258,13 @@ void ToolbarEditDialog::close() getSettings()->setValue( "MainWindow/AdvToolbar", controllerA->getValue() ); getSettings()->setValue( "MainWindow/InputToolbar", controller->getValue() ); getSettings()->setValue( "MainWindow/FSCtoolbar", controllerFSC->getValue() ); + getSettings()->sync(); + accept(); } void ToolbarEditDialog::cancel() { - hide(); + reject(); } /************************************************ @@ -184,25 +282,24 @@ WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent ) setViewMode( QListView::IconMode ); setSpacing( 20 ); setDragEnabled( true ); - setMinimumHeight( 250 ); /* All the buttons do not need a special rendering */ for( int i = 0; i < BUTTON_MAX; i++ ) { QListWidgetItem *widgetItem = new QListWidgetItem( this ); - widgetItem->setText( nameL[i] ); + widgetItem->setText( qtr( nameL[i] ) ); widgetItem->setIcon( QIcon( iconL[i] ) ); widgetItem->setData( Qt::UserRole, QVariant( i ) ); addItem( widgetItem ); } /* Spacers are yet again a different thing */ - QListWidgetItem *widgetItem = new QListWidgetItem( QIcon( ":/space" ), + QListWidgetItem *widgetItem = new QListWidgetItem( QIcon( ":/toolbar/space" ), qtr( "Spacer" ), this ); widgetItem->setData( Qt::UserRole, WIDGET_SPACER ); addItem( widgetItem ); - widgetItem = new QListWidgetItem( QIcon( ":/space" ), + widgetItem = new QListWidgetItem( QIcon( ":/toolbar/space" ), qtr( "Expanding Spacer" ), this ); widgetItem->setData( Qt::UserRole, WIDGET_SPACER_EXTEND ); addItem( widgetItem ); @@ -249,6 +346,15 @@ WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent ) } widgetItem->setText( qtr("Volume") ); break; + case VOLUME_SPECIAL: + { + QListWidgetItem *widgetItem = new QListWidgetItem( this ); + widgetItem->setText( qtr("Small Volume") ); + widgetItem->setIcon( QIcon( ":/toolbar/volume-medium" ) ); + widgetItem->setData( Qt::UserRole, QVariant( i ) ); + addItem( widgetItem ); + } + continue; case TIME_LABEL: { QLabel *timeLabel = new QLabel( "12:42/2:12:42", this ); @@ -264,15 +370,15 @@ WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent ) discLayout->setSpacing( 0 ); discLayout->setMargin( 0 ); QToolButton *prevSectionButton = new QToolButton( discFrame ); - prevSectionButton->setIcon( QIcon( ":/dvd_prev" ) ); + prevSectionButton->setIcon( QIcon( ":/toolbar/dvd_prev" ) ); discLayout->addWidget( prevSectionButton ); QToolButton *menuButton = new QToolButton( discFrame ); - menuButton->setIcon( QIcon( ":/dvd_menu" ) ); + menuButton->setIcon( QIcon( ":/toolbar/dvd_menu" ) ); discLayout->addWidget( menuButton ); QToolButton *nextButton = new QToolButton( discFrame ); - nextButton->setIcon( QIcon( ":/dvd_next" ) ); + nextButton->setIcon( QIcon( ":/toolbar/dvd_next" ) ); discLayout->addWidget( nextButton ); widget = discFrame; @@ -286,11 +392,11 @@ WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent ) telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 ); QToolButton *telexOn = new QToolButton( telexFrame ); - telexOn->setIcon( QIcon( ":/tv" ) ); + telexOn->setIcon( QIcon( ":/toolbar/tv" ) ); telexLayout->addWidget( telexOn ); QToolButton *telexTransparent = new QToolButton; - telexOn->setIcon( QIcon( ":/tvtelx-trans" ) ); + telexOn->setIcon( QIcon( ":/toolbar/tvtelx" ) ); telexLayout->addWidget( telexTransparent ); QSpinBox *telexPage = new QSpinBox; @@ -358,7 +464,7 @@ void WidgetListing::startDrag( Qt::DropActions /*supportedActions*/ ) * to propagate there too */ DroppingController::DroppingController( intf_thread_t *_p_intf, - QString line, + const QString& line, QWidget *_parent ) : AbstractController( _p_intf, _parent ) { @@ -374,6 +480,20 @@ DroppingController::DroppingController( intf_thread_t *_p_intf, parseAndCreate( line, controlLayout ); } +void DroppingController::resetLine( const QString& line ) +{ + hide(); + QLayoutItem *child; + while( (child = controlLayout->takeAt( 0 ) ) != 0 ) + { + child->widget()->hide(); + delete child; + } + + parseAndCreate( line, controlLayout ); + show(); +} + /* Overloading the AbstractController one, because we don't manage the Spacing items in the same ways */ void DroppingController::createAndAddWidget( QBoxLayout *controlLayout, @@ -381,11 +501,15 @@ void DroppingController::createAndAddWidget( QBoxLayout *controlLayout, buttonType_e i_type, int i_option ) { + doubleInt *value = new doubleInt; + value->i_type = i_type; + value->i_option = i_option; + /* Special case for SPACERS, who aren't QWidgets */ if( i_type == WIDGET_SPACER || i_type == WIDGET_SPACER_EXTEND ) { - QLabel *label = new QLabel; - label->setPixmap( QPixmap( ":/space" ) ); + QLabel *label = new QLabel( this ); + label->setPixmap( QPixmap( ":/toolbar/space" ) ); if( i_type == WIDGET_SPACER_EXTEND ) { label->setSizePolicy( QSizePolicy::MinimumExpanding, @@ -412,6 +536,7 @@ void DroppingController::createAndAddWidget( QBoxLayout *controlLayout, if( !widg ) return; /* Install the Event Filter in order to catch the drag */ + widg->setParent( this ); widg->installEventFilter( this ); /* We are in a complex widget, we need to stop events on children too */ @@ -423,7 +548,7 @@ void DroppingController::createAndAddWidget( QBoxLayout *controlLayout, foreach( child, children ) { QWidget *childWidg; - if( childWidg = qobject_cast( child ) ) + if( ( childWidg = qobject_cast( child ) ) ) { child->installEventFilter( this ); childWidg->setEnabled( true ); @@ -449,10 +574,6 @@ void DroppingController::createAndAddWidget( QBoxLayout *controlLayout, /* QList and QBoxLayout don't act the same with insert() */ if( i_index < 0 ) i_index = controlLayout->count() - 1; - /* Insert in the value listing */ - doubleInt *value = new doubleInt; - value->i_type = i_type; - value->i_option = i_option; widgetList.insert( i_index, value ); } @@ -529,16 +650,14 @@ inline int DroppingController::getParentPosInLayout( QPoint point ) QPoint origin = mapToGlobal ( point ); QWidget *tempWidg = QApplication::widgetAt( origin ); + if( tempWidg == NULL ) + return -1; - int i = -1; - if( tempWidg != NULL) + int i = controlLayout->indexOf( tempWidg ); + if( i == -1 ) { - i = controlLayout->indexOf( tempWidg ); - if( i == -1 ) - { - i = controlLayout->indexOf( tempWidg->parentWidget() ); - tempWidg = tempWidg->parentWidget(); - } + i = controlLayout->indexOf( tempWidg->parentWidget() ); + tempWidg = tempWidg->parentWidget(); } /* Return the nearest position */ @@ -553,6 +672,11 @@ void DroppingController::dropEvent( QDropEvent *event ) { int i = getParentPosInLayout( event->pos() ); + /* Workaround: do not let the item move to its current + position + 1 as it breaks the widgetList */ + if ( i - 1 == i_dragIndex ) + --i; + QByteArray data = event->mimeData()->data( "vlc/button-bar" ); QDataStream dataStream(&data, QIODevice::ReadOnly); @@ -608,6 +732,8 @@ bool DroppingController::eventFilter( QObject *obj, QEvent *event ) } if( i == -1 ) return true; + i_dragIndex = i; + doubleInt *dI = widgetList.at( i ); int i_type = dI->i_type; @@ -621,16 +747,19 @@ bool DroppingController::eventFilter( QObject *obj, QEvent *event ) QDrag *drag = new QDrag( widg ); drag->setMimeData( mimeData ); + /* Remove before the drag to not mess DropEvent, + that will createAndAddWidget */ + widgetList.removeAt( i ); + /* Start the effective drag */ drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::MoveAction); - - widgetList.removeAt( i ); - controlLayout->removeWidget( widg ); widg->hide(); + controlLayout->removeWidget( widg ); b_draging = false; } return true; + case QEvent::MouseButtonDblClick: case QEvent::EnabledChange: case QEvent::Hide: case QEvent::HideToParent: