Skip to content

Commit

Permalink
Real fix for trac ticket #140 (continued).
Browse files Browse the repository at this point in the history
Buttons where the background color is meaningful are now rendered in classic Windows style in the Vector Properties dialog (both single value and continuous color renderers).

As part of this change the button itself is colored and not just the adjacent label.  The labels have now been removed and the buttons resized to fill the gap.

Bonus feature:  Continuous color dialog now ranges from black to white by default.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5873 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
morb_au committed Sep 24, 2006
1 parent c6937e7 commit 4d23dd5
Show file tree
Hide file tree
Showing 8 changed files with 1,127 additions and 1,200 deletions.
59 changes: 43 additions & 16 deletions src/gui/qgscontinuouscolordialog.cpp
Expand Up @@ -64,26 +64,43 @@ QgsContinuousColorDialog::QgsContinuousColorDialog(QgsVectorLayer * layer)
qWarning("Warning, data provider is null in QgsContinuousColorDialog::QgsContinuousColorDialog(...)");
return;
}


// new Qt4 idiom
#ifdef Q_WS_WIN
// Coloured buttons do not work under the Windows XP style - use plain Windows instead
btnMinValue->setStyle(&mWindowsStyle);
btnMaxValue->setStyle(&mWindowsStyle);
#endif

//restore the correct colors for minimum and maximum values

const QgsContinuousColorRenderer* renderer = dynamic_cast < const QgsContinuousColorRenderer * >(layer->renderer());;

if (renderer)
{
classificationComboBox->setCurrentItem(renderer->classificationField());
const QgsSymbol* minsymbol = renderer->minimumSymbol();
const QgsSymbol* maxsymbol = renderer->maximumSymbol();

if (mVectorLayer->vectorType() == QGis::Line || mVectorLayer->vectorType() == QGis::Point)
{
lblMinValue->setPaletteBackgroundColor(minsymbol->pen().color());
lblMaxValue->setPaletteBackgroundColor(maxsymbol->pen().color());
}
// old Qt3 idiom
// lblMinValue->setPaletteBackgroundColor(minsymbol->pen().color());
// lblMaxValue->setPaletteBackgroundColor(maxsymbol->pen().color());
// new Qt4 idiom
btnMinValue->setPalette( minsymbol->pen().color() );
btnMaxValue->setPalette( maxsymbol->pen().color() );
}
else
{
lblMinValue->setPaletteBackgroundColor(minsymbol->brush().color());
lblMaxValue->setPaletteBackgroundColor(maxsymbol->brush().color());
// old Qt3 idiom
// lblMinValue->setPaletteBackgroundColor(minsymbol->brush().color());
// lblMaxValue->setPaletteBackgroundColor(maxsymbol->brush().color());
// new Qt4 idiom
btnMinValue->setPalette( minsymbol->brush().color() );
btnMaxValue->setPalette( maxsymbol->brush().color() );
}

outlinewidthspinbox->setMinValue(0);
outlinewidthspinbox->setValue(minsymbol->pen().width());

Expand All @@ -98,6 +115,10 @@ QgsContinuousColorDialog::QgsContinuousColorDialog(QgsVectorLayer * layer)
outlinewidthspinbox->setValue(1);
if (mVectorLayer->vectorType() != QGis::Polygon)
cb_polygonOutline->setVisible(false);

btnMinValue->setPalette(Qt::black);
btnMaxValue->setPalette(Qt::white);

}
// Ensure that the state of other widgets is appropriate for the
// state of the polygonoutline checkbox.
Expand Down Expand Up @@ -148,22 +169,22 @@ void QgsContinuousColorDialog::apply()
QgsSymbol* minsymbol = new QgsSymbol(mVectorLayer->vectorType(), QString::number(minimum, 'f'), "", "");
if (mVectorLayer->vectorType() == QGis::Line || mVectorLayer->vectorType() == QGis::Point)
{
minsymbol->setPen(QPen(lblMinValue->paletteBackgroundColor(),outlinewidthspinbox->value()));
minsymbol->setPen(QPen(btnMinValue->paletteBackgroundColor(),outlinewidthspinbox->value()));
}
else
{
minsymbol->setBrush(QBrush(lblMinValue->paletteBackgroundColor()));
minsymbol->setBrush(QBrush(btnMinValue->paletteBackgroundColor()));
minsymbol->setPen(QPen(QColor(0, 0, 0), outlinewidthspinbox->value()));
}

QgsSymbol* maxsymbol = new QgsSymbol(mVectorLayer->vectorType(), QString::number(maximum, 'f'), "", "");
if (mVectorLayer->vectorType() == QGis::Line || mVectorLayer->vectorType() == QGis::Point)
{
maxsymbol->setPen(QPen(lblMaxValue->paletteBackgroundColor(),outlinewidthspinbox->value()));
maxsymbol->setPen(QPen(btnMaxValue->paletteBackgroundColor(),outlinewidthspinbox->value()));
}
else
{
maxsymbol->setBrush(QBrush(lblMaxValue->paletteBackgroundColor()));
maxsymbol->setBrush(QBrush(btnMaxValue->paletteBackgroundColor()));
maxsymbol->setPen(QPen(QColor(0, 0, 0), outlinewidthspinbox->value()));
}

