Redmond style merged back from kwin_iii to HEAD, done by Chris Lee.

svn path=/trunk/kdebase/kwin/; revision=251771
This commit is contained in:
Luboš Luňák 2003-09-17 08:27:26 +00:00
parent 6e273005c7
commit 7b0773facd
4 changed files with 490 additions and 425 deletions

View file

@ -1,21 +1,11 @@
INCLUDES = $(all_includes)
INCLUDES = -I$(srcdir)/../../lib $(all_includes)
kde_module_LTLIBRARIES = kwin_redmond.la
kde_module_LTLIBRARIES = kwin3_redmond.la
kwin_redmond_la_SOURCES = redmond.cpp
#kwin_redmond_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) -module
kwin_redmond_la_LDFLAGS = $(all_libraries) -avoid-version -module $(KDE_RPATH) $(KDE_MT_LDFLAGS)
kwin3_redmond_la_SOURCES = redmond.cpp
kwin3_redmond_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) -module
kwin3_redmond_la_LIBADD = $(LIB_KDECORE) ../../lib/libkwin.la
METASOURCES = AUTO
noinst_HEADERS = redmond.h
lnkdir = $(kde_datadir)/kwin/
lnk_DATA = redmond.desktop
EXTRA_DIST = $(lnk_DATA)
###KMAKE-start (don't edit or delete this block)
###KMAKE-end

View file

