[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: RFC: [PATCH] Buttons for applet handles
From: John Firebaugh <jfirebaugh () kde ! org>
Date: 2001-07-06 15:25:03
[Download RAW message or body]
After reading the n-th bug report submitted by a user who could not figure
out how to remove applets from the panel, I did something about it. The
attached patch adds two small buttons on the outer edge of the applet
handle: an X button that removes the applet and a triangle button that
shows the applet menu. In tiny mode, these take up nearly the entire
handle, so I would probably vote for showing just the menu button. Any
thoughts? Should this go in?
later,
John
["applethandle.diff" (text/x-diff)]
Index: core/applethandle.cpp
===================================================================
RCS file: /home/kde/kdebase/kicker/core/applethandle.cpp,v
retrieving revision 1.2
diff -u -3 -p -r1.2 applethandle.cpp
--- core/applethandle.cpp 2001/06/07 04:14:25 1.2
+++ core/applethandle.cpp 2001/07/06 15:25:57
@@ -21,36 +21,194 @@ CONNECTION WITH THE SOFTWARE OR THE USE
******************************************************************/
+#include <qlayout.h>
#include <qpainter.h>
+#include <kpushbutton.h>
#include <kapp.h>
#include <kstyle.h>
+#include <kdebug.h>
+#include "container_applet.h"
+
#include "applethandle.h"
+static const char*close_xpm[]={
+"5 5 2 1",
+"# c black",
+". c None",
+"#...#",
+".#.#.",
+"..#..",
+".#.#.",
+"#...#"};
+
+static const char*up_xpm[]={
+"5 5 2 1",
+"# c black",
+". c None",
+".....",
+"..#..",
+".###.",
+"#####",
+"....."};
+
+static const char*down_xpm[]={
+"5 5 2 1",
+"# c black",
+". c None",
+".....",
+"#####",
+".###.",
+"..#..",
+"....."};
+
+static const char*left_xpm[]={
+"5 5 2 1",
+"# c black",
+". c None",
+"...#.",
+"..##.",
+".###.",
+"..##.",
+"...#."};
+
+static const char*right_xpm[]={
+"5 5 2 1",
+"# c black",
+". c None",
+".#...",
+".##..",
+".###.",
+".##..",
+".#..."};
+
+AppletHandle::AppletHandle(AppletContainer* parent, const char* name)
+ : QWidget(parent, name)
+ , _parent(parent)
+ , _fadeout_handle(false)
+ , _drawIt(false)
+{
+ QVBoxLayout* layout = new QVBoxLayout( this );
+
+ _container = new QWidget(this);
+ layout->addWidget( _container );
+
+ _layout = new QBoxLayout(_container, QBoxLayout::LeftToRight, 0, 0);
+
+ _drag = new AppletHandleDrag( _container );
+ _layout->addWidget( _drag );
+
+ _menuButton = new AppletHandleButton( _container );
+ _menuButton->setFixedSize( HandleSize, HandleSize );
+ _menuButton->setPixmap( up_xpm );
+ _layout->addWidget( _menuButton );
+
+ AppletHandleButton* removeButton = new AppletHandleButton( _container );
+ removeButton->setFixedSize( HandleSize, HandleSize );
+ removeButton->setPixmap( close_xpm );
+ _layout->addWidget( removeButton );
+
+ connect( _menuButton, SIGNAL(clicked()), this, SLOT(menuButtonClicked()) );
+ connect( removeButton, SIGNAL(clicked()), this, SIGNAL(removeApplet()) );
+ _drag->installEventFilter( this );
+
+ resetLayout();
+}
+
+void AppletHandle::resetLayout()
+{
+ switch( _parent->popupDirection() ) {
+ case dUp:
+ setFixedWidth(HandleSize);
+ setMaximumHeight(128);
+ _layout->setDirection( QBoxLayout::BottomToTop );
+ _menuButton->setPixmap( up_xpm );
+ break;
+ case dDown:
+ setFixedWidth(HandleSize);
+ setMaximumHeight(128);
+ _layout->setDirection( QBoxLayout::TopToBottom );
+ _menuButton->setPixmap( down_xpm );
+ break;
+ case dLeft:
+ setFixedHeight(HandleSize);
+ setMaximumWidth(128);
+ _layout->setDirection( QBoxLayout::RightToLeft );
+ _menuButton->setPixmap( left_xpm );
+ break;
+ case dRight:
+ setFixedHeight(HandleSize);
+ setMaximumWidth(128);
+ _layout->setDirection( QBoxLayout::LeftToRight );
+ _menuButton->setPixmap( right_xpm );
+ break;
+ }
+
+ if( _fadeout_handle && !_drawIt ) {
+ _container->hide();
+ } else {
+ _container->show();
+ }
+
+ _drag->setOrientation( _parent->orientation() );
+
+ _layout->activate();
+}
+
void AppletHandle::setFadeOutHandle(bool v)
{
_fadeout_handle = v;
- repaint();
+ resetLayout();
}
void AppletHandle::enterEvent(QEvent *)
{
_drawIt = true;
- repaint();
+ resetLayout();
}
void AppletHandle::leaveEvent(QEvent *)
{
_drawIt = false;
- repaint();
+ resetLayout();
}
-void AppletHandle::paintEvent(QPaintEvent *)
+bool AppletHandle::eventFilter (QObject *o, QEvent *e)
{
- if (!_drawIt && _fadeout_handle)
- return;
+ switch (e->type()) {
+ case QEvent::MouseButtonPress:
+ {
+ QMouseEvent* ev = (QMouseEvent*) e;
+ if ( ev->button() == RightButton ) {
+ emit showAppletMenu( mapFromGlobal( ev->globalPos() ) );
+ return true;
+ } else if ( ev->button() == MidButton
+ || ev->button() == LeftButton ) {
+ emit moveApplet( mapFromGlobal( ev->globalPos() ) );
+ }
+ return false;
+ }
+ default:
+ return QWidget::eventFilter(o, e); // standard event processing
+ }
+ return false;
+}
+void AppletHandle::menuButtonClicked()
+{
+ emit showAppletMenu( QPoint(0,0) );
+}
+
+AppletHandleDrag::AppletHandleDrag(QWidget* parent, const char* name)
+ : QWidget( parent, name )
+{
+ setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
+}
+
+
+void AppletHandleDrag::paintEvent(QPaintEvent *)
+{
QPainter p;
p.begin(this);
@@ -95,6 +253,55 @@ void AppletHandle::paintEvent(QPaintEven
}
p.end();
+}
+
+AppletHandleButton::AppletHandleButton( QWidget *parent, const char * name )
+:QPushButton( parent, name )
+{
+ moveMouse = false;
+ setFocusPolicy( NoFocus );
+}
+
+AppletHandleButton::~AppletHandleButton()
+{
+}
+
+void AppletHandleButton::drawButton( QPainter* p )
+{
+ p->fillRect( 0,0, width(), height(), QBrush(colorGroup().brush(QColorGroup::Background)) );
+ p->drawPixmap( (width() - pixmap()->width()) / 2, (height() - pixmap()->height()) / 2, *pixmap() );
+ if ( moveMouse && !isDown() ){
+ p->setPen( white );
+ p->moveTo( 0, height() - 1 );
+ p->lineTo( 0, 0 );
+ p->lineTo( width() - 1, 0 );
+
+ p->setPen( colorGroup().dark() );
+ p->lineTo( width() - 1, height() - 1 );
+ p->lineTo( 0, height() - 1 );
+ }
+ if ( isOn() || isDown() ){
+ p->setPen( colorGroup().dark() );
+ p->moveTo( 0, height() - 1 );
+ p->lineTo( 0, 0 );
+ p->lineTo( width() - 1, 0 );
+
+ p->setPen( white );
+ p->lineTo( width() - 1, height() - 1 );
+ p->lineTo( 0, height() - 1 );
+ }
+}
+
+void AppletHandleButton::enterEvent( QEvent * )
+{
+ moveMouse = true;
+ repaint();
+}
+
+void AppletHandleButton::leaveEvent( QEvent * )
+{
+ moveMouse = false;
+ repaint();
}
#include "applethandle.moc"
Index: core/applethandle.h
===================================================================
RCS file: /home/kde/kdebase/kicker/core/applethandle.h,v
retrieving revision 1.2
diff -u -3 -p -r1.2 applethandle.h
--- core/applethandle.h 2001/06/07 04:14:25 1.2
+++ core/applethandle.h 2001/07/06 15:25:57
@@ -25,27 +25,78 @@ CONNECTION WITH THE SOFTWARE OR THE USE
#define __applethandle_h__
#include <qwidget.h>
+#include <qpushbutton.h>
+class AppletContainer;
+class QBoxLayout;
+class AppletHandleDrag;
+class AppletHandleButton;
+
class AppletHandle : public QWidget
{
Q_OBJECT
public:
- AppletHandle(QWidget* parent = 0, const char* name = 0)
- : QWidget(parent, name)
- , _drawIt(false)
- , _fadeout_handle(false) {}
+ static const int HandleSize = 9;
+
+ AppletHandle(AppletContainer* parent, const char* name = 0);
- void setOrientation(Orientation o) { _orient = o; }
+ void resetLayout();
void setFadeOutHandle(bool);
+ bool eventFilter (QObject *, QEvent *);
+
+ signals:
+ void moveApplet( QPoint moveOffset );
+ void removeApplet();
+ void showAppletMenu( QPoint pos );
+
protected:
void enterEvent(QEvent *);
void leaveEvent(QEvent *);
+
+ protected slots:
+ void menuButtonClicked();
+
+ private:
+ AppletContainer* _parent;
+ QWidget* _container;
+ QBoxLayout* _layout;
+ AppletHandleDrag* _drag;
+ AppletHandleButton* _menuButton;
+ bool _fadeout_handle;
+ bool _drawIt;
+};
+
+class AppletHandleDrag : public QWidget
+{
+ Q_OBJECT
+ public:
+ AppletHandleDrag(QWidget* parent = 0, const char* name = 0);
+
+ void setOrientation( Orientation o ) { _orient = o; };
+
+ protected:
void paintEvent(QPaintEvent *);
+
+ private:
Orientation _orient;
- bool _drawIt;
- bool _fadeout_handle;
+
};
-#endif
+class AppletHandleButton : public QPushButton
+{
+ Q_OBJECT
+public:
+ AppletHandleButton( QWidget *parent=0, const char *name=0 );
+ ~AppletHandleButton();
+
+protected:
+ virtual void drawButton( QPainter * );
+ virtual void enterEvent( QEvent * );
+ virtual void leaveEvent( QEvent * );
+private:
+ bool moveMouse;
+};
+
+#endif
Index: core/container_applet.cpp
===================================================================
RCS file: /home/kde/kdebase/kicker/core/container_applet.cpp,v
retrieving revision 1.15
diff -u -3 -p -r1.15 container_applet.cpp
--- core/container_applet.cpp 2001/04/20 10:17:30 1.15
+++ core/container_applet.cpp 2001/07/06 15:25:57
@@ -47,8 +47,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE
#include "container_applet.h"
#include "container_applet.moc"
-#define HANDLE_SIZE 7
-
AppletContainer::AppletContainer(const AppletInfo& info, QWidget* parent )
: BaseContainer(parent)
, _info(info)
@@ -59,8 +57,10 @@ AppletContainer::AppletContainer(const A
{
// setup handle
_handle = new AppletHandle(this);
- _handle->installEventFilter(this);
- _handle->setOrientation(orientation());
+
+ connect( _handle, SIGNAL(moveApplet(QPoint)), this, SLOT(moveApplet(QPoint)) );
+ connect( _handle, SIGNAL(removeApplet()), this, SLOT(removeApplet()) );
+ connect( _handle, SIGNAL(showAppletMenu(QPoint)), this, SLOT(showAppletMenu(QPoint)) );
//setup appletframe
_appletframe = new QHBox(this);
@@ -69,21 +69,17 @@ AppletContainer::AppletContainer(const A
if (orientation() == Horizontal)
{
- _handle->setFixedWidth(HANDLE_SIZE);
- _handle->setMaximumHeight(128);
_layout = new QBoxLayout(this, QBoxLayout::LeftToRight, 0, 0);
}
else
{
- _handle->setFixedHeight(HANDLE_SIZE);
- _handle->setMaximumWidth(128);
_layout = new QBoxLayout(this, QBoxLayout::TopToBottom, 0, 0);
}
_layout->setResizeMode( QLayout::FreeResize );
_layout->addWidget(_handle);
- _layout->addWidget(_appletframe);
+ _layout->addWidget(_appletframe, 1);
_layout->activate();
}
@@ -94,77 +90,61 @@ void AppletContainer::configure()
_handle->setFadeOutHandle(config->readBoolEntry("FadeOutAppletHandles", false));
}
-bool AppletContainer::eventFilter (QObject *o, QEvent *e)
-{
- switch (e->type())
- {
- case QEvent::MouseButtonPress:
- {
- QMouseEvent* ev = (QMouseEvent*) e;
- if ( ev->button() == RightButton )
- {
- if (!_opMnu)
- _opMnu = new PanelAppletOpMenu(_actions, _info.name(), _info.icon());
-
- switch(_opMnu->exec(getPopupPosition(_opMnu, ev->pos())))
- {
- case PanelAppletOpMenu::Move:
- _moveOffset = QPoint(_handle->width()/2, _handle->height()/2);
- emit moveme(this);
- break;
- case PanelAppletOpMenu::Remove:
- emit removeme(this);
- break;
- case PanelAppletOpMenu::Help:
- help();
- break;
- case PanelAppletOpMenu::About:
- about();
- break;
- case PanelAppletOpMenu::Preferences:
- preferences();
- break;
- case PanelAppletOpMenu::ReportBug:
- reportBug();
- break;
- default:
- break;
- }
- return true;
- }
- else if ( ev->button() == MidButton
- || ev->button() == LeftButton )
- {
- _moveOffset = ev->pos();
- emit moveme(this);
- }
- return false;
- }
- default:
- return QWidget::eventFilter(o, e); // standard event processing
- }
- return false;
-}
-
void AppletContainer::resetLayout()
{
- _handle->setOrientation(orientation());
+ _handle->resetLayout();
if (orientation() == Horizontal)
{
_layout->setDirection(QBoxLayout::LeftToRight);
- _handle->setFixedWidth(HANDLE_SIZE);
- _handle->setMaximumHeight(128);
}
else
{
_layout->setDirection(QBoxLayout::TopToBottom);
- _handle->setFixedHeight(HANDLE_SIZE);
- _handle->setMaximumWidth(128);
}
_layout->activate();
}
+void AppletContainer::moveApplet( QPoint moveOffset )
+{
+ _moveOffset = moveOffset;
+ emit moveme(this);
+}
+
+void AppletContainer::removeApplet()
+{
+ emit removeme(this);
+}
+
+void AppletContainer::showAppletMenu( QPoint pos )
+{
+ if (!_opMnu)
+ _opMnu = new PanelAppletOpMenu(_actions, _info.name(), _info.icon());
+
+ switch(_opMnu->exec(getPopupPosition(_opMnu, pos))) {
+ case PanelAppletOpMenu::Move:
+ moveApplet( QPoint(_handle->width()/2, _handle->height()/2) );
+ break;
+ case PanelAppletOpMenu::Remove:
+ emit removeme(this);
+ break;
+ case PanelAppletOpMenu::Help:
+ help();
+ break;
+ case PanelAppletOpMenu::About:
+ about();
+ break;
+ case PanelAppletOpMenu::Preferences:
+ preferences();
+ break;
+ case PanelAppletOpMenu::ReportBug:
+ reportBug();
+ break;
+ default:
+ break;
+ }
+}
+
void AppletContainer::removeSessionConfigFile()
{
if (_configFile.isEmpty()) return;
@@ -240,22 +220,22 @@ int InternalAppletContainer::widthForHei
{
if (!_applet) {
if (_widthForHeightHint > 0)
- return _widthForHeightHint + HANDLE_SIZE;
+ return _widthForHeightHint + AppletHandle::HandleSize;
else
- return h + HANDLE_SIZE;
+ return h + AppletHandle::HandleSize;
}
- return _applet->widthForHeight(h) + HANDLE_SIZE;
+ return _applet->widthForHeight(h) + AppletHandle::HandleSize;
}
int InternalAppletContainer::heightForWidth(int w)
{
if (!_applet) {
if (_heightForWidthHint > 0)
- return _heightForWidthHint + HANDLE_SIZE;
+ return _heightForWidthHint + AppletHandle::HandleSize;
else
- return w + HANDLE_SIZE;
+ return w + AppletHandle::HandleSize;
}
- return _applet->heightForWidth(w) + HANDLE_SIZE;
+ return _applet->heightForWidth(w) + AppletHandle::HandleSize;
}
void InternalAppletContainer::about()
@@ -407,7 +387,7 @@ int ExternalAppletContainer::widthForHei
QDataStream reply( replyData, IO_ReadOnly );
reply >> w;
}
- return w + HANDLE_SIZE;
+ return w + AppletHandle::HandleSize;
}
int ExternalAppletContainer::heightForWidth(int w)
@@ -431,7 +411,7 @@ int ExternalAppletContainer::heightForWi
QDataStream reply( replyData, IO_ReadOnly );
reply >> h;
}
- return h + HANDLE_SIZE;
+ return h + AppletHandle::HandleSize;
}
bool ExternalAppletContainer::process(const QCString &fun, const QByteArray &data,
Index: core/container_applet.h
===================================================================
RCS file: /home/kde/kdebase/kicker/core/container_applet.h,v
retrieving revision 1.7
diff -u -3 -p -r1.7 container_applet.h
--- core/container_applet.h 2001/02/04 12:57:30 1.7
+++ core/container_applet.h 2001/07/06 15:25:57
@@ -44,8 +44,6 @@ class AppletContainer : public BaseConta
public:
AppletContainer(const AppletInfo& info, QWidget* parent = 0);
- bool eventFilter (QObject *, QEvent *);
-
KPanelApplet::Type type() const { return _type; }
const AppletInfo& info() const { return _info; }
@@ -61,6 +59,9 @@ signals:
void updateLayout();
public slots:
+ void moveApplet( QPoint moveOffset );
+ void removeApplet();
+ void showAppletMenu( QPoint pos );
void activateWindow() { setActiveWindow(); }
protected:
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic