hsqml-demo-samples (empty) → 0.3.0.0
raw patch · 7 files changed
+171/−0 lines, 7 filesdep +basedep +hsqmldep +textsetup-changed
Dependencies added: base, hsqml, text
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- hsqml-demo-samples.cabal +41/−0
- qml/factorial1.qml +23/−0
- qml/factorial2.qml +23/−0
- src/Factorial1.hs +19/−0
- src/Factorial2.hs +33/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2014, Robin KAY++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Robin KAY nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ hsqml-demo-samples.cabal view
@@ -0,0 +1,41 @@+Name: hsqml-demo-samples+Version: 0.3.0.0+Cabal-version: >= 1.10+Build-type: Simple+License: BSD3+License-file: LICENSE+Copyright: (c) 2014 Robin KAY+Author: Robin KAY+Maintainer: komadori@gekkou.co.uk+Stability: experimental+Homepage: http://www.gekkou.co.uk/software/hsqml/+Category: Graphics+Synopsis: HsQML sample programs+Data-dir: qml+Data-files: *.qml+Description:+ HsQML sample programs++Executable hsqml-factorial1+ Default-language: Haskell2010+ Hs-source-dirs: src+ Main-is: Factorial1.hs+ Build-depends:+ base == 4.*,+ text >= 0.11 && < 1.2,+ hsqml == 0.3.*+ GHC-options: -threaded++Executable hsqml-factorial2+ Default-language: Haskell2010+ Hs-source-dirs: src+ Main-is: Factorial2.hs+ Build-depends:+ base == 4.*,+ text >= 0.11 && < 1.2,+ hsqml == 0.3.*+ GHC-options: -threaded++Source-repository head+ type: darcs+ location: http://hub.darcs.net/komadori/hsqml-demo-samples
+ qml/factorial1.qml view
@@ -0,0 +1,23 @@+import QtQuick 2.0++Column {+ height: 300;+ TextEdit {+ id: input; width: 300; height: 30; font.pixelSize: 30; focus: true;+ }+ Rectangle {+ color: "red"; width: childrenRect.width; height: childrenRect.height;+ Text {+ width: 300; height: 30; font.pixelSize: 30;+ text: "Calculate Factorial"; color: "white";+ }+ MouseArea {+ anchors.fill: parent;+ onClicked: output.text = factorial(input.text);+ }+ }+ Text {+ width: 300; wrapMode: Text.WrapAnywhere; font.pixelSize: 30;+ id: output;+ }+}
+ qml/factorial2.qml view
@@ -0,0 +1,23 @@+import QtQuick 2.0++Column {+ height: 300;+ TextEdit {+ id: input; width: 300; height: 30; font.pixelSize: 30; focus: true;+ }+ Rectangle {+ color: "red"; width: childrenRect.width; height: childrenRect.height;+ Text {+ width: 300; height: 30; font.pixelSize: 30;+ text: "Calculate Factorial"; color: "white";+ }+ MouseArea {+ anchors.fill: parent;+ onClicked: factorial(input.text);+ }+ }+ Text {+ width: 300; wrapMode: Text.WrapAnywhere; font.pixelSize: 30;+ text: result;+ }+}
+ src/Factorial1.hs view
@@ -0,0 +1,19 @@+module Main where++import Graphics.QML+import Data.Text (Text)+import qualified Data.Text as T++import Paths_hsqml_demo_samples++main :: IO ()+main = do+ clazz <- newClass [+ defMethod' "factorial" (\_ txt ->+ let n = read $ T.unpack txt :: Integer+ in return . T.pack . show $ product [1..n] :: IO Text)]+ ctx <- newObject clazz ()+ doc <- getDataFileName "factorial1.qml"+ runEngineLoop defaultEngineConfig {+ initialDocument = fileDocument doc,+ contextObject = Just $ anyObjRef ctx}
+ src/Factorial2.hs view
@@ -0,0 +1,33 @@+module Main where++import Graphics.QML+import Control.Concurrent+import Control.Exception+import Data.IORef+import Data.Text (Text)+import qualified Data.Text as T++import Paths_hsqml_demo_samples++main :: IO ()+main = do+ state <- newIORef $ T.pack ""+ skey <- newSignalKey+ clazz <- newClass [+ defPropertySigRO' "result" skey (\_ ->+ readIORef state),+ defMethod' "factorial" (\obj txt -> do+ let n = read $ T.unpack txt :: Integer+ writeIORef state $ T.pack "Working..."+ fireSignal skey obj+ forkIO $ do+ let out = T.take 1000 . T.pack . show $ product [1..n]+ evaluate out+ writeIORef state out+ fireSignal skey obj+ return ())]+ ctx <- newObject clazz ()+ doc <- getDataFileName "factorial2.qml"+ runEngineLoop defaultEngineConfig {+ initialDocument = fileDocument doc,+ contextObject = Just $ anyObjRef ctx}