Marble

FlyToEditWidget.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2013 Mihail Ivchenko <ematirov@gmail.com>
4// SPDX-FileCopyrightText: 2014 Sanjiban Bairagya <sanjiban22393@gmail.com>
5// SPDX-FileCopyrightText: 2014 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
6//
7
8#include "FlyToEditWidget.h"
9
10#include <QComboBox>
11#include <QDoubleSpinBox>
12#include <QHBoxLayout>
13#include <QLabel>
14#include <QToolButton>
15
16#include "GeoDataCamera.h"
17#include "GeoDataLookAt.h"
18#include "MarblePlacemarkModel.h"
19#include "MarbleWidget.h"
20#include "geodata/data/GeoDataFlyTo.h"
21
22namespace Marble
23{
24
25FlyToEditWidget::FlyToEditWidget(const QModelIndex &index, MarbleWidget *widget, QWidget *parent)
26 : QWidget(parent)
27 , m_widget(widget)
28 , m_index(index)
29 , m_button(new QToolButton)
30{
31 auto layout = new QHBoxLayout(this);
32 layout->setSpacing(5);
33
34 auto iconLabel = new QLabel;
35 iconLabel->setPixmap(QPixmap(QStringLiteral(":/marble/flag.png")));
36 layout->addWidget(iconLabel);
37
38 auto pairLayout = new QHBoxLayout;
39 pairLayout->setSpacing(10);
40
41 auto durationLayout = new QHBoxLayout;
42 durationLayout->setSpacing(5);
43
44 auto durationLabel = new QLabel;
45 durationLabel->setText(tr("Duration:"));
46 durationLayout->addWidget(durationLabel);
47
48 m_durationSpin = new QDoubleSpinBox;
49 durationLayout->addWidget(m_durationSpin);
50 m_durationSpin->setValue(flyToElement()->duration());
51 m_durationSpin->setSuffix(tr(" s", "seconds"));
52
53 auto modeLayout = new QHBoxLayout;
54 modeLayout->addSpacing(5);
55
56 auto modeLabel = new QLabel;
57 modeLabel->setText(tr("Mode:"));
58 modeLayout->addWidget(modeLabel);
59
60 m_modeCombo = new QComboBox;
61 modeLayout->addWidget(m_modeCombo);
62 m_modeCombo->addItem(tr("Smooth"));
63 m_modeCombo->addItem(tr("Bounce"));
64
65 if (flyToElement()->flyToMode() == GeoDataFlyTo::Smooth) {
66 m_modeCombo->setCurrentIndex(0);
67 } else if (flyToElement()->flyToMode() == GeoDataFlyTo::Bounce) {
68 m_modeCombo->setCurrentIndex(1);
69 } else {
70 m_modeCombo->setCurrentIndex(-1);
71 }
72
73 pairLayout->addLayout(durationLayout);
74 pairLayout->addLayout(modeLayout);
75
76 layout->addLayout(pairLayout);
77
78 auto flyToPinCenter = new QToolButton;
79 flyToPinCenter->setIcon(QIcon(QStringLiteral(":/marble/places.png")));
80 flyToPinCenter->setToolTip(tr("Current map center"));
81 connect(flyToPinCenter, &QAbstractButton::clicked, this, &FlyToEditWidget::updateCoordinates);
82 layout->addWidget(flyToPinCenter);
83
84 m_button->setIcon(QIcon(QStringLiteral(":/marble/document-save.png")));
85 connect(m_button, &QAbstractButton::clicked, this, &FlyToEditWidget::save);
86 layout->addWidget(m_button);
87}
88
89bool FlyToEditWidget::editable() const
90{
91 return m_button->isEnabled();
92}
93
94void FlyToEditWidget::setEditable(bool editable)
95{
96 m_button->setEnabled(editable);
97}
98
99void FlyToEditWidget::setFirstFlyTo(const QPersistentModelIndex &index)
100{
101 if (m_index.internalPointer() == index.internalPointer()) {
102 m_durationSpin->setValue(0);
103 }
104}
105
106void FlyToEditWidget::updateCoordinates()
107{
108 m_coord = m_widget->focusPoint();
109 m_coord.setAltitude(m_widget->lookAt().range());
110}
111
112void FlyToEditWidget::save()
113{
114 if (flyToElement()->view() != nullptr && m_coord != GeoDataCoordinates()) {
115 GeoDataCoordinates coords = m_coord;
116 if (auto camera = geodata_cast<GeoDataCamera>(flyToElement()->view())) {
117 camera->setCoordinates(coords);
118 } else if (auto lookAt = geodata_cast<GeoDataLookAt>(flyToElement()->view())) {
119 lookAt->setCoordinates(coords);
120 } else {
121 lookAt = new GeoDataLookAt;
122 lookAt->setCoordinates(coords);
123 flyToElement()->setView(lookAt);
124 }
125 }
126
127 flyToElement()->setDuration(m_durationSpin->value());
128
129 if (m_modeCombo->currentIndex() == 0) {
130 flyToElement()->setFlyToMode(GeoDataFlyTo::Smooth);
131 } else if (m_modeCombo->currentIndex() == 1) {
132 flyToElement()->setFlyToMode(GeoDataFlyTo::Bounce);
133 }
134
135 Q_EMIT editingDone(m_index);
136}
137
138GeoDataFlyTo *FlyToEditWidget::flyToElement()
139{
140 auto object = qvariant_cast<GeoDataObject *>(m_index.data(MarblePlacemarkModel::ObjectPointerRole));
141 Q_ASSERT(object);
142 auto flyTo = geodata_cast<GeoDataFlyTo>(object);
143 Q_ASSERT(flyTo);
144 return flyTo;
145}
146
147} // namespace Marble
148
149#include "moc_FlyToEditWidget.cpp"
This file contains the headers for MarbleWidget.
Q_SCRIPTABLE QString camera()
Binds a QML item to a specific geodetic location in screen coordinates.
void clicked(bool checked)
void setIcon(const QIcon &icon)
void addSpacing(int size)
virtual void setSpacing(int spacing) override
void addItem(const QIcon &icon, const QString &text, const QVariant &userData)
void setValue(double val)
void setPixmap(const QPixmap &)
void setText(const QString &)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:37:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.