4 Copyright (C) 2005 Sandro Giessl <sandro@giessl.com>
5 Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
27 #include <QPaintEvent>
29 #include <kconfiggroup.h>
31 #include "WebButton.h"
35 KDE_EXPORT KDecorationFactory
*create_factory()
37 return new Web::WebFactory();
43 WebClient::WebClient(KDecorationBridge
* bridge
, KDecorationFactory
* factory
)
44 : KCommonDecoration(bridge
, factory
)
49 WebClient::~WebClient()
54 QString
WebClient::visibleName() const
59 QString
WebClient::defaultButtonsLeft() const
64 QString
WebClient::defaultButtonsRight() const
69 bool WebClient::decorationBehaviour(DecorationBehaviour behaviour
) const
82 return KCommonDecoration::decorationBehaviour(behaviour
);
86 int WebClient::layoutMetric(LayoutMetric lm
, bool respectWindowState
, const KCommonDecorationButton
*btn
) const
88 // bool maximized = maximizeMode()==MaximizeFull && !options()->moveResizeMaximizedWindows();
96 case LM_TitleEdgeLeft
:
97 case LM_TitleEdgeRight
:
99 case LM_TitleEdgeBottom
:
102 case LM_TitleBorderLeft
:
103 case LM_TitleBorderRight
:
108 case LM_ButtonHeight
:
111 case LM_ButtonSpacing
:
115 return KCommonDecoration::layoutMetric(lm
, respectWindowState
, btn
);
119 KCommonDecorationButton
*WebClient::createButton(ButtonType type
)
123 return new WebButton(MenuButton
, this, shape_
);
125 case OnAllDesktopsButton
:
126 return new WebButton(OnAllDesktopsButton
, this, shape_
);
129 return new WebButton(HelpButton
, this, shape_
);
132 return new WebButton(MinButton
, this, shape_
);
135 return new WebButton(MaxButton
, this, shape_
);
138 return new WebButton(CloseButton
, this, shape_
);
141 return new WebButton(AboveButton
, this, shape_
);
144 return new WebButton(BelowButton
, this, shape_
);
147 return new WebButton(ShadeButton
, this, shape_
);
158 const int textVMargin
= 2;
159 QFontMetrics
fm(options()->font(isActive(), isToolWindow()));
162 switch(options()->preferredBorderSize( factory())) {
166 case BorderVeryLarge
:
175 case BorderOversized
:
182 titleHeight_
= qMax(qMax(14, fm
.height() + textVMargin
* 2), borderSize_
);
183 if (0 != titleHeight_
% 2)
186 KConfig
c("kwinwebrc");
187 shape_
= c
.group("General").readEntry("Shape", true);
189 KCommonDecoration::init();
193 WebClient::reset( unsigned long changed
)
195 if (changed
& SettingColors
)
197 // repaint the whole thing
199 } else if (changed
& SettingFont
) {
200 // font has changed -- update title height
202 const int textVMargin
= 2;
203 QFontMetrics
fm(options()->font(isActive(), isToolWindow()));
204 titleHeight_
= qMax(qMax(14, fm
.height() + textVMargin
* 2), borderSize_
);
205 if (0 != titleHeight_
% 2)
211 KCommonDecoration::reset(changed
);
215 WebClient::paintEvent(QPaintEvent
* pe
)
217 int r_x
, r_y
, r_x2
, r_y2
;
218 widget()->rect().getCoords(&r_x
, &r_y
, &r_x2
, &r_y2
);
219 const int titleEdgeLeft
= layoutMetric(LM_TitleEdgeLeft
);
220 const int titleEdgeTop
= layoutMetric(LM_TitleEdgeTop
);
221 const int titleEdgeRight
= layoutMetric(LM_TitleEdgeRight
);
222 const int titleEdgeBottom
= layoutMetric(LM_TitleEdgeBottom
);
223 const int ttlHeight
= layoutMetric(LM_TitleHeight
);
224 const int titleEdgeBottomBottom
= r_y
+titleEdgeTop
+ttlHeight
+titleEdgeBottom
-1;
225 QRect titleRect
= QRect(r_x
+titleEdgeLeft
+buttonsLeftWidth()+1, r_y
+titleEdgeTop
,
226 r_x2
-titleEdgeRight
-buttonsRightWidth()-(r_x
+titleEdgeLeft
+buttonsLeftWidth()+1),
227 titleEdgeBottomBottom
-(r_y
+titleEdgeTop
) );
230 QPainter
p(widget());
233 QPalette pal
= options()->palette(ColorFrame
, isActive());
234 pal
.setCurrentColorGroup( QPalette::Active
);
235 p
.setBrush( pal
.background() );
237 p
.setClipRegion(pe
->region() - titleRect
);
239 QRect
r(widget()->rect());
240 r
.adjust(0, 0, -1, -1);
243 p
.setClipRegion(pe
->region());
245 p
.fillRect(titleRect
, options()->color(ColorTitleBar
, isActive()));
252 // Draw edge of top-left corner inside the area removed by the mask.
260 // Draw edge of top-right corner inside the area removed by the mask.
262 p
.drawPoint(r
- 5, 1);
263 p
.drawPoint(r
- 4, 1);
264 p
.drawPoint(r
- 3, 2);
265 p
.drawPoint(r
- 2, 3);
266 p
.drawPoint(r
- 2, 4);
268 // Draw edge of bottom-left corner inside the area removed by the mask.
270 p
.drawPoint(1, b
- 5);
271 p
.drawPoint(1, b
- 4);
272 p
.drawPoint(2, b
- 3);
273 p
.drawPoint(3, b
- 2);
274 p
.drawPoint(4, b
- 2);
276 // Draw edge of bottom-right corner inside the area removed by the mask.
278 p
.drawPoint(r
- 2, b
- 5);
279 p
.drawPoint(r
- 2, b
- 4);
280 p
.drawPoint(r
- 3, b
- 3);
281 p
.drawPoint(r
- 4, b
- 2);
282 p
.drawPoint(r
- 5, b
- 2);
285 p
.setFont(options()->font(isActive(), isToolWindow()));
287 p
.setPen(options()->color(ColorFont
, isActive()));
289 p
.drawText(titleRect
, Qt::AlignCenter
, caption());
292 void WebClient::updateWindowShape()
297 QRegion
mask(0, 0, width(), height());
302 // Remove top-left corner.
304 mask
-= QRegion(0, 0, 5, 1);
305 mask
-= QRegion(0, 1, 3, 1);
306 mask
-= QRegion(0, 2, 2, 1);
307 mask
-= QRegion(0, 3, 1, 2);
309 // Remove top-right corner.
311 mask
-= QRegion(r
- 5, 0, 5, 1);
312 mask
-= QRegion(r
- 3, 1, 3, 1);
313 mask
-= QRegion(r
- 2, 2, 2, 1);
314 mask
-= QRegion(r
- 1, 3, 1, 2);
316 // Remove bottom-left corner.
318 mask
-= QRegion(0, b
- 5, 1, 3);
319 mask
-= QRegion(0, b
- 3, 2, 1);
320 mask
-= QRegion(0, b
- 2, 3, 1);
321 mask
-= QRegion(0, b
- 1, 5, 1);
323 // Remove bottom-right corner.
325 mask
-= QRegion(r
- 5, b
- 1, 5, 1);
326 mask
-= QRegion(r
- 3, b
- 2, 3, 1);
327 mask
-= QRegion(r
- 2, b
- 3, 2, 1);
328 mask
-= QRegion(r
- 1, b
- 5, 1, 2);
333 KDecoration
* WebFactory::createDecoration( KDecorationBridge
* b
)
335 return(new WebClient(b
, this))->decoration();
338 bool WebFactory::reset(unsigned long changed
)
340 // Do we need to "hit the wooden hammer" ?
341 bool needHardReset
= true;
342 if ((changed
& ~(SettingColors
| SettingFont
| SettingButtons
)) == 0 )
344 needHardReset
= false;
350 resetDecorations(changed
);
355 bool WebFactory::supports( Ability ability
) const
360 case AbilityAnnounceButtons
:
361 case AbilityAnnounceColors
:
363 case AbilityButtonOnAllDesktops
:
364 case AbilityButtonHelp
:
365 case AbilityButtonMinimize
:
366 case AbilityButtonMaximize
:
367 case AbilityButtonClose
:
368 case AbilityButtonMenu
:
369 case AbilityButtonAboveOthers
:
370 case AbilityButtonBelowOthers
:
371 case AbilityButtonShade
:
372 case AbilityButtonSpacer
:
374 case AbilityColorTitleBack
:
375 case AbilityColorTitleFore
:
382 QList
< WebFactory::BorderSize
> WebFactory::borderSizes() const
383 { // the list must be sorted
384 return QList
< BorderSize
>() << BorderNormal
<< BorderLarge
<<
385 BorderVeryLarge
<< BorderHuge
<< BorderVeryHuge
<< BorderOversized
;
391 // vim:ts=2:sw=2:tw=78:set et:
392 // kate: indent-width 2; replace-tabs on; tab-width 2; space-indent on;