Skip to content
Permalink
Browse files

- slight redesign of symbol selector dialog

- created a new (experimental) class QgsColorButtonV2
- made all widgets in symbology-ng to use QgsColorButtonV2


git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@12135 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Nov 16, 2009
1 parent 15c7901 commit 94c5bc2f661e5a18325b0661650eab4288f93554
@@ -66,3 +66,33 @@ void QgsColorButton::setColor( const QColor &color )
mColor = color;
update();
}


//////////////////

QgsColorButtonV2::QgsColorButtonV2( QWidget* parent )
: QPushButton(parent)
{
}

void QgsColorButtonV2::setColor( const QColor &color )
{
mColor = color;

QPixmap pixmap(iconSize());
pixmap.fill(QColor(0,0,0,0));

QRect rect(1,1, iconSize().width() - 2, iconSize().height() - 2);

// draw a slightly rounded rectangle
QPainter p;
p.begin(&pixmap);
p.setPen(Qt::NoPen);
p.setRenderHint(QPainter::Antialiasing);
p.setBrush(color);
p.drawRoundedRect(rect, 4, 4);
p.end();

// set this pixmap as icon
setIcon(QIcon(pixmap));
}
@@ -17,6 +17,7 @@
#define QGSCOLORBUTTON_H

#include <QToolButton>
#include <QPushButton>

