Compare commits

...

2 Commits

Author SHA1 Message Date
jordi fita mas 8677051303 Shift TimelineView’s items half a day
They are supposed to show how many _nigths_ guests are staying in
lodgins, thus they arrive at afternoon and leave at morning; the shift
puts the starting position at midday.
2025-01-20 11:09:07 +01:00
jordi fita mas b9c68f4b76 Show weekends in alternate base background color 2025-01-20 11:00:11 +01:00
5 changed files with 25 additions and 2 deletions

View File

@ -213,7 +213,9 @@ Control {
Repeater {
delegate: Rectangle {
color: "transparent"
required property bool isWeekend
color: isWeekend ? palette.alternateBase : "transparent"
height: parent.height
width: control.dayWidth

View File

@ -14,7 +14,10 @@ Control {
model: model
delegate: Label {
id: delegate
required property string display
required property bool isWeekend
anchors.bottom: parent.bottom
anchors.top: parent.top
@ -24,6 +27,10 @@ Control {
verticalAlignment: Text.AlignVCenter
width: control.dayWidth
background: Rectangle {
color: delegate.isWeekend ? delegate.palette.alternateBase : "transparent"
}
Separator {
anchors.bottom: parent.bottom
anchors.right: parent.right

View File

@ -25,11 +25,20 @@ QVariant TimelineDayModel::data(const QModelIndex &index, int role) const
switch (role) {
case Qt::DisplayRole:
return QString::number(date.day());
case WeekendRole:
return date.dayOfWeek() > 5;
}
return {};
}
QHash<int, QByteArray> TimelineDayModel::roleNames() const
{
QHash<int, QByteArray> roles = QAbstractListModel::roleNames();
roles[WeekendRole] = "isWeekend";
return roles;
}
QDate TimelineDayModel::fromDate() const
{
return m_fromDate;

View File

@ -13,10 +13,15 @@ class TimelineDayModel : public QAbstractListModel
Q_PROPERTY(QDate toDate READ toDate WRITE setToDate NOTIFY toDateChanged)
public:
enum Role {
WeekendRole = Qt::UserRole,
};
explicit TimelineDayModel(QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override;
QDate fromDate() const;
void setFromDate(QDate date);

View File

@ -9,7 +9,7 @@ struct TimelineView::Item
, day(day)
{
item->setParentItem(&view);
item->setPosition(QPointF(day * view.dayWidth(), 0.0));
item->setPosition(QPointF(day * view.dayWidth() + view.dayWidth() / 2, 0.0));
item->setSize(QSizeF(len * view.dayWidth(), view.height()));
item->setVisible(true);
}