~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to krunner/interfaces/quicksand/qs_completionbox.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright (C) 2007-2008 Ryan P. Bitanga <ryan.bitanga@gmail.com>
 
3
 *
 
4
 *   This program is free software; you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU General Public License as published by
 
6
 *   the Free Software Foundation; either version 2 of the License, or
 
7
 *   (at your option) any later version.
 
8
 *
 
9
 *   This program is distributed in the hope that it will be useful,
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *   GNU General Public License for more details.
 
13
 *
 
14
 *   You should have received a copy of the GNU General Public License
 
15
 *   along with this program; if not, write to the
 
16
 *   Free Software Foundation, Inc.,
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .
 
18
 */
 
19
 
 
20
#include <QKeyEvent>
 
21
#include <QPoint>
 
22
#include <QResizeEvent>
 
23
 
 
24
#include <KDebug>
 
25
 
 
26
#include "qs_completionbox.h"
 
27
#include "qs_statusbar.h"
 
28
 
 
29
namespace QuickSand {
 
30
 
 
31
QsCompletionBox::QsCompletionBox(QWidget *parent)
 
32
    : KCompletionBox(parent),
 
33
        m_offset(0,0)
 
34
{
 
35
    m_status = new QsStatusBar(this);
 
36
    connect(model(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(slotRowsChanged(const QModelIndex &, int, int)));
 
37
    connect(model(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(slotRowsChanged(const QModelIndex &, int, int)));
 
38
    connect(this, SIGNAL(currentRowChanged(int)), m_status, SLOT(slotCurrentRowChanged(int)));
 
39
}
 
40
 
 
41
QRect QsCompletionBox::calculateGeometry() const
 
42
{
 
43
    QRect geom = KCompletionBox::calculateGeometry();
 
44
    geom.setHeight(geom.height() + m_status->geometry().height());
 
45
    geom.setWidth(geom.width() * 3/4);
 
46
    return geom;
 
47
}
 
48
 
 
49
QSize QsCompletionBox::minimumSizeHint() const
 
50
{
 
51
    return sizeHint();
 
52
}
 
53
 
 
54
QSize QsCompletionBox::sizeHint() const
 
55
{
 
56
    return calculateGeometry().size();
 
57
}
 
58
 
 
59
void QsCompletionBox::popup()
 
60
{
 
61
    KCompletionBox::popup();
 
62
    resize(calculateGeometry().size());
 
63
}
 
64
 
 
65
void QsCompletionBox::updateGeometries()
 
66
{
 
67
    KCompletionBox::updateGeometries();
 
68
    int statusHeight = m_status->geometry().height();
 
69
 
 
70
//         setGeometry(calculateGeometry());
 
71
 
 
72
    setViewportMargins(0,0,0,statusHeight);
 
73
 
 
74
    QRect vg = viewport()->geometry();
 
75
    int statusTop = vg.bottom();
 
76
 
 
77
    m_status->setGeometry(vg.left(), statusTop, vg.width(), statusHeight);
 
78
}
 
79
 
 
80
void QsCompletionBox::slotRowsChanged(const QModelIndex &, int, int)
 
81
{
 
82
    int rows = model()->rowCount();
 
83
    m_status->setTotalRows(rows);
 
84
}
 
85
 
 
86
QPoint QsCompletionBox::globalPositionHint() const
 
87
{
 
88
    QWidget *p = qobject_cast<QWidget*>(parent());
 
89
    if (!p) {
 
90
        return QPoint();
 
91
    }
 
92
    return p->mapToGlobal(QPoint(p->width(), 22));
 
93
}
 
94
 
 
95
} // Namespace QuickSand
 
96
 
 
97
#include "qs_completionbox.moc"