]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/toolbar.cpp
Qt: profiles for the interface toolbar edition
[vlc] / modules / gui / qt4 / dialogs / toolbar.cpp
1 /*****************************************************************************
2  * ToolbarEdit.cpp : ToolbarEdit and About dialogs
3  ****************************************************************************
4  * Copyright (C) 2008 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::instance = NULL;
45
46 ToolbarEditDialog::ToolbarEditDialog( intf_thread_t *_p_intf)
47                   : QVLCFrame(  _p_intf )
48 {
49     setWindowTitle( qtr( "Toolbars Editor" ) );
50     QGridLayout *mainLayout = new QGridLayout( this );
51     setMinimumWidth( 600 );
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, 1, 3 );
69     mainLayout->addWidget( widgetBox, 0, 0, 1, -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, 1, 0, 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, 2, 0, 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, 3, 0, 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( ":/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, 4, 0, 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     profileCombo->setCurrentIndex( -1 );
168
169     /* Buttons */
170     QDialogButtonBox *okCancel = new QDialogButtonBox;
171     QPushButton *okButton = new QPushButton( qtr( "Cl&ose" ), this );
172     okButton->setDefault( true );
173     QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ), this );
174     okCancel->addButton( okButton, QDialogButtonBox::AcceptRole );
175     okCancel->addButton( cancelButton, QDialogButtonBox::RejectRole );
176
177     BUTTONACT( deleteButton, deleteProfile() );
178     BUTTONACT( newButton, newProfile() );
179     CONNECT( profileCombo, currentIndexChanged( int ), this, changeProfile( int ) );
180     BUTTONACT( okButton, close() );
181     BUTTONACT( cancelButton, cancel() );
182     mainLayout->addWidget( okCancel, 5, 2 );
183 }
184
185
186 ToolbarEditDialog::~ToolbarEditDialog()
187 {
188     getSettings()->beginWriteArray( "ToolbarProfiles" );
189     for( int i = 0; i < profileCombo->count(); i++ )
190     {
191         getSettings()->setArrayIndex(i);
192         getSettings()->setValue( "ProfileName", profileCombo->itemText( i ) );
193         getSettings()->setValue( "Value", profileCombo->itemData( i ) );
194     }
195     getSettings()->endArray();
196 }
197
198 void ToolbarEditDialog::newProfile()
199 {
200     bool ok;
201     QString name =  QInputDialog::getText( this, qtr( "Profile Name" ),
202                  qtr( "Please enter the new profile name." ), QLineEdit::Normal, 0, &ok );
203     if( !ok ) return;
204
205     QString temp = QString::number( positionCombo->currentIndex() );
206     temp += "|" + controller1->getValue();
207     temp += "|" + controller2->getValue();
208     temp += "|" + controllerA->getValue();
209     temp += "|" + controller->getValue();
210     temp += "|" + controllerFSC->getValue();
211
212     profileCombo->addItem( name, temp );
213     profileCombo->setCurrentIndex( profileCombo->count() - 1 );
214 }
215
216 void ToolbarEditDialog::deleteProfile()
217 {
218     profileCombo->removeItem( profileCombo->currentIndex() );
219 }
220
221 void ToolbarEditDialog::changeProfile( int i )
222 {
223     QStringList qs_list = profileCombo->itemData( i ).toString().split( "|" );
224     if( qs_list.count() < 6 )
225         return;
226
227     positionCombo->setCurrentIndex( positionCombo->findData( qs_list[0].toInt() ) );
228     controller1->resetLine( qs_list[1] );
229     controller2->resetLine( qs_list[2] );
230     controllerA->resetLine( qs_list[3] );
231     controller->resetLine( qs_list[4] );
232     controllerFSC->resetLine( qs_list[5] );
233 }
234
235 void ToolbarEditDialog::close()
236 {
237     msg_Dbg( p_intf, "Close and save" );
238     hide();
239     getSettings()->setValue( "MainWindow/ToolbarPos",
240             positionCombo->itemData( positionCombo->currentIndex() ).toInt() );
241     getSettings()->setValue( "MainWindow/MainToolbar1", controller1->getValue() );
242     getSettings()->setValue( "MainWindow/MainToolbar2", controller2->getValue() );
243     getSettings()->setValue( "MainWindow/AdvToolbar", controllerA->getValue() );
244     getSettings()->setValue( "MainWindow/InputToolbar", controller->getValue() );
245     getSettings()->setValue( "MainWindow/FSCtoolbar", controllerFSC->getValue() );
246 }
247
248 void ToolbarEditDialog::cancel()
249 {
250     hide();
251 }
252
253 /************************************************
254  *  Widget Listing:
255  * Creation of the list of drawed lovely buttons
256  ************************************************/
257 WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent )
258               : QListWidget( _parent )
259 {
260     /* We need the parent to know the options checked */
261     parent = qobject_cast<ToolbarEditDialog *>(_parent);
262     assert( parent );
263
264     /* Normal options */
265     setViewMode( QListView::IconMode );
266     setSpacing( 20 );
267     setDragEnabled( true );
268     setMinimumHeight( 250 );
269
270     /* All the buttons do not need a special rendering */
271     for( int i = 0; i < BUTTON_MAX; i++ )
272     {
273         QListWidgetItem *widgetItem = new QListWidgetItem( this );
274         widgetItem->setText( nameL[i] );
275         widgetItem->setIcon( QIcon( iconL[i] ) );
276         widgetItem->setData( Qt::UserRole, QVariant( i ) );
277         addItem( widgetItem );
278     }
279
280     /* Spacers are yet again a different thing */
281     QListWidgetItem *widgetItem = new QListWidgetItem( QIcon( ":/space" ),
282             qtr( "Spacer" ), this );
283     widgetItem->setData( Qt::UserRole, WIDGET_SPACER );
284     addItem( widgetItem );
285
286     widgetItem = new QListWidgetItem( QIcon( ":/space" ),
287             qtr( "Expanding Spacer" ), this );
288     widgetItem->setData( Qt::UserRole, WIDGET_SPACER_EXTEND );
289     addItem( widgetItem );
290
291     /**
292      * For all other widgets, we create then, do a pseudo rendering in
293      * a pixmaps for the view, and delete the object
294      *
295      * A lot of code is retaken from the Abstract, but not exactly...
296      * So, rewrite.
297      * They are better ways to deal with this, but I doubt that this is
298      * necessary. If you feel like you have the time, be my guest.
299      * --
300      * jb
301      **/
302     for( int i = SPLITTER; i < SPECIAL_MAX; i++ )
303     {
304         QWidget *widget = NULL;
305         QListWidgetItem *widgetItem = new QListWidgetItem( this );
306         switch( i )
307         {
308         case SPLITTER:
309             {
310                 QFrame *line = new QFrame( this );
311                 line->setFrameShape( QFrame::VLine );
312                 line->setFrameShadow( QFrame::Raised );
313                 line->setLineWidth( 0 ); line->setMidLineWidth( 1 );
314                 widget = line;
315             }
316             widgetItem->setText( qtr("Splitter") );
317             break;
318         case INPUT_SLIDER:
319             {
320                 InputSlider *slider = new InputSlider( Qt::Horizontal, this );
321                 widget = slider;
322             }
323             widgetItem->setText( qtr("Time Slider") );
324             break;
325         case VOLUME:
326             {
327                 SoundWidget *snd = new SoundWidget( this, p_intf,
328                         parent->getOptions() & WIDGET_SHINY );
329                 widget = snd;
330             }
331             widgetItem->setText( qtr("Volume") );
332             break;
333         case VOLUME_SPECIAL:
334             {
335                 QListWidgetItem *widgetItem = new QListWidgetItem( this );
336                 widgetItem->setText( "Small Volume" );
337                 widgetItem->setIcon( QIcon( ":/volume-medium" ) );
338                 widgetItem->setData( Qt::UserRole, QVariant( i ) );
339                 addItem( widgetItem );
340             }
341             continue;
342         case TIME_LABEL:
343             {
344                 QLabel *timeLabel = new QLabel( "12:42/2:12:42", this );
345                 widget = timeLabel;
346             }
347             widgetItem->setText( qtr("Time") );
348             break;
349         case MENU_BUTTONS:
350             {
351                 QWidget *discFrame = new QWidget( this );
352                 //discFrame->setLineWidth( 1 );
353                 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
354                 discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
355
356                 QToolButton *prevSectionButton = new QToolButton( discFrame );
357                 prevSectionButton->setIcon( QIcon( ":/dvd_prev" ) );
358                 discLayout->addWidget( prevSectionButton );
359
360                 QToolButton *menuButton = new QToolButton( discFrame );
361                 menuButton->setIcon( QIcon( ":/dvd_menu" ) );
362                 discLayout->addWidget( menuButton );
363
364                 QToolButton *nextButton = new QToolButton( discFrame );
365                 nextButton->setIcon( QIcon( ":/dvd_next" ) );
366                 discLayout->addWidget( nextButton );
367
368                 widget = discFrame;
369             }
370             widgetItem->setText( qtr("DVD menus") );
371             break;
372         case TELETEXT_BUTTONS:
373             {
374                 QWidget *telexFrame = new QWidget( this );
375                 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
376                 telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
377
378                 QToolButton *telexOn = new QToolButton( telexFrame );
379                 telexOn->setIcon( QIcon( ":/tv" ) );
380                 telexLayout->addWidget( telexOn );
381
382                 QToolButton *telexTransparent = new QToolButton;
383                 telexOn->setIcon( QIcon( ":/tvtelx" ) );
384                 telexLayout->addWidget( telexTransparent );
385
386                 QSpinBox *telexPage = new QSpinBox;
387                 telexLayout->addWidget( telexPage );
388
389                 widget = telexFrame;
390             }
391             widgetItem->setText( qtr("Teletext") );
392             break;
393         case ADVANCED_CONTROLLER:
394             {
395                 AdvControlsWidget *advControls = new AdvControlsWidget( p_intf, this );
396                 widget = advControls;
397             }
398             widgetItem->setText( qtr("Advanced Buttons") );
399             break;
400         default:
401             msg_Warn( p_intf, "This should not happen %i", i );
402             break;
403         }
404
405         if( widget == NULL ) continue;
406
407
408         widgetItem->setIcon( QIcon( QPixmap::grabWidget( widget ) ) );
409         widget->hide();
410         widgetItem->setData( Qt::UserRole, QVariant( i ) );
411
412         addItem( widgetItem );
413         delete widget;
414     }
415 }
416
417 void WidgetListing::startDrag( Qt::DropActions /*supportedActions*/ )
418 {
419     QListWidgetItem *item = currentItem();
420
421     QByteArray itemData;
422     QDataStream dataStream( &itemData, QIODevice::WriteOnly );
423
424     int i_type = item->data( Qt::UserRole ).toInt();
425     int i_option = parent->getOptions();
426     dataStream << i_type << i_option;
427
428     /* Create a new dragging event */
429     QDrag *drag = new QDrag( this );
430
431     /* With correct mimedata */
432     QMimeData *mimeData = new QMimeData;
433     mimeData->setData( "vlc/button-bar", itemData );
434     drag->setMimeData( mimeData );
435
436     /* And correct pixmap */
437     QPixmap aPixmap = item->icon().pixmap( QSize( 22, 22 ) );
438     drag->setPixmap( aPixmap );
439     drag->setHotSpot( QPoint( 20, 20 ) );
440
441     /* We want to keep a copy */
442     drag->exec( Qt::CopyAction | Qt::MoveAction );
443 }
444
445 /*
446  * The special controller with drag'n drop abilities.
447  * We don't do this in the main controller, since we don't want the OverHead
448  * to propagate there too
449  */
450 DroppingController::DroppingController( intf_thread_t *_p_intf,
451                                         QString line,
452                                         QWidget *_parent )
453                    : AbstractController( _p_intf, _parent )
454 {
455     rubberband = NULL;
456     b_draging = false;
457     setAcceptDrops( true );
458     controlLayout = new QHBoxLayout( this );
459     controlLayout->setSpacing( 5 );
460     controlLayout->setMargin( 0 );
461     setFrameShape( QFrame::StyledPanel );
462     setFrameShadow( QFrame::Raised );
463
464     parseAndCreate( line, controlLayout );
465 }
466
467 void DroppingController::resetLine( QString line )
468 {
469     hide();
470     QLayoutItem *child;
471     int i =0;
472     while( (child = controlLayout->takeAt( 0 ) ) != 0 )
473     {
474         child->widget()->hide();
475         delete child;
476     }
477
478     parseAndCreate( line, controlLayout );
479     show();
480 }
481
482 /* Overloading the AbstractController one, because we don't manage the
483    Spacing items in the same ways */
484 void DroppingController::createAndAddWidget( QBoxLayout *controlLayout,
485                                              int i_index,
486                                              buttonType_e i_type,
487                                              int i_option )
488 {
489     /* Special case for SPACERS, who aren't QWidgets */
490     if( i_type == WIDGET_SPACER || i_type == WIDGET_SPACER_EXTEND )
491     {
492         QLabel *label = new QLabel;
493         label->setPixmap( QPixmap( ":/space" ) );
494         if( i_type == WIDGET_SPACER_EXTEND )
495         {
496             label->setSizePolicy( QSizePolicy::MinimumExpanding,
497                     QSizePolicy::Preferred );
498
499             /* Create a box around it */
500             label->setFrameStyle( QFrame::Panel | QFrame::Sunken );
501             label->setLineWidth ( 1 );
502             label->setAlignment( Qt::AlignCenter );
503         }
504         else
505             label->setSizePolicy( QSizePolicy::Fixed,
506                     QSizePolicy::Preferred );
507
508         /* Install event Filter for drag'n drop */
509         label->installEventFilter( this );
510         controlLayout->insertWidget( i_index, label );
511     }
512
513     /* Normal Widgets */
514     else
515     {
516         QWidget *widg = createWidget( i_type, i_option );
517         if( !widg ) return;
518
519         /* Install the Event Filter in order to catch the drag */
520         widg->installEventFilter( this );
521
522         /* We are in a complex widget, we need to stop events on children too */
523         if( i_type >= VOLUME && i_type < SPECIAL_MAX )
524         {
525             QList<QObject *>children = widg->children();
526
527             QObject *child;
528             foreach( child, children )
529             {
530                 QWidget *childWidg;
531                 if( childWidg = qobject_cast<QWidget *>( child ) )
532                 {
533                     child->installEventFilter( this );
534                     childWidg->setEnabled( true );
535                 }
536             }
537
538             /* Decorating the frames when possible */
539             QFrame *frame;
540             if( i_type >= MENU_BUTTONS  /* Don't bother to check for volume */
541                 && ( frame = qobject_cast<QFrame *>( widg ) ) != NULL )
542             {
543                 frame->setFrameStyle( QFrame::Panel | QFrame::Raised );
544                 frame->setLineWidth ( 1 );
545             }
546         }
547
548         /* Some Widgets are deactivated at creation */
549         widg->setEnabled( true );
550         widg->show();
551         controlLayout->insertWidget( i_index, widg );
552     }
553
554     /* QList and QBoxLayout don't act the same with insert() */
555     if( i_index < 0 ) i_index = controlLayout->count() - 1;
556
557     /* Insert in the value listing */
558     doubleInt *value = new doubleInt;
559     value->i_type = i_type;
560     value->i_option = i_option;
561     widgetList.insert( i_index, value );
562 }
563
564 DroppingController::~DroppingController()
565 {
566     qDeleteAll( widgetList );
567     widgetList.clear();
568 }
569
570 QString DroppingController::getValue()
571 {
572     QString qs = "";
573
574     for( int i = 0; i < controlLayout->count(); i++ )
575     {
576         doubleInt *dI = widgetList.at( i );
577         assert( dI );
578
579         qs.append( QString::number( dI->i_type ) );
580         if( dI->i_option ) qs.append( "-" + QString::number( dI->i_option ) );
581         qs.append( ';' );
582     }
583     return qs;
584 }
585
586 void DroppingController::dragEnterEvent( QDragEnterEvent * event )
587 {
588     if( event->mimeData()->hasFormat( "vlc/button-bar" ) )
589         event->accept();
590     else
591         event->ignore();
592 }
593
594 void DroppingController::dragMoveEvent( QDragMoveEvent *event )
595 {
596     QPoint origin = event->pos();
597
598     int i_pos = getParentPosInLayout( origin );
599     bool b_end = false;
600
601     /* Both sides of the frame */
602     if( i_pos == -1 )
603     {
604         if( rubberband ) rubberband->hide();
605         return;
606     }
607
608     /* Last item is special because of underlying items */
609     if( i_pos >= controlLayout->count() )
610     {
611         i_pos--;
612         b_end = true;
613     }
614
615     /* Query the underlying item for size && middles */
616     QLayoutItem *tempItem = controlLayout->itemAt( i_pos ); assert( tempItem );
617     QWidget *temp = tempItem->widget(); assert( temp );
618
619     /* Position assignment */
620     origin.ry() = 0;
621     origin.rx() = temp->x() - 2;
622
623     if( b_end ) origin.rx() += temp->width();
624
625     if( !rubberband )
626         rubberband = new QRubberBand( QRubberBand::Line, this );
627     rubberband->setGeometry( origin.x(), origin.y(), 4, height() );
628     rubberband->show();
629 }
630
631 inline int DroppingController::getParentPosInLayout( QPoint point )
632 {
633     point.ry() = height() / 2 ;
634     QPoint origin = mapToGlobal ( point );
635
636     QWidget *tempWidg = QApplication::widgetAt( origin );
637
638     int i = -1;
639     if( tempWidg != NULL)
640     {
641         i = controlLayout->indexOf( tempWidg );
642         if( i == -1 )
643         {
644             i = controlLayout->indexOf( tempWidg->parentWidget() );
645             tempWidg = tempWidg->parentWidget();
646         }
647     }
648
649     /* Return the nearest position */
650     if( ( point.x() - tempWidg->x()  > tempWidg->width() / 2 ) && i != -1 )
651         i++;
652
653     //    msg_Dbg( p_intf, "%i", i);
654     return i;
655 }
656
657 void DroppingController::dropEvent( QDropEvent *event )
658 {
659     int i = getParentPosInLayout( event->pos() );
660
661     QByteArray data = event->mimeData()->data( "vlc/button-bar" );
662     QDataStream dataStream(&data, QIODevice::ReadOnly);
663
664     int i_option = 0, i_type = 0;
665     dataStream >> i_type >> i_option;
666
667     createAndAddWidget( controlLayout, i, (buttonType_e)i_type, i_option );
668
669     /* Hide by precaution, you don't exactly know what could have happened in
670        between */
671     if( rubberband ) rubberband->hide();
672 }
673
674 void DroppingController::dragLeaveEvent ( QDragLeaveEvent * event )
675 {
676     if( rubberband ) rubberband->hide();
677     event->accept();
678 }
679
680 /**
681  * Overloading doAction to block any action
682  **/
683 void DroppingController::doAction( int i )
684 {
685     VLC_UNUSED( i );
686 }
687
688 bool DroppingController::eventFilter( QObject *obj, QEvent *event )
689 {
690     switch( event->type() )
691     {
692         case QEvent::MouseButtonPress:
693             b_draging = true;
694             return true;
695         case QEvent::MouseButtonRelease:
696             b_draging = false;
697             return true;
698         case QEvent::MouseMove:
699             {
700             if( !b_draging ) return true;
701             QWidget *widg = static_cast<QWidget*>(obj);
702
703             QByteArray itemData;
704             QDataStream dataStream( &itemData, QIODevice::WriteOnly );
705
706             int i = -1;
707             i = controlLayout->indexOf( widg );
708             if( i == -1 )
709             {
710                 i = controlLayout->indexOf( widg->parentWidget() );
711                 widg = widg->parentWidget();
712                 /* NOTE: be extra-careful Now with widg access */
713             }
714
715             if( i == -1 ) return true;
716             doubleInt *dI = widgetList.at( i );
717
718             int i_type = dI->i_type;
719             int i_option = dI->i_option;
720             dataStream << i_type << i_option;
721
722             /* With correct mimedata */
723             QMimeData *mimeData = new QMimeData;
724             mimeData->setData( "vlc/button-bar", itemData );
725
726             QDrag *drag = new QDrag( widg );
727             drag->setMimeData( mimeData );
728
729             /* Start the effective drag */
730             drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::MoveAction);
731
732             widgetList.removeAt( i );
733             controlLayout->removeWidget( widg );
734             widg->hide();
735             b_draging = false;
736             }
737             return true;
738
739         case QEvent::MouseButtonDblClick:
740         case QEvent::EnabledChange:
741         case QEvent::Hide:
742         case QEvent::HideToParent:
743         case QEvent::Move:
744         case QEvent::ZOrderChange:
745             return true;
746         default:
747             return false;
748     }
749 }
750