2007-06-15 20:48:52 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// oxygenclient.cpp
|
|
|
|
// -------------------
|
|
|
|
// Oxygen window decoration for KDE
|
|
|
|
// -------------------
|
|
|
|
// Copyright (c) 2003, 2004 David Johnson
|
|
|
|
// Copyright (c) 2006, 2007 Casper Boemann <cbr@boemann.dk>
|
|
|
|
// Copyright (c) 2006, 2007 Riccardo Iaconelli <ruphy@fsfe.org>
|
|
|
|
//
|
|
|
|
// Please see the header file for copyright and license information.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// #ifndef OXYGENCLIENT_H
|
|
|
|
// #define OXYGENCLIENT_H
|
|
|
|
|
|
|
|
#include <kconfig.h>
|
|
|
|
#include <kglobal.h>
|
|
|
|
#include <klocale.h>
|
|
|
|
#include <kdebug.h>
|
|
|
|
|
|
|
|
#include <qbitmap.h>
|
|
|
|
#include <qlabel.h>
|
|
|
|
#include <qlayout.h>
|
|
|
|
#include <qpainter.h>
|
|
|
|
#include <qtooltip.h>
|
|
|
|
//Added by qt3to4:
|
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QResizeEvent>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QEvent>
|
|
|
|
#include <QShowEvent>
|
|
|
|
#include <QPaintEvent>
|
|
|
|
#include <QPainterPath>
|
|
|
|
#include <QTimer>
|
2007-07-16 02:12:45 +00:00
|
|
|
#include <QCache>
|
2007-06-15 20:48:52 +00:00
|
|
|
|
|
|
|
#include "oxygenclient.h"
|
|
|
|
#include "oxygenclient.moc"
|
|
|
|
#include "oxygenbutton.h"
|
|
|
|
#include "oxygen.h"
|
|
|
|
|
|
|
|
#include "definitions.cpp"
|
|
|
|
|
|
|
|
namespace Oxygen
|
|
|
|
{
|
|
|
|
|
|
|
|
// global constants
|
|
|
|
|
|
|
|
// static const int BUTTONSIZE = 18;
|
|
|
|
// static const int DECOSIZE = 8;
|
|
|
|
// static const int TITLESIZE = 18;
|
|
|
|
// static const int TFRAMESIZE = 8;
|
|
|
|
// static const int BFRAMESIZE = 7;
|
|
|
|
// static const int LFRAMESIZE = 8;
|
2007-07-17 23:35:44 +00:00
|
|
|
// static const int RFRAMESIZE = 7;BUTTONSIZE
|
2007-06-15 20:48:52 +00:00
|
|
|
// static const int FRAMEBUTTONSPACE = 67;
|
|
|
|
|
2007-07-19 01:32:16 +00:00
|
|
|
K_GLOBAL_STATIC_WITH_ARGS(OxygenHelper, globalHelper, ("OxygenDeco"))
|
2007-06-15 20:48:52 +00:00
|
|
|
|
|
|
|
void renderDot(QPainter *p, const QPointF &point, qreal diameter)
|
|
|
|
{
|
|
|
|
p->drawEllipse(QRectF(point.x()-diameter/2, point.y()-diameter/2, diameter, diameter));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OxygenClient::OxygenClient(KDecorationBridge *b, KDecorationFactory *f)
|
2007-10-10 00:05:24 +00:00
|
|
|
: KCommonDecoration(b, f), helper_(*globalHelper) { ; }
|
2007-06-15 20:48:52 +00:00
|
|
|
|
|
|
|
OxygenClient::~OxygenClient()
|
|
|
|
{
|
|
|
|
}
|
2007-09-17 18:16:26 +00:00
|
|
|
QString OxygenClient::visibleName() const
|
2007-06-15 20:48:52 +00:00
|
|
|
{
|
2007-09-17 18:16:26 +00:00
|
|
|
return i18n("Oxygen");
|
2007-06-15 20:48:52 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
QString OxygenClient::defaultButtonsLeft() const
|
2007-06-15 20:48:52 +00:00
|
|
|
{
|
2007-09-17 18:16:26 +00:00
|
|
|
return "M";
|
2007-06-15 20:48:52 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
QString OxygenClient::defaultButtonsRight() const
|
2007-06-15 20:48:52 +00:00
|
|
|
{
|
2007-09-17 18:16:26 +00:00
|
|
|
return "HIAX";
|
2007-06-15 20:48:52 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
void OxygenClient::init()
|
2007-06-15 20:48:52 +00:00
|
|
|
{
|
2007-09-17 18:16:26 +00:00
|
|
|
KCommonDecoration::init();
|
2007-06-15 20:48:52 +00:00
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
widget()->setAutoFillBackground(false);
|
|
|
|
widget()->setAttribute(Qt::WA_OpaquePaintEvent);
|
2007-10-10 00:05:24 +00:00
|
|
|
widget()->setAttribute(Qt::WA_PaintOnScreen, false);
|
2007-09-17 18:16:26 +00:00
|
|
|
}
|
2007-06-15 20:48:52 +00:00
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
bool OxygenClient::decorationBehaviour(DecorationBehaviour behaviour) const
|
2007-06-15 20:48:52 +00:00
|
|
|
{
|
2007-09-17 18:16:26 +00:00
|
|
|
switch (behaviour) {
|
|
|
|
case DB_MenuClose:
|
|
|
|
return true;//Handler()->menuClose();
|
2007-06-15 20:48:52 +00:00
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
case DB_WindowMask:
|
|
|
|
return false;
|
2007-06-15 20:48:52 +00:00
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
default:
|
|
|
|
return KCommonDecoration::decorationBehaviour(behaviour);
|
2007-06-15 20:48:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
int OxygenClient::layoutMetric(LayoutMetric lm, bool respectWindowState, const KCommonDecorationButton *btn) const
|
2007-06-15 20:48:52 +00:00
|
|
|
{
|
2007-09-17 18:16:26 +00:00
|
|
|
bool maximized = maximizeMode()==MaximizeFull && !options()->moveResizeMaximizedWindows();
|
|
|
|
|
|
|
|
switch (lm) {
|
|
|
|
case LM_BorderLeft:
|
|
|
|
case LM_BorderRight:
|
|
|
|
case LM_BorderBottom:
|
|
|
|
{
|
|
|
|
if (respectWindowState && maximized) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return BFRAMESIZE;
|
|
|
|
}
|
|
|
|
}
|
2007-06-15 20:48:52 +00:00
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
case LM_TitleEdgeTop:
|
|
|
|
{
|
|
|
|
if (respectWindowState && maximized) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return TFRAMESIZE;
|
|
|
|
}
|
|
|
|
}
|
2007-06-15 20:48:52 +00:00
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
case LM_TitleEdgeBottom:
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2007-06-15 20:48:52 +00:00
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
case LM_TitleEdgeLeft:
|
|
|
|
case LM_TitleEdgeRight:
|
|
|
|
{
|
|
|
|
if (respectWindowState && maximized) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
}
|
2007-06-15 20:48:52 +00:00
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
case LM_TitleBorderLeft:
|
|
|
|
case LM_TitleBorderRight:
|
|
|
|
return 5;
|
|
|
|
|
|
|
|
case LM_ButtonWidth:
|
|
|
|
case LM_ButtonHeight:
|
|
|
|
case LM_TitleHeight:
|
|
|
|
{
|
|
|
|
if (respectWindowState && isToolWindow()) {
|
2007-10-06 00:39:16 +00:00
|
|
|
return OXYGEN_BUTTONSIZE;
|
2007-09-17 18:16:26 +00:00
|
|
|
} else {
|
2007-10-06 00:39:16 +00:00
|
|
|
return OXYGEN_BUTTONSIZE;
|
2007-09-17 18:16:26 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-15 20:48:52 +00:00
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
case LM_ButtonSpacing:
|
|
|
|
return 1;
|
2007-06-15 20:48:52 +00:00
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
case LM_ButtonMarginTop:
|
|
|
|
return 0;
|
2007-06-15 20:48:52 +00:00
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
case LM_ExplicitButtonSpacer:
|
|
|
|
return 3;
|
2007-06-15 20:48:52 +00:00
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
default:
|
|
|
|
return KCommonDecoration::layoutMetric(lm, respectWindowState, btn);
|
|
|
|
}
|
2007-06-15 20:48:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
KCommonDecorationButton *OxygenClient::createButton(::ButtonType type)
|
2007-06-15 20:48:52 +00:00
|
|
|
{
|
2007-09-17 18:16:26 +00:00
|
|
|
switch (type) {
|
|
|
|
case MenuButton:
|
2007-10-10 00:05:24 +00:00
|
|
|
return new OxygenButton(*this, i18n("Menu"), ButtonMenu);
|
2007-06-15 20:48:52 +00:00
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
case HelpButton:
|
2007-10-10 00:05:24 +00:00
|
|
|
return new OxygenButton(*this, i18n("Help"), ButtonHelp);
|
2007-06-15 20:48:52 +00:00
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
case MinButton:
|
2007-10-10 00:05:24 +00:00
|
|
|
return new OxygenButton(*this, i18n("Minimize"), ButtonMin);
|
2007-06-15 20:48:52 +00:00
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
case MaxButton:
|
2007-10-10 00:05:24 +00:00
|
|
|
return new OxygenButton(*this, i18n("Minimize"), ButtonMax);
|
2007-06-15 20:48:52 +00:00
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
case CloseButton:
|
2007-10-10 00:05:24 +00:00
|
|
|
return new OxygenButton(*this, i18n("Minimize"), ButtonClose);
|
2007-06-15 20:48:52 +00:00
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2007-06-15 20:48:52 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 18:16:26 +00:00
|
|
|
|
2007-06-15 20:48:52 +00:00
|
|
|
void OxygenClient::paintEvent(QPaintEvent *e)
|
|
|
|
{
|
2007-07-16 02:12:45 +00:00
|
|
|
Q_UNUSED(e)
|
2007-06-15 20:48:52 +00:00
|
|
|
if (!OxygenFactory::initialized()) return;
|
|
|
|
|
|
|
|
doShape();
|
|
|
|
|
|
|
|
QPalette palette = widget()->palette();
|
|
|
|
QPainter painter(widget());
|
|
|
|
|
2007-10-10 00:25:48 +00:00
|
|
|
// Set palette to the right group. Lubos disagrees with this being a kwin
|
|
|
|
// bug, but anyway, we need the palette group to match the current window.
|
|
|
|
// Since kwin doesn't set it correctly, we have to do it ourselves.
|
2007-09-10 19:09:39 +00:00
|
|
|
if (isActive())
|
|
|
|
palette.setCurrentColorGroup(QPalette::Active);
|
|
|
|
else
|
|
|
|
palette.setCurrentColorGroup(QPalette::Inactive);
|
|
|
|
|
2007-06-15 20:48:52 +00:00
|
|
|
int x,y,w,h;
|
2007-07-16 02:12:45 +00:00
|
|
|
QRect frame = widget()->frameGeometry();
|
|
|
|
QColor color = palette.window();
|
2007-09-17 18:16:26 +00:00
|
|
|
|
|
|
|
const int titleHeight = layoutMetric(LM_TitleHeight);
|
|
|
|
const int titleTop = layoutMetric(LM_TitleEdgeTop) + frame.top();
|
|
|
|
const int titleEdgeLeft = layoutMetric(LM_TitleEdgeLeft);
|
|
|
|
const int marginLeft = layoutMetric(LM_TitleBorderLeft);
|
|
|
|
const int marginRight = layoutMetric(LM_TitleBorderRight);
|
|
|
|
|
|
|
|
const int titleLeft = frame.left() + titleEdgeLeft + buttonsLeftWidth() + marginLeft;
|
|
|
|
const int titleWidth = frame.width() -
|
|
|
|
titleEdgeLeft - layoutMetric(LM_TitleEdgeRight) -
|
|
|
|
buttonsLeftWidth() - buttonsRightWidth() -
|
|
|
|
marginLeft - marginRight;
|
|
|
|
|
2007-07-16 02:12:45 +00:00
|
|
|
|
2007-07-16 18:01:27 +00:00
|
|
|
int splitY = qMin(300, 3*frame.height()/4);
|
2007-07-16 02:12:45 +00:00
|
|
|
|
2007-10-10 00:05:24 +00:00
|
|
|
QPixmap tile = helper_.verticalGradient(color, splitY);
|
2007-09-17 18:16:26 +00:00
|
|
|
painter.drawTiledPixmap(QRect(0, 0, frame.width(), titleHeight + TFRAMESIZE), tile);
|
2007-07-16 18:01:27 +00:00
|
|
|
|
|
|
|
painter.drawTiledPixmap(QRect(0, 0, LFRAMESIZE, splitY), tile);
|
2007-10-10 00:05:24 +00:00
|
|
|
painter.fillRect(0, splitY, LFRAMESIZE, frame.height() - splitY, helper_.backgroundBottomColor(color));
|
2007-07-16 18:01:27 +00:00
|
|
|
|
2007-07-16 02:12:45 +00:00
|
|
|
painter.drawTiledPixmap(QRect(frame.width()-RFRAMESIZE, 0,
|
2007-07-16 18:01:27 +00:00
|
|
|
RFRAMESIZE, splitY), tile,
|
2007-07-16 02:12:45 +00:00
|
|
|
QPoint(frame.width()-RFRAMESIZE, 0));
|
2007-10-10 00:05:24 +00:00
|
|
|
painter.fillRect(frame.width()-RFRAMESIZE, splitY, RFRAMESIZE, frame.height() - splitY, helper_.backgroundBottomColor(color));
|
2007-07-16 18:01:27 +00:00
|
|
|
|
2007-10-10 00:05:24 +00:00
|
|
|
painter.fillRect(0, frame.height() - BFRAMESIZE, frame.width(), BFRAMESIZE, helper_.backgroundBottomColor(color));
|
2007-07-16 02:12:45 +00:00
|
|
|
|
2007-07-16 18:01:27 +00:00
|
|
|
int radialW = qMin(600, frame.width());
|
2007-10-10 00:05:24 +00:00
|
|
|
tile = helper_.radialGradient(color, radialW);
|
2007-07-16 18:01:27 +00:00
|
|
|
QRect radialRect = QRect((frame.width() - radialW) / 2, 0, radialW, 64);
|
2007-07-16 02:12:45 +00:00
|
|
|
painter.drawPixmap(radialRect, tile);
|
|
|
|
|
|
|
|
//painter.setRenderHint(QPainter::Antialiasing,true);
|
2007-06-15 20:48:52 +00:00
|
|
|
|
|
|
|
// draw title text
|
|
|
|
painter.setFont(options()->font(isActive(), false));
|
2007-09-23 14:30:37 +00:00
|
|
|
painter.setPen(palette.windowText());
|
2007-09-17 18:16:26 +00:00
|
|
|
painter.drawText(titleLeft, titleTop, titleWidth, titleHeight,
|
2007-06-15 20:48:52 +00:00
|
|
|
OxygenFactory::titleAlign() | Qt::AlignVCenter, caption());
|
2007-07-16 02:12:45 +00:00
|
|
|
|
2007-06-15 20:48:52 +00:00
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
|
2007-10-09 21:01:18 +00:00
|
|
|
// Draw shadows of the frame
|
2007-07-16 02:12:45 +00:00
|
|
|
frame = widget()->rect();
|
2007-06-15 20:48:52 +00:00
|
|
|
frame.getRect(&x, &y, &w, &h);
|
|
|
|
|
|
|
|
painter.setBrush(Qt::NoBrush);
|
2007-10-09 21:01:18 +00:00
|
|
|
painter.setPen(QColor(255,255,255, 120));
|
|
|
|
painter.drawLine(QPointF(0, 0.5), QPointF(w, 0.5));
|
2007-06-15 20:48:52 +00:00
|
|
|
painter.setPen(QColor(128,128,128, 60));
|
2007-10-09 21:01:18 +00:00
|
|
|
painter.drawLine(QPointF(0.5, 0), QPointF(0.5, h));
|
|
|
|
painter.drawLine(QPointF(w-0.5, 0), QPointF(w-0.5, h));
|
|
|
|
painter.setPen(QColor(0,0,0, 60));
|
|
|
|
painter.drawLine(QPointF(0, h-0.5), QPointF(w, h-0.5));
|
|
|
|
|
|
|
|
painter.setPen(QColor(0,0,0, 40));
|
|
|
|
painter.drawPoint(QPointF(1.5, 1.5)); // top middle point
|
|
|
|
painter.drawPoint(QPointF(w-1.5, 1.5));
|
|
|
|
painter.drawPoint(QPointF(3.5, 0.5)); // top away points
|
|
|
|
painter.drawPoint(QPointF(w-3.5, 0.5));
|
|
|
|
painter.drawPoint(QPointF(0.5, 3.5));
|
|
|
|
painter.drawPoint(QPointF(w-0.5, 3.5));
|
|
|
|
painter.drawPoint(QPointF(1.5, h-1.5)); // bottom middle point
|
|
|
|
painter.drawPoint(QPointF(w-1.5, h-1.5));
|
|
|
|
|
|
|
|
// Draw the 3-dots resize handles
|
2007-07-16 18:01:27 +00:00
|
|
|
qreal cenY = frame.height() / 2 + 0.5;
|
|
|
|
qreal posX = frame.width() - 2.5;
|
2007-06-15 20:48:52 +00:00
|
|
|
painter.setPen(Qt::NoPen);
|
|
|
|
painter.setBrush(QColor(0, 0, 0, 66));
|
2007-09-27 18:30:17 +00:00
|
|
|
renderDot(&painter, QPointF(posX, cenY - 3), 1.8);
|
|
|
|
renderDot(&painter, QPointF(posX, cenY), 1.8);
|
|
|
|
renderDot(&painter, QPointF(posX, cenY + 3), 1.8);
|
2007-06-15 20:48:52 +00:00
|
|
|
|
|
|
|
painter.translate(frame.width()-9, frame.height()-9);
|
2007-09-27 18:30:17 +00:00
|
|
|
renderDot(&painter, QPointF(2.5, 6.5), 1.8);
|
|
|
|
renderDot(&painter, QPointF(5.5, 5.5), 1.8);
|
|
|
|
renderDot(&painter, QPointF(6.5, 2.5), 1.8);
|
2007-06-15 20:48:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OxygenClient::doShape()
|
|
|
|
{
|
2007-10-17 11:50:34 +00:00
|
|
|
bool maximized = maximizeMode()==MaximizeFull && !options()->moveResizeMaximizedWindows();
|
2007-06-15 20:48:52 +00:00
|
|
|
int r=widget()->width();
|
|
|
|
int b=widget()->height();
|
|
|
|
QRegion mask(0,0,r,b);
|
2007-10-17 11:50:34 +00:00
|
|
|
|
|
|
|
if(maximized) {
|
|
|
|
setMask(mask);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-06-15 20:48:52 +00:00
|
|
|
// Remove top-left corner.
|
|
|
|
mask -= QRegion(0, 0, 3, 1);
|
2007-10-09 21:01:18 +00:00
|
|
|
mask -= QRegion(0, 1, 1, 1);
|
2007-06-15 20:48:52 +00:00
|
|
|
mask -= QRegion(0, 2, 1, 1);
|
|
|
|
|
|
|
|
// Remove top-right corner.
|
|
|
|
mask -= QRegion(r - 3, 0, 3, 1);
|
2007-10-09 21:01:18 +00:00
|
|
|
mask -= QRegion(r - 1, 1, 1, 1);
|
2007-06-15 20:48:52 +00:00
|
|
|
mask -= QRegion(r - 1, 2, 1, 1);
|
|
|
|
|
|
|
|
// Remove bottom-left corner.
|
|
|
|
mask -= QRegion(0, b-1-0, 3, b-1-1);
|
2007-10-09 21:01:18 +00:00
|
|
|
mask -= QRegion(0, b-1-1, 1, b-1-1);
|
2007-06-15 20:48:52 +00:00
|
|
|
mask -= QRegion(0, b-1-2, 1, b-1-1);
|
|
|
|
|
|
|
|
// Remove bottom-right corner.
|
|
|
|
mask -= QRegion(r - 3, b-1-0, 3, b-1-1);
|
2007-10-09 21:01:18 +00:00
|
|
|
mask -= QRegion(r - 1, b-1-1, 1, b-1-1);
|
2007-06-15 20:48:52 +00:00
|
|
|
mask -= QRegion(r - 1, b-1-2, 1, b-1-1);
|
|
|
|
|
|
|
|
setMask(mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace Oxygen
|
|
|
|
|
|
|
|
//#include "oxygenclient.moc"
|
|
|
|
|
|
|
|
// #endif
|