From 82b1b04920fdd5882e0cbf28c9871c2ddd404af8 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 2 May 2013 19:27:36 -0300 Subject: Test the CSS for styling the TableView This is a test and I shouldn't be taken seriously. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/divelistview.cpp | 2 ++ qt-ui/mainwindow.ui | 79 +++++++++++++++++++++++++++++++++++++++++++++++- qt-ui/modeldelegates.cpp | 14 +++++++-- qt-ui/modeldelegates.h | 7 +++-- qt-ui/models.cpp | 5 ++- 5 files changed, 99 insertions(+), 8 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index 45b6cf4d7..0bf0b35ba 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -7,6 +7,8 @@ #include "divelistview.h" #include "models.h" #include "modeldelegates.h" +#include +#include DiveListView::DiveListView(QWidget *parent) : QTreeView(parent) { diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui index 073476918..1d31f1cd3 100644 --- a/qt-ui/mainwindow.ui +++ b/qt-ui/mainwindow.ui @@ -28,9 +28,86 @@ + + QTreeView { + show-decoration-selected: 1; + } + + QTreeView::item { + border: 1px solid #d9d9d9; + border-top-color: transparent; + border-bottom-color: transparent; + padding: 2px; + } + + QTreeView::item:hover { + background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1); + border: 1px solid #bfcde4; + } + + QTreeView::item:selected { + border: 1px solid #567dbc; + } + + QTreeView::item:selected:active{ + background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6ea1f1, stop: 1 #567dbc); + } + + QTreeView::item:selected:!active { + background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6b9be8, stop: 1 #577fbf); + } + + +/* + QTreeView::branch { + background: palette(base); + } + + QTreeView::branch:has-siblings:!adjoins-item { + background: cyan; + } + + QTreeView::branch:has-siblings:adjoins-item { + background: red; + } + + QTreeView::branch:!has-children:!has-siblings:adjoins-item { + background: blue; + } + + QTreeView::branch:closed:has-children:has-siblings { + background: pink; + } + + QTreeView::branch:has-children:!has-siblings:closed { + background: gray; + } + + QTreeView::branch:open:has-children:has-siblings { + background: magenta; + } + + QTreeView::branch:open:has-children:!has-siblings { + background: green; + } +*/ + + + + true + + + true + true + + true + + + true + @@ -42,7 +119,7 @@ 0 0 763 - 20 + 19 diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp index 87629bd1b..0b3231583 100644 --- a/qt-ui/modeldelegates.cpp +++ b/qt-ui/modeldelegates.cpp @@ -7,9 +7,21 @@ #include #include #include +#include +#include +#include +#include + +StarWidgetsDelegate::StarWidgetsDelegate(QWidget* parent): + QStyledItemDelegate(parent), + parentWidget(parent) +{ + +} void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { + QStyledItemDelegate::paint(painter, option, index); if (!index.isValid()) return; @@ -20,8 +32,6 @@ void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o int rating = value.toInt(); - if(option.state & QStyle::State_Selected) - painter->fillRect(option.rect, option.palette.highlight()); painter->save(); painter->setRenderHint(QPainter::Antialiasing, true); diff --git a/qt-ui/modeldelegates.h b/qt-ui/modeldelegates.h index eacbb5a1e..5f90a3061 100644 --- a/qt-ui/modeldelegates.h +++ b/qt-ui/modeldelegates.h @@ -1,12 +1,15 @@ #ifndef MODELDELEGATES_H #define MODELDELEGATES_H -#include +#include -class StarWidgetsDelegate : public QAbstractItemDelegate { +class StarWidgetsDelegate : public QStyledItemDelegate { Q_OBJECT public: + explicit StarWidgetsDelegate(QWidget* parent = 0); virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; +private: + QWidget *parentWidget; }; #endif diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 68f575ec8..061ffe418 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -7,6 +7,8 @@ #include "models.h" #include #include +#include +#include extern struct tank_info tank_info[100]; @@ -598,9 +600,6 @@ QVariant DiveTripModel::data(const QModelIndex& index, int role) const if (!index.isValid()) return QVariant(); - if (role != Qt::DisplayRole) - return QVariant(); - TreeItemDT* item = static_cast(index.internalPointer()); return item->data(index.column(), role); -- cgit v1.2.3-70-g09d2 From 696c9ccacd24392ea63477c5ec8a25d6649aedf7 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 2 May 2013 20:32:57 -0300 Subject: Added code to Select a dive, fixed minor annoyances. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- dive.c | 9 +++++++++ dive.h | 2 ++ qt-ui/mainwindow.cpp | 12 ++++++++++++ qt-ui/mainwindow.h | 3 +++ qt-ui/mainwindow.ui | 37 +++---------------------------------- qt-ui/modeldelegates.cpp | 3 ++- qt-ui/models.cpp | 12 +++++++++--- qt-ui/models.h | 6 +++++- 8 files changed, 45 insertions(+), 39 deletions(-) (limited to 'qt-ui') diff --git a/dive.c b/dive.c index 34025d68c..2c2307e41 100644 --- a/dive.c +++ b/dive.c @@ -1810,6 +1810,15 @@ struct dive *merge_dives(struct dive *a, struct dive *b, int offset, gboolean pr return res; } +int get_index_for_dive(struct dive *dive) { + int i; + struct dive *d; + for_each_dive(i, d) + if (d == dive) + return i; + return -1; +} + struct dive *find_dive_including(timestamp_t when) { int i; diff --git a/dive.h b/dive.h index f2153587f..c13cac0aa 100644 --- a/dive.h +++ b/dive.h @@ -350,6 +350,8 @@ struct dive { struct divecomputer dc; }; +extern int get_index_for_dive(struct dive *dive); + static inline int dive_has_gps_location(struct dive *dive) { return dive->latitude.udeg || dive->longitude.udeg; diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 9901e4186..ae2794e3c 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -23,6 +23,7 @@ #include "../divelist.h" #include "../pref.h" #include "modeldelegates.h" +#include "models.h" MainWindow::MainWindow() : ui(new Ui::MainWindow()), model(new DiveTripModel(this)), @@ -31,11 +32,22 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()), ui->setupUi(this); sortModel->setSourceModel(model); ui->ListWidget->setModel(sortModel); + connect(ui->ListWidget, SIGNAL(activated(QModelIndex)), this, SLOT(diveSelected(QModelIndex))); setWindowIcon(QIcon(":subsurface-icon")); readSettings(); } +void MainWindow::diveSelected(const QModelIndex& index) +{ + struct dive *dive = (struct dive*) index.model()->data(index, TreeItemDT::DIVE_ROLE).value(); + + if (dive) + selected_dive = get_index_for_dive(dive); + + // Here should be the code to update the other widgets. +} + void MainWindow::on_actionNew_triggered() { qDebug("actionNew"); diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index eece91ade..e94cb5b7c 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -8,6 +8,7 @@ #define MAINWINDOW_H #include +#include class QSortFilterProxyModel; class DiveTripModel; @@ -66,6 +67,8 @@ private Q_SLOTS: void on_actionAboutSubsurface_triggered(); void on_actionUserManual_triggered(); + void diveSelected(const QModelIndex& index); + protected: void closeEvent(QCloseEvent *); diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui index 1d31f1cd3..fe97d98b4 100644 --- a/qt-ui/mainwindow.ui +++ b/qt-ui/mainwindow.ui @@ -57,45 +57,14 @@ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6b9be8, stop: 1 #577fbf); } - -/* - QTreeView::branch { - background: palette(base); - } - - QTreeView::branch:has-siblings:!adjoins-item { - background: cyan; - } - - QTreeView::branch:has-siblings:adjoins-item { - background: red; - } - - QTreeView::branch:!has-children:!has-siblings:adjoins-item { - background: blue; - } - - QTreeView::branch:closed:has-children:has-siblings { - background: pink; - } - - QTreeView::branch:has-children:!has-siblings:closed { - background: gray; - } - - QTreeView::branch:open:has-children:has-siblings { - background: magenta; - } - - QTreeView::branch:open:has-children:!has-siblings { - background: green; - } -*/ true + + QAbstractItemView::ExtendedSelection + true diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp index 0b3231583..33c1717e6 100644 --- a/qt-ui/modeldelegates.cpp +++ b/qt-ui/modeldelegates.cpp @@ -22,10 +22,11 @@ StarWidgetsDelegate::StarWidgetsDelegate(QWidget* parent): void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QStyledItemDelegate::paint(painter, option, index); + if (!index.isValid()) return; - QVariant value = index.model()->data(index, Qt::DisplayRole); + QVariant value = index.model()->data(index, TreeItemDT::STAR_ROLE); if (!value.isValid()) return; diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 061ffe418..bdc3a7576 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -490,11 +490,17 @@ QVariant DiveItem::data(int column, int role) const case LOCATION: retVal = QString(dive->location); break; - case RATING: - retVal = dive->rating; - break; } } + + if(role == STAR_ROLE){ + retVal = dive->rating; + } + + if(role == DIVE_ROLE){ + retVal = QVariant::fromValue(dive); + } + return retVal; } diff --git a/qt-ui/models.h b/qt-ui/models.h index d063874d3..307cdf5c3 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -82,7 +82,11 @@ private: struct TreeItemDT { Q_DECLARE_TR_FUNCTIONS ( TreeItemDT ); public: - enum Column {NR, DATE, RATING, DEPTH, DURATION, TEMPERATURE, TOTALWEIGHT, SUIT, CYLINDER, NITROX, SAC, OTU, MAXCNS, LOCATION, COLUMNS }; + enum Column {NR, DATE, RATING, DEPTH, DURATION, TEMPERATURE, TOTALWEIGHT, + SUIT, CYLINDER, NITROX, SAC, OTU, MAXCNS, LOCATION, DIVE, COLUMNS }; + + enum ExtraRoles{STAR_ROLE = Qt::UserRole + 1, DIVE_ROLE}; + virtual ~TreeItemDT(); int columnCount() const { return COLUMNS; -- cgit v1.2.3-70-g09d2