@@ -10,17 +10,24 @@ module FF.Qt.TaskWidget (
1010 reload ,
1111) where
1212
13+ import Control.Monad (void , when )
1314import Data.Foldable (for_ )
1415import Data.IORef (IORef , atomicWriteIORef , newIORef , readIORef )
1516import Data.Maybe (fromMaybe )
17+ import Data.Text qualified as Text
1618import Data.Time (defaultTimeLocale , formatTime )
19+ import Foreign.Hoppy.Runtime (delete , nullptr )
1720import Graphics.UI.Qtah.Core.Types qualified as Qt
18- import Graphics.UI.Qtah.Flags (Flags (enumToFlags ))
1921import Graphics.UI.Qtah.Signal (connect_ )
2022import Graphics.UI.Qtah.Widgets.QAbstractButton qualified as QAbstractButton
23+ import Graphics.UI.Qtah.Widgets.QBoxLayout qualified as QBoxLayout
2124import Graphics.UI.Qtah.Widgets.QFrame (QFrame )
25+ import Graphics.UI.Qtah.Widgets.QHBoxLayout (QHBoxLayout )
2226import Graphics.UI.Qtah.Widgets.QLabel (QLabel )
2327import Graphics.UI.Qtah.Widgets.QLabel qualified as QLabel
28+ import Graphics.UI.Qtah.Widgets.QLayout (QLayoutPtr )
29+ import Graphics.UI.Qtah.Widgets.QLayout qualified as QLayout
30+ import Graphics.UI.Qtah.Widgets.QLayoutItem qualified as QLayoutItem
2431import Named (defaults , (!) )
2532import RON.Storage.FS (runStorage )
2633import RON.Storage.FS qualified as Storage
@@ -59,13 +66,15 @@ type OnTaskUpdated =
5966 IO ()
6067
6168data TaskWidget = TaskWidget
62- { parent :: QFrame
69+ { storage :: Storage. Handle
70+ , noteId :: IORef (Maybe NoteId )
71+ , onTaskUpdated :: OnTaskUpdated
72+ , -- UI
73+ parent :: QFrame
6374 , textContent :: QLabel
64- , storage :: Storage. Handle
75+ , tags :: QHBoxLayout
6576 , start :: DateComponent
6677 , end :: DateComponent
67- , noteId :: IORef (Maybe NoteId )
68- , onTaskUpdated :: OnTaskUpdated
6978 , created :: QLabel
7079 , updated :: QLabel
7180 , recurring :: QLabel
@@ -82,20 +91,23 @@ new storage onTaskUpdated = do
8291 ! # objectName " textContent"
8392 ! # openExternalLinks True
8493 ! # textFormat Qt. MarkdownText
85- ! # textInteractionFlags (enumToFlags Qt. TextBrowserInteraction )
94+ ! # textInteractionFlags Qt. textBrowserInteraction
8695 ! # wordWrap True
8796 ! defaults
88- postpone <- qPushButton ! # objectName " postpone" ! # text " Postpone"
89- done <- qPushButton ! # objectName " postpone" ! # text " Done"
97+ tags <- qHBoxLayout ! # spacing 0 ! defaults $ []
98+ postpone <-
99+ qPushButton ! # objectName " postpone" ! # text " Postpone" ! defaults
100+ done <- qPushButton ! # objectName " done" ! # text " Done" ! defaults
90101 created <- qLabel ! # objectName " created" ! defaults
91102 updated <- qLabel ! # objectName " updated" ! defaults
92103 recurring <- qLabel ! # objectName " recurring" ! defaults
93104 parent <-
94105 qFrame ! # objectName " parent" $
95106 QFormLayout
96107 [ RowWidget $ qScrollArea textContent
97- , StringLayout " Start:" start. parent
98- , StringLayout " Deadline:" end. parent
108+ , StringLayout " Tags:" $< tags
109+ , StringLayout " Start:" $< start. parent
110+ , StringLayout " Deadline:" $< end. parent
99111 , StringWidget " Created:" $< created
100112 , StringWidget " Updated:" $< updated
101113 , StringWidget " Recurring:" $< recurring
@@ -132,6 +144,7 @@ update keepOpen this noteDoc = do
132144 entity <- runStorage this. storage $ viewNote noteDoc
133145 let Entity {entityVal = view@ NoteView {note}} = entity
134146 QLabel. setText this. textContent $ fromRgaM note. note_text
147+ resetTags view. tags
135148 DateComponent. setDate this. start note. note_start
136149 DateComponent. setDate this. end note. note_end
137150 QLabel. setText this. created $
@@ -142,3 +155,20 @@ update keepOpen this noteDoc = do
142155 this. recurring
143156 if fromMaybe False note. note_recurring then " Yes" else " No"
144157 this. onTaskUpdated keepOpen entity
158+ where
159+ resetTags tags = do
160+ deleteChildrenWidgets this. tags
161+ for_ tags \ tag ->
162+ void $
163+ QBoxLayout. addWidget this. tags
164+ =<< qPushButton ! # text (Text. unpack tag) ! defaults
165+
166+ deleteChildrenWidgets :: (QLayoutPtr layout ) => layout -> IO ()
167+ deleteChildrenWidgets layout = loop
168+ where
169+ loop = do
170+ child <- QLayout. takeAt layout 0
171+ when (child /= nullptr) do
172+ delete =<< QLayoutItem. widget child
173+ delete child
174+ loop
0 commit comments