File indexing completed on 2024-05-12 05:22:10
0001 /* 0002 SPDX-FileCopyrightText: 2012 Jan Grulich <jgrulich@redhat.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "mainwindow.h" 0008 #include "ui_mainwindow.h" 0009 0010 #include "staticmaps/staticmapurl.h" 0011 0012 using namespace KGAPI2; 0013 0014 MainWindow::MainWindow(QWidget *parent) 0015 : QMainWindow(parent) 0016 , m_ui(new Ui::MainWindow) 0017 { 0018 m_ui->setupUi(this); 0019 0020 connect(m_ui->get, SIGNAL(clicked(bool)), this, SLOT(getImage())); 0021 connect(m_ui->addMarker, SIGNAL(clicked(bool)), this, SLOT(addMarker())); 0022 } 0023 0024 MainWindow::~MainWindow() 0025 { 0026 } 0027 0028 void MainWindow::addMarker() 0029 { 0030 StaticMapMarker marker; 0031 0032 if (!m_ui->markerLocation->text().isEmpty()) { 0033 if (!m_ui->markerLabel->text().isEmpty()) 0034 marker.setLabel(QChar(m_ui->markerLabel->text().at(0))); 0035 0036 marker.setSize((StaticMapMarker::MarkerSize)m_ui->markerSize->currentIndex()); 0037 marker.setColor(m_ui->markerColor->color()); 0038 marker.setLocation(m_ui->markerLocation->text()); 0039 0040 m_ui->markers->addItem(marker.toString()); 0041 m_markers << marker; 0042 } 0043 } 0044 0045 void MainWindow::getImage() 0046 { 0047 StaticMapUrl map; 0048 KContacts::Address addr; 0049 0050 switch (m_ui->locationType->currentIndex()) { 0051 case StaticMapUrl::String: 0052 map.setLocation(m_ui->locationString->text()); 0053 break; 0054 case StaticMapUrl::KABCAddress: 0055 addr.setLocality(m_ui->locationCity->text()); 0056 addr.setStreet(m_ui->locationStreet->text()); 0057 map.setLocation(addr); 0058 break; 0059 case StaticMapUrl::KABCGeo: 0060 map.setLocation(KContacts::Geo(m_ui->locationLatitude->value(), m_ui->locationLongitude->value())); 0061 break; 0062 } 0063 0064 map.setZoomLevel(m_ui->zoom->value()); 0065 map.setSize(QSize(m_ui->width->value(), m_ui->height->value())); 0066 map.setScale(static_cast<StaticMapUrl::Scale>(m_ui->scale->currentIndex() + 1)); 0067 map.setFormat(static_cast<StaticMapUrl::ImageFormat>(m_ui->format->currentIndex())); 0068 map.setMapType(static_cast<StaticMapUrl::MapType>(m_ui->map->currentIndex())); 0069 map.setSensorUsed(m_ui->sensor->currentIndex()); 0070 map.setMarkers(m_markers); 0071 0072 StaticMapTileFetchJob *fetchJob = new StaticMapTileFetchJob(map.url(), this); 0073 connect(fetchJob, SIGNAL(finished(KGAPI2::Job *)), this, SLOT(slotTileFetched(KGAPI2::Job *))); 0074 } 0075 0076 void MainWindow::slotTileFetched(KGAPI2::Job *job) 0077 { 0078 StaticMapTileFetchJob *fetchJob = qobject_cast<StaticMapTileFetchJob *>(job); 0079 Q_ASSERT(fetchJob); 0080 fetchJob->deleteLater(); 0081 0082 const QPixmap pixmap = fetchJob->tilePixmap(); 0083 m_ui->label->setPixmap(pixmap); 0084 } 0085 0086 #include "moc_mainwindow.cpp"