From 85baad95f169c73786937ee960ca53f2e3052934 Mon Sep 17 00:00:00 2001 From: Henning Burchardt Date: Fri, 14 Sep 2001 12:16:51 +0000 Subject: [PATCH] svn path=/trunk/kdebase/kwin/; revision=114199 --- clients/glow/Makefile.am | 23 ++ clients/glow/bitmaps.h | 97 ++++++ clients/glow/glow.desktop | 3 + clients/glow/glowbutton.cpp | 333 +++++++++++++++++++ clients/glow/glowbutton.h | 113 +++++++ clients/glow/glowclient.cpp | 621 ++++++++++++++++++++++++++++++++++++ clients/glow/glowclient.h | 137 ++++++++ clients/glow/kwinglowrc | 11 + 8 files changed, 1338 insertions(+) create mode 100644 clients/glow/Makefile.am create mode 100644 clients/glow/bitmaps.h create mode 100644 clients/glow/glow.desktop create mode 100644 clients/glow/glowbutton.cpp create mode 100644 clients/glow/glowbutton.h create mode 100644 clients/glow/glowclient.cpp create mode 100644 clients/glow/glowclient.h create mode 100644 clients/glow/kwinglowrc diff --git a/clients/glow/Makefile.am b/clients/glow/Makefile.am new file mode 100644 index 0000000000..5ec64781d5 --- /dev/null +++ b/clients/glow/Makefile.am @@ -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 diff --git a/clients/glow/bitmaps.h b/clients/glow/bitmaps.h new file mode 100644 index 0000000000..6eaebc0770 --- /dev/null +++ b/clients/glow/bitmaps.h @@ -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 }; diff --git a/clients/glow/glow.desktop b/clients/glow/glow.desktop new file mode 100644 index 0000000000..843ab4d6cd --- /dev/null +++ b/clients/glow/glow.desktop @@ -0,0 +1,3 @@ +[Desktop Entry] +Name=Glow +X-KDE-Library=libkwinglow diff --git a/clients/glow/glowbutton.cpp b/clients/glow/glowbutton.cpp new file mode 100644 index 0000000000..f66dd98ecf --- /dev/null +++ b/clients/glow/glowbutton.cpp @@ -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 +#include +#include +#include +#include +#include +#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 > intensityField; + intensityField.resize(h); + for( int i=0; isetMask(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 >& 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 > intensityField; + intensityField.resize(h); + for( int i=0; i + +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 >& intensityField, float intensity ); + static QPixmap drawSimpleRoundButton( + const QSize& size, const QColorGroup& group); + static QBitmap drawSimpleRoundButtonMask(const QSize& size); +}; + +}; // namespace + +#endif \ No newline at end of file diff --git a/clients/glow/glowclient.cpp b/clients/glow/glowclient.cpp new file mode 100644 index 0000000000..521ffc7888 --- /dev/null +++ b/clients/glow/glowclient.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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; iaddWidget(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; iaddWidget(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 *buttonList = &m_leftButtonList; + + // hide all buttons + for( unsigned int i=0; ihide(); + + m_leftButtonList.clear(); + m_rightButtonList.clear(); + + for( unsigned int i=0; ishow(); // 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; islotResetAllClientsDelayed(); + } + + void deinit() + { + } +} + +#include "glowclient.moc" + diff --git a/clients/glow/glowclient.h b/clients/glow/glowclient.h new file mode 100644 index 0000000000..a40f2a0d48 --- /dev/null +++ b/clients/glow/glowclient.h @@ -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 +#include +#include +#include + +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 m_buttonList; + vector m_leftButtonList; + vector 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 diff --git a/clients/glow/kwinglowrc b/clients/glow/kwinglowrc new file mode 100644 index 0000000000..aeccdcb847 --- /dev/null +++ b/clients/glow/kwinglowrc @@ -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