add more spacing
[personal-kdebase.git] / workspace / kwin / clients / web / Web.cpp
blobb9dbba6961aa61ab67621e76f5549f619777ed91
1 /*
2 'Web' kwin client
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.
23 #include "Web.h"
25 #include <QPainter>
26 //Added by qt3to4:
27 #include <QPaintEvent>
29 #include <kconfiggroup.h>
31 #include "WebButton.h"
33 extern "C"
35 KDE_EXPORT KDecorationFactory *create_factory()
37 return new Web::WebFactory();
41 namespace Web {
43 WebClient::WebClient(KDecorationBridge* bridge, KDecorationFactory* factory)
44 : KCommonDecoration(bridge, factory)
46 // Empty.
49 WebClient::~WebClient()
51 // Empty.
54 QString WebClient::visibleName() const
56 return i18n("Web");
59 QString WebClient::defaultButtonsLeft() const
61 return "S";
64 QString WebClient::defaultButtonsRight() const
66 return "HIA__X";
69 bool WebClient::decorationBehaviour(DecorationBehaviour behaviour) const
71 switch (behaviour) {
72 case DB_MenuClose:
73 return false;
75 case DB_WindowMask:
76 return true;
78 case DB_ButtonHide:
79 return true;
81 default:
82 return KCommonDecoration::decorationBehaviour(behaviour);
86 int WebClient::layoutMetric(LayoutMetric lm, bool respectWindowState, const KCommonDecorationButton *btn) const
88 // bool maximized = maximizeMode()==MaximizeFull && !options()->moveResizeMaximizedWindows();
90 switch (lm) {
91 case LM_BorderLeft:
92 case LM_BorderRight:
93 case LM_BorderBottom:
94 return borderSize_;
96 case LM_TitleEdgeLeft:
97 case LM_TitleEdgeRight:
98 case LM_TitleEdgeTop:
99 case LM_TitleEdgeBottom:
100 return 0;
102 case LM_TitleBorderLeft:
103 case LM_TitleBorderRight:
104 return 0;
106 case LM_TitleHeight:
107 case LM_ButtonWidth:
108 case LM_ButtonHeight:
109 return titleHeight_;
111 case LM_ButtonSpacing:
112 return 0;
114 default:
115 return KCommonDecoration::layoutMetric(lm, respectWindowState, btn);
119 KCommonDecorationButton *WebClient::createButton(ButtonType type)
121 switch (type) {
122 case MenuButton:
123 return new WebButton(MenuButton, this, shape_);
125 case OnAllDesktopsButton:
126 return new WebButton(OnAllDesktopsButton, this, shape_);
128 case HelpButton:
129 return new WebButton(HelpButton, this, shape_);
131 case MinButton:
132 return new WebButton(MinButton, this, shape_);
134 case MaxButton:
135 return new WebButton(MaxButton, this, shape_);
137 case CloseButton:
138 return new WebButton(CloseButton, this, shape_);
140 case AboveButton:
141 return new WebButton(AboveButton, this, shape_);
143 case BelowButton:
144 return new WebButton(BelowButton, this, shape_);
146 case ShadeButton:
147 return new WebButton(ShadeButton, this, shape_);
149 default:
150 return 0;
154 void
155 WebClient::init()
157 // title height
158 const int textVMargin = 2;
159 QFontMetrics fm(options()->font(isActive(), isToolWindow()));
161 // border size
162 switch(options()->preferredBorderSize( factory())) {
163 case BorderLarge:
164 borderSize_ = 8;
165 break;
166 case BorderVeryLarge:
167 borderSize_ = 12;
168 break;
169 case BorderHuge:
170 borderSize_ = 18;
171 break;
172 case BorderVeryHuge:
173 borderSize_ = 27;
174 break;
175 case BorderOversized:
176 borderSize_ = 40;
177 break;
178 case BorderNormal:
179 default:
180 borderSize_ = 4;
182 titleHeight_ = qMax(qMax(14, fm.height() + textVMargin * 2), borderSize_);
183 if (0 != titleHeight_ % 2)
184 titleHeight_ += 1;
186 KConfig c("kwinwebrc");
187 shape_ = c.group("General").readEntry("Shape", true);
189 KCommonDecoration::init();
192 void
193 WebClient::reset( unsigned long changed )
195 if (changed & SettingColors)
197 // repaint the whole thing
198 widget()->repaint();
199 } else if (changed & SettingFont) {
200 // font has changed -- update title height
201 // 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)
206 titleHeight_ += 1;
208 widget()->repaint();
211 KCommonDecoration::reset(changed);
214 void
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) );
228 titleRect.setTop(1);
230 QPainter p(widget());
232 p.setPen(Qt::black);
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);
241 p.drawRect(r);
243 p.setClipRegion(pe->region());
245 p.fillRect(titleRect, options()->color(ColorTitleBar, isActive()));
247 if (shape_)
249 int r(width());
250 int b(height());
252 // Draw edge of top-left corner inside the area removed by the mask.
254 p.drawPoint(3, 1);
255 p.drawPoint(4, 1);
256 p.drawPoint(2, 2);
257 p.drawPoint(1, 3);
258 p.drawPoint(1, 4);
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()
294 if (!shape_)
295 return;
297 QRegion mask(0, 0, width(), height());
299 int r(width());
300 int b(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);
330 setMask(mask);
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;
347 if (needHardReset) {
348 return true;
349 } else {
350 resetDecorations(changed);
351 return false;
355 bool WebFactory::supports( Ability ability ) const
357 switch( ability )
359 // announce
360 case AbilityAnnounceButtons:
361 case AbilityAnnounceColors:
362 // buttons
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:
373 // colors:
374 case AbilityColorTitleBack:
375 case AbilityColorTitleFore:
376 return true;
377 default:
378 return false;
382 QList< WebFactory::BorderSize > WebFactory::borderSizes() const
383 { // the list must be sorted
384 return QList< BorderSize >() << BorderNormal << BorderLarge <<
385 BorderVeryLarge << BorderHuge << BorderVeryHuge << BorderOversized;
390 #include "Web.moc"
391 // vim:ts=2:sw=2:tw=78:set et:
392 // kate: indent-width 2; replace-tabs on; tab-width 2; space-indent on;