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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
# File 'lib/cosmos/tools/launcher/launcher.rb', line 49
def initialize_central_widget
central_widget = Qt::Widget.new
setCentralWidget(central_widget)
config_file = File.join(Cosmos::USERPATH, 'config', 'tools', 'launcher', @options.config_file)
begin
config = LauncherConfig.new(config_file)
rescue => error
ExceptionDialog.new(self, error, "Error parsing #{config_file}")
end
self.window_title = config.title
default_icon_filename = 'COSMOS_64x64.png'
widgets = []
config.items.each do |item_type, text, shell_command_or_settings, capture_io, icon_filename, variable_parameters|
case item_type
when :TOOL, :MULTITOOL
layout = Qt::VBoxLayout.new
if icon_filename
icon = Cosmos.get_icon(icon_filename)
else
icon = Cosmos.get_icon(default_icon_filename)
end
button = Qt::PushButton.new('')
button.setIcon(icon)
button.setIconSize(Qt::Size.new(64,64))
if item_type == :TOOL
connect(button,
SIGNAL('clicked()'),
LauncherTool.new(self, text, shell_command_or_settings, capture_io, variable_parameters),
SLOT('button_clicked()'))
else
connect(button,
SIGNAL('clicked()'),
LauncherMultitool.new(self, shell_command_or_settings),
SLOT('button_clicked()'))
end
if Kernel.is_mac?
button.setFixedSize(84,84)
else
stylesheet = "padding:4px; text-align:center; " \
"font-family:#{config.tool_font_settings[0]}; " \
"font-size:#{config.tool_font_settings[1]}px"
button.setStyleSheet(stylesheet)
button.setFixedSize(74,74)
end
label = Qt::Label.new(text)
stylesheet = "text-align:center; " \
"font-family:#{config.tool_font_settings[0]}; " \
"font-size:#{config.tool_font_settings[1]}px"
label.setStyleSheet(stylesheet)
label.wordWrap = true
label.setFixedWidth(70)
label.setSizePolicy(Qt::SizePolicy::Fixed, Qt::SizePolicy::Fixed)
label.setMinimumSize(label.sizeHint)
label.setAlignment(Qt::AlignHCenter)
layout.addWidget(button)
layout.addWidget(label)
layout.setAlignment(button, Qt::AlignHCenter)
layout.setAlignment(label, Qt::AlignHCenter)
widgets << layout
when :DIVIDER
divider = Qt::Frame.new
divider.setFrameStyle(Qt::Frame::HLine | Qt::Frame::Raised)
divider.setLineWidth(1)
divider.setMidLineWidth(1)
widgets << divider
when :LABEL
label = Qt::Label.new(text)
stylesheet = "text-align:center; " \
"font-family:#{config.label_font_settings[0]}; " \
"font-size:#{config.label_font_settings[1]}px"
label.setStyleSheet(stylesheet)
widgets << label
else
raise "Unhandled item type from LauncherConfig: #{item_type}"
end
end
col = 0
h_layout = nil
v_layout = Qt::VBoxLayout.new
central_widget.layout = v_layout
widgets.each do |widget|
if Qt::VBoxLayout === widget
unless h_layout
h_layout = Qt::HBoxLayout.new
v_layout.addLayout(h_layout)
col = 0
end
widget.setAlignment(Qt::AlignTop | Qt::AlignLeft)
h_layout.addLayout(widget)
col += 1
if col >= config.num_columns
col = 0
h_layout = nil
end
else
h_layout.addStretch(0) if h_layout
v_layout.addWidget(widget)
h_layout = nil
end
end
h_layout.addStretch(0) if h_layout
end
|