summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-07-01 21:04:03 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-01 19:25:14 -0700
commit4059f5d995ccbacf6e334bd80590942212799f4b (patch)
tree2de732db3d731f5064755a6904ca25ffc065a6a1 /qt-ui
parent3b0936eca3d143c8a75d16b5d7acd0b7d6b3cf1b (diff)
downloadsubsurface-4059f5d995ccbacf6e334bd80590942212799f4b.tar.gz
Correctly display the data on the delegate
A bit more complex than I tought it would be (and a ton of trial and error to find the right spot on the delegate to draw stuff) this delegate follows the current style (so it should be okaish on a dark and on a light theme) This is supposed to work on a QCompleter, but it doesn't (I really don't know why, so maybe I'll remove that completer. sigh.) Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/maintab.cpp14
-rw-r--r--qt-ui/modeldelegates.cpp59
2 files changed, 66 insertions, 7 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index fe1143f39..144a43094 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -63,6 +63,17 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
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()));
@@ -107,9 +118,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)));
- 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));
diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
index 8425d03c9..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
{
@@ -483,14 +488,60 @@ 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->drawText(QPoint(0, 0), index.data().toString());
+ 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
{
- QSize size;
- size.setWidth(option.rect.width());
- size.setHeight(20);
+ 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;
}