Expand All @@ -181,20 +202,26 @@ void QgsContinuousColorDialog::apply()

void QgsContinuousColorDialog::selectMinimumColor()
{
QColor mincolor = QColorDialog::getColor(QColor(Qt::black), this);
QColor mincolor = QColorDialog::getColor(btnMinValue->paletteBackgroundColor(), this);
if(mincolor.isValid())
{
lblMinValue->setPaletteBackgroundColor(mincolor);
// old Qt3 idiom
// lblMinValue->setPaletteBackgroundColor(mincolor);
// new Qt4 idiom
btnMinValue->setPalette(mincolor);
}
setActiveWindow();
}

void QgsContinuousColorDialog::selectMaximumColor()
{
QColor maxcolor = QColorDialog::getColor(QColor(Qt::black), this);
QColor maxcolor = QColorDialog::getColor(btnMaxValue->paletteBackgroundColor(), this);
if(maxcolor.isValid())
{
lblMaxValue->setPaletteBackgroundColor(maxcolor);
// old Qt3 idiom
// lblMaxValue->setPaletteBackgroundColor(maxcolor);
// new Qt4 idiom
btnMaxValue->setPalette(maxcolor);
}
setActiveWindow();
}
Expand Down
20 changes: 18 additions & 2 deletions src/gui/qgscontinuouscolordialog.h
Expand Up @@ -23,27 +23,43 @@
#include "ui_qgscontinuouscolordialogbase.h"
#include <map>

#ifdef Q_WS_WIN
#include <QWindowsStyle>
#endif

class QgsVectorLayer;


class QgsContinuousColorDialog: public QDialog, private Ui::QgsContinuousColorDialogBase
{
Q_OBJECT
public:

public:
QgsContinuousColorDialog(QgsVectorLayer* layer);
~QgsContinuousColorDialog();

public slots:
void apply();
void apply();

protected slots:
void selectMinimumColor();
void selectMaximumColor();
void on_cb_polygonOutline_clicked();

protected:
QgsVectorLayer* mVectorLayer;
/**Stores the names and numbers of the fields with numeric values*/
std::map<QString,int> mFieldMap;

private:
/** Default constructor is private, do not use this */
QgsContinuousColorDialog();

#ifdef Q_WS_WIN
//! Holds the classic Windows style that is used to render labels with a background color
QWindowsStyle mWindowsStyle;
#endif

};

#endif
64 changes: 49 additions & 15 deletions src/gui/qgssinglesymboldialog.cpp
Expand Up @@ -108,13 +108,20 @@ QgsSingleSymbolDialog::QgsSingleSymbolDialog(QgsVectorLayer * layer): QDialog(),

if (renderer)
{
// Set
set ( renderer->symbol());
// Set from the existing renderer
set ( renderer->symbol() );
}
else
{
// Take values from an example instance
QgsSingleSymbolRenderer exampleRenderer = QgsSingleSymbolRenderer( mVectorLayer->vectorType() );
set ( exampleRenderer.symbol() );
}

