From kde-commits Mon Feb 29 23:12:21 2016 From: Jaroslaw Staniek Date: Mon, 29 Feb 2016 23:12:21 +0000 To: kde-commits Subject: [kexi] src/widget/tableview: Make combo box popups for tabular view fit in the current screen Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=145678900030124 Git commit ee9299a317a43e24410acc6697b638ef673db880 by Jaroslaw Staniek. Committed on 29/02/2016 at 23:07. Pushed by staniek into branch 'master'. Make combo box popups for tabular view fit in the current screen BUG:357682 FIXED-IN:2.9.11 Test Plan: Try a table and form with combo boxes, pop up near the screen bo= rders and on other screens than 1st Differential Revision: https://phabricator.kde.org/D841 (from calligra.git) M +33 -1 src/widget/tableview/kexicomboboxbase.cpp M +1 -1 src/widget/tableview/kexicomboboxbase.h M +6 -2 src/widget/tableview/kexicomboboxpopup.cpp M +1 -1 src/widget/tableview/kexicomboboxpopup.h http://commits.kde.org/kexi/ee9299a317a43e24410acc6697b638ef673db880 diff --git a/src/widget/tableview/kexicomboboxbase.cpp b/src/widget/tablevi= ew/kexicomboboxbase.cpp index 4ac8490..9733df3 100644 --- a/src/widget/tableview/kexicomboboxbase.cpp +++ b/src/widget/tableview/kexicomboboxbase.cpp @@ -29,6 +29,8 @@ = #include = +#include +#include #include #include #include @@ -434,13 +436,43 @@ void KexiComboBoxBase::createPopup(bool show) popup()->move(pos); //qDebug() << "pos:" << posMappedToGlobal + QPoint(0, thisWidget->= height()); //to avoid flickering: first resize to 0-height, then show and res= ize back to prev. height - const int w =3D popupWidthHint(); + int w =3D popupWidthHint(); popup()->resize(w, 0); if (show) { popup()->show(); //qDebug() << "SHOW!!!"; } popup()->updateSize(w); + + // make sure the popup fits on the screen + const QRect screen =3D QApplication::desktop()->availableGeometry(= posMappedToGlobal); + pos -=3D screen.topLeft(); // to simplify computation + w =3D popup()->width(); + int h =3D popup()->height(); + if (screen.width() < w) { + w =3D screen.width(); + pos.setX(0); + } else if (screen.width() < (pos.x() + w - 1)) { + pos.setX(screen.width() - w + 1); + } else if (pos.x() < 0) { + pos.setX(0); + } + if (screen.height() < h) { + h =3D screen.height(); + pos.setY(0); + } else if (screen.height() < (pos.y() + h - 1)) { + const int topY =3D pos.y() - thisWidget->height() - h; + if (topY >=3D 0 && (topY + h - 1 < screen.height())) { + pos.setY(pos.y() - thisWidget->height() - h); + } else { + pos.setY(screen.height() - h + 1); + } + } else if (pos.y() < 0) { + pos.setY(0); + } + popup()->move(pos + screen.topLeft()); + popup()->resize(w, h); + if (m_updatePopupSelectionOnShow) { int recordToHighlight =3D -1; KDbLookupFieldSchema *lookupFieldSchema =3D this->lookupFieldS= chema(); diff --git a/src/widget/tableview/kexicomboboxbase.h b/src/widget/tableview= /kexicomboboxbase.h index 5bc0dbb..03f074d 100644 --- a/src/widget/tableview/kexicomboboxbase.h +++ b/src/widget/tableview/kexicomboboxbase.h @@ -1,6 +1,6 @@ /* This file is part of the KDE project Copyright (C) 2002 Peter Simonsson - Copyright (C) 2003-2015 Jaros=C5=82aw Staniek + Copyright (C) 2003-2016 Jaros=C5=82aw Staniek = This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public diff --git a/src/widget/tableview/kexicomboboxpopup.cpp b/src/widget/tablev= iew/kexicomboboxpopup.cpp index 9663ac0..16a9c4e 100644 --- a/src/widget/tableview/kexicomboboxpopup.cpp +++ b/src/widget/tableview/kexicomboboxpopup.cpp @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2004-2015 Jaros=C5=82aw Staniek + Copyright (C) 2004-2016 Jaros=C5=82aw Staniek = This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -33,6 +33,8 @@ #include #include #include +#include +#include = /*! @internal Helper for KexiComboBoxPopup. */ @@ -355,7 +357,9 @@ void KexiComboBoxPopup::updateSize(int minWidth) int width =3D qMax(d->tv->tableSize().width(), (te ? te->totalSize().width() : (parentWidget()= ? parentWidget()->width() : 0/*sanity*/))); //qDebug() << "size=3D" << size(); - resize(qMax(minWidth, width)/*+(d->tv->columnCount()>1?2:0)*/ /*(d->up= dateSizeCalled?0:1)*/, d->tv->recordHeight() * records + 2); + const QRect screen =3D QApplication::desktop()->availableGeometry(this= ); + resize(qMin(screen.width(), qMax(minWidth, width)), d->tv->recordHeigh= t() * records + 2); + //qDebug() << "size after=3D" << size(); if (d->visibleColumnsToShow.isEmpty()) { // record source type is not Query diff --git a/src/widget/tableview/kexicomboboxpopup.h b/src/widget/tablevie= w/kexicomboboxpopup.h index 92b6536..d97b8ea 100644 --- a/src/widget/tableview/kexicomboboxpopup.h +++ b/src/widget/tableview/kexicomboboxpopup.h @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2004-2014 Jaros=C5=82aw Staniek + Copyright (C) 2004-2016 Jaros=C5=82aw Staniek = This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public