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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
/*
'Web' twin client
Copyright (C) 2005 Sandro Giessl <[email protected]>
Copyright (C) 2001 Rik Hemsley (rikkus) <[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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <tqpainter.h>
#include <tdeconfig.h>
#include "Web.h"
#include "WebButton.h"
extern "C"
{
TDE_EXPORT KDecorationFactory *create_factory()
{
return new Web::WebFactory();
}
}
namespace Web {
WebClient::WebClient(KDecorationBridge* bridge, KDecorationFactory* factory)
: KCommonDecoration(bridge, factory)
{
// Empty.
}
WebClient::~WebClient()
{
// Empty.
}
TQString WebClient::visibleName() const
{
return i18n("Web");
}
TQString WebClient::defaultButtonsLeft() const
{
return "S";
}
TQString WebClient::defaultButtonsRight() const
{
return "HIAX";
}
bool WebClient::decorationBehaviour(DecorationBehaviour behaviour) const
{
switch (behaviour) {
case DB_MenuClose:
return false;
case DB_WindowMask:
return true;
case DB_ButtonHide:
return true;
default:
return KCommonDecoration::decorationBehaviour(behaviour);
}
}
int WebClient::layoutMetric(LayoutMetric lm, bool respectWindowState, const KCommonDecorationButton *btn) const
{
// bool maximized = maximizeMode()==MaximizeFull && !options()->moveResizeMaximizedWindows();
switch (lm) {
case LM_BorderLeft:
case LM_BorderRight:
case LM_BorderBottom:
return borderSize_;
case LM_TitleEdgeLeft:
case LM_TitleEdgeRight:
case LM_TitleEdgeTop:
case LM_TitleEdgeBottom:
return 0;
case LM_TitleBorderLeft:
case LM_TitleBorderRight:
return 0;
case LM_TitleHeight:
case LM_ButtonWidth:
case LM_ButtonHeight:
return titleHeight_;
case LM_ButtonSpacing:
return 0;
case LM_ExplicitButtonSpacer:
return 0;
default:
return KCommonDecoration::layoutMetric(lm, respectWindowState, btn);
}
}
KCommonDecorationButton *WebClient::createButton(ButtonType type)
{
switch (type) {
case MenuButton:
return new WebButton(MenuButton, this, "menu", shape_);
case OnAllDesktopsButton:
return new WebButton(OnAllDesktopsButton, this, "on_all_desktops", shape_);
case HelpButton:
return new WebButton(HelpButton, this, "help", shape_);
case MinButton:
return new WebButton(MinButton, this, "minimize", shape_);
case MaxButton:
return new WebButton(MaxButton, this, "maximize", shape_);
case CloseButton:
return new WebButton(CloseButton, this, "close", shape_);
case AboveButton:
return new WebButton(AboveButton, this, "above", shape_);
case BelowButton:
return new WebButton(BelowButton, this, "below", shape_);
case ShadeButton:
return new WebButton(ShadeButton, this, "shade", shape_);
default:
return 0;
}
}
void
WebClient::init()
{
// title height
const int textVMargin = 2;
TQFontMetrics fm(options()->font(isActive(), isToolWindow()));
// border size
switch(options()->preferredBorderSize( factory())) {
case BorderLarge:
borderSize_ = 8;
break;
case BorderVeryLarge:
borderSize_ = 12;
break;
case BorderHuge:
borderSize_ = 18;
break;
case BorderVeryHuge:
borderSize_ = 27;
break;
case BorderOversized:
borderSize_ = 40;
break;
case BorderNormal:
default:
borderSize_ = 4;
}
titleHeight_ = TQMAX(TQMAX(14, fm.height() + textVMargin * 2), borderSize_);
if (0 != titleHeight_ % 2)
titleHeight_ += 1;
TDEConfig c("twinwebrc");
c.setGroup("General");
shape_ = c.readBoolEntry("Shape", true);
KCommonDecoration::init();
}
void
WebClient::reset( unsigned long changed )
{
if (changed & SettingColors)
{
// repaint the whole thing
widget()->repaint(false);
} else if (changed & SettingFont) {
// font has changed -- update title height
// title height
const int textVMargin = 2;
TQFontMetrics fm(options()->font(isActive(), isToolWindow()));
titleHeight_ = TQMAX(TQMAX(14, fm.height() + textVMargin * 2), borderSize_);
if (0 != titleHeight_ % 2)
titleHeight_ += 1;
widget()->repaint(false);
}
KCommonDecoration::reset(changed);
}
void
WebClient::paintEvent(TQPaintEvent * pe)
{
int r_x, r_y, r_x2, r_y2;
widget()->rect().coords(&r_x, &r_y, &r_x2, &r_y2);
const int titleEdgeLeft = layoutMetric(LM_TitleEdgeLeft);
const int titleEdgeTop = layoutMetric(LM_TitleEdgeTop);
const int titleEdgeRight = layoutMetric(LM_TitleEdgeRight);
const int titleEdgeBottom = layoutMetric(LM_TitleEdgeBottom);
const int ttlHeight = layoutMetric(LM_TitleHeight);
const int titleEdgeBottomBottom = r_y+titleEdgeTop+ttlHeight+titleEdgeBottom-1;
TQRect titleRect = TQRect(r_x+titleEdgeLeft+buttonsLeftWidth(), r_y+titleEdgeTop,
r_x2-titleEdgeRight-buttonsRightWidth()-(r_x+titleEdgeLeft+buttonsLeftWidth()),
titleEdgeBottomBottom-(r_y+titleEdgeTop) );
titleRect.setTop(1);
TQPainter p(widget());
p.setPen(TQt::black);
p.setBrush(options()->colorGroup(ColorFrame, isActive()).background());
p.setClipRegion(pe->region() - titleRect);
p.drawRect(widget()->rect());
p.setClipRegion(pe->region());
p.fillRect(titleRect, options()->color(ColorTitleBar, isActive()));
if (shape_)
{
int r(width());
int b(height());
// Draw edge of top-left corner inside the area removed by the mask.
p.drawPoint(3, 1);
p.drawPoint(4, 1);
p.drawPoint(2, 2);
p.drawPoint(1, 3);
p.drawPoint(1, 4);
// Draw edge of top-right corner inside the area removed by the mask.
p.drawPoint(r - 5, 1);
p.drawPoint(r - 4, 1);
p.drawPoint(r - 3, 2);
p.drawPoint(r - 2, 3);
p.drawPoint(r - 2, 4);
// Draw edge of bottom-left corner inside the area removed by the mask.
p.drawPoint(1, b - 5);
p.drawPoint(1, b - 4);
p.drawPoint(2, b - 3);
p.drawPoint(3, b - 2);
p.drawPoint(4, b - 2);
// Draw edge of bottom-right corner inside the area removed by the mask.
p.drawPoint(r - 2, b - 5);
p.drawPoint(r - 2, b - 4);
p.drawPoint(r - 3, b - 3);
p.drawPoint(r - 4, b - 2);
p.drawPoint(r - 5, b - 2);
}
p.setFont(options()->font(isActive(), isToolWindow()));
p.setPen(options()->color(ColorFont, isActive()));
p.drawText(titleRect, AlignCenter, caption());
}
void WebClient::updateWindowShape()
{
if (!shape_)
return;
TQRegion mask(0, 0, width(), height());
int r(width());
int b(height());
// Remove top-left corner.
mask -= TQRegion(0, 0, 5, 1);
mask -= TQRegion(0, 1, 3, 1);
mask -= TQRegion(0, 2, 2, 1);
mask -= TQRegion(0, 3, 1, 2);
// Remove top-right corner.
mask -= TQRegion(r - 5, 0, 5, 1);
mask -= TQRegion(r - 3, 1, 3, 1);
mask -= TQRegion(r - 2, 2, 2, 1);
mask -= TQRegion(r - 1, 3, 1, 2);
// Remove bottom-left corner.
mask -= TQRegion(0, b - 5, 1, 3);
mask -= TQRegion(0, b - 3, 2, 1);
mask -= TQRegion(0, b - 2, 3, 1);
mask -= TQRegion(0, b - 1, 5, 1);
// Remove bottom-right corner.
mask -= TQRegion(r - 5, b - 1, 5, 1);
mask -= TQRegion(r - 3, b - 2, 3, 1);
mask -= TQRegion(r - 2, b - 3, 2, 1);
mask -= TQRegion(r - 1, b - 5, 1, 2);
setMask(mask);
}
KDecoration* WebFactory::createDecoration( KDecorationBridge* b )
{
return(new WebClient(b, this));
}
bool WebFactory::reset(unsigned long changed)
{
// Do we need to "hit the wooden hammer" ?
bool needHardReset = true;
if (changed & SettingColors || changed & SettingFont)
{
needHardReset = false;
} else if (changed & SettingButtons) {
// handled by KCommonDecoration
needHardReset = false;
}
if (needHardReset) {
return true;
} else {
resetDecorations(changed);
return false;
}
}
bool WebFactory::supports( Ability ability )
{
switch( ability )
{
case AbilityAnnounceButtons:
case AbilityButtonOnAllDesktops:
case AbilityButtonHelp:
case AbilityButtonMinimize:
case AbilityButtonMaximize:
case AbilityButtonClose:
case AbilityButtonMenu:
case AbilityButtonAboveOthers:
case AbilityButtonBelowOthers:
case AbilityButtonShade:
return true;
default:
return false;
};
}
TQValueList< WebFactory::BorderSize > WebFactory::borderSizes() const
{ // the list must be sorted
return TQValueList< BorderSize >() << BorderNormal << BorderLarge <<
BorderVeryLarge << BorderHuge << BorderVeryHuge << BorderOversized;
}
}
#include "Web.moc"
|