if (mVectorLayer && mVectorLayer->vectorType() == QGis::Line)
{
lblFillColor->unsetPalette();
// lblFillColor->unsetPalette();
btnFillColor->setPalette(QPalette()); // reset to default application palette
btnFillColor->setEnabled(false);
grpPattern->setEnabled(false);
mGroupPoint->setEnabled(false);
Expand Down Expand Up @@ -174,10 +181,13 @@ QgsSingleSymbolDialog::~QgsSingleSymbolDialog()

void QgsSingleSymbolDialog::selectOutlineColor()
{
QColor c = QColorDialog::getColor(lblOutlineColor->paletteBackgroundColor(),this);
QColor c = QColorDialog::getColor(btnOutlineColor->paletteBackgroundColor(),this);

if ( c.isValid() ) {
lblOutlineColor->setPaletteBackgroundColor(c);
// old Qt3 idiom
// lblOutlineColor->setPaletteBackgroundColor(c);
// new Qt4 idiom
btnOutlineColor->setPalette(c);
emit settingsChanged();
}

Expand All @@ -186,10 +196,13 @@ void QgsSingleSymbolDialog::selectOutlineColor()

void QgsSingleSymbolDialog::selectFillColor()
{
QColor c = QColorDialog::getColor(lblFillColor->paletteBackgroundColor(),this);
QColor c = QColorDialog::getColor(btnFillColor->paletteBackgroundColor(),this);

if ( c.isValid() ) {
lblFillColor->setPaletteBackgroundColor(c);
// old Qt3 idiom
// lblFillColor->setPaletteBackgroundColor(c);
// new Qt4 idiom
btnFillColor->setPalette(c);
emit settingsChanged();
}

Expand All @@ -199,9 +212,9 @@ void QgsSingleSymbolDialog::selectFillColor()
void QgsSingleSymbolDialog::apply( QgsSymbol *sy )
{
//query the values of the widgets and set the symbology of the vector layer
sy->setFillColor(lblFillColor->paletteBackgroundColor());
sy->setFillColor(btnFillColor->paletteBackgroundColor());
sy->setLineWidth(outlinewidthspinbox->value());
sy->setColor(lblOutlineColor->paletteBackgroundColor());
sy->setColor(btnOutlineColor->paletteBackgroundColor());

//
// Apply point symbol
Expand Down Expand Up @@ -323,9 +336,24 @@ void QgsSingleSymbolDialog::set ( const QgsSymbol *sy )
// ... but, drawLine is not correct with width > 0 -> until solved set to 0
outlinewidthspinbox->setMinValue(0);

lblFillColor->setPaletteBackgroundColor(sy->brush().color());

lblOutlineColor->setPaletteBackgroundColor(sy->pen().color());
// old Qt3 idiom
// lblFillColor->setPaletteBackgroundColor(sy->brush().color());
// new Qt4 idiom
#ifdef Q_WS_WIN
// Coloured labels do not work under the Windows XP style - use plain Windows buttons instead
btnFillColor->setStyle(&mWindowsStyle);
#endif
btnFillColor->setPalette( sy->brush().color() );

// old Qt3 idiom
// lblOutlineColor->setPaletteBackgroundColor(sy->pen().color());
// new Qt4 idiom
#ifdef Q_WS_WIN
// Coloured labels do not work under the Windows XP style - use plain Windows buttons instead
btnOutlineColor->setStyle(&mWindowsStyle);
#endif
btnOutlineColor->setPalette( sy->pen().color() );

//stylebutton->setName(QgsSymbologyUtils::penStyle2Char(sy->pen().style()));
//stylebutton->setPixmap(QgsSymbologyUtils::char2LinePixmap(stylebutton->name()));
Expand Down Expand Up @@ -412,7 +440,10 @@ void QgsSingleSymbolDialog::set ( const QgsSymbol *sy )

void QgsSingleSymbolDialog::setOutlineColor(QColor& c)
{
lblOutlineColor->setPaletteBackgroundColor(c);
// old Qt3 idiom
// lblOutlineColor->setPaletteBackgroundColor(c);
// new Qt4 idiom
btnOutlineColor->setPalette(c);
}

void QgsSingleSymbolDialog::setOutlineStyle(Qt::PenStyle pstyle)
Expand All @@ -434,7 +465,10 @@ void QgsSingleSymbolDialog::setOutlineStyle(Qt::PenStyle pstyle)

void QgsSingleSymbolDialog::setFillColor(QColor& c)
{
lblFillColor->setPaletteBackgroundColor(c);
// old Qt3 idiom
// lblFillColor->setPaletteBackgroundColor(c);
// new Qt4 idiom
btnFillColor->setPalette(c);
}

void QgsSingleSymbolDialog::setFillStyle(Qt::BrushStyle fstyle)
Expand Down Expand Up @@ -483,7 +517,7 @@ void QgsSingleSymbolDialog::setOutlineWidth(int width)

QColor QgsSingleSymbolDialog::getOutlineColor()
{
return lblOutlineColor->paletteBackgroundColor();
return btnOutlineColor->paletteBackgroundColor();
}

Qt::PenStyle QgsSingleSymbolDialog::getOutlineStyle()
Expand All @@ -510,7 +544,7 @@ int QgsSingleSymbolDialog::getOutlineWidth()

QColor QgsSingleSymbolDialog::getFillColor()
{
return lblFillColor->paletteBackgroundColor();
return btnFillColor->paletteBackgroundColor();
}

Qt::BrushStyle QgsSingleSymbolDialog::getFillStyle()
Expand Down
15 changes: 13 additions & 2 deletions src/gui/qgssinglesymboldialog.h
Expand Up @@ -22,6 +22,10 @@
#include "ui_qgssinglesymboldialogbase.h"
#include <vector>

#ifdef Q_WS_WIN
#include <QWindowsStyle>
#endif

class QgsSymbol;
class QgsVectorLayer;

Expand Down Expand Up @@ -50,7 +54,7 @@ class QgsSingleSymbolDialog: public QDialog, private Ui::QgsSingleSymbolDialogBa
protected:
QgsVectorLayer* mVectorLayer;
public slots:
/* set from QgsSymbol */
/* arrange the widgets on this dialog to reflect the current state of QgsSymbol */
void set(const QgsSymbol *sy);
/**applies the changes to the vector layer*/
void apply();
Expand All @@ -62,13 +66,20 @@ public slots:
protected slots:
void selectOutlineColor();
void selectFillColor();

private:
/**Default constructor is privat to not use is*/
/** Default constructor is private, do not use this */
QgsSingleSymbolDialog();

/** vector of marker names for combo items */
std::vector<QString> mMarkers;

#ifdef Q_WS_WIN
//! Holds the classic Windows style that is used to render labels with a background color
QWindowsStyle mWindowsStyle;
#endif


signals:
void settingsChanged();
};
Expand Down

0 comments on commit 4d23dd5

Please sign in to comment.