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 );
105 for ( QgsStringMap::const_iterator it = rampInfo.constBegin();
106 it != rampInfo.constEnd(); ++it )
108 if ( it.key().startsWith(
"cpt-city" ) )
110 tableInfo->setItem( i, 0,
new QTableWidgetItem( it.key() ) );
111 tableInfo->setItem( i, 1,
new QTableWidgetItem( it.value() ) );
112 tableInfo->resizeRowToContents( i );
115 tableInfo->resizeColumnToContents( 0 );
116 tableInfo->horizontalHeader()->setStretchLastSection(
true );
117 tableInfo->setRowCount( i );
118 tableInfo->setFixedHeight( tableInfo->rowHeight( 0 ) * i + 5 );
119 dlg->
layout()->addWidget( tableInfo );
120 dlg->resize( 600, 250 );
122 dlg->
layout()->addSpacing( 5 );
125 QString gradientFile =
mRamp->
info().value(
"cpt-city-gradient" );
126 if ( ! gradientFile.isNull() )
128 QString fileName = gradientFile;
130 if ( ! QFile::exists( fileName ) )
132 fileName = gradientFile;
133 fileName.replace(
"<cpt-city>",
"http://soliton.vm.bytemark.co.uk/pub/cpt-city" );
135 label =
new QLabel(
tr(
"Gradient file : %1" ).arg( fileName ), dlg );
136 label->setTextInteractionFlags( Qt::TextBrowserInteraction );
137 dlg->
layout()->addSpacing( 5 );
138 dlg->
layout()->addWidget( label );
142 QString licenseFile =
mRamp->
info().value(
"cpt-city-license" );
143 if ( !licenseFile.isNull() )
145 QString fileName = licenseFile;
147 if ( ! QFile::exists( fileName ) )
149 fileName = licenseFile;
150 fileName.replace(
"<cpt-city>",
"http://soliton.vm.bytemark.co.uk/pub/cpt-city" );
152 label =
new QLabel(
tr(
"License file : %1" ).arg( fileName ), dlg );
153 label->setTextInteractionFlags( Qt::TextBrowserInteraction );
154 dlg->
layout()->addSpacing( 5 );
155 dlg->
layout()->addWidget( label );
156 if ( QFile::exists( fileName ) )
158 QTextEdit *textEdit =
new QTextEdit( dlg );
159 textEdit->setReadOnly(
true );
160 QFile file( fileName );
161 if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) )
163 textEdit->setText( file.readAll() );
165 dlg->
layout()->addSpacing( 5 );
166 dlg->
layout()->addWidget( textEdit );
167 dlg->resize( 600, 500 );
178 groupStops->setChecked( !stops.isEmpty() );
180 QList<QTreeWidgetItem *> items;
181 for ( QgsGradientStopsList::iterator it = stops.begin();
182 it != stops.end(); ++it )
184 double val = it->offset * 100.0;
186 lst <<
"." << QString(( val < 10 ) ?
'0' + QString::number( val ) : QString::number( val ) );
187 QTreeWidgetItem* item =
new QTreeWidgetItem( lst );
192 items.append( item );
195 treeStops->insertTopLevelItems( 0, items );
196 treeStops->resizeColumnToContents( 0 );
197 treeStops->setColumnWidth( 0, treeStops->columnWidth( 0 ) + 20 );
198 treeStops->sortByColumn( 1, Qt::AscendingOrder );
199 treeStops->setSortingEnabled(
true );
206 if ( groupStops->isChecked() )
208 int count = treeStops->topLevelItemCount();
209 for (
int i = 0; i < count; i++ )
211 QTreeWidgetItem* item = treeStops->topLevelItem( i );
213 QColor color = item->data( 0,
StopColorRole ).value<QColor>();
220 QSize size( 300, 40 );
223 btnColor1->blockSignals(
true );
225 btnColor1->blockSignals(
false );
226 btnColor2->blockSignals(
true );
228 btnColor2->blockSignals(
false );
245 QSize iconSize( 16, 16 );
246 QPixmap pixmap( iconSize );
247 pixmap.fill( QColor( 0, 0, 0, 0 ) );
248 QRect rect( 1, 1, iconSize.width() - 2, iconSize.height() - 2 );
253 p.setPen( Qt::NoPen );
254 p.setRenderHint( QPainter::Antialiasing );
256 p.drawRoundedRect( rect, 2, 2 );
259 item->setIcon( 0, QIcon( pixmap ) );
261 item->setText( 0, color.name() );
281 bool useNative = settings.value(
"/qgis/native_color_dialogs",
false ).toBool();
282 if ( settings.value(
"/qgis/live_color_dialogs",
false ).toBool() )
290 this,
tr(
"Edit Stop Color" ), QColorDialog::ShowAlphaChannel );
296 this,
tr(
"Edit Stop Color" ), true );
304 if ( !color.isValid() )
315 double val = key * 100;
316 val = QInputDialog::getDouble(
this,
tr(
"Offset of the stop" ),
317 tr(
"Please enter offset in percents (%) of the new stop" ),
318 val, 0, 100, 2, &ok );
322 double newkey = val / 100.0;
323 item->setText( 1, ( val < 10 ) ?
'0' + QString::number( val ) : QString::number( val ) );
341 if ( !color.isValid() )
348 val = QInputDialog::getDouble(
this,
tr(
"Offset of the stop" ),
349 tr(
"Please enter offset in percents (%) of the new stop" ),
350 val, 0, 100, 2, &ok );
355 double key = val / 100.0;
357 lst <<
"." << QString(( val < 10 ) ?
'0' + QString::number( val ) : QString::number( val ) );
362 if ( !color.isValid() )
367 QTreeWidgetItem* item =
new QTreeWidgetItem( lst );
372 treeStops->addTopLevelItem( item );
374 treeStops->resizeColumnToContents( 0 );
375 treeStops->setColumnWidth( 0, treeStops->columnWidth( 0 ) + 20 );
382 QTreeWidgetItem* item = treeStops->currentItem();
385 int index = treeStops->indexOfTopLevelItem( item );
386 treeStops->takeTopLevelItem( index );
static QPixmap colorRampPreviewPixmap(QgsVectorColorRampV2 *ramp, QSize size)
void setStopColor(QTreeWidgetItem *item, QColor color)
static QString defaultBaseDir()
void on_btnInformation_pressed()
QTreeWidgetItem * mCurrentItem
A generic dialog with layout and button box.
void setColor2(const QColor &color)
QMap< QString, QString > QgsStringMap
QgsStringMap info() const
void toggledStops(bool on)
void setStops(const QgsGradientStopsList &stops)
void setItemStopColor(const QColor &newColor)
void setColor1(QColor color)
QgsVectorGradientColorRampV2 * mRamp
void convertToDiscrete(bool discrete)
void setColor2(QColor color)
QList< QgsGradientStop > QgsGradientStopsList
static QColor getColor(const QColor &initialColor, QWidget *parent, const QString &title=QString(), const bool allowAlpha=false)
Return a color selection from a color dialog.
const QgsGradientStopsList & stops() const
static const int StopOffsetRole
QgsVectorGradientColorRampV2Dialog(QgsVectorGradientColorRampV2 *ramp, QWidget *parent=NULL)
QVBoxLayout * layout()
Returns the central layout. Widgets added to it must have this dialog as parent.
static QColor getLiveColor(const QColor &initialColor, QObject *updateObject, const char *updateSlot, QWidget *parent=0, const QString &title=QString(), const bool allowAlpha=true)
Return a color selection from a color dialog, with live updating of interim selections.
void on_cboType_currentIndexChanged(int index)
static QColor getLiveColor(const QColor &initialColor, QObject *updateObject, const char *updateSlot, QWidget *parent=0, const QString &title="", QColorDialog::ColorDialogOptions options=0)
Return a color selection from a QColorDialog, with live updating of interim selections.
void setColor1(const QColor &color)
void stopDoubleClicked(QTreeWidgetItem *item, int column)
static const int StopColorRole