summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qt-ui/locationinformation.cpp56
-rw-r--r--qt-ui/locationinformation.h3
2 files changed, 54 insertions, 5 deletions
diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp
index 087e31fc9..27cbc61a3 100644
--- a/qt-ui/locationinformation.cpp
+++ b/qt-ui/locationinformation.cpp
@@ -14,6 +14,8 @@
#include <QItemSelectionModel>
#include <qmessagebox.h>
#include <cstdlib>
+#include <QDesktopWidget>
+#include <QScrollBar>
LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBox(parent), modified(false)
{
@@ -421,11 +423,6 @@ DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent)
view->setModelColumn(DiveLocationModel::NAME);
view->setItemDelegate(new LocationFilterDelegate());
connect(this, &QLineEdit::textEdited, this, &DiveLocationLineEdit::setTemporaryDiveSiteName);
-
- //HACK:
- /* This is being show currently just to test. */
- qDebug() << model->rowCount() << model->columnCount();
- view->show();
}
void DiveLocationLineEdit::refreshDiveSiteCache()
@@ -463,6 +460,55 @@ void DiveLocationLineEdit::setTemporaryDiveSiteName(const QString& s)
proxy->invalidate();
}
+void DiveLocationLineEdit::keyPressEvent(QKeyEvent *ev)
+{
+ QLineEdit::keyPressEvent(ev);
+ if(ev->key() != Qt::Key_Left && ev->key() != Qt::Key_Right && !view->isVisible()) {
+ qDebug() << "Showing popup";
+ showPopup();
+ } else {
+ qDebug() << "Not showing popup";
+ }
+}
+
+void DiveLocationLineEdit::showPopup()
+{
+ const QRect screen = QApplication::desktop()->availableGeometry(this);
+ const int maxVisibleItems = 5;
+ Qt::LayoutDirection dir = layoutDirection();
+ QPoint pos;
+ int rh, w;
+ int h = (view->sizeHintForRow(0) * qMin(maxVisibleItems, view->model()->rowCount()) + 3) + 3;
+ QScrollBar *hsb = view->horizontalScrollBar();
+ if (hsb && hsb->isVisible())
+ h += view->horizontalScrollBar()->sizeHint().height();
+
+ rh = height();
+ pos = mapToGlobal(QPoint(0, height() - 2));
+ w = width();
+
+ if (w > screen.width())
+ w = screen.width();
+ if ((pos.x() + w) > (screen.x() + screen.width()))
+ pos.setX(screen.x() + screen.width() - w);
+ if (pos.x() < screen.x())
+ pos.setX(screen.x());
+
+ int top = pos.y() - rh - screen.top() + 2;
+ int bottom = screen.bottom() - pos.y();
+ h = qMax(h, view->minimumHeight());
+ if (h > bottom) {
+ h = qMin(qMax(top, bottom), h);
+ if (top > bottom)
+ pos.setY(pos.y() - h - rh + 2);
+ }
+
+ view->setGeometry(pos.x(), pos.y(), w, h);
+
+ if (!view->isVisible())
+ view->show();
+}
+
DiveLocationListView::DiveLocationListView(QWidget *parent)
{
diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h
index 16d5a3eae..b60c50606 100644
--- a/qt-ui/locationinformation.h
+++ b/qt-ui/locationinformation.h
@@ -93,6 +93,9 @@ public:
DiveLocationLineEdit(QWidget *parent =0 );
void refreshDiveSiteCache();
void setTemporaryDiveSiteName(const QString& s);
+protected:
+ void keyPressEvent(QKeyEvent *ev);
+ void showPopup();
private:
DiveLocationFilterProxyModel *proxy;
DiveLocationModel *model;