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 <QApplication>
#include <QBasicTimer>
#include <QCursor>
#include <QDateTime>
#include <QLabel>
@ -693,32 +694,67 @@ void KCommonDecoration::slotKeepBelow()
setKeepBelow(!keepBelow());
}
static QBasicTimer* timer = NULL;
void KCommonDecoration::menuButtonPressed()
{
static QTime* t = NULL;
static KCommonDecoration* lastClient = NULL;
if (t == NULL)
t = new QTime;
bool dbl = (lastClient == this && t->elapsed() <= QApplication::doubleClickInterval());
lastClient = this;
t->start();
if (!dbl || !decorationBehaviour(DB_MenuClose)) {
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);
if (decorationBehaviour(DB_MenuClose)) {
if (timer == NULL) {
timer = new QBasicTimer();
}
if (!timer->isActive()) {
timer->start(150, this);
}
// double click behavior
static QTime* t = NULL;
static KCommonDecoration* lastClient = NULL;
if (t == NULL) {
t = new QTime;
}
if (lastClient == this && t->elapsed() <= QApplication::doubleClickInterval()) {
closing = true;
} else {
lastClient = this;
t->start();
}
} else {
KDecorationFactory* f = factory();
showWindowMenu(QRect(menutop, menubottom));
doShowWindowMenu();
if (!f->exists(decoration())) // 'this' was deleted
return;
m_button[MenuButton]->setDown(false);
} else
closing = true;
}
}
void KCommonDecoration::menuButtonReleased()
{
if (closing)
if (closing) {
if (timer && timer->isActive()) {
timer->stop();
}
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*/)

@ -352,6 +352,9 @@ public:
const KDecoration* decoration() const;
KDecoration* decoration();
protected:
virtual void timerEvent(QTimerEvent *event);
private Q_SLOTS:
/* look out for buttons that have been destroyed. */
void objDestroyed(QObject *obj);
@ -361,6 +364,7 @@ private:
void moveWidget(int x, int y, 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.
int buttonContainerWidth(const ButtonContainer &btnContainer, bool countHidden = false) const;

Loading…
Cancel
Save