toolbar.cpp 21.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
/*****************************************************************************
 * ToolbarEdit.cpp : ToolbarEdit and About dialogs
 ****************************************************************************
 * Copyright (C) 2008 the VideoLAN team
 * $Id$
 *
 * Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include "dialogs/toolbar.hpp"

#include "util/input_slider.hpp"
#include "util/customwidgets.hpp"
#include "components/interface_widgets.hpp"

#include <QScrollArea>
#include <QGroupBox>
#include <QLabel>
#include <QComboBox>
#include <QListWidget>

#include <QDragEnterEvent>
41
#include <QDialogButtonBox>
42 43 44 45 46 47

ToolbarEditDialog *ToolbarEditDialog::instance = NULL;

ToolbarEditDialog::ToolbarEditDialog( intf_thread_t *_p_intf)
                  : QVLCFrame(  _p_intf )
{
48
    setWindowTitle( qtr( "Toolbars Editor" ) );
49 50 51 52
    QGridLayout *mainLayout = new QGridLayout( this );
    setMinimumWidth( 600 );

    /* main GroupBox */
Christophe Mutricy's avatar
i18n  
Christophe Mutricy committed
53
    QGroupBox *widgetBox = new QGroupBox( qtr( "Toolbar Elements") , this );
54 55 56 57
    widgetBox->setSizePolicy( QSizePolicy::Preferred,
                              QSizePolicy::MinimumExpanding );
    QGridLayout *boxLayout = new QGridLayout( widgetBox );

58
    QLabel *styleLabel = new QLabel( qtr( "Next widget style:" ) );
59 60 61
    flatBox = new QCheckBox( qtr( "Flat Button" ) );
    bigBox = new QCheckBox( qtr( "Big Button" ) );
    shinyBox = new QCheckBox( qtr( "Native Slider" ) );
62 63

    boxLayout->addWidget( new WidgetListing( p_intf, this ), 0, 0, 1, -1);
64 65 66 67
    boxLayout->addWidget( styleLabel, 1, 0 );
    boxLayout->addWidget( flatBox, 1, 1 );
    boxLayout->addWidget( bigBox, 1, 2 );
    boxLayout->addWidget( shinyBox, 1, 3 );
68 69 70 71
    mainLayout->addWidget( widgetBox, 0, 0, 1, -1 );


    /* Main ToolBar */
Christophe Mutricy's avatar
i18n  
Christophe Mutricy committed
72
    QGroupBox *mainToolbarBox = new QGroupBox( qtr( "Main Toolbar" ), this );
73 74
    QGridLayout *mainTboxLayout = new QGridLayout( mainToolbarBox );

Christophe Mutricy's avatar
i18n  
Christophe Mutricy committed
75
    QLabel *label = new QLabel( qtr( "Toolbar position:" ) );
76
    mainTboxLayout->addWidget(label, 0, 0, 1, 2);
77

78 79 80
    positionCombo = new QComboBox;
    positionCombo->addItem( qtr( "Under the Video" ), QVariant( 0 ) );
    positionCombo->addItem( qtr( "Above the Video" ), QVariant( 1 ) );
81 82
    positionCombo->setCurrentIndex( positionCombo->findData(
                getSettings()->value( "MainWindow/ToolbarPos", 0 ).toInt() ) );
83
    mainTboxLayout->addWidget( positionCombo, 0, 2, 1, 1 );
84

85
    QLabel *line1Label = new QLabel( "Line 1:" );
86 87
    QString line1 = getSettings()->value( "MainWindow/MainToolbar1",
                                          MAIN_TB1_DEFAULT ).toString();
88
    controller1 = new DroppingController( p_intf, line1,
89
            this );
90 91
    mainTboxLayout->addWidget( line1Label, 1, 0, 1, 1 );
    mainTboxLayout->addWidget( controller1, 1, 1, 1, 2 );
92

93
    QLabel *line2Label = new QLabel( "Line 2:" );
94 95
    QString line2 = getSettings()->value( "MainWindow/MainToolbar2",
                                          MAIN_TB2_DEFAULT ).toString();
96
    controller2 = new DroppingController( p_intf, line2,
97
            this );
98 99 100 101
    mainTboxLayout->addWidget( line2Label, 2, 0, 1, 1 );
    mainTboxLayout->addWidget( controller2, 2, 1, 1, 2);

    /* Advanced ToolBar */
Christophe Mutricy's avatar
i18n  
Christophe Mutricy committed
102
    QLabel *advLabel = new QLabel( qtr( "Advanced Widget toolbar:" ) );
103 104
    QString lineA = getSettings()->value( "MainWindow/AdvToolbar",
                                          ADV_TB_DEFAULT ).toString();
105
    controllerA = new DroppingController( p_intf, lineA,
106 107 108
            this );
    mainTboxLayout->addWidget( advLabel, 3, 0, 1, 2 );
    mainTboxLayout->addWidget( controllerA, 3, 2, 1, 1 );
109 110

    mainLayout->addWidget( mainToolbarBox, 1, 0, 1, -1 );
111 112

    /* TimeToolBar */
Christophe Mutricy's avatar
i18n  
Christophe Mutricy committed
113
    QGroupBox *timeToolbarBox = new QGroupBox( qtr( "Time Toolbar" ) , this );
114 115
    QGridLayout *timeTboxLayout = new QGridLayout( timeToolbarBox );

116 117
    QString line = getSettings()->value( "MainWindow/InputToolbar",
                                         INPT_TB_DEFAULT ).toString();
118
    controller = new DroppingController( p_intf, line,
119 120 121 122 123 124
            this );
    timeTboxLayout->addWidget( controller, 0, 0, 1, -1 );

    mainLayout->addWidget( timeToolbarBox, 2, 0, 1, -1 );

    /* FSCToolBar */
Christophe Mutricy's avatar
i18n  
Christophe Mutricy committed
125 126
    QGroupBox *FSCToolbarBox = new QGroupBox( qtr( "Fullscreen Controller" ),
                                              this );
127 128
    QGridLayout *FSCTboxLayout = new QGridLayout( FSCToolbarBox );

129 130
    QString lineFSC = getSettings()->value( "MainWindow/FSCtoolbar",
                                            FSC_TB_DEFAULT ).toString();
131
    controllerFSC = new DroppingController( p_intf,
132 133 134 135 136
            lineFSC, this );
    FSCTboxLayout->addWidget( controllerFSC, 0, 0, 1, -1 );

    mainLayout->addWidget( FSCToolbarBox, 3, 0, 1, -1 );

137 138 139
    /* Buttons */
    QDialogButtonBox *okCancel = new QDialogButtonBox;
    QPushButton *okButton = new QPushButton( qtr( "Cl&ose" ), this );
140
    okButton->setDefault( true );
141 142 143
    QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ), this );
    okCancel->addButton( okButton, QDialogButtonBox::AcceptRole );
    okCancel->addButton( cancelButton, QDialogButtonBox::RejectRole );
144

145 146 147
    BUTTONACT( okButton, close() );
    BUTTONACT( cancelButton, cancel() );
    mainLayout->addWidget( okCancel, 4, 2 );
148 149 150 151 152 153 154
}


ToolbarEditDialog::~ToolbarEditDialog()
{
}

155 156 157 158
void ToolbarEditDialog::close()
{
    msg_Dbg( p_intf, "Close and save" );
    hide();
159 160
    getSettings()->setValue( "MainWindow/ToolbarPos",
            positionCombo->itemData( positionCombo->currentIndex() ).toInt() );
161 162 163 164 165
    getSettings()->setValue( "MainWindow/MainToolbar1", controller1->getValue() );
    getSettings()->setValue( "MainWindow/MainToolbar2", controller2->getValue() );
    getSettings()->setValue( "MainWindow/AdvToolbar", controllerA->getValue() );
    getSettings()->setValue( "MainWindow/InputToolbar", controller->getValue() );
    getSettings()->setValue( "MainWindow/FSCtoolbar", controllerFSC->getValue() );
166 167 168 169 170 171 172
}

void ToolbarEditDialog::cancel()
{
    hide();
}

173 174 175 176
/************************************************
 *  Widget Listing:
 * Creation of the list of drawed lovely buttons
 ************************************************/
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent )
              : QListWidget( _parent )
{
    /* We need the parent to know the options checked */
    parent = qobject_cast<ToolbarEditDialog *>(_parent);
    assert( parent );

    /* Normal options */
    setViewMode( QListView::IconMode );
    setSpacing( 20 );
    setDragEnabled( true );
    setMinimumHeight( 250 );

    /* All the buttons do not need a special rendering */
    for( int i = 0; i < BUTTON_MAX; i++ )
    {
        QListWidgetItem *widgetItem = new QListWidgetItem( this );
        widgetItem->setText( nameL[i] );
        widgetItem->setIcon( QIcon( iconL[i] ) );
        widgetItem->setData( Qt::UserRole, QVariant( i ) );
        addItem( widgetItem );
    }

    /* Spacers are yet again a different thing */
    QListWidgetItem *widgetItem = new QListWidgetItem( QIcon( ":/space" ),
            qtr( "Spacer" ), this );
    widgetItem->setData( Qt::UserRole, WIDGET_SPACER );
    addItem( widgetItem );

    widgetItem = new QListWidgetItem( QIcon( ":/space" ),
            qtr( "Expanding Spacer" ), this );
    widgetItem->setData( Qt::UserRole, WIDGET_SPACER_EXTEND );
    addItem( widgetItem );

    /**
     * For all other widgets, we create then, do a pseudo rendering in
     * a pixmaps for the view, and delete the object
     *
     * A lot of code is retaken from the Abstract, but not exactly...
     * So, rewrite.
     * They are better ways to deal with this, but I doubt that this is
     * necessary. If you feel like you have the time, be my guest.
     * --
     * jb
     **/
    for( int i = SPLITTER; i < SPECIAL_MAX; i++ )
    {
        QWidget *widget = NULL;
        QListWidgetItem *widgetItem = new QListWidgetItem( this );
        switch( i )
        {
        case SPLITTER:
            {
                QFrame *line = new QFrame( this );
                line->setFrameShape( QFrame::VLine );
                line->setFrameShadow( QFrame::Raised );
                line->setLineWidth( 0 ); line->setMidLineWidth( 1 );
                widget = line;
            }
            widgetItem->setText( qtr("Splitter") );
            break;
        case INPUT_SLIDER:
            {
                InputSlider *slider = new InputSlider( Qt::Horizontal, this );
                widget = slider;
            }
            widgetItem->setText( qtr("Time Slider") );
            break;
        case VOLUME:
            {
247 248
                SoundWidget *snd = new SoundWidget( this, p_intf,
                        parent->getOptions() & WIDGET_SHINY );
249 250 251 252
                widget = snd;
            }
            widgetItem->setText( qtr("Volume") );
            break;
253 254 255 256 257 258 259 260 261
        case VOLUME_SPECIAL:
            {
                QListWidgetItem *widgetItem = new QListWidgetItem( this );
                widgetItem->setText( "Small Volume" );
                widgetItem->setIcon( QIcon( ":/volume-medium" ) );
                widgetItem->setData( Qt::UserRole, QVariant( i ) );
                addItem( widgetItem );
            }
            continue;
262 263 264 265 266 267 268 269 270 271
        case TIME_LABEL:
            {
                QLabel *timeLabel = new QLabel( "12:42/2:12:42", this );
                widget = timeLabel;
            }
            widgetItem->setText( qtr("Time") );
            break;
        case MENU_BUTTONS:
            {
                QWidget *discFrame = new QWidget( this );
272
                //discFrame->setLineWidth( 1 );
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
                QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
                discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );

                QToolButton *prevSectionButton = new QToolButton( discFrame );
                prevSectionButton->setIcon( QIcon( ":/dvd_prev" ) );
                discLayout->addWidget( prevSectionButton );

                QToolButton *menuButton = new QToolButton( discFrame );
                menuButton->setIcon( QIcon( ":/dvd_menu" ) );
                discLayout->addWidget( menuButton );

                QToolButton *nextButton = new QToolButton( discFrame );
                nextButton->setIcon( QIcon( ":/dvd_next" ) );
                discLayout->addWidget( nextButton );

                widget = discFrame;
            }
            widgetItem->setText( qtr("DVD menus") );
            break;
        case TELETEXT_BUTTONS:
            {
                QWidget *telexFrame = new QWidget( this );
                QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
                telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );

                QToolButton *telexOn = new QToolButton( telexFrame );
                telexOn->setIcon( QIcon( ":/tv" ) );
                telexLayout->addWidget( telexOn );

                QToolButton *telexTransparent = new QToolButton;
303
                telexOn->setIcon( QIcon( ":/tvtelx" ) );
304 305 306 307 308 309 310 311 312 313 314
                telexLayout->addWidget( telexTransparent );

                QSpinBox *telexPage = new QSpinBox;
                telexLayout->addWidget( telexPage );

                widget = telexFrame;
            }
            widgetItem->setText( qtr("Teletext") );
            break;
        case ADVANCED_CONTROLLER:
            {
315
                AdvControlsWidget *advControls = new AdvControlsWidget( p_intf, this );
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
                widget = advControls;
            }
            widgetItem->setText( qtr("Advanced Buttons") );
            break;
        default:
            msg_Warn( p_intf, "This should not happen %i", i );
            break;
        }

        if( widget == NULL ) continue;


        widgetItem->setIcon( QIcon( QPixmap::grabWidget( widget ) ) );
        widget->hide();
        widgetItem->setData( Qt::UserRole, QVariant( i ) );

        addItem( widgetItem );
        delete widget;
    }
}

