Class: Qt::KeyEvent

Inherits:
Object show all
Defined in:
lib/qtext/extensions.rb

Overview

Make keystrokes events easier to work with. For Qt::Key_Whatever events, KeyEvent instances will now respond to whatever?

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object

Provide a shortcut for the Qt::Key_Whatever constants. Just say event.whatever?



237
238
239
240
241
242
243
244
245
246
247
# File 'lib/qtext/extensions.rb', line 237

def method_missing( sym, *args, &block )
  begin
    if sym.to_s[-1] == "?"[0]
      key?( sym.to_s[0..-2] )
    else
      old_method_missing( sym, *args, &block )
    end
  rescue Exception => e
    old_method_missing( sym, *args, &block )
  end
end

Instance Method Details

#ctrl?Boolean

is the control key pressed?

Returns:

  • (Boolean)


230
231
232
# File 'lib/qtext/extensions.rb', line 230

def ctrl?
  modifiers & Qt::ControlModifier.to_i == Qt::ControlModifier.to_i
end

#key?(name) ⇒ Boolean

Returns:

  • (Boolean)


249
250
251
# File 'lib/qtext/extensions.rb', line 249

def key?( name )
  key == eval( "Qt::Key_#{name.to_s.camelize}" )
end

#old_method_missingObject



234
# File 'lib/qtext/extensions.rb', line 234

alias_method :old_method_missing, :method_missing