A little eyecandy:
support titlebar color gradients svn path=/trunk/kdebase/kwin/; revision=256082
This commit is contained in:
parent
78f1c3ab0e
commit
4dca82efb1
1 changed files with 72 additions and 11 deletions
|
@ -3,7 +3,9 @@
|
||||||
*
|
*
|
||||||
* Changes:
|
* Changes:
|
||||||
* Customizable button positions by Karol Szwed <gallium@kde.org>
|
* Customizable button positions by Karol Szwed <gallium@kde.org>
|
||||||
* Thin frame in fixed size windows by Luciano Montanaro <mikelima@virgilio.it>
|
*
|
||||||
|
* Thin frame in fixed size windows and titlebar gradient support are
|
||||||
|
* Copyright (c) 2003 Luciano Montanaro <mikelima@virgilio.it>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "b2client.h"
|
#include "b2client.h"
|
||||||
|
@ -43,6 +45,8 @@ static KPixmap *pixmap[NUM_PIXMAPS];
|
||||||
//inactive, down
|
//inactive, down
|
||||||
#define PIXMAP_ID(i) (pixmap[(i)*4 +3])
|
#define PIXMAP_ID(i) (pixmap[(i)*4 +3])
|
||||||
|
|
||||||
|
KPixmap* titleGradient[2] = {0, 0};
|
||||||
|
|
||||||
static bool pixmaps_created = false;
|
static bool pixmaps_created = false;
|
||||||
static bool colored_frame = false;
|
static bool colored_frame = false;
|
||||||
|
|
||||||
|
@ -127,13 +131,33 @@ static void create_pixmaps()
|
||||||
|
|
||||||
QBitmap helpMask(16, 16, help_mask_bits, true);
|
QBitmap helpMask(16, 16, help_mask_bits, true);
|
||||||
for (i = 0; i < 4; i++) pixmap[P_HELP * 4 + i]->setMask(helpMask);
|
for (i = 0; i < 4; i++) pixmap[P_HELP * 4 + i]->setMask(helpMask);
|
||||||
|
|
||||||
|
QBitmap normalizeMask(16, 16, true);
|
||||||
|
// draw normalize icon mask
|
||||||
|
QPainter mask(&normalizeMask);
|
||||||
|
|
||||||
|
QBrush one(Qt::color1);
|
||||||
|
mask.fillRect(3, 3, 12, 12, one);
|
||||||
|
mask.fillRect(0, 0, 10, 10, one);
|
||||||
|
|
||||||
|
for (i = 0; i < 4; i++) pixmap[P_NORMALIZE * 4 + i]->setMask(normalizeMask);
|
||||||
|
|
||||||
|
titleGradient[0] = 0;
|
||||||
|
titleGradient[1] = 0;
|
||||||
|
|
||||||
redraw_pixmaps();
|
redraw_pixmaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void delete_pixmaps()
|
static void delete_pixmaps()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < NUM_PIXMAPS; i++)
|
for (int i = 0; i < NUM_PIXMAPS; i++) {
|
||||||
delete pixmap[i];
|
delete pixmap[i];
|
||||||
|
pixmap[i] = 0;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
delete titleGradient[i];
|
||||||
|
titleGradient[i] = 0;
|
||||||
|
}
|
||||||
pixmaps_created = false;
|
pixmaps_created = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +186,12 @@ QSizePolicy B2Button::sizePolicy() const
|
||||||
|
|
||||||
void B2Button::drawButton(QPainter *p)
|
void B2Button::drawButton(QPainter *p)
|
||||||
{
|
{
|
||||||
|
KPixmap* gradient = titleGradient[client->isActive() ? 0 : 1];
|
||||||
|
if (gradient) {
|
||||||
|
p->drawTiledPixmap(0, 0, 16, 16, *gradient, 0, 2);
|
||||||
|
} else {
|
||||||
p->fillRect(rect(), bg);
|
p->fillRect(rect(), bg);
|
||||||
|
}
|
||||||
if (useMiniIcon) {
|
if (useMiniIcon) {
|
||||||
QPixmap miniIcon = client->icon().pixmap(QIconSet::Small,
|
QPixmap miniIcon = client->icon().pixmap(QIconSet::Small,
|
||||||
client->isActive() ? QIconSet::Normal : QIconSet::Disabled);
|
client->isActive() ? QIconSet::Normal : QIconSet::Disabled);
|
||||||
|
@ -268,6 +297,8 @@ bool B2Titlebar::x11Event(XEvent *e)
|
||||||
|
|
||||||
void B2Titlebar::drawTitlebar(QPainter &p, bool state)
|
void B2Titlebar::drawTitlebar(QPainter &p, bool state)
|
||||||
{
|
{
|
||||||
|
KPixmap* gradient = titleGradient[state ? 0 : 1];
|
||||||
|
|
||||||
QRect t = rect();
|
QRect t = rect();
|
||||||
// black titlebar frame
|
// black titlebar frame
|
||||||
p.setPen(Qt::black);
|
p.setPen(Qt::black);
|
||||||
|
@ -276,11 +307,12 @@ void B2Titlebar::drawTitlebar(QPainter &p, bool state)
|
||||||
p.drawLine(t.right(), 0, t.right(), t.bottom());
|
p.drawLine(t.right(), 0, t.right(), t.bottom());
|
||||||
|
|
||||||
// titlebar fill
|
// titlebar fill
|
||||||
qDrawShadeRect(&p, 1, 1, t.right()-1, t.height()-1,
|
const QColorGroup cg =
|
||||||
options()->colorGroup(KDecoration::ColorTitleBar, state),
|
options()->colorGroup(KDecoration::ColorTitleBar, state);
|
||||||
false, 1, 0,
|
QBrush brush(cg.background());
|
||||||
&options()->colorGroup(KDecoration::ColorTitleBar, state).
|
if (gradient) brush.setPixmap(*gradient);
|
||||||
brush(QColorGroup::Background));
|
qDrawShadeRect(&p, 1, 1, t.right() - 1, t.height() - 1,
|
||||||
|
cg, false, 1, 0, &brush);
|
||||||
|
|
||||||
// and the caption
|
// and the caption
|
||||||
p.setPen(options()->color(KDecoration::ColorFont, state));
|
p.setPen(options()->color(KDecoration::ColorFont, state));
|
||||||
|
@ -442,8 +474,6 @@ void B2Client::init()
|
||||||
titlebar->recalcBuffer();
|
titlebar->recalcBuffer();
|
||||||
titlebar->installEventFilter(this);
|
titlebar->installEventFilter(this);
|
||||||
positionButtons();
|
positionButtons();
|
||||||
|
|
||||||
//connect(options(), SIGNAL(resetClients()), this, SLOT(slotReset()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void B2Client::addButtons(const QString& s, const QString tips[],
|
void B2Client::addButtons(const QString& s, const QString tips[],
|
||||||
|
@ -969,6 +999,37 @@ static void redraw_pixmaps()
|
||||||
gray, NULL, dgray, NULL, NULL);
|
gray, NULL, dgray, NULL, NULL);
|
||||||
p.end();
|
p.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create the titlebar gradients
|
||||||
|
if (QPixmap::defaultDepth() > 8) {
|
||||||
|
QColor titleColor[4] = {
|
||||||
|
options()->color(KDecoration::ColorTitleBar, true),
|
||||||
|
options()->color(KDecoration::ColorFrame, true),
|
||||||
|
|
||||||
|
options()->color(KDecoration::ColorTitleBlend, false),
|
||||||
|
options()->color(KDecoration::ColorTitleBar, false)
|
||||||
|
};
|
||||||
|
|
||||||
|
if (colored_frame) {
|
||||||
|
titleColor[0] = options()->color(KDecoration::ColorTitleBlend, true);
|
||||||
|
titleColor[1] = options()->color(KDecoration::ColorTitleBar, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 2; i++) {
|
||||||
|
if (titleColor[2 * i] != titleColor[2 * i + 1]) {
|
||||||
|
if (!titleGradient[i]) {
|
||||||
|
titleGradient[i] = new KPixmap;
|
||||||
|
titleGradient[i]->resize(64, 19);
|
||||||
|
}
|
||||||
|
KPixmapEffect::gradient(*titleGradient[i],
|
||||||
|
titleColor[2 * i], titleColor[2 * i + 1],
|
||||||
|
KPixmapEffect::VerticalGradient);
|
||||||
|
} else {
|
||||||
|
delete titleGradient[i];
|
||||||
|
titleGradient[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void B2Client::positionButtons()
|
void B2Client::positionButtons()
|
||||||
|
|
Loading…
Reference in a new issue