Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add QgsColorButton class to display a color which can be altered usin…
…g QColorDialog::getColor. Fix for bug #407. A subclass of QToolButton is needed to draw the button content because some platforms such as Mac OS X and Windows XP enforce a consistent GUI look by always using the button color of the current style and not allowing button backgrounds to be changed on a button by button basis. This class is a simplified version of QtColorButton, an internal class used by Qt Designer to do the same thing. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6251 c8812cc2-4d05-0410-92ff-de0c093fc19c
- Loading branch information
telwertowski
committed
Dec 13, 2006
1 parent
701011c
commit a8a1ef7
Showing
19 changed files
with
259 additions
and
409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*************************************************************************** | ||
qgscolorbutton.cpp - Button which displays a color | ||
-------------------------------------- | ||
Date : 12-Dec-2006 | ||
Copyright : (C) 2006 by Tom Elwertowski | ||
Email : telwertowski at users dot sourceforge dot net | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
/* $Id$ */ | ||
|
||
#include "qgscolorbutton.h" | ||
#include <QPainter> | ||
|
||
/*! | ||
\class QgsColorButton | ||
\brief The QgsColorButton class provides a tool button widget displaying | ||
a color which can be altered by calling QColorDialog::getColor. | ||
A subclass of QToolButton is needed to draw the button content because | ||
some platforms such as Mac OS X and Windows XP enforce a consistent | ||
GUI look by always using the button color of the current style and | ||
not allowing button backgrounds to be changed on a button by button basis. | ||
This class is a simplified version of QtColorButton, an internal class used | ||
by Qt Designer to do the same thing. | ||
*/ | ||
|
||
QgsColorButton::QgsColorButton(QWidget *parent) | ||
: QToolButton(parent) | ||
{} | ||
|
||
QgsColorButton::~QgsColorButton() | ||
{} | ||
|
||
/*! | ||
Paints button in response to a paint event. | ||
*/ | ||
void QgsColorButton::paintEvent(QPaintEvent *e) | ||
{ | ||
QToolButton::paintEvent(e); | ||
if (isEnabled()) | ||
{ | ||
QPainter p(this); | ||
int margin = 2; // Leave some space for highlighting | ||
QRect r = rect().adjusted(margin, margin, -margin, -margin); | ||
p.fillRect(r, mColor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/*************************************************************************** | ||
qgscolorbutton.h - Color button | ||
-------------------------------------- | ||
Date : 12-Dec-2006 | ||
Copyright : (C) 2006 by Tom Elwertowski | ||
Email : telwertowski at users dot sourceforge dot net | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
/* $Id$ */ | ||
#ifndef QGSCOLORBUTTON_H | ||
#define QGSCOLORBUTTON_H | ||
|
||
#include <QToolButton> | ||
|
||
class QgsColorButton: public QToolButton | ||
{ | ||
public: | ||
QgsColorButton(QWidget *parent = 0); | ||
~QgsColorButton(); | ||
|
||
void setColor(const QColor &color) { mColor = color; } | ||
QColor color() const { return mColor; } | ||
|
||
protected: | ||
void paintEvent(QPaintEvent *e); | ||
|
||
private: | ||
QColor mColor; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.