]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/toolbar.cpp
qt4: use const for QString when possible.
[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
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     hide();
252     getSettings()->setValue( "MainWindow/ToolbarPos",
253             positionCombo->itemData( positionCombo->currentIndex() ).toInt() );
254     getSettings()->setValue( "MainWindow/MainToolbar1", controller1->getValue() );
255     getSettings()->setValue( "MainWindow/MainToolbar2", controller2->getValue() );
256     getSettings()->setValue( "MainWindow/AdvToolbar", controllerA->getValue() );
257     getSettings()->setValue( "MainWindow/InputToolbar", controller->getValue() );
258     getSettings()->setValue( "MainWindow/FSCtoolbar", controllerFSC->getValue() );
259 }
260
261 void ToolbarEditDialog::cancel()
262 {
263     hide();
264 }
265
266 /************************************************
267  *  Widget Listing:
268  * Creation of the list of drawed lovely buttons
269  ************************************************/
270 WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent )
271               : QListWidget( _parent )
272 {
273     /* We need the parent to know the options checked */
274     parent = qobject_cast<ToolbarEditDialog *>(_parent);
275     assert( parent );
276
277     /* Normal options */
278     setViewMode( QListView::IconMode );
279     setSpacing( 20 );
280     setDragEnabled( true );
281     setMinimumHeight( 250 );
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( ":/space" ),
295             qtr( "Spacer" ), this );
296     widgetItem->setData( Qt::UserRole, WIDGET_SPACER );
297     addItem( widgetItem );
298
299     widgetItem = new QListWidgetItem( QIcon( ":/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( "Small Volume" );
350                 widgetItem->setIcon( QIcon( ":/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( ":/dvd_prev" ) );
371                 discLayout->addWidget( prevSectionButton );
372
373                 QToolButton *menuButton = new QToolButton( discFrame );
374                 menuButton->setIcon( QIcon( ":/dvd_menu" ) );
375                 discLayout->addWidget( menuButton );
376
377                 QToolButton *nextButton = new QToolButton( discFrame );
378                 nextButton->setIcon( QIcon( ":/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( ":/tv" ) );
393                 telexLayout->addWidget( telexOn );
394
395                 QToolButton *telexTransparent = new QToolButton;
396                 telexOn->setIcon( QIcon( ":/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     int i =0;
485     while( (child = controlLayout->takeAt( 0 ) ) != 0 )
486     {
487         child->widget()->hide();
488         delete child;
489     }
490
491     parseAndCreate( line, controlLayout );
492     show();
493 }
494
495 /* Overloading the AbstractController one, because we don't manage the
496    Spacing items in the same ways */
497 void DroppingController::createAndAddWidget( QBoxLayout *controlLayout,
498                                              int i_index,
499                                              buttonType_e i_type,
500                                              int i_option )
501 {
502     /* Special case for SPACERS, who aren't QWidgets */
503     if( i_type == WIDGET_SPACER || i_type == WIDGET_SPACER_EXTEND )
504     {
505         QLabel *label = new QLabel;
506         label->setPixmap( QPixmap( ":/space" ) );
507         if( i_type == WIDGET_SPACER_EXTEND )
508         {
509             label->setSizePolicy( QSizePolicy::MinimumExpanding,
510                     QSizePolicy::Preferred );
511
512             /* Create a box around it */
513             label->setFrameStyle( QFrame::Panel | QFrame::Sunken );
514             label->setLineWidth ( 1 );
515             label->setAlignment( Qt::AlignCenter );
516         }
517         else
518             label->setSizePolicy( QSizePolicy::Fixed,
519                     QSizePolicy::Preferred );
520
521         /* Install event Filter for drag'n drop */
522         label->installEventFilter( this );
523         controlLayout->insertWidget( i_index, label );
524     }
525
526     /* Normal Widgets */
527     else
528     {
529         QWidget *widg = createWidget( i_type, i_option );
530         if( !widg ) return;
531
532         /* Install the Event Filter in order to catch the drag */
533         widg->installEventFilter( this );
534
535         /* We are in a complex widget, we need to stop events on children too */
536         if( i_type >= VOLUME && i_type < SPECIAL_MAX )
537         {
538             QList<QObject *>children = widg->children();
539
540             QObject *child;
541             foreach( child, children )
542             {
543                 QWidget *childWidg;
544                 if( childWidg = qobject_cast<QWidget *>( child ) )
545                 {
546                     child->installEventFilter( this );
547                     childWidg->setEnabled( true );
548                 }
549             }
550
551             /* Decorating the frames when possible */
552             QFrame *frame;
553             if( i_type >= MENU_BUTTONS  /* Don't bother to check for volume */
554                 && ( frame = qobject_cast<QFrame *>( widg ) ) != NULL )
555             {
556                 frame->setFrameStyle( QFrame::Panel | QFrame::Raised );
557                 frame->setLineWidth ( 1 );
558             }
559         }
560
561         /* Some Widgets are deactivated at creation */
562         widg->setEnabled( true );
563         widg->show();
564         controlLayout->insertWidget( i_index, widg );
565     }
566
567     /* QList and QBoxLayout don't act the same with insert() */
568     if( i_index < 0 ) i_index = controlLayout->count() - 1;
569
570     /* Insert in the value listing */
571     doubleInt *value = new doubleInt;
572     value->i_type = i_type;
573     value->i_option = i_option;
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
651     int i = -1;
652     if( tempWidg != NULL)
653     {
654         i = controlLayout->indexOf( tempWidg );
655         if( i == -1 )
656         {
657             i = controlLayout->indexOf( tempWidg->parentWidget() );
658             tempWidg = tempWidg->parentWidget();
659         }
660     }
661
662     /* Return the nearest position */
663     if( ( point.x() - tempWidg->x()  > tempWidg->width() / 2 ) && i != -1 )
664         i++;
665
666     //    msg_Dbg( p_intf, "%i", i);
667     return i;
668 }
669
670 void DroppingController::dropEvent( QDropEvent *event )
671 {
672     int i = getParentPosInLayout( event->pos() );
673
674     QByteArray data = event->mimeData()->data( "vlc/button-bar" );
675     QDataStream dataStream(&data, QIODevice::ReadOnly);
676
677     int i_option = 0, i_type = 0;
678     dataStream >> i_type >> i_option;
679
680     createAndAddWidget( controlLayout, i, (buttonType_e)i_type, i_option );
681
682     /* Hide by precaution, you don't exactly know what could have happened in
683        between */
684     if( rubberband ) rubberband->hide();
685 }
686
687 void DroppingController::dragLeaveEvent ( QDragLeaveEvent * event )
688 {
689     if( rubberband ) rubberband->hide();
690     event->accept();
691 }
692
693 /**
694  * Overloading doAction to block any action
695  **/
696 void DroppingController::doAction( int i )
697 {
698     VLC_UNUSED( i );
699 }
700
701 bool DroppingController::eventFilter( QObject *obj, QEvent *event )
702 {
703     switch( event->type() )
704     {
705         case QEvent::MouseButtonPress:
706             b_draging = true;
707             return true;
708         case QEvent::MouseButtonRelease:
709             b_draging = false;
710             return true;
711         case QEvent::MouseMove:
712             {
713             if( !b_draging ) return true;
714             QWidget *widg = static_cast<QWidget*>(obj);
715
716             QByteArray itemData;
717             QDataStream dataStream( &itemData, QIODevice::WriteOnly );
718
719             int i = -1;
720             i = controlLayout->indexOf( widg );
721             if( i == -1 )
722             {
723                 i = controlLayout->indexOf( widg->parentWidget() );
724                 widg = widg->parentWidget();
725                 /* NOTE: be extra-careful Now with widg access */
726             }
727
728             if( i == -1 ) return true;
729             doubleInt *dI = widgetList.at( i );
730
731             int i_type = dI->i_type;
732             int i_option = dI->i_option;
733             dataStream << i_type << i_option;
734
735             /* With correct mimedata */
736             QMimeData *mimeData = new QMimeData;
737             mimeData->setData( "vlc/button-bar", itemData );
738
739             QDrag *drag = new QDrag( widg );
740             drag->setMimeData( mimeData );
741
742             /* Start the effective drag */
743             drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::MoveAction);
744
745             widgetList.removeAt( i );
746             controlLayout->removeWidget( widg );
747             widg->hide();
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