From be6e190bd2b0480d76fc29bed95d46ad1aa7f414 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Mon, 21 Sep 2015 14:01:58 -0300 Subject: Skeleton of the new LocationCombobox This is the bare minimum skeleton of the new completer for the dive site management. Nothing works, yet, nothing is hoocked up, yet. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 133 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) (limited to 'qt-ui/locationinformation.cpp') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index bf8300426..3a213e679 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -317,3 +317,136 @@ void LocationInformationWidget::reverseGeocode() geoLookup->lookup(&displayed_dive_site); updateLabels(); } + +DiveLocationFilterProxyModel::DiveLocationFilterProxyModel(QObject *parent) +{ + +} + +DiveLocationLineEdit *location_line_edit = 0; + +bool DiveLocationFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const +{ + if(source_row == 0 || source_row == 1) + return true; + + QString sourceString = sourceModel()->index(source_row, DiveLocationModel::NAME).data(Qt::DisplayRole).toString(); + return sourceString.toLower().startsWith(location_line_edit->text().toLower()); +} + +DiveLocationModel::DiveLocationModel(QObject *o) +{ + resetModel(); +} + +void DiveLocationModel::resetModel() +{ + beginResetModel(); + qDebug() << "Dive site table size" <uuid; + case NAME: return ds->name; + case LATITUDE: return ds->latitude.udeg; + case LONGITUDE: return ds->longitude.udeg; + case DESCRIPTION: return ds->description; + case NOTES: return ds->name; + } + break; + case Qt::DecorationRole : { + if (dive_site_has_gps_location(ds)) + return QIcon(":geocode"); + } + } + return QVariant(); +} + +int DiveLocationModel::columnCount(const QModelIndex& parent) const +{ + return COLUMNS; +} + +int DiveLocationModel::rowCount(const QModelIndex& parent) const +{ + return dive_site_table.nr + 2; +} + + +bool DiveLocationModel::setData(const QModelIndex& index, const QVariant& value, int role) +{ + if(!index.isValid()) + return false; + if (index.row() > 1) + return false; + + new_ds_value[index.row()] = value.toString(); + + dataChanged(index, index); + return true; +} + +DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent) +{ + proxy = new DiveLocationFilterProxyModel(); + model = new DiveLocationModel(); + view = new DiveLocationListView(); + + proxy->setSourceModel(model); + view->setModel(model); + + connect(this, &QLineEdit::textEdited, this, &DiveLocationLineEdit::setTemporaryDiveSiteName); + + //HACK: + /* This is being show currently just to test. */ + qDebug() << "AAAAAAH"; + qDebug() << model->rowCount() << model->columnCount(); + view->show(); +} + +void DiveLocationLineEdit::refreshDiveSiteCache() +{ + model->resetModel(); +} + +static struct dive_site *get_dive_site_name_start_which_str(const QString& str) { + struct dive_site *ds; + int i; + for_each_dive_site(i,ds) { + QString dsName(ds->name); + if (dsName.startsWith(str)) { + return ds; + } + } + return NULL; +} + +void DiveLocationLineEdit::setTemporaryDiveSiteName(const QString& s) +{ + QModelIndex i0 = model->index(0, DiveLocationModel::NAME); + model->setData(i0, text()); + + struct dive_site *ds = get_dive_site_name_start_which_str(text()); + QModelIndex i1 = model->index(1, DiveLocationModel::NAME); + model->setData(i1, ds ? ds->name : INVALID_DIVE_SITE_NAME); +} + +DiveLocationListView::DiveLocationListView(QWidget *parent) +{ + +} -- cgit v1.2.3-70-g09d2 From 8c9a4ecd4b06d62b8b2b6b5a36e025aa84521ec7 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Mon, 21 Sep 2015 15:04:52 -0300 Subject: Stabilize the location model/proxy model Since I removed the old location edit from the UI, I also need to remove a bit of code from the UI that was calling it. fix a few crashes regarding the old location edit. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 34 +++++++++++++++++++++++++--------- qt-ui/locationinformation.h | 1 + qt-ui/maintab.cpp | 31 +++++++------------------------ 3 files changed, 33 insertions(+), 33 deletions(-) (limited to 'qt-ui/locationinformation.cpp') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index 3a213e679..b8d66d56e 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -7,6 +7,7 @@ #include "filtermodels.h" #include "divelocationmodel.h" #include "divesitehelpers.h" +#include "modeldelegates.h" #include #include @@ -327,13 +328,19 @@ DiveLocationLineEdit *location_line_edit = 0; bool DiveLocationFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const { - if(source_row == 0 || source_row == 1) + if(source_row == 0) return true; QString sourceString = sourceModel()->index(source_row, DiveLocationModel::NAME).data(Qt::DisplayRole).toString(); return sourceString.toLower().startsWith(location_line_edit->text().toLower()); } +bool DiveLocationFilterProxyModel::lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const +{ + return source_left.data().toString() <= source_right.data().toString(); +} + + DiveLocationModel::DiveLocationModel(QObject *o) { resetModel(); @@ -342,7 +349,6 @@ DiveLocationModel::DiveLocationModel(QObject *o) void DiveLocationModel::resetModel() { beginResetModel(); - qDebug() << "Dive site table size" <setSourceModel(model); - view->setModel(model); - + proxy->setFilterKeyColumn(DiveLocationModel::NAME); + view->setModel(proxy); + 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() << "AAAAAAH"; qDebug() << model->rowCount() << model->columnCount(); view->show(); } @@ -429,7 +437,7 @@ static struct dive_site *get_dive_site_name_start_which_str(const QString& str) int i; for_each_dive_site(i,ds) { QString dsName(ds->name); - if (dsName.startsWith(str)) { + if (dsName.toLower().startsWith(str.toLower())) { return ds; } } @@ -439,11 +447,19 @@ static struct dive_site *get_dive_site_name_start_which_str(const QString& str) void DiveLocationLineEdit::setTemporaryDiveSiteName(const QString& s) { QModelIndex i0 = model->index(0, DiveLocationModel::NAME); + QModelIndex i1 = model->index(1, DiveLocationModel::NAME); model->setData(i0, text()); - struct dive_site *ds = get_dive_site_name_start_which_str(text()); - QModelIndex i1 = model->index(1, DiveLocationModel::NAME); - model->setData(i1, ds ? ds->name : INVALID_DIVE_SITE_NAME); + QString i1_name = INVALID_DIVE_SITE_NAME; + if (struct dive_site *ds = get_dive_site_name_start_which_str(text())) { + const QString orig_name = QString(ds->name).toLower(); + const QString new_name = text().toLower(); + if (new_name != orig_name) + i1_name = QString(ds->name); + } + + model->setData(i1, i1_name ); + proxy->invalidate(); } DiveLocationListView::DiveLocationListView(QWidget *parent) diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h index 18c3dc760..16d5a3eae 100644 --- a/qt-ui/locationinformation.h +++ b/qt-ui/locationinformation.h @@ -64,6 +64,7 @@ class DiveLocationFilterProxyModel : public QSortFilterProxyModel { public: DiveLocationFilterProxyModel(QObject *parent = 0); virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const; + virtual bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const; }; class DiveLocationModel : public QAbstractTableModel { diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 2499906c9..51df81d87 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -55,23 +55,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), ui.extraData->setModel(extraDataModel); closeMessage(); - QCompleter *completer = new QCompleter(); - QListView *completerListview = new QListView(); - LocationInformationModel::instance()->setFirstRowTextField(ui.location); - completer->setPopup(completerListview); - completer->setModel(LocationInformationModel::instance()); - completer->setCompletionColumn(LocationInformationModel::NAME); - completer->setCaseSensitivity(Qt::CaseInsensitive); - completerListview->setItemDelegate(new LocationFilterDelegate()); - completerListview->setMouseTracking(true); - locationManagementEditHelper = new LocationManagementEditHelper(); - connect(locationManagementEditHelper, &LocationManagementEditHelper::setLineEditText, - ui.location, &QLineEdit::setText); - completerListview->installEventFilter(locationManagementEditHelper); - connect(completerListview, &QAbstractItemView::clicked, - locationManagementEditHelper, &LocationManagementEditHelper::handleActivation); - - ui.location->setCompleter(completer); ui.editDiveSiteButton->setEnabled(true); connect(ui.editDiveSiteButton, SIGNAL(clicked()), MainWindow::instance(), SIGNAL(startDiveSiteEdit())); @@ -238,7 +221,7 @@ bool MainTab::eventFilter(QObject *obj, QEvent *ev) if (line) { if (ev->type() == QEvent::Resize) { - if (line->completer()->popup()->isVisible()) { + /*if (line->completer()->popup()->isVisible()) { QListView *choices = qobject_cast(line->completer()->popup()); QPoint p = ui.location->mapToGlobal(ui.location->pos()); choices->setGeometry( @@ -246,7 +229,9 @@ bool MainTab::eventFilter(QObject *obj, QEvent *ev) p.y() + 3, choices->geometry().width(), choices->geometry().height()); + } + */ } } return false; @@ -392,7 +377,7 @@ void MainTab::enableEdition(EditMode newEditMode) displayMessage(tr("Multiple dives are being edited.")); } else { displayMessage(tr("This dive is being edited.")); - locationManagementEditHelper->resetDiveSiteUuid(); + //locationManagementEditHelper->resetDiveSiteUuid(); } editMode = newEditMode != NONE ? newEditMode : DIVE; } @@ -474,10 +459,6 @@ void MainTab::updateDiveInfo(bool clear) { // I don't like this code here - but globe() wasn't initialized on the constructor. { - QListView *completerListview = qobject_cast(ui.location->completer()->popup()); -#ifndef NO_MARBLE - connect(completerListview, SIGNAL(entered(QModelIndex)), GlobeGPS::instance(), SLOT(centerOnIndex(QModelIndex)), Qt::UniqueConnection); -#endif } ui.location->refreshDiveSiteCache(); @@ -861,7 +842,9 @@ void MainTab::updateDisplayedDiveSite() const QString new_name = ui.location->text(); const QString orig_name = displayed_dive_site.name; const uint32_t orig_uuid = displayed_dive_site.uuid; - const uint32_t new_uuid = locationManagementEditHelper->diveSiteUuid(); + //TODO: FIX THIS + const uint32_t new_uuid = orig_uuid; + // locationManagementEditHelper->diveSiteUuid(); qDebug() << "Updating Displayed Dive Site"; -- cgit v1.2.3-70-g09d2 From 012e8ccb46321258343504ecbb3f7fcca8929c24 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Mon, 21 Sep 2015 15:15:11 -0300 Subject: Re-add the 'plus' button on the delegate This was missing in the delegate - now it's prettier. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'qt-ui/locationinformation.cpp') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index b8d66d56e..087e31fc9 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -358,6 +358,7 @@ QVariant DiveLocationModel::data(const QModelIndex& index, int role) const switch(role) { case Qt::DisplayRole : return new_ds_value[index.row()]; case Qt::ToolTipRole : return "Create a new dive site"; + case Qt::DecorationRole : return QIcon(":plus"); } } -- cgit v1.2.3-70-g09d2 From c4c7e7a7f4d462490e8f0fea846f13bff6076845 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Mon, 21 Sep 2015 16:08:58 -0300 Subject: Display the popup in the correct place The popup should be shown beneath the QLineEdit. this code here is shamelessy stolen from the QCompleter source code because I really didn't want to rethink the correct way of doing this. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 56 +++++++++++++++++++++++++++++++++++++++---- qt-ui/locationinformation.h | 3 +++ 2 files changed, 54 insertions(+), 5 deletions(-) (limited to 'qt-ui/locationinformation.cpp') 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 #include #include +#include +#include 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; -- cgit v1.2.3-70-g09d2 From fdd28fddf2303d6cf2c51383c87195af3774a91c Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Mon, 21 Sep 2015 16:51:39 -0300 Subject: Start to handle keypresses Keypress management is one of the main functions of the completer, so we must create an event filter and hook things up properly. key esq / enter should close the popup (and not leave us with a popup open and no way to close it - it breaks X) Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 46 ++++++++++++++++++++++++++++++++++++++----- qt-ui/locationinformation.h | 1 + 2 files changed, 42 insertions(+), 5 deletions(-) (limited to 'qt-ui/locationinformation.cpp') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index 27cbc61a3..468212c44 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -419,12 +419,41 @@ DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent) proxy->setSourceModel(model); proxy->setFilterKeyColumn(DiveLocationModel::NAME); + view->setModel(proxy); view->setModelColumn(DiveLocationModel::NAME); view->setItemDelegate(new LocationFilterDelegate()); + view->setEditTriggers(QAbstractItemView::NoEditTriggers); + view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + view->setSelectionBehavior(QAbstractItemView::SelectRows); + view->setSelectionMode(QAbstractItemView::SingleSelection); + view->setParent(0, Qt::Popup); + view->installEventFilter(this); + view->setFocusProxy(this); + connect(this, &QLineEdit::textEdited, this, &DiveLocationLineEdit::setTemporaryDiveSiteName); } +bool DiveLocationLineEdit::eventFilter(QObject *o, QEvent *e) +{ + if(e->type() == QEvent::KeyPress) { + QKeyEvent *keyEv = (QKeyEvent*) e; + + qDebug() << view->focusProxy()->objectName(); + + if (keyEv->key() == Qt::Key_Escape) { + view->hide(); + return true; + } + + if(keyEv->key() == Qt::Key_Return) { + view->hide(); + return false; + } + } + return false; +} + void DiveLocationLineEdit::refreshDiveSiteCache() { model->resetModel(); @@ -462,12 +491,17 @@ void DiveLocationLineEdit::setTemporaryDiveSiteName(const QString& s) void DiveLocationLineEdit::keyPressEvent(QKeyEvent *ev) { - QLineEdit::keyPressEvent(ev); - if(ev->key() != Qt::Key_Left && ev->key() != Qt::Key_Right && !view->isVisible()) { - qDebug() << "Showing popup"; + qDebug() << "Pressing key" << ev->key(); + if(ev->key() != Qt::Key_Left && + ev->key() != Qt::Key_Right && + ev->key() != Qt::Key_Escape && + ev->key() != Qt::Key_Return && + !view->isVisible()) { showPopup(); + } else if (ev->key() == Qt::Key_Escape) { + view->hide(); } else { - qDebug() << "Not showing popup"; + QLineEdit::keyPressEvent(ev); } } @@ -505,8 +539,10 @@ void DiveLocationLineEdit::showPopup() view->setGeometry(pos.x(), pos.y(), w, h); - if (!view->isVisible()) + if (!view->isVisible()) { view->show(); + view->setFocus(); + } } DiveLocationListView::DiveLocationListView(QWidget *parent) diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h index b60c50606..a1649d645 100644 --- a/qt-ui/locationinformation.h +++ b/qt-ui/locationinformation.h @@ -93,6 +93,7 @@ public: DiveLocationLineEdit(QWidget *parent =0 ); void refreshDiveSiteCache(); void setTemporaryDiveSiteName(const QString& s); + bool eventFilter(QObject*, QEvent*); protected: void keyPressEvent(QKeyEvent *ev); void showPopup(); -- cgit v1.2.3-70-g09d2 From 534e07399ac459a48d6e049d1ff36cef223eea66 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Mon, 21 Sep 2015 17:11:59 -0300 Subject: Made it possible to keypress again Click outside of the popup closes it, also handles theme enter / return keys. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'qt-ui/locationinformation.cpp') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index 468212c44..f8a125732 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -429,7 +429,7 @@ DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent) view->setSelectionMode(QAbstractItemView::SingleSelection); view->setParent(0, Qt::Popup); view->installEventFilter(this); - view->setFocusProxy(this); + view->setFocusProxy(location_line_edit); connect(this, &QLineEdit::textEdited, this, &DiveLocationLineEdit::setTemporaryDiveSiteName); } @@ -437,6 +437,8 @@ DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent) bool DiveLocationLineEdit::eventFilter(QObject *o, QEvent *e) { if(e->type() == QEvent::KeyPress) { + if (view->focusProxy() == this) qDebug() << "Ueh..."; + else qDebug() << "Nao eh..."; QKeyEvent *keyEv = (QKeyEvent*) e; qDebug() << view->focusProxy()->objectName(); @@ -446,11 +448,21 @@ bool DiveLocationLineEdit::eventFilter(QObject *o, QEvent *e) return true; } - if(keyEv->key() == Qt::Key_Return) { + if(keyEv->key() == Qt::Key_Return || keyEv->key() == Qt::Key_Enter) { view->hide(); return false; } + + event(e); + } + + if(e->type() == QEvent::MouseButtonPress ) { + if (!view->underMouse()) { + view->hide(); + return true; + } } + return false; } -- cgit v1.2.3-70-g09d2 From 317c3de91d6218244c58cee414d11e9f90c100ff Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Mon, 21 Sep 2015 17:18:52 -0300 Subject: Handle dive site activation Connect the view activated signal to send us the index. Removing debug output that I forgot inside it. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 8 ++++++-- qt-ui/locationinformation.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'qt-ui/locationinformation.cpp') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index f8a125732..111257dfc 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -432,13 +432,12 @@ DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent) view->setFocusProxy(location_line_edit); connect(this, &QLineEdit::textEdited, this, &DiveLocationLineEdit::setTemporaryDiveSiteName); + connect(view, &QAbstractItemView::activated, this, &DiveLocationLineEdit::itemActivated); } bool DiveLocationLineEdit::eventFilter(QObject *o, QEvent *e) { if(e->type() == QEvent::KeyPress) { - if (view->focusProxy() == this) qDebug() << "Ueh..."; - else qDebug() << "Nao eh..."; QKeyEvent *keyEv = (QKeyEvent*) e; qDebug() << view->focusProxy()->objectName(); @@ -466,6 +465,11 @@ bool DiveLocationLineEdit::eventFilter(QObject *o, QEvent *e) return false; } +void DiveLocationLineEdit::itemActivated(const QModelIndex& index) +{ + qDebug() << "Activated" << index.data(); +} + void DiveLocationLineEdit::refreshDiveSiteCache() { model->resetModel(); diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h index a1649d645..b52c03a9a 100644 --- a/qt-ui/locationinformation.h +++ b/qt-ui/locationinformation.h @@ -94,6 +94,7 @@ public: void refreshDiveSiteCache(); void setTemporaryDiveSiteName(const QString& s); bool eventFilter(QObject*, QEvent*); + void itemActivated(const QModelIndex& index); protected: void keyPressEvent(QKeyEvent *ev); void showPopup(); -- cgit v1.2.3-70-g09d2 From dd21ab6b11af632b7277c40d96a0fa1c8632acaa Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Mon, 21 Sep 2015 17:22:31 -0300 Subject: Fix correct size of the popup Correct the popup visibility. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'qt-ui/locationinformation.cpp') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index 111257dfc..68096db84 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -508,16 +508,14 @@ void DiveLocationLineEdit::setTemporaryDiveSiteName(const QString& s) void DiveLocationLineEdit::keyPressEvent(QKeyEvent *ev) { qDebug() << "Pressing key" << ev->key(); + QLineEdit::keyPressEvent(ev); if(ev->key() != Qt::Key_Left && ev->key() != Qt::Key_Right && ev->key() != Qt::Key_Escape && - ev->key() != Qt::Key_Return && - !view->isVisible()) { + ev->key() != Qt::Key_Return ) { showPopup(); } else if (ev->key() == Qt::Key_Escape) { view->hide(); - } else { - QLineEdit::keyPressEvent(ev); } } -- cgit v1.2.3-70-g09d2 From fdec250723549453e714580724231ee2fb866907 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 22 Sep 2015 14:13:51 -0300 Subject: Whitespace fix Sorry. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 68 +++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'qt-ui/locationinformation.cpp') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index 68096db84..a66b96c19 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -521,42 +521,42 @@ void DiveLocationLineEdit::keyPressEvent(QKeyEvent *ev) 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); - } + 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); + view->setGeometry(pos.x(), pos.y(), w, h); - if (!view->isVisible()) { - view->show(); - view->setFocus(); - } + if (!view->isVisible()) { + view->show(); + view->setFocus(); + } } DiveLocationListView::DiveLocationListView(QWidget *parent) -- cgit v1.2.3-70-g09d2 From eb2c78e9536f55f972154c9595ccb588318935d9 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 22 Sep 2015 14:31:56 -0300 Subject: Random fixes and improvements Whitespace fixes, constructor fixes, new slot (still unused) Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 35 +++++++++++++++++------------------ qt-ui/locationinformation.h | 8 ++++++++ 2 files changed, 25 insertions(+), 18 deletions(-) (limited to 'qt-ui/locationinformation.cpp') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index a66b96c19..71def344e 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -410,12 +410,10 @@ bool DiveLocationModel::setData(const QModelIndex& index, const QVariant& value, return true; } -DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent) +DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent) : QLineEdit(parent), + proxy(new DiveLocationFilterProxyModel()), model(new DiveLocationModel()), view(new DiveLocationListView()) { location_line_edit = this; - proxy = new DiveLocationFilterProxyModel(); - model = new DiveLocationModel(); - view = new DiveLocationListView(); proxy->setSourceModel(model); proxy->setFilterKeyColumn(DiveLocationModel::NAME); @@ -429,19 +427,24 @@ DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent) view->setSelectionMode(QAbstractItemView::SingleSelection); view->setParent(0, Qt::Popup); view->installEventFilter(this); - view->setFocusProxy(location_line_edit); + view->setFocusPolicy(Qt::NoFocus); + view->setFocusProxy(this); connect(this, &QLineEdit::textEdited, this, &DiveLocationLineEdit::setTemporaryDiveSiteName); + connect(this, &QLineEdit::editingFinished, this, &DiveLocationLineEdit::setDiveSiteName); connect(view, &QAbstractItemView::activated, this, &DiveLocationLineEdit::itemActivated); } +void DiveLocationLineEdit::setDiveSiteName() +{ + +} + bool DiveLocationLineEdit::eventFilter(QObject *o, QEvent *e) { if(e->type() == QEvent::KeyPress) { QKeyEvent *keyEv = (QKeyEvent*) e; - qDebug() << view->focusProxy()->objectName(); - if (keyEv->key() == Qt::Key_Escape) { view->hide(); return true; @@ -451,15 +454,12 @@ bool DiveLocationLineEdit::eventFilter(QObject *o, QEvent *e) view->hide(); return false; } - event(e); - } - - if(e->type() == QEvent::MouseButtonPress ) { - if (!view->underMouse()) { - view->hide(); - return true; - } + } else if(e->type() == QEvent::MouseButtonPress ) { + if (!view->underMouse()) { + view->hide(); + return true; + } } return false; @@ -507,7 +507,6 @@ void DiveLocationLineEdit::setTemporaryDiveSiteName(const QString& s) void DiveLocationLineEdit::keyPressEvent(QKeyEvent *ev) { - qDebug() << "Pressing key" << ev->key(); QLineEdit::keyPressEvent(ev); if(ev->key() != Qt::Key_Left && ev->key() != Qt::Key_Right && @@ -554,8 +553,8 @@ void DiveLocationLineEdit::showPopup() view->setGeometry(pos.x(), pos.y(), w, h); if (!view->isVisible()) { - view->show(); - view->setFocus(); + proxy->invalidate(); + view->show(); } } diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h index b52c03a9a..6df56f05c 100644 --- a/qt-ui/locationinformation.h +++ b/qt-ui/locationinformation.h @@ -90,11 +90,17 @@ public: class DiveLocationLineEdit : public QLineEdit { Q_OBJECT public: + enum DiveSiteType { NO_DIVE_SITE, NEW_DIVE_SITE, EXISTING_DIVE_SITE }; DiveLocationLineEdit(QWidget *parent =0 ); void refreshDiveSiteCache(); void setTemporaryDiveSiteName(const QString& s); bool eventFilter(QObject*, QEvent*); void itemActivated(const QModelIndex& index); + void setDiveSiteName(); + + DiveSiteType currDiveSiteType() const; + uint32_t currDiveSiteUuid() const; + protected: void keyPressEvent(QKeyEvent *ev); void showPopup(); @@ -102,6 +108,8 @@ private: DiveLocationFilterProxyModel *proxy; DiveLocationModel *model; DiveLocationListView *view; + DiveSiteType currType; + uint32_t currUuid; }; #endif -- cgit v1.2.3-70-g09d2 From 33a19328d8a34cc97f39f3726c9f1532742500e1 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 22 Sep 2015 15:23:38 -0300 Subject: Block focus out event The line edit wasn't being properly updated regarding its paint event. Turns out it was because it received a focus out event and then stopped refreshing the paint. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 9 ++++++++- qt-ui/locationinformation.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'qt-ui/locationinformation.cpp') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index 71def344e..822184473 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -396,7 +396,6 @@ int DiveLocationModel::rowCount(const QModelIndex& parent) const return dive_site_table.nr + 2; } - bool DiveLocationModel::setData(const QModelIndex& index, const QVariant& value, int role) { if(!index.isValid()) @@ -465,6 +464,14 @@ bool DiveLocationLineEdit::eventFilter(QObject *o, QEvent *e) return false; } +void DiveLocationLineEdit::focusOutEvent(QFocusEvent* ev) +{ + if (!view->isVisible()) { + qDebug() << "Focusing Out"; + QLineEdit::focusOutEvent(ev); + } +} + void DiveLocationLineEdit::itemActivated(const QModelIndex& index) { qDebug() << "Activated" << index.data(); diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h index 6df56f05c..2b41f5276 100644 --- a/qt-ui/locationinformation.h +++ b/qt-ui/locationinformation.h @@ -103,6 +103,7 @@ public: protected: void keyPressEvent(QKeyEvent *ev); + void focusOutEvent(QFocusEvent *ev); void showPopup(); private: DiveLocationFilterProxyModel *proxy; -- cgit v1.2.3-70-g09d2 From 43524127314d1fd6526dc5c23f1c42984b4d5c1b Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 22 Sep 2015 16:27:07 -0300 Subject: Correctly handle space and tab Space and tab should select the item in the itemview and hide it; enter and return also do that automatically. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'qt-ui/locationinformation.cpp') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index 822184473..c446cada7 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -449,10 +449,18 @@ bool DiveLocationLineEdit::eventFilter(QObject *o, QEvent *e) return true; } - if(keyEv->key() == Qt::Key_Return || keyEv->key() == Qt::Key_Enter) { + if(keyEv->key() == Qt::Key_Return || + keyEv->key() == Qt::Key_Enter) { view->hide(); return false; } + + if (keyEv->key() == Qt::Key_Space || + keyEv->key() == Qt::Key_Tab){ + itemActivated(view->currentIndex()); + view->hide(); + return false; + } event(e); } else if(e->type() == QEvent::MouseButtonPress ) { if (!view->underMouse()) { @@ -560,6 +568,7 @@ void DiveLocationLineEdit::showPopup() view->setGeometry(pos.x(), pos.y(), w, h); if (!view->isVisible()) { + setTemporaryDiveSiteName(text()); proxy->invalidate(); view->show(); } -- cgit v1.2.3-70-g09d2 From 80b42bd28bc9d98dc9f645a4f6e56c224ee855b2 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 22 Sep 2015 16:36:17 -0300 Subject: Set the current dive site uid / text Start to make this thing usefull: Upon selecting the current index or writting something on the line edit, we need to set the dive site. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'qt-ui/locationinformation.cpp') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index c446cada7..206b6eccf 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -357,6 +357,9 @@ void DiveLocationModel::resetModel() QVariant DiveLocationModel::data(const QModelIndex& index, int role) const { if(index.row() <= 1) { // two special cases. + if(index.column() == UUID) { + return RECENTLY_ADDED_DIVESITE; + } switch(role) { case Qt::DisplayRole : return new_ds_value[index.row()]; case Qt::ToolTipRole : return "Create a new dive site"; @@ -475,14 +478,17 @@ bool DiveLocationLineEdit::eventFilter(QObject *o, QEvent *e) void DiveLocationLineEdit::focusOutEvent(QFocusEvent* ev) { if (!view->isVisible()) { - qDebug() << "Focusing Out"; QLineEdit::focusOutEvent(ev); } } void DiveLocationLineEdit::itemActivated(const QModelIndex& index) { - qDebug() << "Activated" << index.data(); + QModelIndex uuidIndex = index.model()->index(index.row(), DiveLocationModel::UUID); + uint32_t uuid = uuidIndex.data().toInt(); + currType = uuid == 1 ? NEW_DIVE_SITE : EXISTING_DIVE_SITE; + currUuid = uuid; + setText(index.data().toString()); } void DiveLocationLineEdit::refreshDiveSiteCache() -- cgit v1.2.3-70-g09d2 From 4b8eec6c580dd33278bd6487a88575ad39b40378 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 22 Sep 2015 17:20:55 -0300 Subject: Fix new/existing dive site choices Only set the currType and currUuid if text changed. This is needed because if you hit key_down it would set NEW_DIVE_SITE because a keypress on the lineedit was due. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'qt-ui/locationinformation.cpp') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index 206b6eccf..bb07303dd 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -489,6 +489,10 @@ void DiveLocationLineEdit::itemActivated(const QModelIndex& index) currType = uuid == 1 ? NEW_DIVE_SITE : EXISTING_DIVE_SITE; currUuid = uuid; setText(index.data().toString()); + if(currUuid == NEW_DIVE_SITE) + qDebug() << "Setting a New dive site"; + else + qDebug() << "Setting a Existing dive site"; } void DiveLocationLineEdit::refreshDiveSiteCache() @@ -533,6 +537,11 @@ void DiveLocationLineEdit::keyPressEvent(QKeyEvent *ev) ev->key() != Qt::Key_Right && ev->key() != Qt::Key_Escape && ev->key() != Qt::Key_Return ) { + + if(ev->key() != Qt::Key_Up && ev->key() != Qt::Key_Down) { + currType = NEW_DIVE_SITE; + currUuid = RECENTLY_ADDED_DIVESITE; + } showPopup(); } else if (ev->key() == Qt::Key_Escape) { view->hide(); -- cgit v1.2.3-70-g09d2 From 7d863b5c280c12d657fa46f909965071d5649ac5 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Wed, 23 Sep 2015 13:56:49 -0300 Subject: Fix keyboard inconsistencies Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 12 ++++-------- qt-ui/locationinformation.h | 1 - 2 files changed, 4 insertions(+), 9 deletions(-) (limited to 'qt-ui/locationinformation.cpp') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index bb07303dd..2f4b8afda 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -433,15 +433,9 @@ DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent) : QLineEdit(parent), view->setFocusProxy(this); connect(this, &QLineEdit::textEdited, this, &DiveLocationLineEdit::setTemporaryDiveSiteName); - connect(this, &QLineEdit::editingFinished, this, &DiveLocationLineEdit::setDiveSiteName); connect(view, &QAbstractItemView::activated, this, &DiveLocationLineEdit::itemActivated); } -void DiveLocationLineEdit::setDiveSiteName() -{ - -} - bool DiveLocationLineEdit::eventFilter(QObject *o, QEvent *e) { if(e->type() == QEvent::KeyPress) { @@ -458,8 +452,7 @@ bool DiveLocationLineEdit::eventFilter(QObject *o, QEvent *e) return false; } - if (keyEv->key() == Qt::Key_Space || - keyEv->key() == Qt::Key_Tab){ + if (keyEv->key() == Qt::Key_Tab){ itemActivated(view->currentIndex()); view->hide(); return false; @@ -493,6 +486,8 @@ void DiveLocationLineEdit::itemActivated(const QModelIndex& index) qDebug() << "Setting a New dive site"; else qDebug() << "Setting a Existing dive site"; + if(view->isVisible()) + view->hide(); } void DiveLocationLineEdit::refreshDiveSiteCache() @@ -585,6 +580,7 @@ void DiveLocationLineEdit::showPopup() if (!view->isVisible()) { setTemporaryDiveSiteName(text()); proxy->invalidate(); + view->setCurrentIndex( view->model()->index(0,1)); view->show(); } } diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h index 2b41f5276..5085f83a2 100644 --- a/qt-ui/locationinformation.h +++ b/qt-ui/locationinformation.h @@ -96,7 +96,6 @@ public: void setTemporaryDiveSiteName(const QString& s); bool eventFilter(QObject*, QEvent*); void itemActivated(const QModelIndex& index); - void setDiveSiteName(); DiveSiteType currDiveSiteType() const; uint32_t currDiveSiteUuid() const; -- cgit v1.2.3-70-g09d2 From e4c0ee32cdcd8487dd88e40fef3ba5de6fa92704 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Wed, 23 Sep 2015 14:46:29 -0300 Subject: Handle palette change for dive site selection If you select a dive site with a different uuid than your current dive.dive_site_uuid, you should get a different pallete to state clearly that something changed. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 13 ++++++++++++- qt-ui/locationinformation.h | 3 +++ qt-ui/maintab.cpp | 9 ++++++++- qt-ui/maintab.h | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) (limited to 'qt-ui/locationinformation.cpp') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index 2f4b8afda..77adc819b 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -488,6 +488,7 @@ void DiveLocationLineEdit::itemActivated(const QModelIndex& index) qDebug() << "Setting a Existing dive site"; if(view->isVisible()) view->hide(); + emit diveSiteSelected(currUuid); } void DiveLocationLineEdit::refreshDiveSiteCache() @@ -580,11 +581,21 @@ void DiveLocationLineEdit::showPopup() if (!view->isVisible()) { setTemporaryDiveSiteName(text()); proxy->invalidate(); - view->setCurrentIndex( view->model()->index(0,1)); + view->setCurrentIndex(view->model()->index(0,1)); view->show(); } } +DiveLocationLineEdit::DiveSiteType DiveLocationLineEdit::currDiveSiteType() const +{ + return currType; +} + +uint32_t DiveLocationLineEdit::currDiveSiteUuid() const +{ + return currUuid; +} + DiveLocationListView::DiveLocationListView(QWidget *parent) { diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h index 5085f83a2..db0d286ac 100644 --- a/qt-ui/locationinformation.h +++ b/qt-ui/locationinformation.h @@ -100,6 +100,9 @@ public: DiveSiteType currDiveSiteType() const; uint32_t currDiveSiteUuid() const; +signals: + void diveSiteSelected(uint32_t uuid); + protected: void keyPressEvent(QKeyEvent *ev); void focusOutEvent(QFocusEvent *ev); diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 51df81d87..a68adb5bf 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -1509,7 +1509,7 @@ void MainTab::on_location_textChanged() markChangedWidget(ui.location); } -void MainTab::on_location_editingFinished() +void MainTab::on_location_diveSiteSelected() { if (editMode == IGNORE || acceptingEdit == true) return; @@ -1519,6 +1519,13 @@ void MainTab::on_location_editingFinished() markChangedWidget(ui.location); emit diveSiteChanged(0); return; + } else { + if (ui.location->currDiveSiteUuid() != displayed_dive.dive_site_uuid) { + markChangedWidget(ui.location); + } else { + QPalette p; + ui.location->setPalette(p); + } } if (currentTrip) { diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index 26dd3853e..a071e6c88 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -69,7 +69,7 @@ slots: void updateDiveInfo(bool clear = false); void acceptChanges(); void rejectChanges(); - void on_location_editingFinished(); + void on_location_diveSiteSelected(); void on_location_textChanged(); void on_divemaster_textChanged(); void on_buddy_textChanged(); -- cgit v1.2.3-70-g09d2 From d586970f3145106d444af8c54651af6563b92a66 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Wed, 23 Sep 2015 14:57:55 -0300 Subject: Removed a ton of dead code Unused dead code / hack for the old QCompleter Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 55 ------------------------------------------- qt-ui/locationinformation.h | 15 +----------- qt-ui/maintab.cpp | 38 +----------------------------- qt-ui/maintab.h | 3 --- 4 files changed, 2 insertions(+), 109 deletions(-) (limited to 'qt-ui/locationinformation.cpp') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index 77adc819b..3b3e02b12 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -259,61 +259,6 @@ void LocationInformationWidget::resetPallete() ui.diveSiteNotes->setPalette(p); } -bool LocationManagementEditHelper::eventFilter(QObject *obj, QEvent *ev) -{ - QListView *view = qobject_cast(obj); - if(!view) - return false; - - if(ev->type() == QEvent::Show) { - last_uuid = 0; - qDebug() << "EventFilter: " << last_uuid; - } - - if(ev->type() == QEvent::KeyPress) { - QKeyEvent *keyEv = (QKeyEvent*) ev; - if(keyEv->key() == Qt::Key_Return) { - handleActivation(view->currentIndex()); - view->hide(); - return true; - } - } - return false; -} - -void LocationManagementEditHelper::handleActivation(const QModelIndex& activated) -{ - if (!activated.isValid()) - return; - QModelIndex uuidIdx = activated.model()->index( - activated.row(), LocationInformationModel::UUID); - last_uuid = uuidIdx.data().toInt(); - - /* if we are in 'recently added divesite mode, create a new divesite, - * and go to dive site edit edit mode. */ - if (last_uuid == RECENTLY_ADDED_DIVESITE) { - uint32_t ds_uuid = create_dive_site_from_current_dive(qPrintable(activated.data().toString())); - qDebug() << "ds_uuid" << ds_uuid; - struct dive_site *ds = get_dive_site_by_uuid(ds_uuid); - copy_dive_site(ds, &displayed_dive_site); - displayed_dive.dive_site_uuid = ds->uuid; - last_uuid = ds->uuid; - // Move this out of here later. - MainWindow::instance()->startDiveSiteEdit(); - } - - qDebug() << "Selected dive_site: " << last_uuid; -} - -void LocationManagementEditHelper::resetDiveSiteUuid() { - last_uuid = 0; - qDebug() << "Reset: " << last_uuid; -} - -uint32_t LocationManagementEditHelper::diveSiteUuid() const { - return last_uuid; -} - void LocationInformationWidget::reverseGeocode() { ReverseGeoLookupThread *geoLookup = ReverseGeoLookupThread::instance(); diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h index db0d286ac..db6809015 100644 --- a/qt-ui/locationinformation.h +++ b/qt-ui/locationinformation.h @@ -46,19 +46,6 @@ private: QAction *closeAction, *acceptAction, *rejectAction; }; -class LocationManagementEditHelper : public QObject { -Q_OBJECT -public: - bool eventFilter(QObject *obj, QEvent *ev); - void handleActivation(const QModelIndex& activated); - void resetDiveSiteUuid(); - uint32_t diveSiteUuid() const; -signals: - void setLineEditText(const QString& text); -private: - uint32_t last_uuid; -}; - class DiveLocationFilterProxyModel : public QSortFilterProxyModel { Q_OBJECT public: @@ -96,7 +83,6 @@ public: void setTemporaryDiveSiteName(const QString& s); bool eventFilter(QObject*, QEvent*); void itemActivated(const QModelIndex& index); - DiveSiteType currDiveSiteType() const; uint32_t currDiveSiteUuid() const; @@ -107,6 +93,7 @@ protected: void keyPressEvent(QKeyEvent *ev); void focusOutEvent(QFocusEvent *ev); void showPopup(); + private: DiveLocationFilterProxyModel *proxy; DiveLocationModel *model; diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index a68adb5bf..8dca49eee 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -195,7 +195,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), connect(ReverseGeoLookupThread::instance(), &QThread::finished, this, &MainTab::setCurrentLocationIndex); - ui.location->installEventFilter(this); acceptingEdit = false; } @@ -210,33 +209,6 @@ MainTab::~MainTab() } } -bool MainTab::eventFilter(QObject *obj, QEvent *ev) -{ - QMoveEvent *mEv; - QResizeEvent *rEv; - QLineEdit *line = qobject_cast(obj); - - if (ev->type() == QEvent::MouseMove || ev->type() == QEvent::HoverMove || ev->type() == QEvent::Paint) - return false; - - if (line) { - if (ev->type() == QEvent::Resize) { - /*if (line->completer()->popup()->isVisible()) { - QListView *choices = qobject_cast(line->completer()->popup()); - QPoint p = ui.location->mapToGlobal(ui.location->pos()); - choices->setGeometry( - choices->geometry().x(), - p.y() + 3, - choices->geometry().width(), - choices->geometry().height()); - - } - */ - } - } - return false; -} - void MainTab::setCurrentLocationIndex() { if (current_dive) { @@ -318,12 +290,6 @@ void MainTab::displayMessage(QString str) ui.diveStatisticsMessage->setText(str); ui.diveStatisticsMessage->animatedShow(); updateTextLabels(); - -// TODO: this doesn't exists anymore. Find out why it was removed from -// the KMessageWidget and try to see if this is still needed. -// ui.tagWidget->fixPopupPosition(ui.diveNotesMessage->bestContentHeight()); -// ui.buddy->fixPopupPosition(ui.diveNotesMessage->bestContentHeight()); -// ui.divemaster->fixPopupPosition(ui.diveNotesMessage->bestContentHeight()); } void MainTab::updateTextLabels(bool showUnits) @@ -377,7 +343,6 @@ void MainTab::enableEdition(EditMode newEditMode) displayMessage(tr("Multiple dives are being edited.")); } else { displayMessage(tr("This dive is being edited.")); - //locationManagementEditHelper->resetDiveSiteUuid(); } editMode = newEditMode != NONE ? newEditMode : DIVE; } @@ -844,7 +809,6 @@ void MainTab::updateDisplayedDiveSite() const uint32_t orig_uuid = displayed_dive_site.uuid; //TODO: FIX THIS const uint32_t new_uuid = orig_uuid; - // locationManagementEditHelper->diveSiteUuid(); qDebug() << "Updating Displayed Dive Site"; @@ -891,7 +855,7 @@ void MainTab::updateDiveSite(int divenr) return; const uint32_t newUuid = displayed_dive_site.uuid; - const uint32_t pickedUuid = locationManagementEditHelper->diveSiteUuid(); + const uint32_t pickedUuid = ui.location->currDiveSiteUuid(); const QString newName = displayed_dive_site.name; const uint32_t origUuid = cd->dive_site_uuid; struct dive_site *origDs = get_dive_site_by_uuid(origUuid); diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index a071e6c88..502ea6910 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -22,7 +22,6 @@ class CylindersModel; class ExtraDataModel; class DivePictureModel; class QCompleter; -class LocationManagementEditHelper; struct Completers { QCompleter *divemaster; @@ -55,7 +54,6 @@ public: void refreshDisplayedDiveSite(); void nextInputField(QKeyEvent *event); void showAndTriggerEditSelective(struct dive_components what); - virtual bool eventFilter(QObject*, QEvent*); signals: void addDiveFinished(); @@ -124,7 +122,6 @@ private: dive_trip_t *currentTrip; dive_trip_t displayedTrip; bool acceptingEdit; - LocationManagementEditHelper *locationManagementEditHelper; void updateDisplayedDiveSite(); void updateDiveSite(int divenr); }; -- cgit v1.2.3-70-g09d2 From 5b3d52acecbe9aac8dd6641fe04703696fa49380 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Wed, 23 Sep 2015 16:03:28 -0300 Subject: Correctly fix the popup position When the message to 'This dive site is being edited' was being show while the popup to choose the dive site, the line edit was being covered. now it correctly moves to the correct place. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 6 +++++- qt-ui/locationinformation.h | 2 +- qt-ui/maintab.cpp | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) (limited to 'qt-ui/locationinformation.cpp') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index 3b3e02b12..56ef2d7f3 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -489,7 +489,7 @@ void DiveLocationLineEdit::keyPressEvent(QKeyEvent *ev) } } -void DiveLocationLineEdit::showPopup() +void DiveLocationLineEdit::fixPopupPosition() { const QRect screen = QApplication::desktop()->availableGeometry(this); const int maxVisibleItems = 5; @@ -522,7 +522,11 @@ void DiveLocationLineEdit::showPopup() } view->setGeometry(pos.x(), pos.y(), w, h); +} +void DiveLocationLineEdit::showPopup() +{ + fixPopupPosition(); if (!view->isVisible()) { setTemporaryDiveSiteName(text()); proxy->invalidate(); diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h index db6809015..3e8adeae2 100644 --- a/qt-ui/locationinformation.h +++ b/qt-ui/locationinformation.h @@ -85,7 +85,7 @@ public: void itemActivated(const QModelIndex& index); DiveSiteType currDiveSiteType() const; uint32_t currDiveSiteUuid() const; - + void fixPopupPosition(); signals: void diveSiteSelected(uint32_t uuid); diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 8dca49eee..867d7a172 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -195,6 +195,9 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), connect(ReverseGeoLookupThread::instance(), &QThread::finished, this, &MainTab::setCurrentLocationIndex); + connect(ui.diveNotesMessage, &KMessageWidget::showAnimationFinished, + ui.location, &DiveLocationLineEdit::fixPopupPosition); + acceptingEdit = false; } -- cgit v1.2.3-70-g09d2 From d95856d3b272671fe9db008605ea84b27195f46b Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Wed, 23 Sep 2015 16:19:58 -0300 Subject: Select an index if no index is selected Defaults to first row. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'qt-ui/locationinformation.cpp') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index 56ef2d7f3..8e08a60be 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -522,6 +522,9 @@ void DiveLocationLineEdit::fixPopupPosition() } view->setGeometry(pos.x(), pos.y(), w, h); + if(!view->currentIndex().isValid()) { + view->setCurrentIndex(view->model()->index(0,1)); + } } void DiveLocationLineEdit::showPopup() @@ -530,7 +533,6 @@ void DiveLocationLineEdit::showPopup() if (!view->isVisible()) { setTemporaryDiveSiteName(text()); proxy->invalidate(); - view->setCurrentIndex(view->model()->index(0,1)); view->show(); } } -- cgit v1.2.3-70-g09d2 From a9642d57518a7132648ea70be35bfd0af282fadc Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Wed, 23 Sep 2015 16:27:44 -0300 Subject: Do not display popup with modifiers Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'qt-ui/locationinformation.cpp') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index 8e08a60be..6e6db0b34 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -469,6 +469,9 @@ void DiveLocationLineEdit::setTemporaryDiveSiteName(const QString& s) model->setData(i1, i1_name ); proxy->invalidate(); + fixPopupPosition(); + if (!view->isVisible()) + view->show(); } void DiveLocationLineEdit::keyPressEvent(QKeyEvent *ev) @@ -482,8 +485,9 @@ void DiveLocationLineEdit::keyPressEvent(QKeyEvent *ev) if(ev->key() != Qt::Key_Up && ev->key() != Qt::Key_Down) { currType = NEW_DIVE_SITE; currUuid = RECENTLY_ADDED_DIVESITE; + } else { + showPopup(); } - showPopup(); } else if (ev->key() == Qt::Key_Escape) { view->hide(); } -- cgit v1.2.3-70-g09d2