2007-11-29 18:32:50 +03:00
|
|
|
/*********************************************************************
|
|
|
|
B-II KWin Client
|
|
|
|
|
|
|
|
Changes:
|
|
|
|
Customizable button positions by Karol Szwed <gallium@kde.org>
|
|
|
|
|
|
|
|
Thin frame in fixed size windows, titlebar gradient support, accessibility
|
|
|
|
improvements, customizable menu double click action and button hover
|
|
|
|
effects are
|
|
|
|
Copyright (c) 2003, 2004, 2006 Luciano Montanaro <mikelima@cirulla.net>
|
2009-11-18 15:48:48 +03:00
|
|
|
|
|
|
|
Added option to turn off titlebar autorelocation
|
|
|
|
Copyright (c) 2009 Jussi Kekkonen <tmt@ubuntu.com>
|
2007-11-29 18:32:50 +03:00
|
|
|
|
|
|
|
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. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
#ifndef CLIENTS_B2_B2CLIENT
|
|
|
|
#define CLIENTS_B2_B2CLIENT
|
|
|
|
|
|
|
|
#include "b2client.h"
|
2007-10-12 12:03:19 +04:00
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QLayout>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QPaintEvent>
|
|
|
|
#include <QPolygon>
|
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QEvent>
|
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QShowEvent>
|
|
|
|
#include <QStyle>
|
|
|
|
#include <QResizeEvent>
|
|
|
|
#include <QMouseEvent>
|
2007-04-30 16:48:59 +04:00
|
|
|
#include <QPainter>
|
2007-10-06 02:21:25 +04:00
|
|
|
#include <QUrl>
|
|
|
|
#include <QTextStream>
|
2007-04-29 21:35:43 +04:00
|
|
|
#include <kicontheme.h>
|
|
|
|
#include <kiconeffect.h>
|
2013-03-07 15:55:39 +04:00
|
|
|
#include <KDE/KLocalizedString>
|
2007-04-29 21:35:43 +04:00
|
|
|
#include <kconfig.h>
|
|
|
|
#include <QBitmap>
|
|
|
|
#include <QLabel>
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <QX11Info>
|
2007-10-06 02:21:25 +04:00
|
|
|
#include <KUrl>
|
|
|
|
#include <KConfigGroup>
|
2013-11-01 15:29:05 +04:00
|
|
|
#include <QDebug>
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
namespace B2 {
|
|
|
|
|
|
|
|
#include "bitmaps.h"
|
|
|
|
|
|
|
|
enum {
|
|
|
|
Norm = 0,
|
|
|
|
Hover, Down, INorm, IHover, IDown,
|
|
|
|
NumStates
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
P_CLOSE = 0,
|
2007-11-22 12:36:14 +03:00
|
|
|
P_MAX = NumStates,
|
|
|
|
P_NORMALIZE = P_MAX + NumStates,
|
|
|
|
P_ICONIFY = P_NORMALIZE + NumStates,
|
|
|
|
P_PINUP = P_ICONIFY + NumStates,
|
|
|
|
P_MENU = P_PINUP + NumStates,
|
|
|
|
P_HELP = P_MENU + NumStates,
|
|
|
|
P_SHADE = P_HELP + NumStates,
|
|
|
|
P_RESIZE = P_SHADE + NumStates,
|
|
|
|
P_NUM_PIXMAPS = P_RESIZE + NumStates
|
2007-04-29 21:35:43 +04:00
|
|
|
};
|
|
|
|
|
2007-11-22 12:36:14 +03:00
|
|
|
static QPixmap *pixmap[P_NUM_PIXMAPS];
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
// active
|
2007-11-22 12:36:14 +03:00
|
|
|
#define PIXMAP_A(i) (pixmap[(i) + Norm])
|
2007-04-29 21:35:43 +04:00
|
|
|
// active, hover
|
2007-11-22 12:36:14 +03:00
|
|
|
#define PIXMAP_AH(i) (pixmap[(i) + Hover])
|
2007-04-29 21:35:43 +04:00
|
|
|
// active, down
|
2007-11-22 12:36:14 +03:00
|
|
|
#define PIXMAP_AD(i) (pixmap[(i) + Down])
|
2007-04-29 21:35:43 +04:00
|
|
|
// inactive
|
2007-11-22 12:36:14 +03:00
|
|
|
#define PIXMAP_I(i) (pixmap[(i) + INorm])
|
2007-04-29 21:35:43 +04:00
|
|
|
// inactive, hover
|
2007-11-22 12:36:14 +03:00
|
|
|
#define PIXMAP_IH(i) (pixmap[(i) + IHover])
|
2007-04-29 21:35:43 +04:00
|
|
|
// inactive, down
|
2007-11-22 12:36:14 +03:00
|
|
|
#define PIXMAP_ID(i) (pixmap[(i) + IDown])
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
static QPixmap* titleGradient[2] = {0, 0};
|
|
|
|
|
2009-11-18 15:48:48 +03:00
|
|
|
static int thickness = 3; // Frame thickness
|
2007-04-29 21:35:43 +04:00
|
|
|
static int buttonSize = 16;
|
|
|
|
|
|
|
|
enum DblClickOperation {
|
|
|
|
NoOp = 0,
|
|
|
|
MinimizeOp,
|
|
|
|
ShadeOp,
|
|
|
|
CloseOp
|
|
|
|
};
|
|
|
|
|
|
|
|
static DblClickOperation menu_dbl_click_op = NoOp;
|
|
|
|
|
|
|
|
static bool pixmaps_created = false;
|
|
|
|
static bool colored_frame = false;
|
|
|
|
static bool do_draw_handle = true;
|
2009-11-18 15:48:48 +03:00
|
|
|
static bool do_amove_tb = true;
|
2007-04-29 21:35:43 +04:00
|
|
|
static bool drawSmallBorders = false;
|
|
|
|
|
|
|
|
// =====================================
|
|
|
|
|
2012-05-18 01:25:22 +04:00
|
|
|
KWIN_DECORATION(B2::B2ClientFactory)
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
// =====================================
|
|
|
|
|
|
|
|
static inline const KDecorationOptions *options()
|
|
|
|
{
|
|
|
|
return KDecoration::options();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void redraw_pixmaps();
|
|
|
|
|
|
|
|
static void read_config(B2ClientFactory *f)
|
|
|
|
{
|
|
|
|
// Force button size to be in a reasonable range.
|
|
|
|
// If the frame width is large, the button size must be large too.
|
2007-10-12 12:03:19 +04:00
|
|
|
buttonSize = (QFontMetrics(options()->font(true)).height() - 1) & 0x3e;
|
2007-04-29 21:35:43 +04:00
|
|
|
if (buttonSize < 16) buttonSize = 16;
|
|
|
|
|
2007-10-18 11:37:43 +04:00
|
|
|
KConfig _conf("kwinb2rc");
|
2007-04-29 21:35:43 +04:00
|
|
|
KConfigGroup conf(&_conf, "General");
|
|
|
|
colored_frame = conf.readEntry("UseTitleBarBorderColors", false);
|
|
|
|
do_draw_handle = conf.readEntry("DrawGrabHandle", true);
|
2009-11-18 15:48:48 +03:00
|
|
|
do_amove_tb = conf.readEntry("AutoMoveTitleBar", true);
|
2007-04-29 21:35:43 +04:00
|
|
|
drawSmallBorders = !options()->moveResizeMaximizedWindows();
|
|
|
|
|
|
|
|
QString opString = conf.readEntry("MenuButtonDoubleClickOperation", "NoOp");
|
|
|
|
if (opString == "Close") {
|
|
|
|
menu_dbl_click_op = B2::CloseOp;
|
|
|
|
} else if (opString == "Minimize") {
|
|
|
|
menu_dbl_click_op = B2::MinimizeOp;
|
|
|
|
} else if (opString == "Shade") {
|
|
|
|
menu_dbl_click_op = B2::ShadeOp;
|
|
|
|
} else {
|
|
|
|
menu_dbl_click_op = B2::NoOp;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (options()->preferredBorderSize(f)) {
|
|
|
|
case KDecoration::BorderTiny:
|
2009-11-18 15:48:48 +03:00
|
|
|
thickness = 1;
|
2007-04-29 21:35:43 +04:00
|
|
|
break;
|
|
|
|
case KDecoration::BorderLarge:
|
|
|
|
thickness = 5;
|
|
|
|
break;
|
|
|
|
case KDecoration::BorderVeryLarge:
|
2007-04-30 16:21:07 +04:00
|
|
|
thickness = 7;
|
2007-04-29 21:35:43 +04:00
|
|
|
break;
|
|
|
|
case KDecoration::BorderHuge:
|
2007-04-30 16:21:07 +04:00
|
|
|
thickness = 9;
|
2008-01-22 14:27:28 +03:00
|
|
|
break;
|
2007-04-29 21:35:43 +04:00
|
|
|
case KDecoration::BorderVeryHuge:
|
2007-04-30 16:21:07 +04:00
|
|
|
thickness = 11;
|
2008-01-22 14:27:28 +03:00
|
|
|
break;
|
2007-04-29 21:35:43 +04:00
|
|
|
case KDecoration::BorderOversized:
|
2007-04-30 16:21:07 +04:00
|
|
|
thickness = 14;
|
2007-04-30 02:33:21 +04:00
|
|
|
break;
|
2007-04-29 21:35:43 +04:00
|
|
|
case KDecoration::BorderNormal:
|
|
|
|
default:
|
2009-11-18 15:48:48 +03:00
|
|
|
thickness = 3;
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void drawB2Rect(QPixmap *pix, const QColor &primary, bool down)
|
|
|
|
{
|
|
|
|
QPainter p(pix);
|
|
|
|
QColor hColor = primary.light(150);
|
|
|
|
QColor lColor = primary.dark(150);
|
|
|
|
|
|
|
|
if (down) qSwap(hColor, lColor);
|
|
|
|
|
|
|
|
if (QPixmap::defaultDepth() > 8) {
|
2007-04-30 16:21:07 +04:00
|
|
|
QLinearGradient gradient(0, 0, pix->width(), pix->height());
|
|
|
|
gradient.setColorAt(0.0, hColor);
|
|
|
|
gradient.setColorAt(1.0, lColor);
|
|
|
|
QBrush brush(gradient);
|
|
|
|
p.fillRect(pix->rect(), brush);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
pix->fill(primary);
|
2007-04-30 16:21:07 +04:00
|
|
|
const int x2 = pix->width() - 1;
|
|
|
|
const int y2 = pix->height() - 1;
|
2007-04-29 21:35:43 +04:00
|
|
|
p.setPen(lColor);
|
|
|
|
p.drawLine(0, 0, x2, 0);
|
|
|
|
p.drawLine(0, 0, 0, y2);
|
|
|
|
p.drawLine(1, x2 - 1, x2 - 1, y2 - 1);
|
|
|
|
p.drawLine(x2 - 1, 1, x2 - 1, y2 - 1);
|
|
|
|
p.setPen(hColor);
|
2007-04-30 16:21:07 +04:00
|
|
|
p.drawRect(1, 1, x2 - 1, y2 - 1);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap* kwin_get_menu_pix_hack()
|
|
|
|
{
|
|
|
|
//return menu_pix; FIXME
|
|
|
|
return PIXMAP_A(P_MENU);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void create_pixmaps()
|
|
|
|
{
|
|
|
|
if (pixmaps_created)
|
|
|
|
return;
|
|
|
|
pixmaps_created = true;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int bsize = buttonSize - 2;
|
|
|
|
if (bsize < 16) bsize = 16;
|
|
|
|
|
2007-11-22 12:36:14 +03:00
|
|
|
for (i = 0; i < P_NUM_PIXMAPS; i++) {
|
|
|
|
switch (NumStates *(i / NumStates)) {
|
2007-10-18 11:37:43 +04:00
|
|
|
case P_CLOSE: // will be initialized by copying P_MAX
|
2007-04-30 02:33:21 +04:00
|
|
|
case P_RESIZE:
|
|
|
|
pixmap[i] = new QPixmap();
|
|
|
|
break;
|
|
|
|
case P_ICONIFY:
|
|
|
|
pixmap[i] = new QPixmap(10, 10);
|
|
|
|
break;
|
|
|
|
case P_SHADE:
|
2007-10-15 11:52:06 +04:00
|
|
|
case P_MAX:
|
2007-10-12 12:03:19 +04:00
|
|
|
case P_HELP:
|
2007-04-30 02:33:21 +04:00
|
|
|
pixmap[i] = new QPixmap(bsize, bsize);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pixmap[i] = new QPixmap(16, 16);
|
|
|
|
break;
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-23 02:54:23 +04:00
|
|
|
|
2007-04-30 16:26:31 +04:00
|
|
|
// This should stay here, before the mask creation, because of a bug with
|
|
|
|
// drawing a bitmap with drawPixmap() with the mask set (present at least
|
|
|
|
// in Qt 4.2.3).
|
2007-06-23 02:54:23 +04:00
|
|
|
titleGradient[0] = 0;
|
|
|
|
titleGradient[1] = 0;
|
2007-04-30 16:26:31 +04:00
|
|
|
redraw_pixmaps();
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
// there seems to be no way to load X bitmaps from data properly, so
|
|
|
|
// we need to create new ones for each mask :P
|
2007-04-30 02:33:21 +04:00
|
|
|
QBitmap pinupMask = QBitmap::fromData(QSize(16, 16), pinup_mask_bits);
|
|
|
|
QBitmap pindownMask = QBitmap::fromData(QSize(16, 16), pindown_mask_bits);
|
|
|
|
QBitmap menuMask = QBitmap::fromData(QSize(16, 16), menu_mask_bits);
|
2009-12-18 00:35:37 +03:00
|
|
|
for (i = 0; i < NumStates; ++i) {
|
2007-04-30 16:26:31 +04:00
|
|
|
bool isDown = (i == Down) || (i == IDown);
|
2007-11-22 12:36:14 +03:00
|
|
|
pixmap[P_MENU + i]->setMask(menuMask);
|
|
|
|
pixmap[P_PINUP + i]->setMask(isDown ? pindownMask: pinupMask);
|
2007-04-30 16:26:31 +04:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
QBitmap normalizeMask(16, 16);
|
|
|
|
normalizeMask.clear();
|
2007-06-23 02:54:23 +04:00
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
// draw normalize icon mask
|
|
|
|
QPainter mask;
|
|
|
|
mask.begin(&normalizeMask);
|
|
|
|
|
|
|
|
QBrush one(Qt::color1);
|
|
|
|
mask.fillRect(normalizeMask.width() - 12, normalizeMask.height() - 12,
|
|
|
|
12, 12, one);
|
|
|
|
mask.fillRect(0, 0, 10, 10, one);
|
|
|
|
mask.end();
|
|
|
|
|
2009-12-18 00:35:37 +03:00
|
|
|
for (i = 0; i < NumStates; ++i)
|
2007-11-22 12:36:14 +03:00
|
|
|
pixmap[P_NORMALIZE + i]->setMask(normalizeMask);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
QBitmap shadeMask(bsize, bsize);
|
|
|
|
shadeMask.clear();
|
|
|
|
mask.begin(&shadeMask);
|
|
|
|
mask.fillRect(0, 0, bsize, 6, one);
|
|
|
|
mask.end();
|
2009-12-18 00:35:37 +03:00
|
|
|
for (i = 0; i < NumStates; ++i)
|
2007-11-22 12:36:14 +03:00
|
|
|
pixmap[P_SHADE + i]->setMask(shadeMask);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_pixmaps()
|
|
|
|
{
|
2007-11-22 12:36:14 +03:00
|
|
|
for (int i = 0; i < P_NUM_PIXMAPS; i++) {
|
2007-04-29 21:35:43 +04:00
|
|
|
delete pixmap[i];
|
|
|
|
pixmap[i] = 0;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
delete titleGradient[i];
|
|
|
|
titleGradient[i] = 0;
|
|
|
|
}
|
|
|
|
pixmaps_created = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// =====================================
|
|
|
|
|
|
|
|
B2ClientFactory::B2ClientFactory()
|
|
|
|
{
|
|
|
|
read_config(this);
|
|
|
|
create_pixmaps();
|
|
|
|
}
|
|
|
|
|
|
|
|
B2ClientFactory::~B2ClientFactory()
|
|
|
|
{
|
|
|
|
delete_pixmaps();
|
|
|
|
}
|
|
|
|
|
|
|
|
KDecoration *B2ClientFactory::createDecoration(KDecorationBridge *b)
|
|
|
|
{
|
|
|
|
return new B2::B2Client(b, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool B2ClientFactory::reset(unsigned long changed)
|
|
|
|
{
|
|
|
|
bool needsReset = SettingColors ? true : false;
|
|
|
|
// TODO Do not recreate decorations if it is not needed. Look at
|
|
|
|
// ModernSystem for how to do that
|
|
|
|
read_config(this);
|
|
|
|
if (changed & SettingFont) {
|
|
|
|
delete_pixmaps();
|
|
|
|
create_pixmaps();
|
|
|
|
needsReset = true;
|
|
|
|
}
|
|
|
|
redraw_pixmaps();
|
|
|
|
// For now just return true.
|
|
|
|
return needsReset;
|
|
|
|
}
|
|
|
|
|
2007-11-01 19:07:38 +03:00
|
|
|
bool B2ClientFactory::supports(Ability ability) const
|
2007-04-29 21:35:43 +04:00
|
|
|
{
|
2007-04-30 02:33:21 +04:00
|
|
|
switch (ability) {
|
2007-11-29 21:02:20 +03:00
|
|
|
// announce
|
2007-10-18 11:37:43 +04:00
|
|
|
case AbilityAnnounceButtons:
|
2007-11-29 21:02:20 +03:00
|
|
|
case AbilityAnnounceColors:
|
|
|
|
// buttons
|
2007-10-18 11:37:43 +04:00
|
|
|
case AbilityButtonMenu:
|
|
|
|
case AbilityButtonOnAllDesktops:
|
|
|
|
case AbilityButtonSpacer:
|
|
|
|
case AbilityButtonHelp:
|
|
|
|
case AbilityButtonMinimize:
|
|
|
|
case AbilityButtonMaximize:
|
|
|
|
case AbilityButtonClose:
|
|
|
|
case AbilityButtonShade:
|
|
|
|
case AbilityButtonResize:
|
2007-11-29 21:02:20 +03:00
|
|
|
// colors
|
|
|
|
case AbilityColorTitleBack:
|
|
|
|
case AbilityColorTitleBlend:
|
|
|
|
case AbilityColorTitleFore:
|
|
|
|
case AbilityColorFrame:
|
|
|
|
case AbilityColorButtonBack:
|
2007-10-18 11:37:43 +04:00
|
|
|
return true;
|
|
|
|
// These are not (yet) supported.
|
|
|
|
case AbilityButtonAboveOthers:
|
|
|
|
case AbilityButtonBelowOthers:
|
|
|
|
default:
|
|
|
|
return false;
|
2007-04-29 21:35:43 +04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
QList< B2ClientFactory::BorderSize > B2ClientFactory::borderSizes() const
|
|
|
|
{
|
|
|
|
// the list must be sorted
|
|
|
|
return QList< BorderSize >() << BorderTiny << BorderNormal <<
|
2007-04-30 16:21:07 +04:00
|
|
|
BorderLarge << BorderVeryLarge <<
|
|
|
|
BorderHuge << BorderVeryHuge << BorderOversized;
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// =====================================
|
|
|
|
|
|
|
|
void B2Client::maxButtonClicked()
|
|
|
|
{
|
|
|
|
maximize(button[BtnMax]->last_button);
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::shadeButtonClicked()
|
|
|
|
{
|
|
|
|
setShade(!isSetShade());
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::resizeButtonPressed()
|
|
|
|
{
|
|
|
|
performWindowOperation(ResizeOp);
|
|
|
|
}
|
|
|
|
|
|
|
|
B2Client::B2Client(KDecorationBridge *b, KDecorationFactory *f)
|
|
|
|
: KDecoration(b, f), bar_x_ofs(0), in_unobs(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::init()
|
|
|
|
{
|
|
|
|
const QString tips[] = {
|
|
|
|
i18n("Menu"),
|
|
|
|
isOnAllDesktops() ?
|
|
|
|
i18n("Not on all desktops") : i18n("On all desktops"),
|
|
|
|
i18n("Minimize"), i18n("Maximize"),
|
|
|
|
i18n("Close"), i18n("Help"),
|
|
|
|
isSetShade() ? i18n("Unshade") : i18n("Shade"),
|
|
|
|
i18n("Resize")
|
|
|
|
};
|
|
|
|
|
|
|
|
// Check this early, otherwise the preview will be rendered badly.
|
|
|
|
resizable = isResizable();
|
|
|
|
|
2007-10-12 12:03:19 +04:00
|
|
|
createMainWidget();
|
2007-04-29 21:35:43 +04:00
|
|
|
widget()->setAttribute(Qt::WA_NoSystemBackground);
|
2007-10-12 12:03:19 +04:00
|
|
|
widget()->installEventFilter(this);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
// Set button pointers to NULL so we know what has been created
|
|
|
|
for (int i = 0; i < BtnCount; i++)
|
|
|
|
button[i] = NULL;
|
|
|
|
|
|
|
|
g = new QGridLayout(widget());
|
2009-07-06 07:26:33 +04:00
|
|
|
|
|
|
|
// force margin and spacing to 0 so that
|
|
|
|
// center widget is correctly located with respect
|
|
|
|
// to window border.
|
|
|
|
g->setSpacing(0);
|
|
|
|
g->setMargin(0);
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
// Left and right border width
|
|
|
|
|
|
|
|
leftSpacer = new QSpacerItem(thickness, 16,
|
|
|
|
QSizePolicy::Fixed, QSizePolicy::Expanding);
|
|
|
|
rightSpacer = new QSpacerItem(thickness, 16,
|
|
|
|
QSizePolicy::Fixed, QSizePolicy::Expanding);
|
|
|
|
|
|
|
|
g->addItem(leftSpacer, 1, 0);
|
|
|
|
g->addItem(rightSpacer, 1, 2);
|
|
|
|
|
|
|
|
// Top border height
|
|
|
|
topSpacer = new QSpacerItem(10, buttonSize + 4,
|
|
|
|
QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
g->addItem(topSpacer, 0, 1);
|
|
|
|
|
|
|
|
// Bottom border height.
|
|
|
|
bottomSpacer = new QSpacerItem(10,
|
|
|
|
thickness + (mustDrawHandle() ? 4 : 0),
|
|
|
|
QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
g->addItem(bottomSpacer, 2, 1);
|
|
|
|
if (isPreview()) {
|
|
|
|
QLabel *previewLabel = new QLabel(
|
|
|
|
i18n("<b><center>B II preview</center></b>"),
|
|
|
|
widget());
|
2007-09-02 00:04:10 +04:00
|
|
|
previewLabel->setAutoFillBackground(true);
|
2007-04-29 21:35:43 +04:00
|
|
|
g->addWidget(previewLabel, 1, 1);
|
|
|
|
} else {
|
|
|
|
g->addItem(new QSpacerItem(0, 0), 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// titlebar
|
2007-06-06 12:01:59 +04:00
|
|
|
g->addItem(new QSpacerItem(0, buttonSize + 4), 0, 0);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
titlebar = new B2Titlebar(this);
|
|
|
|
titlebar->setMinimumWidth(buttonSize + 4);
|
|
|
|
titlebar->setFixedHeight(buttonSize + 4);
|
|
|
|
|
2007-06-06 12:01:59 +04:00
|
|
|
QBoxLayout *titleLayout = new QBoxLayout(QBoxLayout::LeftToRight, titlebar);
|
|
|
|
titleLayout->setMargin(2);
|
|
|
|
titleLayout->setSpacing(1);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
if (options()->customButtonPositions()) {
|
|
|
|
addButtons(options()->titleButtonsLeft(), tips, titlebar, titleLayout);
|
|
|
|
titleLayout->addItem(titlebar->captionSpacer);
|
|
|
|
addButtons(options()->titleButtonsRight(), tips, titlebar, titleLayout);
|
|
|
|
} else {
|
|
|
|
addButtons("MSH", tips, titlebar, titleLayout);
|
|
|
|
titleLayout->addItem(titlebar->captionSpacer);
|
|
|
|
addButtons("IAX", tips, titlebar, titleLayout);
|
|
|
|
}
|
|
|
|
|
2007-06-09 01:52:46 +04:00
|
|
|
titleLayout->addSpacing(2);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2007-06-09 01:52:46 +04:00
|
|
|
QColor c = options()->palette(KDecoration::ColorTitleBar, isActive()).color(QPalette::Active, QPalette::Button);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
for (int i = 0; i < BtnCount; i++) {
|
|
|
|
if (button[i])
|
|
|
|
button[i]->setBg(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
titlebar->updateGeometry();
|
|
|
|
positionButtons();
|
|
|
|
titlebar->recalcBuffer();
|
|
|
|
titlebar->installEventFilter(this);
|
|
|
|
}
|
|
|
|
|
2007-09-03 01:03:30 +04:00
|
|
|
void B2Client::addButtons(const QString& s, const QString tips[],
|
2007-04-29 21:35:43 +04:00
|
|
|
B2Titlebar* tb, QBoxLayout* titleLayout)
|
|
|
|
{
|
|
|
|
if (s.length() <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (int i = 0; i < s.length(); i++) {
|
|
|
|
switch (s[i].toLatin1()) {
|
|
|
|
case 'M': // Menu button
|
|
|
|
if (!button[BtnMenu]) {
|
|
|
|
button[BtnMenu] = new B2Button(this, tb, tips[BtnMenu],
|
|
|
|
Qt::LeftButton | Qt::RightButton);
|
|
|
|
button[BtnMenu]->setPixmaps(P_MENU);
|
|
|
|
button[BtnMenu]->setUseMiniIcon();
|
|
|
|
connect(button[BtnMenu], SIGNAL(pressed()),
|
|
|
|
this, SLOT(menuButtonPressed()));
|
|
|
|
titleLayout->addWidget(button[BtnMenu]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'S': // Sticky button
|
|
|
|
if (!button[BtnSticky]) {
|
|
|
|
button[BtnSticky] = new B2Button(this, tb, tips[BtnSticky]);
|
|
|
|
button[BtnSticky]->setPixmaps(P_PINUP);
|
|
|
|
button[BtnSticky]->setToggle();
|
|
|
|
button[BtnSticky]->setDown(isOnAllDesktops());
|
|
|
|
connect(button[BtnSticky], SIGNAL(clicked()),
|
|
|
|
this, SLOT(toggleOnAllDesktops()));
|
|
|
|
titleLayout->addWidget(button[BtnSticky]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'H': // Help button
|
|
|
|
if (providesContextHelp() && (!button[BtnHelp])) {
|
|
|
|
button[BtnHelp] = new B2Button(this, tb, tips[BtnHelp]);
|
|
|
|
button[BtnHelp]->setPixmaps(P_HELP);
|
|
|
|
connect(button[BtnHelp], SIGNAL(clicked()),
|
|
|
|
this, SLOT(showContextHelp()));
|
|
|
|
titleLayout->addWidget(button[BtnHelp]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'I': // Minimize button
|
|
|
|
if (isMinimizable() && (!button[BtnIconify])) {
|
|
|
|
button[BtnIconify] = new B2Button(this, tb,tips[BtnIconify]);
|
|
|
|
button[BtnIconify]->setPixmaps(P_ICONIFY);
|
|
|
|
connect(button[BtnIconify], SIGNAL(clicked()),
|
|
|
|
this, SLOT(minimize()));
|
|
|
|
titleLayout->addWidget(button[BtnIconify]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'A': // Maximize button
|
|
|
|
if (isMaximizable() && (!button[BtnMax])) {
|
|
|
|
button[BtnMax] = new B2Button(this, tb, tips[BtnMax],
|
|
|
|
Qt::LeftButton | Qt::MidButton | Qt::RightButton);
|
|
|
|
button[BtnMax]->setPixmaps(maximizeMode() == MaximizeFull ?
|
|
|
|
P_NORMALIZE : P_MAX);
|
|
|
|
connect(button[BtnMax], SIGNAL(clicked()),
|
|
|
|
this, SLOT(maxButtonClicked()));
|
|
|
|
titleLayout->addWidget(button[BtnMax]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'X': // Close button
|
|
|
|
if (isCloseable() && !button[BtnClose]) {
|
|
|
|
button[BtnClose] = new B2Button(this, tb, tips[BtnClose]);
|
|
|
|
button[BtnClose]->setPixmaps(P_CLOSE);
|
|
|
|
connect(button[BtnClose], SIGNAL(clicked()),
|
|
|
|
this, SLOT(closeWindow()));
|
|
|
|
titleLayout->addWidget(button[BtnClose]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'L': // Shade button
|
|
|
|
if (isShadeable() && !button[BtnShade]) {
|
|
|
|
button[BtnShade] = new B2Button(this, tb, tips[BtnShade]);
|
|
|
|
button[BtnShade]->setPixmaps(P_SHADE);
|
|
|
|
connect(button[BtnShade], SIGNAL(clicked()),
|
|
|
|
this, SLOT(shadeButtonClicked()));
|
|
|
|
titleLayout->addWidget(button[BtnShade]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'R': // Resize button
|
|
|
|
if (resizable && !button[BtnResize]) {
|
|
|
|
button[BtnResize] = new B2Button(this, tb, tips[BtnResize]);
|
|
|
|
button[BtnResize]->setPixmaps(P_RESIZE);
|
|
|
|
connect(button[BtnResize], SIGNAL(pressed()),
|
|
|
|
this, SLOT(resizeButtonPressed()));
|
|
|
|
titleLayout->addWidget(button[BtnResize]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '_': // Additional spacing
|
|
|
|
titleLayout->addSpacing(4);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool B2Client::mustDrawHandle() const
|
|
|
|
{
|
|
|
|
if (drawSmallBorders && (maximizeMode() & MaximizeVertical)) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return do_draw_handle && resizable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-18 15:48:48 +03:00
|
|
|
bool B2Client::autoMoveTitlebar() const
|
|
|
|
{
|
|
|
|
return do_amove_tb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
void B2Client::iconChange()
|
|
|
|
{
|
|
|
|
if (button[BtnMenu])
|
|
|
|
button[BtnMenu]->repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gallium: New button show/hide magic for customizable
|
|
|
|
// button positions.
|
|
|
|
void B2Client::calcHiddenButtons()
|
|
|
|
{
|
|
|
|
// Hide buttons in this order:
|
|
|
|
// Shade, Sticky, Help, Resize, Maximize, Minimize, Close, Menu
|
|
|
|
B2Button* btnArray[] = {
|
|
|
|
button[BtnShade], button[BtnSticky], button[BtnHelp], button[BtnResize],
|
|
|
|
button[BtnMax], button[BtnIconify], button[BtnClose], button[BtnMenu]
|
|
|
|
};
|
2007-04-30 16:26:31 +04:00
|
|
|
const int minWidth = 120;
|
2007-04-29 21:35:43 +04:00
|
|
|
int currentWidth = width();
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
// Determine how many buttons we need to hide
|
|
|
|
while (currentWidth < minWidth) {
|
|
|
|
currentWidth += buttonSize + 1; // Allow for spacer (extra 1pix)
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
// Bound the number of buttons to hide
|
|
|
|
if (count > BtnCount) count = BtnCount;
|
|
|
|
|
|
|
|
// Hide the required buttons
|
2007-04-30 16:26:31 +04:00
|
|
|
for (int i = 0; i < count; i++) {
|
2007-04-29 21:35:43 +04:00
|
|
|
if (btnArray[i] && btnArray[i]->isVisible())
|
|
|
|
btnArray[i]->hide();
|
|
|
|
}
|
|
|
|
// Show the rest of the buttons
|
2007-04-30 16:26:31 +04:00
|
|
|
for (int i = count; i < BtnCount; i++) {
|
2007-04-29 21:35:43 +04:00
|
|
|
if (btnArray[i] && (!btnArray[i]->isVisible()))
|
|
|
|
btnArray[i]->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::resizeEvent(QResizeEvent * /*e*/)
|
|
|
|
{
|
|
|
|
calcHiddenButtons();
|
|
|
|
titlebar->layout()->activate();
|
|
|
|
positionButtons();
|
|
|
|
|
2007-06-05 12:45:49 +04:00
|
|
|
// may be the resize cut off some space occupied by titlebar, which
|
|
|
|
// was moved, so instead of reducing it, we first try to move it
|
2007-04-29 21:35:43 +04:00
|
|
|
titleMoveAbs(bar_x_ofs);
|
|
|
|
|
|
|
|
doShape();
|
|
|
|
widget()->repaint(); // the frame is misrendered without this
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::captionChange()
|
|
|
|
{
|
2007-06-05 12:45:49 +04:00
|
|
|
// XXX This function and resizeEvent are quite similar.
|
|
|
|
// Factor out common code.
|
|
|
|
calcHiddenButtons();
|
|
|
|
titlebar->layout()->activate();
|
2007-04-29 21:35:43 +04:00
|
|
|
positionButtons();
|
2007-06-23 02:54:23 +04:00
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
titleMoveAbs(bar_x_ofs);
|
2007-06-23 02:54:23 +04:00
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
doShape();
|
|
|
|
titlebar->recalcBuffer();
|
|
|
|
titlebar->repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::paintEvent(QPaintEvent* e)
|
|
|
|
{
|
|
|
|
QPainter p(widget());
|
|
|
|
|
|
|
|
KDecoration::ColorType frameColorGroup = colored_frame ?
|
|
|
|
KDecoration::ColorTitleBar : KDecoration::ColorFrame;
|
|
|
|
|
|
|
|
QRect t = titlebar->geometry();
|
|
|
|
|
|
|
|
// Frame height, this is used a lot of times
|
2007-04-30 16:21:07 +04:00
|
|
|
const int fHeight = height() - t.height() - 1;
|
|
|
|
const int fWidth = width() - 1;
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
// distance from the bottom border - it is different if window is resizable
|
2007-04-30 16:21:07 +04:00
|
|
|
const int bb = mustDrawHandle() ? 4 : 0;
|
|
|
|
const int bDepth = thickness + bb;
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
QPalette fillColor = options()->palette(frameColorGroup, isActive());
|
|
|
|
QBrush fillBrush(options()->color(frameColorGroup, isActive()));
|
|
|
|
|
|
|
|
// outer frame rect
|
|
|
|
p.drawRect(0, t.bottom() - thickness + 1,
|
2007-04-30 16:21:07 +04:00
|
|
|
fWidth, fHeight - bb + thickness);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2009-11-18 15:48:48 +03:00
|
|
|
if (thickness >= 1) {
|
2007-04-29 21:35:43 +04:00
|
|
|
// inner window rect
|
|
|
|
p.drawRect(thickness - 1, t.bottom(),
|
2007-04-30 16:21:07 +04:00
|
|
|
fWidth - 2 * (thickness - 1), fHeight - bDepth + 2);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
if (thickness >= 3) {
|
|
|
|
// frame shade panel
|
|
|
|
qDrawShadePanel(&p, 1, t.bottom() - thickness + 2,
|
2007-04-30 16:21:07 +04:00
|
|
|
width() - 2, fHeight - 1 - bb + thickness, fillColor, false);
|
2007-04-29 21:35:43 +04:00
|
|
|
if (thickness == 4) {
|
2007-04-30 02:33:21 +04:00
|
|
|
p.setPen(fillColor.color(QPalette::Background));
|
2007-04-29 21:35:43 +04:00
|
|
|
p.drawRect(thickness - 2, t.bottom() - 1,
|
2007-04-30 16:21:07 +04:00
|
|
|
width() - 2 * thickness + 3, fHeight + 4 - bDepth);
|
2007-04-29 21:35:43 +04:00
|
|
|
} else if (thickness > 4) {
|
|
|
|
qDrawShadePanel(&p, thickness - 2,
|
|
|
|
t.bottom() - 1, width() - 2 * (thickness - 2),
|
2007-04-30 16:21:07 +04:00
|
|
|
fHeight + 5 - bDepth, fillColor, true);
|
2007-04-29 21:35:43 +04:00
|
|
|
if (thickness >= 5) {
|
|
|
|
// draw frame interior
|
|
|
|
p.fillRect(2, t.bottom() - thickness + 3,
|
|
|
|
width() - 4, thickness - 4, fillBrush);
|
|
|
|
p.fillRect(2, height() - bDepth + 2,
|
|
|
|
width() - 4, thickness - 4, fillBrush);
|
|
|
|
p.fillRect(2, t.bottom() - 1,
|
2007-04-30 16:21:07 +04:00
|
|
|
thickness - 4, fHeight - bDepth + 5, fillBrush);
|
2007-04-29 21:35:43 +04:00
|
|
|
p.fillRect(width() - thickness + 2, t.bottom() - 1,
|
2007-04-30 16:21:07 +04:00
|
|
|
thickness - 4, fHeight - bDepth + 5, fillBrush);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// bottom handle rect
|
|
|
|
if (mustDrawHandle()) {
|
|
|
|
p.setPen(Qt::black);
|
2007-04-30 16:21:07 +04:00
|
|
|
const int hx = width() - 40;
|
|
|
|
const int hw = 40;
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
p.drawLine(width() - 1, height() - thickness - 4,
|
|
|
|
width() - 1, height() - 1);
|
|
|
|
p.drawLine(hx, height() - 1, width() - 1, height() - 1);
|
|
|
|
p.drawLine(hx, height() - 4, hx, height() - 1);
|
|
|
|
|
|
|
|
p.fillRect(hx + 1, height() - thickness - 3,
|
|
|
|
hw - 2, thickness + 2, fillBrush);
|
|
|
|
|
2007-04-30 02:33:21 +04:00
|
|
|
p.setPen(fillColor.color(QPalette::Dark));
|
2007-04-29 21:35:43 +04:00
|
|
|
p.drawLine(width() - 2, height() - thickness - 4,
|
|
|
|
width() - 2, height() - 2);
|
|
|
|
p.drawLine(hx + 1, height() - 2, width() - 2, height() - 2);
|
|
|
|
|
2007-04-30 02:33:21 +04:00
|
|
|
p.setPen(fillColor.color(QPalette::Light));
|
2007-04-29 21:35:43 +04:00
|
|
|
p.drawLine(hx + 1, height() - thickness - 2,
|
|
|
|
hx + 1, height() - 3);
|
|
|
|
p.drawLine(hx + 1, height() - thickness - 3,
|
|
|
|
width() - 3, height() - thickness - 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* OK, we got a paint event, which means parts of us are now visible
|
|
|
|
which were not before. We try the titlebar if it is currently fully
|
|
|
|
obscured, and if yes, try to unobscure it, in the hope that some
|
|
|
|
of the parts which we just painted were in the titlebar area.
|
|
|
|
It can happen, that the titlebar, as it got the FullyObscured event
|
|
|
|
had no chance of becoming partly visible. The problem is, that
|
|
|
|
we now might have the space available, but the titlebar gets no
|
|
|
|
visibilitinotify events until its state changes, so we just try
|
|
|
|
*/
|
2009-11-18 15:48:48 +03:00
|
|
|
if (titlebar->isFullyObscured()) { //FIXME this doesn't work in composited X
|
2007-04-29 21:35:43 +04:00
|
|
|
/* We first see, if our repaint contained the titlebar area */
|
|
|
|
QRegion reg(QRect(0, 0, width(), buttonSize + 4));
|
|
|
|
reg = reg.intersect(e->region());
|
|
|
|
if (!reg.isEmpty())
|
|
|
|
unobscureTitlebar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::doShape()
|
|
|
|
{
|
2007-04-30 16:21:07 +04:00
|
|
|
const QRect t = titlebar->geometry();
|
|
|
|
const int w = width();
|
|
|
|
const int h = height();
|
2007-04-29 21:35:43 +04:00
|
|
|
QRegion mask(widget()->rect());
|
|
|
|
// top to the tilebar right
|
|
|
|
if (bar_x_ofs) {
|
|
|
|
// left from bar
|
|
|
|
mask -= QRect(0, 0, bar_x_ofs, t.height() - thickness);
|
|
|
|
// top left point
|
|
|
|
mask -= QRect(0, t.height() - thickness, 1, 1);
|
|
|
|
}
|
2007-04-30 16:21:07 +04:00
|
|
|
if (t.right() < w - 1) {
|
|
|
|
mask -= QRect(w - 1, t.height() - thickness, 1, 1); // top right point
|
2007-04-29 21:35:43 +04:00
|
|
|
mask -= QRect(t.right() + 1, 0,
|
2007-04-30 16:21:07 +04:00
|
|
|
w - t.right() - 1, t.height() - thickness);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
// bottom right point
|
2007-04-30 16:21:07 +04:00
|
|
|
mask -= QRect(w - 1, h - 1, 1, 1);
|
2007-04-29 21:35:43 +04:00
|
|
|
if (mustDrawHandle()) {
|
|
|
|
// bottom left point
|
2007-04-30 16:21:07 +04:00
|
|
|
mask -= QRect(0, h - 5, 1, 1);
|
2007-04-29 21:35:43 +04:00
|
|
|
// handle left point
|
2007-04-30 16:21:07 +04:00
|
|
|
mask -= QRect(w - 40, h - 1, 1, 1);
|
2007-04-29 21:35:43 +04:00
|
|
|
// bottom left
|
2007-04-30 16:21:07 +04:00
|
|
|
mask -= QRect(0, h - 4, w - 40, 4);
|
2007-04-29 21:35:43 +04:00
|
|
|
} else {
|
|
|
|
// bottom left point
|
2007-04-30 16:21:07 +04:00
|
|
|
mask -= QRect(0, h - 1, 1, 1);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
setMask(mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::showEvent(QShowEvent *)
|
|
|
|
{
|
|
|
|
calcHiddenButtons();
|
|
|
|
positionButtons();
|
2007-06-06 12:01:59 +04:00
|
|
|
// TODO check if setting a flag and doing this during the paintEvent is a
|
|
|
|
// better approach.
|
2007-04-29 21:35:43 +04:00
|
|
|
doShape();
|
|
|
|
}
|
|
|
|
|
|
|
|
KDecoration::Position B2Client::mousePosition(const QPoint& p) const
|
|
|
|
{
|
|
|
|
const int range = 16;
|
|
|
|
QRect t = titlebar->geometry();
|
|
|
|
t.setHeight(buttonSize + 4 - thickness);
|
2007-04-30 16:21:07 +04:00
|
|
|
const int ly = t.bottom();
|
|
|
|
const int lx = t.right();
|
|
|
|
const int bb = mustDrawHandle() ? 0 : 5;
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2007-04-30 16:26:31 +04:00
|
|
|
if (p.x() > lx) {
|
2007-04-29 21:35:43 +04:00
|
|
|
if (p.y() <= ly + range && p.x() >= width() - range)
|
|
|
|
return PositionTopRight;
|
|
|
|
else if (p.y() <= ly + thickness)
|
|
|
|
return PositionTop;
|
|
|
|
} else if (p.x() < bar_x_ofs) {
|
|
|
|
if (p.y() <= ly + range && p.x() <= range)
|
|
|
|
return PositionTopLeft;
|
|
|
|
else if (p.y() <= ly + thickness)
|
|
|
|
return PositionTop;
|
|
|
|
} else if (p.y() < ly) {
|
|
|
|
if (p.x() > bar_x_ofs + thickness &&
|
|
|
|
p.x() < lx - thickness && p.y() > thickness)
|
|
|
|
return KDecoration::mousePosition(p);
|
|
|
|
if (p.x() > bar_x_ofs + range && p.x() < lx - range)
|
|
|
|
return PositionTop;
|
|
|
|
if (p.y() <= range) {
|
|
|
|
if (p.x() <= bar_x_ofs + range)
|
|
|
|
return PositionTopLeft;
|
|
|
|
else return PositionTopRight;
|
|
|
|
} else {
|
|
|
|
if (p.x() <= bar_x_ofs + range)
|
|
|
|
return PositionLeft;
|
|
|
|
else return PositionRight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p.y() >= height() - 8 + bb) {
|
|
|
|
/* the normal Client:: only wants border of 4 pixels */
|
|
|
|
if (p.x() <= range) return PositionBottomLeft;
|
|
|
|
if (p.x() >= width() - range) return PositionBottomRight;
|
|
|
|
return PositionBottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
return KDecoration::mousePosition(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::titleMoveAbs(int new_ofs)
|
|
|
|
{
|
|
|
|
if (new_ofs < 0) new_ofs = 0;
|
2007-06-06 12:01:59 +04:00
|
|
|
if (new_ofs > width() - titlebar->width()) {
|
2007-04-29 21:35:43 +04:00
|
|
|
new_ofs = width() - titlebar->width();
|
|
|
|
}
|
|
|
|
if (bar_x_ofs != new_ofs) {
|
|
|
|
bar_x_ofs = new_ofs;
|
|
|
|
positionButtons();
|
|
|
|
doShape();
|
|
|
|
widget()->repaint(0, 0, width(), buttonSize + 4);
|
|
|
|
titlebar->repaint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::titleMoveRel(int xdiff)
|
|
|
|
{
|
|
|
|
titleMoveAbs(bar_x_ofs + xdiff);
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::desktopChange()
|
|
|
|
{
|
|
|
|
bool on = isOnAllDesktops();
|
|
|
|
if (B2Button *b = button[BtnSticky]) {
|
|
|
|
b->setDown(on);
|
|
|
|
b->setToolTip(
|
|
|
|
on ? i18n("Not on all desktops") : i18n("On all desktops"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::maximizeChange()
|
|
|
|
{
|
|
|
|
bool m = maximizeMode() == MaximizeFull;
|
|
|
|
if (button[BtnMax]) {
|
|
|
|
button[BtnMax]->setPixmaps(m ? P_NORMALIZE : P_MAX);
|
|
|
|
button[BtnMax]->repaint();
|
|
|
|
button[BtnMax]->setToolTip(
|
|
|
|
m ? i18n("Restore") : i18n("Maximize"));
|
|
|
|
}
|
|
|
|
bottomSpacer->changeSize(10, thickness + (mustDrawHandle() ? 4 : 0),
|
|
|
|
QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
|
|
|
|
g->activate();
|
|
|
|
doShape();
|
|
|
|
widget()->repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::activeChange()
|
|
|
|
{
|
|
|
|
widget()->repaint();
|
|
|
|
titlebar->repaint();
|
|
|
|
|
|
|
|
QColor c = options()->palette(
|
2007-04-30 02:33:21 +04:00
|
|
|
KDecoration::ColorTitleBar, isActive()).color(QPalette::Active, QPalette::Button);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
for (int i = 0; i < BtnCount; i++)
|
|
|
|
if (button[i]) {
|
|
|
|
button[i]->setBg(c);
|
|
|
|
button[i]->repaint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::shadeChange()
|
|
|
|
{
|
|
|
|
bottomSpacer->changeSize(10, thickness + (mustDrawHandle() ? 4 : 0),
|
|
|
|
QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
g->activate();
|
|
|
|
doShape();
|
|
|
|
if (B2Button *b = button[BtnShade]) {
|
2007-04-30 02:33:21 +04:00
|
|
|
b->setToolTip(isSetShade() ? i18n("Unshade") : i18n("Shade"));
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize B2Client::minimumSize() const
|
|
|
|
{
|
|
|
|
int left, right, top, bottom;
|
|
|
|
borders(left, right, top, bottom);
|
|
|
|
return QSize(left + right + 2 * buttonSize, top + bottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::resize(const QSize& s)
|
|
|
|
{
|
|
|
|
widget()->resize(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::borders(int &left, int &right, int &top, int &bottom) const
|
|
|
|
{
|
|
|
|
left = right = thickness;
|
|
|
|
top = buttonSize + 4;
|
|
|
|
bottom = thickness + (mustDrawHandle() ? 4 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::menuButtonPressed()
|
|
|
|
{
|
|
|
|
static B2Client *lastClient = NULL;
|
|
|
|
|
2007-04-30 16:26:31 +04:00
|
|
|
const bool dbl = (lastClient == this &&
|
|
|
|
time.elapsed() <= QApplication::doubleClickInterval());
|
2007-04-29 21:35:43 +04:00
|
|
|
lastClient = this;
|
|
|
|
time.start();
|
|
|
|
if (!dbl) {
|
|
|
|
KDecorationFactory* f = factory();
|
|
|
|
QRect menuRect = button[BtnMenu]->rect();
|
|
|
|
QPoint menuTop = button[BtnMenu]->mapToGlobal(menuRect.topLeft());
|
|
|
|
QPoint menuBottom = button[BtnMenu]->mapToGlobal(menuRect.bottomRight());
|
|
|
|
showWindowMenu(QRect(menuTop, menuBottom));
|
|
|
|
if (!f->exists(this)) // 'this' was destroyed
|
|
|
|
return;
|
|
|
|
button[BtnMenu]->setDown(false);
|
|
|
|
} else {
|
|
|
|
switch (menu_dbl_click_op) {
|
|
|
|
case B2::MinimizeOp:
|
|
|
|
minimize();
|
|
|
|
break;
|
|
|
|
case B2::ShadeOp:
|
|
|
|
setShade(!isSetShade());
|
|
|
|
break;
|
|
|
|
case B2::CloseOp:
|
|
|
|
closeWindow();
|
|
|
|
break;
|
|
|
|
case B2::NoOp:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::unobscureTitlebar()
|
|
|
|
{
|
|
|
|
/* we just noticed, that we got obscured by other windows
|
|
|
|
so we look at all windows above us (stacking_order) merging their
|
|
|
|
masks, intersecting it with our titlebar area, and see if we can
|
|
|
|
find a place not covered by any window */
|
2009-11-18 15:48:48 +03:00
|
|
|
if (autoMoveTitlebar()) // I'm not sure if earlier check does it right, so let's make it sure, DO WE AUTOMOVE?
|
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
if (in_unobs) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
in_unobs = 1;
|
2007-04-30 02:33:21 +04:00
|
|
|
QRegion reg(QRect(0, 0, width(), buttonSize + 4));
|
2007-04-29 21:35:43 +04:00
|
|
|
reg = unobscuredRegion(reg);
|
|
|
|
if (!reg.isEmpty()) {
|
|
|
|
// there is at least _one_ pixel from our title area, which is not
|
|
|
|
// obscured, we use the first rect we find
|
|
|
|
// for a first test, we use boundingRect(), later we may refine
|
|
|
|
// to rect(), and search for the nearest, or biggest, or smthg.
|
|
|
|
titleMoveAbs(reg.boundingRect().x());
|
|
|
|
}
|
|
|
|
in_unobs = 0;
|
2009-11-18 15:48:48 +03:00
|
|
|
} // if (autoMoveTitlebar())
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void redraw_pixmaps()
|
|
|
|
{
|
2007-06-23 02:54:23 +04:00
|
|
|
QPalette aPal = options()->palette(KDecoration::ColorButtonBg, true);
|
|
|
|
QPalette iPal = options()->palette(KDecoration::ColorButtonBg, false);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2007-06-23 02:54:23 +04:00
|
|
|
QColor inactiveColor = iPal.color(QPalette::Button);
|
|
|
|
QColor activeColor = aPal.color(QPalette::Button);
|
2007-04-30 16:21:07 +04:00
|
|
|
|
2007-10-15 11:52:06 +04:00
|
|
|
// maximize
|
2007-10-18 11:37:43 +04:00
|
|
|
for (int i = 0; i < NumStates; i++) {
|
|
|
|
bool is_act = (i < 2);
|
|
|
|
bool is_down = ((i & 1) == 1);
|
2007-11-22 12:36:14 +03:00
|
|
|
QPixmap *pix = pixmap[P_MAX + i];
|
2007-10-18 11:37:43 +04:00
|
|
|
QColor color = is_act ? activeColor : inactiveColor;
|
|
|
|
drawB2Rect(pix, color, is_down);
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
// shade
|
|
|
|
QPixmap thinBox(buttonSize - 2, 6);
|
2007-04-30 16:26:31 +04:00
|
|
|
for (int i = 0; i < NumStates; i++) {
|
2007-04-29 21:35:43 +04:00
|
|
|
bool is_act = (i < 2);
|
|
|
|
bool is_down = ((i & 1) == 1);
|
2007-11-22 12:36:14 +03:00
|
|
|
QPixmap *pix = pixmap[P_SHADE + i];
|
2007-04-30 16:21:07 +04:00
|
|
|
QColor color = is_act ? activeColor : inactiveColor;
|
2007-04-29 21:35:43 +04:00
|
|
|
drawB2Rect(&thinBox, color, is_down);
|
|
|
|
pix->fill(Qt::black);
|
2009-10-05 10:59:10 +04:00
|
|
|
QPainter p(pix);
|
|
|
|
p.drawPixmap(0, 0, thinBox);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// normalize + iconify
|
2007-10-15 11:52:06 +04:00
|
|
|
QPixmap smallBox(10, 10);
|
|
|
|
QPixmap largeBox(12, 12);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2007-04-30 16:26:31 +04:00
|
|
|
for (int i = 0; i < NumStates; i++) {
|
2007-04-29 21:35:43 +04:00
|
|
|
bool is_act = (i < 3);
|
|
|
|
bool is_down = (i == Down || i == IDown);
|
2007-11-22 12:36:14 +03:00
|
|
|
QPixmap *pix = pixmap[P_NORMALIZE + i];
|
2007-04-30 16:21:07 +04:00
|
|
|
QColor color = is_act ? activeColor : inactiveColor;
|
|
|
|
drawB2Rect(&smallBox, color, is_down);
|
|
|
|
drawB2Rect(&largeBox, color, is_down);
|
2007-04-29 21:35:43 +04:00
|
|
|
pix->fill(options()->color(KDecoration::ColorTitleBar, is_act));
|
2009-10-05 10:59:10 +04:00
|
|
|
QPainter p(pix);
|
|
|
|
p.drawPixmap(pix->width() - 12, pix->width() - 12, largeBox, 0, 0, 12, 12);
|
|
|
|
p.drawPixmap(0, 0, smallBox, 0, 0, 10, 10);
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2009-10-05 10:59:10 +04:00
|
|
|
QPainter p2(pixmap[P_ICONIFY + i]);
|
|
|
|
p2.drawPixmap(0, 0, smallBox, 0, 0, 10, 10);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// resize
|
2007-04-30 16:26:31 +04:00
|
|
|
for (int i = 0; i < NumStates; i++) {
|
2007-04-29 21:35:43 +04:00
|
|
|
bool is_act = (i < 3);
|
|
|
|
bool is_down = (i == Down || i == IDown);
|
2007-11-22 12:36:14 +03:00
|
|
|
*pixmap[P_RESIZE + i] = *pixmap[P_MAX + i];
|
|
|
|
pixmap[P_RESIZE + i]->detach();
|
2007-04-30 16:21:07 +04:00
|
|
|
drawB2Rect(&smallBox, is_act ? activeColor : inactiveColor, is_down);
|
2009-10-05 10:59:10 +04:00
|
|
|
QPainter p(pixmap[P_RESIZE + i]);
|
|
|
|
p.drawPixmap(0, 0, smallBox, 0, 0, 10, 10);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
QPainter p;
|
2007-10-15 11:52:06 +04:00
|
|
|
// close: copy the maximize image, then add the X
|
|
|
|
for (int i = 0; i < NumStates; i++) {
|
2007-11-22 12:36:14 +03:00
|
|
|
*pixmap[P_CLOSE + i] = *pixmap[P_MAX + i];
|
|
|
|
pixmap[P_CLOSE + i]->detach();
|
2007-10-15 11:52:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < NumStates; i++) {
|
|
|
|
bool isAct = (i < 3);
|
2007-11-22 12:36:14 +03:00
|
|
|
QPixmap *pixm = pixmap[P_CLOSE + i];
|
2007-10-15 11:52:06 +04:00
|
|
|
p.begin(pixm);
|
|
|
|
QColor color = isAct ? activeColor : inactiveColor;
|
|
|
|
QRect r = QRect(3, 3, pixm->width() - 6, pixm->height() - 6);
|
|
|
|
for (int j = 0; j < 2; j++) {
|
|
|
|
r.moveTo(j + 3, 3);
|
|
|
|
p.setPen(j == 0 ? color.light(150) : color.dark(150));
|
|
|
|
p.drawLine(r.left(), r.top(), r.right() - 1, r.bottom() - 1);
|
|
|
|
p.drawLine(r.left(), r.top() + 1, r.right() - 1, r.bottom());
|
|
|
|
p.drawLine(r.right() - 1, r.top(), r.left(), r.bottom() - 1);
|
|
|
|
p.drawLine(r.right() - 1, r.top() + 1, r.left(), r.bottom());
|
|
|
|
}
|
|
|
|
p.end();
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// menu
|
|
|
|
{
|
2007-11-22 12:36:14 +03:00
|
|
|
int off = (pixmap[P_MENU]->width() - 16) / 2;
|
2007-04-30 16:26:31 +04:00
|
|
|
QSize bSize(16, 16);
|
|
|
|
QBitmap lightBitmap = QBitmap::fromData(bSize,
|
2007-10-15 11:52:06 +04:00
|
|
|
menu_white_bits, QImage::Format_MonoLSB);
|
2007-06-23 02:54:23 +04:00
|
|
|
//lightBitmap.setMask(lightBitmap);
|
2007-04-30 16:26:31 +04:00
|
|
|
QBitmap darkBitmap = QBitmap::fromData(bSize,
|
2007-10-15 11:52:06 +04:00
|
|
|
menu_dgray_bits, QImage::Format_MonoLSB);
|
2007-06-23 02:54:23 +04:00
|
|
|
//darkBitmap.setMask(darkBitmap);
|
2007-04-30 16:26:31 +04:00
|
|
|
|
|
|
|
for (int i = 0; i < NumStates; i++) {
|
|
|
|
bool isAct = (i < 3);
|
2007-11-22 12:36:14 +03:00
|
|
|
QPixmap *pixm = pixmap[P_MENU + i];
|
2007-04-30 16:26:31 +04:00
|
|
|
p.begin(pixm);
|
|
|
|
QColor color = isAct ? activeColor : inactiveColor;
|
|
|
|
p.setPen(color.light(150));
|
|
|
|
p.drawPixmap(off, off, lightBitmap);
|
|
|
|
p.setPen(color.dark(150));
|
|
|
|
p.drawPixmap(off, off, darkBitmap);
|
|
|
|
p.end();
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-12 12:03:19 +04:00
|
|
|
// Help button: a question mark.
|
|
|
|
{
|
|
|
|
QFont font = options()->font(true);
|
|
|
|
font.setWeight(QFont::Black);
|
|
|
|
font.setStretch(110);
|
2007-10-15 11:52:06 +04:00
|
|
|
font.setPointSizeF(font.pointSizeF() * 1.1);
|
2007-10-12 12:03:19 +04:00
|
|
|
for (int i = 0; i < NumStates; i++) {
|
|
|
|
bool isAct = (i < 3);
|
2007-11-22 12:36:14 +03:00
|
|
|
QPixmap *pixm = pixmap[P_HELP + i];
|
2007-10-12 12:03:19 +04:00
|
|
|
pixm->fill(QColor(qRgba(0, 0, 0, 0)));
|
2008-03-08 00:20:04 +03:00
|
|
|
pixm->setAlphaChannel(QPixmap(*pixm));
|
2007-10-12 12:03:19 +04:00
|
|
|
p.begin(pixm);
|
|
|
|
QColor color = isAct ? activeColor : inactiveColor;
|
|
|
|
QRect r = QRect(0, 0, pixm->width(), pixm->height());
|
|
|
|
p.setFont(font);
|
|
|
|
QString label = i18nc("Help button label, one character", "?");
|
|
|
|
r.moveTo(1, 2);
|
|
|
|
p.setPen(color.light(150));
|
|
|
|
p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter, label);
|
|
|
|
r.moveTo(0, 1);
|
|
|
|
p.setPen(color.dark(150));
|
|
|
|
p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter, label);
|
|
|
|
p.end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-18 11:37:43 +04:00
|
|
|
// Help button: a question mark.
|
2007-04-29 21:35:43 +04:00
|
|
|
// pin
|
2007-04-30 16:26:31 +04:00
|
|
|
for (int i = 0; i < NumStates; i++) {
|
2007-04-30 16:26:01 +04:00
|
|
|
const bool isDown = (i == Down || i == IDown);
|
2007-04-30 16:26:31 +04:00
|
|
|
bool isAct = (i < 3);
|
|
|
|
|
2009-08-09 17:14:51 +04:00
|
|
|
const QPoint origin(0, 0);
|
|
|
|
const QSize pinSize(16, 16);
|
|
|
|
QBitmap white = QBitmap::fromData(pinSize,
|
|
|
|
isDown ? pindown_white_bits : pinup_white_bits,
|
|
|
|
QImage::Format_MonoLSB);
|
|
|
|
QBitmap gray = QBitmap::fromData(pinSize,
|
|
|
|
isDown ? pindown_gray_bits : pinup_gray_bits,
|
|
|
|
QImage::Format_MonoLSB);
|
|
|
|
QBitmap dgray = QBitmap::fromData(pinSize,
|
|
|
|
isDown ? pindown_dgray_bits : pinup_dgray_bits,
|
2007-11-22 12:36:14 +03:00
|
|
|
QImage::Format_MonoLSB);
|
2009-08-09 17:14:51 +04:00
|
|
|
QPixmap maskedImage(16, 16);
|
2007-11-22 12:36:14 +03:00
|
|
|
QPixmap *pix = pixmap[P_PINUP + i];
|
2007-04-30 16:26:31 +04:00
|
|
|
QColor color = isAct ? activeColor : inactiveColor;
|
2007-11-22 12:36:14 +03:00
|
|
|
QImage pin(16, 16, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
p.begin(&pin);
|
2009-08-09 17:14:51 +04:00
|
|
|
maskedImage.setMask(white);
|
|
|
|
maskedImage.fill(color.light(150));
|
|
|
|
p.drawPixmap(origin, maskedImage);
|
|
|
|
maskedImage.setMask(gray);
|
|
|
|
maskedImage.fill(color);
|
|
|
|
p.drawPixmap(origin, maskedImage);
|
|
|
|
maskedImage.setMask(dgray);
|
|
|
|
maskedImage.fill(color.dark(150));
|
|
|
|
p.drawPixmap(origin, maskedImage);
|
2007-04-30 16:26:31 +04:00
|
|
|
p.end();
|
2007-11-22 12:36:14 +03:00
|
|
|
*pix = QPixmap::fromImage(pin);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Apply the hilight effect to the 'Hover' icons
|
|
|
|
KIconEffect ie;
|
|
|
|
QPixmap hilighted;
|
2007-11-22 12:36:14 +03:00
|
|
|
for (int i = 0; i < P_NUM_PIXMAPS; i += NumStates) {
|
|
|
|
hilighted = ie.apply(*pixmap[i + Norm],
|
2007-10-01 19:09:41 +04:00
|
|
|
KIconLoader::Small, KIconLoader::ActiveState);
|
2007-11-22 12:36:14 +03:00
|
|
|
*pixmap[i + Hover] = hilighted;
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2007-11-22 12:36:14 +03:00
|
|
|
hilighted = ie.apply(*pixmap[i + INorm],
|
2007-10-01 19:09:41 +04:00
|
|
|
KIconLoader::Small, KIconLoader::ActiveState);
|
2007-11-22 12:36:14 +03:00
|
|
|
*pixmap[i + IHover] = hilighted;
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create the titlebar gradients
|
|
|
|
if (QPixmap::defaultDepth() > 8) {
|
|
|
|
QColor titleColor[4] = {
|
|
|
|
options()->color(KDecoration::ColorTitleBar, true),
|
|
|
|
options()->color(KDecoration::ColorFrame, true),
|
|
|
|
|
|
|
|
options()->color(KDecoration::ColorTitleBlend, false),
|
|
|
|
options()->color(KDecoration::ColorTitleBar, false)
|
|
|
|
};
|
|
|
|
|
|
|
|
if (colored_frame) {
|
|
|
|
titleColor[0] = options()->color(KDecoration::ColorTitleBlend, true);
|
|
|
|
titleColor[1] = options()->color(KDecoration::ColorTitleBar, true);
|
|
|
|
}
|
|
|
|
|
2007-04-30 16:26:31 +04:00
|
|
|
for (int i = 0; i < 2; i++) {
|
2007-04-29 21:35:43 +04:00
|
|
|
if (titleColor[2 * i] != titleColor[2 * i + 1]) {
|
|
|
|
if (!titleGradient[i]) {
|
|
|
|
titleGradient[i] = new QPixmap;
|
|
|
|
}
|
2007-04-30 16:21:07 +04:00
|
|
|
const int titleHeight = buttonSize + 3;
|
|
|
|
*titleGradient[i] = QPixmap(64, titleHeight);
|
|
|
|
|
|
|
|
QPainter p(titleGradient[i]);
|
|
|
|
QLinearGradient gradient(0, 0, 0, titleHeight);
|
|
|
|
gradient.setColorAt(0.0, titleColor[2 * i]);
|
|
|
|
gradient.setColorAt(1.0, titleColor[2 * i + 1]);
|
|
|
|
QBrush brush(gradient);
|
|
|
|
p.fillRect(0, 0, 64, titleHeight, brush);
|
2007-04-29 21:35:43 +04:00
|
|
|
} else {
|
|
|
|
delete titleGradient[i];
|
|
|
|
titleGradient[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::positionButtons()
|
|
|
|
{
|
|
|
|
QFontMetrics fm(options()->font(isActive()));
|
|
|
|
QString cap = caption();
|
|
|
|
if (cap.length() < 5) // make sure the titlebar has sufficiently wide
|
|
|
|
cap = "XXXXX"; // area for dragging the window
|
|
|
|
int textLen = fm.width(cap);
|
|
|
|
|
|
|
|
QRect t = titlebar->captionSpacer->geometry();
|
|
|
|
int titleWidth = titlebar->width() - t.width() + textLen + 2;
|
|
|
|
if (titleWidth > width()) titleWidth = width();
|
|
|
|
|
|
|
|
titlebar->resize(titleWidth, buttonSize + 4);
|
|
|
|
titlebar->move(bar_x_ofs, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Transparent bound stuff.
|
2009-10-05 10:59:10 +04:00
|
|
|
//static QRect *visible_bound;
|
2007-04-29 21:35:43 +04:00
|
|
|
static QPolygon bound_shape;
|
|
|
|
|
2007-10-12 12:03:19 +04:00
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
bool B2Client::drawbound(const QRect& geom, bool clear)
|
|
|
|
{
|
2007-11-22 12:36:14 +03:00
|
|
|
// Let kwin draw the bounds, for now.
|
2009-10-05 10:59:10 +04:00
|
|
|
Q_UNUSED(geom);
|
|
|
|
Q_UNUSED(clear);
|
2007-11-22 12:36:14 +03:00
|
|
|
return false;
|
|
|
|
#if 0
|
2007-04-29 21:35:43 +04:00
|
|
|
if (clear) {
|
|
|
|
if (!visible_bound) return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!visible_bound) {
|
|
|
|
visible_bound = new QRect(geom);
|
|
|
|
QRect t = titlebar->geometry();
|
2007-11-22 12:36:14 +03:00
|
|
|
QRect g = geom;
|
|
|
|
// line width is 5 pixels, so compensate for the 2 outer pixels (#88657)
|
|
|
|
g.adjust(2, 2, -2, -2);
|
|
|
|
int frameTop = geom.top() + t.bottom() + 2;
|
|
|
|
int barLeft = geom.left() + bar_x_ofs + 2;
|
2007-04-29 21:35:43 +04:00
|
|
|
int barRight = barLeft + t.width() - 1;
|
|
|
|
if (barRight > geom.right()) barRight = geom.right();
|
|
|
|
barRight -= 2;
|
|
|
|
|
|
|
|
bound_shape.putPoints(0, 8,
|
|
|
|
g.left(), frameTop,
|
|
|
|
barLeft, frameTop,
|
|
|
|
barLeft, g.top(),
|
|
|
|
barRight, g.top(),
|
|
|
|
barRight, frameTop,
|
|
|
|
g.right(), frameTop,
|
|
|
|
g.right(), g.bottom(),
|
|
|
|
g.left(), g.bottom());
|
|
|
|
} else {
|
|
|
|
*visible_bound = geom;
|
|
|
|
}
|
2007-11-22 12:36:14 +03:00
|
|
|
QPainter p;
|
|
|
|
if (p.begin(workspaceWidget())) {
|
|
|
|
p.setPen(QPen(Qt::white, 5));
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Xor);
|
|
|
|
p.drawPolygon(bound_shape);
|
|
|
|
if (clear) {
|
|
|
|
delete visible_bound;
|
|
|
|
visible_bound = 0;
|
2007-10-18 11:37:43 +04:00
|
|
|
}
|
2007-11-22 12:36:14 +03:00
|
|
|
p.end();
|
2007-10-12 12:03:19 +04:00
|
|
|
}
|
2007-11-20 19:00:58 +03:00
|
|
|
#endif
|
2007-04-29 21:35:43 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool B2Client::eventFilter(QObject *o, QEvent *e)
|
|
|
|
{
|
|
|
|
if (o != widget())
|
|
|
|
return false;
|
|
|
|
switch (e->type()) {
|
|
|
|
case QEvent::Resize:
|
|
|
|
resizeEvent(static_cast< QResizeEvent* >(e));
|
|
|
|
return true;
|
|
|
|
case QEvent::Paint:
|
|
|
|
paintEvent(static_cast< QPaintEvent* >(e));
|
|
|
|
return true;
|
|
|
|
case QEvent::MouseButtonDblClick:
|
|
|
|
titlebar->mouseDoubleClickEvent(static_cast< QMouseEvent* >(e));
|
|
|
|
return true;
|
2007-06-23 02:54:23 +04:00
|
|
|
case QEvent::Wheel:
|
|
|
|
titlebar->wheelEvent(static_cast< QWheelEvent* >(e));
|
|
|
|
return true;
|
2007-04-29 21:35:43 +04:00
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
processMousePressEvent(static_cast< QMouseEvent* >(e));
|
|
|
|
return true;
|
|
|
|
case QEvent::Show:
|
|
|
|
showEvent(static_cast< QShowEvent* >(e));
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// =====================================
|
|
|
|
|
|
|
|
B2Button::B2Button(B2Client *_client, QWidget *parent,
|
|
|
|
const QString& tip, const int realizeBtns)
|
2007-04-30 16:26:01 +04:00
|
|
|
: QAbstractButton(parent), hover(false)
|
2007-04-29 21:35:43 +04:00
|
|
|
{
|
|
|
|
setAttribute(Qt::WA_NoSystemBackground);
|
|
|
|
setCursor(Qt::ArrowCursor);
|
|
|
|
realizeButtons = realizeBtns;
|
|
|
|
client = _client;
|
|
|
|
useMiniIcon = false;
|
|
|
|
setFixedSize(buttonSize, buttonSize);
|
2007-04-30 02:33:21 +04:00
|
|
|
this->setToolTip(tip);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QSize B2Button::sizeHint() const
|
|
|
|
{
|
|
|
|
return QSize(buttonSize, buttonSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizePolicy B2Button::sizePolicy() const
|
|
|
|
{
|
|
|
|
return(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
|
|
|
|
}
|
|
|
|
|
2007-04-30 16:26:01 +04:00
|
|
|
void B2Button::paintEvent(QPaintEvent *)
|
2007-04-29 21:35:43 +04:00
|
|
|
{
|
2007-04-30 16:26:01 +04:00
|
|
|
QPainter p(this);
|
2007-04-29 21:35:43 +04:00
|
|
|
QPixmap* gradient = titleGradient[client->isActive() ? 0 : 1];
|
|
|
|
if (gradient) {
|
2007-04-30 16:26:01 +04:00
|
|
|
p.drawTiledPixmap(0, 0, buttonSize, buttonSize, *gradient, 0, 2);
|
2007-04-29 21:35:43 +04:00
|
|
|
} else {
|
2007-04-30 16:26:01 +04:00
|
|
|
p.fillRect(rect(), bg);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
if (useMiniIcon) {
|
2007-04-30 02:33:21 +04:00
|
|
|
QPixmap miniIcon = client->icon().pixmap(
|
|
|
|
style()->pixelMetric(QStyle::PM_SmallIconSize),
|
2007-04-29 21:35:43 +04:00
|
|
|
client->isActive() ? QIcon::Normal : QIcon::Disabled);
|
2007-06-06 12:01:59 +04:00
|
|
|
p.drawPixmap(1 + (width() - miniIcon.width()) / 2,
|
2007-04-29 21:35:43 +04:00
|
|
|
(height() - miniIcon.height()) / 2, miniIcon);
|
|
|
|
} else {
|
|
|
|
int type;
|
|
|
|
if (client->isActive()) {
|
|
|
|
if (isChecked() || isDown())
|
|
|
|
type = Down;
|
|
|
|
else if (hover)
|
|
|
|
type = Hover;
|
|
|
|
else
|
|
|
|
type = Norm;
|
|
|
|
} else {
|
|
|
|
if (isChecked() || isDown())
|
|
|
|
type = IDown;
|
|
|
|
else if (hover)
|
|
|
|
type = IHover;
|
|
|
|
else
|
|
|
|
type = INorm;
|
|
|
|
}
|
2007-06-06 12:01:59 +04:00
|
|
|
p.drawPixmap(1 + (width() - icon[type]->width()) / 2,
|
2007-04-29 21:35:43 +04:00
|
|
|
(height() - icon[type]->height()) / 2, *icon[type]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Button::setPixmaps(int button_id)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < NumStates; i++) {
|
|
|
|
icon[i] = B2::pixmap[button_id + i];
|
|
|
|
}
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Button::mousePressEvent(QMouseEvent * e)
|
|
|
|
{
|
|
|
|
last_button = e->button();
|
|
|
|
QMouseEvent me(e->type(), e->pos(), e->globalPos(),
|
|
|
|
(e->button() & realizeButtons) ? Qt::LeftButton : Qt::NoButton,
|
|
|
|
(e->button() & realizeButtons) ? Qt::LeftButton : Qt::NoButton,
|
|
|
|
e->modifiers());
|
2007-04-30 16:26:01 +04:00
|
|
|
QAbstractButton::mousePressEvent(&me);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void B2Button::mouseReleaseEvent(QMouseEvent * e)
|
|
|
|
{
|
|
|
|
last_button = e->button();
|
|
|
|
QMouseEvent me(e->type(), e->pos(), e->globalPos(),
|
|
|
|
(e->button() & realizeButtons) ? Qt::LeftButton : Qt::NoButton,
|
|
|
|
(e->button() & realizeButtons) ? Qt::LeftButton : Qt::NoButton,
|
|
|
|
e->modifiers());
|
2007-04-30 16:26:01 +04:00
|
|
|
QAbstractButton::mouseReleaseEvent(&me);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void B2Button::enterEvent(QEvent *e)
|
|
|
|
{
|
|
|
|
hover = true;
|
|
|
|
repaint();
|
2007-04-30 16:26:01 +04:00
|
|
|
QAbstractButton::enterEvent(e);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void B2Button::leaveEvent(QEvent *e)
|
|
|
|
{
|
|
|
|
hover = false;
|
|
|
|
repaint();
|
2007-04-30 16:26:01 +04:00
|
|
|
QAbstractButton::leaveEvent(e);
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// =====================================
|
|
|
|
|
|
|
|
B2Titlebar::B2Titlebar(B2Client *parent)
|
2009-12-26 19:57:26 +03:00
|
|
|
: QWidget(parent->widget()),
|
2007-04-29 21:35:43 +04:00
|
|
|
client(parent),
|
|
|
|
set_x11mask(false), isfullyobscured(false), shift_move(false)
|
|
|
|
{
|
|
|
|
setAttribute(Qt::WA_NoSystemBackground);
|
2007-10-12 12:03:19 +04:00
|
|
|
captionSpacer = new QSpacerItem(buttonSize, buttonSize + 3,
|
2007-04-29 21:35:43 +04:00
|
|
|
QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool B2Titlebar::x11Event(XEvent *e)
|
|
|
|
{
|
|
|
|
if (!set_x11mask) {
|
|
|
|
set_x11mask = true;
|
|
|
|
XSelectInput(QX11Info::display(), winId(),
|
|
|
|
KeyPressMask | KeyReleaseMask |
|
|
|
|
ButtonPressMask | ButtonReleaseMask |
|
|
|
|
KeymapStateMask |
|
|
|
|
ButtonMotionMask |
|
|
|
|
EnterWindowMask | LeaveWindowMask |
|
|
|
|
FocusChangeMask |
|
|
|
|
ExposureMask |
|
|
|
|
PropertyChangeMask |
|
|
|
|
StructureNotifyMask | SubstructureRedirectMask |
|
|
|
|
VisibilityChangeMask);
|
|
|
|
}
|
|
|
|
switch (e->type) {
|
|
|
|
case VisibilityNotify:
|
|
|
|
isfullyobscured = false;
|
|
|
|
if (e->xvisibility.state == VisibilityFullyObscured) {
|
|
|
|
isfullyobscured = true;
|
|
|
|
client->unobscureTitlebar();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return QWidget::x11Event(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Titlebar::drawTitlebar(QPainter &p, bool state)
|
|
|
|
{
|
|
|
|
QPixmap* gradient = titleGradient[state ? 0 : 1];
|
|
|
|
|
|
|
|
QRect t = rect();
|
|
|
|
// black titlebar frame
|
|
|
|
p.setPen(Qt::black);
|
|
|
|
p.drawLine(0, 0, 0, t.bottom());
|
|
|
|
p.drawLine(0, 0, t.right(), 0);
|
|
|
|
p.drawLine(t.right(), 0, t.right(), t.bottom());
|
|
|
|
|
|
|
|
// titlebar fill
|
|
|
|
const QPalette cg = options()->palette(KDecoration::ColorTitleBar, state);
|
|
|
|
QBrush brush(cg.background());
|
|
|
|
if (gradient) brush.setTexture(*gradient);
|
|
|
|
qDrawShadeRect(&p, 1, 1, t.right() - 1, t.height() - 1,
|
|
|
|
cg, false, 1, 0, &brush);
|
|
|
|
|
|
|
|
// and the caption
|
|
|
|
p.setPen(options()->color(KDecoration::ColorFont, state));
|
|
|
|
p.setFont(options()->font(state));
|
|
|
|
t = captionSpacer->geometry();
|
2007-10-12 12:03:19 +04:00
|
|
|
p.drawText(t.translated(0, 1), Qt::AlignCenter | Qt::AlignVCenter, client->caption());
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void B2Titlebar::recalcBuffer()
|
|
|
|
{
|
|
|
|
titleBuffer = QPixmap(width(), height());
|
|
|
|
|
|
|
|
QPainter p(&titleBuffer);
|
|
|
|
drawTitlebar(p, true);
|
|
|
|
oldTitle = windowTitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Titlebar::resizeEvent(QResizeEvent *)
|
|
|
|
{
|
|
|
|
recalcBuffer();
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void B2Titlebar::paintEvent(QPaintEvent *)
|
|
|
|
{
|
2009-10-05 10:59:10 +04:00
|
|
|
if (client->isActive()) {
|
|
|
|
QPainter p(this);
|
|
|
|
p.drawPixmap(0, 0, titleBuffer);
|
|
|
|
} else {
|
2007-04-29 21:35:43 +04:00
|
|
|
QPainter p(this);
|
|
|
|
drawTitlebar(p, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Titlebar::mouseDoubleClickEvent(QMouseEvent *e)
|
|
|
|
{
|
|
|
|
if (e->button() == Qt::LeftButton && e->y() < height()) {
|
|
|
|
client->titlebarDblClickOperation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-23 02:54:23 +04:00
|
|
|
void B2Titlebar::wheelEvent(QWheelEvent *e)
|
|
|
|
{
|
|
|
|
if (client->isSetShade() || rect().contains(e->pos()))
|
|
|
|
client->titlebarMouseWheelOperation(e->delta());
|
|
|
|
}
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
void B2Titlebar::mousePressEvent(QMouseEvent * e)
|
|
|
|
{
|
|
|
|
shift_move = e->modifiers() & Qt::ShiftModifier;
|
|
|
|
if (shift_move) {
|
|
|
|
moveOffset = e->globalPos();
|
|
|
|
} else {
|
|
|
|
e->ignore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Titlebar::mouseReleaseEvent(QMouseEvent * e)
|
|
|
|
{
|
|
|
|
if (shift_move) shift_move = false;
|
|
|
|
else e->ignore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Titlebar::mouseMoveEvent(QMouseEvent * e)
|
|
|
|
{
|
|
|
|
if (shift_move) {
|
|
|
|
int oldx = mapFromGlobal(moveOffset).x();
|
|
|
|
int xdiff = e->globalPos().x() - moveOffset.x();
|
|
|
|
moveOffset = e->globalPos();
|
|
|
|
if (oldx >= 0 && oldx <= rect().right()) {
|
|
|
|
client->titleMoveRel(xdiff);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
e->ignore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace B2
|
|
|
|
|
|
|
|
#include "b2client.moc"
|
|
|
|
|
2007-04-30 02:33:21 +04:00
|
|
|
// vim: sw=4 ts=8
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
#endif // CLIENTS/B2/B2CLIENT.CPP
|