-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwindow.cpp
201 lines (158 loc) · 5.64 KB
/
window.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
Author: Jesper Thomschutz 2008, [email protected]
This file is part of Trippy.
Trippy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Trippy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Trippy. If not, see <http://www.gnu.org/licenses/>.
*/
#include "window.h"
Window::Window(QWidget *parent)
:QMainWindow(parent)
{
ui.setupUi(this);
ui.lv_photos->setIconSize(QSize(60, 60));
m_marble = new TrippyMarbleWidget(this);
//Needed to fetch missing tiles. Hope it's alright to use this KDE hosted one...
m_marble->setDownloadUrl( "http://download.kde.org/apps/marble/" );
//Default view for now is mercator and Atlas, since they're my favorite at the moment.
ui.actionAtlas->trigger();
atlasClicked();
ui.actionMercator->trigger();
mercatorClicked();
ui.verticalLayout->addWidget(m_marble);
m_fileDialog = new QFileDialog(this, "Select geo-tagged images");
m_fileDialog->setNameFilter("Image Files (*.jpg)");
m_fileDialog->setFileMode(QFileDialog::ExistingFiles);
m_previousItem = new QStandardItem;
//Add photos button and menu item
QObject::connect(ui.pb_addPhotos, SIGNAL(clicked()), this, SLOT(selectFile()));
QObject::connect(ui.action_Add_Photos, SIGNAL(triggered()), this, SLOT(selectFile()));
//Menubar items:
QObject::connect(ui.actionAtlas, SIGNAL(triggered()), this, SLOT(atlasClicked()));
QObject::connect(ui.actionOpen_Street_Map, SIGNAL(triggered()), this, SLOT(openStreetMapClicked()));
QObject::connect(ui.actionFlat, SIGNAL(triggered()), this, SLOT(flatClicked()));
QObject::connect(ui.actionMercator, SIGNAL(triggered()), this, SLOT(mercatorClicked()));
QObject::connect(ui.actionGlobe, SIGNAL(triggered()), this, SLOT(globeClicked()));
//Files selected from the file dialog
QObject::connect(m_fileDialog, SIGNAL(filesSelected(const QStringList &)), this, SLOT(filesSelected(const QStringList &)));
//An item (photo) was clicked in the list view.
QObject::connect(ui.lv_photos, SIGNAL(clicked(const QModelIndex &)), this, SLOT(photoClicked(const QModelIndex &)));
//Back and Next buttons
QObject::connect(ui.pb_back, SIGNAL(clicked()), this, SLOT(backClicked()));
QObject::connect(ui.pb_next, SIGNAL(clicked()), this, SLOT(nextClicked()));
}
void Window::hideMapClutter()
{
m_marble->setShowCompass(false);
m_marble->setShowScaleBar(false);
m_marble->setShowOverviewMap(false);
}
void Window::repaintMarbleWidget()
{
m_marble->repaint();
}
void Window::selectFile()
{
m_fileDialog->show();
}
void Window::backClicked()
{
int rowCount = ((QStandardItemModel *)ui.lv_photos->model())->rowCount();
if (0 == rowCount)
{
return;
}
int currentRow = ui.lv_photos->currentIndex().row();
QStandardItem *nextItem = ((QStandardItemModel *)ui.lv_photos->model())->item(currentRow-1);
if (!nextItem)
{
nextItem = ((QStandardItemModel *)ui.lv_photos->model())->item(rowCount-1);
}
ui.lv_photos->setCurrentIndex(nextItem->index());
photoClicked(nextItem->index());
}
void Window::nextClicked()
{
int rowCount = ((QStandardItemModel *)ui.lv_photos->model())->rowCount();
if (0 == rowCount)
{
return;
}
int currentRow = ui.lv_photos->currentIndex().row();
QStandardItem *nextItem = ((QStandardItemModel *)ui.lv_photos->model())->item(currentRow+1);
if (!nextItem)
{
nextItem = ((QStandardItemModel *)ui.lv_photos->model())->item(0);
}
ui.lv_photos->setCurrentIndex(nextItem->index());
photoClicked(nextItem->index());
}
void Window::filesSelected(const QStringList &selected)
{
ui.pb_next->setEnabled(true);
ui.pb_back->setEnabled(true);
m_fileDialog->hide();
emit selectedFiles(selected);
}
void Window::photoClicked(const QModelIndex &index)
{
QStandardItemModel *model = (QStandardItemModel *)ui.lv_photos->model();
QStandardItem *item = model->itemFromIndex(index);
item->setData(true, SelectedRole);
if (item != m_previousItem)
{
m_previousItem->setData(false, SelectedRole);
m_previousItem = item;
}
QVariant v = item->data(PhotoRole);
Photo photo = v.value<Photo>();
centerMapOn(&photo);
}
void Window::centerMapOn(Photo *photo)
{
ui.l_photo->setPixmap(photo->getThumbnail());
m_marble->centerOn(photo->getGpsLong(), photo->getGpsLat());
m_marble->zoomView(3000);
}
void Window::atlasClicked()
{
m_marble->setMapThemeId(QLatin1String("earth/srtm/srtm.dgml"));
ui.actionAtlas->setChecked(true);
ui.actionOpen_Street_Map->setChecked(false);
hideMapClutter();
}
void Window::openStreetMapClicked()
{
m_marble->setMapThemeId(QLatin1String("earth/openstreetmap/openstreetmap.dgml"));
ui.actionOpen_Street_Map->setChecked(true);
ui.actionAtlas->setChecked(false);
hideMapClutter();
}
void Window::mercatorClicked()
{
m_marble->setProjection(Mercator);
ui.actionMercator->setChecked(true);
ui.actionGlobe->setChecked(false);
ui.actionFlat->setChecked(false);
}
void Window::flatClicked()
{
m_marble->setProjection(Equirectangular);
ui.actionFlat->setChecked(true);
ui.actionGlobe->setChecked(false);
ui.actionMercator->setChecked(false);
}
void Window::globeClicked()
{
m_marble->setProjection(Spherical);
ui.actionGlobe->setChecked(true);
ui.actionMercator->setChecked(false);
ui.actionFlat->setChecked(false);
}