[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/KDE/3.5/kdebase/kicker/libkicker
From: Benoit Minisini <gambas () users ! sourceforge ! net>
Date: 2008-08-17 11:14:46
Message-ID: 1218971686.564276.22237.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 848301 by bminisini:
Fix the SimpleButton class layout.
Insert the shadow text draw method in libkicker.
M +21 -0 global.cpp
M +5 -0 global.h
M +58 -1 kshadowengine.cpp
M +64 -56 kshadowengine.h
M +14 -13 simplebutton.cpp
M +1 -0 simplebutton.h
--- branches/KDE/3.5/kdebase/kicker/libkicker/global.cpp #848300:848301
@@ -26,6 +26,7 @@
#include <qfile.h>
#include <qpopupmenu.h>
#include <qregexp.h>
+#include <qpainter.h>
#include <kiconeffect.h>
#include <kiconloader.h>
@@ -452,5 +453,25 @@
return iconset;
}
+void drawBlendedRect(QPainter *p, const QRect &r, const QColor &color, int alpha)
+{
+ static QPixmap pix;
+ static QColor last_color = Qt::black;
+ static int last_alpha = 0;
+
+ if (pix.isNull() || last_color != color || last_alpha != alpha)
+ {
+ QImage img(16, 16, 32);
+ img.setAlphaBuffer(false);
+ img.fill((alpha << 24) | (color.rgb() & 0xFFFFFF));
+ img.setAlphaBuffer(true);
+ pix.convertFromImage(img);
+ last_color = color;
+ last_alpha = alpha;
+ }
+
+ p->drawTiledPixmap(r, pix);
+}
+
} // namespace
--- branches/KDE/3.5/kdebase/kicker/libkicker/global.h #848300:848301
@@ -55,6 +55,11 @@
KDE_EXPORT void colorize(QImage& image);
/**
+ * Blend a color rectangle on a painter
+ */
+KDE_EXPORT void drawBlendedRect(QPainter *p, const QRect &r, const QColor &color = \
Qt::black, int alpha = 0x40); +
+/**
* Blend two colours together to get a colour halfway in between
*/
KDE_EXPORT QColor blendColors(const QColor& c1, const QColor& c2);
--- branches/KDE/3.5/kdebase/kicker/libkicker/kshadowengine.cpp #848300:848301
@@ -21,9 +21,13 @@
* Boston, MA 02110-1301, USA.
*/
-#include "kshadowengine.h"
#include <qcolor.h>
+#include <qpainter.h>
+#include <qbitmap.h>
+#include <qpixmap.h>
+
#include "kshadowsettings.h"
+#include "kshadowengine.h"
KShadowEngine::KShadowEngine() :
m_shadowSettings( new KShadowSettings )
@@ -192,3 +196,56 @@
}
return alphaShadow;
}
+
+KTextShadowEngine::KTextShadowEngine() : KShadowEngine()
+{
+ KShadowSettings *shadset = new KShadowSettings();
+
+ shadset->setOffsetX(0);
+ shadset->setOffsetY(0);
+ shadset->setThickness(1);
+ shadset->setMaxOpacity(96);
+
+ setShadowSettings(shadset);
+}
+
+// taken from mtaskbar, by Sebastian Wolff
+void KTextShadowEngine::drawText(QPainter &p, const QRect &tr, int tf, const QString \
&str, const QSize &size) +{
+ // get the color of the shadow: white for dark text, black for bright text
+ QPen textPen = p.pen();
+ QColor shadCol = textPen.color();
+
+ if (shadCol.red() +
+ shadCol.green() +
+ shadCol.blue() <= 3*256/2-1)
+ {
+ shadCol = QColor(255,255,255);
+ }
+ else
+ {
+ shadCol = QColor(0,0,0);
+ }
+
+ // get a transparent pixmap
+ QPainter pixPainter;
+ QPixmap textPixmap(size);
+
+ textPixmap.fill(QColor(0,0,0));
+ textPixmap.setMask(textPixmap.createHeuristicMask(true));
+
+ // draw text
+ pixPainter.begin(&textPixmap);
+ pixPainter.setPen(Qt::white);
+ pixPainter.setFont(p.font()); // get the font from the root painter
+ pixPainter.drawText(tr, tf, str);
+ pixPainter.end();
+
+ // draw shadow
+ QImage img = makeShadow(textPixmap, shadCol);
+
+ // return
+ p.drawImage(0, 0, img);
+ p.drawText(tr, tf, str);
+}
+
--- branches/KDE/3.5/kdebase/kicker/libkicker/kshadowengine.h #848300:848301
@@ -42,74 +42,82 @@
*/
class KDE_EXPORT KShadowEngine
{
- public:
- /// Creates a new shadow engine.
- KShadowEngine();
+public:
+ /// Creates a new shadow engine.
+ KShadowEngine();
- ~KShadowEngine();
+ ~KShadowEngine();
- /**
- * Creates a new shadow engine.
- * @param fx the shadow settings object with the configuration. The Shadow
- * Engine will own this object and also delete it. Must
- * be heap-allocated
- */
- KShadowEngine(KShadowSettings *fx);
+ /**
+ * Creates a new shadow engine.
+ * @param fx the shadow settings object with the configuration. The Shadow
+ * Engine will own this object and also delete it. Must
+ * be heap-allocated
+ */
+ KShadowEngine(KShadowSettings *fx);
- /**
- * Set the KShadowSettings object.
- * @param fx the shadow settings object with the configuration. The Shadow
- * Engine will own this object and also delete it. Must
- * be heap-allocated.
- */
- void setShadowSettings(KShadowSettings *fx);
+ /**
+ * Set the KShadowSettings object.
+ * @param fx the shadow settings object with the configuration. The Shadow
+ * Engine will own this object and also delete it. Must
+ * be heap-allocated.
+ */
+ void setShadowSettings(KShadowSettings *fx);
- /**
- * Get the current KShadowSettings.
- * @param the current shadow settings
- */
- KShadowSettings *shadowSettings();
+ /**
+ * Get the current KShadowSettings.
+ * @param the current shadow settings
+ */
+ KShadowSettings *shadowSettings();
- /**
- * Make shadow!
- *
- * textPixmap is the original pixmap where a (white) text is drawn.
- * bgColor is the color used for the shadow.
- * @param textPixmap the pixmap of the text
- * @param bgColor the background color
- * @return the resulting image
- */
- QImage makeShadow(const QPixmap& textPixmap, const QColor &bgColor);
+ /**
+ * Make shadow!
+ *
+ * textPixmap is the original pixmap where a (white) text is drawn.
+ * bgColor is the color used for the shadow.
+ * @param textPixmap the pixmap of the text
+ * @param bgColor the background color
+ * @return the resulting image
+ */
+ QImage makeShadow(const QPixmap& textPixmap, const QColor &bgColor);
- private:
- // No static objects in libs, and no static deleters in kdefx...
- //static KShadowSettings s_defaultShadowSettings;
+private:
+ // No static objects in libs, and no static deleters in kdefx...
+ //static KShadowSettings s_defaultShadowSettings;
- KShadowSettings *m_shadowSettings;
+ KShadowSettings *m_shadowSettings;
- /*
- * a simple algorithm with 3 pixels thickness
- */
- double defaultDecay(QImage& source, int x, int y);
+ /*
+ * a simple algorithm with 3 pixels thickness
+ */
+ double defaultDecay(QImage& source, int x, int y);
- /*
- * a slower algorithm where the influence of a pixel
- * is qGray(px)/(abs(dx) + abs(dy) +1).
- */
- double doubleLinearDecay(QImage& source, int x, int y);
+ /*
+ * a slower algorithm where the influence of a pixel
+ * is qGray(px)/(abs(dx) + abs(dy) +1).
+ */
+ double doubleLinearDecay(QImage& source, int x, int y);
- /*
- * a very slow algorithm where the influence of a pixel
- * is qGray(px)/(sqrt(sqr(dx) + sqr(dy)) +1).
- */
- double radialDecay(QImage& source, int x, int y);
+ /*
+ * a very slow algorithm where the influence of a pixel
+ * is qGray(px)/(sqrt(sqr(dx) + sqr(dy)) +1).
+ */
+ double radialDecay(QImage& source, int x, int y);
- /*
- * a nice/fast algorithm proposed by Bernardo Hung
- */
- double noDecay(QImage& source, int x, int y);
+ /*
+ * a nice/fast algorithm proposed by Bernardo Hung
+ */
+ double noDecay(QImage& source, int x, int y);
- void *d;
+ void *d;
};
+class KDE_EXPORT KTextShadowEngine : public KShadowEngine
+{
+public:
+ KTextShadowEngine();
+
+ void drawText(QPainter &p, const QRect &tr, int tf, const QString &str, const \
QSize &size); +};
+
#endif
--- branches/KDE/3.5/kdebase/kicker/libkicker/simplebutton.cpp #848300:848301
@@ -68,18 +68,19 @@
const QPixmap* pm = pixmap();
if (!pm)
- {
return QButton::sizeHint();
- }
+ else
+ return QSize(pm->width() + KDialog::spacingHint(), pm->height() + \
KDialog::spacingHint()); +}
- if (m_orientation == Qt::Horizontal)
- {
- return QSize(pm->width() + KDialog::spacingHint(), pm->height());
- }
+QSize SimpleButton::minimumSizeHint() const
+{
+ const QPixmap* pm = pixmap();
+
+ if (!pm)
+ return QButton::minimumSizeHint();
else
- {
- return QSize(pm->width(), pm->height() + KDialog::spacingHint());
- }
+ return QSize(pm->width(), pm->height());
}
void SimpleButton::drawButton( QPainter *p )
@@ -135,6 +136,8 @@
m_normalIcon = effect.apply(image, KIcon::Panel, KIcon::DefaultState);
m_activeIcon = effect.apply(image, KIcon::Panel, KIcon::ActiveState);
m_disabledIcon = effect.apply(image, KIcon::Panel, KIcon::DisabledState);
+
+ updateGeometry();
}
void SimpleButton::slotSettingsChanged(int category)
@@ -218,7 +221,7 @@
void SimpleArrowButton::drawButton( QPainter *p )
{
- QRect r(1, 1, width() - 1, height() - 1);
+ QRect r(1, 1, width() - 2, height() - 2);
QStyle::PrimitiveElement pe = QStyle::PE_ArrowLeft;
switch (_arrow)
@@ -229,10 +232,8 @@
case Qt::DownArrow: pe = QStyle::PE_ArrowDown; break;
}
- int flags = QStyle::Style_Default;
- if (_inside) flags |= QStyle::Style_Enabled;
+ int flags = QStyle::Style_Default | QStyle::Style_Enabled;
if (isDown() || isOn()) flags |= QStyle::Style_Down;
-
style().drawPrimitive(pe, p, r, colorGroup(), flags);
}
--- branches/KDE/3.5/kdebase/kicker/libkicker/simplebutton.h #848300:848301
@@ -35,6 +35,7 @@
void setPixmap(const QPixmap &pix);
void setOrientation(Qt::Orientation orientaton);
QSize sizeHint() const;
+ QSize minimumSizeHint() const;
protected:
void drawButton( QPainter *p );
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic