[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kexi] src/widget/tableview: Make combo box popups for tabular view fit in the current screen
From:       Jaroslaw Staniek <staniek () kde ! org>
Date:       2016-02-29 23:12:21
Message-ID: E1aaWzF-0000sv-9W () scm ! kde ! org
[Download RAW message or body]

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 borders 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/tableview/kexicomboboxbase.cpp index 4ac8490..9733df3 100644
--- a/src/widget/tableview/kexicomboboxbase.cpp
+++ b/src/widget/tableview/kexicomboboxbase.cpp
@@ -29,6 +29,8 @@
 
 #include <KDbTableSchema>
 
+#include <QApplication>
+#include <QDesktopWidget>
 #include <QScopedValueRollback>
 #include <QDebug>
 #include <QScrollBar>
@@ -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 resize back \
                to prev. height
-        const int w = popupWidthHint();
+        int w = 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 = \
QApplication::desktop()->availableGeometry(posMappedToGlobal); +        pos -= \
screen.topLeft(); // to simplify computation +        w = popup()->width();
+        int h = popup()->height();
+        if (screen.width() < w) {
+            w = 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 = screen.height();
+            pos.setY(0);
+        } else if (screen.height() < (pos.y() + h - 1)) {
+            const int topY = pos.y() - thisWidget->height() - h;
+            if (topY >= 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 = -1;
             KDbLookupFieldSchema *lookupFieldSchema = this->lookupFieldSchema();
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 <psn@linux.se>
-   Copyright (C) 2003-2015 Jarosław Staniek <staniek@kde.org>
+   Copyright (C) 2003-2016 Jarosław Staniek <staniek@kde.org>
 
    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/tableview/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ław Staniek <staniek@kde.org>
+   Copyright (C) 2004-2016 Jarosław Staniek <staniek@kde.org>
 
    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 <QEvent>
 #include <QKeyEvent>
 #include <QScrollBar>
+#include <QApplication>
+#include <QDesktopWidget>
 
 /*! @internal
  Helper for KexiComboBoxPopup. */
@@ -355,7 +357,9 @@ void KexiComboBoxPopup::updateSize(int minWidth)
     int width = qMax(d->tv->tableSize().width(),
                            (te ? te->totalSize().width() : (parentWidget() ? \
parentWidget()->width() : 0/*sanity*/)));  //qDebug() << "size=" << size();
-    resize(qMax(minWidth, width)/*+(d->tv->columnCount()>1?2:0)*/ \
/*(d->updateSizeCalled?0:1)*/, d->tv->recordHeight() * records + 2); +    const QRect \
screen = QApplication::desktop()->availableGeometry(this); +    \
resize(qMin(screen.width(), qMax(minWidth, width)), d->tv->recordHeight() * records + \
2); +
     //qDebug() << "size after=" << size();
     if (d->visibleColumnsToShow.isEmpty()) {
         // record source type is not Query
diff --git a/src/widget/tableview/kexicomboboxpopup.h \
b/src/widget/tableview/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ław Staniek <staniek@kde.org>
+   Copyright (C) 2004-2016 Jarosław Staniek <staniek@kde.org>
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic