aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/completer/completerview.cpp
blob: c154b1484b4caa75b3a8abc4582fe041f5a427aa (plain) (blame)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "completerview.h"
#include "completeritemdelegate.h"
#include <QMouseEvent>

CompleterView::CompleterView(QWidget *parent) :
    QListView(parent)
{
    setItemDelegate(new CompleterItemDelegate(this));
}

void CompleterView::selectFirstVisible()
{
    QModelIndex idx;
    for (int i = 0; i < model()->rowCount(); i++)
    {
        if (isRowHidden(i))
            continue;

        idx = model()->index(i, 0, QModelIndex());
        selectionModel()->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect);
        break;
    }
}

bool CompleterView::hasVisibleItem() const
{
    return countVisibleItem() > 0;
}

int CompleterView::countVisibleItem() const
{
    int cnt = 0;
    for (int i = 0; i < model()->rowCount(); i++)
    {
        if (!isRowHidden(i))
            cnt++;
    }
    return cnt;
}

void CompleterView::focusOutEvent(QFocusEvent* e)
{
    emit focusOut();
    QListView::focusOutEvent(e);
}

void CompleterView::keyPressEvent(QKeyEvent* e)
{
    QString txt = e->text();
    if (!txt.isEmpty() && txt[0].isPrint())
    {
        emit textTyped(txt);
        return;
    }

    switch (e->key())
    {
        case Qt::Key_Backspace:
            emit backspace();
            return;
        case Qt::Key_Left:
            emit left();
            return;
        case Qt::Key_Right:
            emit right();
            return;
    }

    QListView::keyPressEvent(e);
}