From 8f36a1cb5ccbb0425f42291fdbd1c5870be9ccd1 Mon Sep 17 00:00:00 2001 From: Waldo Bastian Date: Thu, 26 Oct 2000 21:56:18 +0000 Subject: [PATCH] WABA: Fixed "maximize" with MMB and RMB. Based on a patch Boudewijn Rempt svn path=/trunk/kdebase/kwin/; revision=69005 --- clients/b2/b2client.cpp | 31 +++++++++++++++++++++++++++- clients/b2/b2client.h | 11 ++++++++++ clients/modernsystem/modernsys.cpp | 33 +++++++++++++++++++++++++++++- clients/modernsystem/modernsys.h | 7 +++++++ 4 files changed, 80 insertions(+), 2 deletions(-) diff --git a/clients/b2/b2client.cpp b/clients/b2/b2client.cpp index 30f1a7e4d6..0571118dc9 100644 --- a/clients/b2/b2client.cpp +++ b/clients/b2/b2client.cpp @@ -237,6 +237,19 @@ void B2Button::setPixmaps(KPixmap *pix, KPixmap *pixDown, KPixmap *iPix, repaint(false); } +void B2Button::mousePressEvent( QMouseEvent* e ) +{ + last_button = e->button(); + QMouseEvent me ( e->type(), e->pos(), e->globalPos(), LeftButton, e->state() ); + QButton::mousePressEvent( &me ); +} + +void B2Button::mouseReleaseEvent( QMouseEvent* e ) +{ + QMouseEvent me ( e->type(), e->pos(), e->globalPos(), LeftButton, e->state() ); + QButton::mouseReleaseEvent( &me ); +} + B2Titlebar::B2Titlebar(B2Client *parent) : QWidget(parent) { @@ -399,6 +412,21 @@ void B2Titlebar::mouseMoveEvent( QMouseEvent * e ) } } +void B2Client::maxButtonClicked( ) +{ + switch ( button[BtnMax]->last_button ) { + case MidButton: + maximize( MaximizeVertical ); + break; + case RightButton: + maximize( MaximizeHorizontal ); + break; + default: //LeftButton: + maximize( MaximizeFull ); + break; + } +} + B2Client::B2Client( Workspace *ws, WId w, QWidget *parent, const char *name ) : Client( ws, w, parent, name, WResizeNoErase ) @@ -482,13 +510,14 @@ B2Client::B2Client( Workspace *ws, WId w, QWidget *parent, connect(button[BtnMenu], SIGNAL(clicked()), this, SLOT(menuButtonPressed())); connect(button[BtnSticky], SIGNAL(clicked()), this, SLOT(toggleSticky())); connect(button[BtnIconify], SIGNAL(clicked()), this, SLOT(iconify())); - connect(button[BtnMax], SIGNAL(clicked()), this, SLOT(maximize())); + connect(button[BtnMax], SIGNAL( clicked() ), this, SLOT( maxButtonClicked())); connect(button[BtnClose], SIGNAL(clicked()), this, SLOT(closeWindow())); connect(button[BtnHelp], SIGNAL(clicked()), this, SLOT(contextHelp())); connect(options, SIGNAL(resetClients()), this, SLOT(slotReset())); } + void B2Client::resizeEvent( QResizeEvent* e) { Client::resizeEvent( e ); diff --git a/clients/b2/b2client.h b/clients/b2/b2client.h index d1659e0881..05e31f233a 100644 --- a/clients/b2/b2client.h +++ b/clients/b2/b2client.h @@ -12,6 +12,7 @@ class QGridLayout; class B2Button : public QButton { + Q_OBJECT public: B2Button(Client *_client=0, QWidget *parent=0, const char *name=0) : QButton(parent, name){useMiniIcon = false; client = _client;} @@ -28,13 +29,21 @@ public: protected: virtual void drawButton(QPainter *p); void drawButtonLabel(QPainter *){;} + bool useMiniIcon; KPixmap *pNorm, *pDown, *iNorm, *iDown; QColor bg; //only use one color (the rest is pixmap) so forget QPalette ;) Client *client; + + void mousePressEvent( QMouseEvent* e ); + void mouseReleaseEvent( QMouseEvent* e ); + +public: + int last_button; }; class B2Client; + class B2Titlebar : public QWidget { Q_OBJECT @@ -87,6 +96,7 @@ protected: private slots: void menuButtonPressed(); void slotReset(); + void maxButtonClicked(); private: void positionButtons(); enum ButtonType{BtnMenu=0, BtnSticky, BtnIconify, BtnMax, BtnClose, @@ -99,6 +109,7 @@ private: int bar_x_ofs; B2Titlebar *titlebar; int in_unobs; + }; diff --git a/clients/modernsystem/modernsys.cpp b/clients/modernsystem/modernsys.cpp index 9998fad075..9c7f4750ff 100644 --- a/clients/modernsystem/modernsys.cpp +++ b/clients/modernsystem/modernsys.cpp @@ -202,6 +202,20 @@ void ModernButton::drawButton(QPainter *p) } } +void ModernButton::mousePressEvent( QMouseEvent* e ) +{ + last_button = e->button(); + QMouseEvent me ( e->type(), e->pos(), e->globalPos(), LeftButton, e->state() ); + QButton::mousePressEvent( &me ); +} + +void ModernButton::mouseReleaseEvent( QMouseEvent* e ) +{ + QMouseEvent me ( e->type(), e->pos(), e->globalPos(), LeftButton, e->state() ); + QButton::mouseReleaseEvent( &me ); +} + + void ModernSys::slotReset() { if(aUpperGradient){ @@ -262,7 +276,7 @@ ModernSys::ModernSys( Workspace *ws, WId w, QWidget *parent, connect( button[0], SIGNAL( clicked() ), this, ( SLOT( closeWindow() ) ) ); connect( button[1], SIGNAL( clicked() ), this, ( SLOT( toggleSticky() ) ) ); connect( button[2], SIGNAL( clicked() ), this, ( SLOT( iconify() ) ) ); - connect( button[3], SIGNAL( clicked() ), this, ( SLOT( maximize() ) ) ); + connect( button[3], SIGNAL( clicked() ), this, ( SLOT( maxButtonClicked() ) ) ); QHBoxLayout* hb = new QHBoxLayout(0); hb->setResizeMode(QLayout::FreeResize); @@ -290,6 +304,23 @@ ModernSys::ModernSys( Workspace *ws, WId w, QWidget *parent, } +void ModernSys::maxButtonClicked( ) +{ + switch ( button[3]->last_button ) { + case MidButton: + maximize( MaximizeVertical ); + break; + case RightButton: + maximize( MaximizeHorizontal ); + break; + default: //LeftButton: + maximize( MaximizeFull ); + break; + } +} + + + void ModernSys::resizeEvent( QResizeEvent* ) { //Client::resizeEvent( e ); diff --git a/clients/modernsystem/modernsys.h b/clients/modernsystem/modernsys.h index 04c4d6b463..589b655ea1 100644 --- a/clients/modernsystem/modernsys.h +++ b/clients/modernsystem/modernsys.h @@ -12,6 +12,7 @@ class QSpacerItem; // get rid of autohide :P class ModernButton : public QButton { + Q_OBJECT public: ModernButton(Client *parent=0, const char *name=0, const unsigned char *bitmap=NULL); @@ -19,10 +20,15 @@ public: void reset(); QSize sizeHint() const; protected: + void mousePressEvent( QMouseEvent* e ); + void mouseReleaseEvent( QMouseEvent* e ); + virtual void drawButton(QPainter *p); void drawButtonLabel(QPainter *){;} QBitmap deco; Client *client; +public: + int last_button; }; class ModernSys : public Client @@ -48,6 +54,7 @@ protected: MousePosition mousePosition( const QPoint& ) const; protected slots: void slotReset(); + void maxButtonClicked(); private: ModernButton* button[5]; QSpacerItem* titlebar;