Skip to content

Commit 6e15280

Browse files
committed
ff-qtah: Move dates and actions out of scrollable area in TaskWidget
1 parent 59d5813 commit 6e15280

File tree

3 files changed

+33
-31
lines changed

3 files changed

+33
-31
lines changed

.hlint.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
- error: {lhs: a $ b, rhs: a b, side: isRecUpdate b || isRecConstr b}
22
- ignore: {name: Use camelCase}
3+
- ignore: {name: Use uncurry}

ff-qtah/FF/Qt/EDSL.hs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module FF.Qt.EDSL where
88

99
import Data.Foldable (for_)
1010
import Graphics.UI.Qtah.Core.Types qualified as Qt
11+
import Graphics.UI.Qtah.Widgets.QBoxLayout (QBoxLayoutPtr)
1112
import Graphics.UI.Qtah.Widgets.QBoxLayout qualified as QBoxLayout
1213
import Graphics.UI.Qtah.Widgets.QFormLayout qualified as QFormLayout
1314
import Graphics.UI.Qtah.Widgets.QFrame (QFrame)
@@ -20,9 +21,10 @@ import Graphics.UI.Qtah.Widgets.QLayout (QLayoutPtr (toQLayout))
2021
import Graphics.UI.Qtah.Widgets.QScrollArea (QScrollArea)
2122
import Graphics.UI.Qtah.Widgets.QScrollArea qualified as QScrollArea
2223
import Graphics.UI.Qtah.Widgets.QSizePolicy (QSizePolicyPolicy)
24+
import Graphics.UI.Qtah.Widgets.QVBoxLayout qualified as QVBoxLayout
2325
import Graphics.UI.Qtah.Widgets.QWidget (QWidgetPtr, toQWidget)
2426
import Graphics.UI.Qtah.Widgets.QWidget qualified as QWidget
25-
import Named (arg, (:!))
27+
import Named (arg, argF, (:!), (:?))
2628

2729
data QBoxLayoutItem
2830
= Stretch
@@ -33,22 +35,32 @@ data QFormLayoutItem
3335
| forall a. (QWidgetPtr a) => RowWidget (IO a)
3436
| forall a. (QLayoutPtr a) => StringLayout String a
3537

36-
-- newtype Layout = QFormLayout [QFormLayoutItem]
38+
data Layout
39+
= QFormLayout [QFormLayoutItem]
40+
| QVBoxLayout [QBoxLayoutItem]
3741

38-
qFrame :: [QFormLayoutItem] -> IO QFrame
39-
qFrame items = do
42+
qFrame :: Layout -> IO QFrame
43+
qFrame lo = do
4044
obj <- QFrame.new
41-
-- case lo of
42-
-- QFormLayout items -> do
43-
form <- QFormLayout.newWithParent obj
44-
for_ items $ addRow form
45+
case lo of
46+
QFormLayout items -> do
47+
form <- QFormLayout.newWithParent obj
48+
for_ items $ addRow form
49+
QVBoxLayout items -> do
50+
box <- QVBoxLayout.newWithParent obj
51+
for_ items $ addBoxLayoutItem box
4552
pure obj
4653
where
4754
addRow form = \case
4855
RowLayout io -> QFormLayout.addRowLayout form . toQLayout =<< io
4956
RowWidget io -> QFormLayout.addRowWidget form . toQWidget =<< io
5057
StringLayout s c -> QFormLayout.addRowStringLayout form s $ toQLayout c
5158

59+
addBoxLayoutItem :: (QBoxLayoutPtr p) => p -> QBoxLayoutItem -> IO ()
60+
addBoxLayoutItem box = \case
61+
Stretch -> QBoxLayout.addStretch box
62+
Widget io -> QBoxLayout.addWidget box =<< io
63+
5264
hline :: IO QFrame
5365
hline = do
5466
obj <- QFrame.new
@@ -58,31 +70,29 @@ hline = do
5870
qHBoxLayout :: [QBoxLayoutItem] -> IO QHBoxLayout
5971
qHBoxLayout items = do
6072
obj <- QHBoxLayout.new
61-
for_ items \case
62-
Stretch -> QBoxLayout.addStretch obj
63-
Widget io -> QBoxLayout.addWidget obj =<< io
73+
for_ items $ addBoxLayoutItem obj
6474
pure obj
6575

