From kde-commits Mon Feb 29 23:12:19 2016 From: Jaroslaw Staniek Date: Mon, 29 Feb 2016 23:12:19 +0000 To: kde-commits Subject: [kexi] src: Make Global Search list wider to fit the names Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=145678893529916 Git commit 8779af0dba828b97ad408b5bb4d2455b8d6622aa by Jaroslaw Staniek. Committed on 29/02/2016 at 23:07. Pushed by staniek into branch 'master'. Make Global Search list wider to fit the names BUG:358203 FIXED-IN:2.9.11 Test Plan: Try global search with completion popup for a nontrivial kexi pr= oject, see the geometry Reviewers: piggz Subscribers: Kexi-Devel-list Differential Revision: https://phabricator.kde.org/D842 from calligra.git 3ba81865fc3d5 M +27 -12 src/kexiutils/completer/KexiCompleter.cpp M +21 -8 src/main/KexiSearchLineEdit.cpp http://commits.kde.org/kexi/8779af0dba828b97ad408b5bb4d2455b8d6622aa diff --git a/src/kexiutils/completer/KexiCompleter.cpp b/src/kexiutils/comp= leter/KexiCompleter.cpp index 45cd26d..67ffb0d 100644 --- a/src/kexiutils/completer/KexiCompleter.cpp +++ b/src/kexiutils/completer/KexiCompleter.cpp @@ -929,26 +929,27 @@ void KexiCompleterPrivate::_q_autoResizePopup() showPopup(popupRect); } = -void KexiCompleterPrivate::showPopup(const QRect& rect) +static void adjustPopupGeometry(QWidget *popupWidget, QWidget *widget, int= widthHint, + int heightHint, const QRect ¤tRect) { const QRect screen =3D QApplication::desktop()->availableGeometry(widg= et); - Qt::LayoutDirection dir =3D widget->layoutDirection(); + const Qt::LayoutDirection dir =3D widget->layoutDirection(); QPoint pos; int rh, w; - int h =3D (popup->sizeHintForRow(0) * qMin(maxVisibleItems, popup->mod= el()->rowCount()) + 3) + 3; - QScrollBar *hsb =3D popup->horizontalScrollBar(); - if (hsb && hsb->isVisible()) - h +=3D popup->horizontalScrollBar()->sizeHint().height(); + int h =3D heightHint; = - if (rect.isValid()) { - rh =3D rect.height(); - w =3D rect.width(); - pos =3D widget->mapToGlobal(dir =3D=3D Qt::RightToLeft ? rect.bott= omRight() : rect.bottomLeft()); + if (currentRect.isValid()) { + rh =3D currentRect.height(); + w =3D currentRect.width(); + pos =3D widget->mapToGlobal(dir =3D=3D Qt::RightToLeft ? currentRe= ct.bottomRight() : currentRect.bottomLeft()); } else { rh =3D widget->height(); pos =3D widget->mapToGlobal(QPoint(0, widget->height() - 2)); w =3D widget->width(); } + if (widthHint > w) { + w =3D widthHint; + } = if (w > screen.width()) w =3D screen.width(); @@ -959,7 +960,7 @@ void KexiCompleterPrivate::showPopup(const QRect& rect) = int top =3D pos.y() - rh - screen.top() + 2; int bottom =3D screen.bottom() - pos.y(); - h =3D qMax(h, popup->minimumHeight()); + h =3D qMax(h, popupWidget->minimumHeight()); if (h > bottom) { h =3D qMin(qMax(top, bottom), h); = @@ -967,8 +968,22 @@ void KexiCompleterPrivate::showPopup(const QRect& rect) pos.setY(pos.y() - h - rh + 2); } = - popup->setGeometry(pos.x(), pos.y(), w, h); + popupWidget->setGeometry(pos.x(), pos.y(), w, h); +} = +void KexiCompleterPrivate::showPopup(const QRect& rect) +{ + int widthHint =3D popup->sizeHintForColumn(0); + QScrollBar *vsb =3D popup->verticalScrollBar(); + if (vsb) { + widthHint +=3D vsb->sizeHint().width() + 3 + 3; + } + int heightHint =3D (popup->sizeHintForRow(0) * qMin(maxVisibleItems, p= opup->model()->rowCount()) + 3) + 3; + QScrollBar *hsb =3D popup->horizontalScrollBar(); + if (hsb && hsb->isVisible()) { + heightHint +=3D hsb->sizeHint().height(); + } + adjustPopupGeometry(popup, widget, widthHint, heightHint, rect); if (!popup->isVisible()) popup->show(); } diff --git a/src/main/KexiSearchLineEdit.cpp b/src/main/KexiSearchLineEdit.= cpp index dc446b8..81ab422 100644 --- a/src/main/KexiSearchLineEdit.cpp +++ b/src/main/KexiSearchLineEdit.cpp @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2011-2015 Jaros=C5=82aw Staniek + Copyright (C) 2011-2016 Jaros=C5=82aw Staniek Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). = This program is free software; you can redistribute it and/or @@ -199,6 +199,7 @@ public: } = KexiSearchLineEditCompleter *completer; + QTreeView *popupTreeView; KexiSearchLineEditCompleterPopupModel *model; KexiSearchLineEditPopupItemDelegate *delegate; QPointer previouslyFocusedWidget; @@ -237,6 +238,17 @@ public: { } = + //! Implemented to improve width hint + QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &= index) const + { + QSize size(QStyledItemDelegate::sizeHint(option, index)); + QStyleOptionViewItemV4 v4 =3D option; + QStyledItemDelegate::initStyleOption(&v4, index); + const QSize s =3D v4.widget->style()->sizeFromContents(QStyle::CT_= ItemViewItem, &v4, size, v4.widget); + size.setWidth(s.width()); + return size; + } + virtual void paint(QPainter *painter, const QStyleOptionViewItem &opti= on, const QModelIndex &index) const { @@ -355,10 +367,10 @@ KexiSearchLineEdit::KexiSearchLineEdit(QWidget *paren= t) : QLineEdit(parent), d(new Private(this)) { d->completer =3D new KexiSearchLineEditCompleter(this); - QTreeView *treeView =3D new QTreeView; - kexiTester() << KexiTestObject(treeView, "globalSearch.treeView"); + d->popupTreeView =3D new QTreeView; + kexiTester() << KexiTestObject(d->popupTreeView, "globalSearch.treeVie= w"); = - d->completer->setPopup(treeView); + d->completer->setPopup(d->popupTreeView); d->completer->setModel(d->model =3D new KexiSearchLineEditCompleterPop= upModel(d->completer)); d->completer->setCaseSensitivity(Qt::CaseInsensitive); d->completer->setSubstringCompletion(true); @@ -368,10 +380,10 @@ KexiSearchLineEdit::KexiSearchLineEdit(QWidget *paren= t) // filtering so only table names are displayed. d->completer->setModelSorting(KexiCompleter::UnsortedModel); = - treeView->setHeaderHidden(true); - treeView->setRootIsDecorated(false); - treeView->setItemDelegate( - d->delegate =3D new KexiSearchLineEditPopupItemDelegate(treeView, = d->completer)); + d->popupTreeView->setHeaderHidden(true); + d->popupTreeView->setRootIsDecorated(false); + d->popupTreeView->setItemDelegate( + d->delegate =3D new KexiSearchLineEditPopupItemDelegate(d->popupTr= eeView, d->completer)); = // forked initialization like in QLineEdit::setCompleter: d->completer->setWidget(this); @@ -812,6 +824,7 @@ void KexiSearchLineEdit::complete(int key) d->completer->setCompletionPrefix(text); } = + d->popupTreeView->resizeColumnToContents(0); d->completer->complete(); } =