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>
42 ToolbarEditDialog *ToolbarEditDialog::instance = NULL;
44 ToolbarEditDialog::ToolbarEditDialog( intf_thread_t *_p_intf)
45 : QVLCFrame( _p_intf )
47 setWindowTitle( qtr( "Toolbars Edition" ) );
48 QGridLayout *mainLayout = new QGridLayout( this );
49 setMinimumWidth( 600 );
52 QGroupBox *widgetBox = new QGroupBox( "Toolbar Elements", this );
53 widgetBox->setSizePolicy( QSizePolicy::Preferred,
54 QSizePolicy::MinimumExpanding );
55 QGridLayout *boxLayout = new QGridLayout( widgetBox );
57 boxLayout->addWidget( new WidgetListing( p_intf, this ), 0, 0, 1, -1);
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 );
62 boxLayout->addWidget( flatBox, 1, 0 );
63 boxLayout->addWidget( bigBox, 1, 1 );
64 boxLayout->addWidget( bigBox, 1, 2 );
65 mainLayout->addWidget( widgetBox, 0, 0, 1, -1 );
69 QGroupBox *mainToolbarBox = new QGroupBox( "Main Toolbar", this );
70 QGridLayout *mainTboxLayout = new QGridLayout( mainToolbarBox );
72 QLabel *label = new QLabel( "Toolbar position:" );
73 mainTboxLayout->addWidget(label, 0, 0, 1, 1);
75 QComboBox *positionCombo = new QComboBox;
76 positionCombo->addItems( QStringList() << "Over the Video"
77 << "Under the Video" );
78 mainTboxLayout->addWidget( positionCombo, 0, 1, 1, 1 );
80 QFrame *mainToolFrame = new QFrame;
81 mainToolFrame->setMinimumSize( QSize( 0, 25 ) );
82 mainToolFrame->setFrameShape( QFrame::StyledPanel );
83 mainToolFrame->setFrameShadow( QFrame::Raised );
84 mainTboxLayout->addWidget( mainToolFrame, 1, 0, 1, 2 );
85 mainToolFrame->setAcceptDrops( true );
86 QHBoxLayout *mtlayout = new QHBoxLayout( mainToolFrame );
88 DroppingController *controller = new DroppingController( p_intf );
89 mtlayout->addWidget( controller );
92 QFrame *mainTool2Frame = new QFrame;
93 mainTool2Frame->setMinimumSize( QSize( 0, 25 ) );
94 mainTool2Frame->setFrameShape( QFrame::StyledPanel );
95 mainTool2Frame->setFrameShadow( QFrame::Raised );
96 mainTboxLayout->addWidget( mainTool2Frame, 2, 0, 1, 2 );
97 mainTool2Frame->setAcceptDrops( true );
99 mainLayout->addWidget( mainToolbarBox, 1, 0, 1, -1 );
103 ToolbarEditDialog::~ToolbarEditDialog()
107 WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent )
108 : QListWidget( _parent )
110 /* We need the parent to know the options checked */
111 parent = qobject_cast<ToolbarEditDialog *>(_parent);
115 setViewMode( QListView::IconMode );
117 setDragEnabled( true );
118 setMinimumHeight( 250 );
120 /* All the buttons do not need a special rendering */
121 for( int i = 0; i < BUTTON_MAX; i++ )
123 QListWidgetItem *widgetItem = new QListWidgetItem( this );
124 widgetItem->setText( nameL[i] );
125 widgetItem->setIcon( QIcon( iconL[i] ) );
126 widgetItem->setData( Qt::UserRole, QVariant( i ) );
127 addItem( widgetItem );
130 /* Spacers are yet again a different thing */
131 QListWidgetItem *widgetItem = new QListWidgetItem( QIcon( ":/space" ),
132 qtr( "Spacer" ), this );
133 widgetItem->setData( Qt::UserRole, WIDGET_SPACER );
134 addItem( widgetItem );
136 widgetItem = new QListWidgetItem( QIcon( ":/space" ),
137 qtr( "Expanding Spacer" ), this );
138 widgetItem->setData( Qt::UserRole, WIDGET_SPACER_EXTEND );
139 addItem( widgetItem );
142 * For all other widgets, we create then, do a pseudo rendering in
143 * a pixmaps for the view, and delete the object
145 * A lot of code is retaken from the Abstract, but not exactly...
147 * They are better ways to deal with this, but I doubt that this is
148 * necessary. If you feel like you have the time, be my guest.
152 for( int i = SPLITTER; i < SPECIAL_MAX; i++ )
154 QWidget *widget = NULL;
155 QListWidgetItem *widgetItem = new QListWidgetItem( this );
160 QFrame *line = new QFrame( this );
161 line->setFrameShape( QFrame::VLine );
162 line->setFrameShadow( QFrame::Raised );
163 line->setLineWidth( 0 ); line->setMidLineWidth( 1 );
166 widgetItem->setText( qtr("Splitter") );
170 InputSlider *slider = new InputSlider( Qt::Horizontal, this );
173 widgetItem->setText( qtr("Time Slider") );
177 bool b_shiny = false;
178 SoundWidget *snd = new SoundWidget( this, p_intf, b_shiny );
181 widgetItem->setText( qtr("Volume") );
185 QLabel *timeLabel = new QLabel( "12:42/2:12:42", this );
188 widgetItem->setText( qtr("Time") );
192 QWidget *discFrame = new QWidget( this );
193 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
194 discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
196 QToolButton *prevSectionButton = new QToolButton( discFrame );
197 prevSectionButton->setIcon( QIcon( ":/dvd_prev" ) );
198 discLayout->addWidget( prevSectionButton );
200 QToolButton *menuButton = new QToolButton( discFrame );
201 menuButton->setIcon( QIcon( ":/dvd_menu" ) );
202 discLayout->addWidget( menuButton );
204 QToolButton *nextButton = new QToolButton( discFrame );
205 nextButton->setIcon( QIcon( ":/dvd_next" ) );
206 discLayout->addWidget( nextButton );
210 widgetItem->setText( qtr("DVD menus") );
212 case TELETEXT_BUTTONS:
214 QWidget *telexFrame = new QWidget( this );
215 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
216 telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
218 QToolButton *telexOn = new QToolButton( telexFrame );
219 telexOn->setIcon( QIcon( ":/tv" ) );
220 telexLayout->addWidget( telexOn );
222 QToolButton *telexTransparent = new QToolButton;
223 telexOn->setIcon( QIcon( ":/tvtelx-trans" ) );
224 telexLayout->addWidget( telexTransparent );
226 QSpinBox *telexPage = new QSpinBox;
227 telexLayout->addWidget( telexPage );
231 widgetItem->setText( qtr("Teletext") );
233 case ADVANCED_CONTROLLER:
235 AdvControlsWidget *advControls = new AdvControlsWidget( p_intf );
236 widget = advControls;
238 widgetItem->setText( qtr("Advanced Buttons") );
241 msg_Warn( p_intf, "This should not happen %i", i );
245 if( widget == NULL ) continue;
248 widgetItem->setIcon( QIcon( QPixmap::grabWidget( widget ) ) );
250 widgetItem->setData( Qt::UserRole, QVariant( i ) );
252 addItem( widgetItem );
257 void WidgetListing::startDrag( Qt::DropActions /*supportedActions*/ )
259 QListWidgetItem *item =currentItem();
262 QDataStream dataStream( &itemData, QIODevice::WriteOnly );
264 int i_type = item->data( Qt::UserRole ).toInt();
265 int i_option = parent->getOptions();
266 dataStream << i_type << i_option;
268 QMimeData *mimeData = new QMimeData;
269 mimeData->setData( "vlc/button-bar", itemData );
271 QDrag *drag = new QDrag( this );
272 drag->setMimeData( mimeData );
273 // drag->setHotSpot(QPoint(pixmap.width()/2, pixmap.height()/2));
275 drag->exec(Qt::CopyAction | Qt::MoveAction );
279 DroppingController::DroppingController( intf_thread_t *_p_intf )
280 : AbstractController( _p_intf )
283 setAcceptDrops( true );
284 controlLayout = new QHBoxLayout( this );
285 controlLayout->setSpacing( 0 );
286 controlLayout->setMargin( 0 );
287 setFrameShape( QFrame::StyledPanel );
288 setFrameShadow( QFrame::Raised );
290 QString line2 = getSettings()->value( "MainWindow/Controls2",
291 "0-2;21;4;2;5;21;8;11;10;21;22;20-4" ).toString();
293 parseAndCreate( line2, controlLayout );
295 //QString line1 = getSettings()->value( "MainWindow/Controls2",
296 // "18;19;25;0" ).toString();
297 // parseAndCreate( line1, 1 );
301 /* Overloading the AbstractController one, because we don't manage the
302 Spacing in the same ways */
303 void DroppingController::createAndAddWidget( QBoxLayout *controlLayout,
308 /* Special case for SPACERS, who aren't QWidgets */
309 if( i_type == WIDGET_SPACER || i_type == WIDGET_SPACER_EXTEND )
311 QLabel *label = new QLabel;
312 label->setPixmap( QPixmap( ":/space" ) );
313 if( i_type == WIDGET_SPACER_EXTEND )
315 label->setScaledContents( true );
316 label->setSizePolicy( QSizePolicy::MinimumExpanding,
317 QSizePolicy::Preferred );
320 label->setSizePolicy( QSizePolicy::Fixed,
321 QSizePolicy::Preferred );
323 controlLayout->insertWidget( i_index, label );
327 QWidget *widg = createWidget( i_type, i_option );
330 /* Some Widgets are deactivated at creation */
331 widg->setEnabled( true );
332 controlLayout->insertWidget( i_index, widg );
336 void DroppingController::dragEnterEvent( QDragEnterEvent * event )
338 if( event->mimeData()->hasFormat( "vlc/button-bar" ) )
344 void DroppingController::dragMoveEvent( QDragMoveEvent *event )
346 QPoint origin = event->pos();
348 int i_pos = getParentPosInLayout( origin );
351 /* Both sides of the frame */
354 if( rubberband ) rubberband->hide();
358 /* Last item is special because of underlying items */
359 if( i_pos >= controlLayout->count() )
365 /* Query the underlying item for size && middles */
366 QLayoutItem *tempItem = controlLayout->itemAt( i_pos ); assert( tempItem );
367 QWidget *temp = tempItem->widget(); assert( temp );
369 /* Position assignment */
371 origin.rx() = temp->x() - 2;
373 if( b_end ) origin.rx() += temp->width();
376 rubberband = new QRubberBand( QRubberBand::Line, this );
377 rubberband->setGeometry( origin.x(), origin.y(), 4, height() );
381 inline int DroppingController::getParentPosInLayout( QPoint point)
383 point.ry() = height() / 2 ;
384 QPoint origin = mapToGlobal ( point );
386 QWidget *tempWidg = QApplication::widgetAt( origin );
389 if( tempWidg != NULL)
391 i = controlLayout->indexOf( tempWidg );
394 i = controlLayout->indexOf( tempWidg->parentWidget() );
395 tempWidg = tempWidg->parentWidget();
399 /* Return the nearest position */
400 if( ( point.x() - tempWidg->x() > tempWidg->width() / 2 ) && i != -1 )
403 // msg_Dbg( p_intf, "%i", i);
407 void DroppingController::dropEvent( QDropEvent *event )
409 int i = getParentPosInLayout( event->pos() );
411 QByteArray data = event->mimeData()->data( "vlc/button-bar" );
412 QDataStream dataStream(&data, QIODevice::ReadOnly);
414 int i_option = 0, i_type = 0;
415 dataStream >> i_type >> i_option;
417 createAndAddWidget( controlLayout, i, (buttonType_e)i_type, i_option );
419 /* Hide by precaution, you don't exactly know what could have happened in
421 if( rubberband ) rubberband->hide();
424 void DroppingController::dragLeaveEvent ( QDragLeaveEvent * event )
426 if( rubberband ) rubberband->hide();
430 * Overloading doAction to block any action
432 void DroppingController::doAction( int i ){}