void WidgetListing::startDrag( Qt::DropActions /*supportedActions*/ )
{
339
    QListWidgetItem *item = currentItem();
340 341 342 343 344 345 346 347

    QByteArray itemData;
    QDataStream dataStream( &itemData, QIODevice::WriteOnly );

    int i_type = item->data( Qt::UserRole ).toInt();
    int i_option = parent->getOptions();
    dataStream << i_type << i_option;

348 349 350 351
    /* Create a new dragging event */
    QDrag *drag = new QDrag( this );

    /* With correct mimedata */
352 353 354
    QMimeData *mimeData = new QMimeData;
    mimeData->setData( "vlc/button-bar", itemData );
    drag->setMimeData( mimeData );
355 356

    /* And correct pixmap */
357 358 359
    QPixmap aPixmap = item->icon().pixmap( QSize( 22, 22 ) );
    drag->setPixmap( aPixmap );
    drag->setHotSpot( QPoint( 20, 20 ) );
360

361 362 363
    /* We want to keep a copy */
    drag->exec( Qt::CopyAction | Qt::MoveAction );
}
364

365 366 367 368 369 370 371 372
/*
 * The special controller with drag'n drop abilities.
 * We don't do this in the main controller, since we don't want the OverHead
 * to propagate there too
 */
DroppingController::DroppingController( intf_thread_t *_p_intf,
                                        QString line,
                                        QWidget *_parent )
373
                   : AbstractController( _p_intf, _parent )
374 375
{
    rubberband = NULL;
376
    b_draging = false;
377 378
    setAcceptDrops( true );
    controlLayout = new QHBoxLayout( this );
379
    controlLayout->setSpacing( 5 );
380 381 382 383
    controlLayout->setMargin( 0 );
    setFrameShape( QFrame::StyledPanel );
    setFrameShadow( QFrame::Raised );

384
    parseAndCreate( line, controlLayout );
385 386 387
}

/* Overloading the AbstractController one, because we don't manage the
388
   Spacing items in the same ways */
