24 #include <QColorDialog>
25 #include <QInputDialog>
28 #include <QTableWidget>
32 : QDialog( parent ), mRamp( ramp ), mCurrentItem( 0 )
36 setWindowModality( Qt::WindowModal );
39 btnColor1->setAllowAlpha(
true );
40 btnColor1->setColorDialogTitle(
tr(
"Select ramp color" ) );
41 btnColor1->setContext(
"symbology" );
42 btnColor1->setShowNoColor(
true );
43 btnColor1->setNoColorString(
tr(
"Transparent" ) );
44 btnColor2->setAllowAlpha(
true );
45 btnColor2->setColorDialogTitle(
tr(
"Select ramp color" ) );
46 btnColor2->setContext(
"symbology" );
47 btnColor2->setShowNoColor(
true );
48 btnColor2->setNoColorString(
tr(
"Transparent" ) );
49 connect( btnColor1, SIGNAL( colorChanged(
const QColor& ) ),
this, SLOT(
setColor1(
const QColor& ) ) );
50 connect( btnColor2, SIGNAL( colorChanged(
const QColor& ) ),
this, SLOT(
setColor2(
const QColor& ) ) );
54 connect( groupStops, SIGNAL( toggled(
bool ) ),
this, SLOT(
toggledStops(
bool ) ) );
55 connect( btnAddStop, SIGNAL( clicked() ),
this, SLOT(
addStop() ) );
56 connect( btnRemoveStop, SIGNAL( clicked() ),
this, SLOT(
removeStop() ) );
57 connect( treeStops, SIGNAL( itemDoubleClicked( QTreeWidgetItem*,
int ) ),
this, SLOT(
stopDoubleClicked( QTreeWidgetItem*,
int ) ) );
60 cboType->blockSignals(
true );
61 cboType->addItem(
tr(
"Discrete" ) );
62 cboType->addItem(
tr(
"Continuous" ) );
64 cboType->setCurrentIndex( 0 );
66 cboType->setCurrentIndex( 1 );
67 cboType->blockSignals(
false );
72 btnInformation->setEnabled(
false );
98 QTableWidget *tableInfo =
new QTableWidget( dlg );
99 tableInfo->verticalHeader()->hide();
100 tableInfo->horizontalHeader()->hide();
101 tableInfo->setRowCount(
mRamp->
info().count() );
102 tableInfo->setColumnCount( 2 );
104 for ( QgsStringMap::const_iterator it =
mRamp->
info().constBegin();
107 if ( it.key().startsWith(
"cpt-city" ) )
109 tableInfo->setItem( i, 0,
new QTableWidgetItem( it.key() ) );
110 tableInfo->setItem( i, 1,
new QTableWidgetItem( it.value() ) );
111 tableInfo->resizeRowToContents( i );
114 tableInfo->resizeColumnToContents( 0 );
115 tableInfo->horizontalHeader()->setStretchLastSection(
true );
116 tableInfo->setRowCount( i );
117 tableInfo->setFixedHeight( tableInfo->rowHeight( 0 ) * i + 5 );
118 dlg->
layout()->addWidget( tableInfo );
119 dlg->resize( 600, 250 );
121 dlg->
layout()->addSpacing( 5 );
124 QString gradientFile =
mRamp->
info().value(
"cpt-city-gradient" );
125 if ( ! gradientFile.isNull() )
127 QString fileName = gradientFile;
129 if ( ! QFile::exists( fileName ) )
131 fileName = gradientFile;
132 fileName.replace(
"<cpt-city>",
"http://soliton.vm.bytemark.co.uk/pub/cpt-city" );
134 label =
new QLabel(
tr(
"Gradient file : %1" ).arg( fileName ), dlg );
135 label->setTextInteractionFlags( Qt::TextBrowserInteraction );
136 dlg->
layout()->addSpacing( 5 );
137 dlg->
layout()->addWidget( label );
141 QString licenseFile =
mRamp->
info().value(
"cpt-city-license" );
142 if ( !licenseFile.isNull() )
144 QString fileName = licenseFile;
146 if ( ! QFile::exists( fileName ) )
148 fileName = licenseFile;
149 fileName.replace(
"<cpt-city>",
"http://soliton.vm.bytemark.co.uk/pub/cpt-city" );
151 label =
new QLabel(
tr(
"License file : %1" ).arg( fileName ), dlg );
152 label->setTextInteractionFlags( Qt::TextBrowserInteraction );
153 dlg->
layout()->addSpacing( 5 );
154 dlg->
layout()->addWidget( label );
155 if ( QFile::exists( fileName ) )
157 QTextEdit *textEdit =
new QTextEdit( dlg );
158 textEdit->setReadOnly(
true );
159 QFile
file( fileName );
160 if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) )
162 textEdit->setText( file.readAll() );
164 dlg->
layout()->addSpacing( 5 );
165 dlg->
layout()->addWidget( textEdit );
166 dlg->resize( 600, 500 );
177 groupStops->setChecked( !stops.isEmpty() );
179 QList<QTreeWidgetItem *> items;
180 for ( QgsGradientStopsList::iterator it = stops.begin();
181 it != stops.end(); ++it )
183 double val = it->offset * 100.0;
185 lst <<
"." << QString(( val < 10 ) ?
'0' + QString::number( val ) : QString::number( val ) );
186 QTreeWidgetItem* item =
new QTreeWidgetItem( lst );
191 items.append( item );
194 treeStops->insertTopLevelItems( 0, items );
195 treeStops->resizeColumnToContents( 0 );
196 treeStops->setColumnWidth( 0, treeStops->columnWidth( 0 ) + 20 );
197 treeStops->sortByColumn( 1, Qt::AscendingOrder );
198 treeStops->setSortingEnabled(
true );
205 if ( groupStops->isChecked() )
207 int count = treeStops->topLevelItemCount();
208 for (
int i = 0; i < count; i++ )
210 QTreeWidgetItem* item = treeStops->topLevelItem( i );
212 QColor color = item->data( 0,
StopColorRole ).value<QColor>();
219 QSize
size( 300, 40 );
222 btnColor1->blockSignals(
true );
224 btnColor1->blockSignals(
false );
225 btnColor2->blockSignals(
true );
227 btnColor2->blockSignals(
false );
244 QSize iconSize( 16, 16 );
245 QPixmap pixmap( iconSize );
246 pixmap.fill( QColor( 0, 0, 0, 0 ) );
247 QRect rect( 1, 1, iconSize.width() - 2, iconSize.height() - 2 );
252 p.setPen( Qt::NoPen );
253 p.setRenderHint( QPainter::Antialiasing );
255 p.drawRoundedRect( rect, 2, 2 );
258 item->setIcon( 0, QIcon( pixmap ) );
260 item->setText( 0, color.name() );
280 bool useNative = settings.value(
"/qgis/native_color_dialogs",
false ).toBool();
281 if ( settings.value(
"/qgis/live_color_dialogs",
false ).toBool() )
289 this,
tr(
"Edit Stop Color" ), QColorDialog::ShowAlphaChannel );
295 this,
tr(
"Edit Stop Color" ), true );
303 if ( !color.isValid() )
314 double val = key * 100;
315 val = QInputDialog::getDouble(
this,
tr(
"Offset of the stop" ),
316 tr(
"Please enter offset in percents (%) of the new stop" ),
317 val, 0, 100, 2, &ok );
321 double newkey = val / 100.0;
322 item->setText( 1, ( val < 10 ) ?
'0' + QString::number( val ) : QString::number( val ) );
340 if ( !color.isValid() )
347 val = QInputDialog::getDouble(
this,
tr(
"Offset of the stop" ),
348 tr(
"Please enter offset in percents (%) of the new stop" ),
349 val, 0, 100, 2, &ok );
354 double key = val / 100.0;
356 lst <<
"." << QString(( val < 10 ) ?
'0' + QString::number( val ) : QString::number( val ) );
361 if ( !color.isValid() )
366 QTreeWidgetItem* item =
new QTreeWidgetItem( lst );
371 treeStops->addTopLevelItem( item );
373 treeStops->resizeColumnToContents( 0 );
374 treeStops->setColumnWidth( 0, treeStops->columnWidth( 0 ) + 20 );
381 QTreeWidgetItem* item = treeStops->currentItem();
384 int index = treeStops->indexOfTopLevelItem( item );
385 treeStops->takeTopLevelItem( index );