]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/toolbar.cpp
Qt: ToolbarEditDialog: show tooltip on widgets list
[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 <QGroupBox>
43 #include <QLabel>
44 #include <QComboBox>
45 #include <QListWidget>
46 #include <QSpinBox>
47 #include <QRubberBand>
48 #include <QDrag>
49 #include <QDragEnterEvent>
50 #include <QDialogButtonBox>
51 #include <QInputDialog>
52 #include <QMimeData>
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_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 ) );
193     }
194     profileCombo->setCurrentIndex( -1 );
195
196     /* Buttons */
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 );
203
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 );
210 }
211
212
213 ToolbarEditDialog::~ToolbarEditDialog()
214 {
215     getSettings()->beginWriteArray( "ToolbarProfiles" );
216     for( int i = 0; i < profileCombo->count(); i++ )
217     {
218         getSettings()->setArrayIndex(i);
219         getSettings()->setValue( "ProfileName", profileCombo->itemText( i ) );
220         getSettings()->setValue( "Value", profileCombo->itemData( i ) );
221     }
222     getSettings()->endArray();
223 }
224
225 void ToolbarEditDialog::newProfile()
226 {
227     bool ok;
228     QString name =  QInputDialog::getText( this, qtr( "Profile Name" ),
229                  qtr( "Please enter the new profile name." ), QLineEdit::Normal, 0, &ok );
230     if( !ok ) return;
231
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();
238
239     profileCombo->addItem( name, temp );
240     profileCombo->setCurrentIndex( profileCombo->count() - 1 );
241 }
242
243 void ToolbarEditDialog::deleteProfile()
244 {
245     profileCombo->removeItem( profileCombo->currentIndex() );
246 }
247
248 void ToolbarEditDialog::changeProfile( int i )
249 {
250     QStringList qs_list = profileCombo->itemData( i ).toString().split( "|" );
251     if( qs_list.count() < 6 )
252         return;
253
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] );
260 }
261
262 void ToolbarEditDialog::close()
263 {
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         widgetItem->setToolTip( widgetItem->text() );
309         addItem( widgetItem );
310     }
311
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 );
318
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 );
324
325     /**
326      * For all other widgets, we create then, do a pseudo rendering in
327      * a pixmaps for the view, and delete the object
328      *
329      * A lot of code is retaken from the Abstract, but not exactly...
330      * So, rewrite.
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.
333      * --
334      * jb
335      **/
336     for( int i = SPLITTER; i < SPECIAL_MAX; i++ )
337     {
338         QWidget *widget = NULL;
339         QListWidgetItem *widgetItem = new QListWidgetItem( this );
340         switch( i )
341         {
342         case SPLITTER:
343             {
344                 QFrame *line = new QFrame( this );
345                 line->setFrameShape( QFrame::VLine );
346                 line->setFrameShadow( QFrame::Raised );
347                 line->setLineWidth( 0 ); line->setMidLineWidth( 1 );
348                 widget = line;
349             }
350             widgetItem->setText( qtr("Splitter") );
351             break;
352         case INPUT_SLIDER:
353             {
354                 SeekSlider *slider = new SeekSlider( Qt::Horizontal, this );
355                 widget = slider;
356             }
357             widgetItem->setText( qtr("Time Slider") );
358             break;
359         case VOLUME:
360             {
361                 SoundWidget *snd = new SoundWidget( this, p_intf,
362                         parent->getOptions() & WIDGET_SHINY );
363                 widget = snd;
364             }
365             widgetItem->setText( qtr("Volume") );
366             break;
367         case VOLUME_SPECIAL:
368             {
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 );
374             }
375             continue;
376         case TIME_LABEL:
377             {
378                 QLabel *timeLabel = new QLabel( "12:42/2:12:42", this );
379                 widget = timeLabel;
380             }
381             widgetItem->setText( qtr("Time") );
382             break;
383         case MENU_BUTTONS:
384             {
385                 QWidget *discFrame = new QWidget( this );
386                 //discFrame->setLineWidth( 1 );
387                 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
388                 discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
389
390                 QToolButton *prevSectionButton = new QToolButton( discFrame );
391                 prevSectionButton->setIcon( QIcon( ":/toolbar/dvd_prev" ) );
392                 prevSectionButton->setToolTip( qtr("Previous chapter") );
393                 discLayout->addWidget( prevSectionButton );
394
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 );
399
400                 QToolButton *nextButton = new QToolButton( discFrame );
401                 nextButton->setIcon( QIcon( ":/toolbar/dvd_next" ) );
402                 nextButton->setToolTip( qtr("Next chapter") );
403                 discLayout->addWidget( nextButton );
404
405                 widget = discFrame;
406             }
407             widgetItem->setText( qtr("DVD menus") );
408             break;
409         case TELETEXT_BUTTONS:
410             {
411                 QWidget *telexFrame = new QWidget( this );
412                 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
413                 telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
414
415                 QToolButton *telexOn = new QToolButton( telexFrame );
416                 telexOn->setIcon( QIcon( ":/toolbar/tv" ) );
417                 telexLayout->addWidget( telexOn );
418
419                 QToolButton *telexTransparent = new QToolButton;
420                 telexTransparent->setIcon( QIcon( ":/toolbar/tvtelx" ) );
421                 telexTransparent->setToolTip( qtr("Teletext transparency") );
422                 telexLayout->addWidget( telexTransparent );
423
424                 QSpinBox *telexPage = new QSpinBox;
425                 telexLayout->addWidget( telexPage );
426
427                 widget = telexFrame;
428             }
429             widgetItem->setText( qtr("Teletext") );
430             break;
431         case ADVANCED_CONTROLLER:
432             {
433                 AdvControlsWidget *advControls = new AdvControlsWidget( p_intf, this );
434                 widget = advControls;
435             }
436             widgetItem->setText( qtr("Advanced Buttons") );
437             break;
438         case PLAYBACK_BUTTONS:
439             {
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 );
448             }
449             widgetItem->setText( qtr("Playback Buttons") );
450             break;
451         case ASPECT_RATIO_COMBOBOX:
452             widget = new AspectRatioComboBox( p_intf );
453             widgetItem->setText( qtr("Aspect ratio selector") );
454             break;
455         case SPEED_LABEL:
456             widget = new SpeedLabel( p_intf, this );
457             widgetItem->setText( qtr("Speed selector") );
458             break;
459         case TIME_LABEL_ELAPSED:
460             widget = new QLabel( "2:42", this );
461             widgetItem->setText( qtr("Elapsed time") );
462             break;
463         case TIME_LABEL_REMAINING:
464             widget = new QLabel( "-2:42", this );
465             widgetItem->setText( qtr("Total/Remaining time") );
466             break;
467         default:
468             msg_Warn( p_intf, "This should not happen %i", i );
469             break;
470         }
471
472         if( widget == NULL ) continue;
473
474
475         widgetItem->setIcon( QIcon( QPixmap::grabWidget( widget ) ) );
476         widgetItem->setToolTip( widgetItem->text() );
477         widget->hide();
478         widgetItem->setData( Qt::UserRole, QVariant( i ) );
479
480         addItem( widgetItem );
481         delete widget;
482     }
483 }
484
485 void WidgetListing::startDrag( Qt::DropActions /*supportedActions*/ )
486 {
487     QListWidgetItem *item = currentItem();
488
489     QByteArray itemData;
490     QDataStream dataStream( &itemData, QIODevice::WriteOnly );
491
492     int i_type = item->data( Qt::UserRole ).toInt();
493     int i_option = parent->getOptions();
494     dataStream << i_type << i_option;
495
496     /* Create a new dragging event */
497     QDrag *drag = new QDrag( this );
498
499     /* With correct mimedata */
500     QMimeData *mimeData = new QMimeData;
501     mimeData->setData( "vlc/button-bar", itemData );
502     drag->setMimeData( mimeData );
503
504     /* And correct pixmap */
505     QPixmap aPixmap = item->icon().pixmap( QSize( 22, 22 ) );
506     drag->setPixmap( aPixmap );
507     drag->setHotSpot( QPoint( 20, 20 ) );
508
509     /* We want to keep a copy */
510     drag->exec( Qt::CopyAction | Qt::MoveAction );
511 }
512
513 /*
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
517  */
518 DroppingController::DroppingController( intf_thread_t *_p_intf,
519                                         const QString& line,
520                                         QWidget *_parent )
521                    : AbstractController( _p_intf, _parent )
522 {
523     RTL_UNAFFECTED_WIDGET
524     rubberband = NULL;
525     b_draging = false;
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 );
533
534     parseAndCreate( line, controlLayout );
535 }
536
537 void DroppingController::resetLine( const QString& line )
538 {
539     hide();
540     QLayoutItem *child;
541     while( (child = controlLayout->takeAt( 0 ) ) != 0 )
542     {
543         child->widget()->hide();
544         delete child;
545     }
546
547     parseAndCreate( line, controlLayout );
548     show();
549 }
550
551 /* Overloading the AbstractController one, because we don't manage the
552    Spacing items in the same ways */
553 void DroppingController::createAndAddWidget( QBoxLayout *newControlLayout,
554                                              int i_index,
555                                              buttonType_e i_type,
556                                              int i_option )
557 {
558     doubleInt *value = new doubleInt;
559     value->i_type = i_type;
560     value->i_option = i_option;
561
562     /* Special case for SPACERS, who aren't QWidgets */
563     if( i_type == WIDGET_SPACER || i_type == WIDGET_SPACER_EXTEND )
564     {
565         QLabel *label = new QLabel( this );
566         label->setPixmap( QPixmap( ":/toolbar/space" ) );
567         if( i_type == WIDGET_SPACER_EXTEND )
568         {
569             label->setSizePolicy( QSizePolicy::MinimumExpanding,
570                     QSizePolicy::Preferred );
571
572             /* Create a box around it */
573             label->setFrameStyle( QFrame::Panel | QFrame::Sunken );
574             label->setLineWidth ( 1 );
575             label->setAlignment( Qt::AlignCenter );
576         }
577         else
578             label->setSizePolicy( QSizePolicy::Fixed,
579                     QSizePolicy::Preferred );
580
581         /* Install event Filter for drag'n drop */
582         label->installEventFilter( this );
583         newControlLayout->insertWidget( i_index, label );
584     }
585
586     /* Normal Widgets */
587     else
588     {
589         QWidget *widg = createWidget( i_type, i_option );
590         if( !widg ) return;
591
592         /* Install the Event Filter in order to catch the drag */
593         widg->setParent( this );
594         widg->installEventFilter( this );
595
596         /* We are in a complex widget, we need to stop events on children too */
597         if( i_type >= VOLUME && i_type < SPECIAL_MAX )
598         {
599             QList<QObject *>children = widg->children();
600
601             QObject *child;
602             foreach( child, children )
603             {
604                 QWidget *childWidg;
605                 if( ( childWidg = qobject_cast<QWidget *>( child ) ) )
606                 {
607                     child->installEventFilter( this );
608                     childWidg->setEnabled( true );
609                 }
610             }
611
612             /* Decorating the frames when possible */
613             QFrame *frame;
614             if( i_type >= MENU_BUTTONS  /* Don't bother to check for volume */
615                 && ( frame = qobject_cast<QFrame *>( widg ) ) != NULL )
616             {
617                 frame->setFrameStyle( QFrame::Panel | QFrame::Raised );
618                 frame->setLineWidth ( 1 );
619             }
620         }
621
622         /* Some Widgets are deactivated at creation */
623         widg->setEnabled( true );
624         widg->show();
625         newControlLayout->insertWidget( i_index, widg );
626     }
627
628     /* QList and QBoxLayout don't act the same with insert() */
629     if( i_index < 0 ) i_index = newControlLayout->count() - 1;
630
631     widgetList.insert( i_index, value );
632 }
633
634 DroppingController::~DroppingController()
635 {
636     qDeleteAll( widgetList );
637     widgetList.clear();
638 }
639
640 QString DroppingController::getValue()
641 {
642     QString qs = "";
643
644     for( int i = 0; i < controlLayout->count(); i++ )
645     {
646         doubleInt *dI = widgetList.at( i );
647         assert( dI );
648
649         qs.append( QString::number( dI->i_type ) );
650         if( dI->i_option ) qs.append( "-" + QString::number( dI->i_option ) );
651         qs.append( ';' );
652     }
653     return qs;
654 }
655
656 void DroppingController::dragEnterEvent( QDragEnterEvent * event )
657 {
658     if( event->mimeData()->hasFormat( "vlc/button-bar" ) )
659         event->accept();
660     else
661         event->ignore();
662 }
663
664 void DroppingController::dragMoveEvent( QDragMoveEvent *event )
665 {
666     QPoint origin = event->pos();
667
668     int i_pos = getParentPosInLayout( origin );
669     bool b_end = false;
670
671     /* Both sides of the frame */
672     if( i_pos == -1 )
673     {
674         if( rubberband ) rubberband->hide();
675         return;
676     }
677
678     /* Last item is special because of underlying items */
679     if( i_pos >= controlLayout->count() )
680     {
681         i_pos--;
682         b_end = true;
683     }
684
685     /* Query the underlying item for size && middles */
686     QLayoutItem *tempItem = controlLayout->itemAt( i_pos ); assert( tempItem );
687     QWidget *temp = tempItem->widget(); assert( temp );
688
689     /* Position assignment */
690     origin.ry() = 0;
691     origin.rx() = temp->x() - 2;
692
693     if( b_end ) origin.rx() += temp->width();
694
695     if( !rubberband )
696         rubberband = new QRubberBand( QRubberBand::Line, this );
697     rubberband->setGeometry( origin.x(), origin.y(), 4, height() );
698     rubberband->show();
699 }
700
701 inline int DroppingController::getParentPosInLayout( QPoint point )
702 {
703     point.ry() = height() / 2 ;
704     QPoint origin = mapToGlobal ( point );
705
706     QWidget *tempWidg = QApplication::widgetAt( origin );
707     if( tempWidg == NULL )
708         return -1;
709
710     int i = controlLayout->indexOf( tempWidg );
711     if( i == -1 )
712     {
713         i = controlLayout->indexOf( tempWidg->parentWidget() );
714         tempWidg = tempWidg->parentWidget();
715     }
716
717     /* Return the nearest position */
718     if( ( point.x() - tempWidg->x()  > tempWidg->width() / 2 ) && i != -1 )
719         i++;
720
721     //    msg_Dbg( p_intf, "%i", i);
722     return i;
723 }
724
725 void DroppingController::dropEvent( QDropEvent *event )
726 {
727     int i = getParentPosInLayout( event->pos() );
728
729     QByteArray data = event->mimeData()->data( "vlc/button-bar" );
730     QDataStream dataStream(&data, QIODevice::ReadOnly);
731
732     int i_option = 0, i_type = 0;
733     dataStream >> i_type >> i_option;
734
735     createAndAddWidget( controlLayout, i, (buttonType_e)i_type, i_option );
736
737     /* Hide by precaution, you don't exactly know what could have happened in
738        between */
739     if( rubberband ) rubberband->hide();
740 }
741
742 void DroppingController::dragLeaveEvent ( QDragLeaveEvent * event )
743 {
744     if( rubberband ) rubberband->hide();
745     event->accept();
746 }
747
748 /**
749  * Overloading doAction to block any action
750  **/
751 void DroppingController::doAction( int i )
752 {
753     VLC_UNUSED( i );
754 }
755
756 bool DroppingController::eventFilter( QObject *obj, QEvent *event )
757 {
758     switch( event->type() )
759     {
760         case QEvent::MouseButtonPress:
761             b_draging = true;
762             return true;
763         case QEvent::MouseButtonRelease:
764             b_draging = false;
765             return true;
766         case QEvent::MouseMove:
767             {
768             if( !b_draging ) return true;
769             QWidget *widg = static_cast<QWidget*>(obj);
770
771             QByteArray itemData;
772             QDataStream dataStream( &itemData, QIODevice::WriteOnly );
773
774             int i = -1;
775             i = controlLayout->indexOf( widg );
776             if( i == -1 )
777             {
778                 i = controlLayout->indexOf( widg->parentWidget() );
779                 widg = widg->parentWidget();
780                 /* NOTE: be extra-careful Now with widg access */
781             }
782
783             if( i == -1 ) return true;
784             i_dragIndex = i;
785
786             doubleInt *dI = widgetList.at( i );
787
788             int i_type = dI->i_type;
789             int i_option = dI->i_option;
790             dataStream << i_type << i_option;
791
792             /* With correct mimedata */
793             QMimeData *mimeData = new QMimeData;
794             mimeData->setData( "vlc/button-bar", itemData );
795
796             QDrag *drag = new QDrag( widg );
797             drag->setMimeData( mimeData );
798
799             /* Remove before the drag to not mess DropEvent,
800                that will createAndAddWidget */
801             widgetList.removeAt( i );
802             controlLayout->removeWidget( widg );
803             widg->hide();
804
805             /* Start the effective drag */
806             drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::MoveAction);
807             b_draging = false;
808             }
809             return true;
810
811         case QEvent::MouseButtonDblClick:
812         case QEvent::EnabledChange:
813         case QEvent::Hide:
814         case QEvent::HideToParent:
815         case QEvent::Move:
816         case QEvent::ZOrderChange:
817             return true;
818         default:
819             return false;
820     }
821 }