class ScribbleWindow
Constants
- COLOR_MENU_ID_BLACK
- COLOR_MENU_ID_BLUE
- COLOR_MENU_ID_GREEN
- COLOR_MENU_ID_RED
- COLOR_MENU_ID_YELLOW
Public Class Methods
new()
click to toggle source
Calls superclass method
# File examples/qtscribble/scribble.rb, line 157 def initialize() super # The next lines build the menu bar. We first create the menus # one by one, then add them to the menu bar. # @_menubar = Qt::MenuBar.new( self ) # create a menu bar @_filemenu = @_menubar.addMenu( "&File" ) # create a file menu @_filemenu.addAction( "&Load", self, SLOT( "slotLoad()" ) ) @_filemenu.addAction( "&Save", self, SLOT( "slotSave()" ) ) @_filemenu.addSeparator() @_filemenu.addAction( "&Quit", $qApp, SLOT( "quit()" ) ) @_colormenu = @_menubar.addMenu( "&Color" ) # create a color menu # @_colormenu.addAction( "B&lack", COLOR_MENU_ID_BLACK) # @_colormenu.addAction( "&Red", COLOR_MENU_ID_RED) # @_colormenu.addAction( "&Blue", COLOR_MENU_ID_BLUE) # @_colormenu.addAction( "&Green", COLOR_MENU_ID_GREEN) # @_colormenu.addAction( "&Yellow", COLOR_MENU_ID_YELLOW) # Qt::Object.connect( @_colormenu, SIGNAL( "activated( int )" ), # self, SLOT( "slotColorMenu( int )" ) ) @_helpmenu = @_menubar.addMenu( "&Help" ) # create a help menu @_helpmenu.addAction( "&About QtScribble", self, SLOT( "slotAbout()" ) ) @_helpmenu.addAction( "&About Qt", self, SLOT( "slotAboutQt()" ) ) # We create a Qt::ScrollView and a ScribbleArea. The ScribbleArea will # be managed by the scroll view.# @_scrollview = Qt::ScrollArea.new( self ) @_scrollview.setGeometry( 0, @_menubar.height(), width(), height() - @_menubar.height() ) @_scribblearea = ScribbleArea.new( @_scrollview ) @_scribblearea.setGeometry( 0, 0, 1000, 1000 ) # @_scrollview.addChild( @_scribblearea ) Qt::Object.connect( self, SIGNAL( "colorChanged(QColor)" ), @_scribblearea, SLOT( "setColor(QColor)" ) ) Qt::Object.connect( self, SIGNAL( "save(const QString&)" ), @_scribblearea, SLOT( "slotSave(const QString&)" ) ) Qt::Object.connect( self, SIGNAL( "load(const QString&)" ), @_scribblearea, SLOT( "slotLoad(const QString&)" ) ) end
Public Instance Methods
resizeEvent( event )
click to toggle source
# File examples/qtscribble/scribble.rb, line 198 def resizeEvent( event ) # When the whole window is resized, we have to rearrange the geometry # in the ScribbleWindow as well. Note that the ScribbleArea does not need # to be changed. @_scrollview.setGeometry( 0, @_menubar.height(), width(), height() - @_menubar.height() ) end
slotAbout()
click to toggle source
# File examples/qtscribble/scribble.rb, line 208 def slotAbout() Qt::MessageBox.information( self, "About QtScribble 5", "This is the Scribble 5 application\n" + "Copyright 1998 by Mathias Kalle Dalheimer\n") end
slotAboutQt()
click to toggle source
# File examples/qtscribble/scribble.rb, line 214 def slotAboutQt() Qt::MessageBox.aboutQt( self, "About Qt" ) end
slotColorMenu( item )
click to toggle source
# File examples/qtscribble/scribble.rb, line 218 def slotColorMenu( item ) case item when COLOR_MENU_ID_BLACK emit colorChanged( black ) when COLOR_MENU_ID_RED emit colorChanged( darkRed ) when COLOR_MENU_ID_BLUE emit colorChanged( darkBlue ) when COLOR_MENU_ID_GREEN emit colorChanged( darkGreen ) when COLOR_MENU_ID_YELLOW emit colorChanged( yellow ) end end
slotLoad()
click to toggle source
This is the slot for the menu item File/Load. It opens a Qt::FileDialog to ask the user for a filename, then emits a save() signal with the filename as parameter.
# File examples/qtscribble/scribble.rb, line 239 def slotLoad() # Open a file dialog for loading. The default directory is the # current directory, the filter *.bmp. # filename = Qt::FileDialog.getOpenFileName( ".", "*.bmp", self ) if !filename.nil? emit load( filename ) end end
slotSave()
click to toggle source
This is the slot for the menu item File/Load. It opens a Qt::FileDialog to ask the user for a filename, then emits a save() signal with the filename as parameter.
# File examples/qtscribble/scribble.rb, line 254 def slotSave() # Open a file dialog for saving. The default directory is the # current directory, the filter *.bmp. # filename = Qt::FileDialog.getSaveFileName( ".", "*.bmp", self ) if !filename.nil? emit save( filename ) end end