2003-11-02 11:03:41 +00:00
|
|
|
/*
|
2001-08-22 10:11:06 +00:00
|
|
|
* B-II KWin Client
|
|
|
|
*
|
|
|
|
* Changes:
|
2003-05-21 09:12:44 +00:00
|
|
|
* Customizable button positions by Karol Szwed <gallium@kde.org>
|
2003-11-02 11:03:41 +00:00
|
|
|
*
|
2004-05-23 22:59:13 +00:00
|
|
|
* Thin frame in fixed size windows, titlebar gradient support, accessibility
|
|
|
|
* improvements, customizable menu double click action and button hover
|
|
|
|
* effects are
|
2004-05-21 10:37:36 +00:00
|
|
|
* Copyright (c) 2003,2004 Luciano Montanaro <mikelima@cirulla.net>
|
2003-11-02 11:03:41 +00:00
|
|
|
*/
|
2001-08-22 10:11:06 +00:00
|
|
|
|
2001-06-19 14:32:08 +00:00
|
|
|
#include "b2client.h"
|
2004-05-22 00:31:07 +00:00
|
|
|
#include <qapplication.h>
|
2001-06-19 14:32:08 +00:00
|
|
|
#include <qlayout.h>
|
|
|
|
#include <qdrawutil.h>
|
|
|
|
#include <kpixmapeffect.h>
|
2004-05-23 22:59:13 +00:00
|
|
|
#include <kimageeffect.h>
|
|
|
|
#include <kicontheme.h>
|
|
|
|
#include <kiconeffect.h>
|
2001-06-19 14:32:08 +00:00
|
|
|
#include <kdrawutil.h>
|
2001-07-01 10:10:17 +00:00
|
|
|
#include <klocale.h>
|
2001-09-08 10:12:23 +00:00
|
|
|
#include <kconfig.h>
|
2001-06-19 14:32:08 +00:00
|
|
|
#include <qbitmap.h>
|
2003-09-20 17:44:49 +00:00
|
|
|
#include <qlabel.h>
|
|
|
|
#include <qtooltip.h>
|
2001-06-19 14:32:08 +00:00
|
|
|
|
2003-09-20 17:44:49 +00:00
|
|
|
#include <X11/Xlib.h>
|
2001-06-19 14:32:08 +00:00
|
|
|
|
2002-08-27 18:08:20 +00:00
|
|
|
namespace B2 {
|
|
|
|
|
|
|
|
#include "bitmaps.h"
|
|
|
|
|
2004-05-23 22:59:13 +00:00
|
|
|
enum {
|
|
|
|
Norm = 0,
|
|
|
|
Hover, Down, INorm, IHover, IDown,
|
|
|
|
NumStates
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
P_CLOSE = 0,
|
2004-06-20 10:03:04 +00:00
|
|
|
P_MAX, P_NORMALIZE, P_ICONIFY, P_PINUP, P_MENU, P_HELP, P_SHADE, P_RESIZE,
|
2004-05-23 22:59:13 +00:00
|
|
|
P_NUM_BUTTON_TYPES
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NUM_PIXMAPS (P_NUM_BUTTON_TYPES * NumStates)
|
2001-06-19 14:32:08 +00:00
|
|
|
|
|
|
|
static KPixmap *pixmap[NUM_PIXMAPS];
|
|
|
|
|
2004-05-23 22:59:13 +00:00
|
|
|
// active
|
|
|
|
#define PIXMAP_A(i) (pixmap[(i) * NumStates + Norm])
|
|
|
|
// active, hover
|
|
|
|
#define PIXMAP_AH(i) (pixmap[(i) * NumStates + Hover])
|
|
|
|
// active, down
|
|
|
|
#define PIXMAP_AD(i) (pixmap[(i) * NumStates + Down])
|
|
|
|
// inactive
|
|
|
|
#define PIXMAP_I(i) (pixmap[(i) * NumStates + INorm])
|
|
|
|
// inactive, hover
|
|
|
|
#define PIXMAP_IH(i) (pixmap[(i) * NumStates + IHover])
|
|
|
|
// inactive, down
|
|
|
|
#define PIXMAP_ID(i) (pixmap[(i) * NumStates + IDown])
|
2001-06-19 14:32:08 +00:00
|
|
|
|
2003-10-22 13:52:51 +00:00
|
|
|
static KPixmap* titleGradient[2] = {0, 0};
|
2003-10-04 02:02:07 +00:00
|
|
|
|
2003-10-04 18:53:44 +00:00
|
|
|
static int thickness = 4; // Frame thickness
|
2003-10-15 16:50:29 +00:00
|
|
|
static int buttonSize = 16;
|
2003-10-04 18:53:44 +00:00
|
|
|
|
2004-05-22 00:31:07 +00:00
|
|
|
enum DblClickOperation {
|
|
|
|
NoOp = 0,
|
|
|
|
MinimizeOp,
|
|
|
|
ShadeOp,
|
|
|
|
CloseOp
|
|
|
|
};
|
|
|
|
|
|
|
|
static DblClickOperation menu_dbl_click_op = NoOp;
|
|
|
|
|
2001-06-19 14:32:08 +00:00
|
|
|
static bool pixmaps_created = false;
|
2001-09-08 10:12:23 +00:00
|
|
|
static bool colored_frame = false;
|
2004-06-20 10:03:04 +00:00
|
|
|
static bool do_draw_handle = true;
|
2004-09-26 10:29:23 +00:00
|
|
|
static bool drawSmallBorders = false;
|
2001-09-08 10:12:23 +00:00
|
|
|
|
2003-10-04 18:53:44 +00:00
|
|
|
// =====================================
|
|
|
|
|
|
|
|
extern "C" KDecorationFactory* create_factory()
|
|
|
|
{
|
|
|
|
return new B2::B2ClientFactory();
|
|
|
|
}
|
|
|
|
|
|
|
|
// =====================================
|
|
|
|
|
2003-09-20 17:44:49 +00:00
|
|
|
static inline const KDecorationOptions *options()
|
|
|
|
{
|
|
|
|
return KDecoration::options();
|
|
|
|
}
|
|
|
|
|
2003-10-18 20:37:49 +00:00
|
|
|
static void redraw_pixmaps();
|
|
|
|
|
2003-10-04 18:53:44 +00:00
|
|
|
static void read_config(B2ClientFactory *f)
|
2001-09-08 10:12:23 +00:00
|
|
|
{
|
2003-10-15 16:50:29 +00:00
|
|
|
// Force button size to be in a reasonable range.
|
|
|
|
// If the frame width is large, the button size must be large too.
|
|
|
|
buttonSize = (QFontMetrics(options()->font(true)).height() + 1) & 0x3e;
|
|
|
|
if (buttonSize < 16) buttonSize = 16;
|
|
|
|
|
2001-09-08 10:12:23 +00:00
|
|
|
KConfig conf("kwinb2rc");
|
|
|
|
conf.setGroup("General");
|
2004-06-02 13:46:54 +00:00
|
|
|
colored_frame = conf.readBoolEntry("UseTitleBarBorderColors", false);
|
2004-06-20 10:03:04 +00:00
|
|
|
do_draw_handle = conf.readBoolEntry("DrawGrabHandle", true);
|
2004-09-26 10:29:23 +00:00
|
|
|
drawSmallBorders = !options()->moveResizeMaximizedWindows();
|
|
|
|
|
2004-05-22 00:31:07 +00:00
|
|
|
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;
|
|
|
|
}
|
2003-10-04 18:53:44 +00:00
|
|
|
|
|
|
|
switch (options()->preferredBorderSize(f)) {
|
|
|
|
case KDecoration::BorderTiny:
|
|
|
|
thickness = 2;
|
|
|
|
break;
|
|
|
|
case KDecoration::BorderLarge:
|
|
|
|
thickness = 5;
|
|
|
|
break;
|
|
|
|
case KDecoration::BorderVeryLarge:
|
|
|
|
thickness = 8;
|
|
|
|
break;
|
|
|
|
case KDecoration::BorderHuge:
|
2003-10-18 20:37:49 +00:00
|
|
|
thickness = 12;
|
|
|
|
break;
|
2003-10-04 18:53:44 +00:00
|
|
|
case KDecoration::BorderVeryHuge:
|
|
|
|
case KDecoration::BorderOversized:
|
|
|
|
case KDecoration::BorderNormal:
|
|
|
|
default:
|
|
|
|
thickness = 4;
|
|
|
|
}
|
2001-09-08 10:12:23 +00:00
|
|
|
}
|
2001-06-19 14:32:08 +00:00
|
|
|
|
|
|
|
static void drawB2Rect(KPixmap *pix, const QColor &primary, bool down)
|
|
|
|
{
|
2003-10-18 20:37:49 +00:00
|
|
|
QPainter p(pix);
|
2001-06-19 14:32:08 +00:00
|
|
|
QColor hColor = primary.light(150);
|
|
|
|
QColor lColor = primary.dark(150);
|
|
|
|
|
2004-05-15 23:15:01 +00:00
|
|
|
if (QPixmap::defaultDepth() > 8) {
|
|
|
|
if (down)
|
2001-06-19 14:32:08 +00:00
|
|
|
KPixmapEffect::gradient(*pix, lColor, hColor,
|
|
|
|
KPixmapEffect::DiagonalGradient);
|
|
|
|
else
|
|
|
|
KPixmapEffect::gradient(*pix, hColor, lColor,
|
|
|
|
KPixmapEffect::DiagonalGradient);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pix->fill(primary);
|
2004-06-20 10:03:04 +00:00
|
|
|
int x2 = pix->width() - 1;
|
|
|
|
int y2 = pix->height() - 1;
|
2001-06-19 14:32:08 +00:00
|
|
|
p.setPen(down ? hColor : lColor);
|
|
|
|
p.drawLine(0, 0, x2, 0);
|
|
|
|
p.drawLine(0, 0, 0, y2);
|
2004-06-20 10:03:04 +00:00
|
|
|
p.drawLine(1, x2 - 1, x2 - 1, y2 - 1);
|
|
|
|
p.drawLine(x2 - 1, 1, x2 - 1, y2 - 1);
|
2001-06-19 14:32:08 +00:00
|
|
|
p.setPen(down ? lColor : hColor);
|
|
|
|
p.drawRect(1, 1, x2, y2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap* kwin_get_menu_pix_hack()
|
|
|
|
{
|
|
|
|
//return menu_pix; FIXME
|
|
|
|
return PIXMAP_A(P_MENU);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void create_pixmaps()
|
|
|
|
{
|
2004-05-15 23:15:01 +00:00
|
|
|
if (pixmaps_created)
|
2001-06-19 14:32:08 +00:00
|
|
|
return;
|
|
|
|
pixmaps_created = true;
|
|
|
|
|
|
|
|
int i;
|
2003-10-18 20:37:49 +00:00
|
|
|
int bsize = buttonSize - 2;
|
|
|
|
if (bsize < 16) bsize = 16;
|
2003-11-02 11:03:41 +00:00
|
|
|
|
2001-06-19 14:32:08 +00:00
|
|
|
for (i = 0; i < NUM_PIXMAPS; i++) {
|
|
|
|
pixmap[i] = new KPixmap;
|
2004-05-23 22:59:13 +00:00
|
|
|
switch (i / NumStates) {
|
2003-10-18 20:37:49 +00:00
|
|
|
case P_MAX: // will be initialized by copying P_CLOSE
|
2004-06-20 10:03:04 +00:00
|
|
|
case P_RESIZE:
|
2003-11-02 11:03:41 +00:00
|
|
|
break;
|
|
|
|
case P_ICONIFY:
|
2003-10-18 20:37:49 +00:00
|
|
|
pixmap[i]->resize(10, 10); break;
|
2004-05-15 23:15:01 +00:00
|
|
|
case P_SHADE:
|
2003-11-02 11:03:41 +00:00
|
|
|
case P_CLOSE:
|
2003-10-18 20:37:49 +00:00
|
|
|
pixmap[i]->resize(bsize, bsize); break;
|
2003-11-02 11:03:41 +00:00
|
|
|
default:
|
2003-10-18 20:37:49 +00:00
|
|
|
pixmap[i]->resize(16, 16); break;
|
2001-06-19 14:32:08 +00: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
|
|
|
|
QBitmap pinupMask(16, 16, pinup_mask_bits, true);
|
|
|
|
PIXMAP_A(P_PINUP)->setMask(pinupMask);
|
|
|
|
PIXMAP_I(P_PINUP)->setMask(pinupMask);
|
|
|
|
QBitmap pindownMask(16, 16, pindown_mask_bits, true);
|
|
|
|
PIXMAP_AD(P_PINUP)->setMask(pindownMask);
|
|
|
|
PIXMAP_ID(P_PINUP)->setMask(pindownMask);
|
|
|
|
|
|
|
|
QBitmap menuMask(16, 16, menu_mask_bits, true);
|
2004-05-23 22:59:13 +00:00
|
|
|
for (i = 0; i < NumStates; i++)
|
|
|
|
pixmap[P_MENU * NumStates + i]->setMask(menuMask);
|
2001-06-19 14:32:08 +00:00
|
|
|
|
|
|
|
QBitmap helpMask(16, 16, help_mask_bits, true);
|
2004-05-23 22:59:13 +00:00
|
|
|
for (i = 0; i < NumStates; i++)
|
|
|
|
pixmap[P_HELP * NumStates + i]->setMask(helpMask);
|
2003-11-02 11:03:41 +00:00
|
|
|
|
2003-10-04 02:02:07 +00:00
|
|
|
QBitmap normalizeMask(16, 16, true);
|
|
|
|
// draw normalize icon mask
|
2004-05-15 23:15:01 +00:00
|
|
|
QPainter mask;
|
|
|
|
mask.begin(&normalizeMask);
|
2003-11-02 11:03:41 +00:00
|
|
|
|
2003-10-04 02:02:07 +00:00
|
|
|
QBrush one(Qt::color1);
|
2003-11-09 00:41:10 +00:00
|
|
|
mask.fillRect(normalizeMask.width() - 12, normalizeMask.height() - 12,
|
|
|
|
12, 12, one);
|
2003-10-04 02:02:07 +00:00
|
|
|
mask.fillRect(0, 0, 10, 10, one);
|
2004-05-15 23:15:01 +00:00
|
|
|
mask.end();
|
2003-11-02 11:03:41 +00:00
|
|
|
|
2004-05-23 22:59:13 +00:00
|
|
|
for (i = 0; i < NumStates; i++)
|
|
|
|
pixmap[P_NORMALIZE * NumStates + i]->setMask(normalizeMask);
|
2004-05-15 23:15:01 +00:00
|
|
|
|
|
|
|
QBitmap shadeMask(bsize, bsize, true);
|
|
|
|
mask.begin(&shadeMask);
|
|
|
|
mask.fillRect(0, 0, bsize, 6, one);
|
|
|
|
mask.end();
|
2004-05-23 22:59:13 +00:00
|
|
|
for (i = 0; i < NumStates; i++)
|
|
|
|
pixmap[P_SHADE * NumStates + i]->setMask(shadeMask);
|
2003-11-02 11:03:41 +00:00
|
|
|
|
2003-10-04 02:02:07 +00:00
|
|
|
titleGradient[0] = 0;
|
|
|
|
titleGradient[1] = 0;
|
|
|
|
|
2001-06-19 14:32:08 +00:00
|
|
|
redraw_pixmaps();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_pixmaps()
|
|
|
|
{
|
2003-10-04 02:02:07 +00:00
|
|
|
for (int i = 0; i < NUM_PIXMAPS; i++) {
|
|
|
|
delete pixmap[i];
|
|
|
|
pixmap[i] = 0;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
delete titleGradient[i];
|
|
|
|
titleGradient[i] = 0;
|
|
|
|
}
|
2001-06-19 14:32:08 +00:00
|
|
|
pixmaps_created = false;
|
|
|
|
}
|
|
|
|
|
2003-09-20 17:44:49 +00:00
|
|
|
// =====================================
|
2001-06-19 14:32:08 +00:00
|
|
|
|
2003-10-11 12:24:51 +00:00
|
|
|
B2ClientFactory::B2ClientFactory()
|
2001-06-19 14:32:08 +00:00
|
|
|
{
|
2003-10-11 12:24:51 +00:00
|
|
|
read_config(this);
|
|
|
|
create_pixmaps();
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
|
|
|
|
2003-10-11 12:24:51 +00:00
|
|
|
B2ClientFactory::~B2ClientFactory()
|
2001-06-19 14:32:08 +00:00
|
|
|
{
|
2003-10-11 12:24:51 +00:00
|
|
|
delete_pixmaps();
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
|
|
|
|
2003-10-11 12:24:51 +00:00
|
|
|
KDecoration *B2ClientFactory::createDecoration(KDecorationBridge *b)
|
2001-06-19 14:32:08 +00:00
|
|
|
{
|
2003-10-11 12:24:51 +00:00
|
|
|
return new B2::B2Client(b, this);
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
|
|
|
|
2003-10-18 20:37:49 +00:00
|
|
|
bool B2ClientFactory::reset(unsigned long changed)
|
2001-06-19 14:32:08 +00:00
|
|
|
{
|
2003-10-18 21:03:29 +00:00
|
|
|
bool needsReset = SettingColors ? true : false;
|
2003-10-11 12:24:51 +00:00
|
|
|
// TODO Do not recreate decorations if it is not needed. Look at
|
|
|
|
// ModernSystem for how to do that
|
|
|
|
read_config(this);
|
2003-10-18 20:37:49 +00:00
|
|
|
if (changed & SettingFont) {
|
|
|
|
delete_pixmaps();
|
|
|
|
create_pixmaps();
|
|
|
|
needsReset = true;
|
|
|
|
}
|
2003-10-11 12:24:51 +00:00
|
|
|
redraw_pixmaps();
|
|
|
|
// For now just return true.
|
2003-10-18 20:37:49 +00:00
|
|
|
return needsReset;
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
|
|
|
|
2003-10-11 12:24:51 +00:00
|
|
|
QValueList< B2ClientFactory::BorderSize > B2ClientFactory::borderSizes() const
|
2003-11-02 11:03:41 +00:00
|
|
|
{
|
2003-10-11 12:24:51 +00:00
|
|
|
// the list must be sorted
|
2003-11-02 11:03:41 +00:00
|
|
|
return QValueList< BorderSize >() << BorderTiny << BorderNormal <<
|
2003-10-18 20:37:49 +00:00
|
|
|
BorderLarge << BorderVeryLarge << BorderHuge;
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
2003-10-03 12:03:16 +00:00
|
|
|
|
2003-09-20 17:44:49 +00:00
|
|
|
// =====================================
|
2001-06-19 14:32:08 +00:00
|
|
|
|
2004-06-02 13:46:54 +00:00
|
|
|
void B2Client::maxButtonClicked()
|
2001-06-19 14:32:08 +00:00
|
|
|
{
|
2004-07-22 16:30:07 +00:00
|
|
|
maximize(button[BtnMax]->last_button);
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
|
|
|
|
2004-05-15 23:15:01 +00:00
|
|
|
void B2Client::shadeButtonClicked()
|
|
|
|
{
|
|
|
|
setShade(!isShade());
|
|
|
|
}
|
|
|
|
|
2004-07-25 13:49:19 +00:00
|
|
|
void B2Client::resizeButtonPressed()
|
2004-06-20 10:03:04 +00:00
|
|
|
{
|
|
|
|
performWindowOperation(ResizeOp);
|
|
|
|
}
|
|
|
|
|
2003-11-02 11:03:41 +00:00
|
|
|
B2Client::B2Client(KDecorationBridge *b, KDecorationFactory *f)
|
2003-09-20 17:44:49 +00:00
|
|
|
: KDecoration(b, f), bar_x_ofs(0), in_unobs(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::init()
|
2001-06-19 14:32:08 +00:00
|
|
|
{
|
2004-05-15 23:15:01 +00:00
|
|
|
const QString tips[] = {
|
|
|
|
i18n("Menu"),
|
|
|
|
isOnAllDesktops() ?
|
2004-06-27 16:18:56 +00:00
|
|
|
i18n("Not on all desktops") : i18n("On all desktops"),
|
2004-05-15 23:15:01 +00:00
|
|
|
i18n("Minimize"), i18n("Maximize"),
|
|
|
|
i18n("Close"), i18n("Help"),
|
2004-06-20 10:03:04 +00:00
|
|
|
isShade() ? i18n("Unshade") : i18n("Shade"),
|
|
|
|
i18n("Resize")
|
2004-05-15 23:15:01 +00:00
|
|
|
};
|
2001-08-22 10:11:06 +00:00
|
|
|
|
2003-09-20 17:44:49 +00:00
|
|
|
createMainWidget(WResizeNoErase | WRepaintNoErase);
|
|
|
|
widget()->installEventFilter(this);
|
|
|
|
|
|
|
|
widget()->setBackgroundMode(NoBackground);
|
2001-09-08 10:12:23 +00:00
|
|
|
|
2001-08-22 10:11:06 +00:00
|
|
|
// Set button pointers to NULL so we know what has been created
|
2003-10-11 12:24:51 +00:00
|
|
|
for (int i = 0; i < BtnCount; i++)
|
2003-11-02 11:03:41 +00:00
|
|
|
button[i] = NULL;
|
2001-07-01 10:10:17 +00:00
|
|
|
|
2003-09-20 17:44:49 +00:00
|
|
|
g = new QGridLayout(widget(), 0, 0);
|
|
|
|
if (isPreview()) {
|
2003-11-02 11:03:41 +00:00
|
|
|
g->addMultiCellWidget(
|
2004-06-02 13:46:54 +00:00
|
|
|
new QLabel(i18n("<b><center>B II preview</center></b>"),
|
2003-11-02 11:03:41 +00:00
|
|
|
widget()),
|
2003-09-20 17:44:49 +00:00
|
|
|
1, 1, 1, 2);
|
|
|
|
} else {
|
2004-06-02 13:46:54 +00:00
|
|
|
g->addMultiCell(new QSpacerItem(0, 0), 1, 1, 1, 2);
|
2003-09-20 17:44:49 +00:00
|
|
|
}
|
2003-10-04 18:53:44 +00:00
|
|
|
|
|
|
|
// Left and right border width
|
2003-11-02 11:03:41 +00:00
|
|
|
leftSpacer = new QSpacerItem(thickness, 16,
|
2004-10-24 14:49:26 +00:00
|
|
|
QSizePolicy::Fixed, QSizePolicy::Expanding);
|
2003-11-02 11:03:41 +00:00
|
|
|
rightSpacer = new QSpacerItem(thickness, 16,
|
2004-10-24 14:49:26 +00:00
|
|
|
QSizePolicy::Fixed, QSizePolicy::Expanding);
|
2003-10-04 18:53:44 +00:00
|
|
|
|
|
|
|
g->addItem(leftSpacer, 1, 0);
|
2001-06-19 14:32:08 +00:00
|
|
|
g->addColSpacing(1, 16);
|
|
|
|
g->setColStretch(2, 1);
|
|
|
|
g->setRowStretch(1, 1);
|
2003-10-04 18:53:44 +00:00
|
|
|
g->addItem(rightSpacer, 1, 3);
|
|
|
|
|
2003-05-21 09:12:44 +00:00
|
|
|
// Bottom border height
|
2004-06-20 10:03:04 +00:00
|
|
|
spacer = new QSpacerItem(10, thickness + (mustDrawHandle() ? 4 : 0),
|
2004-10-24 14:49:26 +00:00
|
|
|
QSizePolicy::Expanding, QSizePolicy::Fixed);
|
2003-10-04 18:53:44 +00:00
|
|
|
g->addItem(spacer, 3, 1);
|
|
|
|
|
2001-06-19 14:32:08 +00:00
|
|
|
// titlebar
|
2003-10-15 16:50:29 +00:00
|
|
|
g->addRowSpacing(0, buttonSize + 4);
|
2001-06-19 14:32:08 +00:00
|
|
|
|
|
|
|
titlebar = new B2Titlebar(this);
|
2004-07-03 10:35:13 +00:00
|
|
|
titlebar->setMinimumWidth(buttonSize + 4);
|
2003-10-15 16:50:29 +00:00
|
|
|
titlebar->setFixedHeight(buttonSize + 4);
|
2001-06-19 14:32:08 +00:00
|
|
|
|
2004-06-02 13:46:54 +00:00
|
|
|
QBoxLayout *titleLayout = new QBoxLayout(titlebar,
|
|
|
|
QBoxLayout::LeftToRight, 0, 1, 0);
|
2001-06-19 14:32:08 +00:00
|
|
|
titleLayout->addSpacing(3);
|
|
|
|
|
2004-06-02 13:46:54 +00:00
|
|
|
if (options()->customButtonPositions()) {
|
|
|
|
addButtons(options()->titleButtonsLeft(), tips, titlebar, titleLayout);
|
2002-08-27 15:12:14 +00:00
|
|
|
titleLayout->addItem(titlebar->captionSpacer);
|
2004-06-02 13:46:54 +00:00
|
|
|
addButtons(options()->titleButtonsRight(), tips, titlebar, titleLayout);
|
2001-08-22 10:11:06 +00:00
|
|
|
} else {
|
2004-06-02 13:46:54 +00:00
|
|
|
addButtons("MSH", tips, titlebar, titleLayout);
|
2002-08-27 15:12:14 +00:00
|
|
|
titleLayout->addItem(titlebar->captionSpacer);
|
2004-06-02 13:46:54 +00:00
|
|
|
addButtons("IAX", tips, titlebar, titleLayout);
|
2001-08-22 10:11:06 +00:00
|
|
|
}
|
2001-06-19 14:32:08 +00:00
|
|
|
|
2001-08-22 10:11:06 +00:00
|
|
|
titleLayout->addSpacing(3);
|
2003-11-02 11:03:41 +00:00
|
|
|
|
2003-09-20 17:44:49 +00:00
|
|
|
QColor c = options()->colorGroup(KDecoration::ColorTitleBar, isActive()).
|
2001-06-19 14:32:08 +00:00
|
|
|
color(QColorGroup::Button);
|
2001-08-22 10:11:06 +00:00
|
|
|
|
2004-07-03 10:35:13 +00:00
|
|
|
for (int i = 0; i < BtnCount; i++) {
|
2001-08-22 10:11:06 +00:00
|
|
|
if (button[i])
|
|
|
|
button[i]->setBg(c);
|
2004-07-03 10:35:13 +00:00
|
|
|
}
|
2001-08-22 10:11:06 +00:00
|
|
|
|
2004-07-03 10:35:13 +00:00
|
|
|
titlebar->updateGeometry();
|
2004-06-02 13:46:54 +00:00
|
|
|
positionButtons();
|
2001-06-19 14:32:08 +00:00
|
|
|
titlebar->recalcBuffer();
|
2003-10-03 12:03:16 +00:00
|
|
|
titlebar->installEventFilter(this);
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
|
|
|
|
2001-08-22 10:11:06 +00:00
|
|
|
void B2Client::addButtons(const QString& s, const QString tips[],
|
2002-08-27 15:12:14 +00:00
|
|
|
B2Titlebar* tb, QBoxLayout* titleLayout)
|
2001-06-19 14:32:08 +00:00
|
|
|
{
|
2002-08-27 15:12:14 +00:00
|
|
|
if (s.length() <= 0)
|
2001-08-22 10:11:06 +00:00
|
|
|
return;
|
|
|
|
|
2003-10-11 12:24:51 +00:00
|
|
|
for (unsigned int i = 0; i < s.length(); i++) {
|
|
|
|
switch (s[i].latin1()) {
|
2004-05-16 18:27:26 +00:00
|
|
|
case 'M': // Menu button
|
|
|
|
if (!button[BtnMenu]) {
|
|
|
|
button[BtnMenu] = new B2Button(this, tb, tips[BtnMenu],
|
|
|
|
LeftButton | RightButton);
|
|
|
|
button[BtnMenu]->setPixmaps(P_MENU);
|
|
|
|
button[BtnMenu]->setUseMiniIcon();
|
2004-05-23 22:59:13 +00:00
|
|
|
connect(button[BtnMenu], SIGNAL(pressed()),
|
2004-05-16 18:27:26 +00:00
|
|
|
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])) {
|
2004-06-20 10:03:04 +00:00
|
|
|
button[BtnIconify] = new B2Button(this, tb,tips[BtnIconify]);
|
2004-05-16 18:27:26 +00:00
|
|
|
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])) {
|
2004-06-20 10:03:04 +00:00
|
|
|
button[BtnMax] = new B2Button(this, tb, tips[BtnMax],
|
2004-05-16 18:27:26 +00:00
|
|
|
LeftButton | MidButton | 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]) {
|
2004-06-20 10:03:04 +00:00
|
|
|
button[BtnClose] = new B2Button(this, tb, tips[BtnClose]);
|
2004-05-16 18:27:26 +00:00
|
|
|
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]) {
|
2004-06-20 10:03:04 +00:00
|
|
|
button[BtnShade] = new B2Button(this, tb, tips[BtnShade]);
|
2004-05-16 18:27:26 +00:00
|
|
|
button[BtnShade]->setPixmaps(P_SHADE);
|
|
|
|
connect(button[BtnShade], SIGNAL(clicked()),
|
|
|
|
this, SLOT(shadeButtonClicked()));
|
|
|
|
titleLayout->addWidget(button[BtnShade]);
|
|
|
|
}
|
|
|
|
break;
|
2004-06-20 10:03:04 +00:00
|
|
|
case 'R': // Resize button
|
|
|
|
if (isResizable() && !button[BtnResize]) {
|
|
|
|
button[BtnResize] = new B2Button(this, tb, tips[BtnResize]);
|
|
|
|
button[BtnResize]->setPixmaps(P_RESIZE);
|
2004-07-25 13:49:19 +00:00
|
|
|
connect(button[BtnResize], SIGNAL(pressed()),
|
|
|
|
this, SLOT(resizeButtonPressed()));
|
2004-06-20 10:03:04 +00:00
|
|
|
titleLayout->addWidget(button[BtnResize]);
|
|
|
|
}
|
|
|
|
break;
|
2004-05-16 18:27:26 +00:00
|
|
|
case '_': // Additional spacing
|
|
|
|
titleLayout->addSpacing(4);
|
|
|
|
break;
|
2001-08-22 10:11:06 +00:00
|
|
|
}
|
2003-11-02 11:03:41 +00:00
|
|
|
}
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
|
|
|
|
2004-07-28 16:44:42 +00:00
|
|
|
bool B2Client::mustDrawHandle() const
|
|
|
|
{
|
|
|
|
if (drawSmallBorders && (maximizeMode() & MaximizeVertical)) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2004-09-26 10:29:23 +00:00
|
|
|
return do_draw_handle && isResizable();
|
2004-07-28 16:44:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-22 10:11:06 +00:00
|
|
|
void B2Client::iconChange()
|
2001-06-19 14:32:08 +00:00
|
|
|
{
|
2001-08-22 10:11:06 +00:00
|
|
|
if (button[BtnMenu])
|
2003-11-02 11:03:41 +00:00
|
|
|
button[BtnMenu]->repaint(false);
|
2001-08-22 10:11:06 +00:00
|
|
|
}
|
2001-06-19 14:32:08 +00:00
|
|
|
|
2001-08-22 10:11:06 +00:00
|
|
|
// Gallium: New button show/hide magic for customizable
|
|
|
|
// button positions.
|
|
|
|
void B2Client::calcHiddenButtons()
|
|
|
|
{
|
|
|
|
// Hide buttons in this order:
|
2004-06-20 10:03:04 +00:00
|
|
|
// Shade, Sticky, Help, Resize, Maximize, Minimize, Close, Menu
|
2004-05-15 23:15:01 +00:00
|
|
|
B2Button* btnArray[] = {
|
2004-06-20 10:03:04 +00:00
|
|
|
button[BtnShade], button[BtnSticky], button[BtnHelp], button[BtnResize],
|
2004-05-15 23:15:01 +00:00
|
|
|
button[BtnMax], button[BtnIconify], button[BtnClose], button[BtnMenu]
|
|
|
|
};
|
2003-11-02 11:03:41 +00:00
|
|
|
int minWidth = 120;
|
2001-08-22 10:11:06 +00:00
|
|
|
int currentWidth = width();
|
|
|
|
int count = 0;
|
|
|
|
int i;
|
2001-06-19 14:32:08 +00:00
|
|
|
|
2001-08-22 10:11:06 +00:00
|
|
|
// Determine how many buttons we need to hide
|
2003-10-11 12:24:51 +00:00
|
|
|
while (currentWidth < minWidth) {
|
2003-10-15 16:50:29 +00:00
|
|
|
currentWidth += buttonSize + 1; // Allow for spacer (extra 1pix)
|
2001-08-22 10:11:06 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
// Bound the number of buttons to hide
|
|
|
|
if (count > BtnCount) count = BtnCount;
|
2001-06-19 14:32:08 +00:00
|
|
|
|
2001-08-22 10:11:06 +00:00
|
|
|
// Hide the required buttons
|
2003-10-11 12:24:51 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
2001-08-22 10:11:06 +00:00
|
|
|
if (btnArray[i] && btnArray[i]->isVisible())
|
|
|
|
btnArray[i]->hide();
|
|
|
|
}
|
|
|
|
// Show the rest of the buttons
|
2003-10-11 12:24:51 +00:00
|
|
|
for (i = count; i < BtnCount; i++) {
|
2001-08-22 10:11:06 +00:00
|
|
|
if (btnArray[i] && (!btnArray[i]->isVisible()))
|
|
|
|
btnArray[i]->show();
|
|
|
|
}
|
|
|
|
}
|
2001-06-19 14:32:08 +00:00
|
|
|
|
2003-09-20 17:44:49 +00:00
|
|
|
void B2Client::resizeEvent(QResizeEvent * /*e*/)
|
2001-08-22 10:11:06 +00:00
|
|
|
{
|
|
|
|
calcHiddenButtons();
|
|
|
|
titlebar->layout()->activate();
|
2001-06-19 14:32:08 +00:00
|
|
|
positionButtons();
|
2001-08-22 10:11:06 +00:00
|
|
|
|
2003-10-02 16:52:20 +00:00
|
|
|
/* may be the resize cut off some space occupied by titlebar, which
|
2001-06-19 14:32:08 +00:00
|
|
|
was moved, so instead of reducing it, we first try to move it */
|
|
|
|
titleMoveAbs(bar_x_ofs);
|
|
|
|
|
2004-10-24 14:49:26 +00:00
|
|
|
doShape();
|
2003-10-02 16:52:20 +00:00
|
|
|
widget()->repaint(); // the frame is misrendered without this
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
|
|
|
|
2003-09-20 17:44:49 +00:00
|
|
|
void B2Client::captionChange()
|
2001-06-19 14:32:08 +00:00
|
|
|
{
|
|
|
|
positionButtons();
|
|
|
|
titleMoveAbs(bar_x_ofs);
|
|
|
|
doShape();
|
|
|
|
titlebar->recalcBuffer();
|
|
|
|
titlebar->repaint(false);
|
|
|
|
}
|
|
|
|
|
2004-06-02 13:46:54 +00:00
|
|
|
void B2Client::paintEvent(QPaintEvent* e)
|
2001-06-19 14:32:08 +00:00
|
|
|
{
|
2003-09-20 17:44:49 +00:00
|
|
|
QPainter p(widget());
|
2003-11-02 11:03:41 +00:00
|
|
|
|
|
|
|
KDecoration::ColorType frameColorGroup = colored_frame ?
|
2003-09-20 17:44:49 +00:00
|
|
|
KDecoration::ColorTitleBar : KDecoration::ColorFrame;
|
2003-11-02 11:03:41 +00:00
|
|
|
|
2001-06-19 14:32:08 +00:00
|
|
|
QRect t = titlebar->geometry();
|
|
|
|
|
2003-10-04 18:53:44 +00:00
|
|
|
// Frame height, this is used a lot of times
|
|
|
|
int fHeight = height() - t.height();
|
|
|
|
|
|
|
|
// distance from the bottom border - it is different if window is resizable
|
2004-06-20 10:03:04 +00:00
|
|
|
int bb = mustDrawHandle() ? 4 : 0;
|
2003-10-04 18:53:44 +00:00
|
|
|
int bDepth = thickness + bb;
|
|
|
|
|
|
|
|
QColorGroup fillColor = options()->colorGroup(frameColorGroup, isActive());
|
|
|
|
QBrush fillBrush(options()->color(frameColorGroup, isActive()));
|
2001-06-19 14:32:08 +00:00
|
|
|
|
|
|
|
// outer frame rect
|
2004-06-02 13:46:54 +00:00
|
|
|
p.drawRect(0, t.bottom() - thickness + 1,
|
|
|
|
width(), fHeight - bb + thickness);
|
2001-06-19 14:32:08 +00:00
|
|
|
|
2003-10-04 18:53:44 +00:00
|
|
|
if (thickness >= 2) {
|
|
|
|
// inner window rect
|
2004-06-02 13:46:54 +00:00
|
|
|
p.drawRect(thickness - 1, t.bottom(),
|
|
|
|
width() - 2 * (thickness - 1), fHeight - bDepth + 2);
|
2003-11-02 11:03:41 +00:00
|
|
|
|
2003-10-04 18:53:44 +00:00
|
|
|
if (thickness >= 3) {
|
|
|
|
// frame shade panel
|
2003-11-02 11:03:41 +00:00
|
|
|
qDrawShadePanel(&p, 1, t.bottom() - thickness + 2,
|
2003-10-04 18:53:44 +00:00
|
|
|
width() - 2, fHeight - 2 - bb + thickness, fillColor, false);
|
|
|
|
if (thickness == 4) {
|
|
|
|
p.setPen(fillColor.background());
|
2003-11-02 11:03:41 +00:00
|
|
|
p.drawRect(thickness - 2, t.bottom() - 1,
|
2003-10-04 18:53:44 +00:00
|
|
|
width() - 2 * (thickness - 2), fHeight + 4 - bDepth);
|
|
|
|
} else if (thickness > 4) {
|
2003-11-02 11:03:41 +00:00
|
|
|
qDrawShadePanel(&p, thickness - 2,
|
|
|
|
t.bottom() - 1, width() - 2 * (thickness - 2),
|
2003-10-04 18:53:44 +00:00
|
|
|
fHeight + 4 - bDepth, fillColor, true);
|
|
|
|
if (thickness >= 5) {
|
|
|
|
// draw frame interior
|
2003-11-02 11:03:41 +00:00
|
|
|
p.fillRect(2, t.bottom() - thickness + 3,
|
2003-10-04 18:53:44 +00:00
|
|
|
width() - 4, thickness - 4, fillBrush);
|
2003-11-02 11:03:41 +00:00
|
|
|
p.fillRect(2, height() - bDepth + 2,
|
2003-10-04 18:53:44 +00:00
|
|
|
width() - 4, thickness - 4, fillBrush);
|
2003-11-02 11:03:41 +00:00
|
|
|
p.fillRect(2, t.bottom() - 1,
|
2003-10-04 18:53:44 +00:00
|
|
|
thickness - 4, fHeight - bDepth + 4, fillBrush);
|
|
|
|
p.fillRect(width() - thickness + 2, t.bottom() - 1,
|
|
|
|
thickness - 4, fHeight - bDepth + 4, fillBrush);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// bottom handle rect
|
2004-06-20 10:03:04 +00:00
|
|
|
if (mustDrawHandle()) {
|
2003-10-04 18:53:44 +00:00
|
|
|
p.setPen(Qt::black);
|
|
|
|
int hx = width() - 40;
|
|
|
|
int hw = 40;
|
|
|
|
|
2003-11-02 11:03:41 +00:00
|
|
|
p.drawLine(width() - 1, height() - thickness - 4,
|
2003-10-04 18:53:44 +00:00
|
|
|
width() - 1, height() - 1);
|
|
|
|
p.drawLine(hx, height() - 1, width() - 1, height() - 1);
|
|
|
|
p.drawLine(hx, height() - 4, hx, height() - 1);
|
2003-05-21 09:12:44 +00:00
|
|
|
|
2003-11-02 11:03:41 +00:00
|
|
|
p.fillRect(hx + 1, height() - thickness - 3,
|
2003-10-04 18:53:44 +00:00
|
|
|
hw - 2, thickness + 2, fillBrush);
|
2003-05-21 09:12:44 +00:00
|
|
|
|
2003-11-02 11:03:41 +00:00
|
|
|
p.setPen(fillColor.dark());
|
|
|
|
p.drawLine(width() - 2, height() - thickness - 4,
|
2003-10-04 18:53:44 +00:00
|
|
|
width() - 2, height() - 2);
|
|
|
|
p.drawLine(hx + 1, height() - 2, width() - 2, height() - 2);
|
2003-05-21 09:12:44 +00:00
|
|
|
|
2003-10-04 18:53:44 +00:00
|
|
|
p.setPen(fillColor.light());
|
2003-11-02 11:03:41 +00:00
|
|
|
p.drawLine(hx + 1, height() - thickness - 2,
|
2003-10-04 18:53:44 +00:00
|
|
|
hx + 1, height() - 3);
|
2003-11-02 11:03:41 +00:00
|
|
|
p.drawLine(hx + 1, height() - thickness - 3,
|
2003-10-04 18:53:44 +00:00
|
|
|
width() - 3, height() - thickness - 3);
|
2003-11-02 11:03:41 +00:00
|
|
|
}
|
2001-06-19 14:32:08 +00:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
*/
|
|
|
|
if (titlebar->isFullyObscured()) {
|
|
|
|
/* We first see, if our repaint contained the titlebar area */
|
2003-10-15 16:50:29 +00:00
|
|
|
QRegion reg(QRect(0, 0, width(), buttonSize + 4));
|
2001-06-19 14:32:08 +00:00
|
|
|
reg = reg.intersect(e->region());
|
|
|
|
if (!reg.isEmpty())
|
|
|
|
unobscureTitlebar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::doShape()
|
|
|
|
{
|
|
|
|
QRect t = titlebar->geometry();
|
2003-09-20 17:44:49 +00:00
|
|
|
QRegion mask(widget()->rect());
|
2001-06-19 14:32:08 +00:00
|
|
|
// top to the tilebar right
|
|
|
|
if (bar_x_ofs) {
|
2003-10-04 18:53:44 +00:00
|
|
|
mask -= QRect(0, 0, bar_x_ofs, t.height() - thickness); //left from bar
|
|
|
|
mask -= QRect(0, t.height() - thickness, 1, 1); //top left point
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
2003-10-04 18:53:44 +00:00
|
|
|
if (t.right() < width() - 1) {
|
2003-11-02 11:03:41 +00:00
|
|
|
mask -= QRect(width() - 1,
|
2003-10-04 18:53:44 +00:00
|
|
|
t.height() - thickness, 1, 1); //top right point
|
2003-11-02 11:03:41 +00:00
|
|
|
mask -= QRect(t.right() + 1, 0,
|
2003-10-04 18:53:44 +00:00
|
|
|
width() - t.right() - 1, t.height() - thickness);
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
2003-10-04 18:53:44 +00:00
|
|
|
mask -= QRect(width() - 1, height() - 1, 1, 1); //bottom right point
|
2004-06-20 10:03:04 +00:00
|
|
|
if (mustDrawHandle()) {
|
2003-10-04 18:53:44 +00:00
|
|
|
mask -= QRect(0, height() - 5, 1, 1); //bottom left point
|
|
|
|
mask -= QRect(width() - 40, height() - 1, 1, 1); //handle left point
|
|
|
|
mask -= QRect(0, height() - 4, width() - 40, 4); //bottom left
|
2003-05-21 09:12:44 +00:00
|
|
|
} else {
|
2003-10-04 18:53:44 +00:00
|
|
|
mask -= QRect(0, height() - 1, 1, 1); // bottom left point
|
2003-05-21 09:12:44 +00:00
|
|
|
}
|
2001-06-19 14:32:08 +00:00
|
|
|
|
|
|
|
setMask(mask);
|
|
|
|
}
|
|
|
|
|
2003-11-20 09:05:00 +00:00
|
|
|
void B2Client::showEvent(QShowEvent *)
|
2001-06-19 14:32:08 +00:00
|
|
|
{
|
2001-08-22 10:11:06 +00:00
|
|
|
calcHiddenButtons();
|
2004-07-03 10:35:13 +00:00
|
|
|
positionButtons();
|
2001-06-19 14:32:08 +00:00
|
|
|
doShape();
|
|
|
|
}
|
|
|
|
|
2004-06-02 13:46:54 +00:00
|
|
|
KDecoration::Position B2Client::mousePosition(const QPoint& p) const
|
2001-06-19 14:32:08 +00:00
|
|
|
{
|
|
|
|
const int range = 16;
|
|
|
|
QRect t = titlebar->geometry();
|
2003-10-15 16:50:29 +00:00
|
|
|
t.setHeight(buttonSize + 4 - thickness);
|
2001-06-19 14:32:08 +00:00
|
|
|
int ly = t.bottom();
|
|
|
|
int lx = t.right();
|
2004-06-20 10:03:04 +00:00
|
|
|
int bb = mustDrawHandle() ? 0 : 5;
|
2001-06-19 14:32:08 +00:00
|
|
|
|
2004-06-02 13:46:54 +00:00
|
|
|
if (p.x() > t.right()) {
|
|
|
|
if (p.y() <= ly + range && p.x() >= width() - range)
|
2003-12-15 15:10:17 +00:00
|
|
|
return PositionTopRight;
|
2004-06-02 13:46:54 +00:00
|
|
|
else if (p.y() <= ly + thickness)
|
2003-12-15 15:10:17 +00:00
|
|
|
return PositionTop;
|
2004-06-02 13:46:54 +00:00
|
|
|
} else if (p.x() < bar_x_ofs) {
|
|
|
|
if (p.y() <= ly + range && p.x() <= range)
|
2003-12-15 15:10:17 +00:00
|
|
|
return PositionTopLeft;
|
2004-06-02 13:46:54 +00:00
|
|
|
else if (p.y() <= ly + thickness)
|
2003-12-15 15:10:17 +00:00
|
|
|
return PositionTop;
|
2004-06-02 13:46:54 +00:00
|
|
|
} else if (p.y() < ly) {
|
2003-11-02 11:03:41 +00:00
|
|
|
if (p.x() > bar_x_ofs + thickness &&
|
2003-10-04 18:53:44 +00:00
|
|
|
p.x() < lx - thickness && p.y() > thickness)
|
2003-09-20 17:44:49 +00:00
|
|
|
return KDecoration::mousePosition(p);
|
2003-10-04 18:53:44 +00:00
|
|
|
if (p.x() > bar_x_ofs + range && p.x() < lx - range)
|
2003-12-15 15:10:17 +00:00
|
|
|
return PositionTop;
|
2004-06-02 13:46:54 +00:00
|
|
|
if (p.y() <= range) {
|
|
|
|
if (p.x() <= bar_x_ofs + range)
|
2003-12-15 15:10:17 +00:00
|
|
|
return PositionTopLeft;
|
|
|
|
else return PositionTopRight;
|
2001-06-19 14:32:08 +00:00
|
|
|
} else {
|
2004-06-02 13:46:54 +00:00
|
|
|
if (p.x() <= bar_x_ofs + range)
|
2003-12-15 15:10:17 +00:00
|
|
|
return PositionLeft;
|
|
|
|
else return PositionRight;
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-21 09:12:44 +00:00
|
|
|
if (p.y() >= height() - 8 + bb) {
|
2001-06-19 14:32:08 +00:00
|
|
|
/* the normal Client:: only wants border of 4 pixels */
|
2003-12-15 15:10:17 +00:00
|
|
|
if (p.x() <= range) return PositionBottomLeft;
|
|
|
|
if (p.x() >= width() - range) return PositionBottomRight;
|
|
|
|
return PositionBottom;
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
|
|
|
|
2003-09-20 17:44:49 +00:00
|
|
|
return KDecoration::mousePosition(p);
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::titleMoveAbs(int new_ofs)
|
|
|
|
{
|
|
|
|
if (new_ofs < 0) new_ofs = 0;
|
|
|
|
if (new_ofs + titlebar->width() > width()) {
|
|
|
|
new_ofs = width() - titlebar->width();
|
|
|
|
}
|
|
|
|
if (bar_x_ofs != new_ofs) {
|
|
|
|
bar_x_ofs = new_ofs;
|
|
|
|
positionButtons();
|
|
|
|
doShape();
|
2004-06-02 13:46:54 +00:00
|
|
|
widget()->repaint(0, 0, width(), buttonSize + 4, false);
|
2001-06-19 14:32:08 +00:00
|
|
|
titlebar->repaint(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::titleMoveRel(int xdiff)
|
|
|
|
{
|
|
|
|
titleMoveAbs(bar_x_ofs + xdiff);
|
|
|
|
}
|
|
|
|
|
2003-09-20 17:44:49 +00:00
|
|
|
void B2Client::desktopChange()
|
2001-06-19 14:32:08 +00:00
|
|
|
{
|
2003-09-20 17:44:49 +00:00
|
|
|
bool on = isOnAllDesktops();
|
2003-09-30 18:13:18 +00:00
|
|
|
if (B2Button *b = button[BtnSticky]) {
|
2003-09-20 17:44:49 +00:00
|
|
|
b->setDown(on);
|
|
|
|
QToolTip::remove(b);
|
2004-06-02 13:46:54 +00:00
|
|
|
QToolTip::add(b,
|
2004-06-27 16:18:56 +00:00
|
|
|
on ? i18n("Not on all desktops") : i18n("On all desktops"));
|
2001-08-22 10:11:06 +00:00
|
|
|
}
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
|
|
|
|
2003-09-20 17:44:49 +00:00
|
|
|
void B2Client::maximizeChange()
|
2001-06-19 14:32:08 +00:00
|
|
|
{
|
2003-09-20 17:44:49 +00:00
|
|
|
bool m = maximizeMode() == MaximizeFull;
|
2001-08-22 10:11:06 +00:00
|
|
|
if (button[BtnMax]) {
|
2004-06-02 13:46:54 +00:00
|
|
|
button[BtnMax]->setPixmaps(m ? P_NORMALIZE : P_MAX);
|
2001-08-22 10:11:06 +00:00
|
|
|
button[BtnMax]->repaint();
|
2003-09-20 17:44:49 +00:00
|
|
|
QToolTip::remove(button[BtnMax]);
|
2003-11-02 11:03:41 +00:00
|
|
|
QToolTip::add(button[BtnMax],
|
2003-09-20 17:44:49 +00:00
|
|
|
m ? i18n("Restore") : i18n("Maximize"));
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
2004-06-20 10:03:04 +00:00
|
|
|
spacer->changeSize(10, thickness + (mustDrawHandle() ? 4 : 0),
|
2003-05-21 09:12:44 +00:00
|
|
|
QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
|
|
|
|
g->activate();
|
|
|
|
doShape();
|
2003-09-20 17:44:49 +00:00
|
|
|
widget()->repaint(false);
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
|
|
|
|
2003-09-20 17:44:49 +00:00
|
|
|
void B2Client::activeChange()
|
2001-06-19 14:32:08 +00:00
|
|
|
{
|
2003-09-20 17:44:49 +00:00
|
|
|
widget()->repaint(false);
|
2001-06-19 14:32:08 +00:00
|
|
|
titlebar->repaint(false);
|
2001-08-22 10:11:06 +00:00
|
|
|
|
2003-09-20 17:44:49 +00:00
|
|
|
QColor c = options()->colorGroup(
|
|
|
|
KDecoration::ColorTitleBar, isActive()).color(QColorGroup::Button);
|
2001-06-19 14:32:08 +00:00
|
|
|
|
2003-10-11 12:24:51 +00:00
|
|
|
for (int i = 0; i < BtnCount; i++)
|
2001-08-22 10:11:06 +00:00
|
|
|
if (button[i]) {
|
|
|
|
button[i]->setBg(c);
|
|
|
|
button[i]->repaint(false);
|
|
|
|
}
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
|
|
|
|
2003-09-20 17:44:49 +00:00
|
|
|
void B2Client::shadeChange()
|
|
|
|
{
|
2004-06-20 10:03:04 +00:00
|
|
|
spacer->changeSize(10, thickness + (mustDrawHandle() ? 4 : 0),
|
2003-10-01 12:55:55 +00:00
|
|
|
QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
g->activate();
|
2003-10-01 13:01:50 +00:00
|
|
|
doShape();
|
2004-05-16 13:21:51 +00:00
|
|
|
if (B2Button *b = button[BtnShade]) {
|
|
|
|
QToolTip::remove(b);
|
|
|
|
QToolTip::add(b, isShade() ? i18n("Unshade") : i18n("Shade"));
|
|
|
|
}
|
2003-09-20 17:44:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QSize B2Client::minimumSize() const
|
|
|
|
{
|
2004-05-04 13:59:48 +00:00
|
|
|
int left, right, top, bottom;
|
|
|
|
borders(left, right, top, bottom);
|
|
|
|
return QSize(left + right + 2 * buttonSize, top + bottom);
|
2003-09-20 17:44:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::resize(const QSize& s)
|
|
|
|
{
|
|
|
|
widget()->resize(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::borders(int &left, int &right, int &top, int &bottom) const
|
2003-11-02 11:03:41 +00:00
|
|
|
{
|
2003-11-02 16:35:59 +00:00
|
|
|
left = right = thickness;
|
2003-10-15 16:50:29 +00:00
|
|
|
top = buttonSize + 4;
|
2004-06-20 10:03:04 +00:00
|
|
|
bottom = thickness + (mustDrawHandle() ? 4 : 0);
|
2003-09-20 17:44:49 +00:00
|
|
|
}
|
|
|
|
|
2001-06-19 14:32:08 +00:00
|
|
|
void B2Client::menuButtonPressed()
|
|
|
|
{
|
2004-05-22 00:31:07 +00:00
|
|
|
static B2Client *lastClient = NULL;
|
|
|
|
|
|
|
|
bool dbl = (lastClient == this &&
|
|
|
|
time.elapsed() <= QApplication::doubleClickInterval());
|
|
|
|
lastClient = this;
|
|
|
|
time.start();
|
|
|
|
if (!dbl) {
|
2004-05-23 22:59:13 +00:00
|
|
|
KDecorationFactory* f = factory();
|
2004-06-02 13:46:54 +00:00
|
|
|
QRect menuRect = button[BtnMenu]->rect();
|
|
|
|
QPoint menuTop = button[BtnMenu]->mapToGlobal(menuRect.topLeft());
|
|
|
|
QPoint menuBottom = button[BtnMenu]->mapToGlobal(menuRect.bottomRight());
|
|
|
|
showWindowMenu(QRect(menuTop, menuBottom));
|
2004-05-22 00:31:07 +00:00
|
|
|
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(!isShade());
|
|
|
|
break;
|
|
|
|
case B2::CloseOp:
|
|
|
|
closeWindow();
|
|
|
|
break;
|
|
|
|
case B2::NoOp:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 */
|
|
|
|
if (in_unobs) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
in_unobs = 1;
|
2003-10-15 16:50:29 +00:00
|
|
|
QRegion reg(QRect(0,0,width(), buttonSize + 4));
|
2004-06-02 13:46:54 +00:00
|
|
|
reg = unobscuredRegion(reg);
|
2001-06-19 14:32:08 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void redraw_pixmaps()
|
|
|
|
{
|
2004-05-15 23:15:01 +00:00
|
|
|
int i;
|
2003-09-20 17:44:49 +00:00
|
|
|
QColorGroup aGrp = options()->colorGroup(KDecoration::ColorButtonBg, true);
|
|
|
|
QColorGroup iGrp = options()->colorGroup(KDecoration::ColorButtonBg, false);
|
2001-06-19 14:32:08 +00:00
|
|
|
|
|
|
|
// close
|
|
|
|
drawB2Rect(PIXMAP_A(P_CLOSE), aGrp.button(), false);
|
2004-05-23 22:59:13 +00:00
|
|
|
drawB2Rect(PIXMAP_AH(P_CLOSE), aGrp.button(), true);
|
2001-06-19 14:32:08 +00:00
|
|
|
drawB2Rect(PIXMAP_AD(P_CLOSE), aGrp.button(), true);
|
|
|
|
|
|
|
|
drawB2Rect(PIXMAP_I(P_CLOSE), iGrp.button(), false);
|
2004-05-23 22:59:13 +00:00
|
|
|
drawB2Rect(PIXMAP_IH(P_CLOSE), iGrp.button(), true);
|
2001-06-19 14:32:08 +00:00
|
|
|
drawB2Rect(PIXMAP_ID(P_CLOSE), iGrp.button(), true);
|
|
|
|
|
2004-05-15 23:15:01 +00:00
|
|
|
// shade
|
|
|
|
KPixmap thinBox;
|
|
|
|
thinBox.resize(buttonSize - 2, 6);
|
2004-05-23 22:59:13 +00:00
|
|
|
for (i = 0; i < NumStates; i++) {
|
2004-05-15 23:15:01 +00:00
|
|
|
bool is_act = (i < 2);
|
|
|
|
bool is_down = ((i & 1) == 1);
|
2004-05-23 22:59:13 +00:00
|
|
|
KPixmap *pix = pixmap[P_SHADE * NumStates + i];
|
2004-05-15 23:15:01 +00:00
|
|
|
QColor color = is_act ? aGrp.button() : iGrp.button();
|
|
|
|
drawB2Rect(&thinBox, color, is_down);
|
|
|
|
pix->fill(Qt::black);
|
|
|
|
bitBlt(pix, 0, 0, &thinBox,
|
|
|
|
0, 0, thinBox.width(), thinBox.height(), Qt::CopyROP, true);
|
|
|
|
}
|
|
|
|
|
2001-06-19 14:32:08 +00:00
|
|
|
// maximize
|
2004-05-23 22:59:13 +00:00
|
|
|
for (i = 0; i < NumStates; i++) {
|
|
|
|
*pixmap[P_MAX * NumStates + i] = *pixmap[P_CLOSE * NumStates + i];
|
|
|
|
pixmap[P_MAX * NumStates + i]->detach();
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
2004-06-20 10:03:04 +00:00
|
|
|
|
2001-06-19 14:32:08 +00:00
|
|
|
// normalize + iconify
|
|
|
|
KPixmap smallBox;
|
|
|
|
smallBox.resize(10, 10);
|
|
|
|
KPixmap largeBox;
|
|
|
|
largeBox.resize(12, 12);
|
|
|
|
|
2004-06-20 10:03:04 +00:00
|
|
|
for (i = 0; i < NumStates; i++) {
|
2004-05-23 22:59:13 +00:00
|
|
|
bool is_act = (i < 3);
|
|
|
|
bool is_down = (i == Down || i == IDown);
|
|
|
|
KPixmap *pix = pixmap[P_NORMALIZE * NumStates + i];
|
2001-08-22 10:11:06 +00:00
|
|
|
drawB2Rect(&smallBox, is_act ? aGrp.button() : iGrp.button(), is_down);
|
|
|
|
drawB2Rect(&largeBox, is_act ? aGrp.button() : iGrp.button(), is_down);
|
2003-09-20 17:44:49 +00:00
|
|
|
pix->fill(options()->color(KDecoration::ColorTitleBar, is_act));
|
2003-11-02 11:03:41 +00:00
|
|
|
bitBlt(pix, pix->width() - 12, pix->width() - 12, &largeBox,
|
2003-10-18 20:37:49 +00:00
|
|
|
0, 0, 12, 12, Qt::CopyROP, true);
|
2001-06-19 14:32:08 +00:00
|
|
|
bitBlt(pix, 0, 0, &smallBox, 0, 0, 10, 10, Qt::CopyROP, true);
|
|
|
|
|
2004-05-23 22:59:13 +00:00
|
|
|
bitBlt(pixmap[P_ICONIFY * NumStates + i], 0, 0,
|
2003-10-18 20:37:49 +00:00
|
|
|
&smallBox, 0, 0, 10, 10, Qt::CopyROP, true);
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
2004-06-20 10:03:04 +00:00
|
|
|
|
|
|
|
// resize
|
|
|
|
for (i = 0; i < NumStates; i++) {
|
|
|
|
bool is_act = (i < 3);
|
|
|
|
bool is_down = (i == Down || i == IDown);
|
|
|
|
*pixmap[P_RESIZE * NumStates + i] = *pixmap[P_CLOSE * NumStates + i];
|
|
|
|
pixmap[P_RESIZE * NumStates + i]->detach();
|
|
|
|
drawB2Rect(&smallBox, is_act ? aGrp.button() : iGrp.button(), is_down);
|
|
|
|
bitBlt(pixmap[P_RESIZE * NumStates + i],
|
|
|
|
0, 0, &smallBox, 0, 0, 10, 10, Qt::CopyROP, true);
|
|
|
|
}
|
|
|
|
|
2001-06-19 14:32:08 +00:00
|
|
|
|
|
|
|
QPainter p;
|
|
|
|
// x for close + menu + help
|
2004-05-23 22:59:13 +00:00
|
|
|
for (int j = 0; j < 3; j++) {
|
|
|
|
int pix;
|
|
|
|
unsigned const char *light, *dark;
|
2003-11-02 11:03:41 +00:00
|
|
|
switch (j) {
|
2004-05-23 22:59:13 +00:00
|
|
|
case 0:
|
|
|
|
pix = P_CLOSE; light = close_white_bits; dark = close_dgray_bits;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pix = P_MENU; light = menu_white_bits; dark = menu_dgray_bits;
|
|
|
|
break;
|
2003-10-18 20:37:49 +00:00
|
|
|
default:
|
2004-05-23 22:59:13 +00:00
|
|
|
pix = P_HELP; light = help_light_bits; dark = help_dark_bits;
|
|
|
|
break;
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
2004-05-23 22:59:13 +00:00
|
|
|
int off = (pixmap[pix * NumStates]->width() - 16) / 2;
|
|
|
|
for (i = 0; i < NumStates; i++) {
|
|
|
|
p.begin(pixmap[pix * NumStates + i]);
|
|
|
|
kColorBitmaps(&p, (i < 3) ? aGrp : iGrp, off, off, 16, 16, true,
|
2001-06-19 14:32:08 +00:00
|
|
|
light, NULL, NULL, dark, NULL, NULL);
|
|
|
|
p.end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// pin
|
2004-05-23 22:59:13 +00:00
|
|
|
for (i = 0; i < NumStates; i++) {
|
|
|
|
bool isDown = (i == Down || i == IDown);
|
|
|
|
unsigned const char *white = isDown ? pindown_white_bits : pinup_white_bits;
|
|
|
|
unsigned const char *gray = isDown ? pindown_gray_bits : pinup_gray_bits;
|
|
|
|
unsigned const char *dgray =isDown ? pindown_dgray_bits : pinup_dgray_bits;
|
|
|
|
p.begin(pixmap[P_PINUP * NumStates + i]);
|
|
|
|
kColorBitmaps(&p, (i < 3) ? aGrp : iGrp, 0, 0, 16, 16, true, white,
|
2001-06-19 14:32:08 +00:00
|
|
|
gray, NULL, dgray, NULL, NULL);
|
|
|
|
p.end();
|
|
|
|
}
|
2003-11-02 11:03:41 +00:00
|
|
|
|
2004-05-23 22:59:13 +00:00
|
|
|
// Apply the hilight effect to the 'Hover' icons
|
|
|
|
KIconEffect ie;
|
|
|
|
QPixmap hilighted;
|
|
|
|
for (i = 0; i < P_NUM_BUTTON_TYPES; i++) {
|
|
|
|
int offset = i * NumStates;
|
|
|
|
hilighted = ie.apply(*pixmap[offset + Norm],
|
|
|
|
KIcon::Small, KIcon::ActiveState);
|
|
|
|
*pixmap[offset + Hover] = hilighted;
|
|
|
|
|
|
|
|
hilighted = ie.apply(*pixmap[offset + INorm],
|
|
|
|
KIcon::Small, KIcon::ActiveState);
|
|
|
|
*pixmap[offset + IHover] = hilighted;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-04 02:02:07 +00: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);
|
|
|
|
}
|
2003-11-02 11:03:41 +00:00
|
|
|
|
2003-10-04 02:02:07 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (titleColor[2 * i] != titleColor[2 * i + 1]) {
|
|
|
|
if (!titleGradient[i]) {
|
|
|
|
titleGradient[i] = new KPixmap;
|
|
|
|
}
|
2003-10-15 16:50:29 +00:00
|
|
|
titleGradient[i]->resize(64, buttonSize + 3);
|
2003-11-02 11:03:41 +00:00
|
|
|
KPixmapEffect::gradient(*titleGradient[i],
|
2003-10-04 02:02:07 +00:00
|
|
|
titleColor[2 * i], titleColor[2 * i + 1],
|
|
|
|
KPixmapEffect::VerticalGradient);
|
2003-11-02 11:03:41 +00:00
|
|
|
} else {
|
|
|
|
delete titleGradient[i];
|
2003-10-04 02:02:07 +00:00
|
|
|
titleGradient[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-06-19 14:32:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void B2Client::positionButtons()
|
|
|
|
{
|
2003-09-20 17:44:49 +00:00
|
|
|
QFontMetrics fm(options()->font(isActive()));
|
2003-04-29 11:40:39 +00:00
|
|
|
QString cap = caption();
|
2003-10-11 12:24:51 +00:00
|
|
|
if (cap.length() < 5) // make sure the titlebar has sufficiently wide
|
|
|
|
cap = "XXXXX"; // area for dragging the window
|
2004-05-16 18:27:26 +00:00
|
|
|
int textLen = fm.width(cap);
|
2001-06-19 14:32:08 +00:00
|
|
|
|
2001-08-22 10:11:06 +00:00
|
|
|
QRect t = titlebar->captionSpacer->geometry();
|
2004-05-16 18:27:26 +00:00
|
|
|
int titleWidth = titlebar->width() - t.width() + textLen + 2;
|
|
|
|
if (titleWidth > width()) titleWidth = width();
|
2001-06-19 14:32:08 +00:00
|
|
|
|
2003-10-15 16:50:29 +00:00
|
|
|
titlebar->resize(titleWidth, buttonSize + 4);
|
2001-06-19 14:32:08 +00:00
|
|
|
titlebar->move(bar_x_ofs, 0);
|
|
|
|
}
|
|
|
|
|
2003-09-21 20:43:44 +00:00
|
|
|
// Transparent bound stuff.
|
|
|
|
|
|
|
|
static QRect *visible_bound;
|
|
|
|
static QPointArray bound_shape;
|
|
|
|
|
|
|
|
bool B2Client::drawbound(const QRect& geom, bool clear)
|
|
|
|
{
|
|
|
|
if (clear) {
|
|
|
|
if (!visible_bound) return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!visible_bound) {
|
|
|
|
visible_bound = new QRect(geom);
|
|
|
|
QRect t = titlebar->geometry();
|
|
|
|
int frameTop = geom.top() + t.bottom();
|
|
|
|
int barLeft = geom.left() + bar_x_ofs;
|
2003-11-02 11:03:41 +00:00
|
|
|
int barRight = barLeft + t.width() - 1;
|
2003-09-21 20:43:44 +00:00
|
|
|
if (barRight > geom.right()) barRight = geom.right();
|
2004-09-22 15:09:42 +00:00
|
|
|
// line width is 5 pixels, so compensate for the 2 outer pixels (#88657)
|
|
|
|
QRect g = geom;
|
|
|
|
g.setLeft( g.left() + 2 );
|
|
|
|
g.setTop( g.top() + 2 );
|
|
|
|
g.setRight( g.right() - 2 );
|
|
|
|
g.setBottom( g.bottom() - 2 );
|
|
|
|
frameTop += 2;
|
|
|
|
barLeft += 2;
|
|
|
|
barRight -= 2;
|
2003-11-02 11:03:41 +00:00
|
|
|
|
2003-09-21 20:43:44 +00:00
|
|
|
bound_shape.putPoints(0, 8,
|
2004-09-22 15:09:42 +00:00
|
|
|
g.left(), frameTop,
|
2003-09-21 20:43:44 +00:00
|
|
|
barLeft, frameTop,
|
2004-09-22 15:09:42 +00:00
|
|
|
barLeft, g.top(),
|
|
|
|
barRight, g.top(),
|
2003-09-21 20:43:44 +00:00
|
|
|
barRight, frameTop,
|
2004-09-22 15:09:42 +00:00
|
|
|
g.right(), frameTop,
|
|
|
|
g.right(), g.bottom(),
|
|
|
|
g.left(), g.bottom());
|
2003-09-21 20:43:44 +00:00
|
|
|
} else {
|
|
|
|
*visible_bound = geom;
|
|
|
|
}
|
|
|
|
QPainter p(workspaceWidget());
|
|
|
|
p.setPen(QPen(Qt::white, 5));
|
|
|
|
p.setRasterOp(Qt::XorROP);
|
|
|
|
p.drawPolygon(bound_shape);
|
|
|
|
|
|
|
|
if (clear) {
|
|
|
|
delete visible_bound;
|
|
|
|
visible_bound = 0;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-09-20 17:44:49 +00:00
|
|
|
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;
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
processMousePressEvent(static_cast< QMouseEvent* >(e));
|
|
|
|
return true;
|
|
|
|
case QEvent::Show:
|
|
|
|
showEvent(static_cast< QShowEvent* >(e));
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
2003-07-26 10:41:28 +00:00
|
|
|
}
|
2002-08-27 18:08:20 +00:00
|
|
|
|
2003-09-20 17:44:49 +00:00
|
|
|
// =====================================
|
|
|
|
|
2004-05-23 22:59:13 +00:00
|
|
|
B2Button::B2Button(B2Client *_client, QWidget *parent,
|
|
|
|
const QString& tip, const int realizeBtns)
|
|
|
|
: QButton(parent, 0), hover(false)
|
2003-11-02 11:03:41 +00:00
|
|
|
{
|
2003-10-11 12:24:51 +00:00
|
|
|
setBackgroundMode(NoBackground);
|
2004-06-01 23:32:28 +00:00
|
|
|
setCursor(arrowCursor);
|
2003-11-02 11:03:41 +00:00
|
|
|
realizeButtons = realizeBtns;
|
2003-10-11 12:24:51 +00:00
|
|
|
client = _client;
|
|
|
|
useMiniIcon = false;
|
2003-11-02 11:03:41 +00:00
|
|
|
setFixedSize(buttonSize, buttonSize);
|
2003-10-11 12:24:51 +00:00
|
|
|
QToolTip::add(this, tip);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QSize B2Button::sizeHint() const
|
2001-06-19 14:32:08 +00:00
|
|
|
{
|
2003-10-15 16:50:29 +00:00
|
|
|
return QSize(buttonSize, buttonSize);
|
2003-09-20 17:44:49 +00:00
|
|
|
}
|
|
|
|
|
2003-10-11 12:24:51 +00:00
|
|
|
QSizePolicy B2Button::sizePolicy() const
|
2003-09-20 17:44:49 +00:00
|
|
|
{
|
2003-10-11 12:24:51 +00:00
|
|
|
return(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
|
2003-09-20 17:44:49 +00:00
|
|
|
}
|
|
|
|
|
2003-10-11 12:24:51 +00:00
|
|
|
void B2Button::drawButton(QPainter *p)
|
2003-09-20 17:44:49 +00:00
|
|
|
{
|
2003-10-11 12:24:51 +00:00
|
|
|
KPixmap* gradient = titleGradient[client->isActive() ? 0 : 1];
|
2003-11-02 11:03:41 +00:00
|
|
|
if (gradient) {
|
2003-10-15 16:50:29 +00:00
|
|
|
p->drawTiledPixmap(0, 0, buttonSize, buttonSize, *gradient, 0, 2);
|
2003-11-02 11:03:41 +00:00
|
|
|
} else {
|
2003-10-11 12:24:51 +00:00
|
|
|
p->fillRect(rect(), bg);
|
|
|
|
}
|
|
|
|
if (useMiniIcon) {
|
|
|
|
QPixmap miniIcon = client->icon().pixmap(QIconSet::Small,
|
|
|
|
client->isActive() ? QIconSet::Normal : QIconSet::Disabled);
|
2004-05-23 22:59:13 +00:00
|
|
|
p->drawPixmap((width() - miniIcon.width()) / 2,
|
|
|
|
(height() - miniIcon.height()) / 2, miniIcon);
|
|
|
|
} else {
|
|
|
|
int type;
|
|
|
|
if (client->isActive()) {
|
|
|
|
if (isOn() || isDown())
|
|
|
|
type = Down;
|
|
|
|
else if (hover)
|
|
|
|
type = Hover;
|
|
|
|
else
|
|
|
|
type = Norm;
|
|
|
|
} else {
|
|
|
|
if (isOn() || isDown())
|
|
|
|
type = IDown;
|
|
|
|
else if (hover)
|
|
|
|
type = IHover;
|
2003-10-11 12:24:51 +00:00
|
|
|
else
|
2004-05-23 22:59:13 +00:00
|
|
|
type = INorm;
|
2003-10-11 12:24:51 +00:00
|
|
|
}
|
2004-05-23 22:59:13 +00:00
|
|
|
p->drawPixmap((width() - icon[type]->width()) / 2,
|
|
|
|
(height() - icon[type]->height()) / 2, *icon[type]);
|
2003-10-11 12:24:51 +00:00
|
|
|
}
|
2003-09-20 17:44:49 +00:00
|
|
|
}
|
|
|
|
|
2003-10-11 12:24:51 +00:00
|
|
|
void B2Button::setPixmaps(int button_id)
|
|
|
|
{
|
2004-05-23 22:59:13 +00:00
|
|
|
button_id *= NumStates;
|
|
|
|
for (int i = 0; i < NumStates; i++) {
|
|
|
|
icon[i] = B2::pixmap[button_id + i];
|
|
|
|
}
|
|
|
|
repaint(false);
|
2003-10-11 12:24:51 +00:00
|
|
|
}
|
|
|
|
|
2004-05-23 22:59:13 +00:00
|
|
|
void B2Button::mousePressEvent(QMouseEvent * e)
|
2003-10-11 12:24:51 +00:00
|
|
|
{
|
|
|
|
last_button = e->button();
|
2004-05-23 22:59:13 +00:00
|
|
|
QMouseEvent me(e->type(), e->pos(), e->globalPos(),
|
|
|
|
(e->button() & realizeButtons) ? LeftButton : NoButton,
|
|
|
|
e->state());
|
2003-10-11 12:24:51 +00:00
|
|
|
QButton::mousePressEvent(&me);
|
|
|
|
}
|
|
|
|
|
2004-05-23 22:59:13 +00:00
|
|
|
void B2Button::mouseReleaseEvent(QMouseEvent * e)
|
2003-10-11 12:24:51 +00:00
|
|
|
{
|
|
|
|
last_button = e->button();
|
2004-05-23 22:59:13 +00:00
|
|
|
QMouseEvent me(e->type(), e->pos(), e->globalPos(),
|
|
|
|
(e->button() & realizeButtons) ? LeftButton : NoButton,
|
|
|
|
e->state());
|
2003-10-11 12:24:51 +00:00
|
|
|
QButton::mouseReleaseEvent(&me);
|
|
|
|
}
|
|
|
|
|
2004-06-01 23:32:28 +00:00
|
|
|
void B2Button::enterEvent(QEvent *e)
|
2004-05-23 22:59:13 +00:00
|
|
|
{
|
|
|
|
hover = true;
|
|
|
|
repaint(false);
|
2004-06-01 23:32:28 +00:00
|
|
|
QButton::enterEvent(e);
|
2004-05-23 22:59:13 +00:00
|
|
|
}
|
|
|
|
|
2004-06-01 23:32:28 +00:00
|
|
|
void B2Button::leaveEvent(QEvent *e)
|
2004-05-23 22:59:13 +00:00
|
|
|
{
|
|
|
|
hover = false;
|
|
|
|
repaint(false);
|
2004-06-01 23:32:28 +00:00
|
|
|
QButton::leaveEvent(e);
|
2004-05-23 22:59:13 +00:00
|
|
|
}
|
2004-06-01 23:32:28 +00:00
|
|
|
|
2003-10-11 12:24:51 +00:00
|
|
|
// =====================================
|
|
|
|
|
|
|
|
B2Titlebar::B2Titlebar(B2Client *parent)
|
|
|
|
: QWidget(parent->widget(), 0, WStyle_Customize | WRepaintNoErase),
|
|
|
|
client(parent),
|
|
|
|
set_x11mask(false), isfullyobscured(false), shift_move(false)
|
|
|
|
{
|
|
|
|
setBackgroundMode(NoBackground);
|
2004-07-03 10:35:13 +00:00
|
|
|
captionSpacer = new QSpacerItem(buttonSize, buttonSize + 4,
|
2003-10-15 16:50:29 +00:00
|
|
|
QSizePolicy::Expanding, QSizePolicy::Fixed);
|
2003-09-20 17:44:49 +00:00
|
|
|
}
|
|
|
|
|
2003-10-11 12:24:51 +00:00
|
|
|
bool B2Titlebar::x11Event(XEvent *e)
|
|
|
|
{
|
|
|
|
if (!set_x11mask) {
|
|
|
|
set_x11mask = true;
|
|
|
|
XSelectInput(qt_xdisplay(), winId(),
|
|
|
|
KeyPressMask | KeyReleaseMask |
|
|
|
|
ButtonPressMask | ButtonReleaseMask |
|
|
|
|
KeymapStateMask |
|
|
|
|
ButtonMotionMask |
|
|
|
|
EnterWindowMask | LeaveWindowMask |
|
|
|
|
FocusChangeMask |
|
|
|
|
ExposureMask |
|
|
|
|
PropertyChangeMask |
|
|
|
|
StructureNotifyMask | SubstructureRedirectMask |
|
|
|
|
VisibilityChangeMask);
|
|
|
|
}
|
2004-06-02 13:46:54 +00:00
|
|
|
switch (e->type) {
|
2003-10-11 12:24:51 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
KPixmap* gradient = titleGradient[state ? 0 : 1];
|
2003-11-02 11:03:41 +00:00
|
|
|
|
2003-10-11 12:24:51 +00:00
|
|
|
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
|
2003-11-02 11:03:41 +00:00
|
|
|
const QColorGroup cg =
|
2003-10-11 12:24:51 +00:00
|
|
|
options()->colorGroup(KDecoration::ColorTitleBar, state);
|
|
|
|
QBrush brush(cg.background());
|
|
|
|
if (gradient) brush.setPixmap(*gradient);
|
2003-11-02 11:03:41 +00:00
|
|
|
qDrawShadeRect(&p, 1, 1, t.right() - 1, t.height() - 1,
|
2003-10-11 12:24:51 +00:00
|
|
|
cg, false, 1, 0, &brush);
|
|
|
|
|
|
|
|
// and the caption
|
|
|
|
p.setPen(options()->color(KDecoration::ColorFont, state));
|
|
|
|
p.setFont(options()->font(state));
|
|
|
|
t = captionSpacer->geometry();
|
|
|
|
p.drawText(t, AlignLeft | AlignVCenter, client->caption());
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Titlebar::recalcBuffer()
|
|
|
|
{
|
|
|
|
titleBuffer.resize(width(), height());
|
|
|
|
|
|
|
|
QPainter p(&titleBuffer);
|
|
|
|
drawTitlebar(p, true);
|
|
|
|
oldTitle = caption();
|
|
|
|
}
|
|
|
|
|
|
|
|
void B2Titlebar::resizeEvent(QResizeEvent *)
|
|
|
|
{
|
|
|
|
recalcBuffer();
|
|
|
|
repaint(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void B2Titlebar::paintEvent(QPaintEvent *)
|
|
|
|
{
|
|
|
|
if(client->isActive())
|
|
|
|
bitBlt(this, 0, 0, &titleBuffer, 0, 0, titleBuffer.width(),
|
|
|
|
titleBuffer.height(), Qt::CopyROP, true);
|
|
|
|
else {
|
|
|
|
QPainter p(this);
|
|
|
|
drawTitlebar(p, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-06 15:21:14 +00:00
|
|
|
void B2Titlebar::mouseDoubleClickEvent(QMouseEvent *e)
|
2003-10-11 12:24:51 +00:00
|
|
|
{
|
2004-03-06 15:21:14 +00:00
|
|
|
if (e->y() < height()) {
|
|
|
|
client->titlebarDblClickOperation();
|
|
|
|
}
|
2003-10-11 12:24:51 +00:00
|
|
|
}
|
|
|
|
|
2004-06-02 13:46:54 +00:00
|
|
|
void B2Titlebar::mousePressEvent(QMouseEvent * e)
|
2003-10-11 12:24:51 +00:00
|
|
|
{
|
|
|
|
shift_move = e->state() & ShiftButton;
|
|
|
|
if (shift_move) {
|
|
|
|
moveOffset = e->globalPos();
|
|
|
|
} else {
|
2003-10-19 09:26:34 +00:00
|
|
|
e->ignore();
|
2003-10-11 12:24:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-02 13:46:54 +00:00
|
|
|
void B2Titlebar::mouseReleaseEvent(QMouseEvent * e)
|
2003-10-11 12:24:51 +00:00
|
|
|
{
|
2003-10-19 09:26:34 +00:00
|
|
|
if (shift_move) shift_move = false;
|
|
|
|
else e->ignore();
|
2003-10-11 12:24:51 +00:00
|
|
|
}
|
|
|
|
|
2004-06-02 13:46:54 +00:00
|
|
|
void B2Titlebar::mouseMoveEvent(QMouseEvent * e)
|
2003-10-11 12:24:51 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2003-10-19 09:16:11 +00:00
|
|
|
} else {
|
|
|
|
e->ignore();
|
2003-11-02 11:03:41 +00:00
|
|
|
}
|
2003-10-11 12:24:51 +00:00
|
|
|
}
|
|
|
|
|
2003-10-19 09:16:11 +00:00
|
|
|
} // namespace B2
|
2001-06-19 14:32:08 +00:00
|
|
|
|
|
|
|
#include "b2client.moc"
|
2003-09-20 17:44:49 +00:00
|
|
|
|
|
|
|
// vim: sw=4
|
|
|
|
|