Add delay before showing window menu

The window menu is shown after a strong click on the menu button.
This makes close by double click on menu button working correctly.
A single (strong) click will open the window menu, a double click
will close the menu. A  triple click is no longer required.

REVIEW: 103995
BUG: 157184
FIXED-IN: 4.9.0
remotes/origin/Plasma/5.0
Martin Gräßlin 14 years ago
parent ac868aff98
commit 095a00b912
  1. 66
      libkdecorations/kcommondecoration.cpp
  2. 4
      libkdecorations/kcommondecoration.h

@ -26,6 +26,7 @@
#include "kcommondecoration_p.h" #include "kcommondecoration_p.h"
#include <QApplication> #include <QApplication>
#include <QBasicTimer>
#include <QCursor> #include <QCursor>
#include <QDateTime> #include <QDateTime>
#include <QLabel> #include <QLabel>
@ -693,32 +694,67 @@ void KCommonDecoration::slotKeepBelow()
setKeepBelow(!keepBelow()); setKeepBelow(!keepBelow());
} }
static QBasicTimer* timer = NULL;
void KCommonDecoration::menuButtonPressed() void KCommonDecoration::menuButtonPressed()
{ {
static QTime* t = NULL; if (decorationBehaviour(DB_MenuClose)) {
static KCommonDecoration* lastClient = NULL; if (timer == NULL) {
if (t == NULL) timer = new QBasicTimer();
t = new QTime; }
bool dbl = (lastClient == this && t->elapsed() <= QApplication::doubleClickInterval()); if (!timer->isActive()) {
lastClient = this; timer->start(150, this);
t->start(); }
if (!dbl || !decorationBehaviour(DB_MenuClose)) { // double click behavior
QRect menuRect = m_button[MenuButton]->rect(); static QTime* t = NULL;
QPoint menutop = m_button[MenuButton]->mapToGlobal(menuRect.topLeft()); static KCommonDecoration* lastClient = NULL;
QPoint menubottom = m_button[MenuButton]->mapToGlobal(menuRect.bottomRight()) + QPoint(0, 2); if (t == NULL) {
t = new QTime;
}
if (lastClient == this && t->elapsed() <= QApplication::doubleClickInterval()) {
closing = true;
} else {
lastClient = this;
t->start();
}
} else {
KDecorationFactory* f = factory(); KDecorationFactory* f = factory();
showWindowMenu(QRect(menutop, menubottom)); doShowWindowMenu();
if (!f->exists(decoration())) // 'this' was deleted if (!f->exists(decoration())) // 'this' was deleted
return; return;
m_button[MenuButton]->setDown(false); m_button[MenuButton]->setDown(false);
} else }
closing = true;
} }
void KCommonDecoration::menuButtonReleased() void KCommonDecoration::menuButtonReleased()
{ {
if (closing) if (closing) {
if (timer && timer->isActive()) {
timer->stop();
}
closeWindow(); closeWindow();
}
}
void KCommonDecoration::timerEvent(QTimerEvent *event)
{
if (timer && event->timerId() == timer->timerId()) {
timer->stop();
closing = false;
if (!m_button[MenuButton]->isDown()) {
return;
}
doShowWindowMenu();
return;
}
QObject::timerEvent(event);
}
void KCommonDecoration::doShowWindowMenu()
{
QRect menuRect = m_button[MenuButton]->rect();
QPoint menutop = m_button[MenuButton]->mapToGlobal(menuRect.topLeft());
QPoint menubottom = m_button[MenuButton]->mapToGlobal(menuRect.bottomRight()) + QPoint(0, 2);
showWindowMenu(QRect(menutop, menubottom));
} }
void KCommonDecoration::resizeEvent(QResizeEvent */*e*/) void KCommonDecoration::resizeEvent(QResizeEvent */*e*/)

@ -352,6 +352,9 @@ public:
const KDecoration* decoration() const; const KDecoration* decoration() const;
KDecoration* decoration(); KDecoration* decoration();
protected:
virtual void timerEvent(QTimerEvent *event);
private Q_SLOTS: private Q_SLOTS:
/* look out for buttons that have been destroyed. */ /* look out for buttons that have been destroyed. */
void objDestroyed(QObject *obj); void objDestroyed(QObject *obj);
@ -361,6 +364,7 @@ private:
void moveWidget(int x, int y, QWidget *widget) const; void moveWidget(int x, int y, QWidget *widget) const;
void resizeWidget(int w, int h, QWidget *widget) const; void resizeWidget(int w, int h, QWidget *widget) const;
void doShowWindowMenu();
typedef QVector <KCommonDecorationButton*> ButtonContainer; ///< If the entry is 0, it's a spacer. typedef QVector <KCommonDecorationButton*> ButtonContainer; ///< If the entry is 0, it's a spacer.
int buttonContainerWidth(const ButtonContainer &btnContainer, bool countHidden = false) const; int buttonContainerWidth(const ButtonContainer &btnContainer, bool countHidden = false) const;

Loading…
Cancel
Save