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