/*************************************************************************** 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