|
| 1 | +/*************************************************************************** |
| 2 | + qgsdecorationgriddialog.cpp |
| 3 | + ---------------------- |
| 4 | + begin : May 10, 2012 |
| 5 | + copyright : (C) 2012 by Etienne Tourigny |
| 6 | + email : etourigny.dev at gmail dot com |
| 7 | +
|
| 8 | + ***************************************************************************/ |
| 9 | +/*************************************************************************** |
| 10 | + * * |
| 11 | + * This program is free software; you can redistribute it and/or modify * |
| 12 | + * it under the terms of the GNU General Public License as published by * |
| 13 | + * the Free Software Foundation; either version 2 of the License, or * |
| 14 | + * (at your option) any later version. * |
| 15 | + * * |
| 16 | + ***************************************************************************/ |
| 17 | + |
| 18 | +#include "qgsdecorationgriddialog.h" |
| 19 | + |
| 20 | +#include "qgsdecorationgrid.h" |
| 21 | + |
| 22 | +#include "qgslogger.h" |
| 23 | +#include "qgscontexthelp.h" |
| 24 | +#include "qgsstylev2.h" |
| 25 | +#include "qgssymbolv2.h" |
| 26 | +#include "qgssymbolv2selectordialog.h" |
| 27 | +#include "qgssymbolv2propertiesdialog.h" |
| 28 | + |
| 29 | +#include <QFontDialog> |
| 30 | +#include <QColorDialog> |
| 31 | +#include <QSettings> |
| 32 | + |
| 33 | +QgsDecorationGridDialog::QgsDecorationGridDialog( QgsDecorationGrid& deco, QWidget* parent ) |
| 34 | + : QDialog( parent ), mDeco( deco ), mLineSymbol( 0 ), mMarkerSymbol( 0 ) |
| 35 | +{ |
| 36 | + setupUi( this ); |
| 37 | + |
| 38 | + QSettings settings; |
| 39 | + restoreGeometry( settings.value( "/Windows/DecorationGrid/geometry" ).toByteArray() ); |
| 40 | + |
| 41 | + chkEnable->setChecked( mDeco.enabled() ); |
| 42 | + |
| 43 | + // mXMinLineEdit->setValidator( new QDoubleValidator( mXMinLineEdit ) ); |
| 44 | + |
| 45 | + mGridTypeComboBox->insertItem( 0, tr( "Solid" ) ); |
| 46 | + mGridTypeComboBox->insertItem( 1, tr( "Cross" ) ); |
| 47 | + mGridTypeComboBox->insertItem( 2, tr( "Marker" ) ); |
| 48 | + |
| 49 | + mAnnotationPositionComboBox->insertItem( 0, tr( "Inside frame" ) ); |
| 50 | + // mAnnotationPositionComboBox->insertItem( 1, tr( "Outside frame" ) ); |
| 51 | + |
| 52 | + mAnnotationDirectionComboBox->insertItem( 0, tr( "Horizontal" ) ); |
| 53 | + mAnnotationDirectionComboBox->insertItem( 1, tr( "Vertical" ) ); |
| 54 | + mAnnotationDirectionComboBox->insertItem( 2, tr( "Horizontal and Vertical" ) ); |
| 55 | + mAnnotationDirectionComboBox->insertItem( 2, tr( "Boundary direction" ) ); |
| 56 | + |
| 57 | + updateGuiElements(); |
| 58 | + |
| 59 | + connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) ); |
| 60 | + |
| 61 | +} |
| 62 | + |
| 63 | +void QgsDecorationGridDialog::updateGuiElements() |
| 64 | +{ |
| 65 | + // blockAllSignals( true ); |
| 66 | + |
| 67 | + chkEnable->setChecked( mDeco.enabled() ); |
| 68 | + |
| 69 | + mIntervalXSpinBox->setValue( mDeco.gridIntervalX() ); |
| 70 | + mIntervalYSpinBox->setValue( mDeco.gridIntervalY() ); |
| 71 | + mOffsetXSpinBox->setValue( mDeco.gridOffsetX() ); |
| 72 | + mOffsetYSpinBox->setValue( mDeco.gridOffsetY() ); |
| 73 | + |
| 74 | + QgsDecorationGrid::GridStyle gridStyle = mDeco.gridStyle(); |
| 75 | + if ( gridStyle == QgsDecorationGrid::Cross ) |
| 76 | + { |
| 77 | + mGridTypeComboBox->setCurrentIndex( mGridTypeComboBox->findText( tr( "Cross" ) ) ); |
| 78 | + } |
| 79 | + else if ( gridStyle == QgsDecorationGrid::Marker ) |
| 80 | + { |
| 81 | + mGridTypeComboBox->setCurrentIndex( mGridTypeComboBox->findText( tr( "Marker" ) ) ); |
| 82 | + } |
| 83 | + else |
| 84 | + { |
| 85 | + mGridTypeComboBox->setCurrentIndex( mGridTypeComboBox->findText( tr( "Solid" ) ) ); |
| 86 | + } |
| 87 | + |
| 88 | + mCrossWidthSpinBox->setValue( mDeco.crossLength() ); |
| 89 | + |
| 90 | + QgsDecorationGrid::GridAnnotationPosition annotationPos = mDeco.gridAnnotationPosition(); |
| 91 | + if ( annotationPos == QgsDecorationGrid::InsideMapFrame ) |
| 92 | + { |
| 93 | + mAnnotationPositionComboBox->setCurrentIndex( mAnnotationPositionComboBox->findText( tr( "Inside frame" ) ) ); |
| 94 | + } |
| 95 | + else |
| 96 | + { |
| 97 | + mAnnotationPositionComboBox->setCurrentIndex( mAnnotationPositionComboBox->findText( tr( "Outside frame" ) ) ); |
| 98 | + } |
| 99 | + |
| 100 | + mDrawAnnotationCheckBox->setChecked( mDeco.showGridAnnotation() ); |
| 101 | + |
| 102 | + QgsDecorationGrid::GridAnnotationDirection dir = mDeco.gridAnnotationDirection(); |
| 103 | + if ( dir == QgsDecorationGrid::Horizontal ) |
| 104 | + { |
| 105 | + mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Horizontal" ) ) ); |
| 106 | + } |
| 107 | + else if ( dir == QgsDecorationGrid::Vertical ) |
| 108 | + { |
| 109 | + mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Vertical" ) ) ); |
| 110 | + } |
| 111 | + else if ( dir == QgsDecorationGrid::HorizontalAndVertical ) |
| 112 | + { |
| 113 | + mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Horizontal and Vertical" ) ) ); |
| 114 | + } |
| 115 | + else //BoundaryDirection |
| 116 | + { |
| 117 | + mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Boundary direction" ) ) ); |
| 118 | + } |
| 119 | + |
| 120 | + mCoordinatePrecisionSpinBox->setValue( mDeco.gridAnnotationPrecision() ); |
| 121 | + |
| 122 | + // QPen gridPen = mDeco.gridPen(); |
| 123 | + // mLineWidthSpinBox->setValue( gridPen.widthF() ); |
| 124 | + // mLineColorButton->setColor( gridPen.color() ); |
| 125 | + |
| 126 | + if ( mLineSymbol ) |
| 127 | + delete mLineSymbol; |
| 128 | + if ( mDeco.lineSymbol() ) |
| 129 | + { |
| 130 | + mLineSymbol = dynamic_cast<QgsLineSymbolV2*>( mDeco.lineSymbol()->clone() ); |
| 131 | + QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( mLineSymbol, mLineSymbolButton->iconSize() ); |
| 132 | + mLineSymbolButton->setIcon( icon ); |
| 133 | + } |
| 134 | + |
| 135 | + if ( mMarkerSymbol ) |
| 136 | + delete mMarkerSymbol; |
| 137 | + if ( mDeco.markerSymbol() ) |
| 138 | + { |
| 139 | + mMarkerSymbol = dynamic_cast<QgsMarkerSymbolV2*>( mDeco.markerSymbol()->clone() ); |
| 140 | + QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( mMarkerSymbol, mMarkerSymbolButton->iconSize() ); |
| 141 | + mMarkerSymbolButton->setIcon( icon ); |
| 142 | + } |
| 143 | + |
| 144 | + // blockAllSignals( false ); |
| 145 | +} |
| 146 | + |
| 147 | +void QgsDecorationGridDialog::updateDecoFromGui() |
| 148 | +{ |
| 149 | + mDeco.setEnabled( chkEnable->isChecked() ); |
| 150 | + |
| 151 | + mDeco.setGridIntervalX( mIntervalXSpinBox->value() ); |
| 152 | + mDeco.setGridIntervalY( mIntervalYSpinBox->value() ); |
| 153 | + mDeco.setGridOffsetX( mOffsetXSpinBox->value() ); |
| 154 | + mDeco.setGridOffsetY( mOffsetYSpinBox->value() ); |
| 155 | + // mDeco.setGridPenWidth( mLineWidthSpinBox->value() ); |
| 156 | + if ( mGridTypeComboBox->currentText() == tr( "Cross" ) ) |
| 157 | + { |
| 158 | + mDeco.setGridStyle( QgsDecorationGrid::Cross ); |
| 159 | + } |
| 160 | + else if ( mGridTypeComboBox->currentText() == tr( "Marker" ) ) |
| 161 | + { |
| 162 | + mDeco.setGridStyle( QgsDecorationGrid::Marker ); |
| 163 | + } |
| 164 | + else |
| 165 | + { |
| 166 | + mDeco.setGridStyle( QgsDecorationGrid::Solid ); |
| 167 | + } |
| 168 | + mDeco.setCrossLength( mCrossWidthSpinBox->value() ); |
| 169 | + mDeco.setAnnotationFrameDistance( mDistanceToMapFrameSpinBox->value() ); |
| 170 | + if ( mAnnotationPositionComboBox->currentText() == tr( "Inside frame" ) ) |
| 171 | + { |
| 172 | + mDeco.setGridAnnotationPosition( QgsDecorationGrid::InsideMapFrame ); |
| 173 | + } |
| 174 | + else |
| 175 | + { |
| 176 | + mDeco.setGridAnnotationPosition( QgsDecorationGrid::OutsideMapFrame ); |
| 177 | + } |
| 178 | + mDeco.setShowGridAnnotation( mDrawAnnotationCheckBox->isChecked() ); |
| 179 | + QString text = mAnnotationDirectionComboBox->currentText(); |
| 180 | + if ( text == tr( "Horizontal" ) ) |
| 181 | + { |
| 182 | + mDeco.setGridAnnotationDirection( QgsDecorationGrid::Horizontal ); |
| 183 | + } |
| 184 | + else if ( text == tr( "Vertical" ) ) |
| 185 | + { |
| 186 | + mDeco.setGridAnnotationDirection( QgsDecorationGrid::Vertical ); |
| 187 | + } |
| 188 | + else if ( text == tr( "Horizontal and Vertical" ) ) |
| 189 | + { |
| 190 | + mDeco.setGridAnnotationDirection( QgsDecorationGrid::HorizontalAndVertical ); |
| 191 | + } |
| 192 | + else //BoundaryDirection |
| 193 | + { |
| 194 | + mDeco.setGridAnnotationDirection( QgsDecorationGrid::BoundaryDirection ); |
| 195 | + } |
| 196 | + mDeco.setGridAnnotationPrecision( mCoordinatePrecisionSpinBox->value() ); |
| 197 | + if ( mLineSymbol ) |
| 198 | + { |
| 199 | + mDeco.setLineSymbol( mLineSymbol ); |
| 200 | + mLineSymbol = dynamic_cast<QgsLineSymbolV2*>( mDeco.lineSymbol()->clone() ); |
| 201 | + } |
| 202 | + if ( mMarkerSymbol ) |
| 203 | + { |
| 204 | + mDeco.setMarkerSymbol( mMarkerSymbol ); |
| 205 | + mMarkerSymbol = dynamic_cast<QgsMarkerSymbolV2*>( mDeco.markerSymbol()->clone() ); |
| 206 | + } |
| 207 | +} |
| 208 | + |
| 209 | +QgsDecorationGridDialog::~QgsDecorationGridDialog() |
| 210 | +{ |
| 211 | + QSettings settings; |
| 212 | + settings.setValue( "/Windows/DecorationGrid/geometry", saveGeometry() ); |
| 213 | + if ( mLineSymbol ) |
| 214 | + delete mLineSymbol; |
| 215 | + if ( mMarkerSymbol ) |
| 216 | + delete mMarkerSymbol; |
| 217 | +} |
| 218 | + |
| 219 | +void QgsDecorationGridDialog::on_buttonBox_helpRequested() |
| 220 | +{ |
| 221 | + QgsContextHelp::run( metaObject()->className() ); |
| 222 | +} |
| 223 | + |
| 224 | +void QgsDecorationGridDialog::on_buttonBox_accepted() |
| 225 | +{ |
| 226 | + updateDecoFromGui(); |
| 227 | + // mDeco.update(); |
| 228 | + accept(); |
| 229 | +} |
| 230 | + |
| 231 | +void QgsDecorationGridDialog::apply() |
| 232 | +{ |
| 233 | + updateDecoFromGui(); |
| 234 | + mDeco.update(); |
| 235 | + //accept(); |
| 236 | +} |
| 237 | + |
| 238 | +void QgsDecorationGridDialog::on_buttonBox_rejected() |
| 239 | +{ |
| 240 | + reject(); |
| 241 | +} |
| 242 | + |
| 243 | + |
| 244 | +// void QgsDecorationGridDialog::on_mLineColorButton_clicked() |
| 245 | +// { |
| 246 | + // QColor newColor = QColorDialog::getColor( mLineColorButton->color() ); |
| 247 | + // if ( newColor.isValid() ) |
| 248 | + // { |
| 249 | + // mLineColorButton->setColor( newColor ); |
| 250 | + // mDeco.setGridPenColor( newColor ); |
| 251 | + // } |
| 252 | +// } |
| 253 | + |
| 254 | +void QgsDecorationGridDialog::on_mLineSymbolButton_clicked() |
| 255 | +{ |
| 256 | + if ( ! mLineSymbol ) |
| 257 | + return; |
| 258 | + |
| 259 | + QgsLineSymbolV2* lineSymbol = dynamic_cast<QgsLineSymbolV2*>( mLineSymbol->clone() ); |
| 260 | + QgsSymbolV2PropertiesDialog dlg( lineSymbol, 0, this ); |
| 261 | + if ( dlg.exec() == QDialog::Rejected ) |
| 262 | + { |
| 263 | + delete lineSymbol; |
| 264 | + } |
| 265 | + else |
| 266 | + { |
| 267 | + delete mLineSymbol; |
| 268 | + mLineSymbol = lineSymbol; |
| 269 | + if ( mLineSymbol ) |
| 270 | + { |
| 271 | + QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( mLineSymbol, mLineSymbolButton->iconSize() ); |
| 272 | + mLineSymbolButton->setIcon( icon ); |
| 273 | + } |
| 274 | + } |
| 275 | +} |
| 276 | + |
| 277 | +void QgsDecorationGridDialog::on_mMarkerSymbolButton_clicked() |
| 278 | +{ |
| 279 | + if ( ! mMarkerSymbol ) |
| 280 | + return; |
| 281 | + |
| 282 | + QgsMarkerSymbolV2* markerSymbol = dynamic_cast<QgsMarkerSymbolV2*>( mMarkerSymbol->clone() ); |
| 283 | + QgsSymbolV2PropertiesDialog dlg( markerSymbol, 0, this ); |
| 284 | + if ( dlg.exec() == QDialog::Rejected ) |
| 285 | + { |
| 286 | + delete markerSymbol; |
| 287 | + } |
| 288 | + else |
| 289 | + { |
| 290 | + delete mMarkerSymbol; |
| 291 | + mMarkerSymbol = markerSymbol; |
| 292 | + if ( mMarkerSymbol ) |
| 293 | + { |
| 294 | + QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( mMarkerSymbol, mMarkerSymbolButton->iconSize() ); |
| 295 | + mMarkerSymbolButton->setIcon( icon ); |
| 296 | + } |
| 297 | + } |
| 298 | +} |
| 299 | + |
| 300 | +void QgsDecorationGridDialog::on_mAnnotationFontButton_clicked() |
| 301 | +{ |
| 302 | + bool ok; |
| 303 | +#if defined(Q_WS_MAC) && QT_VERSION >= 0x040500 && defined(QT_MAC_USE_COCOA) |
| 304 | + // Native Mac dialog works only for Qt Carbon |
| 305 | + QFont newFont = QFontDialog::getFont( &ok, mDeco.gridAnnotationFont(), this, QString(), QFontDialog::DontUseNativeDialog ); |
| 306 | +#else |
| 307 | + QFont newFont = QFontDialog::getFont( &ok, mDeco.gridAnnotationFont() ); |
| 308 | +#endif |
| 309 | + if ( ok ) |
| 310 | + { |
| 311 | + mDeco.setGridAnnotationFont( newFont ); |
| 312 | + } |
| 313 | +} |
0 commit comments