1 /*****************************************************************************
2 * toolbar.cpp : ToolbarEdit dialog
3 ****************************************************************************
4 * Copyright (C) 2008-2009 the VideoLAN team
7 * Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
28 #include "dialogs/toolbar.hpp"
31 #include "util/input_slider.hpp"
32 #include "util/customwidgets.hpp"
33 #include "components/interface_widgets.hpp"
34 #include "util/buttons/DeckButtonsLayout.hpp"
35 #include "util/buttons/BrowseButton.hpp"
36 #include "util/buttons/RoundButton.hpp"
39 #include "input_manager.hpp"
40 #include <vlc_vout.h> /* vout_thread_t for aspect ratio combobox */
45 #include <QListWidget>
47 #include <QRubberBand>
49 #include <QDragEnterEvent>
50 #include <QDialogButtonBox>
51 #include <QInputDialog>
56 ToolbarEditDialog::ToolbarEditDialog( QWidget *_w, intf_thread_t *_p_intf)
57 : QVLCDialog( _w, _p_intf )
59 setWindowTitle( qtr( "Toolbars Editor" ) );
60 setWindowRole( "vlc-toolbars-editor" );
61 QGridLayout *mainLayout = new QGridLayout( this );
62 setMinimumWidth( 600 );
63 setAttribute( Qt::WA_DeleteOnClose );
66 QGroupBox *widgetBox = new QGroupBox( qtr( "Toolbar Elements") , this );
67 widgetBox->setSizePolicy( QSizePolicy::Preferred,
68 QSizePolicy::MinimumExpanding );
69 QGridLayout *boxLayout = new QGridLayout( widgetBox );
71 QLabel *styleLabel = new QLabel( qtr( "Next widget style:" ) );
72 flatBox = new QCheckBox( qtr( "Flat Button" ) );
73 bigBox = new QCheckBox( qtr( "Big Button" ) );
74 shinyBox = new QCheckBox( qtr( "Native Slider" ) );
76 boxLayout->addWidget( new WidgetListing( p_intf, this ), 0, 0, 1, -1);
77 boxLayout->addWidget( styleLabel, 1, 0 );
78 boxLayout->addWidget( flatBox, 1, 1 );
79 boxLayout->addWidget( bigBox, 1, 2 );
80 boxLayout->addWidget( shinyBox, 2, 1 );
81 mainLayout->addWidget( widgetBox, 0, 0, 5, 1 );
85 QGroupBox *mainToolbarBox = new QGroupBox( qtr( "Main Toolbar" ), this );
86 QGridLayout *mainTboxLayout = new QGridLayout( mainToolbarBox );
88 QLabel *label = new QLabel( qtr( "Toolbar position:" ) );
89 mainTboxLayout->addWidget(label, 0, 0, 1, 2);
91 positionCombo = new QComboBox;
92 positionCombo->addItem( qtr( "Under the Video" ), QVariant( 0 ) );
93 positionCombo->addItem( qtr( "Above the Video" ), QVariant( 1 ) );
94 positionCombo->setCurrentIndex( positionCombo->findData(
95 getSettings()->value( "MainWindow/ToolbarPos", 0 ).toInt() ) );
96 mainTboxLayout->addWidget( positionCombo, 0, 2, 1, 1 );
98 QLabel *line1Label = new QLabel( qtr("Line 1:") );
99 QString line1 = getSettings()->value( "MainWindow/MainToolbar1",
100 MAIN_TB1_DEFAULT ).toString();
101 controller1 = new DroppingController( p_intf, line1,
103 mainTboxLayout->addWidget( line1Label, 1, 0, 1, 1 );
104 mainTboxLayout->addWidget( controller1, 1, 1, 1, 2 );
106 QLabel *line2Label = new QLabel( qtr("Line 2:") );
107 QString line2 = getSettings()->value( "MainWindow/MainToolbar2",
108 MAIN_TB2_DEFAULT ).toString();
109 controller2 = new DroppingController( p_intf, line2,
111 mainTboxLayout->addWidget( line2Label, 2, 0, 1, 1 );
112 mainTboxLayout->addWidget( controller2, 2, 1, 1, 2);
114 /* Advanced ToolBar */
115 QLabel *advLabel = new QLabel( qtr( "Advanced Widget toolbar:" ) );
116 QString lineA = getSettings()->value( "MainWindow/AdvToolbar",
117 ADV_TB_DEFAULT ).toString();
118 controllerA = new DroppingController( p_intf, lineA,
120 mainTboxLayout->addWidget( advLabel, 3, 0, 1, 2 );
121 mainTboxLayout->addWidget( controllerA, 3, 2, 1, 1 );
123 mainLayout->addWidget( mainToolbarBox, 0, 1, 1, -1 );
126 QGroupBox *timeToolbarBox = new QGroupBox( qtr( "Time Toolbar" ) , this );
127 QGridLayout *timeTboxLayout = new QGridLayout( timeToolbarBox );
129 QString line = getSettings()->value( "MainWindow/InputToolbar",
130 INPT_TB_DEFAULT ).toString();
131 controller = new DroppingController( p_intf, line,
133 timeTboxLayout->addWidget( controller, 0, 0, 1, -1 );
135 mainLayout->addWidget( timeToolbarBox, 1, 1, 1, -1 );
138 QGroupBox *FSCToolbarBox = new QGroupBox( qtr( "Fullscreen Controller" ),
140 QGridLayout *FSCTboxLayout = new QGridLayout( FSCToolbarBox );
142 QString lineFSC = getSettings()->value( "MainWindow/FSCtoolbar",
143 FSC_TB_DEFAULT ).toString();
144 controllerFSC = new DroppingController( p_intf,
146 FSCTboxLayout->addWidget( controllerFSC, 0, 0, 1, -1 );
148 mainLayout->addWidget( FSCToolbarBox, 2, 1, 1, -1 );
151 QGroupBox *profileBox = new QGroupBox( qtr( "Profile" ), this );
152 QGridLayout *profileBoxLayout = new QGridLayout( profileBox );
154 profileCombo = new QComboBox;
155 QLabel *profileLabel = new QLabel( qtr( "Select profile:" ), this );
157 QToolButton *newButton = new QToolButton;
158 newButton->setIcon( QIcon( ":/new" ) );
159 newButton->setToolTip( qtr("New profile") );
160 QToolButton *deleteButton = new QToolButton;
161 deleteButton->setIcon( QIcon( ":/toolbar/clear" ) );
162 deleteButton->setToolTip( qtr( "Delete the current profile" ) );
164 profileBoxLayout->addWidget( profileLabel, 0, 0 );
165 profileBoxLayout->addWidget( profileCombo, 0, 1 );
166 profileBoxLayout->addWidget( newButton, 0, 2 );
167 profileBoxLayout->addWidget( deleteButton, 0, 3 );
169 mainLayout->addWidget( profileBox, 3, 1, 1, -1 );
172 int i_size = getSettings()->beginReadArray( "ToolbarProfiles" );
173 for( int i = 0; i < i_size; i++ )
175 getSettings()->setArrayIndex(i);
176 profileCombo->addItem( getSettings()->value( "ProfileName" ).toString(),
177 getSettings()->value( "Value" ).toString() );
179 getSettings()->endArray();
181 /* Load defaults ones if we have no combos */
182 /* We could decide that we load defaults on first launch of the dialog
183 or when the combo is back to 0. I choose the second solution, because some clueless
184 user might hit on delete a bit too much, but discussion is opened. -- jb */
187 profileCombo->addItem( PROFILE_NAME_6, QString( VALUE_6 ) );
188 profileCombo->addItem( PROFILE_NAME_1, QString( VALUE_1 ) );
189 profileCombo->addItem( PROFILE_NAME_2, QString( VALUE_2 ) );
190 profileCombo->addItem( PROFILE_NAME_3, QString( VALUE_3 ) );
191 profileCombo->addItem( PROFILE_NAME_4, QString( VALUE_4 ) );
192 profileCombo->addItem( PROFILE_NAME_5, QString( VALUE_5 ) );
194 profileCombo->setCurrentIndex( -1 );
197 QDialogButtonBox *okCancel = new QDialogButtonBox;
198 QPushButton *okButton = new QPushButton( qtr( "Cl&ose" ), this );
199 okButton->setDefault( true );
200 QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ), this );
201 okCancel->addButton( okButton, QDialogButtonBox::AcceptRole );
202 okCancel->addButton( cancelButton, QDialogButtonBox::RejectRole );
204 BUTTONACT( deleteButton, deleteProfile() );
205 BUTTONACT( newButton, newProfile() );
206 CONNECT( profileCombo, currentIndexChanged( int ), this, changeProfile( int ) );
207 BUTTONACT( okButton, close() );
208 BUTTONACT( cancelButton, cancel() );
209 mainLayout->addWidget( okCancel, 5, 2 );
213 ToolbarEditDialog::~ToolbarEditDialog()
215 getSettings()->beginWriteArray( "ToolbarProfiles" );
216 for( int i = 0; i < profileCombo->count(); i++ )
218 getSettings()->setArrayIndex(i);
219 getSettings()->setValue( "ProfileName", profileCombo->itemText( i ) );
220 getSettings()->setValue( "Value", profileCombo->itemData( i ) );
222 getSettings()->endArray();
225 void ToolbarEditDialog::newProfile()
228 QString name = QInputDialog::getText( this, qtr( "Profile Name" ),
229 qtr( "Please enter the new profile name." ), QLineEdit::Normal, 0, &ok );
232 QString temp = QString::number( positionCombo->currentIndex() );
233 temp += "|" + controller1->getValue();
234 temp += "|" + controller2->getValue();
235 temp += "|" + controllerA->getValue();
236 temp += "|" + controller->getValue();
237 temp += "|" + controllerFSC->getValue();
239 profileCombo->addItem( name, temp );
240 profileCombo->setCurrentIndex( profileCombo->count() - 1 );
243 void ToolbarEditDialog::deleteProfile()
245 profileCombo->removeItem( profileCombo->currentIndex() );
248 void ToolbarEditDialog::changeProfile( int i )
250 QStringList qs_list = profileCombo->itemData( i ).toString().split( "|" );
251 if( qs_list.count() < 6 )
254 positionCombo->setCurrentIndex( positionCombo->findData( qs_list[0].toInt() ) );
255 controller1->resetLine( qs_list[1] );
256 controller2->resetLine( qs_list[2] );
257 controllerA->resetLine( qs_list[3] );
258 controller->resetLine( qs_list[4] );
259 controllerFSC->resetLine( qs_list[5] );
262 void ToolbarEditDialog::close()
264 getSettings()->setValue( "MainWindow/ToolbarPos",
265 positionCombo->itemData( positionCombo->currentIndex() ).toInt() );
266 getSettings()->setValue( "MainWindow/MainToolbar1", controller1->getValue() );
267 getSettings()->setValue( "MainWindow/MainToolbar2", controller2->getValue() );
268 getSettings()->setValue( "MainWindow/AdvToolbar", controllerA->getValue() );
269 getSettings()->setValue( "MainWindow/InputToolbar", controller->getValue() );
270 getSettings()->setValue( "MainWindow/FSCtoolbar", controllerFSC->getValue() );
271 getSettings()->sync();
275 void ToolbarEditDialog::cancel()
280 /************************************************
282 * Creation of the list of drawed lovely buttons
283 ************************************************/
284 WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent )
285 : QListWidget( _parent )
287 /* We need the parent to know the options checked */
288 parent = qobject_cast<ToolbarEditDialog *>(_parent);
292 setViewMode( QListView::IconMode );
294 setGridSize( QSize(90, 50) );
297 setTextElideMode( Qt::ElideNone );
298 setDragEnabled( true );
300 /* All the buttons do not need a special rendering */
301 for( int i = 0; i < BUTTON_MAX; i++ )
303 QListWidgetItem *widgetItem = new QListWidgetItem( this );
304 widgetItem->setText( qtr( nameL[i] ) );
305 QPixmap pix( iconL[i] );
306 widgetItem->setIcon( pix.scaled( 16, 16, Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
307 widgetItem->setData( Qt::UserRole, QVariant( i ) );
308 widgetItem->setToolTip( widgetItem->text() );
309 addItem( widgetItem );
312 /* Spacers are yet again a different thing */
313 QListWidgetItem *widgetItem = new QListWidgetItem( QIcon( ":/toolbar/space" ),
314 qtr( "Spacer" ), this );
315 widgetItem->setData( Qt::UserRole, WIDGET_SPACER );
316 widgetItem->setToolTip( widgetItem->text() );
317 addItem( widgetItem );
319 widgetItem = new QListWidgetItem( QIcon( ":/toolbar/space" ),
320 qtr( "Expanding Spacer" ), this );
321 widgetItem->setData( Qt::UserRole, WIDGET_SPACER_EXTEND );
322 widgetItem->setToolTip( widgetItem->text() );
323 addItem( widgetItem );
326 * For all other widgets, we create then, do a pseudo rendering in
327 * a pixmaps for the view, and delete the object
329 * A lot of code is retaken from the Abstract, but not exactly...
331 * They are better ways to deal with this, but I doubt that this is
332 * necessary. If you feel like you have the time, be my guest.
336 for( int i = SPLITTER; i < SPECIAL_MAX; i++ )
338 QWidget *widget = NULL;
339 QListWidgetItem *widgetItem = new QListWidgetItem( this );
344 QFrame *line = new QFrame( this );
345 line->setFrameShape( QFrame::VLine );
346 line->setFrameShadow( QFrame::Raised );
347 line->setLineWidth( 0 ); line->setMidLineWidth( 1 );
350 widgetItem->setText( qtr("Splitter") );
354 SeekSlider *slider = new SeekSlider( Qt::Horizontal, this );
357 widgetItem->setText( qtr("Time Slider") );
361 SoundWidget *snd = new SoundWidget( this, p_intf,
362 parent->getOptions() & WIDGET_SHINY );
365 widgetItem->setText( qtr("Volume") );
369 QListWidgetItem *widgetItem = new QListWidgetItem( this );
370 widgetItem->setText( qtr("Small Volume") );
371 widgetItem->setIcon( QIcon( ":/toolbar/volume-medium" ) );
372 widgetItem->setData( Qt::UserRole, QVariant( i ) );
373 addItem( widgetItem );
378 QLabel *timeLabel = new QLabel( "12:42/2:12:42", this );
381 widgetItem->setText( qtr("Time") );
385 QWidget *discFrame = new QWidget( this );
386 //discFrame->setLineWidth( 1 );
387 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
388 discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
390 QToolButton *prevSectionButton = new QToolButton( discFrame );
391 prevSectionButton->setIcon( QIcon( ":/toolbar/dvd_prev" ) );
392 prevSectionButton->setToolTip( qtr("Previous chapter") );
393 discLayout->addWidget( prevSectionButton );
395 QToolButton *menuButton = new QToolButton( discFrame );
396 menuButton->setIcon( QIcon( ":/toolbar/dvd_menu" ) );
397 menuButton->setToolTip( qtr("Go to the DVD menu") );
398 discLayout->addWidget( menuButton );
400 QToolButton *nextButton = new QToolButton( discFrame );
401 nextButton->setIcon( QIcon( ":/toolbar/dvd_next" ) );
402 nextButton->setToolTip( qtr("Next chapter") );
403 discLayout->addWidget( nextButton );
407 widgetItem->setText( qtr("DVD menus") );
409 case TELETEXT_BUTTONS:
411 QWidget *telexFrame = new QWidget( this );
412 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
413 telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
415 QToolButton *telexOn = new QToolButton( telexFrame );
416 telexOn->setIcon( QIcon( ":/toolbar/tv" ) );
417 telexLayout->addWidget( telexOn );
419 QToolButton *telexTransparent = new QToolButton;
420 telexTransparent->setIcon( QIcon( ":/toolbar/tvtelx" ) );
421 telexTransparent->setToolTip( qtr("Teletext transparency") );
422 telexLayout->addWidget( telexTransparent );
424 QSpinBox *telexPage = new QSpinBox;
425 telexLayout->addWidget( telexPage );
429 widgetItem->setText( qtr("Teletext") );
431 case ADVANCED_CONTROLLER:
433 AdvControlsWidget *advControls = new AdvControlsWidget( p_intf, this );
434 widget = advControls;
436 widgetItem->setText( qtr("Advanced Buttons") );
438 case PLAYBACK_BUTTONS:
440 widget = new QWidget;
441 DeckButtonsLayout *layout = new DeckButtonsLayout( widget );
442 BrowseButton *prev = new BrowseButton( widget, BrowseButton::Backward );
443 BrowseButton *next = new BrowseButton( widget );
444 RoundButton *play = new RoundButton( widget );
445 layout->setBackwardButton( prev );
446 layout->setForwardButton( next );
447 layout->setRoundButton( play );
449 widgetItem->setText( qtr("Playback Buttons") );
451 case ASPECT_RATIO_COMBOBOX:
452 widget = new AspectRatioComboBox( p_intf );
453 widgetItem->setText( qtr("Aspect ratio selector") );
456 widget = new SpeedLabel( p_intf, this );
457 widgetItem->setText( qtr("Speed selector") );
459 case TIME_LABEL_ELAPSED:
460 widget = new QLabel( "2:42", this );
461 widgetItem->setText( qtr("Elapsed time") );
463 case TIME_LABEL_REMAINING:
464 widget = new QLabel( "-2:42", this );
465 widgetItem->setText( qtr("Total/Remaining time") );
468 msg_Warn( p_intf, "This should not happen %i", i );
472 if( widget == NULL ) continue;
475 widgetItem->setIcon( QIcon( QPixmap::grabWidget( widget ) ) );
476 widgetItem->setToolTip( widgetItem->text() );
478 widgetItem->setData( Qt::UserRole, QVariant( i ) );
480 addItem( widgetItem );
485 void WidgetListing::startDrag( Qt::DropActions /*supportedActions*/ )
487 QListWidgetItem *item = currentItem();
490 QDataStream dataStream( &itemData, QIODevice::WriteOnly );
492 int i_type = item->data( Qt::UserRole ).toInt();
493 int i_option = parent->getOptions();
494 dataStream << i_type << i_option;
496 /* Create a new dragging event */
497 QDrag *drag = new QDrag( this );
499 /* With correct mimedata */
500 QMimeData *mimeData = new QMimeData;
501 mimeData->setData( "vlc/button-bar", itemData );
502 drag->setMimeData( mimeData );
504 /* And correct pixmap */
505 QPixmap aPixmap = item->icon().pixmap( QSize( 22, 22 ) );
506 drag->setPixmap( aPixmap );
507 drag->setHotSpot( QPoint( 20, 20 ) );
509 /* We want to keep a copy */
510 drag->exec( Qt::CopyAction | Qt::MoveAction );
514 * The special controller with drag'n drop abilities.
515 * We don't do this in the main controller, since we don't want the OverHead
516 * to propagate there too
518 DroppingController::DroppingController( intf_thread_t *_p_intf,
521 : AbstractController( _p_intf, _parent )
523 RTL_UNAFFECTED_WIDGET
526 setAcceptDrops( true );
527 controlLayout = new QHBoxLayout( this );
528 controlLayout->setSpacing( 5 );
529 controlLayout->setMargin( 0 );
530 setFrameShape( QFrame::StyledPanel );
531 setFrameShadow( QFrame::Raised );
532 setMinimumHeight( 20 );
534 parseAndCreate( line, controlLayout );
537 void DroppingController::resetLine( const QString& line )
541 while( (child = controlLayout->takeAt( 0 ) ) != 0 )
543 child->widget()->hide();
547 parseAndCreate( line, controlLayout );
551 /* Overloading the AbstractController one, because we don't manage the
552 Spacing items in the same ways */
553 void DroppingController::createAndAddWidget( QBoxLayout *newControlLayout,
558 doubleInt *value = new doubleInt;
559 value->i_type = i_type;
560 value->i_option = i_option;
562 /* Special case for SPACERS, who aren't QWidgets */
563 if( i_type == WIDGET_SPACER || i_type == WIDGET_SPACER_EXTEND )
565 QLabel *label = new QLabel( this );
566 label->setPixmap( QPixmap( ":/toolbar/space" ) );
567 if( i_type == WIDGET_SPACER_EXTEND )
569 label->setSizePolicy( QSizePolicy::MinimumExpanding,
570 QSizePolicy::Preferred );
572 /* Create a box around it */
573 label->setFrameStyle( QFrame::Panel | QFrame::Sunken );
574 label->setLineWidth ( 1 );
575 label->setAlignment( Qt::AlignCenter );
578 label->setSizePolicy( QSizePolicy::Fixed,
579 QSizePolicy::Preferred );
581 /* Install event Filter for drag'n drop */
582 label->installEventFilter( this );
583 newControlLayout->insertWidget( i_index, label );
589 QWidget *widg = createWidget( i_type, i_option );
592 /* Install the Event Filter in order to catch the drag */
593 widg->setParent( this );
594 widg->installEventFilter( this );
596 /* We are in a complex widget, we need to stop events on children too */
597 if( i_type >= VOLUME && i_type < SPECIAL_MAX )
599 QList<QObject *>children = widg->children();
602 foreach( child, children )
605 if( ( childWidg = qobject_cast<QWidget *>( child ) ) )
607 child->installEventFilter( this );
608 childWidg->setEnabled( true );
612 /* Decorating the frames when possible */
614 if( i_type >= MENU_BUTTONS /* Don't bother to check for volume */
615 && ( frame = qobject_cast<QFrame *>( widg ) ) != NULL )
617 frame->setFrameStyle( QFrame::Panel | QFrame::Raised );
618 frame->setLineWidth ( 1 );
622 /* Some Widgets are deactivated at creation */
623 widg->setEnabled( true );
625 newControlLayout->insertWidget( i_index, widg );
628 /* QList and QBoxLayout don't act the same with insert() */
629 if( i_index < 0 ) i_index = newControlLayout->count() - 1;
631 widgetList.insert( i_index, value );
634 DroppingController::~DroppingController()
636 qDeleteAll( widgetList );
640 QString DroppingController::getValue()
644 for( int i = 0; i < controlLayout->count(); i++ )
646 doubleInt *dI = widgetList.at( i );
649 qs.append( QString::number( dI->i_type ) );
650 if( dI->i_option ) qs.append( "-" + QString::number( dI->i_option ) );
656 void DroppingController::dragEnterEvent( QDragEnterEvent * event )
658 if( event->mimeData()->hasFormat( "vlc/button-bar" ) )
664 void DroppingController::dragMoveEvent( QDragMoveEvent *event )
666 QPoint origin = event->pos();
668 int i_pos = getParentPosInLayout( origin );
671 /* Both sides of the frame */
674 if( rubberband ) rubberband->hide();
678 /* Last item is special because of underlying items */
679 if( i_pos >= controlLayout->count() )
685 /* Query the underlying item for size && middles */
686 QLayoutItem *tempItem = controlLayout->itemAt( i_pos ); assert( tempItem );
687 QWidget *temp = tempItem->widget(); assert( temp );
689 /* Position assignment */
691 origin.rx() = temp->x() - 2;
693 if( b_end ) origin.rx() += temp->width();
696 rubberband = new QRubberBand( QRubberBand::Line, this );
697 rubberband->setGeometry( origin.x(), origin.y(), 4, height() );
701 inline int DroppingController::getParentPosInLayout( QPoint point )
703 point.ry() = height() / 2 ;
704 QPoint origin = mapToGlobal ( point );
706 QWidget *tempWidg = QApplication::widgetAt( origin );
707 if( tempWidg == NULL )
710 int i = controlLayout->indexOf( tempWidg );
713 i = controlLayout->indexOf( tempWidg->parentWidget() );
714 tempWidg = tempWidg->parentWidget();
717 /* Return the nearest position */
718 if( ( point.x() - tempWidg->x() > tempWidg->width() / 2 ) && i != -1 )
721 // msg_Dbg( p_intf, "%i", i);
725 void DroppingController::dropEvent( QDropEvent *event )
727 int i = getParentPosInLayout( event->pos() );
729 QByteArray data = event->mimeData()->data( "vlc/button-bar" );
730 QDataStream dataStream(&data, QIODevice::ReadOnly);
732 int i_option = 0, i_type = 0;
733 dataStream >> i_type >> i_option;
735 createAndAddWidget( controlLayout, i, (buttonType_e)i_type, i_option );
737 /* Hide by precaution, you don't exactly know what could have happened in
739 if( rubberband ) rubberband->hide();
742 void DroppingController::dragLeaveEvent ( QDragLeaveEvent * event )
744 if( rubberband ) rubberband->hide();
749 * Overloading doAction to block any action
751 void DroppingController::doAction( int i )
756 bool DroppingController::eventFilter( QObject *obj, QEvent *event )
758 switch( event->type() )
760 case QEvent::MouseButtonPress:
763 case QEvent::MouseButtonRelease:
766 case QEvent::MouseMove:
768 if( !b_draging ) return true;
769 QWidget *widg = static_cast<QWidget*>(obj);
772 QDataStream dataStream( &itemData, QIODevice::WriteOnly );
775 i = controlLayout->indexOf( widg );
778 i = controlLayout->indexOf( widg->parentWidget() );
779 widg = widg->parentWidget();
780 /* NOTE: be extra-careful Now with widg access */
783 if( i == -1 ) return true;
786 doubleInt *dI = widgetList.at( i );
788 int i_type = dI->i_type;
789 int i_option = dI->i_option;
790 dataStream << i_type << i_option;
792 /* With correct mimedata */
793 QMimeData *mimeData = new QMimeData;
794 mimeData->setData( "vlc/button-bar", itemData );
796 QDrag *drag = new QDrag( widg );
797 drag->setMimeData( mimeData );
799 /* Remove before the drag to not mess DropEvent,
800 that will createAndAddWidget */
801 widgetList.removeAt( i );
802 controlLayout->removeWidget( widg );
805 /* Start the effective drag */
806 drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::MoveAction);
811 case QEvent::MouseButtonDblClick:
812 case QEvent::EnabledChange:
814 case QEvent::HideToParent:
816 case QEvent::ZOrderChange: