summaryrefslogtreecommitdiffstats
path: root/kwin-styles/glow/glowbutton.h
blob: 3d4f5e1d0f7d8569184051ef2c93f5dbce57004f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/***************************************************************************
                          glowbutton.h  -  description
                             -------------------
    begin                : Thu Sep 14 2001
    copyright            : (C) 2001 by Henning Burchardt
    email                : h_burchardt@gmx.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 <vector>
#include <qmap.h>
#include <qbutton.h>

class QPixmap;
class QBitmap;
class QTimer;
class QString;

namespace Glow
{

class PixmapCache
{
public:
	static const QPixmap* find(const QString& key);
	static void insert(const QString& key, const QPixmap *pixmap);
	static void erase(const QString& key);
	static void clear();
private:
	static QMap<QString, const QPixmap*> m_pixmapMap;
};


//-----------------------------------------------------------------------------

class GlowButton : public QButton
{
	Q_OBJECT

public:
	GlowButton(QWidget *parent, const char* name, const QString& tip, const int realizeBtns);
	~GlowButton();

	void setTipText( const QString& tip );

	QString getPixmapName() const;
	ButtonState lastButton() const;

	/** Sets the name of the pixmap in the pixmap cache.
	 * If no background pixmap is wanted use QString::null as name. */
	void setPixmapName(const QString& pixmapName);

protected:
	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 _steps;
	QString m_pixmapName;

	QTimer *m_timer;
	int m_pos;
	TimerStatus m_timerStatus;

	int m_realizeButtons;
	ButtonState _last_button;
};

//-----------------------------------------------------------------------------

class GlowButtonFactory
{
public:
	GlowButtonFactory();

	int getSteps();

	/**
	 * Sets the number of pixmaps used to create the glow effect of the
	 * glow buttons.
	 */
	void setSteps(int steps);

	/**
	 * Creates a background pixmap for a glow button.
	 * The pixmap will consist of sub pixmaps of the size of the button which
	 * are placed one below the other. Each sub pixmap is copied on the button
	 * in succession to create the glow effect. The last sub pixmap is used
	 * when the button is pressed.
	 */
	QPixmap * createGlowButtonPixmap(
				const QImage & bg_image,
//				const QImage & bg_alpha_image,
				const QImage & fg_image,
				const QImage & glow_image,
				const QColor & color,
				const QColor & glow_color);

	GlowButton* createGlowButton(
		QWidget *parent, const char* name, const QString& tip, const int realizeBtns = Qt::LeftButton);

private:
	int _steps;
};

} // namespace

#endif