6676
qLabel ::
6777
(Qt.IsQtTextInteractionFlags textInteractionFlags) =>
6878
"alignment" :! Qt.QtAlignmentFlag ->
6979
"openExternalLinks" :! Bool ->
70-
"sizePolicy" :! (QSizePolicyPolicy, QSizePolicyPolicy) ->
80+
"sizePolicy" :? (QSizePolicyPolicy, QSizePolicyPolicy) ->
7181
"textInteractionFlags" :! textInteractionFlags ->
7282
"textFormat" :! Qt.QtTextFormat ->
7383
"wordWrap" :! Bool ->
7484
IO QLabel
7585
qLabel
7686
(arg #alignment -> a)
7787
(arg #openExternalLinks -> oel)
78-
(arg #sizePolicy -> (sp1, sp2))
88+
(argF #sizePolicy -> sp)
7989
(arg #textInteractionFlags -> tif)
8090
(arg #textFormat -> tf)
8191
(arg #wordWrap -> ww) = do
8292
obj <- QLabel.new
8393
QLabel.setAlignment obj a
8494
QLabel.setOpenExternalLinks obj oel
85-
QWidget.setSizePolicyRaw obj sp1 sp2
95+
for_ sp \(sp1, sp2) -> QWidget.setSizePolicyRaw obj sp1 sp2
8696
QLabel.setTextInteractionFlags obj tif
8797
QLabel.setTextFormat obj tf
8898
QLabel.setWordWrap obj ww
@@ -92,4 +102,5 @@ qScrollArea :: (QWidgetPtr widget) => widget -> IO QScrollArea
92102
qScrollArea w = do
93103
obj <- QScrollArea.new
94104
QScrollArea.setWidget obj w
105+
QScrollArea.setWidgetResizable obj True
95106
pure obj

ff-qtah/FF/Qt/TaskWidget.hs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ import Graphics.UI.Qtah.Widgets.QFrame (QFrame)
1818
import Graphics.UI.Qtah.Widgets.QLabel (QLabel)
1919
import Graphics.UI.Qtah.Widgets.QLabel qualified as QLabel
2020
import Graphics.UI.Qtah.Widgets.QPushButton qualified as QPushButton
21-
import Graphics.UI.Qtah.Widgets.QScrollArea (QScrollArea)
22-
import Graphics.UI.Qtah.Widgets.QSizePolicy (
23-
QSizePolicyPolicy (..),
24-
)
25-
import Graphics.UI.Qtah.Widgets.QWidget qualified as QWidget
26-
import Named ((!))
21+
import Named (defaults, (!))
2722
import RON.Storage.FS (runStorage)
2823
import RON.Storage.FS qualified as Storage
2924

@@ -41,9 +36,9 @@ import FF.Types (
4136
import FF.Qt.DateComponent (DateComponent)
4237
import FF.Qt.DateComponent qualified as DateComponent
4338
import FF.Qt.EDSL (
39+
Layout (..),
4440
QBoxLayoutItem (..),
4541
QFormLayoutItem (..),
46-
hline,
4742
qFrame,
4843
qHBoxLayout,
4944
qLabel,
@@ -57,9 +52,7 @@ type OnTaskUpdated =
5752
IO ()
5853

5954
data TaskWidget = TaskWidget
60-
{ parent :: QScrollArea
61-
, innerWidget :: QFrame
62-
-- ^ the main widget inside the scroll area
55+
{ parent :: QFrame
6356
, textContent :: QLabel
6457
, storage :: Storage.Handle
6558
, start :: DateComponent
@@ -78,20 +71,18 @@ new storage onTaskUpdated = do
7871
qLabel
7972
! #alignment Qt.AlignTop
8073
! #openExternalLinks True
81-
! #sizePolicy (MinimumExpanding, MinimumExpanding)
8274
! #textInteractionFlags Qt.TextBrowserInteraction
8375
! #textFormat Qt.MarkdownText
8476
! #wordWrap True
77+
! defaults
8578
postpone <- QPushButton.newWithText "Postpone"
86-
innerWidget <-
87-
qFrame
88-
[ RowWidget $ pure textContent
89-
, RowWidget hline
79+
parent <-
80+
qFrame . QFormLayout $
81+
[ RowWidget $ qScrollArea textContent
9082
, StringLayout "Start:" start.parent
9183
, StringLayout "Deadline:" end.parent
9284
, RowLayout $ qHBoxLayout [Widget $ pure postpone, Stretch]
9385
]
94-
parent <- qScrollArea innerWidget
9586
-- end setup UI
9687

9788
noteId <- newIORef Nothing
@@ -121,5 +112,4 @@ update keepOpen this noteDoc = do
121112
QLabel.setText this.textContent $ fromRgaM note_text
122113
DateComponent.setDate this.start note_start
123114
DateComponent.setDate this.end note_end
124-
QWidget.adjustSize this.innerWidget
125115
this.onTaskUpdated keepOpen entity

0 commit comments

Comments
 (0)