Class: Cosmos::AboutDialog

Inherits:
Qt::Dialog show all
Defined in:
lib/cosmos/gui/dialogs/about_dialog.rb

Constant Summary collapse

ABOUT_COSMOS =
''
@@pry_dialogs =
[]

Instance Method Summary collapse

Methods inherited from Qt::Dialog

#exec

Constructor Details

#initialize(parent, about_string) ⇒ AboutDialog

Returns a new instance of AboutDialog.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/cosmos/gui/dialogs/about_dialog.rb', line 40

def initialize (parent, about_string)
  super(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
  @saved_text = ''
  setWindowTitle('About')

  # Get Word Icon
  filename = File.join(::Cosmos::USERPATH, 'config', 'data', 'cosmos_word.gif')
  filename = File.join(::Cosmos::PATH, 'data', 'cosmos_word.gif') unless File.exist?(filename)
  word_icon = Qt::Label.new
  word_icon.setPixmap(Qt::Pixmap.new(filename))

  copyright = Qt::Label.new("Copyright 2014 - Ball Aerospace & Technologies Corp.")
  authors = Qt::Label.new("Created by Ryan Melton (ryanmelt) and Jason Thomas (jmthomas)")
  ver = Qt::Label.new("Version: " + COSMOS_VERSION)
  user_ver = nil
  user_ver = Qt::Label.new("User Version: " + USER_VERSION) if defined? USER_VERSION and USER_VERSION != 'Unofficial'
  icon_layout = Qt::VBoxLayout.new do
    addWidget(word_icon)
    addWidget(copyright)
    addWidget(authors)
    addWidget(ver)
    addWidget(user_ver) if user_ver
    addStretch
  end

  # Get COSMOS Configurable About Text
  filename = File.join(Cosmos::USERPATH, 'config', 'data', 'about.txt')
  filename = File.join(Cosmos::PATH, 'data', 'about.txt') unless File.exist?(filename)
  configurable_about_text = File.read(filename)
  configurable_about_text.gsub!("\r", '') unless Kernel.is_windows?
  if Kernel.is_windows?
    configurable_about_text << "\n" + "Main Application x:#{parent.x} y:#{parent.y} width:#{parent.frameGeometry.width + 16} height:#{parent.frameGeometry.height + 38}\n\n" +  ABOUT_COSMOS
  else
    configurable_about_text << "\n" + "Main Application x:#{parent.x} y:#{parent.y} width:#{parent.frameGeometry.width} height:#{parent.frameGeometry.height}\n\n" +  ABOUT_COSMOS      end

  # Set the application about text
  about = Qt::Label.new(about_string + "\n\n" + configurable_about_text)
  about.setAlignment(Qt::AlignTop)
  about.setWordWrap(true)

  dialog = self
  ok = Qt::PushButton.new('Ok') do
    connect(SIGNAL('clicked()')) { dialog.done(0) }
  end

  button_layout = Qt::HBoxLayout.new do
    addStretch
    addWidget(ok)
    addStretch
  end

  self.layout = Qt::VBoxLayout.new do
    scroll_area = Qt::ScrollArea.new
    scroll_area.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff)
    addWidget(scroll_area)
    scroll_widget = Qt::Widget.new
    scroll_area.setWidget(scroll_widget)
    interior_layout = Qt::VBoxLayout.new
    interior_layout.addLayout(icon_layout)
    interior_layout.addWidget(about)
    scroll_widget.setLayout(interior_layout)
    scroll_area.setMinimumWidth(scroll_widget.minimumSizeHint.width + 20)
    scroll_widget.adjustSize
    addLayout(button_layout)
  end

  setMaximumWidth(800)
  self.raise()
  exec()
  dispose()
end

Instance Method Details

#keyPressEvent(event) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/cosmos/gui/dialogs/about_dialog.rb', line 112

def keyPressEvent(event)
  @saved_text << event.text.to_s
  if @saved_text[0] == 'p'
    if @saved_text[1]
      if @saved_text[1] == 'r'
        if @saved_text[2]
          if @saved_text[2] == 'y'
            self.done(0)
            @@pry_dialogs << PryDialog.new(nil, binding)
            return
          end
          @saved_text = ''
        end
      else
        @saved_text = ''
      end
    end
  else
    @saved_text = ''
  end
  super(event)
end