/** \ingroup gui
* A cross platform button subclass for selecting colors.
@@ -37,4 +38,18 @@ class GUI_EXPORT QgsColorButton: public QToolButton
QColor mColor;
};


class QgsColorButtonV2 : public QPushButton
{
public:
QgsColorButtonV2( QWidget* parent = 0 );

void setColor( const QColor &color );
QColor color() const { return mColor; }

private:
QColor mColor;
};


#endif
@@ -27,6 +27,7 @@ QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog(QgsVectorLayer* lay
if (embedded)
{
buttonBox->hide();
layout()->setContentsMargins(0,0,0,0);
}

connect(buttonBox, SIGNAL(accepted()), this, SLOT(onOK()));
@@ -16,14 +16,7 @@
#include <QStandardItemModel>
#include <QSvgRenderer>

static void updateColorButton(QAbstractButton* button, QColor color)
{
QPixmap p(20,20);
p.fill(color);
button->setIcon(QIcon(p));
}

//////////

QgsSimpleLineSymbolLayerV2Widget::QgsSimpleLineSymbolLayerV2Widget(QWidget* parent)
: QgsSymbolLayerV2Widget(parent)
@@ -51,7 +44,7 @@ void QgsSimpleLineSymbolLayerV2Widget::setSymbolLayer(QgsSymbolLayerV2* layer)

// set values
spinWidth->setValue(mLayer->width());
updateColorButton(btnChangeColor, mLayer->color());
btnChangeColor->setColor(mLayer->color());
cboPenStyle->setPenStyle(mLayer->penStyle());
spinOffset->setValue(mLayer->offset());
cboJoinStyle->setPenJoinStyle(mLayer->penJoinStyle());
@@ -75,7 +68,7 @@ void QgsSimpleLineSymbolLayerV2Widget::colorChanged()
if (!color.isValid())
return;
mLayer->setColor(color);
updateColorButton(btnChangeColor, mLayer->color());
btnChangeColor->setColor(mLayer->color());
emit changed();
}

@@ -145,8 +138,8 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setSymbolLayer(QgsSymbolLayerV2* layer)
break;
}
}
updateColorButton(btnChangeColorBorder, mLayer->borderColor());
updateColorButton(btnChangeColorFill, mLayer->color());
btnChangeColorBorder->setColor(mLayer->borderColor());
btnChangeColorFill->setColor(mLayer->color());
spinSize->setValue(mLayer->size());
spinAngle->setValue(mLayer->angle());

@@ -176,7 +169,7 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setColorBorder()
if (!borderColor.isValid())
return;
mLayer->setBorderColor(borderColor);
updateColorButton(btnChangeColorBorder, mLayer->borderColor());
btnChangeColorBorder->setColor(mLayer->borderColor());
emit changed();
}

@@ -186,7 +179,7 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setColorFill()
if (!color.isValid())
return;
mLayer->setColor(color);
updateColorButton(btnChangeColorFill, mLayer->color());
btnChangeColorFill->setColor(mLayer->color());
emit changed();
}

@@ -232,8 +225,8 @@ void QgsSimpleFillSymbolLayerV2Widget::setSymbolLayer(QgsSymbolLayerV2* layer)
mLayer = static_cast<QgsSimpleFillSymbolLayerV2*>(layer);

// set values
updateColorButton(btnChangeColor, mLayer->color());
updateColorButton(btnChangeBorderColor, mLayer->borderColor());
btnChangeColor->setColor(mLayer->color());
btnChangeBorderColor->setColor(mLayer->borderColor());
cboFillStyle->setBrushStyle(mLayer->brushStyle());
}

@@ -248,7 +241,7 @@ void QgsSimpleFillSymbolLayerV2Widget::setColor()
if (!color.isValid())
return;
mLayer->setColor(color);
updateColorButton(btnChangeColor, mLayer->color());
btnChangeColor->setColor(mLayer->color());
emit changed();
}

@@ -258,7 +251,7 @@ void QgsSimpleFillSymbolLayerV2Widget::setBorderColor()
if (!color.isValid())
return;
mLayer->setBorderColor(color);
updateColorButton(btnChangeBorderColor, mLayer->borderColor());
btnChangeBorderColor->setColor(mLayer->borderColor());
emit changed();
}

@@ -482,7 +475,7 @@ void QgsLineDecorationSymbolLayerV2Widget::setSymbolLayer(QgsSymbolLayerV2* laye
mLayer = static_cast<QgsLineDecorationSymbolLayerV2*>(layer);

// set values
updateColorButton(btnChangeColor, mLayer->color());
btnChangeColor->setColor(mLayer->color());
}

QgsSymbolLayerV2* QgsLineDecorationSymbolLayerV2Widget::symbolLayer()
@@ -496,6 +489,6 @@ void QgsLineDecorationSymbolLayerV2Widget::colorChanged()
if (!color.isValid())
return;
mLayer->setColor(color);
updateColorButton(btnChangeColor, mLayer->color());
btnChangeColor->setColor(mLayer->color());
emit changed();
}
@@ -27,6 +27,7 @@ QgsSymbolV2SelectorDialog::QgsSymbolV2SelectorDialog(QgsSymbolV2* symbol, QgsSty
if (embedded)
{
buttonBox->hide();
layout()->setContentsMargins(0,0,0,0);
}

connect(btnSymbolProperties, SIGNAL(clicked()), this, SLOT(changeSymbolProperties()));
@@ -44,12 +45,15 @@ QgsSymbolV2SelectorDialog::QgsSymbolV2SelectorDialog(QgsSymbolV2* symbol, QgsSty
// there's a correspondence between symbol type number and page numbering => exploit it!
stackedWidget->setCurrentIndex(symbol->type());

connect(btnSetColor, SIGNAL(clicked()), this, SLOT(setSymbolColor()));
connect(btnColorMarker, SIGNAL(clicked()), this, SLOT(setSymbolColor()));
connect(btnColorLine, SIGNAL(clicked()), this, SLOT(setSymbolColor()));
connect(btnColorFill, SIGNAL(clicked()), this, SLOT(setSymbolColor()));
connect(spinAngle, SIGNAL(valueChanged(double)), this, SLOT(setMarkerAngle(double)));
connect(spinSize, SIGNAL(valueChanged(double)), this, SLOT(setMarkerSize(double)));
connect(spinWidth, SIGNAL(valueChanged(double)), this, SLOT(setLineWidth(double)));

connect(btnAddToStyle, SIGNAL(clicked()), this, SLOT(addSymbolToStyle()));
btnSymbolProperties->setIcon( QIcon( QgsApplication::defaultThemePath() + "mActionOptions.png" ) );
btnAddToStyle->setIcon( QIcon( QgsApplication::defaultThemePath() + "symbologyAdd.png" ) );
}

@@ -114,9 +118,10 @@ void QgsSymbolV2SelectorDialog::updateSymbolPreview()

void QgsSymbolV2SelectorDialog::updateSymbolColor()
{
QPixmap p(20,20);
p.fill(mSymbol->color());
btnSetColor->setIcon(QIcon(p));
QColor c = mSymbol->color();
btnColorMarker->setColor(c);
btnColorLine->setColor(c);
btnColorFill->setColor(c);
}

void QgsSymbolV2SelectorDialog::updateSymbolInfo()
@@ -5,15 +5,6 @@

#include <QColorDialog>

static void updateColorButton(QAbstractButton* button, QColor color)
{
QPixmap p(20,20);
p.fill(color);
button->setIcon(QIcon(p));
}

/////////


QgsVectorGradientColorRampV2Dialog::QgsVectorGradientColorRampV2Dialog(QgsVectorGradientColorRampV2* ramp, QWidget* parent)
: QDialog(parent), mRamp(ramp)
@@ -32,8 +23,8 @@ void QgsVectorGradientColorRampV2Dialog::updatePreview()
QSize size(300,40);
lblPreview->setPixmap(QgsSymbolLayerV2Utils::colorRampPreviewPixmap(mRamp, size));

updateColorButton(btnColor1, mRamp->color1());
updateColorButton(btnColor2, mRamp->color2());
btnColor1->setColor(mRamp->color1());
btnColor2->setColor(mRamp->color2());
}

void QgsVectorGradientColorRampV2Dialog::setColor1()

0 comments on commit 94c5bc2

Please sign in to comment.