mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Merge branch 'tomaz-css' into Qt
Tomaz' code does a much better job of shading the dive list! Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
commit
ff2ce39970
10 changed files with 106 additions and 16 deletions
9
dive.c
9
dive.c
|
@ -1810,6 +1810,15 @@ struct dive *merge_dives(struct dive *a, struct dive *b, int offset, gboolean pr
|
||||||
return res;
|
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)
|
struct dive *find_dive_including(timestamp_t when)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
2
dive.h
2
dive.h
|
@ -350,6 +350,8 @@ struct dive {
|
||||||
struct divecomputer dc;
|
struct divecomputer dc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern int get_index_for_dive(struct dive *dive);
|
||||||
|
|
||||||
static inline int dive_has_gps_location(struct dive *dive)
|
static inline int dive_has_gps_location(struct dive *dive)
|
||||||
{
|
{
|
||||||
return dive->latitude.udeg || dive->longitude.udeg;
|
return dive->latitude.udeg || dive->longitude.udeg;
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include "divelistview.h"
|
#include "divelistview.h"
|
||||||
#include "models.h"
|
#include "models.h"
|
||||||
#include "modeldelegates.h"
|
#include "modeldelegates.h"
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QHeaderView>
|
||||||
|
|
||||||
DiveListView::DiveListView(QWidget *parent) : QTreeView(parent)
|
DiveListView::DiveListView(QWidget *parent) : QTreeView(parent)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "../divelist.h"
|
#include "../divelist.h"
|
||||||
#include "../pref.h"
|
#include "../pref.h"
|
||||||
#include "modeldelegates.h"
|
#include "modeldelegates.h"
|
||||||
|
#include "models.h"
|
||||||
|
|
||||||
MainWindow::MainWindow() : ui(new Ui::MainWindow()),
|
MainWindow::MainWindow() : ui(new Ui::MainWindow()),
|
||||||
model(new DiveTripModel(this)),
|
model(new DiveTripModel(this)),
|
||||||
|
@ -33,6 +34,7 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()),
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
sortModel->setSourceModel(model);
|
sortModel->setSourceModel(model);
|
||||||
ui->ListWidget->setModel(sortModel);
|
ui->ListWidget->setModel(sortModel);
|
||||||
|
connect(ui->ListWidget, SIGNAL(activated(QModelIndex)), this, SLOT(diveSelected(QModelIndex)));
|
||||||
|
|
||||||
/* figure out appropriate widths for the columns. The strings chosen
|
/* figure out appropriate widths for the columns. The strings chosen
|
||||||
* are somewhat random (but at least we're trying to allow them to be
|
* are somewhat random (but at least we're trying to allow them to be
|
||||||
|
@ -70,6 +72,16 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()),
|
||||||
readSettings();
|
readSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::diveSelected(const QModelIndex& index)
|
||||||
|
{
|
||||||
|
struct dive *dive = (struct dive*) index.model()->data(index, TreeItemDT::DIVE_ROLE).value<void*>();
|
||||||
|
|
||||||
|
if (dive)
|
||||||
|
selected_dive = get_index_for_dive(dive);
|
||||||
|
|
||||||
|
// Here should be the code to update the other widgets.
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionNew_triggered()
|
void MainWindow::on_actionNew_triggered()
|
||||||
{
|
{
|
||||||
qDebug("actionNew");
|
qDebug("actionNew");
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QModelIndex>
|
||||||
|
|
||||||
class QSortFilterProxyModel;
|
class QSortFilterProxyModel;
|
||||||
class DiveTripModel;
|
class DiveTripModel;
|
||||||
|
@ -66,6 +67,8 @@ private Q_SLOTS:
|
||||||
void on_actionAboutSubsurface_triggered();
|
void on_actionAboutSubsurface_triggered();
|
||||||
void on_actionUserManual_triggered();
|
void on_actionUserManual_triggered();
|
||||||
|
|
||||||
|
void diveSelected(const QModelIndex& index);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *);
|
void closeEvent(QCloseEvent *);
|
||||||
|
|
||||||
|
|
|
@ -28,9 +28,55 @@
|
||||||
<widget class="QGraphicsView" name="ProfileWidget"/>
|
<widget class="QGraphicsView" name="ProfileWidget"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="DiveListView" name="ListWidget">
|
<widget class="DiveListView" name="ListWidget">
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true"> 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
</string>
|
||||||
|
</property>
|
||||||
|
<property name="alternatingRowColors">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||||
|
</property>
|
||||||
|
<property name="rootIsDecorated">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
<property name="sortingEnabled">
|
<property name="sortingEnabled">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="animated">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="allColumnsShowFocus">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -42,7 +88,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>763</width>
|
<width>763</width>
|
||||||
<height>20</height>
|
<height>19</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuFile">
|
<widget class="QMenu" name="menuFile">
|
||||||
|
|
|
@ -7,18 +7,24 @@
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
#include <QStyle>
|
||||||
|
#include <QStyleOption>
|
||||||
|
|
||||||
|
StarWidgetsDelegate::StarWidgetsDelegate(QWidget* parent):
|
||||||
|
QStyledItemDelegate(parent),
|
||||||
|
parentWidget(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
|
QStyledItemDelegate::paint(painter, option, index);
|
||||||
|
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QVariant value = index.model()->data(index, Qt::DisplayRole);
|
QVariant value = index.model()->data(index, TreeItemDT::STAR_ROLE);
|
||||||
|
|
||||||
if(option.state & QStyle::State_Selected)
|
|
||||||
painter->fillRect(option.rect, option.palette.highlight());
|
|
||||||
else
|
|
||||||
painter->fillRect(option.rect, index.model()->data(index, Qt::BackgroundRole).value<QBrush>());
|
|
||||||
|
|
||||||
if (!value.isValid())
|
if (!value.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
#ifndef MODELDELEGATES_H
|
#ifndef MODELDELEGATES_H
|
||||||
#define MODELDELEGATES_H
|
#define MODELDELEGATES_H
|
||||||
|
|
||||||
#include <QAbstractItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
class StarWidgetsDelegate : public QAbstractItemDelegate {
|
class StarWidgetsDelegate : public QStyledItemDelegate {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
explicit StarWidgetsDelegate(QWidget* parent = 0);
|
||||||
virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||||
virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||||
|
private:
|
||||||
|
QWidget *parentWidget;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -490,12 +490,18 @@ QVariant DiveItem::data(int column, int role) const
|
||||||
case LOCATION:
|
case LOCATION:
|
||||||
retVal = QString(dive->location);
|
retVal = QString(dive->location);
|
||||||
break;
|
break;
|
||||||
case RATING:
|
|
||||||
retVal = dive->rating;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(role == STAR_ROLE){
|
||||||
|
retVal = dive->rating;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(role == DIVE_ROLE){
|
||||||
|
retVal = QVariant::fromValue<void*>(dive);
|
||||||
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -601,9 +607,6 @@ QVariant DiveTripModel::data(const QModelIndex& index, int role) const
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
if (role == Qt::BackgroundRole)
|
|
||||||
return QBrush(QColor(index.row() % 2 ? Qt::white : QColor(Qt::lightGray).lighter(120)));
|
|
||||||
|
|
||||||
TreeItemDT* item = static_cast<TreeItemDT*>(index.internalPointer());
|
TreeItemDT* item = static_cast<TreeItemDT*>(index.internalPointer());
|
||||||
|
|
||||||
return item->data(index.column(), role);
|
return item->data(index.column(), role);
|
||||||
|
|
|
@ -82,7 +82,11 @@ private:
|
||||||
struct TreeItemDT {
|
struct TreeItemDT {
|
||||||
Q_DECLARE_TR_FUNCTIONS ( TreeItemDT );
|
Q_DECLARE_TR_FUNCTIONS ( TreeItemDT );
|
||||||
public:
|
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();
|
virtual ~TreeItemDT();
|
||||||
int columnCount() const {
|
int columnCount() const {
|
||||||
return COLUMNS;
|
return COLUMNS;
|
||||||
|
|
Loading…
Reference in a new issue