File indexing completed on 2024-04-14 03:47:44
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2013 Mihail Ivchenko <ematirov@gmail.com> 0004 // SPDX-FileCopyrightText: 2014 Sanjiban Bairagya <sanjiban22393@gmail.com> 0005 // SPDX-FileCopyrightText: 2014 Illya Kovalevskyy <illya.kovalevskyy@gmail.com> 0006 // 0007 0008 #include "FlyToEditWidget.h" 0009 0010 #include <QDoubleSpinBox> 0011 #include <QToolButton> 0012 #include <QLabel> 0013 #include <QHBoxLayout> 0014 #include <QComboBox> 0015 0016 #include "MarbleWidget.h" 0017 #include "geodata/data/GeoDataFlyTo.h" 0018 #include "GeoDataLookAt.h" 0019 #include "GeoDataCamera.h" 0020 #include "MarblePlacemarkModel.h" 0021 0022 namespace Marble 0023 { 0024 0025 FlyToEditWidget::FlyToEditWidget( const QModelIndex &index, MarbleWidget* widget, QWidget *parent ) : 0026 QWidget( parent ), 0027 m_widget( widget ), 0028 m_index( index ), 0029 m_button( new QToolButton ) 0030 { 0031 QHBoxLayout *layout = new QHBoxLayout; 0032 layout->setSpacing( 5 ); 0033 0034 QLabel* iconLabel = new QLabel; 0035 iconLabel->setPixmap(QPixmap(QStringLiteral(":/marble/flag.png"))); 0036 layout->addWidget( iconLabel ); 0037 0038 QHBoxLayout *pairLayout = new QHBoxLayout; 0039 pairLayout->setSpacing( 10 ); 0040 0041 QHBoxLayout *durationLayout = new QHBoxLayout; 0042 durationLayout->setSpacing( 5 ); 0043 0044 QLabel *durationLabel = new QLabel; 0045 durationLabel->setText( tr("Duration:") ); 0046 durationLayout->addWidget( durationLabel ); 0047 0048 m_durationSpin = new QDoubleSpinBox; 0049 durationLayout->addWidget( m_durationSpin ); 0050 m_durationSpin->setValue( flyToElement()->duration() ); 0051 m_durationSpin->setSuffix( tr(" s", "seconds") ); 0052 0053 QHBoxLayout *modeLayout = new QHBoxLayout; 0054 modeLayout->addSpacing( 5 ); 0055 0056 QLabel *modeLabel = new QLabel; 0057 modeLabel->setText( tr("Mode:") ); 0058 modeLayout->addWidget( modeLabel ); 0059 0060 m_modeCombo = new QComboBox; 0061 modeLayout->addWidget( m_modeCombo ); 0062 m_modeCombo->addItem( tr("Smooth") ); 0063 m_modeCombo->addItem( tr("Bounce") ); 0064 0065 if( flyToElement()->flyToMode() == GeoDataFlyTo::Smooth ){ 0066 m_modeCombo->setCurrentIndex( 0 ); 0067 } else if( flyToElement()->flyToMode() == GeoDataFlyTo::Bounce ){ 0068 m_modeCombo->setCurrentIndex( 1 ); 0069 } else { 0070 m_modeCombo->setCurrentIndex( -1 ); 0071 } 0072 0073 pairLayout->addLayout( durationLayout ); 0074 pairLayout->addLayout( modeLayout ); 0075 0076 layout->addLayout( pairLayout ); 0077 0078 QToolButton* flyToPinCenter = new QToolButton; 0079 flyToPinCenter->setIcon(QIcon(QStringLiteral(":/marble/places.png"))); 0080 flyToPinCenter->setToolTip(tr("Current map center")); 0081 connect(flyToPinCenter, SIGNAL(clicked()), this, SLOT(updateCoordinates())); 0082 layout->addWidget(flyToPinCenter); 0083 0084 m_button->setIcon(QIcon(QStringLiteral(":/marble/document-save.png"))); 0085 connect(m_button, SIGNAL(clicked()), this, SLOT(save())); 0086 layout->addWidget( m_button ); 0087 0088 setLayout( layout ); 0089 } 0090 0091 bool FlyToEditWidget::editable() const 0092 { 0093 return m_button->isEnabled(); 0094 } 0095 0096 void FlyToEditWidget::setEditable( bool editable ) 0097 { 0098 m_button->setEnabled( editable ); 0099 } 0100 0101 void FlyToEditWidget::setFirstFlyTo(const QPersistentModelIndex &index) 0102 { 0103 if( m_index.internalPointer() == index.internalPointer() ) { 0104 m_durationSpin->setValue(0); 0105 } 0106 } 0107 0108 void FlyToEditWidget::updateCoordinates() 0109 { 0110 m_coord = m_widget->focusPoint(); 0111 m_coord.setAltitude( m_widget->lookAt().range() ); 0112 } 0113 0114 void FlyToEditWidget::save() 0115 { 0116 if (flyToElement()->view() != nullptr && m_coord != GeoDataCoordinates()) { 0117 GeoDataCoordinates coords = m_coord; 0118 if (auto camera = geodata_cast<GeoDataCamera>(flyToElement()->view())) { 0119 camera->setCoordinates( coords ); 0120 } else if (auto lookAt = geodata_cast<GeoDataLookAt>(flyToElement()->view())) { 0121 lookAt->setCoordinates( coords ); 0122 } else{ 0123 lookAt = new GeoDataLookAt; 0124 lookAt->setCoordinates( coords ); 0125 flyToElement()->setView( lookAt ); 0126 } 0127 } 0128 0129 flyToElement()->setDuration(m_durationSpin->value()); 0130 0131 if (m_modeCombo->currentIndex() == 0) { 0132 flyToElement()->setFlyToMode( GeoDataFlyTo::Smooth ); 0133 } else if (m_modeCombo->currentIndex() == 1) { 0134 flyToElement()->setFlyToMode( GeoDataFlyTo::Bounce ); 0135 } 0136 0137 emit editingDone(m_index); 0138 } 0139 0140 GeoDataFlyTo* FlyToEditWidget::flyToElement() 0141 { 0142 GeoDataObject *object = qvariant_cast<GeoDataObject*>(m_index.data( MarblePlacemarkModel::ObjectPointerRole ) ); 0143 Q_ASSERT( object ); 0144 auto flyTo = geodata_cast<GeoDataFlyTo>(object); 0145 Q_ASSERT(flyTo); 0146 return flyTo; 0147 } 0148 0149 } // namespace Marble 0150 0151 #include "moc_FlyToEditWidget.cpp"