QStyle - tooltip - add wakeDelay and sleepDelay as styleHints
In earlier patches we allowed the user to control the tooltip duration. However the user still couldn't control the wake delay and sleep delay. This patch changes that and is the final patch in solving: Task-number: QTBUG-1016 Change-Id: I5e2c719737634ad7f371ad03691744612472ae70 Reviewed-by: J-P Nurmi <jpnurmi@digia.com> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
This commit is contained in:
parent
ee79d94271
commit
29570d8442
@ -1852,8 +1852,11 @@ bool QApplication::event(QEvent *e)
|
||||
if (showToolTip) {
|
||||
QHelpEvent e(QEvent::ToolTip, d->toolTipPos, d->toolTipGlobalPos);
|
||||
QApplication::sendEvent(d->toolTipWidget, &e);
|
||||
if (e.isAccepted())
|
||||
d->toolTipFallAsleep.start(2000, this);
|
||||
if (e.isAccepted()) {
|
||||
QStyle *s = d->toolTipWidget->style();
|
||||
int sleepDelay = s->styleHint(QStyle::SH_ToolTip_FallAsleepDelay, 0, d->toolTipWidget, 0);
|
||||
d->toolTipFallAsleep.start(sleepDelay, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (te->timerId() == d->toolTipFallAsleep.timerId()) {
|
||||
@ -2956,7 +2959,9 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
|
||||
d->toolTipWidget = w;
|
||||
d->toolTipPos = relpos;
|
||||
d->toolTipGlobalPos = mouse->globalPos();
|
||||
d->toolTipWakeUp.start(d->toolTipFallAsleep.isActive()?20:700, this);
|
||||
QStyle *s = d->toolTipWidget->style();
|
||||
int wakeDelay = s->styleHint(QStyle::SH_ToolTip_WakeUpDelay, 0, d->toolTipWidget, 0);
|
||||
d->toolTipWakeUp.start(d->toolTipFallAsleep.isActive() ? 20 : wakeDelay, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5105,6 +5105,14 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget
|
||||
case SH_Menu_SupportsSections:
|
||||
ret = false;
|
||||
break;
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
case SH_ToolTip_WakeUpDelay:
|
||||
ret = 700;
|
||||
break;
|
||||
case SH_ToolTip_FallAsleepDelay:
|
||||
ret = 2000;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ret = 0;
|
||||
break;
|
||||
|
@ -1894,6 +1894,12 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
|
||||
\value SH_Menu_SupportsSections Determines if the style displays sections in menus or treat them as
|
||||
plain separators. Sections are separators with a text and icon hint.
|
||||
|
||||
\value SH_ToolTip_WakeUpDelay Determines the delay before a tooltip is shown, in milliseconds.
|
||||
|
||||
\value SH_ToolTip_FallAsleepDelay Determines the delay (in milliseconds) before a new wake time is needed when
|
||||
a tooltip is shown (notice: shown, not hidden). When a new wake isn't needed, a user-requested tooltip
|
||||
will be shown nearly instantly.
|
||||
|
||||
\sa styleHint()
|
||||
*/
|
||||
|
||||
|
@ -698,6 +698,8 @@ public:
|
||||
SH_RequestSoftwareInputPanel,
|
||||
SH_ScrollBar_Transient,
|
||||
SH_Menu_SupportsSections,
|
||||
SH_ToolTip_WakeUpDelay,
|
||||
SH_ToolTip_FallAsleepDelay,
|
||||
// Add new style hint values here
|
||||
|
||||
SH_CustomBase = 0xf0000000
|
||||
|
@ -45,12 +45,46 @@
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
#include <QProxyStyle>
|
||||
#include <QSpinBox>
|
||||
|
||||
class QToolTipTest : public QProxyStyle
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QToolTipTest() : QProxyStyle()
|
||||
{
|
||||
wakeTime = QApplication::style()->styleHint(SH_ToolTip_WakeUpDelay);
|
||||
sleepTime = QApplication::style()->styleHint(SH_ToolTip_FallAsleepDelay);
|
||||
}
|
||||
|
||||
int styleHint(StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0,
|
||||
QStyleHintReturn *returnData = 0) const
|
||||
{
|
||||
switch (hint) {
|
||||
case SH_ToolTip_WakeUpDelay:
|
||||
return wakeTime;
|
||||
case SH_ToolTip_FallAsleepDelay:
|
||||
return sleepTime;
|
||||
default:
|
||||
return QProxyStyle::styleHint(hint, option, widget, returnData);
|
||||
}
|
||||
}
|
||||
|
||||
public slots:
|
||||
void setWakeTime(int wake) { wakeTime = wake; }
|
||||
void setSleepTime(int sleep) { sleepTime = sleep; }
|
||||
protected:
|
||||
int wakeTime;
|
||||
int sleepTime;
|
||||
};
|
||||
|
||||
class TestDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TestDialog();
|
||||
TestDialog(QToolTipTest *s);
|
||||
QToolTipTest *style;
|
||||
protected slots:
|
||||
void showSomeToolTips();
|
||||
};
|
||||
@ -72,7 +106,7 @@ void TestDialog::showSomeToolTips()
|
||||
QTest::qWait(12000);
|
||||
}
|
||||
|
||||
TestDialog::TestDialog()
|
||||
TestDialog::TestDialog(QToolTipTest *s) : style(s)
|
||||
{
|
||||
// Notice that these tool tips will disappear if another tool tip is shown.
|
||||
QLabel *label1 = new QLabel(tr("Tooltip - Only two seconds display"));
|
||||
@ -89,10 +123,27 @@ TestDialog::TestDialog()
|
||||
Q_ASSERT(pb->toolTipDuration() == -1);
|
||||
connect(pb, SIGNAL(clicked()), this, SLOT(showSomeToolTips()));
|
||||
|
||||
QLabel *wakeLabel = new QLabel(tr("Wake Delay:"));
|
||||
QSpinBox *wakeSpinBox = new QSpinBox();
|
||||
wakeSpinBox->setRange(0, 100000);
|
||||
wakeSpinBox->setValue(style->styleHint(QStyle::SH_ToolTip_WakeUpDelay));
|
||||
connect(wakeSpinBox, SIGNAL(valueChanged(int)), style, SLOT(setWakeTime(int)));
|
||||
|
||||
QLabel *sleepLabel = new QLabel(tr("Sleep Delay:"));
|
||||
QSpinBox *sleepSpinBox = new QSpinBox();
|
||||
sleepSpinBox->setRange(0, 100000);
|
||||
sleepSpinBox->setValue(style->styleHint(QStyle::SH_ToolTip_FallAsleepDelay));
|
||||
connect(sleepSpinBox, SIGNAL(valueChanged(int)), style, SLOT(setSleepTime(int)));
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
layout->addWidget(label1);
|
||||
layout->addWidget(label2);
|
||||
layout->addWidget(pb);
|
||||
layout->addWidget(wakeLabel);
|
||||
layout->addWidget(wakeSpinBox);
|
||||
layout->addWidget(wakeLabel);
|
||||
layout->addWidget(sleepLabel);
|
||||
layout->addWidget(sleepSpinBox);
|
||||
|
||||
setLayout(layout);
|
||||
}
|
||||
@ -100,7 +151,9 @@ TestDialog::TestDialog()
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
TestDialog dlg;
|
||||
QToolTipTest *style = new QToolTipTest();
|
||||
QApplication::setStyle(style);
|
||||
TestDialog dlg(style);
|
||||
dlg.show();
|
||||
return app.exec();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user