]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/toolbar.cpp
Added window roles for X11
[vlc] / modules / gui / qt4 / dialogs / toolbar.cpp
1 /*****************************************************************************
2  * ToolbarEdit.cpp : ToolbarEdit dialog
3  ****************************************************************************
4  * Copyright (C) 2008-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include "dialogs/toolbar.hpp"
29
30 #include "util/input_slider.hpp"
31 #include "util/customwidgets.hpp"
32 #include "components/interface_widgets.hpp"
33
34 #include <QScrollArea>
35 #include <QGroupBox>
36 #include <QLabel>
37 #include <QComboBox>
38 #include <QListWidget>
39
40 #include <QDragEnterEvent>
41 #include <QDialogButtonBox>
42 #include <QInputDialog>
43
44 ToolbarEditDialog::ToolbarEditDialog( QWidget *_w, intf_thread_t *_p_intf)
45                   : QVLCDialog( _w,  _p_intf )
46 {
47     setWindowTitle( qtr( "Toolbars Editor" ) );
48     setWindowRole( "vlc-toolbars-editor" );
49     QGridLayout *mainLayout = new QGridLayout( this );
50     setMinimumWidth( 600 );
51     setAttribute( Qt::WA_DeleteOnClose );
52
53     /* main GroupBox */
54     QGroupBox *widgetBox = new QGroupBox( qtr( "Toolbar Elements") , this );
55     widgetBox->setSizePolicy( QSizePolicy::Preferred,
56                               QSizePolicy::MinimumExpanding );
57     QGridLayout *boxLayout = new QGridLayout( widgetBox );
58
59     QLabel *styleLabel = new QLabel( qtr( "Next widget style:" ) );
60     flatBox = new QCheckBox( qtr( "Flat Button" ) );
61     bigBox = new QCheckBox( qtr( "Big Button" ) );
62     shinyBox = new QCheckBox( qtr( "Native Slider" ) );
63
64     boxLayout->addWidget( new WidgetListing( p_intf, this ), 0, 0, 1, -1);
65     boxLayout->addWidget( styleLabel, 1, 0 );
66     boxLayout->addWidget( flatBox, 1, 1 );
67     boxLayout->addWidget( bigBox, 1, 2 );
68     boxLayout->addWidget( shinyBox, 2, 1 );
69     mainLayout->addWidget( widgetBox, 0, 0, 5, 1 );
70
71
72     /* Main ToolBar */
73     QGroupBox *mainToolbarBox = new QGroupBox( qtr( "Main Toolbar" ), this );
74     QGridLayout *mainTboxLayout = new QGridLayout( mainToolbarBox );
75
76     QLabel *label = new QLabel( qtr( "Toolbar position:" ) );
77     mainTboxLayout->addWidget(label, 0, 0, 1, 2);
78
79     positionCombo = new QComboBox;
80     positionCombo->addItem( qtr( "Under the Video" ), QVariant( 0 ) );
81     positionCombo->addItem( qtr( "Above the Video" ), QVariant( 1 ) );
82     positionCombo->setCurrentIndex( positionCombo->findData(
83                 getSettings()->value( "MainWindow/ToolbarPos", 0 ).toInt() ) );
84     mainTboxLayout->addWidget( positionCombo, 0, 2, 1, 1 );
85
86     QLabel *line1Label = new QLabel( "Line 1:" );
87     QString line1 = getSettings()->value( "MainWindow/MainToolbar1",
88                                           MAIN_TB1_DEFAULT ).toString();
89     controller1 = new DroppingController( p_intf, line1,
90             this );
91     mainTboxLayout->addWidget( line1Label, 1, 0, 1, 1 );
92     mainTboxLayout->addWidget( controller1, 1, 1, 1, 2 );
93
94     QLabel *line2Label = new QLabel( "Line 2:" );
95     QString line2 = getSettings()->value( "MainWindow/MainToolbar2",
96                                           MAIN_TB2_DEFAULT ).toString();
97     controller2 = new DroppingController( p_intf, line2,
98             this );
99     mainTboxLayout->addWidget( line2Label, 2, 0, 1, 1 );
100     mainTboxLayout->addWidget( controller2, 2, 1, 1, 2);
101
102     /* Advanced ToolBar */
103     QLabel *advLabel = new QLabel( qtr( "Advanced Widget toolbar:" ) );
104     QString lineA = getSettings()->value( "MainWindow/AdvToolbar",
105                                           ADV_TB_DEFAULT ).toString();
106     controllerA = new DroppingController( p_intf, lineA,
107             this );
108     mainTboxLayout->addWidget( advLabel, 3, 0, 1, 2 );
109     mainTboxLayout->addWidget( controllerA, 3, 2, 1, 1 );
110
111     mainLayout->addWidget( mainToolbarBox, 0, 1, 1, -1 );
112
113     /* TimeToolBar */
114     QGroupBox *timeToolbarBox = new QGroupBox( qtr( "Time Toolbar" ) , this );
115     QGridLayout *timeTboxLayout = new QGridLayout( timeToolbarBox );
116
117     QString line = getSettings()->value( "MainWindow/InputToolbar",
118                                          INPT_TB_DEFAULT ).toString();
119     controller = new DroppingController( p_intf, line,
120             this );
121     timeTboxLayout->addWidget( controller, 0, 0, 1, -1 );
122
123     mainLayout->addWidget( timeToolbarBox, 1, 1, 1, -1 );
124
125     /* FSCToolBar */
126     QGroupBox *FSCToolbarBox = new QGroupBox( qtr( "Fullscreen Controller" ),
127                                               this );
128     QGridLayout *FSCTboxLayout = new QGridLayout( FSCToolbarBox );
129
130     QString lineFSC = getSettings()->value( "MainWindow/FSCtoolbar",
131                                             FSC_TB_DEFAULT ).toString();
132     controllerFSC = new DroppingController( p_intf,
133             lineFSC, this );
134     FSCTboxLayout->addWidget( controllerFSC, 0, 0, 1, -1 );
135
136     mainLayout->addWidget( FSCToolbarBox, 2, 1, 1, -1 );
137
138     /* Profile */
139     QGroupBox *profileBox = new QGroupBox( qtr( "Profile" ), this );
140     QGridLayout *profileBoxLayout = new QGridLayout( profileBox );
141
142     profileCombo = new QComboBox;
143     QLabel *profileLabel = new QLabel( qtr( "Select profile:" ), this );
144
145     QToolButton *newButton = new QToolButton;
146     newButton->setIcon( QIcon( ":/new" ) );
147     QToolButton *deleteButton = new QToolButton;
148     deleteButton->setIcon( QIcon( ":/toolbar/clear" ) );
149     deleteButton->setToolTip( qtr( "Delete the current profile" ) );
150
151     profileBoxLayout->addWidget( profileLabel, 0, 0 );
152     profileBoxLayout->addWidget( profileCombo, 0, 1 );
153     profileBoxLayout->addWidget( newButton, 0, 2 );
154     profileBoxLayout->addWidget( deleteButton, 0, 3 );
155
156     mainLayout->addWidget( profileBox, 3, 1, 1, -1 );
157
158     /* Fill combos */
159     int i_size = getSettings()->beginReadArray( "ToolbarProfiles" );
160     for( int i = 0; i < i_size; i++ )
161     {
162         getSettings()->setArrayIndex(i);
163         profileCombo->addItem( getSettings()->value( "ProfileName" ).toString(),
164                                getSettings()->value( "Value" ).toString() );
165     }
166     getSettings()->endArray();
167
168     /* Load defaults ones if we have no combos */
169     /* We could decide that we load defaults on first launch of the dialog
170        or when the combo is back to 0. I choose the second solution, because some clueless
171        user might hit on delete a bit too much, but discussion is opened. -- jb */
172     if( i_size == 0 )
173     {
174         profileCombo->addItem( PROFILE_NAME_1, QString( VALUE_1 ) );
175         profileCombo->addItem( PROFILE_NAME_2, QString( VALUE_2 ) );
176         profileCombo->addItem( PROFILE_NAME_3, QString( VALUE_3 ) );
177         profileCombo->addItem( PROFILE_NAME_4, QString( VALUE_4 ) );
178         profileCombo->addItem( PROFILE_NAME_5, QString( VALUE_5 ) );
179     }
180     profileCombo->setCurrentIndex( -1 );
181
182     /* Buttons */
183     QDialogButtonBox *okCancel = new QDialogButtonBox;
184     QPushButton *okButton = new QPushButton( qtr( "Cl&ose" ), this );
185     okButton->setDefault( true );
186     QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ), this );
187     okCancel->addButton( okButton, QDialogButtonBox::AcceptRole );
188     okCancel->addButton( cancelButton, QDialogButtonBox::RejectRole );
189
190     BUTTONACT( deleteButton, deleteProfile() );
191     BUTTONACT( newButton, newProfile() );
192     CONNECT( profileCombo, currentIndexChanged( int ), this, changeProfile( int ) );
193     BUTTONACT( okButton, close() );
194     BUTTONACT( cancelButton, cancel() );
195     mainLayout->addWidget( okCancel, 5, 2 );
196 }
197
198
199 ToolbarEditDialog::~ToolbarEditDialog()
200 {
201     getSettings()->beginWriteArray( "ToolbarProfiles" );
202     for( int i = 0; i < profileCombo->count(); i++ )
203     {
204         getSettings()->setArrayIndex(i);
205         getSettings()->setValue( "ProfileName", profileCombo->itemText( i ) );
206         getSettings()->setValue( "Value", profileCombo->itemData( i ) );
207     }
208     getSettings()->endArray();
209 }
210
211 void ToolbarEditDialog::newProfile()
212 {
213     bool ok;
214     QString name =  QInputDialog::getText( this, qtr( "Profile Name" ),
215                  qtr( "Please enter the new profile name." ), QLineEdit::Normal, 0, &ok );
216     if( !ok ) return;
217
218     QString temp = QString::number( positionCombo->currentIndex() );
219     temp += "|" + controller1->getValue();
220     temp += "|" + controller2->getValue();
221     temp += "|" + controllerA->getValue();
222     temp += "|" + controller->getValue();
223     temp += "|" + controllerFSC->getValue();
224
225     profileCombo->addItem( name, temp );
226     profileCombo->setCurrentIndex( profileCombo->count() - 1 );
227 }
228
229 void ToolbarEditDialog::deleteProfile()
230 {
231     profileCombo->removeItem( profileCombo->currentIndex() );
232 }
233
234 void ToolbarEditDialog::changeProfile( int i )
235 {
236     QStringList qs_list = profileCombo->itemData( i ).toString().split( "|" );
237     if( qs_list.count() < 6 )
238         return;
239
240     positionCombo->setCurrentIndex( positionCombo->findData( qs_list[0].toInt() ) );
241     controller1->resetLine( qs_list[1] );
242     controller2->resetLine( qs_list[2] );
243     controllerA->resetLine( qs_list[3] );
244     controller->resetLine( qs_list[4] );
245     controllerFSC->resetLine( qs_list[5] );
246 }
247
248 void ToolbarEditDialog::close()
249 {
250     msg_Dbg( p_intf, "Close and save" );
251     getSettings()->setValue( "MainWindow/ToolbarPos",
252             positionCombo->itemData( positionCombo->currentIndex() ).toInt() );
253     getSettings()->setValue( "MainWindow/MainToolbar1", controller1->getValue() );
254     getSettings()->setValue( "MainWindow/MainToolbar2", controller2->getValue() );
255     getSettings()->setValue( "MainWindow/AdvToolbar", controllerA->getValue() );
256     getSettings()->setValue( "MainWindow/InputToolbar", controller->getValue() );
257     getSettings()->setValue( "MainWindow/FSCtoolbar", controllerFSC->getValue() );
258     getSettings()->sync();
259     accept();
260 }
261
262 void ToolbarEditDialog::cancel()
263 {
264     reject();
265 }
266
267 /************************************************
268  *  Widget Listing:
269  * Creation of the list of drawed lovely buttons
270  ************************************************/
271 WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent )
272               : QListWidget( _parent )
273 {
274     /* We need the parent to know the options checked */
275     parent = qobject_cast<ToolbarEditDialog *>(_parent);
276     assert( parent );
277
278     /* Normal options */
279     setViewMode( QListView::IconMode );
280     setSpacing( 20 );
281     setDragEnabled( true );
282
283     /* All the buttons do not need a special rendering */
284     for( int i = 0; i < BUTTON_MAX; i++ )
285     {
286         QListWidgetItem *widgetItem = new QListWidgetItem( this );
287         widgetItem->setText( qtr( nameL[i] ) );
288         widgetItem->setIcon( QIcon( iconL[i] ) );
289         widgetItem->setData( Qt::UserRole, QVariant( i ) );
290         addItem( widgetItem );
291     }
292
293     /* Spacers are yet again a different thing */
294     QListWidgetItem *widgetItem = new QListWidgetItem( QIcon( ":/toolbar/space" ),
295             qtr( "Spacer" ), this );
296     widgetItem->setData( Qt::UserRole, WIDGET_SPACER );
297     addItem( widgetItem );
298
299     widgetItem = new QListWidgetItem( QIcon( ":/toolbar/space" ),
300             qtr( "Expanding Spacer" ), this );
301     widgetItem->setData( Qt::UserRole, WIDGET_SPACER_EXTEND );
302     addItem( widgetItem );
303
304     /**
305      * For all other widgets, we create then, do a pseudo rendering in
306      * a pixmaps for the view, and delete the object
307      *
308      * A lot of code is retaken from the Abstract, but not exactly...
309      * So, rewrite.
310      * They are better ways to deal with this, but I doubt that this is
311      * necessary. If you feel like you have the time, be my guest.
312      * --
313      * jb
314      **/
315     for( int i = SPLITTER; i < SPECIAL_MAX; i++ )
316     {
317         QWidget *widget = NULL;
318         QListWidgetItem *widgetItem = new QListWidgetItem( this );
319         switch( i )
320         {
321         case SPLITTER:
322             {
323                 QFrame *line = new QFrame( this );
324                 line->setFrameShape( QFrame::VLine );
325                 line->setFrameShadow( QFrame::Raised );
326                 line->setLineWidth( 0 ); line->setMidLineWidth( 1 );
327                 widget = line;
328             }
329             widgetItem->setText( qtr("Splitter") );
330             break;
331         case INPUT_SLIDER:
332             {
333                 InputSlider *slider = new InputSlider( Qt::Horizontal, this );
334                 widget = slider;
335             }
336             widgetItem->setText( qtr("Time Slider") );
337             break;
338         case VOLUME:
339             {
340                 SoundWidget *snd = new SoundWidget( this, p_intf,
341                         parent->getOptions() & WIDGET_SHINY );
342                 widget = snd;
343             }
344             widgetItem->setText( qtr("Volume") );
345             break;
346         case VOLUME_SPECIAL:
347             {
348                 QListWidgetItem *widgetItem = new QListWidgetItem( this );
349                 widgetItem->setText( qtr("Small Volume") );
350                 widgetItem->setIcon( QIcon( ":/toolbar/volume-medium" ) );
351                 widgetItem->setData( Qt::UserRole, QVariant( i ) );
352                 addItem( widgetItem );
353             }
354             continue;
355         case TIME_LABEL:
356             {
357                 QLabel *timeLabel = new QLabel( "12:42/2:12:42", this );
358                 widget = timeLabel;
359             }
360             widgetItem->setText( qtr("Time") );
361             break;
362         case MENU_BUTTONS:
363             {
364                 QWidget *discFrame = new QWidget( this );
365                 //discFrame->setLineWidth( 1 );
366                 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
367                 discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
368
369                 QToolButton *prevSectionButton = new QToolButton( discFrame );
370                 prevSectionButton->setIcon( QIcon( ":/toolbar/dvd_prev" ) );
371                 discLayout->addWidget( prevSectionButton );
372
373                 QToolButton *menuButton = new QToolButton( discFrame );
374                 menuButton->setIcon( QIcon( ":/toolbar/dvd_menu" ) );
375                 discLayout->addWidget( menuButton );
376
377                 QToolButton *nextButton = new QToolButton( discFrame );
378                 nextButton->setIcon( QIcon( ":/toolbar/dvd_next" ) );
379                 discLayout->addWidget( nextButton );
380
381                 widget = discFrame;
382             }
383             widgetItem->setText( qtr("DVD menus") );
384             break;
385         case TELETEXT_BUTTONS:
386             {
387                 QWidget *telexFrame = new QWidget( this );
388                 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
389                 telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
390
391                 QToolButton *telexOn = new QToolButton( telexFrame );
392                 telexOn->setIcon( QIcon( ":/toolbar/tv" ) );
393                 telexLayout->addWidget( telexOn );
394
395                 QToolButton *telexTransparent = new QToolButton;
396                 telexOn->setIcon( QIcon( ":/toolbar/tvtelx" ) );
397                 telexLayout->addWidget( telexTransparent );
398
399                 QSpinBox *telexPage = new QSpinBox;
400                 telexLayout->addWidget( telexPage );
401
402                 widget = telexFrame;
403             }
404             widgetItem->setText( qtr("Teletext") );
405             break;
406         case ADVANCED_CONTROLLER:
407             {
408                 AdvControlsWidget *advControls = new AdvControlsWidget( p_intf, this );
409                 widget = advControls;
410             }
411             widgetItem->setText( qtr("Advanced Buttons") );
412             break;
413         default:
414             msg_Warn( p_intf, "This should not happen %i", i );
415             break;
416         }
417
418         if( widget == NULL ) continue;
419
420
421         widgetItem->setIcon( QIcon( QPixmap::grabWidget( widget ) ) );
422         widget->hide();
423         widgetItem->setData( Qt::UserRole, QVariant( i ) );
424
425         addItem( widgetItem );
426         delete widget;
427     }
428 }
429
430 void WidgetListing::startDrag( Qt::DropActions /*supportedActions*/ )
431 {
432     QListWidgetItem *item = currentItem();
433
434     QByteArray itemData;
435     QDataStream dataStream( &itemData, QIODevice::WriteOnly );
436
437     int i_type = item->data( Qt::UserRole ).toInt();
438     int i_option = parent->getOptions();
439     dataStream << i_type << i_option;
440
441     /* Create a new dragging event */
442     QDrag *drag = new QDrag( this );
443
444     /* With correct mimedata */
445     QMimeData *mimeData = new QMimeData;
446     mimeData->setData( "vlc/button-bar", itemData );
447     drag->setMimeData( mimeData );
448
449     /* And correct pixmap */
450     QPixmap aPixmap = item->icon().pixmap( QSize( 22, 22 ) );
451     drag->setPixmap( aPixmap );
452     drag->setHotSpot( QPoint( 20, 20 ) );
453
454     /* We want to keep a copy */
455     drag->exec( Qt::CopyAction | Qt::MoveAction );
456 }
457
458 /*
459  * The special controller with drag'n drop abilities.
460  * We don't do this in the main controller, since we don't want the OverHead
461  * to propagate there too
462  */
463 DroppingController::DroppingController( intf_thread_t *_p_intf,
464                                         const QString& line,
465                                         QWidget *_parent )
466                    : AbstractController( _p_intf, _parent )
467 {
468     rubberband = NULL;
469     b_draging = false;
470     setAcceptDrops( true );
471     controlLayout = new QHBoxLayout( this );
472     controlLayout->setSpacing( 5 );
473     controlLayout->setMargin( 0 );
474     setFrameShape( QFrame::StyledPanel );
475     setFrameShadow( QFrame::Raised );
476
477     parseAndCreate( line, controlLayout );
478 }
479
480 void DroppingController::resetLine( const QString& line )
481 {
482     hide();
483     QLayoutItem *child;
484     while( (child = controlLayout->takeAt( 0 ) ) != 0 )
485     {
486         child->widget()->hide();
487         delete child;
488     }
489
490     parseAndCreate( line, controlLayout );
491     show();
492 }
493
494 /* Overloading the AbstractController one, because we don't manage the
495    Spacing items in the same ways */
496 void DroppingController::createAndAddWidget( QBoxLayout *controlLayout,
497                                              int i_index,
498                                              buttonType_e i_type,
499                                              int i_option )
500 {
501     doubleInt *value = new doubleInt;
502     value->i_type = i_type;
503     value->i_option = i_option;
504
505     /* Special case for SPACERS, who aren't QWidgets */
506     if( i_type == WIDGET_SPACER || i_type == WIDGET_SPACER_EXTEND )
507     {
508         QLabel *label = new QLabel( this );
509         label->setPixmap( QPixmap( ":/toolbar/space" ) );
510         if( i_type == WIDGET_SPACER_EXTEND )
511         {
512             label->setSizePolicy( QSizePolicy::MinimumExpanding,
513                     QSizePolicy::Preferred );
514
515             /* Create a box around it */
516             label->setFrameStyle( QFrame::Panel | QFrame::Sunken );
517             label->setLineWidth ( 1 );
518             label->setAlignment( Qt::AlignCenter );
519         }
520         else
521             label->setSizePolicy( QSizePolicy::Fixed,
522                     QSizePolicy::Preferred );
523
524         /* Install event Filter for drag'n drop */
525         label->installEventFilter( this );
526         controlLayout->insertWidget( i_index, label );
527     }
528
529     /* Normal Widgets */
530     else
531     {
532         QWidget *widg = createWidget( i_type, i_option );
533         if( !widg ) return;
534
535         /* Install the Event Filter in order to catch the drag */
536         widg->setParent( this );
537         widg->installEventFilter( this );
538
539         /* We are in a complex widget, we need to stop events on children too */
540         if( i_type >= VOLUME && i_type < SPECIAL_MAX )
541         {
542             QList<QObject *>children = widg->children();
543
544             QObject *child;
545             foreach( child, children )
546             {
547                 QWidget *childWidg;
548                 if( ( childWidg = qobject_cast<QWidget *>( child ) ) )
549                 {
550                     child->installEventFilter( this );
551                     childWidg->setEnabled( true );
552                 }
553             }
554
555             /* Decorating the frames when possible */
556             QFrame *frame;
557             if( i_type >= MENU_BUTTONS  /* Don't bother to check for volume */
558                 && ( frame = qobject_cast<QFrame *>( widg ) ) != NULL )
559             {
560                 frame->setFrameStyle( QFrame::Panel | QFrame::Raised );
561                 frame->setLineWidth ( 1 );
562             }
563         }
564
565         /* Some Widgets are deactivated at creation */
566         widg->setEnabled( true );
567         widg->show();
568         controlLayout->insertWidget( i_index, widg );
569     }
570
571     /* QList and QBoxLayout don't act the same with insert() */
572     if( i_index < 0 ) i_index = controlLayout->count() - 1;
573
574     widgetList.insert( i_index, value );
575 }
576
577 DroppingController::~DroppingController()
578 {
579     qDeleteAll( widgetList );
580     widgetList.clear();
581 }
582
583 QString DroppingController::getValue()
584 {
585     QString qs = "";
586
587     for( int i = 0; i < controlLayout->count(); i++ )
588     {
589         doubleInt *dI = widgetList.at( i );
590         assert( dI );
591
592         qs.append( QString::number( dI->i_type ) );
593         if( dI->i_option ) qs.append( "-" + QString::number( dI->i_option ) );
594         qs.append( ';' );
595     }
596     return qs;
597 }
598
599 void DroppingController::dragEnterEvent( QDragEnterEvent * event )
600 {
601     if( event->mimeData()->hasFormat( "vlc/button-bar" ) )
602         event->accept();
603     else
604         event->ignore();
605 }
606
607 void DroppingController::dragMoveEvent( QDragMoveEvent *event )
608 {
609     QPoint origin = event->pos();
610
611     int i_pos = getParentPosInLayout( origin );
612     bool b_end = false;
613
614     /* Both sides of the frame */
615     if( i_pos == -1 )
616     {
617         if( rubberband ) rubberband->hide();
618         return;
619     }
620
621     /* Last item is special because of underlying items */
622     if( i_pos >= controlLayout->count() )
623     {
624         i_pos--;
625         b_end = true;
626     }
627
628     /* Query the underlying item for size && middles */
629     QLayoutItem *tempItem = controlLayout->itemAt( i_pos ); assert( tempItem );
630     QWidget *temp = tempItem->widget(); assert( temp );
631
632     /* Position assignment */
633     origin.ry() = 0;
634     origin.rx() = temp->x() - 2;
635
636     if( b_end ) origin.rx() += temp->width();
637
638     if( !rubberband )
639         rubberband = new QRubberBand( QRubberBand::Line, this );
640     rubberband->setGeometry( origin.x(), origin.y(), 4, height() );
641     rubberband->show();
642 }
643
644 inline int DroppingController::getParentPosInLayout( QPoint point )
645 {
646     point.ry() = height() / 2 ;
647     QPoint origin = mapToGlobal ( point );
648
649     QWidget *tempWidg = QApplication::widgetAt( origin );
650     if( tempWidg == NULL )
651         return -1;
652
653     int i = controlLayout->indexOf( tempWidg );
654     if( i == -1 )
655     {
656         i = controlLayout->indexOf( tempWidg->parentWidget() );
657         tempWidg = tempWidg->parentWidget();
658     }
659
660     /* Return the nearest position */
661     if( ( point.x() - tempWidg->x()  > tempWidg->width() / 2 ) && i != -1 )
662         i++;
663
664     //    msg_Dbg( p_intf, "%i", i);
665     return i;
666 }
667
668 void DroppingController::dropEvent( QDropEvent *event )
669 {
670     int i = getParentPosInLayout( event->pos() );
671
672     QByteArray data = event->mimeData()->data( "vlc/button-bar" );
673     QDataStream dataStream(&data, QIODevice::ReadOnly);
674
675     int i_option = 0, i_type = 0;
676     dataStream >> i_type >> i_option;
677
678     createAndAddWidget( controlLayout, i, (buttonType_e)i_type, i_option );
679
680     /* Hide by precaution, you don't exactly know what could have happened in
681        between */
682     if( rubberband ) rubberband->hide();
683 }
684
685 void DroppingController::dragLeaveEvent ( QDragLeaveEvent * event )
686 {
687     if( rubberband ) rubberband->hide();
688     event->accept();
689 }
690
691 /**
692  * Overloading doAction to block any action
693  **/
694 void DroppingController::doAction( int i )
695 {
696     VLC_UNUSED( i );
697 }
698
699 bool DroppingController::eventFilter( QObject *obj, QEvent *event )
700 {
701     switch( event->type() )
702     {
703         case QEvent::MouseButtonPress:
704             b_draging = true;
705             return true;
706         case QEvent::MouseButtonRelease:
707             b_draging = false;
708             return true;
709         case QEvent::MouseMove:
710             {
711             if( !b_draging ) return true;
712             QWidget *widg = static_cast<QWidget*>(obj);
713
714             QByteArray itemData;
715             QDataStream dataStream( &itemData, QIODevice::WriteOnly );
716
717             int i = -1;
718             i = controlLayout->indexOf( widg );
719             if( i == -1 )
720             {
721                 i = controlLayout->indexOf( widg->parentWidget() );
722                 widg = widg->parentWidget();
723                 /* NOTE: be extra-careful Now with widg access */
724             }
725
726             if( i == -1 ) return true;
727             doubleInt *dI = widgetList.at( i );
728
729             int i_type = dI->i_type;
730             int i_option = dI->i_option;
731             dataStream << i_type << i_option;
732
733             /* With correct mimedata */
734             QMimeData *mimeData = new QMimeData;
735             mimeData->setData( "vlc/button-bar", itemData );
736
737             QDrag *drag = new QDrag( widg );
738             drag->setMimeData( mimeData );
739
740             /* Remove before the drag to not mess DropEvent,
741                that will createAndAddWidget */
742             widgetList.removeAt( i );
743
744             /* Start the effective drag */
745             drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::MoveAction);
746             widg->hide();
747             controlLayout->removeWidget( widg );
748             b_draging = false;
749             }
750             return true;
751
752         case QEvent::MouseButtonDblClick:
753         case QEvent::EnabledChange:
754         case QEvent::Hide:
755         case QEvent::HideToParent:
756         case QEvent::Move:
757         case QEvent::ZOrderChange:
758             return true;
759         default:
760             return false;
761     }
762 }
763