1 /*****************************************************************************
2 * toolbar.cpp : ToolbarEdit dialog
3 ****************************************************************************
4 * Copyright (C) 2008-2009 the VideoLAN team
7 * Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
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.
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.
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 *****************************************************************************/
28 #include "dialogs/toolbar.hpp"
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"
39 #include "input_manager.hpp"
40 #include <vlc_vout.h> /* vout_thread_t for aspect ratio combobox */
45 #include <QListWidget>
47 #include <QRubberBand>
49 #include <QDragEnterEvent>
50 #include <QDialogButtonBox>
51 #include <QInputDialog>
53 #include <QFormLayout>
54 #include <QVBoxLayout>
56 #include <QSignalMapper>
60 ToolbarEditDialog::ToolbarEditDialog( QWidget *_w, intf_thread_t *_p_intf)
61 : QVLCDialog( _w, _p_intf )
63 setWindowTitle( qtr( "Toolbars Editor" ) );
64 setWindowRole( "vlc-toolbars-editor" );
65 QGridLayout *mainLayout = new QGridLayout( this );
66 setMinimumWidth( 600 );
67 setAttribute( Qt::WA_DeleteOnClose );
70 QGroupBox *widgetBox = new QGroupBox( qtr( "Toolbar Elements") , this );
71 widgetBox->setSizePolicy( QSizePolicy::Preferred,
72 QSizePolicy::MinimumExpanding );
73 QGridLayout *boxLayout = new QGridLayout( widgetBox );
75 flatBox = new QCheckBox( qtr( "Flat Button" ) );
76 flatBox->setToolTip( qtr( "Next widget style" ) );
77 bigBox = new QCheckBox( qtr( "Big Button" ) );
78 bigBox->setToolTip( flatBox->toolTip() );
79 shinyBox = new QCheckBox( qtr( "Native Slider" ) );
80 shinyBox->setToolTip( flatBox->toolTip() );
82 boxLayout->addWidget( new WidgetListing( p_intf, this ), 1, 0, 1, -1 );
83 boxLayout->addWidget( flatBox, 0, 0 );
84 boxLayout->addWidget( bigBox, 0, 1 );
85 boxLayout->addWidget( shinyBox, 0, 2 );
86 mainLayout->addWidget( widgetBox, 5, 0, 3, 6 );
88 QTabWidget *tabWidget = new QTabWidget();
89 mainLayout->addWidget( tabWidget, 1, 0, 4, 9 );
92 QWidget *mainToolbarBox = new QWidget();
93 tabWidget->addTab( mainToolbarBox, qtr( "Main Toolbar" ) );
94 QFormLayout *mainTboxLayout = new QFormLayout( mainToolbarBox );
96 positionCheckbox = new QCheckBox( qtr( "Above the Video" ) );
97 positionCheckbox->setChecked(
98 getSettings()->value( "MainWindow/ToolbarPos", 0 ).toInt() );
99 mainTboxLayout->addRow( new QLabel( qtr( "Toolbar position:" ) ),
102 QString line1 = getSettings()->value( "MainWindow/MainToolbar1",
103 MAIN_TB1_DEFAULT ).toString();
104 controller1 = new DroppingController( p_intf, line1, this );
105 mainTboxLayout->addRow( new QLabel( qtr("Line 1:") ), controller1 );
107 QString line2 = getSettings()->value( "MainWindow/MainToolbar2",
108 MAIN_TB2_DEFAULT ).toString();
109 controller2 = new DroppingController( p_intf, line2, this );
110 mainTboxLayout->addRow( new QLabel( qtr("Line 2:") ), controller2 );
113 QString line = getSettings()->value( "MainWindow/InputToolbar",
114 INPT_TB_DEFAULT ).toString();
115 controller = new DroppingController( p_intf, line, this );
116 QWidget *timeToolbarBox = new QWidget();
117 timeToolbarBox->setLayout( new QVBoxLayout() );
118 timeToolbarBox->layout()->addWidget( controller );
119 tabWidget->addTab( timeToolbarBox, qtr( "Time Toolbar" ) );
121 /* Advanced ToolBar */
122 QString lineA = getSettings()->value( "MainWindow/AdvToolbar",
123 ADV_TB_DEFAULT ).toString();
124 controllerA = new DroppingController( p_intf, lineA, this );
125 QWidget *advToolbarBox = new QWidget();
126 advToolbarBox->setLayout( new QVBoxLayout() );
127 advToolbarBox->layout()->addWidget( controllerA );
128 tabWidget->addTab( advToolbarBox, qtr( "Advanced Widget" ) );
131 QString lineFSC = getSettings()->value( "MainWindow/FSCtoolbar",
132 FSC_TB_DEFAULT ).toString();
133 controllerFSC = new DroppingController( p_intf, lineFSC, this );
134 QWidget *FSCToolbarBox = new QWidget();
135 FSCToolbarBox->setLayout( new QVBoxLayout() );
136 FSCToolbarBox->layout()->addWidget( controllerFSC );
137 tabWidget->addTab( FSCToolbarBox, qtr( "Fullscreen Controller" ) );
140 QGridLayout *profileBoxLayout = new QGridLayout();
142 profileCombo = new QComboBox;
144 QToolButton *newButton = new QToolButton;
145 newButton->setIcon( QIcon( ":/new" ) );
146 newButton->setToolTip( qtr("New profile") );
147 QToolButton *deleteButton = new QToolButton;
148 deleteButton->setIcon( QIcon( ":/toolbar/clear" ) );
149 deleteButton->setToolTip( qtr( "Delete the current profile" ) );
151 profileBoxLayout->addWidget( new QLabel( qtr( "Select profile:" ) ), 0, 0 );
152 profileBoxLayout->addWidget( profileCombo, 0, 1 );
153 profileBoxLayout->addWidget( newButton, 0, 2 );
154 profileBoxLayout->addWidget( deleteButton, 0, 3 );
156 mainLayout->addLayout( profileBoxLayout, 0, 0, 1, 9 );
159 int i_size = getSettings()->beginReadArray( "ToolbarProfiles" );
160 for( int i = 0; i < i_size; i++ )
162 getSettings()->setArrayIndex(i);
163 profileCombo->addItem( getSettings()->value( "ProfileName" ).toString(),
164 getSettings()->value( "Value" ).toString() );
166 getSettings()->endArray();
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 */
174 profileCombo->addItem( PROFILE_NAME_6, QString( VALUE_6 ) );
175 profileCombo->addItem( PROFILE_NAME_1, QString( VALUE_1 ) );
176 profileCombo->addItem( PROFILE_NAME_2, QString( VALUE_2 ) );
177 profileCombo->addItem( PROFILE_NAME_3, QString( VALUE_3 ) );
178 profileCombo->addItem( PROFILE_NAME_4, QString( VALUE_4 ) );
179 profileCombo->addItem( PROFILE_NAME_5, QString( VALUE_5 ) );
181 profileCombo->setCurrentIndex( -1 );
183 /* Build and prepare our preview */
184 PreviewWidget *previewWidget = new PreviewWidget( controller, controller1, controller2 );
185 QGroupBox *previewBox = new QGroupBox( qtr("Preview"), this );
186 previewBox->setLayout( new QVBoxLayout() );
187 previewBox->layout()->addWidget( previewWidget );
188 mainLayout->addWidget( previewBox, 5, 6, 3, 3 );
189 CONNECT( positionCheckbox, stateChanged(int),
190 previewWidget, setBarsTopPosition(int) );
193 QDialogButtonBox *okCancel = new QDialogButtonBox;
194 QPushButton *okButton = new QPushButton( qtr( "Cl&ose" ), this );
195 okButton->setDefault( true );
196 QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ), this );
197 okCancel->addButton( okButton, QDialogButtonBox::AcceptRole );
198 okCancel->addButton( cancelButton, QDialogButtonBox::RejectRole );
200 BUTTONACT( deleteButton, deleteProfile() );
201 BUTTONACT( newButton, newProfile() );
202 CONNECT( profileCombo, currentIndexChanged( int ), this, changeProfile( int ) );
203 BUTTONACT( okButton, close() );
204 BUTTONACT( cancelButton, cancel() );
205 mainLayout->addWidget( okCancel, 8, 0, 1, 9 );
209 ToolbarEditDialog::~ToolbarEditDialog()
211 getSettings()->beginWriteArray( "ToolbarProfiles" );
212 for( int i = 0; i < profileCombo->count(); i++ )
214 getSettings()->setArrayIndex(i);
215 getSettings()->setValue( "ProfileName", profileCombo->itemText( i ) );
216 getSettings()->setValue( "Value", profileCombo->itemData( i ) );
218 getSettings()->endArray();
221 void ToolbarEditDialog::newProfile()
224 QString name = QInputDialog::getText( this, qtr( "Profile Name" ),
225 qtr( "Please enter the new profile name." ), QLineEdit::Normal, 0, &ok );
228 QString temp = QString::number( !!positionCheckbox->isChecked() );
229 temp += "|" + controller1->getValue();
230 temp += "|" + controller2->getValue();
231 temp += "|" + controllerA->getValue();
232 temp += "|" + controller->getValue();
233 temp += "|" + controllerFSC->getValue();
235 profileCombo->addItem( name, temp );
236 profileCombo->setCurrentIndex( profileCombo->count() - 1 );
239 void ToolbarEditDialog::deleteProfile()
241 profileCombo->removeItem( profileCombo->currentIndex() );
244 void ToolbarEditDialog::changeProfile( int i )
246 QStringList qs_list = profileCombo->itemData( i ).toString().split( "|" );
247 if( qs_list.count() < 6 )
250 positionCheckbox->setChecked( qs_list[0].toInt() );
251 controller1->resetLine( qs_list[1] );
252 controller2->resetLine( qs_list[2] );
253 controllerA->resetLine( qs_list[3] );
254 controller->resetLine( qs_list[4] );
255 controllerFSC->resetLine( qs_list[5] );
258 void ToolbarEditDialog::close()
260 getSettings()->setValue( "MainWindow/ToolbarPos", !!positionCheckbox->isChecked() );
261 getSettings()->setValue( "MainWindow/MainToolbar1", controller1->getValue() );
262 getSettings()->setValue( "MainWindow/MainToolbar2", controller2->getValue() );
263 getSettings()->setValue( "MainWindow/AdvToolbar", controllerA->getValue() );
264 getSettings()->setValue( "MainWindow/InputToolbar", controller->getValue() );
265 getSettings()->setValue( "MainWindow/FSCtoolbar", controllerFSC->getValue() );
266 getSettings()->sync();
270 void ToolbarEditDialog::cancel()
276 PreviewWidget::PreviewWidget( QWidget *a, QWidget *b, QWidget *c )
282 for ( int i=0; i<3; i++ ) bars[i]->installEventFilter( this );
283 setAutoFillBackground( true );
284 setBarsTopPosition( false );
287 void PreviewWidget::setBarsTopPosition( int b )
293 void PreviewWidget::paintEvent( QPaintEvent * )
295 int i_total = 0, i_offset = 0, i;
296 QPainter painter( this );
298 for( int i=0; i<3; i++ )
300 pixmaps[i] = QPixmap::grabWidget( bars[i], bars[i]->contentsRect() );
301 for( int j=0; j < bars[i]->layout()->count(); j++ )
303 QLayoutItem *item = bars[i]->layout()->itemAt( j );
304 if ( !strcmp( item->widget()->metaObject()->className(), "QLabel" ) )
306 QPainter eraser( &pixmaps[i] );
307 eraser.fillRect( item->geometry(), palette().background() );
311 pixmaps[i] = pixmaps[i].scaled( size(), Qt::KeepAspectRatio );
315 i_total += pixmaps[i].size().height();
318 i = ( b_top ) ? 1 : 3;
321 painter.drawPixmap( pixmaps[i].rect().translated( 0, i_offset ), pixmaps[i] );
322 i_offset += pixmaps[i].rect().height();
325 /* Draw central area */
326 QRect conearea( 0, i_offset, size().width(), size().height() - i_total );
327 painter.fillRect( conearea, Qt::black );
328 QPixmap cone = QPixmap( ":/logo/vlc128.png" );
329 if ( ( conearea.size() - QSize(10, 10) - cone.size() ).isEmpty() )
330 cone = cone.scaled( conearea.size() - QSize(10, 10), Qt::KeepAspectRatio );
331 if ( cone.size().isValid() )
333 painter.drawPixmap( ((conearea.size() - cone.size()) / 2).width(),
334 i_offset + ((conearea.size() - cone.size()) / 2).height(),
338 /* Draw bottom bars */
339 i_offset += conearea.height();
340 for( i = 0 ; i< ((b_top) ? 1 : 3); i++ )
342 painter.drawPixmap( pixmaps[i].rect().translated( 0, i_offset ), pixmaps[i] );
343 i_offset += pixmaps[i].rect().height();
347 painter.fillRect( rect(), QColor( 255, 255, 255, 128 ) );
352 bool PreviewWidget::eventFilter( QObject *obj, QEvent *event )
355 return QWidget::eventFilter( obj, event );
357 if ( event->type() == QEvent::LayoutRequest )
362 /************************************************
364 * Creation of the list of drawed lovely buttons
365 ************************************************/
366 WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent )
367 : QListWidget( _parent )
369 /* We need the parent to know the options checked */
370 parent = qobject_cast<ToolbarEditDialog *>(_parent);
374 setViewMode( QListView::ListMode );
375 setTextElideMode( Qt::ElideNone );
376 setDragEnabled( true );
377 setIconSize( QSize( 64, 32 ) );
379 /* All the buttons do not need a special rendering */
380 for( int i = 0; i < BUTTON_MAX; i++ )
382 QListWidgetItem *widgetItem = new QListWidgetItem( this );
383 widgetItem->setText( qtr( nameL[i] ) );
384 widgetItem->setSizeHint( QSize( widgetItem->sizeHint().width(), 32 ) );
385 QPixmap pix( iconL[i] );
386 widgetItem->setIcon( pix.scaled( 16, 16, Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
387 widgetItem->setData( Qt::UserRole, QVariant( i ) );
388 widgetItem->setToolTip( widgetItem->text() );
389 addItem( widgetItem );
392 /* Spacers are yet again a different thing */
393 QListWidgetItem *widgetItem = new QListWidgetItem( QIcon( ":/toolbar/space" ),
394 qtr( "Spacer" ), this );
395 widgetItem->setData( Qt::UserRole, WIDGET_SPACER );
396 widgetItem->setToolTip( widgetItem->text() );
397 widgetItem->setSizeHint( QSize( widgetItem->sizeHint().width(), 32 ) );
398 addItem( widgetItem );
400 widgetItem = new QListWidgetItem( QIcon( ":/toolbar/space" ),
401 qtr( "Expanding Spacer" ), this );
402 widgetItem->setData( Qt::UserRole, WIDGET_SPACER_EXTEND );
403 widgetItem->setToolTip( widgetItem->text() );
404 widgetItem->setSizeHint( QSize( widgetItem->sizeHint().width(), 32 ) );
405 addItem( widgetItem );
408 * For all other widgets, we create then, do a pseudo rendering in
409 * a pixmaps for the view, and delete the object
411 * A lot of code is retaken from the Abstract, but not exactly...
413 * They are better ways to deal with this, but I doubt that this is
414 * necessary. If you feel like you have the time, be my guest.
418 for( int i = SPLITTER; i < SPECIAL_MAX; i++ )
420 QWidget *widget = NULL;
421 QListWidgetItem *widgetItem = new QListWidgetItem( this );
422 widgetItem->setSizeHint( QSize( widgetItem->sizeHint().width(), 32 ) );
427 QFrame *line = new QFrame( this );
428 line->setFrameShape( QFrame::VLine );
429 line->setFrameShadow( QFrame::Raised );
430 line->setLineWidth( 0 ); line->setMidLineWidth( 1 );
433 widgetItem->setText( qtr("Splitter") );
437 SeekSlider *slider = new SeekSlider( Qt::Horizontal, this );
440 widgetItem->setText( qtr("Time Slider") );
444 SoundWidget *snd = new SoundWidget( this, p_intf,
445 parent->getOptions() & WIDGET_SHINY );
448 widgetItem->setText( qtr("Volume") );
452 QListWidgetItem *widgetItem = new QListWidgetItem( this );
453 widgetItem->setText( qtr("Small Volume") );
454 widgetItem->setIcon( QIcon( ":/toolbar/volume-medium" ) );
455 widgetItem->setData( Qt::UserRole, QVariant( i ) );
456 addItem( widgetItem );
461 QLabel *timeLabel = new QLabel( "12:42/2:12:42", this );
464 widgetItem->setText( qtr("Time") );
468 QWidget *discFrame = new QWidget( this );
469 //discFrame->setLineWidth( 1 );
470 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
471 discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
473 QToolButton *prevSectionButton = new QToolButton( discFrame );
474 prevSectionButton->setIcon( QIcon( ":/toolbar/dvd_prev" ) );
475 prevSectionButton->setToolTip( qtr("Previous chapter") );
476 discLayout->addWidget( prevSectionButton );
478 QToolButton *menuButton = new QToolButton( discFrame );
479 menuButton->setIcon( QIcon( ":/toolbar/dvd_menu" ) );
480 menuButton->setToolTip( qtr("Go to the DVD menu") );
481 discLayout->addWidget( menuButton );
483 QToolButton *nextButton = new QToolButton( discFrame );
484 nextButton->setIcon( QIcon( ":/toolbar/dvd_next" ) );
485 nextButton->setToolTip( qtr("Next chapter") );
486 discLayout->addWidget( nextButton );
490 widgetItem->setText( qtr("DVD menus") );
492 case TELETEXT_BUTTONS:
494 QWidget *telexFrame = new QWidget( this );
495 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
496 telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
498 QToolButton *telexOn = new QToolButton( telexFrame );
499 telexOn->setIcon( QIcon( ":/toolbar/tv" ) );
500 telexLayout->addWidget( telexOn );
502 QToolButton *telexTransparent = new QToolButton;
503 telexTransparent->setIcon( QIcon( ":/toolbar/tvtelx" ) );
504 telexTransparent->setToolTip( qtr("Teletext transparency") );
505 telexLayout->addWidget( telexTransparent );
507 QSpinBox *telexPage = new QSpinBox;
508 telexLayout->addWidget( telexPage );
512 widgetItem->setText( qtr("Teletext") );
514 case ADVANCED_CONTROLLER:
516 AdvControlsWidget *advControls = new AdvControlsWidget( p_intf, this );
517 widget = advControls;
519 widgetItem->setText( qtr("Advanced Buttons") );
521 case PLAYBACK_BUTTONS:
523 widget = new QWidget;
524 DeckButtonsLayout *layout = new DeckButtonsLayout( widget );
525 BrowseButton *prev = new BrowseButton( widget, BrowseButton::Backward );
526 BrowseButton *next = new BrowseButton( widget );
527 RoundButton *play = new RoundButton( widget );
528 layout->setBackwardButton( prev );
529 layout->setForwardButton( next );
530 layout->setRoundButton( play );
532 widgetItem->setText( qtr("Playback Buttons") );
534 case ASPECT_RATIO_COMBOBOX:
535 widget = new AspectRatioComboBox( p_intf );
536 widgetItem->setText( qtr("Aspect ratio selector") );
539 widget = new SpeedLabel( p_intf, this );
540 widgetItem->setText( qtr("Speed selector") );
542 case TIME_LABEL_ELAPSED:
543 widget = new QLabel( "2:42", this );
544 widgetItem->setText( qtr("Elapsed time") );
546 case TIME_LABEL_REMAINING:
547 widget = new QLabel( "-2:42", this );
548 widgetItem->setText( qtr("Total/Remaining time") );
551 msg_Warn( p_intf, "This should not happen %i", i );
555 if( widget == NULL ) continue;
558 widgetItem->setIcon( QIcon( QPixmap::grabWidget( widget ) ) );
559 widgetItem->setToolTip( widgetItem->text() );
561 widgetItem->setData( Qt::UserRole, QVariant( i ) );
563 addItem( widgetItem );
568 void WidgetListing::startDrag( Qt::DropActions /*supportedActions*/ )
570 QListWidgetItem *item = currentItem();
573 QDataStream dataStream( &itemData, QIODevice::WriteOnly );
575 int i_type = item->data( Qt::UserRole ).toInt();
576 int i_option = parent->getOptions();
577 dataStream << i_type << i_option;
579 /* Create a new dragging event */
580 QDrag *drag = new QDrag( this );
582 /* With correct mimedata */
583 QMimeData *mimeData = new QMimeData;
584 mimeData->setData( "vlc/button-bar", itemData );
585 drag->setMimeData( mimeData );
587 /* And correct pixmap */
588 QPixmap aPixmap = item->icon().pixmap( QSize( 22, 22 ) );
589 drag->setPixmap( aPixmap );
590 drag->setHotSpot( QPoint( 20, 20 ) );
592 /* We want to keep a copy */
593 drag->exec( Qt::CopyAction | Qt::MoveAction );
597 * The special controller with drag'n drop abilities.
598 * We don't do this in the main controller, since we don't want the OverHead
599 * to propagate there too
601 DroppingController::DroppingController( intf_thread_t *_p_intf,
604 : AbstractController( _p_intf, _parent )
606 RTL_UNAFFECTED_WIDGET
609 setAcceptDrops( true );
610 controlLayout = new QHBoxLayout( this );
611 controlLayout->setSpacing( 5 );
612 controlLayout->setMargin( 0 );
613 setFrameShape( QFrame::StyledPanel );
614 setFrameShadow( QFrame::Raised );
615 setMinimumHeight( 20 );
617 parseAndCreate( line, controlLayout );
620 void DroppingController::resetLine( const QString& line )
624 while( (child = controlLayout->takeAt( 0 ) ) != 0 )
626 child->widget()->hide();
630 parseAndCreate( line, controlLayout );
634 /* Overloading the AbstractController one, because we don't manage the
635 Spacing items in the same ways */
636 void DroppingController::createAndAddWidget( QBoxLayout *newControlLayout,
641 /* Special case for SPACERS, who aren't QWidgets */
642 if( i_type == WIDGET_SPACER || i_type == WIDGET_SPACER_EXTEND )
644 QLabel *label = new QLabel( this );
645 label->setPixmap( QPixmap( ":/toolbar/space" ) );
646 if( i_type == WIDGET_SPACER_EXTEND )
648 label->setSizePolicy( QSizePolicy::MinimumExpanding,
649 QSizePolicy::Preferred );
651 /* Create a box around it */
652 label->setFrameStyle( QFrame::Panel | QFrame::Sunken );
653 label->setLineWidth ( 1 );
654 label->setAlignment( Qt::AlignCenter );
657 label->setSizePolicy( QSizePolicy::Fixed,
658 QSizePolicy::Preferred );
660 /* Install event Filter for drag'n drop */
661 label->installEventFilter( this );
662 newControlLayout->insertWidget( i_index, label );
668 QWidget *widg = createWidget( i_type, i_option );
671 /* Install the Event Filter in order to catch the drag */
672 widg->setParent( this );
673 widg->installEventFilter( this );
675 /* We are in a complex widget, we need to stop events on children too */
676 if( i_type >= VOLUME && i_type < SPECIAL_MAX )
678 QList<QObject *>children = widg->children();
681 foreach( child, children )
684 if( ( childWidg = qobject_cast<QWidget *>( child ) ) )
686 child->installEventFilter( this );
687 childWidg->setEnabled( true );
691 /* Decorating the frames when possible */
693 if( i_type >= MENU_BUTTONS /* Don't bother to check for volume */
694 && ( frame = qobject_cast<QFrame *>( widg ) ) != NULL )
696 frame->setFrameStyle( QFrame::Panel | QFrame::Raised );
697 frame->setLineWidth ( 1 );
701 /* Some Widgets are deactivated at creation */
702 widg->setEnabled( true );
704 newControlLayout->insertWidget( i_index, widg );
707 /* QList and QBoxLayout don't act the same with insert() */
708 if( i_index < 0 ) i_index = newControlLayout->count() - 1;
710 doubleInt *value = new doubleInt;
711 value->i_type = i_type;
712 value->i_option = i_option;
714 widgetList.insert( i_index, value );
717 DroppingController::~DroppingController()
719 qDeleteAll( widgetList );
723 QString DroppingController::getValue()
727 for( int i = 0; i < controlLayout->count(); i++ )
729 doubleInt *dI = widgetList.at( i );
732 qs.append( QString::number( dI->i_type ) );
733 if( dI->i_option ) qs.append( "-" + QString::number( dI->i_option ) );
739 void DroppingController::dragEnterEvent( QDragEnterEvent * event )
741 if( event->mimeData()->hasFormat( "vlc/button-bar" ) )
747 void DroppingController::dragMoveEvent( QDragMoveEvent *event )
749 QPoint origin = event->pos();
751 int i_pos = getParentPosInLayout( origin );
754 /* Both sides of the frame */
757 if( rubberband ) rubberband->hide();
761 /* Last item is special because of underlying items */
762 if( i_pos >= controlLayout->count() )
768 /* Query the underlying item for size && middles */
769 QLayoutItem *tempItem = controlLayout->itemAt( i_pos ); assert( tempItem );
770 QWidget *temp = tempItem->widget(); assert( temp );
772 /* Position assignment */
774 origin.rx() = temp->x() - 2;
776 if( b_end ) origin.rx() += temp->width();
779 rubberband = new QRubberBand( QRubberBand::Line, this );
780 rubberband->setGeometry( origin.x(), origin.y(), 4, height() );
784 inline int DroppingController::getParentPosInLayout( QPoint point )
786 point.ry() = height() / 2 ;
787 QPoint origin = mapToGlobal ( point );
789 QWidget *tempWidg = QApplication::widgetAt( origin );
790 if( tempWidg == NULL )
793 int i = controlLayout->indexOf( tempWidg );
796 i = controlLayout->indexOf( tempWidg->parentWidget() );
797 tempWidg = tempWidg->parentWidget();
800 /* Return the nearest position */
801 if( ( point.x() - tempWidg->x() > tempWidg->width() / 2 ) && i != -1 )
804 // msg_Dbg( p_intf, "%i", i);
808 void DroppingController::dropEvent( QDropEvent *event )
810 int i = getParentPosInLayout( event->pos() );
812 QByteArray data = event->mimeData()->data( "vlc/button-bar" );
813 QDataStream dataStream(&data, QIODevice::ReadOnly);
815 int i_option = 0, i_type = 0;
816 dataStream >> i_type >> i_option;
818 createAndAddWidget( controlLayout, i, (buttonType_e)i_type, i_option );
820 /* Hide by precaution, you don't exactly know what could have happened in
822 if( rubberband ) rubberband->hide();
825 void DroppingController::dragLeaveEvent ( QDragLeaveEvent * event )
827 if( rubberband ) rubberband->hide();
832 * Overloading doAction to block any action
834 void DroppingController::doAction( int i )
839 bool DroppingController::eventFilter( QObject *obj, QEvent *event )
841 switch( event->type() )
843 case QEvent::MouseButtonPress:
846 case QEvent::MouseButtonRelease:
849 case QEvent::MouseMove:
851 if( !b_draging ) return true;
852 QWidget *widg = static_cast<QWidget*>(obj);
855 QDataStream dataStream( &itemData, QIODevice::WriteOnly );
858 i = controlLayout->indexOf( widg );
861 i = controlLayout->indexOf( widg->parentWidget() );
862 widg = widg->parentWidget();
863 /* NOTE: be extra-careful Now with widg access */
866 if( i == -1 ) return true;
869 doubleInt *dI = widgetList.at( i );
871 int i_type = dI->i_type;
872 int i_option = dI->i_option;
873 dataStream << i_type << i_option;
875 /* With correct mimedata */
876 QMimeData *mimeData = new QMimeData;
877 mimeData->setData( "vlc/button-bar", itemData );
879 QDrag *drag = new QDrag( widg );
880 drag->setMimeData( mimeData );
882 /* Remove before the drag to not mess DropEvent,
883 that will createAndAddWidget */
884 widgetList.removeAt( i );
885 controlLayout->removeWidget( widg );
888 /* Start the effective drag */
889 drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::MoveAction);
894 case QEvent::MouseButtonDblClick:
895 case QEvent::EnabledChange:
897 case QEvent::HideToParent:
899 case QEvent::ZOrderChange: