summaryrefslogtreecommitdiff
path: root/gui/jumpwidget.cpp
blob: 8c9ca337c1b9bf550e8281c466c2838a5b216cb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "jumpwidget.h"

#include <QDebug>
#include <QKeyEvent>

JumpWidget::JumpWidget(QWidget *parent )
    : QWidget(parent)
{
    m_ui.setupUi(this);

    connect(m_ui.jumpButton, SIGNAL(clicked()),
            SLOT(slotJump()));
    connect(m_ui.spinBox, SIGNAL(editingFinished()),
            SLOT(slotJump()));
    connect(m_ui.cancelButton, SIGNAL(clicked()),
            SLOT(slotCancel()));

    installEventFilter(this);
}

void JumpWidget::slotJump()
{
    if (isVisible()) {
        emit jumpTo(m_ui.spinBox->value());
    }
    hide();
}

void JumpWidget::slotCancel()
{
    hide();
}

void JumpWidget::showEvent(QShowEvent *event)
{
    m_ui.spinBox->setFocus(Qt::ShortcutFocusReason);
    return QWidget::showEvent(event);
}

bool JumpWidget::eventFilter(QObject *object, QEvent* event)
{
    if (event->type() == QEvent::KeyPress) {
        if ((static_cast<QKeyEvent*>(event))->key() == Qt::Key_Escape) {
            hide();
        }
    }
    return QWidget::eventFilter(object, event);
}

#include "jumpwidget.moc"