diff options
author | Thorbjørn Martsum <tmartsum@gmail.com> | 2013-07-01 07:10:48 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-07-03 05:34:34 +0200 |
commit | 29570d8442cce4bd2756ba4949afecbf50d4368e (patch) | |
tree | b8dabe3034c190fb61cb5781cbc809b2385dfc5e /tests/manual/widgets/kernel | |
parent | ee79d942714d28d517bd0f1f48d66b65d2026626 (diff) |
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>
Diffstat (limited to 'tests/manual/widgets/kernel')
-rw-r--r-- | tests/manual/widgets/kernel/qtooltip/main.cpp | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/tests/manual/widgets/kernel/qtooltip/main.cpp b/tests/manual/widgets/kernel/qtooltip/main.cpp index d0f0db8ff5..a7a2b9915c 100644 --- a/tests/manual/widgets/kernel/qtooltip/main.cpp +++ b/tests/manual/widgets/kernel/qtooltip/main.cpp @@ -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(); } |