1 /*****************************************************************************
2 * ToolbarEdit.cpp : ToolbarEdit and About dialogs
3 ****************************************************************************
4 * Copyright (C) 2008 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"
30 #include "util/input_slider.hpp"
31 #include "util/customwidgets.hpp"
32 #include "components/interface_widgets.hpp"
34 #include <QScrollArea>
38 #include <QListWidget>
40 #include <QDragEnterEvent>
41 #include <QDialogButtonBox>
43 ToolbarEditDialog *ToolbarEditDialog::instance = NULL;
45 ToolbarEditDialog::ToolbarEditDialog( intf_thread_t *_p_intf)
46 : QVLCFrame( _p_intf )
48 setWindowTitle( qtr( "Toolbars Editor" ) );
49 QGridLayout *mainLayout = new QGridLayout( this );
50 setMinimumWidth( 600 );
53 QGroupBox *widgetBox = new QGroupBox( "Toolbar Elements", this );
54 widgetBox->setSizePolicy( QSizePolicy::Preferred,
55 QSizePolicy::MinimumExpanding );
56 QGridLayout *boxLayout = new QGridLayout( widgetBox );
58 flatBox = new QCheckBox( qtr( "Flat Button" ) );
59 bigBox = new QCheckBox( qtr( "Big Button" ) );
60 shinyBox = new QCheckBox( qtr( "Native Slider" ) );
61 shinyBox->setChecked( true );
63 boxLayout->addWidget( new WidgetListing( p_intf, this ), 0, 0, 1, -1);
64 boxLayout->addWidget( flatBox, 1, 0 );
65 boxLayout->addWidget( bigBox, 1, 1 );
66 boxLayout->addWidget( shinyBox, 1, 2 );
67 mainLayout->addWidget( widgetBox, 0, 0, 1, -1 );
71 QGroupBox *mainToolbarBox = new QGroupBox( "Main Toolbar", this );
72 QGridLayout *mainTboxLayout = new QGridLayout( mainToolbarBox );
74 QLabel *label = new QLabel( "Toolbar position:" );
75 mainTboxLayout->addWidget(label, 0, 0, 1, 2);
77 QComboBox *positionCombo = new QComboBox;
78 positionCombo->addItems( QStringList() << "Above the Video"
79 << "Under the Video" );
80 mainTboxLayout->addWidget( positionCombo, 0, 2, 1, 1 );
82 QLabel *line1Label = new QLabel( "Line 1:" );
83 QString line1 = getSettings()->value( "MainWindow/Controls1",
84 "64;36;37;38;65").toString();
85 controller1 = new DroppingController( p_intf, line1,
87 mainTboxLayout->addWidget( line1Label, 1, 0, 1, 1 );
88 mainTboxLayout->addWidget( controller1, 1, 1, 1, 2 );
90 QLabel *line2Label = new QLabel( "Line 2:" );
91 QString line2 = getSettings()->value( "MainWindow/Controls2",
92 "0-2;64;3;1;4;64;7;10;9;65;34-4;" ).toString();
93 controller2 = new DroppingController( p_intf, line2,
95 mainTboxLayout->addWidget( line2Label, 2, 0, 1, 1 );
96 mainTboxLayout->addWidget( controller2, 2, 1, 1, 2);
98 /* Advanced ToolBar */
99 QLabel *advLabel = new QLabel( "Advanced Widget toolbar:" );
100 QString lineA = getSettings()->value( "MainWindow/AdvControl",
101 "12;11;13;14").toString();
102 controllerA = new DroppingController( p_intf, lineA,
104 mainTboxLayout->addWidget( advLabel, 3, 0, 1, 2 );
105 mainTboxLayout->addWidget( controllerA, 3, 2, 1, 1 );
107 mainLayout->addWidget( mainToolbarBox, 1, 0, 1, -1 );
110 QGroupBox *timeToolbarBox = new QGroupBox( "Time Toolbar", this );
111 QGridLayout *timeTboxLayout = new QGridLayout( timeToolbarBox );
113 QString line = getSettings()->value( "MainWindow/InputControl",
114 "5-1;33;6-1").toString();
115 controller = new DroppingController( p_intf, line,
117 timeTboxLayout->addWidget( controller, 0, 0, 1, -1 );
119 mainLayout->addWidget( timeToolbarBox, 2, 0, 1, -1 );
122 QGroupBox *FSCToolbarBox = new QGroupBox( "Fullscreen Controller", this );
123 QGridLayout *FSCTboxLayout = new QGridLayout( FSCToolbarBox );
125 QString lineFSC = getSettings()->value( "MainWindow/FSCline",
126 "0-2;64;3;1;4;64;36;64;37;64;8;65;35-4;34" ).toString();
127 controllerFSC = new DroppingController( p_intf,
129 FSCTboxLayout->addWidget( controllerFSC, 0, 0, 1, -1 );
131 mainLayout->addWidget( FSCToolbarBox, 3, 0, 1, -1 );
134 QDialogButtonBox *okCancel = new QDialogButtonBox;
135 QPushButton *okButton = new QPushButton( qtr( "Cl&ose" ), this );
136 QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ), this );
137 okCancel->addButton( okButton, QDialogButtonBox::AcceptRole );
138 okCancel->addButton( cancelButton, QDialogButtonBox::RejectRole );
140 BUTTONACT( okButton, close() );
141 BUTTONACT( cancelButton, cancel() );
142 mainLayout->addWidget( okCancel, 4, 2 );
146 ToolbarEditDialog::~ToolbarEditDialog()
150 void ToolbarEditDialog::close()
152 msg_Dbg( p_intf, "Close and save" );
154 getSettings()->setValue( "MainWindow/Controls1", controller1->getValue() );
155 getSettings()->setValue( "MainWindow/Controls2", controller2->getValue() );
156 getSettings()->setValue( "MainWindow/AdcControl", controllerA->getValue() );
157 getSettings()->setValue( "MainWindow/InputControl", controller->getValue() );
158 getSettings()->setValue( "MainWindow/FSCline", controllerFSC->getValue() );
161 void ToolbarEditDialog::cancel()
166 WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent )
167 : QListWidget( _parent )
169 /* We need the parent to know the options checked */
170 parent = qobject_cast<ToolbarEditDialog *>(_parent);
174 setViewMode( QListView::IconMode );
176 setDragEnabled( true );
177 setMinimumHeight( 250 );
179 /* All the buttons do not need a special rendering */
180 for( int i = 0; i < BUTTON_MAX; i++ )
182 QListWidgetItem *widgetItem = new QListWidgetItem( this );
183 widgetItem->setText( nameL[i] );
184 widgetItem->setIcon( QIcon( iconL[i] ) );
185 widgetItem->setData( Qt::UserRole, QVariant( i ) );
186 addItem( widgetItem );
189 /* Spacers are yet again a different thing */
190 QListWidgetItem *widgetItem = new QListWidgetItem( QIcon( ":/space" ),
191 qtr( "Spacer" ), this );
192 widgetItem->setData( Qt::UserRole, WIDGET_SPACER );
193 addItem( widgetItem );
195 widgetItem = new QListWidgetItem( QIcon( ":/space" ),
196 qtr( "Expanding Spacer" ), this );
197 widgetItem->setData( Qt::UserRole, WIDGET_SPACER_EXTEND );
198 addItem( widgetItem );
201 * For all other widgets, we create then, do a pseudo rendering in
202 * a pixmaps for the view, and delete the object
204 * A lot of code is retaken from the Abstract, but not exactly...
206 * They are better ways to deal with this, but I doubt that this is
207 * necessary. If you feel like you have the time, be my guest.
211 for( int i = SPLITTER; i < SPECIAL_MAX; i++ )
213 QWidget *widget = NULL;
214 QListWidgetItem *widgetItem = new QListWidgetItem( this );
219 QFrame *line = new QFrame( this );
220 line->setFrameShape( QFrame::VLine );
221 line->setFrameShadow( QFrame::Raised );
222 line->setLineWidth( 0 ); line->setMidLineWidth( 1 );
225 widgetItem->setText( qtr("Splitter") );
229 InputSlider *slider = new InputSlider( Qt::Horizontal, this );
232 widgetItem->setText( qtr("Time Slider") );
236 SoundWidget *snd = new SoundWidget( this, p_intf,
237 parent->getOptions() & WIDGET_SHINY );
240 widgetItem->setText( qtr("Volume") );
244 QLabel *timeLabel = new QLabel( "12:42/2:12:42", this );
247 widgetItem->setText( qtr("Time") );
251 QWidget *discFrame = new QWidget( this );
252 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
253 discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
255 QToolButton *prevSectionButton = new QToolButton( discFrame );
256 prevSectionButton->setIcon( QIcon( ":/dvd_prev" ) );
257 discLayout->addWidget( prevSectionButton );
259 QToolButton *menuButton = new QToolButton( discFrame );
260 menuButton->setIcon( QIcon( ":/dvd_menu" ) );
261 discLayout->addWidget( menuButton );
263 QToolButton *nextButton = new QToolButton( discFrame );
264 nextButton->setIcon( QIcon( ":/dvd_next" ) );
265 discLayout->addWidget( nextButton );
269 widgetItem->setText( qtr("DVD menus") );
271 case TELETEXT_BUTTONS:
273 QWidget *telexFrame = new QWidget( this );
274 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
275 telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
277 QToolButton *telexOn = new QToolButton( telexFrame );
278 telexOn->setIcon( QIcon( ":/tv" ) );
279 telexLayout->addWidget( telexOn );
281 QToolButton *telexTransparent = new QToolButton;
282 telexOn->setIcon( QIcon( ":/tvtelx-trans" ) );
283 telexLayout->addWidget( telexTransparent );
285 QSpinBox *telexPage = new QSpinBox;
286 telexLayout->addWidget( telexPage );
290 widgetItem->setText( qtr("Teletext") );
292 case ADVANCED_CONTROLLER:
294 AdvControlsWidget *advControls = new AdvControlsWidget( p_intf, this );
295 widget = advControls;
297 widgetItem->setText( qtr("Advanced Buttons") );
300 msg_Warn( p_intf, "This should not happen %i", i );
304 if( widget == NULL ) continue;
307 widgetItem->setIcon( QIcon( QPixmap::grabWidget( widget ) ) );
309 widgetItem->setData( Qt::UserRole, QVariant( i ) );
311 addItem( widgetItem );
316 void WidgetListing::startDrag( Qt::DropActions /*supportedActions*/ )
318 QListWidgetItem *item =currentItem();
321 QDataStream dataStream( &itemData, QIODevice::WriteOnly );
323 int i_type = item->data( Qt::UserRole ).toInt();
324 int i_option = parent->getOptions();
325 dataStream << i_type << i_option;
327 QMimeData *mimeData = new QMimeData;
328 mimeData->setData( "vlc/button-bar", itemData );
330 QDrag *drag = new QDrag( this );
331 drag->setMimeData( mimeData );
332 QPixmap aPixmap = item->icon().pixmap( QSize( 22, 22 ) );
333 drag->setPixmap( aPixmap );
334 drag->setHotSpot( QPoint( 20, 20 ) );
335 drag->exec(Qt::CopyAction | Qt::MoveAction );
339 DroppingController::DroppingController( intf_thread_t *_p_intf, QString line, QWidget *_parent )
340 : AbstractController( _p_intf, _parent )
343 setAcceptDrops( true );
344 controlLayout = new QHBoxLayout( this );
345 controlLayout->setSpacing( 0 );
346 controlLayout->setMargin( 0 );
347 setFrameShape( QFrame::StyledPanel );
348 setFrameShadow( QFrame::Raised );
351 parseAndCreate( line, controlLayout );
355 /* Overloading the AbstractController one, because we don't manage the
356 Spacing in the same ways */
357 void DroppingController::createAndAddWidget( QBoxLayout *controlLayout,
362 doubleInt *value = new doubleInt;
363 value->i_type = i_type;
364 value->i_option = i_option;
366 /* Special case for SPACERS, who aren't QWidgets */
367 if( i_type == WIDGET_SPACER || i_type == WIDGET_SPACER_EXTEND )
369 QLabel *label = new QLabel;
370 label->setPixmap( QPixmap( ":/space" ) );
371 if( i_type == WIDGET_SPACER_EXTEND )
373 label->setScaledContents( true );
374 label->setSizePolicy( QSizePolicy::MinimumExpanding,
375 QSizePolicy::Preferred );
378 label->setSizePolicy( QSizePolicy::Fixed,
379 QSizePolicy::Preferred );
381 controlLayout->insertWidget( i_index, label );
385 QWidget *widg = createWidget( i_type, i_option );
388 /* Some Widgets are deactivated at creation */
389 widg->setEnabled( true );
391 controlLayout->insertWidget( i_index, widg );
393 /* QList and QBoxLayout don't act the same with insert() */
394 if( i_index < 0 ) i_index = controlLayout->count() -1 ;
396 widgetList.insert( i_index, value );
399 QString DroppingController::getValue()
403 for( int i = 0; i < controlLayout->count(); i++ )
405 doubleInt *dI = widgetList.at( i );
408 qs.append( QString::number( dI->i_type ) );
409 if( dI->i_option ) qs.append( "-" + QString::number( dI->i_option ) );
415 void DroppingController::dragEnterEvent( QDragEnterEvent * event )
417 if( event->mimeData()->hasFormat( "vlc/button-bar" ) )
423 void DroppingController::dragMoveEvent( QDragMoveEvent *event )
425 QPoint origin = event->pos();
427 int i_pos = getParentPosInLayout( origin );
430 /* Both sides of the frame */
433 if( rubberband ) rubberband->hide();
437 /* Last item is special because of underlying items */
438 if( i_pos >= controlLayout->count() )
444 /* Query the underlying item for size && middles */
445 QLayoutItem *tempItem = controlLayout->itemAt( i_pos ); assert( tempItem );
446 QWidget *temp = tempItem->widget(); assert( temp );
448 /* Position assignment */
450 origin.rx() = temp->x() - 2;
452 if( b_end ) origin.rx() += temp->width();
455 rubberband = new QRubberBand( QRubberBand::Line, this );
456 rubberband->setGeometry( origin.x(), origin.y(), 4, height() );
460 inline int DroppingController::getParentPosInLayout( QPoint point)
462 point.ry() = height() / 2 ;
463 QPoint origin = mapToGlobal ( point );
465 QWidget *tempWidg = QApplication::widgetAt( origin );
468 if( tempWidg != NULL)
470 i = controlLayout->indexOf( tempWidg );
473 i = controlLayout->indexOf( tempWidg->parentWidget() );
474 tempWidg = tempWidg->parentWidget();
478 /* Return the nearest position */
479 if( ( point.x() - tempWidg->x() > tempWidg->width() / 2 ) && i != -1 )
482 // msg_Dbg( p_intf, "%i", i);
486 void DroppingController::dropEvent( QDropEvent *event )
488 int i = getParentPosInLayout( event->pos() );
490 QByteArray data = event->mimeData()->data( "vlc/button-bar" );
491 QDataStream dataStream(&data, QIODevice::ReadOnly);
493 int i_option = 0, i_type = 0;
494 dataStream >> i_type >> i_option;
496 createAndAddWidget( controlLayout, i, (buttonType_e)i_type, i_option );
498 /* Hide by precaution, you don't exactly know what could have happened in
500 if( rubberband ) rubberband->hide();
503 void DroppingController::dragLeaveEvent ( QDragLeaveEvent * event )
505 if( rubberband ) rubberband->hide();
509 * Overloading doAction to block any action
511 void DroppingController::doAction( int i ){}