@ -14,6 +14,7 @@
*/
#include "redmond.h"
#include <qlayout.h>
#include <qdrawutil.h>
#include <qdatetime.h>
@ -21,12 +22,12 @@
#include <kimageeffect.h>
#include <kdrawutil.h>
#include <klocale.h>
#include <qbitmap.h>
#include "../../workspace.h"
#include "../../options.h"
#include <qimage.h>
using namespace KWinInternal;
#include <qbitmap.h>
#include <qtooltip.h>
#include <qimage.h>
#include <qlabel.h>
#include <qapplication.h>
namespace Redmond {
@ -94,6 +95,10 @@ static QPixmap *defaultMenuPix;
static QColor *btnForeground;
static bool pixmaps_created = false;
static inline const KDecorationOptions *options()
{
return KDecoration::options();
}
static void drawButtonFrame( KPixmap *pix, const QColorGroup &g, bool sunken )
{
@ -103,22 +108,22 @@ static void drawButtonFrame( KPixmap *pix, const QColorGroup &g, bool sunken )
p.begin(pix);
// titlebar button frame
p.setPen( sunken ? Qt::black : g.light());
p.setPen( sunken ? g.dark().dark(155) : g.light());
p.drawLine(0, 0, x2-1, 0);
p.drawLine(0, 0, 0, y2-1);
if (sunken)
{
p.setPen( g.dark() );
p.setPen( g.mid().dark(135) );
p.drawLine(1, 1, x2-2, 1);
p.drawLine(1, 1, 1, y2-2);
}
p.setPen( sunken ? g.light() : g.dark());
p.setPen( sunken ? g.light() : g.mid().dark(135));
p.drawLine(1, y2-1, x2-1, y2-1);
p.drawLine(x2-1, 1, x2-1, y2-1);
p.setPen( sunken ? g.light() : Qt::black);
p.setPen( sunken ? g.light() : g.dark().dark(155));
p.drawLine(0, y2, x2, y2);
p.drawLine(x2, 0, x2, y2);
}
@ -144,7 +149,7 @@ static void create_pixmaps( )
defaultMenuPix = new QPixmap(kdelogo);
// buttons (active/inactive, sunken/unsunken)
QColorGroup g = options->colorGroup(Options::ButtonBg, true);
QColorGroup g = options()->colorGroup(KDecoration::ColorButtonBg, true);
QColor c = g.background();
btnPix1->resize(16, 14);
btnDownPix1->resize(16, 14);
@ -156,8 +161,7 @@ static void create_pixmaps( )
iMiniBtnPix1->resize(12, 12);
iMiniBtnDownPix1->resize(12, 12);
if(highcolor)
{
if (highcolor && false) {
KPixmapEffect::gradient(*btnPix1, c.light(130), c.dark(130),
KPixmapEffect::VerticalGradient);
KPixmapEffect::gradient(*btnDownPix1, c.dark(130), c.light(130),
@ -168,7 +172,7 @@ static void create_pixmaps( )
KPixmapEffect::gradient(*miniBtnDownPix1, c.dark(130), c.light(130),
KPixmapEffect::VerticalGradient);
g = options->colorGroup(Options::ButtonBg, false);
g = options()->colorGroup(KDecoration::ColorButtonBg, false);
c = g.background();
KPixmapEffect::gradient(*iBtnPix1, c.light(130), c.dark(130),
KPixmapEffect::VerticalGradient);
@ -178,15 +182,13 @@ static void create_pixmaps( )
KPixmapEffect::VerticalGradient);
KPixmapEffect::gradient(*iMiniBtnDownPix1, c.dark(130), c.light(130),
KPixmapEffect::VerticalGradient);
}
else
{
} else {
btnPix1->fill(c.rgb());
btnDownPix1->fill(c.rgb());
miniBtnPix1->fill(c.rgb());
miniBtnDownPix1->fill(c.rgb());
g = options->colorGroup(Options::ButtonBg, false);
g = options()->colorGroup(KDecoration::ColorButtonBg, false);
c = g.background();
iBtnPix1->fill(c.rgb());
iBtnDownPix1->fill(c.rgb());
@ -194,20 +196,20 @@ static void create_pixmaps( )
iMiniBtnDownPix1->fill(c.rgb());
}
g = options->colorGroup(Options::ButtonBg, true);
g = options()->colorGroup(KDecoration::ColorButtonBg, true);
drawButtonFrame(btnPix1, g, false);
drawButtonFrame(btnDownPix1, g, true);
drawButtonFrame(miniBtnPix1, g, false);
drawButtonFrame(miniBtnDownPix1, g, true);
g = options->colorGroup(Options::ButtonBg, false);
g = options()->colorGroup(KDecoration::ColorButtonBg, false);
drawButtonFrame(iBtnPix1, g, false);
drawButtonFrame(iBtnDownPix1, g, true);
drawButtonFrame(iMiniBtnPix1, g, false);
drawButtonFrame(iMiniBtnDownPix1, g, true);
// Make sure button pixmaps contrast with the current colour scheme.
if(qGray(options->color(Options::ButtonBg, true).rgb()) > 127)
if (qGray(options()->color(KDecoration::ColorButtonBg, true).rgb()) > 127)
btnForeground = new QColor(Qt::black);
else
btnForeground = new QColor(Qt::white);
@ -229,40 +231,40 @@ void delete_pixmaps()
}
GalliumButton::GalliumButton(Client *parent, const char *name,
RedmondButton::RedmondButton(RedmondDeco *parent, const char *name,
const unsigned char *bitmap, bool menuButton, bool isMini, const QString& tip)
: KWinButton(parent, name, tip)
: QButton(parent->widget(), name)
{
// Eliminate background flicker
setBackgroundMode( QWidget::NoBackground );
setBackgroundMode( NoBackground );
menuBtn = menuButton;
miniBtn = isMini;
client = parent;
// Use larger button for the menu, or mini-buttons for toolwindows.
if ( isMini )
{
if ( isMini ) {
setFixedSize(12, 12);
resize(12, 12);
} else
if ( menuButton )
{
} else {
if ( menuButton ) {
setFixedSize(16, 16);
resize(16, 16);
}
else
{
} else {
setFixedSize(16, 14);
resize(16, 14);
}
}
if(bitmap)
if ( bitmap ) {
setBitmap(bitmap);
}
QToolTip::add(this, tip);
}
QSize GalliumButton::sizeHint() const
QSize RedmondButton::sizeHint() const
{
if ( miniBtn )
return( QSize(12, 12) );
@ -274,13 +276,13 @@ QSize GalliumButton::sizeHint() const
}
void GalliumButton::reset()
void RedmondButton::reset()
{
repaint(false);
}
void GalliumButton::setBitmap(const unsigned char *bitmap)
void RedmondButton::setBitmap(const unsigned char *bitmap)
{
pix.resize(0, 0);
deco = QBitmap(10, 10, bitmap, true);
@ -289,7 +291,7 @@ void GalliumButton::setBitmap(const unsigned char *bitmap)
}
void GalliumButton::setPixmap( const QPixmap &p )
void RedmondButton::setPixmap( const QPixmap &p )
{
deco.resize(0, 0);
pix = p;
@ -305,37 +307,33 @@ void GalliumButton::setPixmap( const QPixmap &p )
}
void GalliumButton::mousePressEvent( QMouseEvent* e )
void RedmondButton::mousePressEvent( QMouseEvent* e )
{
last_button = e->button();
QMouseEvent me(e->type(), e->pos(), e->globalPos(),
LeftButton, e->state());
KWinButton::mousePressEvent( &me );
QButton::mousePressEvent( &me );
}
void GalliumButton::mouseReleaseEvent( QMouseEvent* e )
void RedmondButton::mouseReleaseEvent( QMouseEvent* e )
{
last_button = e->button();
QMouseEvent me ( e->type(), e->pos(), e->globalPos(),
LeftButton, e->state() );
KWinButton::mouseReleaseEvent( &me );
QButton::mouseReleaseEvent( &me );
}
void GalliumButton::drawButton(QPainter *p)
{
if(pix.isNull())
{
if(client->isActive())
void RedmondButton::drawButton(QPainter *p)
{
if ( pix.isNull() ) {
if ( client->isActive() ) {
if ( isDown() )
p->drawPixmap(0, 0, miniBtn ? *miniBtnDownPix1 : *btnDownPix1);
else
p->drawPixmap(0, 0, miniBtn ? *miniBtnPix1 : *btnPix1);
}
else
{
} else {
if ( isDown() )
p->drawPixmap(0, 0, miniBtn ? *iMiniBtnDownPix1 : *iBtnDownPix1);
else
@ -346,14 +344,11 @@ void GalliumButton::drawButton(QPainter *p)
int xOff = (width()-10)/2;
int yOff = (height()-10)/2;
p->drawPixmap(isDown() ? xOff+1: xOff, isDown() ? yOff+1 : yOff, deco);
}
else
{
} else {
p->fillRect(0, 0, width(), height(),
options->color(Options::TitleBar, client->isActive()));
options()->color(KDecoration::ColorTitleBar, client->isActive()));
if ( menuBtn && miniBtn )
{
if ( menuBtn && miniBtn ) {
QPixmap tmpPix;
// Smooth scale the menu button pixmap
@ -366,114 +361,119 @@ void GalliumButton::drawButton(QPainter *p)
}
GalliumClient::GalliumClient( Workspace *ws, WId w, QWidget *parent,
const char *name )
: Client( ws, w, parent, name, WResizeNoErase | WStaticContents |
WRepaintNoErase )
RedmondDeco::RedmondDeco(KDecorationBridge *b, KDecorationFactory *f)
: KDecoration(b, f)
{
setBackgroundMode( QWidget::NoBackground );
}
void RedmondDeco::init()
{
createMainWidget(WResizeNoErase);
widget()->installEventFilter(this);
widget()->setBackgroundMode(NoBackground);
// bool reverse = QApplication::reverseLayout();
// Finally, toolwindows look small
if ( isTool() ) {
titleHeight = 14;
smallButtons = true;
} else {
// if ( isTool() ) {
// titleHeight = 14;
// smallButtons = true;
// } else {
titleHeight = 18;
smallButtons = false;
}
// }
lastButtonWidth = 0;
QGridLayout* g = new QGridLayout(this, 0, 0, 0);
QGridLayout* g = new QGridLayout(widget(), 0, 0, 0);
g->setResizeMode(QLayout::FreeResize);
if (isPreview()) {
g->addWidget(new QLabel(i18n("<center><b>Redmond preview</b></center>"), widget()), 3, 1);
} else {
g->addWidget(new QWidget(widget()), 3, 1);
}
g->addRowSpacing(0, 4); // Top grab bar
g->addWidget(windowWrapper(), 3, 1);
// without the next line, unshade flickers
g->addItem( new QSpacerItem( 0, 0, QSizePolicy::Fixed,
QSizePolicy::Expanding ) );
g->addItem(new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding));
g->setRowStretch(3, 10); // Wrapped window
g->addRowSpacing(4, 4); // bottom handles
g->addRowSpacing(2, 1); // Line below title bar
g->addColSpacing(0, 4);
g->addColSpacing(2, 4);
button[BtnMenu] = new GalliumButton(this, "menu", NULL, true, smallButtons,
i18n("Menu"));
button[BtnClose] = new GalliumButton(this, "close", close_bits, false, smallButtons,
i18n("Close"));
button[BtnIconify] = new GalliumButton(this, "iconify", iconify_bits, false, smallButtons,
i18n("Minimize"));
button[BtnMax] = new GalliumButton(this, "maximize", maximize_bits, false, smallButtons,
i18n("Maximize"));
button[BtnMenu] = new RedmondButton(this, "menu", NULL, true, smallButtons, i18n("Menu"));
button[BtnClose] = new RedmondButton(this, "close", close_bits, false, smallButtons, i18n("Close"));
button[BtnMin] = new RedmondButton(this, "iconify", iconify_bits, false, smallButtons, i18n("Minimize"));
button[BtnMax] = new RedmondButton(this, "maximize", maximize_bits, false, smallButtons, i18n("Maximize"));
// Connect required stuff together
connect(button[BtnMenu], SIGNAL(pressed()), this, SLOT(menuButtonPressed()));
connect( button[BtnMenu], SIGNAL(released()), this, SLOT( menuButtonReleased() ));
connect(button[BtnClose], SIGNAL(clicked()), this, SLOT(closeWindow()));
connect( button[BtnIconify], SIGNAL( clicked() ), this, SLOT( iconify() ));
connect(button[BtnMin], SIGNAL(clicked()), this, SLOT(minimize()));
connect(button[BtnMax], SIGNAL(clicked()), this, SLOT(slotMaximize()));
connect( options, SIGNAL(resetClients()), this, SLOT( slotReset() ));
// Pack the titleBar hbox with items
hb = new QBoxLayout(0, QBoxLayout::LeftToRight, 0, 0, 0);
hb->setResizeMode(QLayout::FreeResize);
g->addLayout( hb, 1, 1 );
hb->addSpacing(2);
hb->addWidget(button[BtnMenu]);
titlebar = new QSpacerItem(10, titleHeight, QSizePolicy::Expanding, QSizePolicy::Minimum);
hb->addItem(titlebar);
hb->addSpacing(2);
if( providesContextHelp() )
{
button[BtnHelp] = new GalliumButton(this, "help", question_bits, false, smallButtons,
i18n("Help"));
if ( providesContextHelp() ) {
button[BtnHelp] = new RedmondButton(this, "help", question_bits, false, smallButtons, i18n("Help"));
connect( button[BtnHelp], SIGNAL( clicked() ), this, SLOT( contextHelp() ));
hb->addWidget( button[BtnHelp] );
}
else
} else {
button[BtnHelp] = NULL;
}
hb->addWidget( button[BtnIconify] );
hb->addWidget(button[BtnMin]);
hb->addWidget(button[BtnMax]);
hb->addSpacing(2);
hb->addWidget(button[BtnClose]);
hb->addSpacing(2);
g->addLayout(hb, 1, 1);
// Hide buttons which are not required
// We can un-hide them if required later
if (!isMinimizable())
button[BtnIconify]->hide();
button[BtnMin]->hide();
if (!isMaximizable())
button[BtnMax]->hide();
if (!isCloseable())
button[BtnClose]->hide();
hiddenItems = false;
closing = false;
// Make sure that the menu button uses the correct mini-icon
iconChange();
widget()->layout()->activate();
}
void GalliumClient::slotReset()
void RedmondDeco::slotReset()
{
// 0 to 3 ( 4 buttons - Help, Max, Iconify, Close )
for(int i = GalliumClient::BtnHelp; i <= GalliumClient::BtnClose; i++)
for(int i = RedmondDeco::BtnHelp; i <= RedmondDeco::BtnClose; i++)
if (button[i])
button[i]->reset();
// The menu is reset by iconChange()
repaint( false );
widget()->repaint( false );
}
void GalliumClient::iconChange()
void RedmondDeco::iconChange()
{
if(!miniIcon().isNull())
button[BtnMenu]->setPixmap(miniIcon());
QPixmap *miniIcon = new QPixmap(icon().pixmap(QIconSet::Small, QIconSet::Normal));
if (!miniIcon->isNull())
button[BtnMenu]->setPixmap(*miniIcon);
else
button[BtnMenu]->setPixmap(*defaultMenuPix);
@ -482,25 +482,22 @@ void GalliumClient::iconChange()
}
void GalliumClient::slotMaximize()
void RedmondDeco::slotMaximize()
{
if ( button[BtnMax]->last_button == MidButton )
maximize( MaximizeVertical );
maximize( maximizeMode() ^ MaximizeVertical );
else if ( button[BtnMax]->last_button == RightButton )
maximize( MaximizeHorizontal );
maximize( maximizeMode() ^ MaximizeHorizontal );
else
maximize();
maximize( maximizeMode() == MaximizeFull ? MaximizeRestore : MaximizeFull );
}
void GalliumClient::resizeEvent( QResizeEvent* e)
void RedmondDeco::resizeEvent(QResizeEvent *)
{
Client::resizeEvent( e );
calcHiddenButtons();
if (isVisibleToTLW())
{
/*
if (isVisibleToTLW()) {
update(rect());
int dx = 0;
int dy = 0;
@ -523,24 +520,25 @@ void GalliumClient::resizeEvent( QResizeEvent* e)
QApplication::postEvent( this, new QPaintEvent( titlebar->geometry(), FALSE ) );
}
}
*/
}
void GalliumClient::captionChange( const QString& )
void RedmondDeco::captionChange( const QString& )
{
repaint( titlebar->geometry(), false );
widget()->repaint( titlebar->geometry(), false );
}
void GalliumClient::paintEvent( QPaintEvent* )
void RedmondDeco::paintEvent( QPaintEvent* )
{
bool hicolor = QPixmap::defaultDepth() > 8;
int fontoffset = 1;
QPainter p(this);
QPainter p(widget());
// Obtain widget bounds.
QRect r(rect());
QRect r(widget()->rect());
int x = r.x();
int y = r.y();
int x2 = r.width()-1;
@ -550,7 +548,7 @@ void GalliumClient::paintEvent( QPaintEvent* )
// Draw part of the frame that is the frame color
// ==============================================
QColorGroup g = options->colorGroup(Options::Frame, isActive());
QColorGroup g = options()->colorGroup(KDecoration::ColorFrame, isActive());
p.setPen( g.background() );
p.drawLine( x, y, x2-1, y );
p.drawLine( x, y, x, y2-1 );
@ -569,41 +567,37 @@ void GalliumClient::paintEvent( QPaintEvent* )
p.drawLine( x+1, y+1, x2-2, y+1);
p.drawLine( x+1, y+1, x+1, y2-2);
p.setPen(g.dark());
p.setPen(g.mid().dark(135));
p.drawLine( x2-1, y+1, x2-1, y2-1);
p.drawLine( x+1, y2-1, x2-1, y2-1);
// Draw black edges
p.setPen( Qt::black );
p.setPen( g.dark().dark(155) );
p.drawLine(x2, y, x2, y2);
p.drawLine(x, y2, x2, y2);
// Draw the title bar.
// ===================
r = titlebar->geometry();
QFontMetrics fm(options->font(true));
QFontMetrics fm(options()->font(true));
// Obtain blend colours.
QColor c1 = options->color(Options::TitleBar, isActive() );
QColor c2 = options->color(Options::TitleBlend, isActive() );
QColor c1 = options()->color(KDecoration::ColorTitleBar, isActive() );
QColor c2 = options()->color(KDecoration::ColorTitleBlend, isActive() );
// Paint without a buffer if the colours are the same to
// improve performance, and only draw gradients on hicolor displays.
if ((c1 != c2) && hicolor)
{
if ((c1 != c2) && hicolor) {
// KS - Add gradient caching if needed at a later stage.
// Create a disposable pixmap buffer for the title blend
KPixmap* titleBuffer = new KPixmap;
titleBuffer->resize(w-8, titleHeight);
if (titleBuffer->depth() > 16)
{
if (titleBuffer->depth() > 16) {
KPixmapEffect::gradient(*titleBuffer, c1, c2,
KPixmapEffect::HorizontalGradient);
}
else
{
} else {
// This enables dithering on 15 and 16bit displays, preventing
// some pretty horrible banding effects
QImage image = KImageEffect::gradient(titleBuffer->size(), c1, c2,
@ -618,15 +612,14 @@ void GalliumClient::paintEvent( QPaintEvent* )
// to draw the title text on the pixmap.
// Reduce the font size and weight for toolwindows.
QFont fnt = options->font(true);
if ( smallButtons )
{
QFont fnt = options()->font(true);
if ( smallButtons ) {
fnt.setPointSize( fnt.pointSize() - 2 ); // Shrink font by 2 pt.
fnt.setWeight( QFont::Normal );
fontoffset = 0;
}
p2.setFont( fnt );
p2.setPen( options->color(Options::Font, isActive() ));
p2.setPen( options()->color(KDecoration::ColorFont, isActive() ));
p2.drawText( r.x(), fontoffset, r.width()-3, r.height()-1,
AlignLeft | AlignVCenter, caption() );
p2.end();
@ -635,14 +628,13 @@ void GalliumClient::paintEvent( QPaintEvent* )
delete titleBuffer;
} else
{
} else {
// Assume lower ended hardware, so don't use buffers.
// Don't draw a gradient either.
p.fillRect( 4, 4, w-8, titleHeight, c1 );
// Draw the title text.
QFont fnt = options->font(true);
QFont fnt = options()->font(true);
if ( smallButtons )
{
fnt.setPointSize( fnt.pointSize() - 2 ); // Shrink font by 2 pt.
@ -650,165 +642,224 @@ void GalliumClient::paintEvent( QPaintEvent* )
fontoffset = 0;
}
p.setFont( fnt );
p.setPen(options->color(Options::Font, isActive() ));
p.setPen(options()->color(KDecoration::ColorFont, isActive() ));
p.drawText(r.x()+4, r.y()+fontoffset, r.width()-3, r.height()-1,
AlignLeft | AlignVCenter, caption() );
}
}
void GalliumClient::showEvent(QShowEvent *ev)
void RedmondDeco::showEvent(QShowEvent *)
{
calcHiddenButtons();
show();
Client::showEvent(ev);
widget()->show();
}
void GalliumClient::mouseDoubleClickEvent( QMouseEvent * e )
void RedmondDeco::mouseDoubleClickEvent( QMouseEvent * e )
{
if (titlebar->geometry().contains( e->pos() ) )
workspace()->performWindowOperation( this, options->operationTitlebarDblClick() );
titlebarDblClickOperation();
}
void GalliumClient::maximizeChange(bool m)
void RedmondDeco::maximizeChange(bool m)
{
button[BtnMax]->setBitmap(m ? minmax_bits : maximize_bits);
button[BtnMax]->setTipText(m ? i18n("Restore") : i18n("Maximize"));
}
void GalliumClient::activeChange(bool)
{
if(!miniIcon().isNull())
{
button[BtnMenu]->setPixmap(miniIcon());
}
else
button[BtnMenu]->setPixmap(kdelogo);
for(int i=GalliumClient::BtnHelp; i < GalliumClient::BtnMenu; i++)
{
if(button[i])
button[i]->reset();
}
// Reset the menu button ?
repaint(false);
}
void GalliumClient::calcHiddenButtons()
void RedmondDeco::calcHiddenButtons()
{
// order of hiding is help, maximize, minimize, close, then menu;
int minWidth = 32 + 16*4 + (providesContextHelp() ? 16*2 : 16 );
if(lastButtonWidth > width()) // Shrinking
{
if (lastButtonWidth > width()) { // Shrinking
lastButtonWidth = width();
if(width() < minWidth)
{
if (width() < minWidth) {
hiddenItems = true;
for(int i = GalliumClient::BtnHelp; i <= GalliumClient::BtnMenu; i++)
{
if(button[i])
{
if( !button[i]->isHidden() )
{
for(int i = RedmondDeco::BtnHelp; i <= RedmondDeco::BtnMenu; i++) {
if (button[i]) {
if ( !button[i]->isHidden() ) {
button[i]->hide();
}
minWidth -= button[i]->sizeHint().width();
if(width() >= minWidth)
if (width() >= minWidth) {
return;
}
}
}
}
else
if(hiddenItems) // Expanding
{
} else {
if ( hiddenItems ) { // Expanding
lastButtonWidth = width();
int totalSize = 16*3;
for(int i = GalliumClient::BtnMenu; i >= GalliumClient::BtnHelp; i--)
{
if(button[i])
{
if(button[i]->sizeHint().width() + totalSize <= width())
{
for (int i = RedmondDeco::BtnMenu; i >= RedmondDeco::BtnHelp; i--) {
if (button[i]) {
if (button[i]->sizeHint().width() + totalSize <= width()) {
totalSize += button[i]->sizeHint().width();
button[i]->resize(button[i]->sizeHint());
button[i]->show();
}
else
} else {
return;
}
}
}
// all items shown now
hiddenItems = false;
}
else
} else {
lastButtonWidth = width();
}
}
}
RedmondDeco::MousePosition RedmondDeco::mousePosition(const QPoint &p) const
{
// MousePosition m = KDecoration::mousePosition(p);
// return m;
return KDecoration::mousePosition(p);
}
void GalliumClient::menuButtonPressed()
void RedmondDeco::borders(int &l, int &r, int &t, int &b) const
{
// bool reverse = QApplication::reverseLayout();
l = 4;
r = 4;
t = titlebar->geometry().height() + 5;
b = 4;
}
void RedmondDeco::resize(const QSize &s)
{
widget()->resize(s);
}
QSize RedmondDeco::minimumSize() const
{
return QSize(50, 50); // what's good for the goose....
}
void RedmondDeco::activeChange()
{
QPixmap *miniIcon = new QPixmap(icon().pixmap(QIconSet::Small, QIconSet::Normal));
if (!miniIcon->isNull()) {
button[BtnMenu]->setPixmap(*miniIcon);
} else {
button[BtnMenu]->setPixmap(kdelogo);
}
// Reset the menu button ?
for (int i = BtnHelp; i < BtnCount; i++) {
if (button[i]) button[i]->reset();
}
widget()->repaint(false);
}
void RedmondDeco::captionChange()
{
widget()->repaint(titlebar->geometry(), false);
}
void RedmondDeco::maximizeChange()
{
bool m = (maximizeMode() == MaximizeFull);
button[BtnMax]->setBitmap(m ? minmax_bits : maximize_bits);
QToolTip::remove(button[BtnMax]);
QToolTip::add(button[BtnMax], m ? i18n("Restore") : i18n("Maximize"));
}
void RedmondDeco::desktopChange()
{
}
void RedmondDeco::shadeChange()
{
}
void RedmondDeco::menuButtonPressed()
{
static QTime* t = NULL;
static GalliumClient* lastClient = NULL;
if( t == NULL )
t = new QTime;
static RedmondDeco* lastClient = NULL;
if (t == NULL) t = new QTime;
bool dbl = ( lastClient == this && t->elapsed() <= QApplication::doubleClickInterval());
lastClient = this;
t->start();
if( !dbl )
{
if (!dbl) {
QPoint menupoint(button[BtnMenu]->rect().bottomLeft().x()-3,
button[BtnMenu]->rect().bottomLeft().y()+2 );
workspace()->showWindowMenu( button[BtnMenu]->mapToGlobal( menupoint ), this );
button[BtnMenu]->rect().bottomLeft().y()+4);
showWindowMenu(button[BtnMenu]->mapToGlobal(menupoint));
button[BtnMenu]->setDown(false);
}
else
closing = true;
}
void GalliumClient::menuButtonReleased()
{
if ( closing )
} else {
closeWindow();
}
}
extern "C"
bool RedmondDeco::eventFilter(QObject *o, QEvent *e)
{
Client *allocate(Workspace *ws, WId w, int)
{
return(new Redmond::GalliumClient(ws, w));
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::Show: {
showEvent(static_cast<QShowEvent *>(e));
return true;
}
case QEvent::MouseButtonDblClick: {
mouseDoubleClickEvent(static_cast<QMouseEvent *>(e));
return true;
}
case QEvent::MouseButtonPress: {
processMousePressEvent(static_cast<QMouseEvent *>(e));
return true;
}
default: {
break;
}
}
void init()
{
Redmond::create_pixmaps();
return false;
}
void reset()
RedmondDecoFactory::RedmondDecoFactory()
{
Redmond::delete_pixmaps();
Redmond::create_pixmaps();
Workspace::self()->slotResetAllClientsDelayed();
create_pixmaps();
}
void deinit()
RedmondDecoFactory::~RedmondDecoFactory()
{
Redmond::delete_pixmaps();
}
KDecoration *RedmondDecoFactory::createDecoration( KDecorationBridge *b )
{
return new RedmondDeco(b, this);
}
bool RedmondDecoFactory::reset( unsigned long changed )
{
if ( changed && false ) {
return true;
} else {
resetDecorations(changed);
return false;
}
}
}
extern "C" KDecorationFactory *create_factory()
{
return new Redmond::RedmondDecoFactory();
}

View file

@ -6,4 +6,4 @@ Name[fa]=ردموند
Name[ko]=
Name[lv]=Redmonda
Name[th]=
X-KDE-Library=kwin_redmond
X-KDE-Library=kwin3_redmond

View file

@ -3,12 +3,15 @@
*
* Redmond KWin client
*
* Copyright 2001
* Copyright 2001-2003
* Ported to kwin_iii by Chris Lee <clee@kde.org>
* Karol Szwed <gallium@kde.org>
* http://gallium.n3.net/
*
* Based on the default KWin client.
*
* Updated to support the new API 9/2003 (CL)
* Updated to emulate More Accurately 9/2003 (CL)
* Updated to support toolwindows 3/2001 (KS)
*
*/
@ -20,20 +23,22 @@
#include <qbutton.h>
#include <qbitmap.h>
#include <kpixmap.h>
#include "../../client.h"
#include "../../kwinbutton.h"
#include <kdecoration.h>
#include <kdecorationfactory.h>
class QLabel;
class QSpacerItem;
class QBoxLayout;
namespace Redmond {
using namespace KWinInternal;
class RedmondDeco;
class GalliumButton : public KWinButton
class RedmondButton : public QButton
{
Q_OBJECT
public:
GalliumButton(Client *parent=0, const char *name=0,
RedmondButton(RedmondDeco *parent=0, const char *name=0,
const unsigned char *bitmap=NULL,
bool menuButton=false, bool isMini=false,
const QString& tip=NULL);
@ -54,18 +59,18 @@ class GalliumButton : public KWinButton
QPixmap pix;
bool menuBtn;
bool miniBtn;
Client* client;
RedmondDeco *client;
};
class GalliumClient : public Client
class RedmondDeco : public KDecoration
{
Q_OBJECT
public:
GalliumClient( Workspace *ws, WId w, QWidget *parent=0,
const char *name=0 );
~GalliumClient() {;}
RedmondDeco(KDecorationBridge *, KDecorationFactory *);
~RedmondDeco() {;}
void init();
protected:
void resizeEvent(QResizeEvent*);
@ -78,24 +83,43 @@ class GalliumClient : public Client
void iconChange();
void calcHiddenButtons();
// New stuff.
MousePosition mousePosition(const QPoint &) const;
void borders(int &, int &, int &, int &) const;
void resize(const QSize &);
QSize minimumSize() const;
void activeChange();
void captionChange();
void maximizeChange();
void desktopChange();
void shadeChange();
bool eventFilter(QObject *, QEvent *);
protected slots:
void slotReset();
void slotMaximize();
void menuButtonPressed();
void menuButtonReleased();
private:
enum Buttons{ BtnHelp=0, BtnMax, BtnIconify, BtnClose,
BtnMenu, BtnCount };
enum Buttons{ BtnHelp=0, BtnMax, BtnMin, BtnClose, BtnMenu, BtnCount };
GalliumButton* button[ GalliumClient::BtnCount ];
RedmondButton* button[RedmondDeco::BtnCount];
int lastButtonWidth;
int titleHeight;
QSpacerItem* titlebar;
bool hiddenItems;
QBoxLayout* hb;
bool smallButtons;
bool closing;
};
class RedmondDecoFactory : public QObject, public KDecorationFactory
{
Q_OBJECT
public:
RedmondDecoFactory();
virtual ~RedmondDecoFactory();
virtual KDecoration *createDecoration(KDecorationBridge *);
virtual bool reset(unsigned long);
};
}