~ubuntu-branches/ubuntu/wily/marble/wily-proposed

« back to all changes in this revision

Viewing changes to src/lib/marble/TourWidget.cpp

  • Committer: Package Import Robot
  • Author(s): Scarlett Clark
  • Date: 2015-02-10 08:12:41 UTC
  • mfrom: (1.5.9) (68.1.8 vivid-proposed)
  • Revision ID: package-import@ubuntu.com-20150210081241-pv81u6p0zr1yuulq
Tags: 4:14.12.2-0ubuntu1
* New upstream release
* Remove unstable from watch file, uscan fails with 
  remote site does not even have current version
* batchpatch new symbols.

Show diffs side-by-side

added added

removed removed

Lines of Context:
118
118
    QObject::connect( m_tourUi.m_actionSaveTour, SIGNAL( triggered() ), q, SLOT( saveTour() ) );
119
119
    QObject::connect( m_tourUi.m_actionSaveTourAs, SIGNAL( triggered() ), q, SLOT( saveTourAs() ) );
120
120
    QObject::connect( m_tourUi.m_actionRecord, SIGNAL(triggered()), q, SLOT( captureTour()) );
 
121
    QObject::connect( &m_playback, SIGNAL( finished() ), q, SLOT( stopPlaying() ) );
121
122
}
122
123
 
123
124
TourWidget::TourWidget( QWidget *parent, Qt::WindowFlags flags )
137
138
}
138
139
 
139
140
TourItemDelegate::TourItemDelegate( QListView* view, MarbleWidget* widget ):
140
 
                    m_listView( view ), m_widget( widget )
 
141
                    m_listView( view ), m_widget( widget ), m_editable( true )
141
142
{
142
143
    QObject::connect( this, SIGNAL( editingChanged( QModelIndex ) ), m_listView, SLOT( update( QModelIndex ) ) );
143
144
    m_listView->setEditTriggers( QAbstractItemView::NoEditTriggers );
166
167
    button.features = QStyleOptionButton::None;
167
168
    button.iconSize = QSize( 16, 16 );
168
169
    button.state &= ~QStyle::State_HasFocus;
 
170
    if( !editable() ) {
 
171
        button.state &= ~QStyle::State_Enabled;
 
172
    }
169
173
 
170
174
    QRect const iconRect = position( GeoDataElementIcon, option );
171
175
 
313
317
    if ( object->nodeType() == GeoDataTypes::GeoDataFlyToType ) {
314
318
        FlyToEditWidget* widget = new FlyToEditWidget(index, m_widget, parent);
315
319
        connect(widget, SIGNAL(editingDone(QModelIndex)), this, SLOT(closeEditor(QModelIndex)));
 
320
        connect( this, SIGNAL( editableChanged( bool) ), widget, SLOT( setEditable( bool ) ) );
316
321
        return widget;
317
322
 
318
323
    } else if ( object->nodeType() == GeoDataTypes::GeoDataTourControlType ) {
319
324
        TourControlEditWidget* widget = new TourControlEditWidget(index, parent);
320
325
        connect(widget, SIGNAL(editingDone(QModelIndex)), this, SLOT(closeEditor(QModelIndex)));
 
326
        connect( this, SIGNAL( editableChanged( bool) ), widget, SLOT( setEditable( bool ) ) );
321
327
        return widget;
322
328
 
323
329
    } else if ( object->nodeType() == GeoDataTypes::GeoDataWaitType ) {
324
330
        WaitEditWidget* widget = new WaitEditWidget(index, parent);
325
331
        connect(widget, SIGNAL(editingDone(QModelIndex)), this, SLOT(closeEditor(QModelIndex)));
 
332
        connect( this, SIGNAL( editableChanged( bool) ), widget, SLOT( setEditable( bool ) ) );
326
333
        return widget;
327
334
 
328
335
    } else if ( object->nodeType() == GeoDataTypes::GeoDataSoundCueType ) {
329
336
        SoundCueEditWidget* widget = new SoundCueEditWidget(index, parent);
330
337
        connect(widget, SIGNAL(editingDone(QModelIndex)), this, SLOT(closeEditor(QModelIndex)));
 
338
        connect( this, SIGNAL( editableChanged( bool) ), widget, SLOT( setEditable( bool ) ) );
331
339
        return widget;
332
340
 
333
341
    }
334
342
    return 0;
335
343
}
336
344
 
 
345
bool TourItemDelegate::editable() const
 
