2001-05-06 19:03:20 +00:00
|
|
|
/*
|
|
|
|
'Web' kwin client
|
|
|
|
|
2005-03-21 19:57:25 +00:00
|
|
|
Copyright (C) 2005 Sandro Giessl <sandro@giessl.com>
|
2001-05-06 19:03:20 +00:00
|
|
|
Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
|
|
|
|
|
|
|
|
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
|
2005-10-05 08:44:32 +00:00
|
|
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2005-07-04 19:02:09 +00:00
|
|
|
Boston, MA 02110-1301, USA.
|
2001-05-06 19:03:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <qpainter.h>
|
2005-07-28 14:59:42 +00:00
|
|
|
//Added by qt3to4:
|
|
|
|
#include <QPaintEvent>
|
2001-05-06 19:03:20 +00:00
|
|
|
|
|
|
|
#include <kconfig.h>
|
|
|
|
|
|
|
|
#include "Web.h"
|
|
|
|
#include "WebButton.h"
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
2004-11-21 16:19:09 +00:00
|
|
|
KDE_EXPORT KDecorationFactory *create_factory()
|
2001-05-06 19:03:20 +00:00
|
|
|
{
|
2003-09-18 14:59:47 +00:00
|
|
|
return new Web::WebFactory();
|
2001-05-06 19:03:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-27 18:08:20 +00:00
|
|
|
namespace Web {
|
2003-09-18 14:59:47 +00:00
|
|
|
|
|
|
|
WebClient::WebClient(KDecorationBridge* bridge, KDecorationFactory* factory)
|
2005-03-21 19:57:25 +00:00
|
|
|
: KCommonDecoration(bridge, factory)
|
2001-05-06 19:03:20 +00:00
|
|
|
{
|
2003-09-18 14:59:47 +00:00
|
|
|
// Empty.
|
|
|
|
}
|
|
|
|
|
|
|
|
WebClient::~WebClient()
|
|
|
|
{
|
|
|
|
// Empty.
|
|
|
|
}
|
|
|
|
|
2005-03-21 19:57:25 +00:00
|
|
|
QString WebClient::visibleName() const
|
|
|
|
{
|
|
|
|
return i18n("Web");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString WebClient::defaultButtonsLeft() const
|
|
|
|
{
|
|
|
|
return "S";
|
|
|
|
}
|
|
|
|
|
|
|
|
QString 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-26 13:18:32 +00:00
|
|
|
int WebClient::layoutMetric(LayoutMetric lm, bool respectWindowState, const KCommonDecorationButton *btn) const
|
2005-03-21 19:57:25 +00:00
|
|
|
{
|
|
|
|
// 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:
|
2005-03-26 13:18:32 +00:00
|
|
|
return KCommonDecoration::layoutMetric(lm, respectWindowState, btn);
|
2005-03-21 19:57:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-18 14:59:47 +00:00
|
|
|
void
|
|
|
|
WebClient::init()
|
|
|
|
{
|
|
|
|
// title height
|
2003-11-20 09:05:00 +00:00
|
|
|
const int textVMargin = 2;
|
2005-03-21 19:57:25 +00:00
|
|
|
QFontMetrics fm(options()->font(isActive(), isToolWindow()));
|
2003-09-18 14:59:47 +00:00
|
|
|
|
|
|
|
// border size
|
2003-09-24 12:41:56 +00:00
|
|
|
switch(options()->preferredBorderSize( factory())) {
|
2003-09-18 14:59:47 +00:00
|
|
|
case BorderLarge:
|
|
|
|
borderSize_ = 8;
|
|
|
|
break;
|
|
|
|
case BorderVeryLarge:
|
|
|
|
borderSize_ = 12;
|
|
|
|
break;
|
|
|
|
case BorderHuge:
|
2003-09-23 14:40:18 +00:00
|
|
|
borderSize_ = 18;
|
|
|
|
break;
|
|
|
|
case BorderVeryHuge:
|
|
|
|
borderSize_ = 27;
|
|
|
|
break;
|
|
|
|
case BorderOversized:
|
|
|
|
borderSize_ = 40;
|
2003-09-18 14:59:47 +00:00
|
|
|
break;
|
|
|
|
case BorderNormal:
|
|
|
|
default:
|
|
|
|
borderSize_ = 4;
|
|
|
|
}
|
2003-09-23 14:40:18 +00:00
|
|
|
titleHeight_ = QMAX(QMAX(14, fm.height() + textVMargin * 2), borderSize_);
|
2005-03-21 19:57:25 +00:00
|
|
|
if (0 != titleHeight_ % 2)
|
|
|
|
titleHeight_ += 1;
|
2001-05-06 19:03:20 +00:00
|
|
|
|
2005-03-21 19:57:25 +00:00
|
|
|
KConfig c("kwinwebrc");
|
|
|
|
c.setGroup("General");
|
|
|
|
shape_ = c.readBoolEntry("Shape", true);
|
2001-05-06 19:03:20 +00:00
|
|
|
|
2005-03-21 19:57:25 +00:00
|
|
|
KCommonDecoration::init();
|
2001-05-06 19:03:20 +00:00
|
|
|
}
|
|
|
|
|
2003-09-18 14:59:47 +00:00
|
|
|
void
|
|
|
|
WebClient::reset( unsigned long changed )
|
2001-05-06 19:03:20 +00:00
|
|
|
{
|
2003-09-18 14:59:47 +00:00
|
|
|
if (changed & SettingColors)
|
|
|
|
{
|
|
|
|
// repaint the whole thing
|
|
|
|
widget()->repaint(false);
|
|
|
|
} else if (changed & SettingFont) {
|
|
|
|
// font has changed -- update title height
|
|
|
|
// title height
|
2005-05-06 09:20:08 +00:00
|
|
|
const int textVMargin = 2;
|
2005-03-21 19:57:25 +00:00
|
|
|
QFontMetrics fm(options()->font(isActive(), isToolWindow()));
|
|
|
|
titleHeight_ = QMAX(QMAX(14, fm.height() + textVMargin * 2), borderSize_);
|
|
|
|
if (0 != titleHeight_ % 2)
|
|
|
|
titleHeight_ += 1;
|
|
|
|
|
2003-09-18 14:59:47 +00:00
|
|
|
widget()->repaint(false);
|
|
|
|
}
|
|
|
|
|
2005-03-21 19:57:25 +00:00
|
|
|
KCommonDecoration::reset(changed);
|
2001-05-06 19:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-08-27 18:08:20 +00:00
|
|
|
WebClient::paintEvent(QPaintEvent * pe)
|
2001-05-06 19:03:20 +00:00
|
|
|
{
|
2005-03-21 19:57:25 +00:00
|
|
|
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;
|
|
|
|
QRect titleRect = QRect(r_x+titleEdgeLeft+buttonsLeftWidth(), r_y+titleEdgeTop,
|
|
|
|
r_x2-titleEdgeRight-buttonsRightWidth()-(r_x+titleEdgeLeft+buttonsLeftWidth()),
|
|
|
|
titleEdgeBottomBottom-(r_y+titleEdgeTop) );
|
2001-05-06 19:03:20 +00:00
|
|
|
titleRect.setTop(1);
|
|
|
|
|
2003-09-18 14:59:47 +00:00
|
|
|
QPainter p(widget());
|
2001-05-06 19:03:20 +00:00
|
|
|
|
|
|
|
p.setPen(Qt::black);
|
2003-09-18 14:59:47 +00:00
|
|
|
p.setBrush(options()->colorGroup(ColorFrame, isActive()).background());
|
2001-05-06 19:03:20 +00:00
|
|
|
|
|
|
|
p.setClipRegion(pe->region() - titleRect);
|
|
|
|
|
2003-09-18 14:59:47 +00:00
|
|
|
p.drawRect(widget()->rect());
|
2001-05-06 19:03:20 +00:00
|
|
|
|
|
|
|
p.setClipRegion(pe->region());
|
|
|
|
|
2003-09-18 14:59:47 +00:00
|
|
|
p.fillRect(titleRect, options()->color(ColorTitleBar, isActive()));
|
2001-05-06 19:03:20 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2005-03-21 19:57:25 +00:00
|
|
|
p.setFont(options()->font(isActive(), isToolWindow()));
|
2001-05-19 01:58:07 +00:00
|
|
|
|
2003-09-18 14:59:47 +00:00
|
|
|
p.setPen(options()->color(ColorFont, isActive()));
|
2001-05-19 01:58:07 +00:00
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
p.drawText(titleRect, Qt::AlignCenter, caption());
|
2001-05-06 19:03:20 +00:00
|
|
|
}
|
|
|
|
|
2005-03-21 19:57:25 +00:00
|
|
|
void WebClient::updateWindowShape()
|
2001-05-06 19:03:20 +00:00
|
|
|
{
|
|
|
|
if (!shape_)
|
|
|
|
return;
|
2001-09-11 06:53:46 +00:00
|
|
|
|
2001-05-06 19:03:20 +00:00
|
|
|
QRegion mask(0, 0, width(), height());
|
|
|
|
|
|
|
|
int r(width());
|
|
|
|
int b(height());
|
|
|
|
|
|
|
|
// Remove top-left corner.
|
|
|
|
|
|
|
|
mask -= QRegion(0, 0, 5, 1);
|
|
|
|
mask -= QRegion(0, 1, 3, 1);
|
|
|
|
mask -= QRegion(0, 2, 2, 1);
|
|
|
|
mask -= QRegion(0, 3, 1, 2);
|
|
|
|
|
|
|
|
// Remove top-right corner.
|
|
|
|
|
|
|
|
mask -= QRegion(r - 5, 0, 5, 1);
|
|
|
|
mask -= QRegion(r - 3, 1, 3, 1);
|
|
|
|
mask -= QRegion(r - 2, 2, 2, 1);
|
|
|
|
mask -= QRegion(r - 1, 3, 1, 2);
|
|
|
|
|
|
|
|
// Remove bottom-left corner.
|
|
|
|
|
|
|
|
mask -= QRegion(0, b - 5, 1, 3);
|
|
|
|
mask -= QRegion(0, b - 3, 2, 1);
|
|
|
|
mask -= QRegion(0, b - 2, 3, 1);
|
|
|
|
mask -= QRegion(0, b - 1, 5, 1);
|
|
|
|
|
|
|
|
// Remove bottom-right corner.
|
|
|
|
|
|
|
|
mask -= QRegion(r - 5, b - 1, 5, 1);
|
|
|
|
mask -= QRegion(r - 3, b - 2, 3, 1);
|
|
|
|
mask -= QRegion(r - 2, b - 3, 2, 1);
|
|
|
|
mask -= QRegion(r - 1, b - 5, 1, 2);
|
|
|
|
|
|
|
|
setMask(mask);
|
|
|
|
}
|
|
|
|
|
2003-09-18 14:59:47 +00:00
|
|
|
KDecoration* WebFactory::createDecoration( KDecorationBridge* b )
|
|
|
|
{
|
|
|
|
return(new WebClient(b, this));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebFactory::reset(unsigned long changed)
|
2001-05-06 19:03:20 +00:00
|
|
|
{
|
2003-09-18 14:59:47 +00:00
|
|
|
// Do we need to "hit the wooden hammer" ?
|
|
|
|
bool needHardReset = true;
|
|
|
|
if (changed & SettingColors || changed & SettingFont)
|
|
|
|
{
|
|
|
|
needHardReset = false;
|
2005-03-21 19:57:25 +00:00
|
|
|
} else if (changed & SettingButtons) {
|
|
|
|
// handled by KCommonDecoration
|
|
|
|
needHardReset = false;
|
2003-09-18 14:59:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (needHardReset) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
resetDecorations(changed);
|
|
|
|
return false;
|
|
|
|
}
|
2001-05-06 19:03:20 +00:00
|
|
|
}
|
|
|
|
|
2004-11-05 15:33:09 +00:00
|
|
|
bool WebFactory::supports( Ability ability )
|
|
|
|
{
|
|
|
|
switch( ability )
|
|
|
|
{
|
|
|
|
case AbilityAnnounceButtons:
|
|
|
|
case AbilityButtonOnAllDesktops:
|
|
|
|
case AbilityButtonHelp:
|
|
|
|
case AbilityButtonMinimize:
|
|
|
|
case AbilityButtonMaximize:
|
|
|
|
case AbilityButtonClose:
|
2005-03-21 19:57:25 +00:00
|
|
|
case AbilityButtonMenu:
|
|
|
|
case AbilityButtonAboveOthers:
|
|
|
|
case AbilityButtonBelowOthers:
|
|
|
|
case AbilityButtonShade:
|
2004-11-05 15:33:09 +00:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
QList< WebFactory::BorderSize > WebFactory::borderSizes() const
|
2003-09-24 12:41:56 +00:00
|
|
|
{ // the list must be sorted
|
2005-07-28 14:59:42 +00:00
|
|
|
return QList< BorderSize >() << BorderNormal << BorderLarge <<
|
2003-09-24 12:41:56 +00:00
|
|
|
BorderVeryLarge << BorderHuge << BorderVeryHuge << BorderOversized;
|
|
|
|
}
|
|
|
|
|
2003-07-26 10:41:28 +00:00
|
|
|
}
|
2002-08-27 18:08:20 +00:00
|
|
|
|
2001-05-06 19:03:20 +00:00
|
|
|
#include "Web.moc"
|
|
|
|
// vim:ts=2:sw=2:tw=78:set et:
|
2005-03-21 19:57:25 +00:00
|
|
|
// kate: indent-width 2; replace-tabs on; tab-width 2; space-indent on;
|