From 770f8b1e85e996268ea441b67a94fcf38fd2a2cb Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Wed, 7 Jan 2015 15:04:15 -0200
Subject: [PATCH 1/3] Added Delegate Skeleton for the Drag Columns

this new class is the responsible to draw the Columns
that can be dragged from the Top bar to the Bottom one.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/divelogimportdialog.cpp | 15 +++++++++++++++
 qt-ui/divelogimportdialog.h   |  9 +++++++++
 2 files changed, 24 insertions(+)

diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index ebd46f2..7343cd4 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -431,3 +431,18 @@ void DiveLogImportDialog::on_buttonBox_accepted()
 	process_dives(true, false);
 	MainWindow::instance()->refreshDisplay();
 }
+
+TagDragDelegate::TagDragDelegate(QObject *parent) : QStyledItemDelegate(parent)
+{
+}
+
+QSize	TagDragDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
+{
+	return QStyledItemDelegate::sizeHint(option, index);
+}
+
+void TagDragDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
+{
+	QStyledItemDelegate::paint(painter, option, index);
+}
+
diff --git a/qt-ui/divelogimportdialog.h b/qt-ui/divelogimportdialog.h
index 7e43434..b6fed1c 100644
--- a/qt-ui/divelogimportdialog.h
+++ b/qt-ui/divelogimportdialog.h
@@ -7,6 +7,7 @@
 #include <QDragLeaveEvent>
 #include <QTableView>
 #include <QAbstractTableModel>
+#include <QStyledItemDelegate>
 
 #include "../dive.h"
 #include "../divelist.h"
@@ -109,4 +110,12 @@ private:
 	static const CSVAppConfig CSVApps[CSVAPPS];
 };
 
+class TagDragDelegate : public QStyledItemDelegate {
+	Q_OBJECT
+public:
+	TagDragDelegate(QObject *parent);
+	QSize	sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const;
+	void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
+};
+
 #endif // DIVELOGIMPORTDIALOG_H
-- 
2.2.1

From b6a4ee1eaffde35579313b610b83b5cacea702ef Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Wed, 7 Jan 2015 15:09:29 -0200
Subject: [PATCH 2/3] Give the items a bit more spacing / Enable the Delegate

Enable the new delegate on the view, and give the items
a bit more spacing, so we can draw things around them.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/divelogimportdialog.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index 7343cd4..37c456a 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -315,7 +315,7 @@ DiveLogImportDialog::DiveLogImportDialog(QStringList fn, QWidget *parent) : QDia
 
 	ColumnNameProvider *provider = new ColumnNameProvider(this);
 	ui->avaliableColumns->setModel(provider);
-
+	ui->avaliableColumns->setItemDelegate(new TagDragDelegate(ui->avaliableColumns));
 	resultModel = new ColumnNameResult(this);
 	ui->tableView->setModel(resultModel);
 
@@ -438,7 +438,8 @@ TagDragDelegate::TagDragDelegate(QObject *parent) : QStyledItemDelegate(parent)
 
 QSize	TagDragDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
 {
-	return QStyledItemDelegate::sizeHint(option, index);
+	QSize originalSize = QStyledItemDelegate::sizeHint(option, index);
+	return originalSize + QSize(5,5);
 }
 
 void TagDragDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
-- 
2.2.1

From 3b0a0fc9b2104fe4ffae47a3851d6545abe1baad Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Wed, 7 Jan 2015 15:19:19 -0200
Subject: [PATCH 3/3] Draw a nice rounded rect on the Avaliable Columns

This drawns a nice rounded rect around the avaliable
columns, using antialiasing.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/divelogimportdialog.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index 37c456a..ba3adf5 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -444,6 +444,10 @@ QSize	TagDragDelegate::sizeHint(const QStyleOptionViewItem & option, const QMode
 
 void TagDragDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
 {
+	painter->save();
+	painter->setRenderHints(QPainter::Antialiasing);
+	painter->drawRoundedRect(option.rect.adjusted(4,4,-4,-4), 5, 5);
+	painter->restore();
 	QStyledItemDelegate::paint(painter, option, index);
 }
 
-- 
2.2.1

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to