346
{
 
347
    return m_editable;
 
348
}
 
349
 
 
350
void TourItemDelegate::setEditable( bool editable )
 
351
{
 
352
    if( m_editable != editable ) {
 
353
        m_editable = editable;
 
354
        emit editableChanged( m_editable );
 
355
    }
 
356
}
 
357
 
337
358
bool TourItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
338
359
{
339
360
    Q_UNUSED( model );
340
 
    if ( ( event->type() == QEvent::MouseButtonRelease ) ) {
 
361
    if ( ( event->type() == QEvent::MouseButtonRelease ) && editable() ) {
341
362
        QMouseEvent *mouseEvent = static_cast<QMouseEvent*>( event );
342
363
        QRect editRect = position( EditButton, option );
343
364
        if ( editRect.contains( mouseEvent->pos() ) ) {
358
379
 
359
380
void TourItemDelegate::closeEditor( const QModelIndex &index )
360
381
{
 
382
    emit edited( index );
361
383
    m_listView->closePersistentEditor( index );
362
384
    m_editingIndices.removeOne( index );
363
385
}
371
393
{
372
394
    d->m_widget = widget;
373
395
    d->m_delegate = new TourItemDelegate( d->m_tourUi.m_listView, d->m_widget );
 
396
    QObject::connect( d->m_delegate, SIGNAL( edited( QModelIndex ) ), this, SLOT( updateDuration() ) );
374
397
    d->m_tourUi.m_listView->setItemDelegate( d->m_delegate );
375
398
}
376
399
 
391
414
    d->m_tourUi.actionPlay->setIcon( QIcon( ":/marble/playback-pause.png" ) );
392
415
    d->m_tourUi.actionPlay->setEnabled( true );
393
416
    d->m_tourUi.actionStop->setEnabled( true );
 
417
    d->m_delegate->setEditable( false );
394
418
}
395
419
 
396
420
void TourWidget::pausePlaying()
408
432
    d->m_tourUi.actionPlay->setEnabled( true );
409
433
    d->m_tourUi.actionStop->setEnabled( false );
410
434
    d->m_playState = false;
 
435
    d->m_delegate->setEditable( true );
411
436
}
412
437
 
413
438
void TourWidget::handleSliderMove( int value )
465
490
    QVariant coordinatesVariant = m_widget->model()->treeModel()->data( index, MarblePlacemarkModel::CoordinateRole );
466
491
    if ( !coordinatesVariant.isNull() ) {
467
492
        GeoDataCoordinates const coordinates = coordinatesVariant.value<GeoDataCoordinates>();
468
 
        m_widget->centerOn( coordinates );
 
493
        GeoDataLookAt lookat;
 
494
        lookat.setCoordinates( coordinates );
 
495
        lookat.setRange( coordinates.altitude() );
 
496
        m_widget->flyTo( lookat, Instant );
469
497
    }
470
498
}
471
499
 
473
501
{
474
502
    GeoDataFlyTo *flyTo = new GeoDataFlyTo();
475
503
    flyTo->setView( new GeoDataLookAt( m_widget->lookAt() ) );
 
504
    GeoDataLookAt *lookat = new GeoDataLookAt( m_widget->lookAt() );
 
505
    lookat->setAltitude( lookat->range() );
 
506
    flyTo->setView( lookat );
476
507
    GeoDataObject *rootObject =  rootIndexObject();
477
508
    if ( rootObject->nodeType() == GeoDataTypes::GeoDataPlaylistType ) {
478
509
        GeoDataPlaylist *playlist = static_cast<GeoDataPlaylist*>( rootObject );
479
510
        QModelIndex currentIndex = m_tourUi.m_listView->currentIndex();
480
 
        if ( currentIndex.isValid() ) {
481
 
            playlist->insertPrimitive( currentIndex.row()+1, flyTo );
482
 
        } else {
483
 
            playlist->addPrimitive( flyTo );
484
 
        }
 
511
        QModelIndex playlistIndex = m_widget->model()->treeModel()->index( playlist );
 
512
        int row = currentIndex.isValid() ? currentIndex.row()+1 : playlist->size();
 
513
        m_widget->model()->treeModel()->addTourPrimitive( playlistIndex, flyTo, row );
485
514
        m_isChanged = true;
486
515
        m_tourUi.m_actionSaveTour->setEnabled( true );
487
516
    }
497
526
        GeoDataObject *rootObject =  rootIndexObject();
498
527
        if ( rootObject && rootObject->nodeType() == GeoDataTypes::GeoDataPlaylistType ) {
499
528
            GeoDataPlaylist *playlist = static_cast<GeoDataPlaylist*>( rootObject );
 
529
            QModelIndex playlistIndex = m_widget->model()->treeModel()->index( playlist );
500
530
            QModelIndexList selected = m_tourUi.m_listView->selectionModel()->selectedIndexes();
501
531
            qSort( selected.begin(), selected.end(), qGreater<QModelIndex>() );
502
532
            QModelIndexList::iterator end = selected.end();
503
533
            QModelIndexList::iterator iter = selected.begin();
504
534
            for( ; iter != end; ++iter ) {
505
 
                playlist->removePrimitiveAt( iter->row() );
 
535
                m_widget->model()->treeModel()->removeTourPrimitive( playlistIndex, iter->row() );
506
536
            }
507
537
            m_isChanged = true;
508
538
            m_tourUi.m_actionSaveTour->setEnabled( true );
537
567
    GeoDataObject *rootObject =  rootIndexObject();
538
568
    if ( rootObject && rootObject->nodeType() == GeoDataTypes::GeoDataPlaylistType ) {
539
569
        GeoDataPlaylist *playlist = static_cast<GeoDataPlaylist*>( rootObject );
 
570
        QModelIndex playlistIndex = m_widget->model()->treeModel()->index( playlist );
540
571
        QModelIndexList selected = m_tourUi.m_listView->selectionModel()->selectedIndexes();
541
572
        qSort( selected.begin(), selected.end(), qLess<QModelIndex>() );
542
573
        QModelIndexList::iterator end = selected.end();
544
575
        for( ; iter != end; ++iter ) {
545
576
            int const index = iter->row();
546
577
            Q_ASSERT( index > 0 );
547
 
            playlist->swapPrimitives( index-1, index );
 
578
            m_widget->model()->treeModel()->swapTourPrimitives( playlistIndex, index-1, index );
548
579
        }
549
580
        m_isChanged = true;
550
581
        m_tourUi.m_actionSaveTour->setEnabled( true );
 
582
        updateButtonsStates();
551
583
    }
552
584
}
553
585
 
556
588
    GeoDataObject *rootObject = rootIndexObject();
557
589
    if ( rootObject && rootObject->nodeType() == GeoDataTypes::GeoDataPlaylistType ) {
558
590
        GeoDataPlaylist *playlist = static_cast<GeoDataPlaylist*>( rootObject );
 
591
        QModelIndex playlistIndex = m_widget->model()->treeModel()->index( playlist );
559
592
        QModelIndexList selected = m_tourUi.m_listView->selectionModel()->selectedIndexes();
560
593
        qSort( selected.begin(), selected.end(), qGreater<QModelIndex>() );
561
594
        QModelIndexList::iterator end = selected.end();
563
596
        for( ; iter != end; ++iter ) {
564
597
            int const index = iter->row();
565
598
            Q_ASSERT( index < playlist->size()-1 );
566
 
            playlist->swapPrimitives( index, index+1 );
 
599
            m_widget->model()->treeModel()->swapTourPrimitives( playlistIndex, index, index+1 );
567
600
        }
568
601
        m_isChanged = true;
569
602
        m_tourUi.m_actionSaveTour->setEnabled( true );
 
603
        updateButtonsStates();
570
604
    }
571
605
}
572
606
 
627
661
    }
