[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kexi] src: Make Global Search list wider to fit the names
From: Jaroslaw Staniek <staniek () kde ! org>
Date: 2016-02-29 23:12:19
Message-ID: E1aaWzD-0000sv-6u () scm ! kde ! org
[Download RAW message or body]
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 project, 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/completer/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 = QApplication::desktop()->availableGeometry(widget);
- Qt::LayoutDirection dir = widget->layoutDirection();
+ const Qt::LayoutDirection dir = widget->layoutDirection();
QPoint pos;
int rh, w;
- int h = (popup->sizeHintForRow(0) * qMin(maxVisibleItems, \
popup->model()->rowCount()) + 3) + 3;
- QScrollBar *hsb = popup->horizontalScrollBar();
- if (hsb && hsb->isVisible())
- h += popup->horizontalScrollBar()->sizeHint().height();
+ int h = heightHint;
- if (rect.isValid()) {
- rh = rect.height();
- w = rect.width();
- pos = widget->mapToGlobal(dir == Qt::RightToLeft ? rect.bottomRight() : \
rect.bottomLeft()); + if (currentRect.isValid()) {
+ rh = currentRect.height();
+ w = currentRect.width();
+ pos = widget->mapToGlobal(dir == Qt::RightToLeft ? currentRect.bottomRight() \
: currentRect.bottomLeft()); } else {
rh = widget->height();
pos = widget->mapToGlobal(QPoint(0, widget->height() - 2));
w = widget->width();
}
+ if (widthHint > w) {
+ w = widthHint;
+ }
if (w > screen.width())
w = screen.width();
@@ -959,7 +960,7 @@ void KexiCompleterPrivate::showPopup(const QRect& rect)
int top = pos.y() - rh - screen.top() + 2;
int bottom = screen.bottom() - pos.y();
- h = qMax(h, popup->minimumHeight());
+ h = qMax(h, popupWidget->minimumHeight());
if (h > bottom) {
h = 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 = popup->sizeHintForColumn(0);
+ QScrollBar *vsb = popup->verticalScrollBar();
+ if (vsb) {
+ widthHint += vsb->sizeHint().width() + 3 + 3;
+ }
+ int heightHint = (popup->sizeHintForRow(0) * qMin(maxVisibleItems, \
popup->model()->rowCount()) + 3) + 3; + QScrollBar *hsb = \
popup->horizontalScrollBar(); + if (hsb && hsb->isVisible()) {
+ heightHint += 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ław Staniek <staniek@kde.org>
+ Copyright (C) 2011-2016 Jarosław Staniek <staniek@kde.org>
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<QWidget> 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 = option;
+ QStyledItemDelegate::initStyleOption(&v4, index);
+ const QSize s = \
v4.widget->style()->sizeFromContents(QStyle::CT_ItemViewItem, &v4, size, v4.widget); \
+ size.setWidth(s.width()); + return size;
+ }
+
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
@@ -355,10 +367,10 @@ KexiSearchLineEdit::KexiSearchLineEdit(QWidget *parent)
: QLineEdit(parent), d(new Private(this))
{
d->completer = new KexiSearchLineEditCompleter(this);
- QTreeView *treeView = new QTreeView;
- kexiTester() << KexiTestObject(treeView, "globalSearch.treeView");
+ d->popupTreeView = new QTreeView;
+ kexiTester() << KexiTestObject(d->popupTreeView, "globalSearch.treeView");
- d->completer->setPopup(treeView);
+ d->completer->setPopup(d->popupTreeView);
d->completer->setModel(d->model = new \
KexiSearchLineEditCompleterPopupModel(d->completer)); \
d->completer->setCaseSensitivity(Qt::CaseInsensitive); \
d->completer->setSubstringCompletion(true); @@ -368,10 +380,10 @@ \
KexiSearchLineEdit::KexiSearchLineEdit(QWidget *parent) // filtering so only table \
names are displayed. d->completer->setModelSorting(KexiCompleter::UnsortedModel);
- treeView->setHeaderHidden(true);
- treeView->setRootIsDecorated(false);
- treeView->setItemDelegate(
- d->delegate = new KexiSearchLineEditPopupItemDelegate(treeView, \
d->completer)); + d->popupTreeView->setHeaderHidden(true);
+ d->popupTreeView->setRootIsDecorated(false);
+ d->popupTreeView->setItemDelegate(
+ d->delegate = new KexiSearchLineEditPopupItemDelegate(d->popupTreeView, \
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();
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic