Add QListView and start QFont, and add a launcher to the examples.

parent bb02a5fe
......@@ -19,10 +19,13 @@ executable qtah-examples
main-is: Main.hs
other-modules:
Graphics.UI.Qtah.Example.Notepad
other-extensions:
ScopedTypeVariables
build-depends:
base >=4 && <5
, binary >=0.7 && <0.9
, bytestring >=0.10 && <0.11
, containers <0.6
, filepath >=1.0 && <1.5
, hoppy-runtime >=0.3 && <0.4
, qtah >=0.2 && <0.3
......
......@@ -24,7 +24,6 @@ import Control.Monad (forM_, unless, when)
import Data.Bits ((.|.))
import Data.Functor (void)
import Data.IORef (IORef, newIORef, readIORef, writeIORef)
import Foreign.Hoppy.Runtime (withScopedPtr)
import qualified Graphics.UI.Qtah.Core.QCoreApplication as QCoreApplication
import Graphics.UI.Qtah.Event
import Graphics.UI.Qtah.Gui.QCloseEvent (QCloseEvent)
......@@ -32,7 +31,6 @@ import Graphics.UI.Qtah.Signal (connect_)
import qualified Graphics.UI.Qtah.Core.QEvent as QEvent
import qualified Graphics.UI.Qtah.Widgets.QAction as QAction
import Graphics.UI.Qtah.Widgets.QAction (triggeredSignal)
import qualified Graphics.UI.Qtah.Widgets.QApplication as QApplication
import qualified Graphics.UI.Qtah.Widgets.QFileDialog as QFileDialog
import qualified Graphics.UI.Qtah.Widgets.QMainWindow as QMainWindow
import Graphics.UI.Qtah.Widgets.QMainWindow (QMainWindow)
......@@ -48,7 +46,6 @@ import Graphics.UI.Qtah.Widgets.QTextEdit (
undoAvailableSignal,
)
import qualified Graphics.UI.Qtah.Widgets.QWidget as QWidget
import System.Environment (getArgs)
import System.FilePath (takeFileName)
data Notepad = Notepad
......@@ -59,10 +56,9 @@ data Notepad = Notepad
}
run :: IO ()
run = withScopedPtr (getArgs >>= QApplication.new) $ \_ -> do
run = do
mainWindow <- makeMainWindow
QWidget.show mainWindow
QCoreApplication.exec
makeMainWindow :: IO QMainWindow
makeMainWindow = do
......@@ -78,7 +74,8 @@ makeMainWindow = do
menuFileSave <- QMenu.addNewAction menuFile "&Save"
menuFileSaveAs <- QMenu.addNewAction menuFile "Sa&ve as..."
_ <- QMenu.addSeparator menuFile
menuFileQuit <- QMenu.addNewAction menuFile "&Quit"
menuFileClose <- QMenu.addNewAction menuFile "&Close"
menuFileQuit <- QMenu.addNewAction menuFile "&Quit Examples"
menuEdit <- QMenuBar.addNewMenu menu "&Edit"
menuEditUndo <- QMenu.addNewAction menuEdit "&Undo"
......@@ -115,7 +112,10 @@ makeMainWindow = do
connect_ menuFileOpen triggeredSignal $ \_ -> fileOpen me
connect_ menuFileSave triggeredSignal $ \_ -> void $ fileSave me
connect_ menuFileSaveAs triggeredSignal $ \_ -> void $ fileSaveAs me
connect_ menuFileQuit triggeredSignal $ \_ -> QWidget.close window
connect_ menuFileClose triggeredSignal $ \_ -> void $ QWidget.close window
connect_ menuFileQuit triggeredSignal $ \_ -> do
closed <- QWidget.close window
when closed QCoreApplication.quit
connect_ menuEditUndo triggeredSignal $ \_ -> QTextEdit.undo text
connect_ menuEditRedo triggeredSignal $ \_ -> QTextEdit.redo text
......
......@@ -15,9 +15,147 @@
-- You should have received a copy of the GNU Lesser General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
{-# LANGUAGE ScopedTypeVariables #-}
module Main where
import Control.Arrow ((&&&))
import Control.Monad (forM_)
import Data.IORef (IORef, newIORef, readIORef, writeIORef)
import qualified Data.Map as M
import Foreign.Hoppy.Runtime (withScopedPtr)
import qualified Graphics.UI.Qtah.Core.QCoreApplication as QCoreApplication
import qualified Graphics.UI.Qtah.Core.QItemSelectionModel as QItemSelectionModel
import qualified Graphics.UI.Qtah.Core.QModelIndex as QModelIndex
import qualified Graphics.UI.Qtah.Core.QStringListModel as QStringListModel
import qualified Graphics.UI.Qtah.Core.QVariant as QVariant
import Graphics.UI.Qtah.Event (onEvent)
import qualified Graphics.UI.Qtah.Example.Notepad as Notepad
import qualified Graphics.UI.Qtah.Gui.QCloseEvent as QCloseEvent
import qualified Graphics.UI.Qtah.Gui.QFont as QFont
import qualified Graphics.UI.Qtah.Widgets.QAbstractButton as QAbstractButton
import qualified Graphics.UI.Qtah.Widgets.QAbstractItemView as QAbstractItemView
import qualified Graphics.UI.Qtah.Widgets.QApplication as QApplication
import qualified Graphics.UI.Qtah.Widgets.QBoxLayout as QBoxLayout
import qualified Graphics.UI.Qtah.Widgets.QLabel as QLabel
import qualified Graphics.UI.Qtah.Widgets.QListView as QListView
import qualified Graphics.UI.Qtah.Widgets.QPushButton as QPushButton
import qualified Graphics.UI.Qtah.Widgets.QSplitter as QSplitter
import qualified Graphics.UI.Qtah.Widgets.QVBoxLayout as QVBoxLayout
import qualified Graphics.UI.Qtah.Widgets.QWidget as QWidget
import Graphics.UI.Qtah.Signal (connect_)
import System.Environment (getArgs)
data Example = Example
{ exTitle :: String
, exDescription :: String
, exMain :: IO ()
}
examples :: [Example]
examples =
[ Example
{ exTitle = "Notepad"
, exDescription = "A notepad program for editing text files."
, exMain = Notepad.run
}
]
examplesByTitle :: M.Map String Example
examplesByTitle = M.fromList $ map (exTitle &&& id) examples
-- | State of the example chooser UI.
data UI = UI
{ uiWindow :: QWidget.QWidget
, uiListModel :: QStringListModel.QStringListModel
, uiCurrentExampleRef :: IORef (Maybe Example)
, uiDescriptionLabel :: QLabel.QLabel
}
main :: IO ()
main = Notepad.run
main = withScopedPtr (getArgs >>= QApplication.new) $ \_ -> do
ui <- newChooserWindow
QWidget.show $ uiWindow ui
QCoreApplication.exec
newChooserWindow :: IO UI
newChooserWindow = do
-- Create and initialize widgets.
window <- QWidget.new
QWidget.setWindowTitle window "Qtah Examples"
QWidget.resizeRaw window 500 350
model <- QStringListModel.newWithContents $ M.keys examplesByTitle
listView <- QListView.new
QAbstractItemView.setModel listView model
QAbstractItemView.setEditTriggers listView QAbstractItemView.noEditTriggers
titleLabel <- QLabel.newWithText "Qtah Example Programs"
titleFont <- QWidget.font titleLabel
QFont.setPixelSize titleFont 25
QWidget.setFont titleLabel titleFont
descriptionLabel <- QLabel.new
QLabel.setWordWrap descriptionLabel True
runButton <- QPushButton.newWithText "&Launch"
quitButton <- QPushButton.newWithText "&Quit"
rightBox <- QWidget.new
rightBoxLayout <- QVBoxLayout.new
QWidget.setLayout rightBox rightBoxLayout
QBoxLayout.addWidget rightBoxLayout descriptionLabel
QBoxLayout.addStretch rightBoxLayout
QBoxLayout.addWidget rightBoxLayout runButton
QBoxLayout.addWidget rightBoxLayout quitButton
splitter <- QSplitter.new
QSplitter.addWidget splitter listView
QSplitter.addWidget splitter rightBox
QSplitter.setSizes splitter [200 :: Int, 300]
layout <- QVBoxLayout.newWithParent window
QBoxLayout.addWidget layout titleLabel
QBoxLayout.addWidgetWithStretch layout splitter 1
-- Set up signals.
currentExampleRef <- newIORef Nothing
let ui = UI { uiWindow = window
, uiListModel = model
, uiCurrentExampleRef = currentExampleRef
, uiDescriptionLabel = descriptionLabel
}
_ <- onEvent window $ \(_ :: QCloseEvent.QCloseEvent) -> do
QCoreApplication.quit
return False
selectionModel <- QAbstractItemView.selectionModel listView
connect_ selectionModel QItemSelectionModel.currentChangedSignal $ \index _ ->
exampleSelected ui index
connect_ listView QAbstractItemView.activatedSignal $ \_ -> runSelectedExample ui
connect_ runButton QAbstractButton.clickedSignal $ \_ -> runSelectedExample ui
connect_ quitButton QAbstractButton.clickedSignal $ \_ -> QCoreApplication.quit
return ui
exampleSelected :: UI -> QModelIndex.QModelIndex -> IO ()
exampleSelected ui index = do
name <- QVariant.toString =<< QModelIndex.getData index
-- If we can't find the example, then do nothing.
forM_ (M.lookup name examplesByTitle) $ \example -> do
writeIORef (uiCurrentExampleRef ui) $ Just example
QLabel.setText (uiDescriptionLabel ui) $ exDescription example
runSelectedExample :: UI -> IO ()
runSelectedExample ui = do
maybeExample <- readIORef $ uiCurrentExampleRef ui
forM_ maybeExample $ \example -> exMain example
......@@ -94,6 +94,7 @@ executable qtah-generator
, Graphics.UI.Qtah.Generator.Interface.Gui.QEnterEvent
, Graphics.UI.Qtah.Generator.Interface.Gui.QExposeEvent
, Graphics.UI.Qtah.Generator.Interface.Gui.QFocusEvent
, Graphics.UI.Qtah.Generator.Interface.Gui.QFont
, Graphics.UI.Qtah.Generator.Interface.Gui.QHideEvent
, Graphics.UI.Qtah.Generator.Interface.Gui.QHoverEvent
, Graphics.UI.Qtah.Generator.Interface.Gui.QImage
......@@ -163,6 +164,7 @@ executable qtah-generator
, Graphics.UI.Qtah.Generator.Interface.Widgets.QLayout
, Graphics.UI.Qtah.Generator.Interface.Widgets.QLayoutItem
, Graphics.UI.Qtah.Generator.Interface.Widgets.QLineEdit
, Graphics.UI.Qtah.Generator.Interface.Widgets.QListView
, Graphics.UI.Qtah.Generator.Interface.Widgets.QMainWindow
, Graphics.UI.Qtah.Generator.Interface.Widgets.QMenu
, Graphics.UI.Qtah.Generator.Interface.Widgets.QMenuBar
......
......@@ -26,6 +26,7 @@ import qualified Graphics.UI.Qtah.Generator.Interface.Gui.QDoubleValidator as QD
import qualified Graphics.UI.Qtah.Generator.Interface.Gui.QEnterEvent as QEnterEvent
import qualified Graphics.UI.Qtah.Generator.Interface.Gui.QExposeEvent as QExposeEvent
import qualified Graphics.UI.Qtah.Generator.Interface.Gui.QFocusEvent as QFocusEvent
import qualified Graphics.UI.Qtah.Generator.Interface.Gui.QFont as QFont
import qualified Graphics.UI.Qtah.Generator.Interface.Gui.QHideEvent as QHideEvent
import qualified Graphics.UI.Qtah.Generator.Interface.Gui.QHoverEvent as QHoverEvent
import qualified Graphics.UI.Qtah.Generator.Interface.Gui.QImage as QImage
......@@ -65,8 +66,9 @@ modules =
, QColor.aModule
, QDoubleValidator.aModule
, QEnterEvent.aModule
, QFocusEvent.aModule
, QExposeEvent.aModule
, QFocusEvent.aModule
, QFont.aModule
, QHideEvent.aModule
, QHoverEvent.aModule
, QImage.aModule
......
-- This file is part of Qtah.
--
-- Copyright 2017 Bryan Gardiner <bog@khumba.net>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU Lesser General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU Lesser General Public License for more details.
--
-- You should have received a copy of the GNU Lesser General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
module Graphics.UI.Qtah.Generator.Interface.Gui.QFont (
aModule,
c_QFont,
) where
import Foreign.Hoppy.Generator.Spec (
Export (ExportClass),
addReqIncludes,
classSetConversionToGc,
classSetEntityPrefix,
ident,
includeStd,
makeClass,
mkCtor,
mkMethod,
)
import Foreign.Hoppy.Generator.Spec.ClassFeature (
ClassFeature (Assignable, Copyable, Equatable),
classAddFeatures,
)
import Foreign.Hoppy.Generator.Types (intT, voidT)
import Foreign.Hoppy.Generator.Version (collect, just)
import Graphics.UI.Qtah.Generator.Module (AModule (AQtModule), makeQtModule)
import Graphics.UI.Qtah.Generator.Types
{-# ANN module "HLint: ignore Use camelCase" #-}
aModule =
AQtModule $
makeQtModule ["Gui", "QFont"]
[ QtExport $ ExportClass c_QFont
]
c_QFont =
addReqIncludes [includeStd "QFont"] $
classSetConversionToGc $
classAddFeatures [Assignable, Copyable, Equatable] $
classSetEntityPrefix "" $
makeClass (ident "QFont") Nothing [] $
collect
[ just $ mkCtor "new" []
, just $ mkMethod "setPixelSize" [intT] voidT
, just $ mkMethod "setPointSize" [intT] voidT
]
-- TODO The rest of QFont.
......@@ -53,6 +53,7 @@ import qualified Graphics.UI.Qtah.Generator.Interface.Widgets.QLabel as QLabel
import qualified Graphics.UI.Qtah.Generator.Interface.Widgets.QLayout as QLayout
import qualified Graphics.UI.Qtah.Generator.Interface.Widgets.QLayoutItem as QLayoutItem
import qualified Graphics.UI.Qtah.Generator.Interface.Widgets.QLineEdit as QLineEdit
import qualified Graphics.UI.Qtah.Generator.Interface.Widgets.QListView as QListView
import qualified Graphics.UI.Qtah.Generator.Interface.Widgets.QMainWindow as QMainWindow
import qualified Graphics.UI.Qtah.Generator.Interface.Widgets.QMenu as QMenu
import qualified Graphics.UI.Qtah.Generator.Interface.Widgets.QMenuBar as QMenuBar
......@@ -118,6 +119,7 @@ modules =
, QLayout.aModule
, QLayoutItem.aModule
, QLineEdit.aModule
, QListView.aModule
, QMainWindow.aModule
, QMenu.aModule
, QMenuBar.aModule
......
......@@ -46,7 +46,6 @@ import Foreign.Hoppy.Generator.Types (
import Graphics.UI.Qtah.Generator.Interface.Core.QAbstractItemModel (c_QAbstractItemModel)
import Graphics.UI.Qtah.Generator.Interface.Core.QItemSelectionModel (c_QItemSelectionModel)
import Graphics.UI.Qtah.Generator.Interface.Core.QModelIndex (c_QModelIndex)
import Graphics.UI.Qtah.Generator.Interface.Core.QObject (c_QObject)
import Graphics.UI.Qtah.Generator.Interface.Core.QPoint (c_QPoint)
import Graphics.UI.Qtah.Generator.Interface.Core.QRect (c_QRect)
import Graphics.UI.Qtah.Generator.Interface.Core.QSize (c_QSize)
......@@ -60,6 +59,7 @@ import Graphics.UI.Qtah.Generator.Interface.Internal.Listener (
c_ListenerQModelIndex,
c_ListenerQSize,
)
import Graphics.UI.Qtah.Generator.Interface.Widgets.QAbstractScrollArea (c_QAbstractScrollArea)
import Graphics.UI.Qtah.Generator.Interface.Widgets.QWidget (c_QWidget)
import Graphics.UI.Qtah.Generator.Module (AModule (AQtModule), makeQtModule)
import Graphics.UI.Qtah.Generator.Types
......@@ -83,7 +83,7 @@ aModule =
c_QAbstractItemView =
addReqIncludes [includeStd "QAbstractItemView"] $
classSetEntityPrefix "" $
makeClass (ident "QAbstractItemView") Nothing [c_QObject] $
makeClass (ident "QAbstractItemView") Nothing [c_QAbstractScrollArea] $
[ mkProp "alternatingRowColors" boolT
, mkBoolHasProp "autoScroll"
, mkProp "autoScrollMargin" intT
......
-- This file is part of Qtah.
--
-- Copyright 2017 Bryan Gardiner <bog@khumba.net>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU Lesser General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU Lesser General Public License for more details.
--
-- You should have received a copy of the GNU Lesser General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
module Graphics.UI.Qtah.Generator.Interface.Widgets.QListView (
aModule,
) where
import Foreign.Hoppy.Generator.Spec (
Export (ExportClass),
addReqIncludes,
classSetEntityPrefix,
ident,
includeStd,
makeClass,
mkCtor,
)
import Graphics.UI.Qtah.Generator.Interface.Widgets.QAbstractItemView (c_QAbstractItemView)
import Graphics.UI.Qtah.Generator.Module (AModule (AQtModule), makeQtModule)
import Graphics.UI.Qtah.Generator.Types
{-# ANN module "HLint: ignore Use camelCase" #-}
aModule =
AQtModule $
makeQtModule ["Widgets", "QListView"]
[ QtExport $ ExportClass c_QListView ]
c_QListView =
addReqIncludes [includeStd "QListView"] $
classSetEntityPrefix "" $
makeClass (ident "QListView") Nothing [c_QAbstractItemView]
[ mkCtor "new" []
-- TODO
]
......@@ -52,6 +52,7 @@ import Graphics.UI.Qtah.Generator.Interface.Core.Types (
e_WindowType,
qreal,
)
import Graphics.UI.Qtah.Generator.Interface.Gui.QFont (c_QFont)
import Graphics.UI.Qtah.Generator.Interface.Internal.Listener (c_ListenerQPoint)
import Graphics.UI.Qtah.Generator.Interface.Widgets.QAction (c_QAction)
import Graphics.UI.Qtah.Generator.Interface.Widgets.QLayout (c_QLayout)
......@@ -90,7 +91,7 @@ c_QWidget =
-- TODO childrenRegion
, just $ mkMethod "clearFocus" [] voidT
, just $ mkMethod "clearMask" [] voidT
, just $ mkMethod "close" [] voidT
, just $ mkMethod "close" [] boolT
, just $ mkConstMethod "contentsMargins" [] $ objT c_QMargins
, just $ mkConstMethod "contentsRect" [] $ objT c_QRect
-- TODO contextMenuPolicy
......@@ -101,6 +102,7 @@ c_QWidget =
-- TODO focusPolicy
, just $ mkConstMethod "focusProxy" [] $ ptrT $ objT c_QWidget
, just $ mkConstMethod "focusWidget" [] $ ptrT $ objT c_QWidget
, just $ mkProp "font" $ objT c_QFont
-- TODO font
-- TODO fontInfo
-- TODO fontMetrics
......
......@@ -81,6 +81,7 @@ library
, Graphics.UI.Qtah.Gui.QEnterEvent
, Graphics.UI.Qtah.Gui.QExposeEvent
, Graphics.UI.Qtah.Gui.QFocusEvent
, Graphics.UI.Qtah.Gui.QFont
, Graphics.UI.Qtah.Gui.QHideEvent
, Graphics.UI.Qtah.Gui.QHoverEvent
, Graphics.UI.Qtah.Gui.QImage
......@@ -148,6 +149,7 @@ library
, Graphics.UI.Qtah.Widgets.QLayout
, Graphics.UI.Qtah.Widgets.QLayoutItem
, Graphics.UI.Qtah.Widgets.QLineEdit
, Graphics.UI.Qtah.Widgets.QListView
, Graphics.UI.Qtah.Widgets.QMainWindow
, Graphics.UI.Qtah.Widgets.QMenu
, Graphics.UI.Qtah.Widgets.QMenuBar
......@@ -222,6 +224,7 @@ library
, Graphics.UI.Qtah.Generated.Gui.QEnterEvent
, Graphics.UI.Qtah.Generated.Gui.QExposeEvent
, Graphics.UI.Qtah.Generated.Gui.QFocusEvent
, Graphics.UI.Qtah.Generated.Gui.QFont
, Graphics.UI.Qtah.Generated.Gui.QHideEvent
, Graphics.UI.Qtah.Generated.Gui.QHoverEvent
, Graphics.UI.Qtah.Generated.Gui.QImage
......@@ -286,6 +289,7 @@ library
, Graphics.UI.Qtah.Generated.Widgets.QLayout
, Graphics.UI.Qtah.Generated.Widgets.QLayoutItem
, Graphics.UI.Qtah.Generated.Widgets.QLineEdit
, Graphics.UI.Qtah.Generated.Widgets.QListView
, Graphics.UI.Qtah.Generated.Widgets.QMainWindow
, Graphics.UI.Qtah.Generated.Widgets.QMenu
, Graphics.UI.Qtah.Generated.Widgets.QMenuBar
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment