Class Ui::Qt4::Widgets::CommandLine
In: ui/qt/widgets/commandline.rb
Parent: Qt::LineEdit

CommandLine is a custom Qt widget that behaves as a standard command line. It keeps a buffer of typed in commands that can be accessed by means of the Up and Down keys.

When the widget signals a returnPressed the last command inserted by the user is accessible using the last_command method.

Methods

Public Class methods

Create the widget and initialize the internal data structures that will hold the command history.

[Source]

# File ui/qt/widgets/commandline.rb, line 33
        def initialize(parent=nil)
          super(parent)
          #initialize internal history buffer
          @history = []
          @pointer = 0
          @up = true
        end

Public Instance methods

Clears the internal command history buffer.

[Source]

# File ui/qt/widgets/commandline.rb, line 100
        def clear_history()
          @history.clear
        end

override some event handlers

[Source]

# File ui/qt/widgets/commandline.rb, line 59
        def keyPressEvent(event)
          #print_history('in') if (event.key == Qt::Key_Up || event.key == Qt::Key_Down || event.key == Qt::Key_Return)
          #p 'beb'
          case event.key 
            when Qt::Key_Up:
              if ((@history.size > 0) && (@pointer >= 0) )
                if (@pointer == @history.size)
                  @history << self.text 
                end
                @pointer -= 1 if @pointer > 0
                self.text = @history[@pointer]
              end
              return
      
            when Qt::Key_Down:
              if ((@history.size > 0) && (@pointer < @history.size) )
                @pointer += 1 if @pointer < @history.size - 1
                self.text = @history[@pointer]
              end
              return
      
            #add a new element to the local @history
            when Qt::Key_Return:
      
              #keep an eye on the last entry to avoid empty entries in the list
              if ((@history.size > 0) && (@history.last.strip.size == 0) )
                @history.pop
              end
      
              if self.text.strip.size > 0
                @history << self.text
                @pointer = @history.size
                self.clear
              end
          end
      
          #print_history('out') if (event.key == Qt::Key_Up || event.key == Qt::Key_Down || event.key == Qt::Key_Return)
          super
        end

Returns the last command issued by the user. This method should be used when the parent window captures a returnPressed event to examine the las line inputted by the user.

[Source]

# File ui/qt/widgets/commandline.rb, line 107
        def last_command()
          @history.last
        end

[Validate]