389 390 391 392 393 394 395 396 397 398 399 400 401 402
void DroppingController::createAndAddWidget( QBoxLayout *controlLayout,
                                             int i_index,
                                             buttonType_e i_type,
                                             int i_option )
{
    /* Special case for SPACERS, who aren't QWidgets */
    if( i_type == WIDGET_SPACER || i_type == WIDGET_SPACER_EXTEND )
    {
        QLabel *label = new QLabel;
        label->setPixmap( QPixmap( ":/space" ) );
        if( i_type == WIDGET_SPACER_EXTEND )
        {
            label->setSizePolicy( QSizePolicy::MinimumExpanding,
                    QSizePolicy::Preferred );
403 404 405 406 407

            /* Create a box around it */
            label->setFrameStyle( QFrame::Panel | QFrame::Sunken );
            label->setLineWidth ( 1 );
            label->setAlignment( Qt::AlignCenter );
408 409 410 411 412
        }
        else
            label->setSizePolicy( QSizePolicy::Fixed,
                    QSizePolicy::Preferred );

413 414
        /* Install event Filter for drag'n drop */
        label->installEventFilter( this );
415 416
        controlLayout->insertWidget( i_index, label );
    }
417 418

    /* Normal Widgets */
419 420 421 422 423
    else
    {
        QWidget *widg = createWidget( i_type, i_option );
        if( !widg ) return;

424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
        /* Install the Event Filter in order to catch the drag */
        widg->installEventFilter( this );

        /* We are in a complex widget, we need to stop events on children too */
        if( i_type >= VOLUME && i_type < SPECIAL_MAX )
        {
            QList<QObject *>children = widg->children();

            QObject *child;
            foreach( child, children )
            {
                QWidget *childWidg;
                if( childWidg = qobject_cast<QWidget *>( child ) )
                {
                    child->installEventFilter( this );
                    childWidg->setEnabled( true );
                }
            }

            /* Decorating the frames when possible */
            QFrame *frame;
            if( i_type >= MENU_BUTTONS  /* Don't bother to check for volume */
                && ( frame = qobject_cast<QFrame *>( widg ) ) != NULL )
            {
                frame->setFrameStyle( QFrame::Panel | QFrame::Raised );
                frame->setLineWidth ( 1 );
            }
        }

453 454
        /* Some Widgets are deactivated at creation */
        widg->setEnabled( true );
455
        widg->show();
456 457
        controlLayout->insertWidget( i_index, widg );
    }
458

459
    /* QList and QBoxLayout don't act the same with insert() */
460
    if( i_index < 0 ) i_index = controlLayout->count() - 1;
461

462 463 464 465
    /* Insert in the value listing */
    doubleInt *value = new doubleInt;
    value->i_type = i_type;
    value->i_option = i_option;
466 467 468
    widgetList.insert( i_index, value );
}

469 470 471 472 473 474
DroppingController::~DroppingController()
{
    qDeleteAll( widgetList );
    widgetList.clear();
}

475 476 477 478 479 480 481 482 483 484 485 486 487 488
QString DroppingController::getValue()
{
    QString qs = "";

    for( int i = 0; i < controlLayout->count(); i++ )
    {
        doubleInt *dI = widgetList.at( i );
        assert( dI );

        qs.append( QString::number( dI->i_type ) );
        if( dI->i_option ) qs.append( "-" + QString::number( dI->i_option ) );
        qs.append( ';' );
    }
    return qs;
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
}

void DroppingController::dragEnterEvent( QDragEnterEvent * event )
{
    if( event->mimeData()->hasFormat( "vlc/button-bar" ) )
        event->accept();
    else
        event->ignore();
}

