1+ {-# LANGUAGE BlockArguments #-}
12{-# LANGUAGE NamedFieldPuns #-}
23{-# LANGUAGE OverloadedRecordDot #-}
34
45module FF.Qt.TaskWidget (
56 TaskWidget (parent ),
67 new ,
7- update ,
8+ reload ,
89) where
910
10- -- global
11+ import Data.IORef ( IORef , atomicWriteIORef , newIORef , readIORef )
1112import Foreign.Hoppy.Runtime (toGc )
1213import Graphics.UI.Qtah.Core.Types (QtAlignmentFlag (AlignTop ))
14+ import Graphics.UI.Qtah.Signal (connect_ )
15+ import Graphics.UI.Qtah.Widgets.QAbstractButton qualified as QAbstractButton
1316import Graphics.UI.Qtah.Widgets.QBoxLayout qualified as QBoxLayout
1417import Graphics.UI.Qtah.Widgets.QFormLayout qualified as QFormLayout
1518import Graphics.UI.Qtah.Widgets.QFrame (QFrame )
@@ -18,25 +21,24 @@ import Graphics.UI.Qtah.Widgets.QHBoxLayout qualified as QHBoxLayout
1821import Graphics.UI.Qtah.Widgets.QLabel (QLabel )
1922import Graphics.UI.Qtah.Widgets.QLabel qualified as QLabel
2023import Graphics.UI.Qtah.Widgets.QPushButton qualified as QPushButton
21- import Graphics.UI.Qtah.Widgets.QScrollArea (QScrollArea )
24+ import Graphics.UI.Qtah.Widgets.QScrollArea (QScrollArea , setWidget )
2225import Graphics.UI.Qtah.Widgets.QScrollArea qualified as QScrollArea
2326import Graphics.UI.Qtah.Widgets.QSizePolicy (QSizePolicy , QSizePolicyPolicy )
2427import Graphics.UI.Qtah.Widgets.QSizePolicy qualified as QSizePolicy
2528import Graphics.UI.Qtah.Widgets.QWidget qualified as QWidget
2629import RON.Storage.FS (runStorage )
2730import RON.Storage.FS qualified as Storage
2831
29- -- project
30- import FF (fromRgaM , viewNote )
32+ import FF (cmdPostpone , fromRgaM , viewNote )
3133import FF.Types (
3234 Entity (.. ),
35+ EntityDoc ,
3336 Note (.. ),
3437 NoteId ,
3538 View (NoteView , note ),
3639 loadNote ,
3740 )
3841
39- -- package
4042import FF.Qt.DateComponent (DateComponent )
4143import FF.Qt.DateComponent qualified as DateComponent
4244
@@ -48,14 +50,15 @@ data TaskWidget = TaskWidget
4850 , storage :: Storage. Handle
4951 , start :: DateComponent
5052 , end :: DateComponent
53+ , noteId :: IORef (Maybe NoteId )
5154 }
5255
5356new :: Storage. Handle -> IO TaskWidget
5457new storage = do
5558 parent <- QScrollArea. new
5659
5760 innerWidget <- QFrame. new
58- QScrollArea. setWidget parent innerWidget
61+ setWidget parent innerWidget
5962
6063 textContent <- QLabel. new
6164 QWidget. setSizePolicy textContent
@@ -83,11 +86,39 @@ new storage = do
8386 QBoxLayout. addStretch actions
8487 QFormLayout. addRowLayout form actions
8588
86- pure TaskWidget {parent, innerWidget, textContent, storage, start, end}
87-
88- update :: TaskWidget -> NoteId -> IO ()
89- update this noteId = do
90- Entity {entityVal} <- runStorage this. storage $ loadNote noteId >>= viewNote
89+ noteId <- newIORef Nothing
90+
91+ let this =
92+ TaskWidget
93+ { parent
94+ , innerWidget
95+ , textContent
96+ , storage
97+ , start
98+ , end
99+ , noteId
100+ }
101+
102+ connect_ postpone QAbstractButton. clickedSignal $ postponeSlot this
103+
104+ pure this
105+
106+ postponeSlot :: TaskWidget -> Bool -> IO ()
107+ postponeSlot this _checked = do
108+ mNoteId <- readIORef this. noteId
109+ case mNoteId of
110+ Just noteId ->
111+ runStorage this. storage (cmdPostpone noteId) >>= update this
112+ Nothing -> pure ()
113+
114+ reload :: TaskWidget -> NoteId -> IO ()
115+ reload this noteId = do
116+ atomicWriteIORef this. noteId $ Just noteId
117+ runStorage this. storage (loadNote noteId) >>= update this
118+
119+ update :: TaskWidget -> EntityDoc Note -> IO ()
120+ update this noteDoc = do
121+ Entity {entityVal} <- runStorage this. storage $ viewNote noteDoc
91122 let NoteView {note} = entityVal
92123 let Note {note_text, note_start, note_end} = note
93124 QLabel. setText this. textContent $ fromRgaM note_text
0 commit comments