summaryrefslogtreecommitdiffstats
path: root/twin-styles/glow/glowbutton.h
blob: 9bd56de6e6d68bc9a20ca63cce72751e53c624b1 (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
129
/***************************************************************************
                          glowbutton.h  -  description
                             -------------------
    begin                : Thu Sep 14 2001
    copyright            : (C) 2001 by Henning Burchardt
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 <tqmap.h>
#include <tqbutton.h>

class TQPixmap;
class TQBitmap;
class TQTimer;
class TQString;

namespace Glow
{

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


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

class GlowButton : public TQButton
{
	TQ_OBJECT
  

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

	void setTipText( const TQString& tip );

	TQString getPixmapName() const;
	ButtonState lastButton() const;

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

protected:
	virtual void paintEvent( TQPaintEvent * );
	virtual void enterEvent( TQEvent * );
	virtual void leaveEvent( TQEvent * );
	virtual void mousePressEvent( TQMouseEvent * );
	virtual void mouseReleaseEvent( TQMouseEvent * );

protected slots:
	void slotTimeout();

private:
	enum TimerStatus { Run, Stop };

	int m_updateTime;
	int _steps;
	TQString m_pixmapName;

	TQTimer *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.
	 */
	TQPixmap * createGlowButtonPixmap(
				const TQImage & bg_image,
//				const TQImage & bg_alpha_image,
				const TQImage & fg_image,
				const TQImage & glow_image,
				const TQColor & color,
				const TQColor & glow_color);

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

private:
	int _steps;
};

} // namespace

#endif