Commit 498f4450 authored by David Schulz's avatar David Schulz Committed by Leandro Melo
Browse files

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: default avatarLeandro Melo <leandro.melo@nokia.com>
parent db8a20bc
......@@ -179,7 +179,7 @@ private:
class GenericProposalListView : public QListView
{
public:
GenericProposalListView(QWidget *parent) : QListView(parent) {}
GenericProposalListView(QWidget *parent);
QSize calculateSize() const;
QPoint infoFramePos() const;
......@@ -192,19 +192,24 @@ public:
void selectLastRow() { selectRow(model()->rowCount() - 1); }
};
GenericProposalListView::GenericProposalListView(QWidget *parent)
: QListView(parent)
{
setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
}
QSize GenericProposalListView::calculateSize() const
{
static const int maxVisibleItems = 10;
// Determine size by calculating the space of the visible items
int visibleItems = model()->rowCount();
if (visibleItems > maxVisibleItems)
visibleItems = maxVisibleItems;
const int visibleItems = qMin(model()->rowCount(), maxVisibleItems);
const int firstVisibleRow = verticalScrollBar()->value();
const QStyleOptionViewItem &option = viewOptions();
QSize shint;
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())
shint = tmp;
}
......@@ -321,6 +326,8 @@ GenericProposalWidget::GenericProposalWidget()
d->m_completionListView->setSelectionMode(QAbstractItemView::SingleSelection);
d->m_completionListView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
d->m_completionListView->setMinimumSize(1, 1);
connect(d->m_completionListView->verticalScrollBar(), SIGNAL(valueChanged(int)),
this, SLOT(updatePositionAndSize()));
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setMargin(0);
......
......@@ -60,10 +60,12 @@ public:
private:
bool updateAndCheck(const QString &prefix);
void updatePositionAndSize();
void notifyActivation(int index);
void abort();
private slots:
void updatePositionAndSize();
protected:
virtual bool eventFilter(QObject *o, QEvent *e);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment