[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kdeui/colors
From: Christoph Feck <christoph () maxiom ! de>
Date: 2010-05-03 21:31:27
Message-ID: 20100503213127.B6B8BAC8AB () svn ! kde ! org
[Download RAW message or body]
SVN commit 1122432 by cfeck:
Add support for alpha channel in KColorButton
REVIEW: 3567
M +39 -15 kcolorbutton.cpp
M +14 -0 kcolorbutton.h
--- trunk/KDE/kdelibs/kdeui/colors/kcolorbutton.cpp #1122431:1122432
@@ -22,6 +22,7 @@
#include <config.h>
+#include <QtCore/QPointer>
#include <QtGui/QPainter>
#include <QtGui/qdrawutil.h>
#include <QtGui/QApplication>
@@ -45,6 +46,7 @@
KColorButton *q;
QColor m_defaultColor;
bool m_bdefaultColor : 1;
+ bool m_alphaChannel : 1;
bool dragFlag : 1;
QColor col;
@@ -58,6 +60,7 @@
, d( new KColorButtonPrivate(this) )
{
d->m_bdefaultColor = false;
+ d->m_alphaChannel = false;
d->m_defaultColor = QColor();
setAcceptDrops( true);
@@ -71,6 +74,7 @@
{
d->col = c;
d->m_bdefaultColor = false;
+ d->m_alphaChannel = false;
d->m_defaultColor = QColor();
setAcceptDrops( true);
@@ -84,6 +88,7 @@
{
d->col = c;
d->m_bdefaultColor = true;
+ d->m_alphaChannel = false;
d->m_defaultColor = defaultColor;
setAcceptDrops( true);
@@ -105,11 +110,21 @@
{
if ( d->col != c ) {
d->col = c;
- repaint();
+ update();
emit changed( d->col );
}
}
+void KColorButton::setAlphaChannelEnabled( bool alpha )
+{
+ d->m_alphaChannel = alpha;
+}
+
+bool KColorButton::isAlphaChannelEnabled() const
+{
+ return d->m_alphaChannel;
+}
+
QColor KColorButton::defaultColor() const
{
return d->m_defaultColor;
@@ -157,8 +172,19 @@
QColor fillCol = isEnabled() ? d->col : palette().color(backgroundRole());
qDrawShadePanel( &painter, x, y, w, h, palette(), true, 1, NULL);
- if ( fillCol.isValid() )
+ if ( fillCol.isValid() ) {
+ if ( fillCol.alpha() != 255 ) {
+ QPixmap chessboardPattern(16, 16);
+ QPainter patternPainter(&chessboardPattern);
+ patternPainter.fillRect( 0, 0, 8, 8, Qt::black);
+ patternPainter.fillRect( 8, 8, 8, 8, Qt::black);
+ patternPainter.fillRect( 0, 8, 8, 8, Qt::white);
+ patternPainter.fillRect( 8, 0, 8, 8, Qt::white);
+ patternPainter.end();
+ painter.fillRect( x+1, y+1, w-2, h-2, QBrush(chessboardPattern) );
+ }
painter.fillRect( x+1, y+1, w-2, h-2, fillCol );
+ }
if ( hasFocus() ) {
QRect focusRect = style()->subElementRect( QStyle::SE_PushButtonFocusRect, &butOpt, this );
@@ -234,23 +260,21 @@
void KColorButton::KColorButtonPrivate::_k_chooseColor()
{
- QColor c = q->color();
- if ( m_bdefaultColor )
- {
- if( KColorDialog::getColor( c, m_defaultColor, q ) != QDialog::Rejected ) {
- if ( c.isValid() )
- q->setColor( c );
- else
+ QPointer<KColorDialog> dialog = new KColorDialog(q, true);
+ dialog->setColor(q->color());
+ if (m_bdefaultColor) {
+ dialog->setDefaultColor(m_defaultColor);
+ }
+ dialog->setAlphaChannelEnabled(m_alphaChannel);
+ if (dialog->exec() != QDialog::Rejected) {
+ if (dialog->color().isValid()) {
+ q->setColor(dialog->color());
+ } else if (m_bdefaultColor) {
q->setColor( m_defaultColor );
}
}
- else
- {
- if( KColorDialog::getColor( c, q ) != QDialog::Rejected ) {
- q->setColor( c );
+ delete dialog;
}
- }
-}
#include "kcolorbutton.moc"
--- trunk/KDE/kdelibs/kdeui/colors/kcolorbutton.h #1122431:1122432
@@ -39,6 +39,7 @@
Q_OBJECT
Q_PROPERTY( QColor color READ color WRITE setColor USER true )
Q_PROPERTY( QColor defaultColor READ defaultColor WRITE setDefaultColor )
+ Q_PROPERTY( bool alphaChannelEnabled READ isAlphaChannelEnabled WRITE setAlphaChannelEnabled )
public:
/**
@@ -69,6 +70,19 @@
void setColor( const QColor &c );
/**
+ * When set to true, allow the user to change the alpha component
+ * of the color. The default value is false.
+ * @since 4.5
+ */
+ void setAlphaChannelEnabled( bool alpha );
+
+ /**
+ * Returns true if the user is allowed to change the alpha component.
+ * @since 4.5
+ */
+ bool isAlphaChannelEnabled() const;
+
+ /**
* Returns the default color or an invalid color
* if no default color is set.
*/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic