forked from qt-creator/qt-creator
Editor: update autocompleter list width.
The width of the List view showing the autocompleter proposals is now adjusted when scrolling. Task-number: QTCREATORBUG-7185 Change-Id: I5b26ef6195d389b30fdf0964bebd9c2f33056c66 Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
This commit is contained in:
committed by
Leandro Melo
parent
db8a20bc57
commit
498f4450fe
@@ -179,7 +179,7 @@ private:
|
|||||||
class GenericProposalListView : public QListView
|
class GenericProposalListView : public QListView
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GenericProposalListView(QWidget *parent) : QListView(parent) {}
|
GenericProposalListView(QWidget *parent);
|
||||||
|
|
||||||
QSize calculateSize() const;
|
QSize calculateSize() const;
|
||||||
QPoint infoFramePos() const;
|
QPoint infoFramePos() const;
|
||||||
@@ -192,19 +192,24 @@ public:
|
|||||||
void selectLastRow() { selectRow(model()->rowCount() - 1); }
|
void selectLastRow() { selectRow(model()->rowCount() - 1); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GenericProposalListView::GenericProposalListView(QWidget *parent)
|
||||||
|
: QListView(parent)
|
||||||
|
{
|
||||||
|
setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
|
||||||
|
}
|
||||||
|
|
||||||
QSize GenericProposalListView::calculateSize() const
|
QSize GenericProposalListView::calculateSize() const
|
||||||
{
|
{
|
||||||
static const int maxVisibleItems = 10;
|
static const int maxVisibleItems = 10;
|
||||||
|
|
||||||
// Determine size by calculating the space of the visible items
|
// Determine size by calculating the space of the visible items
|
||||||
int visibleItems = model()->rowCount();
|
const int visibleItems = qMin(model()->rowCount(), maxVisibleItems);
|
||||||
if (visibleItems > maxVisibleItems)
|
const int firstVisibleRow = verticalScrollBar()->value();
|
||||||
visibleItems = maxVisibleItems;
|
|
||||||
|
|
||||||
const QStyleOptionViewItem &option = viewOptions();
|
const QStyleOptionViewItem &option = viewOptions();
|
||||||
QSize shint;
|
QSize shint;
|
||||||
for (int i = 0; i < visibleItems; ++i) {
|
for (int i = 0; i < visibleItems; ++i) {
|
||||||
QSize tmp = itemDelegate()->sizeHint(option, model()->index(i, 0));
|
QSize tmp = itemDelegate()->sizeHint(option, model()->index(i + firstVisibleRow, 0));
|
||||||
if (shint.width() < tmp.width())
|
if (shint.width() < tmp.width())
|
||||||
shint = tmp;
|
shint = tmp;
|
||||||
}
|
}
|
||||||
@@ -321,6 +326,8 @@ GenericProposalWidget::GenericProposalWidget()
|
|||||||
d->m_completionListView->setSelectionMode(QAbstractItemView::SingleSelection);
|
d->m_completionListView->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
d->m_completionListView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
d->m_completionListView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
d->m_completionListView->setMinimumSize(1, 1);
|
d->m_completionListView->setMinimumSize(1, 1);
|
||||||
|
connect(d->m_completionListView->verticalScrollBar(), SIGNAL(valueChanged(int)),
|
||||||
|
this, SLOT(updatePositionAndSize()));
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||||
layout->setMargin(0);
|
layout->setMargin(0);
|
||||||
|
|||||||
@@ -60,10 +60,12 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool updateAndCheck(const QString &prefix);
|
bool updateAndCheck(const QString &prefix);
|
||||||
void updatePositionAndSize();
|
|
||||||
void notifyActivation(int index);
|
void notifyActivation(int index);
|
||||||
void abort();
|
void abort();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void updatePositionAndSize();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool eventFilter(QObject *o, QEvent *e);
|
virtual bool eventFilter(QObject *o, QEvent *e);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user