Skip to content

Commit 44a6cc8

Browse files
committed
ff-qtah: Add display real dates in start/end fields
1 parent e9d23ee commit 44a6cc8

2 files changed

Lines changed: 34 additions & 15 deletions

File tree

ff-qtah/FF/Qt/DateComponent.hs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{-# LANGUAGE NamedFieldPuns #-}
2+
{-# LANGUAGE ViewPatterns #-}
23

3-
module FF.Qt.DateComponent (DateComponent (super), new) where
4+
module FF.Qt.DateComponent (DateComponent (super), new, setDate) where
45

5-
-- global
6+
import Data.Time (Day, toGregorian)
7+
import Graphics.UI.Qtah.Core.QDate qualified as QDate
68
import Graphics.UI.Qtah.Widgets.QAbstractSpinBox qualified as QAbstractSpinBox
79
import Graphics.UI.Qtah.Widgets.QBoxLayout qualified as QBoxLayout
810
import Graphics.UI.Qtah.Widgets.QDateEdit (QDateEdit)
@@ -28,6 +30,7 @@ new title = do
2830

2931
dateEdit <- QDateEdit.new
3032
QDateTimeEdit.setCalendarPopup dateEdit True
33+
QDateTimeEdit.setDisplayFormat dateEdit "ddd d MMM yyyy"
3134
QBoxLayout.addWidget super dateEdit
3235

3336
QBoxLayout.addStretch super
@@ -39,3 +42,12 @@ new title = do
3942
setEditable :: DateComponent -> Bool -> IO ()
4043
setEditable DateComponent{dateEdit} editable =
4144
QAbstractSpinBox.setReadOnly dateEdit $ not editable
45+
46+
setDate :: DateComponent -> Maybe Day -> IO ()
47+
setDate DateComponent{dateEdit} day = do
48+
qdate <-
49+
case day of
50+
Just (toGregorian -> (y, m, d)) ->
51+
QDate.newWithYmd (fromInteger y) m d
52+
Nothing -> QDate.new -- TODO replace with button "add date"
53+
QDateTimeEdit.setDate dateEdit qdate

ff-qtah/FF/Qt/TaskWidget.hs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,25 @@ import RON.Storage.FS qualified as Storage
2828
import FF (fromRgaM, viewNote)
2929
import FF.Types (
3030
Entity (..),
31-
Note (Note, note_text),
31+
Note (..),
3232
NoteId,
3333
View (NoteView, note),
3434
loadNote,
3535
)
3636

3737
-- package
38+
import FF.Qt.DateComponent (DateComponent)
3839
import FF.Qt.DateComponent qualified as DateComponent
3940

4041
data TaskWidget = TaskWidget
4142
{ super :: QScrollArea
4243
, frame :: QFrame
43-
, label :: QLabel
44+
-- ^ widget inside the scroll area
45+
, textLabel :: QLabel
46+
-- ^ label for the text
4447
, storage :: Storage.Handle
48+
, start :: DateComponent
49+
, end :: DateComponent
4550
}
4651

4752
new :: Storage.Handle -> IO TaskWidget
@@ -51,29 +56,31 @@ new storage = do
5156
frame <- QFrame.new
5257
QScrollArea.setWidget super frame
5358

54-
label <- QLabel.new
55-
QWidget.setSizePolicy label
59+
textLabel <- QLabel.new
60+
QWidget.setSizePolicy textLabel
5661
=<< makeSimpleSizePolicy QSizePolicy.MinimumExpanding
57-
QLabel.setAlignment label AlignTop
58-
QLabel.setWordWrap label True
62+
QLabel.setAlignment textLabel AlignTop
63+
QLabel.setWordWrap textLabel True
5964

6065
start <- DateComponent.new "Start:"
6166
end <- DateComponent.new "Deadline:"
6267

6368
box <- QVBoxLayout.newWithParent frame
64-
QBoxLayout.addWidget box label
69+
QBoxLayout.addWidget box textLabel
6570
QBoxLayout.addLayout box start.super
6671
QBoxLayout.addLayout box end.super
6772

68-
pure TaskWidget{super, frame, label, storage}
73+
pure TaskWidget{super, frame, textLabel, storage, start, end}
6974

7075
update :: TaskWidget -> NoteId -> IO ()
71-
update TaskWidget{frame, label, storage} noteId = do
72-
Entity{entityVal} <- runStorage storage $ loadNote noteId >>= viewNote
76+
update this noteId = do
77+
Entity{entityVal} <- runStorage this.storage $ loadNote noteId >>= viewNote
7378
let NoteView{note} = entityVal
74-
let Note{note_text} = note
75-
QLabel.setText label $ fromRgaM note_text
76-
QWidget.adjustSize frame
79+
let Note{note_text, note_start, note_end} = note
80+
QLabel.setText this.textLabel $ fromRgaM note_text
81+
DateComponent.setDate this.start note_start
82+
DateComponent.setDate this.end note_end
83+
QWidget.adjustSize this.frame
7784

7885
makeSimpleSizePolicy :: QSizePolicyPolicy -> IO QSizePolicy
7986
makeSimpleSizePolicy policy =

0 commit comments

Comments
 (0)