svn path=/trunk/kdebase/kwin/; revision=114199
This commit is contained in:
parent
4ef029256c
commit
85baad95f1
8 changed files with 1338 additions and 0 deletions
23
clients/glow/Makefile.am
Normal file
23
clients/glow/Makefile.am
Normal file
|
@ -0,0 +1,23 @@
|
|||
|
||||
INCLUDES = $(all_includes)
|
||||
|
||||
kde_module_LTLIBRARIES = libkwinglow.la
|
||||
|
||||
libkwinglow_la_SOURCES = glowclient.cpp glowbutton.cpp
|
||||
libkwinglow_la_LIBADD = ../../kwin.la
|
||||
libkwinglow_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN)
|
||||
|
||||
METASOURCES = AUTO
|
||||
noinst_HEADERS = glowclient.h bitmaps.h glowbutton.h
|
||||
|
||||
datadir = $(kde_datadir)/kwin/
|
||||
data_DATA = glow.desktop
|
||||
|
||||
confdir = $(kde_confdir)
|
||||
conf_DATA = kwinglowrc
|
||||
|
||||
EXTRA_DIST = $(data_DATA) $(conf_DATA)
|
||||
|
||||
###KMAKE-start (don't edit or delete this block)
|
||||
|
||||
###KMAKE-end
|
97
clients/glow/bitmaps.h
Normal file
97
clients/glow/bitmaps.h
Normal file
|
@ -0,0 +1,97 @@
|
|||
/***************************************************************************
|
||||
bitmaps.h - description
|
||||
-------------------
|
||||
begin : Thu Sep 12 2001
|
||||
copyright : (C) 2001 by Henning Burchardt
|
||||
email : h_burchardt@gmx.de
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#define DEFAULT_BITMAP_SIZE 17
|
||||
#define SMALL_BITMAP_SIZE 13
|
||||
|
||||
static unsigned char close_bits[] = {
|
||||
0x00,0x00,0x16,0x00,0x00,0x16,0x00,0x00,0xf8,0x00,0x00,0x0c,0x10,0x10,0x60,
|
||||
0x30,0x18,0x00,0x60,0x0c,0xc8,0xc0,0x07,0x16,0x80,0x03,0x60,0xc0,0x07,0x00,
|
||||
0x60,0x0c,0x00,0x30,0x18,0xf8,0x10,0x10,0x00,0x00,0x00,0x46,0x00,0x00,0xfe,
|
||||
0x00,0x00,0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x89,0xf3,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
|
||||
static unsigned char close_small_bits[] = {
|
||||
0x00,0xc0,0x00,0x00,0x00,0xa0,0x00,0x20,0x10,0xc1,0xb0,0x01,0xe0,0x00,0xb0,
|
||||
0x81,0x10,0x01,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x81,0xf2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
|
||||
static unsigned char help_bits[] = {
|
||||
0x00,0x00,0x16,0x00,0x00,0x16,0x00,0x00,0x10,0x00,0x00,0x0c,0x80,0x07,0xb6,
|
||||
0x40,0x0c,0x00,0x00,0x0c,0xc8,0x00,0x0c,0x16,0x00,0x06,0xb6,0x00,0x03,0x00,
|
||||
0x00,0x01,0x00,0x00,0x00,0x10,0x00,0x01,0x00,0x00,0x00,0xac,0x00,0x00,0xfe,
|
||||
0x00,0x00,0x0a,0x00,0x00,0x00,0x00,0x24,0xc4,0x3f,0x40,0x01,0xf3,0x00,0x00,
|
||||
0x70,0xb9,0x65,0x40,0x70,0xb9,0x65,0x40 };
|
||||
static unsigned char help_small_bits[] = {
|
||||
0x00,0xc0,0x00,0x00,0x00,0xa0,0x00,0x20,0xe0,0xc0,0x80,0x00,0xc0,0x00,0x40,
|
||||
0x00,0x40,0x00,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0xc2,0x08,0x91,0xf2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
|
||||
static unsigned char maximizeoff_bits[] = {
|
||||
0x00,0x00,0x16,0x00,0x00,0x16,0x00,0x00,0x1e,0x00,0x00,0x0c,0xf0,0x1f,0x60,
|
||||
0xf0,0x1f,0x00,0x10,0x10,0xc8,0x10,0x10,0x16,0x10,0x10,0x60,0x10,0x10,0x00,
|
||||
0x10,0x10,0x00,0x10,0x10,0x1e,0xf0,0x1f,0x00,0x00,0x00,0x50,0x00,0x00,0xfe,
|
||||
0x00,0x00,0x0a,0x00,0x00,0x00,0x00,0x68,0xb9,0x65,0x40,0x01,0xf2,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0xe0,0xb1,0x65,0x40 };
|
||||
static unsigned char maximizeoff_small_bits[] = {
|
||||
0x00,0xa0,0x00,0x00,0x00,0xa0,0x00,0x20,0xf0,0xa1,0xf0,0x01,0x10,0x01,0x10,
|
||||
0x01,0xf0,0x01,0x00,0xa0,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x49,0xf3,0x00,0x00,0x68,0xb9,0x65,0x40,0x68,0xb9,0x65,0x40,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
|
||||
static unsigned char maximizeon_bits[] = {
|
||||
0x00,0x00,0x16,0x00,0x00,0x16,0x00,0x00,0xf8,0x00,0x00,0x0c,0xf0,0x07,0x60,
|
||||
0xf0,0x07,0x00,0x10,0x04,0xc8,0xd0,0x1f,0x16,0xd0,0x1f,0x60,0x70,0x10,0x00,
|
||||
0x40,0x10,0x00,0x40,0x10,0xf8,0xc0,0x1f,0x00,0x00,0x00,0xcc,0x00,0x00,0xfe,
|
||||
0x00,0x00,0x0a,0x00,0x00,0x00,0x00,0xec,0xad,0x07,0x08,0x59,0xf2,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
|
||||
static unsigned char maximizeon_small_bits[] = {
|
||||
0x00,0xc0,0x00,0x00,0x00,0xa0,0x00,0x20,0xf0,0xc0,0x90,0x00,0xf0,0x01,0x20,
|
||||
0x81,0xe0,0x01,0x00,0x60,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x81,
|
||||
0x08,0x08,0x19,0xf3,0x00,0x00,0x58,0xab,0x07,0x08,0x90,0xb9,0x65,0x40,0x8c,
|
||||
0x81,0x08,0x08,0x21,0x00,0x00,0x00 };
|
||||
static unsigned char minimize_bits[] = {
|
||||
0x00,0x00,0x16,0x00,0x00,0x16,0x00,0x00,0x10,0x00,0x00,0x0c,0x00,0x00,0xb6,
|
||||
0xe0,0x0f,0x00,0x00,0x00,0xc8,0x20,0x08,0x16,0x60,0x0c,0xb6,0xc0,0x06,0x00,
|
||||
0x80,0x03,0x00,0x00,0x01,0x10,0x00,0x00,0x00,0x00,0x00,0xb2,0x00,0x00,0xfe,
|
||||
0x00,0x00,0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x29,0xf2,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
|
||||
static unsigned char minimize_small_bits[] = {
|
||||
0x00,0xc0,0x00,0x00,0x00,0xa0,0x00,0x20,0xf0,0xc1,0x00,0x00,0xf0,0x01,0xe0,
|
||||
0x00,0x40,0x00,0x00,0x80,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0xad,
|
||||
0x07,0x08,0x21,0xf3,0x00,0x00,0x68,0xb9,0x65,0x40,0x68,0xb9,0x65,0x40,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
|
||||
static unsigned char stickyoff_bits[] = {
|
||||
0x00,0x00,0x16,0x00,0x00,0x16,0x00,0x00,0x1e,0x00,0x00,0x0c,0x50,0x15,0x60,
|
||||
0xe0,0x00,0x00,0xf0,0x11,0xc8,0xe0,0x00,0x16,0x50,0x15,0x60,0x00,0x00,0x00,
|
||||
0x10,0x11,0x00,0x00,0x00,0x1e,0x50,0x15,0x00,0x00,0x00,0x46,0x00,0x00,0xfe,
|
||||
0x00,0x00,0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x0a,0x08,0x31,0xf2,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x29,0xf2,0x00,0x00 };
|
||||
static unsigned char stickyoff_small_bits[] = {
|
||||
0x00,0xa0,0x00,0x00,0x00,0xa0,0x00,0x20,0xf0,0xa1,0x30,0x01,0x50,0x01,0x10,
|
||||
0x01,0xf0,0x01,0x00,0xc0,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,
|
||||
0x00,0x00,0x59,0xf3,0x00,0x00,0x68,0xb9,0x65,0x40,0x68,0xb9,0x65,0x40,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
|
||||
static unsigned char stickyon_bits[] = {
|
||||
0x00,0x00,0x16,0x00,0x00,0x16,0x00,0x00,0xf8,0x00,0x00,0x0c,0x50,0x15,0x60,
|
||||
0xe0,0x0e,0x00,0xf0,0x1f,0xc8,0xe0,0x0e,0x16,0x50,0x15,0x60,0xe0,0x0e,0x00,
|
||||
0xf0,0x1f,0x00,0xe0,0x0e,0xf8,0x50,0x15,0x00,0x00,0x00,0xac,0x00,0x00,0xfe,
|
||||
0x00,0x00,0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x40,0x69,0xf2,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
|
||||
static unsigned char stickyon_small_bits[] = {
|
||||
0x00,0xc0,0x00,0x00,0x00,0xa0,0x00,0x20,0xf0,0xc1,0xb0,0x01,0x50,0x01,0xb0,
|
||||
0x81,0xf0,0x01,0x00,0xc0,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0xb8,0xb9,
|
||||
0x65,0x40,0x49,0xf3,0x00,0x00,0xb0,0xb9,0x65,0x40,0xb0,0xb9,0x65,0x40,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
|
3
clients/glow/glow.desktop
Normal file
3
clients/glow/glow.desktop
Normal file
|
@ -0,0 +1,3 @@
|
|||
[Desktop Entry]
|
||||
Name=Glow
|
||||
X-KDE-Library=libkwinglow
|
333
clients/glow/glowbutton.cpp
Normal file
333
clients/glow/glowbutton.cpp
Normal file
|
@ -0,0 +1,333 @@
|
|||
/***************************************************************************
|
||||
glowbutton.cpp - description
|
||||
-------------------
|
||||
begin : Thu Sep 6 2001
|
||||
copyright : (C) 2001 by Henning Burchardt
|
||||
email : h_burchardt@gmx.de
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include <vector>
|
||||
#include <qpixmap.h>
|
||||
#include <qbitmap.h>
|
||||
#include <qpainter.h>
|
||||
#include <qimage.h>
|
||||
#include <qtimer.h>
|
||||
#include "glowbutton.h"
|
||||
|
||||
using namespace KWinInternal;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
GlowButton::GlowButton(QWidget *parent, const char *name,
|
||||
const QString& tip, QPixmap *pixmap)
|
||||
: KWinWidgetButton(parent, name, 0, tip), m_pixmap(pixmap)
|
||||
{
|
||||
m_steps = 20;
|
||||
m_updateTime = 50;
|
||||
|
||||
m_timer = new QTimer();
|
||||
QObject::connect(m_timer, SIGNAL(timeout()), this, SLOT(slotTimeout()));
|
||||
m_pos = 0;
|
||||
m_timerStatus = Stop;
|
||||
}
|
||||
|
||||
GlowButton::~GlowButton()
|
||||
{
|
||||
}
|
||||
|
||||
QPixmap *GlowButton::getPixmap()
|
||||
{
|
||||
return m_pixmap;
|
||||
}
|
||||
|
||||
void GlowButton::setPixmap(QPixmap *pixmap)
|
||||
{
|
||||
m_pixmap = pixmap;
|
||||
QBitmap mask(width(), height());
|
||||
mask.fill(Qt::color0);
|
||||
bitBlt(&mask, 0, 0, pixmap->mask(), 0, 0, width(), height());
|
||||
setMask(mask);
|
||||
repaint(false);
|
||||
}
|
||||
|
||||
void GlowButton::paintEvent( QPaintEvent *e )
|
||||
{
|
||||
QWidget::paintEvent(e);
|
||||
if( m_pixmap != 0 )
|
||||
{
|
||||
int pos = m_pos>=0?m_pos:-m_pos;
|
||||
bitBlt(this, 0, 0, m_pixmap, 0, pos*height(), width(), height());
|
||||
}
|
||||
}
|
||||
|
||||
void GlowButton::enterEvent( QEvent *e )
|
||||
{
|
||||
if( m_pos<0 )
|
||||
m_pos=-m_pos;
|
||||
m_timerStatus = Run;
|
||||
if( ! m_timer->isActive() )
|
||||
m_timer->start(m_updateTime);
|
||||
KWinWidgetButton::enterEvent(e);
|
||||
}
|
||||
|
||||
void GlowButton::leaveEvent( QEvent *e )
|
||||
{
|
||||
m_timerStatus = Stop;
|
||||
if( ! m_timer->isActive() )
|
||||
m_timer->start(m_updateTime);
|
||||
KWinWidgetButton::leaveEvent(e);
|
||||
}
|
||||
|
||||
void GlowButton::mousePressEvent( QMouseEvent *e )
|
||||
{
|
||||
if( m_timer->isActive() )
|
||||
m_timer->stop();
|
||||
m_pos = m_steps;
|
||||
repaint(false);
|
||||
// emit pressed();
|
||||
KWinWidgetButton::mousePressEvent(e);
|
||||
}
|
||||
|
||||
void GlowButton::mouseReleaseEvent( QMouseEvent *e )
|
||||
{
|
||||
QPoint p = mapToParent(mapFromGlobal(e->globalPos()));
|
||||
if( ! geometry().contains(p) )
|
||||
m_timerStatus = Stop;
|
||||
else
|
||||
{
|
||||
emit clicked();
|
||||
emit clicked(e->button());
|
||||
}
|
||||
if( ! m_timer->isActive() )
|
||||
m_timer->start(m_updateTime);
|
||||
// emit released();
|
||||
KWinWidgetButton::mouseReleaseEvent(e);
|
||||
}
|
||||
|
||||
void GlowButton::slotTimeout()
|
||||
{
|
||||
repaint(false);
|
||||
|
||||
if( m_pos>=m_steps-1 )
|
||||
m_pos = -m_pos;
|
||||
|
||||
if( m_timerStatus==Stop )
|
||||
{
|
||||
if( m_pos==0 )
|
||||
{
|
||||
m_timer->stop();
|
||||
return;
|
||||
}
|
||||
else if( m_pos>0 )
|
||||
m_pos = -m_pos;
|
||||
}
|
||||
|
||||
m_pos++;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
GlowButtonFactory::GlowButtonFactory()
|
||||
{
|
||||
m_steps = 20;
|
||||
// cerr << "GlowButtonFactory " << "GlowButtonFactory " << m_steps << endl;
|
||||
m_glowFactor = 1.0;
|
||||
m_updateTime = 50;
|
||||
}
|
||||
|
||||
QPixmap* GlowButtonFactory::createGlowButtonPixmap(
|
||||
const QSize& size, const QColor& glowColor,
|
||||
const QColorGroup& colorGroup, const QPixmap& fgPixmap )
|
||||
{
|
||||
QPixmap pm(size);
|
||||
pm.fill(glowColor);
|
||||
return createGlowButtonPixmap(
|
||||
size, pm, colorGroup, fgPixmap);
|
||||
}
|
||||
|
||||
QPixmap* GlowButtonFactory::createGlowButtonPixmap(
|
||||
const QSize& size, const QPixmap& glowPixmap,
|
||||
const QColorGroup& colorGroup, const QPixmap& fgPixmap)
|
||||
{
|
||||
// cerr << "GlowButtonFactory " << "createGlowButtonPixmap " << endl;
|
||||
int w = size.width();
|
||||
int h = size.height();
|
||||
|
||||
vector< vector<float> > intensityField;
|
||||
intensityField.resize(h);
|
||||
for( int i=0; i<h; i++ )
|
||||
{
|
||||
intensityField[i].resize(w);
|
||||
for( int j=0; j<w; j++ )
|
||||
{
|
||||
float distance = 0;
|
||||
// float distance = sqrt(
|
||||
// ((w/2.0-j)*(w/2.0-j)+(h/2.0-i)*(h/2.0-i))/(w*w/4.0+h*h/4.0) );
|
||||
intensityField[i][j] = (1-distance);
|
||||
}
|
||||
}
|
||||
|
||||
QPainter painter;
|
||||
QPixmap upPixmap(w, h);
|
||||
upPixmap = DrawUtils::drawSimpleRoundButton(size, colorGroup);
|
||||
// upPixmap.fill(colorGroup.background());
|
||||
painter.begin(&upPixmap);
|
||||
// QApplication::style().drawButton(
|
||||
// &painter, 0, 0, w, h, colorGroup, false );
|
||||
painter.drawPixmap(0, 0, fgPixmap);
|
||||
painter.end();
|
||||
|
||||
QPixmap downPixmap(w, h);
|
||||
downPixmap = DrawUtils::drawSimpleRoundButton(size, colorGroup);
|
||||
// downPixmap.fill(colorGroup.background());
|
||||
painter.begin(&downPixmap);
|
||||
// QApplication::style().drawButton(
|
||||
// &painter, 0, 0, w, h, colorGroup, true );
|
||||
painter.drawPixmap(1, 1, fgPixmap);
|
||||
painter.end();
|
||||
|
||||
QPixmap *pm = new QPixmap(w, (m_steps+1)*h);
|
||||
QPixmap fadedPixmap;
|
||||
for( int i=0; i<m_steps; i++ )
|
||||
{
|
||||
// float intensity = (float) i/m_steps;
|
||||
float intensity = (float) i/m_steps/2;
|
||||
fadedPixmap = DrawUtils::fadePixmaps(upPixmap, glowPixmap,
|
||||
intensityField, intensity);
|
||||
bitBlt(pm, 0, i*h, &fadedPixmap);
|
||||
}
|
||||
fadedPixmap = DrawUtils::fadePixmaps(downPixmap, glowPixmap,
|
||||
intensityField, 0.5f);
|
||||
bitBlt(pm, 0, m_steps*h, &fadedPixmap);
|
||||
|
||||
QBitmap simpleMask = DrawUtils::drawSimpleRoundButtonMask(size);
|
||||
QBitmap mask(w, (m_steps+1)*h);
|
||||
mask.fill(Qt::color0);
|
||||
// painter.begin(&mask);
|
||||
for( int i=0; i<m_steps+1; i++ )
|
||||
bitBlt(&mask, 0, i*h, &simpleMask);
|
||||
// QApplication::style().drawButtonMask( &painter, 0, i*h, w, h );
|
||||
// painter.end();
|
||||
|
||||
pm->setMask(mask);
|
||||
return pm;
|
||||
}
|
||||
|
||||
GlowButton* GlowButtonFactory::createGlowButton(
|
||||
QWidget *parent, const char* name, const QString& tip, QPixmap *pixmap)
|
||||
{
|
||||
GlowButton *glowButton = new GlowButton(
|
||||
parent, name, tip, pixmap);
|
||||
glowButton->m_steps = m_steps;
|
||||
glowButton->m_updateTime = m_updateTime;
|
||||
return glowButton;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
QPixmap DrawUtils::fadePixmaps(
|
||||
const QPixmap& bgPixmap, const QPixmap& fgPixmap,
|
||||
const vector< vector<float> >& intensityField, float intensity )
|
||||
{
|
||||
// cerr << "DrawUtils " << "fadePixmaps " << endl;
|
||||
QImage bgImg = bgPixmap.convertToImage();
|
||||
QImage fgImg = fgPixmap.convertToImage();
|
||||
QImage newImg(bgImg.width(), bgImg.height(), bgImg.depth());
|
||||
int w = bgImg.width();
|
||||
int h = bgImg.height();
|
||||
for( int y=0; y<h; y++ )
|
||||
{
|
||||
uint* bgLine = (uint*) bgImg.scanLine(y);
|
||||
uint* fgLine = (uint*) fgImg.scanLine(y);
|
||||
uint* newLine = (uint*) newImg.scanLine(y);
|
||||
for( int x=0; x<w; x++ )
|
||||
{
|
||||
QRgb bgRgb = *(bgLine+x);
|
||||
uint bgRed = qRed(bgRgb);
|
||||
uint bgGreen = qGreen(bgRgb);
|
||||
uint bgBlue = qBlue(bgRgb);
|
||||
QRgb fgRgb = *(fgLine+x);
|
||||
uint fgRed = qRed(fgRgb);
|
||||
uint fgGreen = qGreen(fgRgb);
|
||||
uint fgBlue = qBlue(fgRgb);
|
||||
float factor = intensityField[y][x]*intensity;
|
||||
uint newRed = (uint) ((1-factor)*bgRed + factor*fgRed);
|
||||
uint newGreen = (uint) ((1-factor)*bgGreen + factor*fgGreen);
|
||||
uint newBlue = (uint) ((1-factor)*bgBlue + factor*fgBlue);
|
||||
*(newLine+x) = qRgb( newRed, newGreen, newBlue );
|
||||
}
|
||||
}
|
||||
|
||||
QPixmap newPixmap;
|
||||
newPixmap.convertFromImage(newImg);
|
||||
return newPixmap;
|
||||
}
|
||||
|
||||
QPixmap DrawUtils::drawSimpleRoundButton(
|
||||
const QSize& size, const QColorGroup& colorGroup)
|
||||
{
|
||||
QColor mid = colorGroup.button();
|
||||
QColor border = colorGroup.light();
|
||||
int w = size.width();
|
||||
int h = size.height();
|
||||
|
||||
QPainter p;
|
||||
|
||||
vector< vector<float> > intensityField;
|
||||
intensityField.resize(h);
|
||||
for( int i=0; i<h; i++ )
|
||||
{
|
||||
intensityField[i].resize(w);
|
||||
for( int j=0; j<w; j++ )
|
||||
{
|
||||
float distance = sqrt(
|
||||
((w/2.0-j)*(w/2.0-j)+(h/2.0-i)*(h/2.0-i))/(w*w/4.0+h*h/4.0) );
|
||||
intensityField[i][j] = (1-distance);
|
||||
}
|
||||
}
|
||||
|
||||
QPixmap darkPm(size);
|
||||
darkPm.fill(mid);
|
||||
QPixmap lightPm(size);
|
||||
lightPm.fill(border);
|
||||
|
||||
QPixmap pm = fadePixmaps(lightPm, darkPm, intensityField, 1.0);
|
||||
|
||||
p.begin(&pm);
|
||||
int hh, ss, vv;
|
||||
mid.hsv(&hh, &ss, &vv);
|
||||
mid.setHsv(hh, 0, vv);
|
||||
p.setPen(colorGroup.mid());
|
||||
p.drawEllipse(0, 0, w, h);
|
||||
p.end();
|
||||
|
||||
pm.setMask(drawSimpleRoundButtonMask(size));
|
||||
|
||||
return pm;
|
||||
}
|
||||
|
||||
QBitmap DrawUtils::drawSimpleRoundButtonMask( const QSize& size )
|
||||
{
|
||||
int w = size.width();
|
||||
int h = size.height();
|
||||
QPainter p;
|
||||
QBitmap mask(size);
|
||||
mask.fill(Qt::color0);
|
||||
p.begin(&mask);
|
||||
p.setPen(Qt::color1);
|
||||
p.setBrush(Qt::color1);
|
||||
p.drawEllipse(0, 0, w, h);
|
||||
p.end();
|
||||
return mask;
|
||||
}
|
||||
|
||||
#include "glowbutton.moc"
|
113
clients/glow/glowbutton.h
Normal file
113
clients/glow/glowbutton.h
Normal file
|
@ -0,0 +1,113 @@
|
|||
/***************************************************************************
|
||||
glowbutton.h - description
|
||||
-------------------
|
||||
begin : Thu Sep 14 2001
|
||||
copyright : (C) 2001 by Henning Burchardt
|
||||
email : h_burchardt@gmx.de
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef GLOW_BUTTON_H
|
||||
#define GLOW_BUTTON_H
|
||||
|
||||
#include <kwin/kwinbutton.h>
|
||||
|
||||
class QPixmap;
|
||||
class QBitmap;
|
||||
class QTimer;
|
||||
|
||||
namespace KWinInternal
|
||||
{
|
||||
|
||||
class GlowButtonFactory;
|
||||
|
||||
class GlowButton : public KWinWidgetButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
friend class GlowButtonFactory;
|
||||
public:
|
||||
~GlowButton();
|
||||
|
||||
QPixmap *getPixmap();
|
||||
|
||||
void setPixmap(QPixmap* pixmap);
|
||||
|
||||
protected:
|
||||
GlowButton(QWidget *parent, const char* name,
|
||||
const QString& tip, QPixmap *bgPixmap=0);
|
||||
|
||||
virtual void paintEvent( QPaintEvent * );
|
||||
virtual void enterEvent( QEvent * );
|
||||
virtual void leaveEvent( QEvent * );
|
||||
virtual void mousePressEvent( QMouseEvent * );
|
||||
virtual void mouseReleaseEvent( QMouseEvent * );
|
||||
|
||||
protected slots:
|
||||
void slotTimeout();
|
||||
|
||||
private:
|
||||
enum TimerStatus { Run, Stop };
|
||||
|
||||
int m_updateTime;
|
||||
int m_steps;
|
||||
|
||||
QPixmap *m_pixmap;
|
||||
QTimer *m_timer;
|
||||
int m_pos;
|
||||
TimerStatus m_timerStatus;
|
||||
|
||||
signals:
|
||||
// void pressed();
|
||||
// void released();
|
||||
void clicked();
|
||||
void clicked(int button);
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class GlowButtonFactory
|
||||
{
|
||||
public:
|
||||
GlowButtonFactory();
|
||||
|
||||
QPixmap* createGlowButtonPixmap(
|
||||
const QSize& size, const QColor& glowColor,
|
||||
const QColorGroup& colorGroup, const QPixmap& fgPixmap );
|
||||
QPixmap* createGlowButtonPixmap(
|
||||
const QSize& size, const QPixmap& glowPixmap,
|
||||
const QColorGroup& colorGroup, const QPixmap& fgPixmap );
|
||||
GlowButton* createGlowButton(
|
||||
QWidget *parent, const char* name,
|
||||
const QString& tip, QPixmap *pixmap=0);
|
||||
|
||||
private:
|
||||
int m_steps;
|
||||
float m_glowFactor;
|
||||
int m_updateTime;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class DrawUtils
|
||||
{
|
||||
public:
|
||||
static QPixmap fadePixmaps(
|
||||
const QPixmap& bgPixmap, const QPixmap& glowPixmap,
|
||||
const vector< vector<float> >& intensityField, float intensity );
|
||||
static QPixmap drawSimpleRoundButton(
|
||||
const QSize& size, const QColorGroup& group);
|
||||
static QBitmap drawSimpleRoundButtonMask(const QSize& size);
|
||||
};
|
||||
|
||||
}; // namespace
|
||||
|
||||
#endif
|
621
clients/glow/glowclient.cpp
Normal file
621
clients/glow/glowclient.cpp
Normal file
|
@ -0,0 +1,621 @@
|
|||
/***************************************************************************
|
||||
glowclient.cpp - description
|
||||
-------------------
|
||||
begin : Thu Sep 6 2001
|
||||
copyright : (C) 2001 by Henning Burchardt
|
||||
email : h_burchardt@gmx.de
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include <cmath>
|
||||
#include <qpixmap.h>
|
||||
#include <qbitmap.h>
|
||||
#include <qpainter.h>
|
||||
#include <qapplication.h>
|
||||
#include <qlayout.h>
|
||||
#include <qfontmetrics.h>
|
||||
#include <kpixmapeffect.h>
|
||||
#include <kpixmap.h>
|
||||
#include <kconfig.h>
|
||||
#include <kwin/options.h>
|
||||
#include <kwin/workspace.h>
|
||||
#include "bitmaps.h"
|
||||
#include "glowclient.h"
|
||||
#include "glowbutton.h"
|
||||
|
||||
using namespace KWinInternal;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
GlowClientConfig::GlowClientConfig()
|
||||
{
|
||||
}
|
||||
|
||||
void GlowClientConfig::load()
|
||||
{
|
||||
// cerr << "GlowClientConfig " << "load " << endl;
|
||||
KConfig conf("kwinglowrc");
|
||||
conf.setGroup("General");
|
||||
|
||||
QColor defaultButtonColor = Qt::white;
|
||||
QColor defaultCloseButtonColor = Qt::red;
|
||||
|
||||
QString stickyButtonGlowType =
|
||||
conf.readEntry("stickyButtonGlowType", "TitleBar");
|
||||
if(stickyButtonGlowType=="TitleBar")
|
||||
stickyButtonGlowColor = options->color(Options::TitleBar);
|
||||
else if(stickyButtonGlowType=="TitleBlend")
|
||||
stickyButtonGlowColor = options->color(Options::TitleBlend);
|
||||
else // if( stickyButtonGlowType=="Custom" )
|
||||
stickyButtonGlowColor = conf.readColorEntry(
|
||||
"stickyButtonGlowColor", &defaultButtonColor);
|
||||
|
||||
QString helpButtonGlowType =
|
||||
conf.readEntry("helpButtonGlowType", "TitleBar");
|
||||
if(helpButtonGlowType=="TitleBar")
|
||||
helpButtonGlowColor = options->color(Options::TitleBar);
|
||||
else if(helpButtonGlowType=="TitleBlend")
|
||||
helpButtonGlowColor = options->color(Options::TitleBlend);
|
||||
else // if( helpButtonGlowType=="Custom" )
|
||||
helpButtonGlowColor = conf.readColorEntry(
|
||||
"helpButtonGlowColor", &defaultButtonColor);
|
||||
|
||||
QString iconifyButtonGlowType =
|
||||
conf.readEntry("iconifyButtonGlowType", "TitleBar");
|
||||
if(iconifyButtonGlowType=="TitleBar")
|
||||
iconifyButtonGlowColor = options->color(Options::TitleBar);
|
||||
else if(iconifyButtonGlowType=="TitleBlend")
|
||||
iconifyButtonGlowColor = options->color(Options::TitleBlend);
|
||||
else // if( iconifyButtonGlowType=="Custom" )
|
||||
iconifyButtonGlowColor = conf.readColorEntry(
|
||||
"iconifyButtonGlowColor", &defaultButtonColor);
|
||||
|
||||
QString maximizeButtonGlowType =
|
||||
conf.readEntry("maximizeButtonGlowType", "TitleBar");
|
||||
if(maximizeButtonGlowType=="TitleBar")
|
||||
maximizeButtonGlowColor = options->color(Options::TitleBar);
|
||||
else if(maximizeButtonGlowType=="TitleBlend")
|
||||
maximizeButtonGlowColor = options->color(Options::TitleBlend);
|
||||
else // if( maximizeButtonGlowType=="Custom" )
|
||||
maximizeButtonGlowColor = conf.readColorEntry(
|
||||
"maximizeButtonGlowColor", &defaultButtonColor);
|
||||
|
||||
QString closeButtonGlowType =
|
||||
conf.readEntry("closeButtonGlowType", "Custom");
|
||||
if(closeButtonGlowType=="TitleBar")
|
||||
closeButtonGlowColor = options->color(Options::TitleBar);
|
||||
else if(closeButtonGlowType=="TitleBlend")
|
||||
closeButtonGlowColor = options->color(Options::TitleBlend);
|
||||
else // if( closeButtonGlowType=="Custom" )
|
||||
closeButtonGlowColor = conf.readColorEntry(
|
||||
"closeButtonGlowColor", &defaultCloseButtonColor);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
GlowClientGlobals *GlowClientGlobals::m_instance = 0;
|
||||
|
||||
GlowClientGlobals *GlowClientGlobals::instance()
|
||||
{
|
||||
// cerr << "GlowClientGlobals " << "instance " << endl;
|
||||
if( ! m_instance )
|
||||
m_instance = new GlowClientGlobals();
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
QPixmap *GlowClientGlobals::getPixmap(
|
||||
int type, bool isActive, bool isLeft, bool isSmall)
|
||||
{
|
||||
int modifiers = 0;
|
||||
modifiers |= isActive ? Active : NotActive;
|
||||
modifiers |= isLeft ? PosLeft : PosRight;
|
||||
modifiers |= isSmall ? SizeSmall : SizeNormal;
|
||||
return m_pixmapMap[type][modifiers];
|
||||
}
|
||||
|
||||
GlowClientGlobals::GlowClientGlobals()
|
||||
{
|
||||
// cerr << "GlowClientGlobals " << "GlowClientGlobals " << endl;
|
||||
buttonFactory = new GlowButtonFactory();
|
||||
readConfig();
|
||||
createPixmaps();
|
||||
}
|
||||
|
||||
void GlowClientGlobals::readConfig()
|
||||
{
|
||||
config = new GlowClientConfig();
|
||||
config->load();
|
||||
}
|
||||
|
||||
void GlowClientGlobals::createPixmaps()
|
||||
{
|
||||
// cerr << "GlowClientGlobals " << "createPixmaps " << endl;
|
||||
int types[] = { StickyOn, StickyOff, Help, Iconify, MaximizeOn,
|
||||
MaximizeOff, Close };
|
||||
for( int i=0; i<7; i++ )
|
||||
{
|
||||
int modifiers[] = {
|
||||
Active | PosLeft | SizeSmall,
|
||||
Active | PosLeft | SizeNormal,
|
||||
Active | PosRight | SizeSmall,
|
||||
Active | PosRight | SizeNormal,
|
||||
NotActive | PosLeft | SizeSmall,
|
||||
NotActive | PosLeft | SizeNormal,
|
||||
NotActive | PosRight | SizeSmall,
|
||||
NotActive | PosRight | SizeNormal };
|
||||
for( int j=0; j<8; j++ )
|
||||
m_pixmapMap[types[i]][modifiers[j]] =
|
||||
createPixmap(types[i],modifiers[j]);
|
||||
}
|
||||
}
|
||||
|
||||
QPixmap *GlowClientGlobals::createPixmap(int type, int modifiers)
|
||||
{
|
||||
// cerr << "GlowClientGlobals " << "createPixmap " << endl;
|
||||
bool isActive;
|
||||
if( modifiers & Active )
|
||||
isActive = true;
|
||||
else
|
||||
isActive = false;
|
||||
int size;
|
||||
if( modifiers & SizeNormal )
|
||||
size = DEFAULT_BITMAP_SIZE;
|
||||
else
|
||||
size = SMALL_BITMAP_SIZE;
|
||||
QColorGroup g;
|
||||
if( modifiers & PosLeft )
|
||||
g = options->colorGroup(Options::TitleBar, isActive);
|
||||
else
|
||||
g = options->colorGroup(Options::ButtonBg, isActive);
|
||||
QColor c;
|
||||
if( qGray(g.background().rgb()) <= 127 ) // background is dark
|
||||
c = Qt::white;
|
||||
else // background is light
|
||||
c = Qt::black;
|
||||
|
||||
QPixmap pm(size, size);
|
||||
pm.fill(c);
|
||||
|
||||
if( type == StickyOn )
|
||||
{
|
||||
if( modifiers & SizeNormal )
|
||||
pm.setMask(QBitmap(size, size, stickyon_bits, true));
|
||||
else
|
||||
pm.setMask(QBitmap(size, size, stickyon_small_bits, true));
|
||||
return buttonFactory->createGlowButtonPixmap(
|
||||
QSize(size,size), config->stickyButtonGlowColor, g, pm);
|
||||
}
|
||||
else if( type==StickyOff )
|
||||
{
|
||||
if( modifiers & SizeNormal )
|
||||
pm.setMask(QBitmap(size, size, stickyoff_bits, true));
|
||||
else
|
||||
pm.setMask(QBitmap(size, size, stickyoff_small_bits, true));
|
||||
return buttonFactory->createGlowButtonPixmap(
|
||||
QSize(size,size), config->stickyButtonGlowColor, g, pm);
|
||||
}
|
||||
else if( type==Help )
|
||||
{
|
||||
if( modifiers & SizeNormal )
|
||||
pm.setMask(QBitmap(size, size, help_bits, true));
|
||||
else
|
||||
pm.setMask(QBitmap(size, size, help_small_bits, true));
|
||||
return buttonFactory->createGlowButtonPixmap(
|
||||
QSize(size,size), config->helpButtonGlowColor, g, pm);
|
||||
}
|
||||
else if( type==Iconify )
|
||||
{
|
||||
if( modifiers & SizeNormal )
|
||||
pm.setMask(QBitmap(size, size, minimize_bits, true));
|
||||
else
|
||||
pm.setMask(QBitmap(size, size, minimize_small_bits, true));
|
||||
return buttonFactory->createGlowButtonPixmap(
|
||||
QSize(size,size), config->iconifyButtonGlowColor, g, pm);
|
||||
}
|
||||
else if( type==MaximizeOn )
|
||||
{
|
||||
if( modifiers & SizeNormal )
|
||||
pm.setMask(QBitmap(size, size, maximizeon_bits, true));
|
||||
else
|
||||
pm.setMask(QBitmap(size, size, maximizeon_small_bits, true));
|
||||
return buttonFactory->createGlowButtonPixmap(
|
||||
QSize(size,size), config->maximizeButtonGlowColor, g, pm);
|
||||
}
|
||||
else if( type==MaximizeOff )
|
||||
{
|
||||
if( modifiers & SizeNormal )
|
||||
pm.setMask(QBitmap(size, size, maximizeoff_bits, true));
|
||||
else
|
||||
pm.setMask(QBitmap(size, size, maximizeoff_small_bits, true));
|
||||
return buttonFactory->createGlowButtonPixmap(
|
||||
QSize(size,size), config->maximizeButtonGlowColor, g, pm);
|
||||
}
|
||||
else if( type==Close )
|
||||
{
|
||||
if( modifiers & SizeNormal )
|
||||
pm.setMask(QBitmap(size, size, close_bits, true));
|
||||
else
|
||||
pm.setMask(QBitmap(size, size, close_small_bits, true));
|
||||
return buttonFactory->createGlowButtonPixmap(
|
||||
QSize(size,size), config->closeButtonGlowColor, g, pm);
|
||||
}
|
||||
else // should not happen
|
||||
return buttonFactory->createGlowButtonPixmap(
|
||||
QSize(size,size), Qt::white, g, QPixmap());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
GlowClient::GlowClient(KWinInternal::Workspace *ws, WId w,
|
||||
QWidget *parent, const char* name )
|
||||
: KWinInternal::Client(ws, w, parent, name),
|
||||
m_stickyButton(0), m_helpButton(0), m_minimizeButton(0),
|
||||
m_maximizeButton(0), m_closeButton(0),
|
||||
m_mainLayout(0)
|
||||
{
|
||||
cerr << "GlowClient " << "GlowClient " << endl;
|
||||
createButtons();
|
||||
resetLayout();
|
||||
repaint();
|
||||
|
||||
QObject::connect(KWinInternal::options, SIGNAL(resetClients()),
|
||||
this, SLOT(slotReset()));
|
||||
}
|
||||
|
||||
GlowClient::~GlowClient()
|
||||
{
|
||||
}
|
||||
|
||||
void GlowClient::resizeEvent( QResizeEvent *e )
|
||||
{
|
||||
Client::resizeEvent(e);
|
||||
doShape();
|
||||
repaint(false);
|
||||
}
|
||||
|
||||
void GlowClient::paintEvent( QPaintEvent *e )
|
||||
{
|
||||
cerr << "GlowClient " << "paintEvent " << endl;
|
||||
Client::paintEvent(e);
|
||||
|
||||
QRect r_this = rect();
|
||||
QRect r_title = m_titleSpacer->geometry();
|
||||
QColorGroup titleCg =
|
||||
options->colorGroup(Options::TitleBar, isActive());
|
||||
QColorGroup titleBlendCg =
|
||||
options->colorGroup(Options::TitleBlend, isActive());
|
||||
QColorGroup cg = colorGroup();
|
||||
QColor titleColor = options->color(Options::TitleBar, isActive());
|
||||
QColor titleBlendColor = options->color(Options::TitleBlend, isActive());
|
||||
QPainter painter;
|
||||
|
||||
painter.begin(this);
|
||||
painter.setPen(cg.dark());
|
||||
// draw an outer dark frame
|
||||
painter.drawRect(r_this);
|
||||
// draw a line below title bar
|
||||
painter.drawLine(0, r_title.height()-1,
|
||||
r_this.width()-1, r_title.height()-1);
|
||||
painter.end();
|
||||
|
||||
// pixmap for title bar
|
||||
// int titleBufferWidth = r_title.x() + r_title.width();
|
||||
int titleBufferWidth = width()-2;
|
||||
int titleBufferHeight = r_title.height()-2;
|
||||
KPixmap titleBuffer(QSize(titleBufferWidth, titleBufferHeight));
|
||||
KPixmapEffect::gradient(titleBuffer, titleColor, titleBlendColor,
|
||||
KPixmapEffect::DiagonalGradient);
|
||||
painter.begin(&titleBuffer);
|
||||
painter.setFont(options->font(isActive()));
|
||||
painter.setPen(options->color(Options::Font, isActive()));
|
||||
painter.drawText(r_title.x(), 0,
|
||||
r_title.x()+r_title.width(), titleBufferHeight,
|
||||
Qt::AlignLeft | Qt::AlignVCenter, caption() );
|
||||
painter.end();
|
||||
|
||||
painter.begin(this);
|
||||
painter.drawPixmap(1, 1, titleBuffer);
|
||||
painter.end();
|
||||
}
|
||||
|
||||
void GlowClient::showEvent( QShowEvent *e )
|
||||
{
|
||||
Client::showEvent(e);
|
||||
doShape();
|
||||
repaint(false);
|
||||
}
|
||||
|
||||
void GlowClient::mouseDoubleClickEvent( QMouseEvent *e )
|
||||
{
|
||||
if( m_titleSpacer->geometry().contains(e->pos()) )
|
||||
workspace()->performWindowOperation(
|
||||
this, options->operationTitlebarDblClick());
|
||||
}
|
||||
|
||||
void GlowClient::captionChange(const QString&)
|
||||
{
|
||||
repaint(false);
|
||||
}
|
||||
|
||||
void GlowClient::activeChange(bool)
|
||||
{
|
||||
updateButtonPixmaps();
|
||||
repaint(false);
|
||||
}
|
||||
|
||||
void GlowClient::iconChange()
|
||||
{
|
||||
// we have no (t yet an) icon button, so do nothing
|
||||
}
|
||||
|
||||
void GlowClient::stickyChange(bool on)
|
||||
{
|
||||
if(on)
|
||||
m_stickyButton->setPixmap(
|
||||
GlowClientGlobals::instance()->getPixmap(
|
||||
GlowClientGlobals::StickyOn, isActive(),
|
||||
isLeft(m_stickyButton), isTool()));
|
||||
else
|
||||
m_stickyButton->setPixmap(
|
||||
GlowClientGlobals::instance()->getPixmap(
|
||||
GlowClientGlobals::StickyOff, isActive(),
|
||||
isLeft(m_stickyButton), isTool()));
|
||||
}
|
||||
|
||||
void GlowClient::maximizeChange(bool on)
|
||||
{
|
||||
if(on)
|
||||
m_maximizeButton->setPixmap(
|
||||
GlowClientGlobals::instance()->getPixmap(
|
||||
GlowClientGlobals::MaximizeOn, isActive(),
|
||||
isLeft(m_maximizeButton), isTool()));
|
||||
else
|
||||
m_maximizeButton->setPixmap(
|
||||
GlowClientGlobals::instance()->getPixmap(
|
||||
GlowClientGlobals::MaximizeOff, isActive(),
|
||||
isLeft(m_maximizeButton), isTool()));
|
||||
}
|
||||
|
||||
Client::MousePosition GlowClient::mousePosition(const QPoint &pos) const
|
||||
{
|
||||
// we have no resize handle yet so we return the default position
|
||||
return Client::mousePosition(pos);
|
||||
}
|
||||
|
||||
void GlowClient::createButtons()
|
||||
{
|
||||
cerr << "GlowClient " << "createButtons " << endl;
|
||||
GlowClientGlobals *globals = GlowClientGlobals::instance();
|
||||
GlowButtonFactory *factory = globals->buttonFactory;
|
||||
int s = isTool() ? SMALL_BITMAP_SIZE : DEFAULT_BITMAP_SIZE;
|
||||
QSize size(s,s);
|
||||
|
||||
m_stickyButton = factory->createGlowButton(
|
||||
this, "StickyButton", "Sticky");
|
||||
m_stickyButton->setFixedSize(size);
|
||||
QObject::connect(m_stickyButton, SIGNAL(clicked()),
|
||||
this, SLOT(toggleSticky()));
|
||||
m_buttonList.insert(m_buttonList.end(), m_stickyButton);
|
||||
|
||||
m_helpButton = factory->createGlowButton(
|
||||
this, "HelpButton", "Help");
|
||||
m_helpButton->setFixedSize(size);
|
||||
QObject::connect(m_helpButton, SIGNAL(clicked()),
|
||||
this, SLOT(contextHelp()));
|
||||
m_buttonList.insert(m_buttonList.end(), m_helpButton);
|
||||
|
||||
m_minimizeButton = factory->createGlowButton(
|
||||
this, "IconifyButton", "Minimize");
|
||||
m_minimizeButton->setFixedSize(size);
|
||||
QObject::connect(m_minimizeButton, SIGNAL(clicked()),
|
||||
this, SLOT(iconify()));
|
||||
m_buttonList.insert(m_buttonList.end(), m_minimizeButton);
|
||||
|
||||
m_maximizeButton=factory->createGlowButton(
|
||||
this, "MaximizeButton", "Maximize");
|
||||
m_maximizeButton->setFixedSize(size);
|
||||
QObject::connect(m_maximizeButton, SIGNAL(clicked(int)),
|
||||
this, SLOT(slotMaximize(int)));
|
||||
m_buttonList.insert(m_buttonList.end(), m_maximizeButton);
|
||||
|
||||
m_closeButton = factory->createGlowButton(
|
||||
this, "CloseButton", "Close");
|
||||
m_closeButton->setFixedSize(size);
|
||||
QObject::connect(m_closeButton, SIGNAL(clicked()),
|
||||
this, SLOT(closeWindow()));
|
||||
m_buttonList.insert(m_buttonList.end(), m_closeButton);
|
||||
}
|
||||
|
||||
void GlowClient::resetLayout()
|
||||
{
|
||||
cerr << "GlowClient " << "resetLayout " << endl;
|
||||
const unsigned int sideMargin = 2;
|
||||
const unsigned int bottomMargin = 2;
|
||||
const unsigned int titleVMargin = 2;
|
||||
|
||||
QFontMetrics fm(KWinInternal::options->font(isActive(),isTool()));
|
||||
unsigned int titleHeight = QMAX(15, fm.height()+2*titleVMargin);
|
||||
if( titleHeight%2 != 0 )
|
||||
titleHeight+=1;
|
||||
|
||||
if( m_mainLayout )
|
||||
delete m_mainLayout;
|
||||
m_mainLayout = new QVBoxLayout(this, 0, 0);
|
||||
|
||||
// update button positions and colors
|
||||
updateButtonPositions();
|
||||
updateButtonPixmaps();
|
||||
|
||||
QHBoxLayout *topLayout = new QHBoxLayout(m_mainLayout, 1);
|
||||
topLayout->addSpacing(sideMargin);
|
||||
for( unsigned int i=0; i<m_leftButtonList.size(); i++ )
|
||||
topLayout->addWidget(m_leftButtonList[i], Qt::AlignVCenter);
|
||||
topLayout->addSpacing(sideMargin);
|
||||
|
||||
m_titleSpacer = new QSpacerItem(0, titleHeight,
|
||||
QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
topLayout->addItem(m_titleSpacer);
|
||||
|
||||
topLayout->addSpacing(sideMargin);
|
||||
for( unsigned int i=0; i<m_rightButtonList.size(); i++ )
|
||||
topLayout->addWidget(m_rightButtonList[i], Qt::AlignVCenter);
|
||||
topLayout->addSpacing(sideMargin);
|
||||
|
||||
QHBoxLayout *midLayout = new QHBoxLayout(m_mainLayout, 0);
|
||||
midLayout->addSpacing(sideMargin);
|
||||
midLayout->addWidget(windowWrapper());
|
||||
midLayout->addSpacing(sideMargin);
|
||||
|
||||
m_mainLayout->addSpacing(bottomMargin);
|
||||
m_mainLayout->setStretchFactor(topLayout, 0);
|
||||
m_mainLayout->setStretchFactor(midLayout, 1);
|
||||
}
|
||||
|
||||
void GlowClient::updateButtonPositions()
|
||||
{
|
||||
cerr << "GlowClient " << "updateButtonPositions " << endl;
|
||||
QString buttons = options->titleButtonsLeft() + "|"
|
||||
+ options->titleButtonsRight();
|
||||
vector<GlowButton*> *buttonList = &m_leftButtonList;
|
||||
|
||||
// hide all buttons
|
||||
for( unsigned int i=0; i<m_buttonList.size(); i++ )
|
||||
m_buttonList[i]->hide();
|
||||
|
||||
m_leftButtonList.clear();
|
||||
m_rightButtonList.clear();
|
||||
|
||||
for( unsigned int i=0; i<buttons.length(); i++ )
|
||||
{
|
||||
char c = buttons[i].latin1();
|
||||
GlowButton *button = 0;
|
||||
if( c=='S' ) // sticky
|
||||
button = m_stickyButton;
|
||||
else if( c=='H' && providesContextHelp() ) // help
|
||||
button = m_helpButton;
|
||||
else if( c=='I' && isMinimizable() ) // iconify
|
||||
button = m_minimizeButton;
|
||||
else if( c=='A' && isMaximizable() ) // maximize
|
||||
button = m_maximizeButton;
|
||||
else if( c=='X' ) // close
|
||||
button= m_closeButton;
|
||||
else if( c=='|' )
|
||||
buttonList = &m_rightButtonList;
|
||||
|
||||
if(button)
|
||||
{
|
||||
button->show(); // show visible buttons
|
||||
buttonList->insert(buttonList->end(), button);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GlowClient::updateButtonPixmaps()
|
||||
{
|
||||
cerr << "GlowClient " << "updateButtonPixmaps " << endl;
|
||||
GlowClientGlobals *globals = GlowClientGlobals::instance();
|
||||
|
||||
if( isSticky() )
|
||||
m_stickyButton->setPixmap(globals->getPixmap(
|
||||
GlowClientGlobals::StickyOn, isActive(),
|
||||
isLeft(m_stickyButton), isTool()));
|
||||
else
|
||||
m_stickyButton->setPixmap(globals->getPixmap(
|
||||
GlowClientGlobals::StickyOff, isActive(),
|
||||
isLeft(m_stickyButton), isTool()));
|
||||
|
||||
m_helpButton->setPixmap(globals->getPixmap(
|
||||
GlowClientGlobals::Help, isActive(),
|
||||
isLeft(m_helpButton), isTool()));
|
||||
|
||||
m_minimizeButton->setPixmap(globals->getPixmap(
|
||||
GlowClientGlobals::Iconify, isActive(),
|
||||
isLeft(m_minimizeButton), isTool()));
|
||||
|
||||
if( isMaximized() )
|
||||
m_maximizeButton->setPixmap(globals->getPixmap(
|
||||
GlowClientGlobals::MaximizeOn, isActive(),
|
||||
isLeft(m_maximizeButton), isTool()));
|
||||
else
|
||||
m_maximizeButton->setPixmap(globals->getPixmap(
|
||||
GlowClientGlobals::MaximizeOff, isActive(),
|
||||
isLeft(m_maximizeButton), isTool()));
|
||||
|
||||
m_closeButton->setPixmap(globals->getPixmap(
|
||||
GlowClientGlobals::Close, isActive(),
|
||||
isLeft(m_closeButton), isTool()));
|
||||
}
|
||||
|
||||
void GlowClient::doShape()
|
||||
{
|
||||
QRegion mask(QRect(0, 0, width(), height()));
|
||||
mask -= QRect(0, 0, 1, 1);
|
||||
mask -= QRect(width()-1, 0, 1, 1);
|
||||
mask -= QRect(0, height()-1, 1, 1);
|
||||
mask -= QRect(width()-1, height()-1, 1, 1);
|
||||
setMask(mask);
|
||||
}
|
||||
|
||||
bool GlowClient::isLeft(GlowButton *button)
|
||||
{
|
||||
for( unsigned int i=0; i<m_leftButtonList.size(); i++ )
|
||||
if( m_leftButtonList[i] == button )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GlowClient::isRight(GlowButton *button)
|
||||
{
|
||||
for( unsigned int i=0; i<m_rightButtonList.size(); i++ )
|
||||
if( m_rightButtonList[i] == button )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void GlowClient::slotReset()
|
||||
{
|
||||
resetLayout();
|
||||
repaint(false);
|
||||
}
|
||||
|
||||
void GlowClient::slotMaximize(int button)
|
||||
{
|
||||
if(button == QMouseEvent::RightButton)
|
||||
maximize(MaximizeHorizontal);
|
||||
else if(button == QMouseEvent::MidButton)
|
||||
maximize(MaximizeVertical);
|
||||
else // if(button == QMouseEvent::LeftButton)
|
||||
maximize(MaximizeFull);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
Client * allocate(Workspace * ws, WId w)
|
||||
{
|
||||
return new GlowClient(ws, w);
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
Workspace::self()->slotResetAllClientsDelayed();
|
||||
}
|
||||
|
||||
void deinit()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#include "glowclient.moc"
|
||||
|
137
clients/glow/glowclient.h
Normal file
137
clients/glow/glowclient.h
Normal file
|
@ -0,0 +1,137 @@
|
|||
/***************************************************************************
|
||||
glowclient.h - description
|
||||
-------------------
|
||||
begin : Thu Sep 6 2001
|
||||
copyright : (C) 2001 by Henning Burchardt
|
||||
email : h_burchardt@gmx.de
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef GLOW_CLIENT_H
|
||||
#define GLOW_CLIENT_H
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <kwin/client.h>
|
||||
#include <kwin/kwinbutton.h>
|
||||
|
||||
class QPixmap;
|
||||
class QBitmap;
|
||||
class QTimer;
|
||||
class QVBoxLayout;
|
||||
class QSpacerItem;
|
||||
|
||||
namespace KWinInternal
|
||||
{
|
||||
|
||||
class GlowButton;
|
||||
class GlowButtonFactory;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class GlowClientConfig
|
||||
{
|
||||
public:
|
||||
GlowClientConfig();
|
||||
|
||||
void load();
|
||||
|
||||
QColor stickyButtonGlowColor;
|
||||
QColor helpButtonGlowColor;
|
||||
QColor iconifyButtonGlowColor;
|
||||
QColor maximizeButtonGlowColor;
|
||||
QColor closeButtonGlowColor;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class GlowClientGlobals
|
||||
{
|
||||
public:
|
||||
enum PixmapType { StickyOn, StickyOff, Help, Iconify, MaximizeOn,
|
||||
MaximizeOff, Close };
|
||||
enum PixmapModifiers { Active=2, NotActive=4, PosLeft=8, PosRight=16,
|
||||
SizeNormal=32, SizeSmall=64 };
|
||||
|
||||
static GlowClientGlobals *instance();
|
||||
|
||||
QPixmap *getPixmap(int type, bool isActive, bool isLeft, bool isSmall);
|
||||
|
||||
GlowClientConfig *config;
|
||||
GlowButtonFactory *buttonFactory;
|
||||
|
||||
private:
|
||||
static GlowClientGlobals *m_instance;
|
||||
|
||||
GlowClientGlobals();
|
||||
|
||||
void readConfig();
|
||||
void createPixmaps();
|
||||
QPixmap *createPixmap(int type, int modifiers);
|
||||
|
||||
map< int, map< int, QPixmap* > > m_pixmapMap;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class GlowClient : public KWinInternal::Client
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
GlowClient( KWinInternal::Workspace *ws, WId w,
|
||||
QWidget *parent=0, const char* name=0 );
|
||||
~GlowClient();
|
||||
|
||||
protected:
|
||||
virtual void resizeEvent( QResizeEvent * );
|
||||
virtual void paintEvent( QPaintEvent * );
|
||||
virtual void showEvent( QShowEvent * );
|
||||
virtual void mouseDoubleClickEvent( QMouseEvent * );
|
||||
virtual void captionChange( const QString& name );
|
||||
virtual void maximizeChange(bool m);
|
||||
virtual void activeChange(bool);
|
||||
virtual void iconChange();
|
||||
virtual void stickyChange(bool on);
|
||||
virtual MousePosition mousePosition(const QPoint &) const;
|
||||
|
||||
private:
|
||||
vector<GlowButton*> m_buttonList;
|
||||
vector<GlowButton*> m_leftButtonList;
|
||||
vector<GlowButton*> m_rightButtonList;
|
||||
GlowButton *m_stickyButton;
|
||||
GlowButton *m_helpButton;
|
||||
GlowButton *m_minimizeButton;
|
||||
GlowButton *m_maximizeButton;
|
||||
GlowButton *m_closeButton;
|
||||
QVBoxLayout *m_mainLayout;
|
||||
QSpacerItem *m_titleSpacer;
|
||||
|
||||
void createButtons();
|
||||
void updateButtonPositions();
|
||||
/**
|
||||
* Before this method is called we have to update the button
|
||||
* positions with updateButtonPositions() because the pixmaps
|
||||
* depend on the position
|
||||
*/
|
||||
void updateButtonPixmaps();
|
||||
void resetLayout();
|
||||
void doShape();
|
||||
bool isLeft(GlowButton *button);
|
||||
bool isRight(GlowButton *button);
|
||||
|
||||
protected slots:
|
||||
void slotReset();
|
||||
void slotMaximize(int button);
|
||||
};
|
||||
|
||||
}; // namespace
|
||||
|
||||
#endif
|
11
clients/glow/kwinglowrc
Normal file
11
clients/glow/kwinglowrc
Normal file
|
@ -0,0 +1,11 @@
|
|||
[General]
|
||||
stickyButtonGlowType=TitleBar
|
||||
stickyButtonGlowColor=255,255,255
|
||||
helpButtonGlowType=TitleBar
|
||||
helpButtonGlowColor=255,255,255
|
||||
iconifyButtonGlowType=TitleBar
|
||||
iconifyButtonGlowColor=255,255,255
|
||||
maximizeButtonGlowType=TitleBar
|
||||
maximizeButtonGlowColor=255,255,255
|
||||
closeButtonGlowType=Custom
|
||||
closeButtonGlowColor=255,0,0
|
Loading…
Reference in a new issue