14 #include <QStringList>
16 #include <QMouseEvent>
19 #include <QFileDialog>
20 #include <QHBoxLayout>
21 #include <QSvgRenderer>
22 #include <QColorDialog>
27 #include "ui_OverviewMapConfigWidget.h"
47 m_planetID(
Planet::planetList() ),
65 QHash<QString, QSvgWidget *>::const_iterator pos = m_svgWidgets.constBegin();
66 QHash<QString, QSvgWidget *>::const_iterator
const end = m_svgWidgets.constEnd();
67 for (; pos != end; ++pos ) {
74 return QStringList(
"overviewmap" );
79 return tr(
"Overview Map");
84 return tr(
"&Overview Map");
89 return QString(
"overviewmap" );
99 return tr(
"This is a float item that provides an overview map.");
109 return QList<PluginAuthor>()
115 return QIcon(
":/icons/worldmap.png");
120 if ( !m_configDialog ) {
122 m_configDialog =
new QDialog();
123 ui_configWidget =
new Ui::OverviewMapConfigWidget;
124 ui_configWidget->setupUi( m_configDialog );
125 for(
int i = 0; i < m_planetID.size(); ++i ) {
126 ui_configWidget->m_planetComboBox->addItem(
Planet::name(m_planetID.value( i ) ) );
128 ui_configWidget->m_planetComboBox->setCurrentIndex( 2 );
130 loadMapSuggestions();
131 connect( ui_configWidget->m_buttonBox, SIGNAL(accepted()),
133 connect( ui_configWidget->m_buttonBox, SIGNAL(rejected()),
135 connect( ui_configWidget->m_buttonBox->button( QDialogButtonBox::Reset ), SIGNAL(clicked()),
137 QPushButton *applyButton = ui_configWidget->m_buttonBox->button( QDialogButtonBox::Apply );
138 connect( applyButton, SIGNAL(clicked()),
140 connect( ui_configWidget->m_fileChooserButton, SIGNAL(clicked()),
141 SLOT(chooseCustomMap()) );
142 connect( ui_configWidget->m_widthBox, SIGNAL(valueChanged(
int)),
143 SLOT(synchronizeSpinboxes()) );
144 connect( ui_configWidget->m_heightBox, SIGNAL(valueChanged(
int)),
145 SLOT(synchronizeSpinboxes()) );
146 connect( ui_configWidget->m_planetComboBox, SIGNAL(currentIndexChanged(
int)),
147 SLOT(showCurrentPlanetPreview()) );
148 connect( ui_configWidget->m_colorChooserButton, SIGNAL(clicked()),
149 SLOT(choosePositionIndicatorColor()) );
150 connect( ui_configWidget->m_tableWidget, SIGNAL(cellClicked(
int,
int)),
151 SLOT(useMapSuggestion(
int)) );
153 return m_configDialog;
172 if ( target != m_target ) {
173 changeBackground( target );
178 if ( !( m_latLonAltBox == latLonAltBox
179 && m_centerLon == centerLon
180 && m_centerLat == centerLat ) )
182 m_latLonAltBox = latLonAltBox;
183 m_centerLon = centerLon;
184 m_centerLat = centerLat;
195 if ( m_svgobj.isValid() ) {
197 if ( m_worldmap.size() != mapRect.size().toSize() || m_mapChanged ) {
198 m_mapChanged =
false;
199 m_worldmap = QPixmap( mapRect.size().toSize() );
200 m_worldmap.fill( Qt::transparent );
202 mapPainter.begin( &m_worldmap );
203 mapPainter.setViewport( m_worldmap.rect() );
204 m_svgobj.render( &mapPainter );
208 painter->drawPixmap( QPoint( 0, 0 ), m_worldmap );
211 painter->setPen( QPen( Qt::DashLine ) );
212 painter->drawRect( QRectF( QPoint( 0, 0 ), mapRect.size().toSize() ) );
214 for (
int y = 1; y < 4; ++y ) {
216 painter->setPen( QPen( Qt::DashLine ) );
219 painter->setPen( QPen( Qt::DotLine ) );
222 painter->drawLine( 0.0, 0.25 * y * mapRect.height(),
223 mapRect.width(), 0.25 * y * mapRect.height() );
225 for (
int x = 1; x < 8; ++x ) {
227 painter->setPen( QPen( Qt::DashLine ) );
230 painter->setPen( QPen( Qt::DotLine ) );
233 painter->drawLine( 0.125 * x * mapRect.width(), 0,
234 0.125 * x * mapRect.width(), mapRect.height() );
239 qreal xWest = mapRect.width() / 2.0
240 + mapRect.width() / ( 2.0 *
M_PI ) * m_latLonAltBox.
west();
241 qreal xEast = mapRect.width() / 2.0
242 + mapRect.width() / ( 2.0 *
M_PI ) * m_latLonAltBox.
east();
243 qreal xNorth = mapRect.height() / 2.0
244 - mapRect.height() /
M_PI * m_latLonAltBox.
north();
245 qreal xSouth = mapRect.height() / 2.0
246 - mapRect.height() /
M_PI * m_latLonAltBox.
south();
248 qreal lon = m_centerLon;
249 qreal lat = m_centerLat;
251 qreal x = mapRect.width() / 2.0 + mapRect.width() / ( 2.0 *
M_PI ) * lon;
252 qreal y = mapRect.height() / 2.0 - mapRect.height() /
M_PI * lat;
254 painter->setPen( QPen( Qt::white ) );
255 painter->setBrush( QBrush( Qt::transparent ) );
256 painter->setRenderHint( QPainter::Antialiasing,
false );
258 qreal boxWidth = xEast - xWest;
259 qreal boxHeight = xSouth - xNorth;
261 qreal minBoxSize = 2.0;
262 if ( boxHeight < minBoxSize ) boxHeight = minBoxSize;
264 if ( m_latLonAltBox.
west() <= m_latLonAltBox.
east() ) {
266 if ( boxWidth < minBoxSize ) boxWidth = minBoxSize;
268 painter->drawRect( QRectF( xWest, xNorth, boxWidth, boxHeight ) );
277 if ( boxWidth < minBoxSize ) boxWidth = minBoxSize;
279 painter->drawRect( QRectF( 0, xNorth, boxWidth, boxHeight ) );
281 boxWidth = mapRect.width() - xWest;
284 if ( boxWidth < minBoxSize ) boxWidth = minBoxSize;
286 painter->drawRect( QRectF( xWest, xNorth, boxWidth, boxHeight ) );
289 painter->setPen( QPen( m_posColor ) );
290 painter->setBrush( QBrush( m_posColor ) );
292 qreal circleRadius = 2.5;
293 painter->setRenderHint( QPainter::Antialiasing,
true );
294 painter->drawEllipse( QRectF( x - circleRadius, y - circleRadius , 2 * circleRadius, 2 * circleRadius ) );
303 foreach (
const QString &key, m_settings.keys() ) {
304 result.insert( key, m_settings[key] );
314 m_settings.insert(
"width", settings.value(
"width", m_defaultSize.toSize().width() ) );
315 m_settings.insert(
"height", settings.value(
"height", m_defaultSize.toSize().height() ) );
318 QString mapFile =
MarbleDirs::path( QString(
"svg/%1map.svg" ).arg( planet ) );
320 if ( planet ==
"moon" ) {
323 else if ( planet ==
"earth" || mapFile.isEmpty() ) {
327 m_settings.insert(
"path_" + planet, settings.value(
"path_" + planet, mapFile ) );
330 m_settings.insert(
"posColor", settings.value(
"posColor", QColor( Qt::white ).
name() ) );
340 if ( !m_configDialog ) {
344 ui_configWidget->m_widthBox->setValue( m_settings.value(
"width" ).toInt() );
345 ui_configWidget->m_heightBox->setValue( m_settings.value(
"height" ).toInt() );
346 QPalette palette = ui_configWidget->m_colorChooserButton->palette();
347 palette.setColor( QPalette::Button, QColor( m_settings.value(
"posColor" ).toString() ) );
348 ui_configWidget->m_colorChooserButton->setPalette( palette );
353 if ( !m_configDialog ) {
357 m_settings.insert(
"width",
contentRect().width() );
358 m_settings.insert(
"height",
contentRect().height() );
361 foreach(
const QString &planet, planets ) {
362 m_settings.insert(
"path_" + planet, m_svgPaths[planet] );
365 m_settings.insert(
"posColor", m_posColor.name() );
373 foreach(
const QString &planet, planets ) {
374 m_svgPaths.insert( planet, m_settings.value(
"path_" + planet, QString() ).toString() );
377 m_posColor = QColor( m_settings.value(
"posColor" ).toString() );
380 if ( !m_configDialog ) {
384 setCurrentWidget( m_svgWidgets[m_planetID[2]] );
385 showCurrentPlanetPreview();
386 setContentSize( QSizeF( ui_configWidget->m_widthBox->value(), ui_configWidget->m_heightBox->value() ) );
400 bool cursorAboveFloatItem(
false);
401 if ( e->type() == QEvent::MouseButtonDblClick || e->type() == QEvent::MouseMove ) {
402 QMouseEvent *
event =
static_cast<QMouseEvent*
>(e);
405 if ( floatItemRect.contains(event->pos()) ) {
406 cursorAboveFloatItem =
true;
409 if ( e->type() == QEvent::MouseButtonDblClick ) {
411 QPointF pos =
event->pos() - floatItemRect.topLeft()
414 qreal lon = ( pos.x() - mapRect.width() / 2.0 ) / mapRect.width() * 360.0 ;
415 qreal lat = ( mapRect.height() / 2.0 - pos.y() ) / mapRect.height() * 180.0;
422 if ( cursorAboveFloatItem && e->type() == QEvent::MouseMove
423 && !
event->buttons() & Qt::LeftButton )
426 widget->setCursor(QCursor(Qt::CrossCursor));
434 void OverviewMap::changeBackground(
const QString& target )
436 m_svgobj.load( m_svgPaths[target] );
440 QSvgWidget *OverviewMap::currentWidget()
const
442 return m_svgWidgets[m_planetID[ui_configWidget->m_planetComboBox->currentIndex()]];
445 void OverviewMap::setCurrentWidget( QSvgWidget *widget )
447 m_svgWidgets[m_planetID[ui_configWidget->m_planetComboBox->currentIndex()]] = widget;
448 if( m_target == m_planetID[ui_configWidget->m_planetComboBox->currentIndex()] ) {
449 changeBackground( m_target );
453 void OverviewMap::loadPlanetMaps()
455 foreach(
const QString& planet, m_planetID ) {
456 if ( m_svgWidgets.contains( planet) ) {
457 m_svgWidgets[planet]->load( m_svgPaths[planet] );
459 m_svgWidgets[planet] =
new QSvgWidget( m_svgPaths[planet] );
464 void OverviewMap::loadMapSuggestions()
466 QStringList paths = QDir(
MarbleDirs::pluginPath(
"" ) ).entryList( QStringList(
"*.svg" ), QDir::Files | QDir::NoDotAndDotDot );
467 for(
int i = 0; i < paths.size(); ++i ) {
471 ui_configWidget->m_tableWidget->setRowCount( paths.size() );
472 for(
int i = 0; i < paths.size(); ++i ) {
473 ui_configWidget->m_tableWidget->setCellWidget( i, 0,
new QSvgWidget( paths[i] ) );
474 ui_configWidget->m_tableWidget->setItem( i, 1,
new QTableWidgetItem( paths[i] ) );
478 void OverviewMap::chooseCustomMap()
480 QString path = QFileDialog::getOpenFileName ( m_configDialog, tr(
"Choose Overview Map" ),
"",
"SVG (*.svg)" );
483 ui_configWidget->m_fileChooserButton->layout()->removeWidget( currentWidget() );
484 delete currentWidget();
485 QSvgWidget *widget =
new QSvgWidget( path );
486 setCurrentWidget( widget );
487 ui_configWidget->m_fileChooserButton->layout()->addWidget( widget );
488 m_svgPaths[m_planetID[ui_configWidget->m_planetComboBox->currentIndex()]] = path;
492 void OverviewMap::synchronizeSpinboxes()
494 if( sender() == ui_configWidget->m_widthBox ) {
495 ui_configWidget->m_heightBox->setValue( ui_configWidget->m_widthBox->value() / 2 );
497 else if( sender() == ui_configWidget->m_heightBox ) {
498 ui_configWidget->m_widthBox->setValue( ui_configWidget->m_heightBox->value() * 2 );
502 void OverviewMap::showCurrentPlanetPreview()
const
504 delete ui_configWidget->m_fileChooserButton->layout();
505 ui_configWidget->m_fileChooserButton->setLayout(
new QHBoxLayout() );
506 ui_configWidget->m_fileChooserButton->layout()->addWidget( currentWidget() );
509 void OverviewMap::choosePositionIndicatorColor()
511 QColor c = QColorDialog::getColor( m_posColor, 0,
512 tr(
"Please choose the color for the position indicator" ),
513 QColorDialog::ShowAlphaChannel );
517 QPalette palette = ui_configWidget->m_colorChooserButton->palette();
518 palette.setColor( QPalette::Button, m_posColor );
519 ui_configWidget->m_colorChooserButton->setPalette( palette );
523 void OverviewMap::useMapSuggestion(
int index )
525 QString path = ui_configWidget->m_tableWidget->item( index, 1 )->text();
526 m_svgPaths[m_planetID[ui_configWidget->m_planetComboBox->currentIndex()]] = path;
527 delete currentWidget();
528 QSvgWidget *widget =
new QSvgWidget( path );
529 setCurrentWidget( widget );
530 showCurrentPlanetPreview();
537 #include "OverviewMap.moc"
virtual QHash< QString, QVariant > settings() const
Settings of the plugin.
GeoDataLatLonAltBox latLonAltBox(const QRect &screenRect) const
static QString pluginPath(const QString &relativePath)
bool visible() const
Check visibility of the float item.
static QString path(const QString &relativePath)
QList< PluginAuthor > pluginAuthors() const
QStringList backendTypes() const
Returns the name(s) of the backend that the plugin can render This method should return the name of t...
QString copyrightYears() const
This file contains the headers for MarbleModel.
QString guiString() const
String that should be displayed in GUI.
void changeViewport(ViewportParams *viewport)
virtual bool eventFilter(QObject *object, QEvent *e)
virtual void setSettings(const QHash< QString, QVariant > &settings)
Set the settings of the plugin.
void restoreDefaultSettings()
Passes an empty set of settings to the plugin.
QSizeF size() const
Returns the size of the item.
QString nameId() const
Returns the unique name of the plugin.
void paintContent(QPainter *painter)
Here the items paint their content.
static QStringList planetList()
qreal north(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the northern boundary of the bounding box.
qreal east(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the eastern boundary of the bounding box.
void settingsChanged(QString nameId)
This signal is emitted if the settings of the RenderPlugin changed.
The abstract class for float item plugins.
QRectF contentRect() const
Returns the rect of the content in item coordinates.
virtual void setSettings(const QHash< QString, QVariant > &settings)
Set the settings of the item.
QString description() const
Returns a user description of the plugin.
static void normalizeLonLat(qreal &lon, qreal &lat, GeoDataCoordinates::Unit=GeoDataCoordinates::Radian)
normalize both longitude and latitude at the same time This method normalizes both latitude and longi...
qreal padding() const
Returns the padding of the item.
A public class that controls what is visible in the viewport of a Marble map.
virtual QHash< QString, QVariant > settings() const
QPointF positivePosition() const
Return the positive position of the ScreenGraphicsItem.
#define Q_EXPORT_PLUGIN2(a, b)
QString name() const
Returns the user-visible name of the plugin.
bool isInitialized() const
This file contains the headers for ViewportParams.
bool eventFilter(QObject *object, QEvent *e)
qreal centerLatitude() const
qreal west(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the western boundary of the bounding box.
The data model (not based on QAbstractModel) for a MarbleWidget.
void setCacheMode(CacheMode mode)
Set the cache mode of the item.
qreal centerLongitude() const
The class that creates an overview map.
qreal south(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the southern boundary of the bounding box.
QDialog * configDialog()
Returns a pointer to the configuration dialog of the plugin.
void update()
Marks the item and all parent items as invalid.
QString name() const
The user visible name of the planet.
bool enabled() const
is enabled
const MarbleModel * marbleModel() const
Access to the MarbleModel.
void setContentSize(const QSizeF &size)
Sets the size of the content of the item.
A class that defines a 3D bounding box for geographic data.
QIcon icon() const
Returns an icon for the plugin.