summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/maintab.cpp30
-rw-r--r--qt-ui/maintab.h2
-rw-r--r--qt-ui/modeldelegates.cpp69
-rw-r--r--qt-ui/modeldelegates.h9
-rw-r--r--qt-ui/printdialog.cpp2
-rw-r--r--qt-ui/printdialog.h2
6 files changed, 100 insertions, 14 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index dd6ce72b0..591f665d5 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -58,6 +58,24 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
ui.extraData->setModel(extraDataModel);
closeMessage();
+ QCompleter *completer = new QCompleter();
+ completer->setModel(LocationInformationModel::instance());
+ completer->setCompletionColumn(LocationInformationModel::NAME);
+ completer->setCompletionRole(Qt::DisplayRole);
+ completer->setCompletionMode(QCompleter::PopupCompletion);
+ completer->setCaseSensitivity(Qt::CaseInsensitive);
+
+ QListView *completerListview = new QListView();
+ completerListview->setItemDelegate(new LocationFilterDelegate());
+ completer->setPopup(completerListview);
+
+ QListView *completerListView2 = new QListView();
+ completerListView2->setItemDelegate(new LocationFilterDelegate());
+ completerListView2->setModel(LocationInformationModel::instance());
+ completerListView2->setModelColumn(1);
+ completerListView2->show();
+
+ ui.location->setCompleter(completer);
connect(ui.addDiveSite, SIGNAL(clicked()), this, SLOT(showDiveSiteSimpleEdit()));
connect(ui.geocodeButton, SIGNAL(clicked()), this, SLOT(reverseGeocode()));
@@ -101,11 +119,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
connect(ui.cylinders->view(), SIGNAL(clicked(QModelIndex)), this, SLOT(editCylinderWidget(QModelIndex)));
connect(ui.weights->view(), SIGNAL(clicked(QModelIndex)), this, SLOT(editWeightWidget(QModelIndex)));
- LocationCompletionModel *locationCompletion = new LocationCompletionModel();
- ui.location->setCompleter(new QCompleter(locationCompletion));
- ui.location->completer()->setCaseSensitivity(Qt::CaseInsensitive);
- ui.location->completer()->setCompletionMode(QCompleter::PopupCompletion);
-
ui.cylinders->view()->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this));
ui.cylinders->view()->setItemDelegateForColumn(CylindersModel::USE, new TankUseDelegate(this));
ui.weights->view()->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate(this));
@@ -471,9 +484,6 @@ void MainTab::updateDiveInfo(bool clear)
struct dive *prevd;
char buf[1024];
- LocationCompletionModel *m = qobject_cast<LocationCompletionModel*>(ui.location->completer()->model());
- m->updateModel();
-
process_selected_dives();
process_all_dives(&displayed_dive, &prevd);
@@ -768,9 +778,9 @@ void MainTab::reload()
{
suitModel.updateModel();
buddyModel.updateModel();
- locationModel.updateModel();
diveMasterModel.updateModel();
tagModel.updateModel();
+ LocationInformationModel::instance()->update();
}
// tricky little macro to edit all the selected dives
@@ -1382,8 +1392,6 @@ void MainTab::on_location_editingFinished()
markChangedWidget(ui.location);
LocationInformationModel::instance()->update();
- LocationCompletionModel *m = qobject_cast<LocationCompletionModel*>(ui.location->completer()->model());
- m->updateModel();
emit diveSiteChanged(uuid);
return;
}
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index eac1521cc..306aee66e 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -14,6 +14,7 @@
#include "ui_maintab.h"
#include "completionmodels.h"
+#include "divelocationmodel.h"
#include "dive.h"
class WeightModel;
@@ -106,7 +107,6 @@ private:
EditMode editMode;
BuddyCompletionModel buddyModel;
DiveMasterCompletionModel diveMasterModel;
- LocationCompletionModel locationModel;
SuitCompletionModel suitModel;
TagCompletionModel tagModel;
DivePictureModel *divePictureModel;
diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
index 827e6ab27..68e62a5cb 100644
--- a/qt-ui/modeldelegates.cpp
+++ b/qt-ui/modeldelegates.cpp
@@ -10,10 +10,15 @@
#include "weigthsysteminfomodel.h"
#include "weightmodel.h"
#include "divetripmodel.h"
+#include "qthelper.h"
#include <QCompleter>
#include <QKeyEvent>
#include <QTextDocument>
+#include <QApplication>
+#include <QFont>
+#include <QBrush>
+#include <QColor>
QSize DiveListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
@@ -476,3 +481,67 @@ QSize HTMLDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModel
doc.setTextWidth(options.rect.width());
return QSize(doc.idealWidth(), doc.size().height());
}
+
+LocationFilterDelegate::LocationFilterDelegate(QObject *parent)
+{
+}
+
+void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+ QFont fontBigger = qApp->font();
+ QFont fontSmaller = qApp->font();
+ QFontMetrics fmBigger(fontBigger);
+ QStyleOptionViewItemV4 opt = option;
+ QStyledItemDelegate::initStyleOption(&opt, index);
+ QBrush bg;
+ QString diveSiteName = index.data().toString();
+
+ struct dive_site *ds = get_dive_site_by_uuid(
+ index.model()->data(index.model()->index(index.row(),0)).toInt()
+ );
+ if (!ds)
+ return;
+
+ const char *gpsCoords = printGPSCoords(displayed_dive_site.latitude.udeg, displayed_dive_site.longitude.udeg);
+ QString diveSiteCoords(gpsCoords);
+ free( (void*) gpsCoords);
+
+ fontBigger.setPointSize(fontBigger.pointSize() + 2);
+ fontBigger.setBold(true);
+
+ painter->save();
+ painter->setRenderHint(QPainter::Antialiasing);
+ if( ( option.state & QStyle::State_Selected ) || ( option.state & QStyle::State_MouseOver ) )
+ bg = option.palette.highlight();
+ else
+ bg = option.palette.window();
+ painter->setPen(QPen(Qt::NoPen));
+ painter->setBrush(bg);
+ painter->drawRect(option.rect);
+ painter->restore();
+
+ painter->save();
+ painter->setBrush(option.palette.text());
+ painter->setFont(fontBigger);
+ painter->drawText(option.rect.x(),option.rect.y() + fmBigger.boundingRect("YH").height(), diveSiteName);
+ painter->setFont(fontSmaller);
+ painter->setBrush(option.palette.brightText());
+ painter->drawText(option.rect.x(),option.rect.y() + fmBigger.boundingRect("YH").height() * 2, diveSiteCoords);
+ painter->restore();
+}
+
+QSize LocationFilterDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+ QFont fontBigger = qApp->font();
+ fontBigger.setPointSize(fontBigger.pointSize() + 2);
+ fontBigger.setBold(true);
+
+ QFontMetrics fmBigger(fontBigger);
+
+ QFont fontSmaller = qApp->font();
+ QFontMetrics fmSmaller(fontSmaller);
+
+ QSize retSize = QStyledItemDelegate::sizeHint(option, index);
+ retSize.setHeight(fmBigger.boundingRect("Yellow House").height() + 5 /*spacing*/ + fmSmaller.boundingRect("Yellow House").height());
+ return retSize;
+}
diff --git a/qt-ui/modeldelegates.h b/qt-ui/modeldelegates.h
index f501c5214..95701775a 100644
--- a/qt-ui/modeldelegates.h
+++ b/qt-ui/modeldelegates.h
@@ -129,4 +129,13 @@ public:
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
+
+class LocationFilterDelegate : public QStyledItemDelegate {
+ Q_OBJECT
+public:
+ LocationFilterDelegate(QObject *parent = 0);
+ void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
+ QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
+};
+
#endif // MODELDELEGATES_H
diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp
index 4a3314691..6f30f89f5 100644
--- a/qt-ui/printdialog.cpp
+++ b/qt-ui/printdialog.cpp
@@ -2,6 +2,7 @@
#include "printoptions.h"
#include "mainwindow.h"
+#ifndef NO_PRINTING
#include <QProgressBar>
#include <QPrintPreviewDialog>
#include <QPrintDialog>
@@ -10,7 +11,6 @@
#define SETTINGS_GROUP "PrintDialog"
-#ifndef NO_PRINTING
PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
{
// check if the options were previously stored in the settings; if not use some defaults.
diff --git a/qt-ui/printdialog.h b/qt-ui/printdialog.h
index 9937cd549..a34037442 100644
--- a/qt-ui/printdialog.h
+++ b/qt-ui/printdialog.h
@@ -1,12 +1,12 @@
#ifndef PRINTDIALOG_H
#define PRINTDIALOG_H
+#ifndef NO_PRINTING
#include <QDialog>
#include <QPrinter>
#include "printoptions.h"
#include "printer.h"
-#ifndef NO_PRINTING
class QProgressBar;
class PrintOptions;
class PrintLayout;