module Controller.Menu.File.Export.ImageParameters (Parameters (..),defaultParams,fileTypeList,fileTypeFromInt ,intFromFileType) where import Util.Color (Color (..)) import Util.FileType (FileType(..),extension) import Util.Sexp (Sexp(..)) import Util.Sexpable (Sexpable(..),PSE,recordToSexp,recordFromSexp) import I18n (__) data Parameters = Parameters { fontPointSize :: Int , fontColor :: Color , backgroundColor :: Color , padding :: Int , rowLineWidth :: Int , colLineWidth :: Int , fileType :: Maybe FileType } defaultParams :: Parameters defaultParams = Parameters 10 (Color (0,0,0)) (Color (255,255,255)) 3 1 1 Nothing instance Sexpable Parameters where toSexp = recordToSexp [ ("fontPointSize", toSexp . fontPointSize) , ("fontColor", toSexp . fontColor) , ("backgroundColor", toSexp . backgroundColor) , ("padding", toSexp . padding) , ("rowLineWidth", toSexp . rowLineWidth) , ("colLineWidth", toSexp . colLineWidth) , ("fileType", toSexp . fileType) ] fromSexp = recordFromSexp setParam defaultParams setParam :: Parameters -> Sexp -> PSE Parameters setParam p sexp = case sexp of List [Atom "fontPointSize",fps] -> do parameter <- fromSexp fps return $ p {fontPointSize = parameter} List [Atom "fontColor",color] -> do parameter <- fromSexp color return $ p {fontColor = parameter} List [Atom "backgroundColor",color] -> do parameter <- fromSexp color return $ p {backgroundColor = parameter} List [Atom "padding",padding] -> do parameter <- fromSexp padding return $ p {padding = parameter} List [Atom "rowLineWidth",width] -> do parameter <- fromSexp width return $ p {rowLineWidth = parameter} List [Atom "colLineWidth",width] -> do parameter <- fromSexp width return $ p {colLineWidth = parameter} List [Atom "fileType",fileType] -> do parameter <- fromSexp fileType return $ p {fileType = parameter} _ -> return p fileTypeList :: [String] fileTypeList = [ (__ "By extension") , extension Bmp, extension Jpeg , extension Png, extension Tif] fileTypeFromInt :: Int -> Maybe FileType fileTypeFromInt i = case i of 0 -> Nothing 1 -> Just Bmp 2 -> Just Jpeg 3 -> Just Png 4 -> Just Tif intFromFileType :: Maybe FileType -> Int intFromFileType fileType = case fileType of Nothing -> 0 Just Bmp -> 1 Just Jpeg -> 2 Just Png -> 3 Just Tif -> 4