diff options
author | David Schulz <david.schulz@nokia.com> | 2012-09-04 16:00:32 +0200 |
---|---|---|
committer | Leandro Melo <leandro.melo@nokia.com> | 2012-09-07 12:19:53 +0200 |
commit | 498f4450fefaedf698177242859d20c78aea07d5 (patch) | |
tree | 434bba2eac0bdab5ae1873e57c2477a40b1901ab | |
parent | db8a20bc574eaec56b904af425578555ab840e2f (diff) | |
download | qt-creator-498f4450fefaedf698177242859d20c78aea07d5.tar.gz |
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>
-rw-r--r-- | src/plugins/texteditor/codeassist/genericproposalwidget.cpp | 17 | ||||
-rw-r--r-- | src/plugins/texteditor/codeassist/genericproposalwidget.h | 4 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/plugins/texteditor/codeassist/genericproposalwidget.cpp b/src/plugins/texteditor/codeassist/genericproposalwidget.cpp index 439efaf5a0..7d5b63b35e 100644 --- a/src/plugins/texteditor/codeassist/genericproposalwidget.cpp +++ b/src/plugins/texteditor/codeassist/genericproposalwidget.cpp @@ -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); diff --git a/src/plugins/texteditor/codeassist/genericproposalwidget.h b/src/plugins/texteditor/codeassist/genericproposalwidget.h index 6fdcfb6079..745f7d51bc 100644 --- a/src/plugins/texteditor/codeassist/genericproposalwidget.h +++ b/src/plugins/texteditor/codeassist/genericproposalwidget.h @@ -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); |