void DroppingController::dragMoveEvent( QDragMoveEvent *event )
{
    QPoint origin = event->pos();

    int i_pos = getParentPosInLayout( origin );
    bool b_end = false;

    /* Both sides of the frame */
    if( i_pos == -1 )
    {
        if( rubberband ) rubberband->hide();
        return;
    }

    /* Last item is special because of underlying items */
    if( i_pos >= controlLayout->count() )
    {
        i_pos--;
        b_end = true;
    }

    /* Query the underlying item for size && middles */
    QLayoutItem *tempItem = controlLayout->itemAt( i_pos ); assert( tempItem );
    QWidget *temp = tempItem->widget(); assert( temp );

    /* Position assignment */
    origin.ry() = 0;
    origin.rx() = temp->x() - 2;

    if( b_end ) origin.rx() += temp->width();

    if( !rubberband )
        rubberband = new QRubberBand( QRubberBand::Line, this );
    rubberband->setGeometry( origin.x(), origin.y(), 4, height() );
    rubberband->show();
}

536
inline int DroppingController::getParentPosInLayout( QPoint point )
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
{
    point.ry() = height() / 2 ;
    QPoint origin = mapToGlobal ( point );

    QWidget *tempWidg = QApplication::widgetAt( origin );

    int i = -1;
    if( tempWidg != NULL)
    {
        i = controlLayout->indexOf( tempWidg );
        if( i == -1 )
        {
            i = controlLayout->indexOf( tempWidg->parentWidget() );
            tempWidg = tempWidg->parentWidget();
        }
    }

    /* Return the nearest position */
    if( ( point.x() - tempWidg->x()  > tempWidg->width() / 2 ) && i != -1 )
        i++;

    //    msg_Dbg( p_intf, "%i", i);
    return i;
}

void DroppingController::dropEvent( QDropEvent *event )
{
    int i = getParentPosInLayout( event->pos() );

    QByteArray data = event->mimeData()->data( "vlc/button-bar" );
    QDataStream dataStream(&data, QIODevice::ReadOnly);

    int i_option = 0, i_type = 0;
    dataStream >> i_type >> i_option;

    createAndAddWidget( controlLayout, i, (buttonType_e)i_type, i_option );

    /* Hide by precaution, you don't exactly know what could have happened in
       between */
    if( rubberband ) rubberband->hide();
}

void DroppingController::dragLeaveEvent ( QDragLeaveEvent * event )
{
    if( rubberband ) rubberband->hide();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
582
    event->accept();
583 584 585 586 587
}

/**
 * Overloading doAction to block any action
 **/
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
588 589 590 591
void DroppingController::doAction( int i )
{
    VLC_UNUSED( i );
}
592

593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
bool DroppingController::eventFilter( QObject *obj, QEvent *event )
{
    switch( event->type() )
    {
        case QEvent::MouseButtonPress:
            b_draging = true;
            return true;
        case QEvent::MouseButtonRelease:
            b_draging = false;
            return true;
        case QEvent::MouseMove:
            {
            if( !b_draging ) return true;
            QWidget *widg = static_cast<QWidget*>(obj);

            QByteArray itemData;
            QDataStream dataStream( &itemData, QIODevice::WriteOnly );

            int i = -1;
            i = controlLayout->indexOf( widg );
            if( i == -1 )
            {
                i = controlLayout->indexOf( widg->parentWidget() );
                widg = widg->parentWidget();
                /* NOTE: be extra-careful Now with widg access */
            }

            if( i == -1 ) return true;
            doubleInt *dI = widgetList.at( i );

            int i_type = dI->i_type;
            int i_option = dI->i_option;
            dataStream << i_type << i_option;

            /* With correct mimedata */
            QMimeData *mimeData = new QMimeData;
            mimeData->setData( "vlc/button-bar", itemData );

            QDrag *drag = new QDrag( widg );
            drag->setMimeData( mimeData );

            /* Start the effective drag */
            drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::MoveAction);

            widgetList.removeAt( i );
            controlLayout->removeWidget( widg );
            widg->hide();
            b_draging = false;
            }
            return true;

644
        case QEvent::MouseButtonDblClick:
645 646 647 648 649 650 651 652 653 654 655
        case QEvent::EnabledChange:
        case QEvent::Hide:
        case QEvent::HideToParent:
        case QEvent::Move:
        case QEvent::ZOrderChange:
            return true;
        default:
            return false;
    }
}