628
662
}
629
663
 
 
664
void TourWidget::updateDuration()
 
665
{
 
666
    d->m_tourUi.m_slider->setMaximum( d->m_playback.duration() * 100 );
 
667
}
 
668
 
630
669
void TourWidget::moveDown()
631
670
{
632
671
    d->moveDown();
804
843
FlyToEditWidget::FlyToEditWidget( const QModelIndex &index, MarbleWidget* widget, QWidget *parent ) :
805
844
    QWidget( parent ),
806
845
    m_widget( widget ),
807
 
    m_index( index )
 
846
    m_index( index ),
 
847
    m_button( new QToolButton )
808
848
{
809
849
    QHBoxLayout *layout = new QHBoxLayout;
810
850
    layout->setSpacing( 5 );
817
857
    flyToLabel->setText( tr( "Current map center" ) );
818
858
    layout->addWidget( flyToLabel );
819
859
 
820
 
    QToolButton *button = new QToolButton;
821
 
    button->setIcon( QIcon( ":/marble/document-save.png" ) );
822
 
    connect(button, SIGNAL(clicked()), this, SLOT(save()));
823
 
    layout->addWidget( button );
 
860
    m_button->setIcon( QIcon( ":/marble/document-save.png" ) );
 
861
    connect(m_button, SIGNAL(clicked()), this, SLOT(save()));
 
862
    layout->addWidget( m_button );
824
863
 
825
864
    setLayout( layout );
826
865
}
827
866
 
 
867
bool FlyToEditWidget::editable() const
 
868
{
 
869
    return m_button->isEnabled();
 
870
}
 
871
 
828
872
void FlyToEditWidget::save()
829
873
{
830
874
    if(flyToElement()->view()!=0){
831
875
        GeoDataCoordinates coords = m_widget->focusPoint();
 
876
        coords.setAltitude( m_widget->lookAt().range() );
832
877
        if ( flyToElement()->view()->nodeType() == GeoDataTypes::GeoDataCameraType ) {
833
878
            GeoDataCamera* camera = dynamic_cast<GeoDataCamera*>( flyToElement()->view() );
834
879
            camera->setCoordinates( coords );
844
889
    emit editingDone(m_index);
845
890
}
846
891
 
 
892
void FlyToEditWidget::setEditable( bool editable )
 
893
{
 
894
    m_button->setEnabled( editable );
 
895
}
 
896
 
847
897
GeoDataFlyTo* FlyToEditWidget::flyToElement()
848
898
{
849
899
    GeoDataObject *object = qvariant_cast<GeoDataObject*>(m_index.data( MarblePlacemarkModel::ObjectPointerRole ) );
855
905
TourControlEditWidget::TourControlEditWidget( const QModelIndex &index, QWidget *parent ) :
856
906
    QWidget( parent ),
857
907
    m_index( index ),
 
908
    m_button( new QToolButton ),
858
909
    m_radio_play( new QRadioButton ),
859
910
    m_radio_pause( new QRadioButton )
860
911
{
877
928
        m_radio_pause->setChecked( true );
878
929
    }
879
930
 
880
 
    QToolButton *button = new QToolButton;
881
 
    button->setIcon( QIcon( ":/marble/document-save.png" ) );
882
 
    connect(button, SIGNAL(clicked()), this, SLOT(save()));
883
 
    layout->addWidget( button );
 
931
    m_button->setIcon( QIcon( ":/marble/document-save.png" ) );
 
932
    connect(m_button, SIGNAL(clicked()), this, SLOT(save()));
 
933
    layout->addWidget( m_button );
884
934
 
885
935
    setLayout( layout );
886
936
}
887
937
 
 
938
bool TourControlEditWidget::editable() const
 
939
{
 
940
    return m_button->isEnabled();
 
941
}
 
942
 
888
943
void TourControlEditWidget::save()
889
944
{
890
945
    if( m_radio_play->isChecked() ){
895
950
    emit editingDone(m_index);
896
951
}
897
952
 
 
953
void TourControlEditWidget::setEditable( bool editable )
 
954
{
 
955
    m_button->setEnabled( editable );
 
956
}
 
957
 
898
958
GeoDataTourControl* TourControlEditWidget::tourControlElement()
899
959
{
900
960
    GeoDataObject *object = qvariant_cast<GeoDataObject*>(m_index.data( MarblePlacemarkModel::ObjectPointerRole ) );
906
966
WaitEditWidget::WaitEditWidget( const QModelIndex &index, QWidget *parent ) :
907
967
    QWidget( parent ),
908
968
    m_index( index ),
 
969
    m_button( new QToolButton ),
909
970
    m_spinBox( new QDoubleSpinBox )
910
971
{
911
972
    QHBoxLayout *layout = new QHBoxLayout;
922
983
    layout->addWidget( m_spinBox );
923
984
    m_spinBox->setValue( waitElement()->duration() );
924
985
 
925
 
    QToolButton *button = new QToolButton;
926
 
    button->setIcon( QIcon( ":/marble/document-save.png" ) );
927
 
    connect(button, SIGNAL(clicked()), this, SLOT(save()));
928
 
    layout->addWidget( button );
 
986
    m_button->setIcon( QIcon( ":/marble/document-save.png" ) );
 
987
    connect(m_button, SIGNAL(clicked()), this, SLOT(save()));
 
988
    layout->addWidget( m_button );
929
989
 
930
990
    setLayout( layout );
931
991
}
932
992
 
 
993
bool WaitEditWidget::editable() const
 
994
{
 
995
    return m_button->isEnabled();
 
996
}
 
997
 
933
998
void WaitEditWidget::save()
934
999
{
935
1000
    waitElement()->setDuration( m_spinBox->value() );
936
1001
    emit editingDone(m_index);
937
1002
}
938
1003
 
 
1004
void WaitEditWidget::setEditable( bool editable )
 
1005
{
 
1006
    m_button->setEnabled( editable );
 
1007
}
 
1008
 
939
1009
GeoDataWait* WaitEditWidget::waitElement()
940
1010
{
941
1011
    GeoDataObject *object = qvariant_cast<GeoDataObject*>(m_index.data( MarblePlacemarkModel::ObjectPointerRole ) );
947
1017
SoundCueEditWidget::SoundCueEditWidget( const QModelIndex &index, QWidget *parent ) :
948
1018
    QWidget( parent ),
949
1019
    m_index( index ),
 
1020
    m_button( new QToolButton ),
950
1021
    m_lineEdit( new QLineEdit )
951
1022
{
952
1023
    QHBoxLayout *layout = new QHBoxLayout;
959
1030
    m_lineEdit->setPlaceholderText( "Audio location" );
960
1031
    layout->addWidget( m_lineEdit );
961
1032
 
962
 
    QToolButton *button = new QToolButton;
963
 
    button->setIcon( QIcon( ":/marble/document-save.png" ) );
964
 
    connect(button, SIGNAL(clicked()), this, SLOT(save()));
965
 
    layout->addWidget( button );
 
1033
    m_button->setIcon( QIcon( ":/marble/document-save.png" ) );
 
1034
    connect(m_button, SIGNAL(clicked()), this, SLOT(save()));
 
1035
    layout->addWidget( m_button );
966
1036
 
967
1037
    setLayout( layout );
968
1038
}
969
1039
 
 
1040
bool SoundCueEditWidget::editable() const
 
1041
{
 
1042
    return m_button->isEnabled();
 
1043
}
 
1044
 
970
1045
void SoundCueEditWidget::save()
971
1046
{
972
1047
    soundCueElement()->setHref( m_lineEdit->text() );
973
1048
    emit editingDone(m_index);
974
1049
}
975
1050
 
 
1051
void SoundCueEditWidget::setEditable( bool editable )
 
1052
{
 
1053
    m_button->setEnabled( editable );
 
1054
}
 
1055
 
976
1056
GeoDataSoundCue* SoundCueEditWidget::soundCueElement()
977
1057
{
978
1058
    GeoDataObject *object = qvariant_cast<GeoDataObject*>(m_index.data( MarblePlacemarkModel::ObjectPointerRole ) );