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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
//
// C++ Implementation: mallorybutton
//
// Description:
//
//
// Author: Remi Villatel <maxilys@tele2.fr>, (C) 2005
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include <tqtooltip.h>
#include <tqpainter.h>
#include <tqpixmap.h>
#include "enums.h"
#include "mallorybutton.h"
#include "malloryhandler.h"
#include "pixmaps.h"
#include "embeddata.h"
MalloryButton::MalloryButton(MalloryClient *parent, const char *name, const TQString& tip, ButtonType type) : TQButton(parent->widget(), name), m_client(parent), m_lastMouse(0), m_type(type), hover(false), isOnAllDesktops(false), isMaximized(false)
{
TQToolTip::add(this, tip);
setCursor(arrowCursor);
setBackgroundMode(NoBackground);
setFixedSize(MalloryHandler::buttonSize(), MalloryHandler::buttonSize());
}
MalloryButton::~MalloryButton()
{
}
void MalloryButton::setTipText(const TQString &tip)
{
TQToolTip::remove(this);
TQToolTip::add(this, tip);
}
TQSize MalloryButton::sizeHint() const // MXLS
{
return TQSize(MalloryHandler::buttonSize(), MalloryHandler::buttonSize());
}
void MalloryButton::enterEvent(TQEvent *e)
{
hover = true;
repaint(false);
TQButton::enterEvent(e);
}
void MalloryButton::leaveEvent(TQEvent *e)
{
hover = false;
repaint(false);
TQButton::enterEvent(e);
}
void MalloryButton::mousePressEvent(TQMouseEvent *e)
{
m_lastMouse = e->button();
TQMouseEvent me(e->type(), e->pos(), e->globalPos(), LeftButton, e->state());
TQButton::mousePressEvent(&me);
}
void MalloryButton::mouseReleaseEvent(TQMouseEvent *e)
{
m_lastMouse = e->button();
TQMouseEvent me(e->type(), e->pos(), e->globalPos(), LeftButton, e->state());
TQButton::mouseReleaseEvent(&me);
}
void MalloryButton::drawButton(TQPainter *painter)
{
if (!MalloryHandler::initialized())
return;
bool active = m_client->isActive();
int buttonSize = MalloryHandler::buttonSize();
int ofx = (buttonSize-16)/2;
int ofy = ofx;
// Crush the bug the hard way!
if (ofy < 2)
ofy = 2;
TQPixmap pufferPixmap;
pufferPixmap.resize(buttonSize, buttonSize);
TQPainter pufferPainter(&pufferPixmap);
pufferPainter.drawPixmap(0, 0, active ? *Pixmaps::active_button_ground : *Pixmaps::inactive_button_ground);
if (m_type == ButtonMenu)
{
TQPixmap menu_icon = m_client->icon().pixmap(TQIconSet::Small, TQIconSet::Normal);
pufferPainter.drawPixmap(ofx, ofy, menu_icon);
}
else
{
// Paint the little icon on the buttons.
// Lotsa trouble with this! Stupid scope!
if (hover && !isDown())
{
// Hover
if (m_type == ButtonHelp)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_help_hover : *Pixmaps::inactive_help_hover);
else if (m_type == ButtonMax)
{
if (isMaximized)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_restore_hover : *Pixmaps::inactive_restore_hover);
else
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_max_hover : *Pixmaps::inactive_max_hover);
}
else if (m_type == ButtonMin)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_min_hover : *Pixmaps::inactive_min_hover);
else if (m_type == ButtonClose)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_close_hover : *Pixmaps::inactive_close_hover);
else if (m_type == ButtonOnAllDesktops)
{
if (isOnAllDesktops)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_unsticky_hover : *Pixmaps::inactive_unsticky_hover);
else
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_sticky_hover : *Pixmaps::inactive_sticky_hover);
}
else if (m_type == ButtonAbove)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_above_hover : *Pixmaps::inactive_above_hover);
else if (m_type == ButtonBelow)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_below_hover : *Pixmaps::inactive_below_hover);
}
else if (isDown())
{
// Sunken
if (m_type == ButtonHelp)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_help_sunken : *Pixmaps::inactive_help_sunken);
else if (m_type == ButtonMax)
{
if (isMaximized)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_restore_sunken : *Pixmaps::inactive_restore_sunken);
else
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_max_sunken : *Pixmaps::inactive_max_sunken);
}
else if (m_type == ButtonMin)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_min_sunken : *Pixmaps::inactive_min_sunken);
else if (m_type == ButtonClose)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_close_sunken : *Pixmaps::inactive_close_sunken);
else if (m_type == ButtonOnAllDesktops)
{
if (isOnAllDesktops)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_unsticky_sunken : *Pixmaps::inactive_unsticky_sunken);
else
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_sticky_sunken : *Pixmaps::inactive_sticky_sunken);
}
else if (m_type == ButtonAbove)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_above_sunken : *Pixmaps::inactive_above_sunken);
else if (m_type == ButtonBelow)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_below_sunken : *Pixmaps::inactive_below_sunken);
}
else
{
// Normal
if (m_type == ButtonHelp)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_help_normal : *Pixmaps::inactive_help_normal);
else if (m_type == ButtonMax)
{
if (isMaximized)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_restore_normal : *Pixmaps::inactive_restore_normal);
else
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_max_normal : *Pixmaps::inactive_max_normal);
}
else if (m_type == ButtonMin)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_min_normal : *Pixmaps::inactive_min_normal);
else if (m_type == ButtonClose)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_close_normal : *Pixmaps::inactive_close_normal);
else if (m_type == ButtonOnAllDesktops)
{
if (isOnAllDesktops)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_unsticky_normal : *Pixmaps::inactive_unsticky_normal);
else
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_sticky_normal : *Pixmaps::inactive_sticky_normal);
}
else if (m_type == ButtonAbove)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_above_normal : *Pixmaps::inactive_above_normal);
else if (m_type == ButtonBelow)
pufferPainter.drawImage(ofx, ofy, active ? *Pixmaps::active_below_normal : *Pixmaps::inactive_below_normal);
}
}
pufferPainter.end();
painter->drawPixmap(0, 0, pufferPixmap);
}
#include "mallorybutton.moc"
|