class Window
** ** Copyright (C) 2004-2006 Trolltech AS. All rights reserved. ** ** This file is part of the example classes of the Qt Toolkit. ** ** This file may be used under the terms of the GNU General Public ** License version 2.0 as published by the Free Software Foundation ** and appearing in the file LICENSE.GPL included in the packaging of ** this file. Please review the following information to ensure GNU ** General Public Licensing requirements will be met: ** www.trolltech.com/products/qt/opensource.html ** ** If you are unsure which license is appropriate for your use, please ** review the following information: ** www.trolltech.com/products/qt/licensing.html or contact the ** sales department at sales@trolltech.com. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. **
** Translated to QtRuby by Richard Dale
** ** Copyright (C) 2004-2005 Trolltech AS. All rights reserved. ** ** This file is part of the example classes of the Qt Toolkit. ** ** This file may be used under the terms of the GNU General Public ** License version 2.0 as published by the Free Software Foundation ** and appearing in the file LICENSE.GPL included in the packaging of ** self file. Please review the following information to ensure GNU ** General Public Licensing requirements will be met: ** www.trolltech.com/products/qt/opensource.html ** ** If you are unsure which license is appropriate for your use, please ** review the following information: ** www.trolltech.com/products/qt/licensing.html or contact the ** sales department at sales@trolltech.com. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. **
** Translated to QtRuby by Richard Dale
** ** Copyright (C) 2004-2005 Trolltech AS. All rights reserved. ** ** This file is part of the example classes of the Qt Toolkit. ** ** This file may be used under the terms of the GNU General Public ** License version 2.0 as published by the Free Software Foundation ** and appearing in the file LICENSE.GPL included in the packaging of ** this file. Please review the following information to ensure GNU ** General Public Licensing requirements will be met: ** www.trolltech.com/products/qt/opensource.html ** ** If you are unsure which license is appropriate for your use, please ** review the following information: ** www.trolltech.com/products/qt/licensing.html or contact the ** sales department at sales@trolltech.com. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. **
** Translated to QtRuby by Richard Dale
Constants
- NumColumns
- NumRenderAreas
- NumRows
- NumTransformedAreas
Public Class Methods
# File examples/desktop/systray/window.rb, line 33 def initialize(parent = nil) super(parent) createIconGroupBox() createMessageGroupBox() @iconLabel.minimumWidth = @durationLabel.sizeHint.width createActions() createTrayIcon() connect(@showMessageButton, SIGNAL(:clicked), self, SLOT(:showMessage)) connect(@showIconCheckBox, SIGNAL('toggled(bool)'), @trayIcon, SLOT('setVisible(bool)')) connect(@iconComboBox, SIGNAL('currentIndexChanged(int)'), self, SLOT('setIcon(int)')) connect(@trayIcon, SIGNAL(:messageClicked), self, SLOT(:messageClicked)) connect(@trayIcon, SIGNAL('activated(QSystemTrayIcon::ActivationReason)'), self, SLOT('iconActivated(QSystemTrayIcon::ActivationReason)')) self.layout = Qt::VBoxLayout.new do |m| m.addWidget(@iconGroupBox) m.addWidget(@messageGroupBox) end @iconComboBox.currentIndex = 1 @trayIcon.show setWindowTitle(tr("Systray")) resize(400, 300) end
Public Instance Methods
# File examples/dialogs/findfiles/window.rb, line 69 def browse() directory = Qt::FileDialog.getExistingDirectory(self, tr("Find Files"), Qt::Dir.currentPath()) @directoryComboBox.addItem(directory) @directoryComboBox.currentIndex += 1 end
# File examples/painting/basicdrawing/window.rb, line 188 def brushChanged() style = @brushStyleComboBox.itemData(@brushStyleComboBox.currentIndex(), @idRole).toInt if style == Qt::LinearGradientPattern linearGradient = Qt::LinearGradient.new(0, 0, 100, 100) linearGradient.setColorAt(0.0, Qt::Color.new(Qt::white)) linearGradient.setColorAt(0.2, Qt::Color.new(Qt::green)) linearGradient.setColorAt(1.0, Qt::Color.new(Qt::black)) @renderArea.brush = Qt::Brush.new(linearGradient) elsif style == Qt::RadialGradientPattern radialGradient = Qt::RadialGradient.new(50, 50, 50, 50, 50) radialGradient.setColorAt(0.0, Qt::Color.new(Qt::white)) radialGradient.setColorAt(0.2, Qt::Color.new(Qt::green)) radialGradient.setColorAt(1.0, Qt::Color.new(Qt::black)) @renderArea.brush = Qt::Brush.new(radialGradient) elsif style == Qt::ConicalGradientPattern conicalGradient = Qt::ConicalGradient.new(50, 50, 150) conicalGradient.setColorAt(0.0, Qt::Color.new(Qt::white)) conicalGradient.setColorAt(0.2, Qt::Color.new(Qt::green)) conicalGradient.setColorAt(1.0, Qt::Color.new(Qt::black)) @renderArea.brush = Qt::Brush.new(conicalGradient) elsif style == Qt::TexturePattern @renderArea.brush = Qt::Brush.new(Qt::Pixmap.new("images/brick.png")) else @renderArea.brush = Qt::Brush.new(Qt::green, style) end end
# File examples/widgets/spinboxes/window.rb, line 208 def changePrecision(decimals) @doubleSpinBox.decimals = decimals @scaleSpinBox.decimals = decimals @priceSpinBox.decimals = decimals end
# File examples/desktop/systray/window.rb, line 71 def closeEvent(event) if @trayIcon.visible? Qt::MessageBox.information(self, tr("Systray"), tr("The program will keep running in the " "system tray. To terminate the program, " "choose <b>Quit</b> in the context menu " "that pops up when clicking self program's " "entry in the system tray.")) hide() event.ignore() end end
# File examples/desktop/systray/window.rb, line 194 def createActions() @minimizeAction = Qt::Action.new(tr("Mi&nimize"), self) connect(@minimizeAction, SIGNAL(:triggered), self, SLOT(:hide)) @maximizeAction = Qt::Action.new(tr("Ma&ximize"), self) connect(@maximizeAction, SIGNAL(:triggered), self, SLOT(:showMaximized)) @restoreAction = Qt::Action.new(tr("&Restore"), self) connect(@restoreAction, SIGNAL(:triggered), self, SLOT(:show)) @quitAction = Qt::Action.new(tr("&Quit"), self) connect(@quitAction, SIGNAL(:triggered), $qApp, SLOT(:quit)) end
# File examples/dialogs/findfiles/window.rb, line 153 def createButton(text, member) button = Qt::PushButton.new(text) connect(button, SIGNAL('clicked()'), self, member) return button end
# File examples/dialogs/findfiles/window.rb, line 159 def createComboBox(text = "") comboBox = Qt::ComboBox.new comboBox.editable = true comboBox.addItem(text) comboBox.setSizePolicy(Qt::SizePolicy::Expanding, Qt::SizePolicy::Preferred) return comboBox end
# File examples/widgets/sliders/window.rb, line 62 def createControls(title) @controlsGroup = Qt::GroupBox.new(title) @minimumLabel = Qt::Label.new(tr("Minimum value:")) @maximumLabel = Qt::Label.new(tr("Maximum value:")) @valueLabel = Qt::Label.new(tr("Current value:")) @invertedAppearance = Qt::CheckBox.new(tr("Inverted appearance")) @invertedKeyBindings = Qt::CheckBox.new(tr("Inverted key bindings")) @minimumSpinBox = Qt::SpinBox.new do |s| s.range = -100..100 s.singleStep = 1 end @maximumSpinBox = Qt::SpinBox.new do |s| s.range = -100..100 s.singleStep = 1 end @valueSpinBox = Qt::SpinBox.new do |s| s.range = -100..100 s.singleStep = 1 end @orientationCombo = Qt::ComboBox.new @orientationCombo.addItem(tr("Horizontal slider-like widgets")) @orientationCombo.addItem(tr("Vertical slider-like widgets")) connect(@orientationCombo, SIGNAL('activated(int)'), @stackedWidget, SLOT('setCurrentIndex(int)')) connect(@minimumSpinBox, SIGNAL('valueChanged(int)'), @horizontalSliders, SLOT('setMinimum(int)')) connect(@minimumSpinBox, SIGNAL('valueChanged(int)'), @verticalSliders, SLOT('setMinimum(int)')) connect(@maximumSpinBox, SIGNAL('valueChanged(int)'), @horizontalSliders, SLOT('setMaximum(int)')) connect(@maximumSpinBox, SIGNAL('valueChanged(int)'), @verticalSliders, SLOT('setMaximum(int)')) connect(@invertedAppearance, SIGNAL('toggled(bool)'), @horizontalSliders, SLOT('invertAppearance(bool)')) connect(@invertedAppearance, SIGNAL('toggled(bool)'), @verticalSliders, SLOT('invertAppearance(bool)')) connect(@invertedKeyBindings, SIGNAL('toggled(bool)'), @horizontalSliders, SLOT('invertKeyBindings(bool)')) connect(@invertedKeyBindings, SIGNAL('toggled(bool)'), @verticalSliders, SLOT('invertKeyBindings(bool)')) controlsLayout = Qt::GridLayout.new do |c| c.addWidget(@minimumLabel, 0, 0) c.addWidget(@maximumLabel, 1, 0) c.addWidget(@valueLabel, 2, 0) c.addWidget(@minimumSpinBox, 0, 1) c.addWidget(@maximumSpinBox, 1, 1) c.addWidget(@valueSpinBox, 2, 1) c.addWidget(@invertedAppearance, 0, 2) c.addWidget(@invertedKeyBindings, 1, 2) c.addWidget(@orientationCombo, 3, 0, 1, 3) end @controlsGroup.layout = controlsLayout end
# File examples/widgets/spinboxes/window.rb, line 91 def createDateTimeEdits() @editsGroup = Qt::GroupBox.new(tr("Date and time spin boxes")) dateLabel = Qt::Label.new dateEdit = Qt::DateTimeEdit.new(Qt::Date.currentDate()) dateEdit.setDateRange(Qt::Date.new(2005, 1, 1), Qt::Date.new(2010, 12, 31)) dateLabel.text = tr("Appointment date (between %s and %s:" % [dateEdit.minimumDate().toString(Qt::ISODate), dateEdit.maximumDate().toString(Qt::ISODate) ] ) timeLabel = Qt::Label.new timeEdit = Qt::DateTimeEdit.new(Qt::Time.currentTime()) timeEdit.setTimeRange(Qt::Time.new(9, 0, 0, 0), Qt::Time.new(16, 30, 0, 0)) timeLabel.text = tr("Appointment time (between %s and %s:" % [timeEdit.minimumTime().toString(Qt::ISODate), timeEdit.maximumTime().toString(Qt::ISODate) ] ) @meetingLabel = Qt::Label.new @meetingEdit = Qt::DateTimeEdit.new(Qt::DateTime.currentDateTime()) formatLabel = Qt::Label.new(tr("Format string for the meeting date and time:")) formatComboBox = Qt::ComboBox.new do |f| f.addItem("yyyy-MM-dd hh:mm:ss (zzz ms)") f.addItem("hh:mm:ss MM/dd/yyyy") f.addItem("hh:mm:ss dd/MM/yyyy") f.addItem("hh:mm:ss") f.addItem("hh:mm ap") end connect(formatComboBox, SIGNAL('activated(const QString&)'), self, SLOT('setFormatString(const QString&)')) setFormatString(formatComboBox.currentText()) editsLayout = Qt::VBoxLayout.new do |l| l.addWidget(dateLabel) l.addWidget(dateEdit) l.addWidget(timeLabel) l.addWidget(timeEdit) l.addWidget(@meetingLabel) l.addWidget(@meetingEdit) l.addWidget(formatLabel) l.addWidget(formatComboBox) end @editsGroup.layout = editsLayout end
# File examples/widgets/spinboxes/window.rb, line 154 def createDoubleSpinBoxes() @doubleSpinBoxesGroup = Qt::GroupBox.new(tr("Double precision spinboxes")) precisionLabel = Qt::Label.new(tr("Number of decimal places to show:")) precisionSpinBox = Qt::SpinBox.new do |s| s.range = 0..14 s.value = 2 end doubleLabel = Qt::Label.new(tr("Enter a value between %d and %d:" % [-20, 20])) @doubleSpinBox = Qt::DoubleSpinBox.new do |s| s.range = -20.0..20.0 s.singleStep = 1.0 s.value = 0.0 end scaleLabel = Qt::Label.new(tr("Enter a scale factor between %2f and %2f:" % [0.0, 1000.0])) @scaleSpinBox = Qt::DoubleSpinBox.new do |s| s.range = 0.0..1000.0 s.singleStep = 10.0 s.suffix = "%" s.specialValueText = tr("No scaling") s.value = 100.0 end priceLabel = Qt::Label.new(tr("Enter a price between %2f and %2f:" % [0.0, 1000.0])) @priceSpinBox = Qt::DoubleSpinBox.new do |s| s.range = 0.0..1000.0 s.singleStep = 1.0 s.prefix = "$" s.value = 99.99 end connect(precisionSpinBox, SIGNAL('valueChanged(int)'), self, SLOT('changePrecision(int)')) spinBoxLayout = Qt::VBoxLayout.new do |s| s.addWidget(precisionLabel) s.addWidget(precisionSpinBox) s.addWidget(doubleLabel) s.addWidget(@doubleSpinBox) s.addWidget(scaleLabel) s.addWidget(@scaleSpinBox) s.addWidget(priceLabel) s.addWidget(@priceSpinBox) end @doubleSpinBoxesGroup.layout = spinBoxLayout end
# File examples/dialogs/findfiles/window.rb, line 167 def createFilesTable() @filesTable = Qt::TableWidget.new(0, 2) labels = [] labels << tr("File Name") << tr("Size") @filesTable.horizontalHeaderLabels = labels @filesTable.horizontalHeader().setResizeMode(0, Qt::HeaderView::Stretch) @filesTable.verticalHeader().hide() @filesTable.showGrid = false end
# File examples/widgets/groupbox/window.rb, line 41 def createFirstExclusiveGroup() groupBox = Qt::GroupBox.new(tr("Exclusive Radio Buttons")) radio1 = Qt::RadioButton.new(tr("&Radio button 1")) radio2 = Qt::RadioButton.new(tr("R&adio button 2")) radio3 = Qt::RadioButton.new(tr("Ra&dio button 3")) radio1.checked = true vbox = Qt::VBoxLayout.new vbox.addWidget(radio1) vbox.addWidget(radio2) vbox.addWidget(radio3) vbox.addStretch(1) groupBox.layout = vbox return groupBox end
# File examples/desktop/systray/window.rb, line 114 def createIconGroupBox() @iconGroupBox = Qt::GroupBox.new(tr("Tray Icon")) @iconLabel = Qt::Label.new("Icon:") @iconComboBox = Qt::ComboBox.new @iconComboBox.addItem(Qt::Icon.new(":/images/bad.svg"), tr("Bad")) @iconComboBox.addItem(Qt::Icon.new(":/images/heart.svg"), tr("Heart")) @iconComboBox.addItem(Qt::Icon.new(":/images/trash.svg"), tr("Trash")) @showIconCheckBox = Qt::CheckBox.new(tr("Show icon")) @showIconCheckBox.checked = true @iconGroupBox.layout = Qt::HBoxLayout.new do |l| l.addWidget(@iconLabel) l.addWidget(@iconComboBox) l.addStretch() l.addWidget(@showIconCheckBox) end end
# File examples/layouts/borderlayout/window.rb, line 47 def createLabel(text) label = Qt::Label.new(text) label.frameStyle = Qt::Frame::Box | Qt::Frame::Raised return label end
# File examples/desktop/systray/window.rb, line 135 def createMessageGroupBox() @messageGroupBox = Qt::GroupBox.new(tr("Balloon Message")) @typeLabel = Qt::Label.new(tr("Type:")) @typeComboBox = Qt::ComboBox.new @typeComboBox.addItem(tr("None"), Qt::Variant.new(Qt::SystemTrayIcon::NoIcon.to_i)) @typeComboBox.addItem(style().standardIcon(Qt::Style::SP_MessageBoxInformation), tr("Information"), Qt::Variant.new(Qt::SystemTrayIcon::Information.to_i)) @typeComboBox.addItem(style().standardIcon(Qt::Style::SP_MessageBoxWarning), tr("Warning"), Qt::Variant.new(Qt::SystemTrayIcon::Warning.to_i)) @typeComboBox.addItem(style().standardIcon(Qt::Style::SP_MessageBoxCritical), tr("Critical"), Qt::Variant.new(Qt::SystemTrayIcon::Critical.to_i)) @typeComboBox.currentIndex = 1 @durationLabel = Qt::Label.new(tr("Duration:")) @durationSpinBox = Qt::SpinBox.new do |s| s.range = 5..60 s.suffix = " s" s.value = 15 end @durationWarningLabel = Qt::Label.new(tr("(some systems might ignore self " "hint)")) @durationWarningLabel.indent = 10 @titleLabel = Qt::Label.new(tr("Title:")) @titleEdit = Qt::LineEdit.new(tr("Cannot connect to network")) @bodyLabel = Qt::Label.new(tr("Body:")) @bodyEdit = Qt::TextEdit.new @bodyEdit.setPlainText(tr("Don't believe me. Honestly, I don't have a " "clue.\nClick self balloon for details.")) @showMessageButton = Qt::PushButton.new(tr("Show Message")) @showMessageButton.default = true @messageGroupBox.layout = Qt::GridLayout.new do |m| m.addWidget(@typeLabel, 0, 0) m.addWidget(@typeComboBox, 0, 1, 1, 2) m.addWidget(@durationLabel, 1, 0) m.addWidget(@durationSpinBox, 1, 1) m.addWidget(@durationWarningLabel, 1, 2, 1, 3) m.addWidget(@titleLabel, 2, 0) m.addWidget(@titleEdit, 2, 1, 1, 4) m.addWidget(@bodyLabel, 3, 0) m.addWidget(@bodyEdit, 3, 1, 2, 4) m.addWidget(@showMessageButton, 5, 4) m.setColumnStretch(3, 1) m.setRowStretch(4, 1) end end
# File examples/widgets/groupbox/window.rb, line 83 def createNonExclusiveGroup() groupBox = Qt::GroupBox.new(tr("Non-Exclusive Checkboxes")) groupBox.flat = true checkBox1 = Qt::CheckBox.new(tr("&Checkbox 1")) checkBox2 = Qt::CheckBox.new(tr("C&heckbox 2")) checkBox2.checked = true tristateBox = Qt::CheckBox.new(tr("Tri-&state button")) tristateBox.tristate = true tristateBox.checkState = Qt::PartiallyChecked vbox = Qt::VBoxLayout.new vbox.addWidget(checkBox1) vbox.addWidget(checkBox2) vbox.addWidget(tristateBox) vbox.addStretch(1) groupBox.layout = vbox return groupBox end
# File examples/widgets/groupbox/window.rb, line 104 def createPushButtonGroup() groupBox = Qt::GroupBox.new(tr("&Push Buttons")) groupBox.checkable = true groupBox.checked = true pushButton = Qt::PushButton.new(tr("&Normal Button")) toggleButton = Qt::PushButton.new(tr("&Toggle Button")) toggleButton.checkable = true toggleButton.checked = true flatButton = Qt::PushButton.new(tr("&Flat Button")) flatButton.flat = true popupButton = Qt::PushButton.new(tr("Pop&up Button")) menu = Qt::Menu.new(self) menu.addAction(tr("&First Item")) menu.addAction(tr("&Second Item")) menu.addAction(tr("&Third Item")) menu.addAction(tr("F&ourth Item")) popupButton.menu = menu vbox = Qt::VBoxLayout.new vbox.addWidget(pushButton) vbox.addWidget(toggleButton) vbox.addWidget(flatButton) vbox.addWidget(popupButton) vbox.addStretch(1) groupBox.layout = vbox return groupBox end
# File examples/widgets/groupbox/window.rb, line 60 def createSecondExclusiveGroup() groupBox = Qt::GroupBox.new(tr("E&xclusive Radio Buttons")) groupBox.checkable = true groupBox.checked = false radio1 = Qt::RadioButton.new(tr("Rad&io button 1")) radio2 = Qt::RadioButton.new(tr("Radi&o button 2")) radio3 = Qt::RadioButton.new(tr("Radio &button 3")) radio1.checked = true checkBox = Qt::CheckBox.new(tr("Ind&ependent checkbox")) checkBox.checked = true vbox = Qt::VBoxLayout.new vbox.addWidget(radio1) vbox.addWidget(radio2) vbox.addWidget(radio3) vbox.addWidget(checkBox) vbox.addStretch(1) groupBox.layout = vbox return groupBox end
# File examples/opengl/hellogl/window.rb, line 54 def createSlider(changedSignal, setterSlot) slider = Qt::Slider.new(Qt::Vertical) do |s| s.range = 0..(360 * 16) s.singleStep = 16 s.pageStep = 15 * 16 s.tickInterval = 15 * 16 s.tickPosition = Qt::Slider::TicksRight end connect(slider, SIGNAL('valueChanged(int)'), @glWidget, setterSlot) connect(@glWidget, changedSignal, slider, SLOT('setValue(int)')) return slider end
# File examples/widgets/spinboxes/window.rb, line 49 def createSpinBoxes() @spinBoxesGroup = Qt::GroupBox.new(tr("Spinboxes")) integerLabel = Qt::Label.new(tr("Enter a value between %d and %d:" % [-20, 20])) integerSpinBox = Qt::SpinBox.new do |i| i.range = -20..20 i.singleStep = 1 i.value = 0 end zoomLabel = Qt::Label.new(tr("Enter a zoom value between %d and %d:" % [0, 1000])) zoomSpinBox = Qt::SpinBox.new do |z| z.range = 0..1000 z.singleStep = 10 z.suffix = "%" z.specialValueText = tr("Automatic") z.value = 100 end priceLabel = Qt::Label.new(tr("Enter a price between %d and %d:" % [0, 999])) @priceSpinBox = Qt::SpinBox.new do |s| s.range = 0..999 s.singleStep = 1 s.prefix = "$" s.value = 99 end spinBoxLayout = Qt::VBoxLayout.new do |s| s.addWidget(integerLabel) s.addWidget(integerSpinBox) s.addWidget(zoomLabel) s.addWidget(zoomSpinBox) s.addWidget(priceLabel) s.addWidget(@priceSpinBox) end @spinBoxesGroup.layout = spinBoxLayout end
# File examples/desktop/systray/window.rb, line 208 def createTrayIcon() @trayIconMenu = Qt::Menu.new(self) do |t| t.addAction(@minimizeAction) t.addAction(@maximizeAction) t.addAction(@restoreAction) t.addSeparator() t.addAction(@quitAction) end @trayIcon = Qt::SystemTrayIcon.new(self) @trayIcon.contextMenu = @trayIconMenu end
# File examples/opengl/textures/window.rb, line 68 def currentGlWidget=() @currentGlWidget = sender() end
# File examples/painting/painterpaths/window.rb, line 244 def currentItemData(comboBox) return comboBox.itemData(comboBox.currentIndex()) end
# File examples/painting/painterpaths/window.rb, line 220 def fillGradientChanged() color1 = qVariantValue(Qt::Color, currentItemData(@fillColor1ComboBox)) color2 = qVariantValue(Qt::Color, currentItemData(@fillColor2ComboBox)) (0...NumRenderAreas).each do |i| @renderAreas[i].setFillGradient(color1, color2) end end
# File examples/painting/painterpaths/window.rb, line 212 def fillRuleChanged() rule = currentItemData(@fillRuleComboBox).toInt (0...NumRenderAreas).each do |i| @renderAreas[i].fillRule = rule end end
# File examples/dialogs/findfiles/window.rb, line 76 def find() @filesTable.rowCount = 0 fileName = @fileComboBox.currentText() text = @textComboBox.currentText() path = @directoryComboBox.currentText() directory = Qt::Dir.new(path) if fileName.empty? fileName = "*" end files = directory.entryList([fileName], Qt::Dir::Files | Qt::Dir::NoSymLinks) if !text.empty? files = findFiles(directory, files, text) end showFiles(directory, files) end
# File examples/dialogs/findfiles/window.rb, line 96 def findFiles(directory, files, text) progressDialog = Qt::ProgressDialog.new(self) do |p| p.cancelButtonText = tr("&Cancel") p.range = 0..files.length p.windowTitle = tr("Find Files") end foundFiles = [] (0...files.length).each do |i| progressDialog.value = i progressDialog.labelText = tr("Searching file number %s of %s..." % [i, files.length]) $qApp.processEvents() if progressDialog.wasCanceled break end file = Qt::File.new(directory.absoluteFilePath(files[i])) if file.open(Qt::IODevice::ReadOnly.to_i) inf = Qt::TextStream.new(file) while !inf.atEnd() if progressDialog.wasCanceled() break end line = inf.readLine() if line.include?(text) foundFiles << files[i] break end end end end progressDialog.dispose return foundFiles end
# File examples/desktop/systray/window.rb, line 92 def iconActivated(reason) case reason when Qt::SystemTrayIcon::Trigger when Qt::SystemTrayIcon::DoubleClick @iconComboBox.currentIndex = (iconComboBox.currentIndex + 1) % @iconComboBox.length when Qt::SystemTrayIcon::MiddleClick showMessage() end end
# File examples/desktop/systray/window.rb, line 108 def messageClicked() Qt::MessageBox.information(nil, tr("Systray"), tr("Sorry, I already gave what help I could.\n" "Maybe you should try asking a human?")) end
# File examples/painting/transformations/window.rb, line 132 def operationChanged() operationTable = [ RenderArea::NoTransformation, RenderArea::Rotate, RenderArea::Scale, RenderArea::Translate ] operations = [] (0...NumTransformedAreas).each do |i| index = @operationComboBoxes[i].currentIndex() operations.push(operationTable[index]) @transformedRenderAreas[i].operations = operations end end
# File examples/painting/basicdrawing/window.rb, line 179 def penChanged() width = @penWidthSpinBox.value() style = @penStyleComboBox.itemData(@penStyleComboBox.currentIndex(), @idRole).toInt cap = @penCapComboBox.itemData(@penCapComboBox.currentIndex(), @idRole).toInt join = @penJoinComboBox.itemData(@penJoinComboBox.currentIndex(), @idRole).toInt @renderArea.pen = Qt::Pen.new(Qt::Brush.new(Qt::blue), width, style, cap, join) end
# File examples/painting/painterpaths/window.rb, line 229 def penColorChanged() color = qVariantValue(Qt::Color, currentItemData(@penColorComboBox)) (0...NumRenderAreas).each do |i| @renderAreas[i].penColor = color end end
# File examples/painting/painterpaths/window.rb, line 237 def populateWithColors(comboBox) colorNames = Qt::Color::colorNames() colorNames.each do |name| comboBox.addItem(name, qVariantFromValue(Qt::Color.new(name))) end end
# File examples/opengl/textures/window.rb, line 72 def rotateOneStep() if !@currentGlWidget.nil? @currentGlWidget.rotateBy(+2 * 16, +2 * 16, -1 * 16) end end
# File examples/widgets/spinboxes/window.rb, line 139 def setFormatString(formatString) @meetingEdit.displayFormat = formatString if @meetingEdit.displayedSections() & Qt::DateTimeEdit::DateSections_Mask.to_i @meetingEdit.setDateRange(Qt::Date.new(2004, 11, 1), Qt::Date.new(2005, 11, 30)) @meetingLabel.text = tr("Meeting date (between %s and %s:" % [@meetingEdit.minimumDate().toString(Qt::ISODate), @meetingEdit.maximumDate().toString(Qt::ISODate) ] ) else @meetingEdit.setTimeRange(Qt::Time.new(0, 7, 20, 0), Qt::Time.new(21, 0, 0, 0)) @meetingLabel.text = tr("Meeting time (between %s and %s:" % [@meetingEdit.minimumTime().toString(Qt::ISODate), @meetingEdit.maximumTime().toString(Qt::ISODate) ] ) end end
# File examples/desktop/systray/window.rb, line 84 def setIcon(index) icon = @iconComboBox.itemIcon(index) @trayIcon.icon = icon setWindowIcon(icon) @trayIcon.toolTip = @iconComboBox.itemText(index) end
# File examples/desktop/systray/window.rb, line 64 def setVisible(visible) @minimizeAction.enabled = visible @maximizeAction.enabled = !visible @restoreAction.enabled = !visible super(visible) end
# File examples/painting/transformations/window.rb, line 74 def setupShapes() truck = Qt::PainterPath.new truck.fillRule = Qt::WindingFill truck.moveTo(0.0, 87.0) truck.lineTo(0.0, 60.0) truck.lineTo(10.0, 60.0) truck.lineTo(35.0, 35.0) truck.lineTo(100.0, 35.0) truck.lineTo(100.0, 87.0) truck.lineTo(0.0, 87.0) truck.moveTo(17.0, 60.0) truck.lineTo(55.0, 60.0) truck.lineTo(55.0, 40.0) truck.lineTo(37.0, 40.0) truck.lineTo(17.0, 60.0) truck.addEllipse(17.0, 75.0, 25.0, 25.0) truck.addEllipse(63.0, 75.0, 25.0, 25.0) clock = Qt::PainterPath.new clock.addEllipse(-50.0, -50.0, 100.0, 100.0) clock.addEllipse(-48.0, -48.0, 96.0, 96.0) clock.moveTo(0.0, 0.0) clock.lineTo(-2.0, -2.0) clock.lineTo(0.0, -42.0) clock.lineTo(2.0, -2.0) clock.lineTo(0.0, 0.0) clock.moveTo(0.0, 0.0) clock.lineTo(2.732, -0.732) clock.lineTo(24.495, 14.142) clock.lineTo(0.732, 2.732) clock.lineTo(0.0, 0.0) house = Qt::PainterPath.new house.moveTo(-45.0, -20.0) house.lineTo(0.0, -45.0) house.lineTo(45.0, -20.0) house.lineTo(45.0, 45.0) house.lineTo(-45.0, 45.0) house.lineTo(-45.0, -20.0) house.addRect(15.0, 5.0, 20.0, 35.0) house.addRect(-35.0, -15.0, 25.0, 25.0) text = Qt::PainterPath.new font = Qt::Font.new font.pixelSize = 50 fontBoundingRect = Qt::FontMetrics.new(font).boundingRect(tr("Qt")) text.addText(-Qt::PointF.new(fontBoundingRect.center()), font, tr("Qt")) @shapes = [] @shapes.push(clock) @shapes.push(house) @shapes.push(text) @shapes.push(truck) connect(@shapeComboBox, SIGNAL('activated(int)'), self, SLOT('shapeSelected(int)')) end
# File examples/painting/basicdrawing/window.rb, line 174 def shapeChanged() shape = @shapeComboBox.itemData(@shapeComboBox.currentIndex(), @idRole).toInt @renderArea.shape = shape end
# File examples/painting/transformations/window.rb, line 146 def shapeSelected(index) shape = @shapes[index] @originalRenderArea.shape = shape (0...NumTransformedAreas).each do |i| @transformedRenderAreas[i].shape = shape end end
# File examples/dialogs/findfiles/window.rb, line 134 def showFiles(directory, files) (0...files.length).each do |i| file = Qt::File.new(directory.absoluteFilePath(files[i])) size = Qt::FileInfo.new(file).size() fileNameItem = Qt::TableWidgetItem.new(files[i]) fileNameItem.flags = Qt::ItemIsEnabled.to_i sizeItem = Qt::TableWidgetItem.new("%d KB" % ((size + 1023) / 1024)) sizeItem.textAlignment = Qt::AlignVCenter | Qt::AlignRight sizeItem.flags = Qt::ItemIsEnabled.to_i row = @filesTable.rowCount() @filesTable.insertRow(row) @filesTable.setItem(row, 0, fileNameItem) @filesTable.setItem(row, 1, sizeItem) end @filesFoundLabel.text = tr("%d file(s) found" % files.length()) end
# File examples/desktop/systray/window.rb, line 102 def showMessage() icon = @typeComboBox.itemData(@typeComboBox.currentIndex).to_i @trayIcon.showMessage(@titleEdit.text, @bodyEdit.toPlainText, icon, @durationSpinBox.value() * 1000) end
# File examples/widgets/lineedits/window.rb, line 191 def slotAccessChanged(index) case index when 0 @accessLineEdit.readOnly = false when 1 @accessLineEdit.readOnly = true end end
# File examples/widgets/lineedits/window.rb, line 165 def slotAlignmentChanged(index) case index when 0 @alignmentLineEdit.alignment = Qt::AlignLeft.to_i when 1 @alignmentLineEdit.alignment = Qt::AlignCenter.to_i when 2 @alignmentLineEdit.alignment = Qt::AlignRight.to_i end end
# File examples/widgets/lineedits/window.rb, line 140 def slotEchoChanged(index) case index when 0 @echoLineEdit.echoMode = Qt::LineEdit::Normal when 1 @echoLineEdit.echoMode = Qt::LineEdit::Password when 2 @echoLineEdit.echoMode = Qt::LineEdit::NoEcho end end
# File examples/widgets/lineedits/window.rb, line 176 def slotInputMaskChanged(index) case index when 0 @inputMaskLineEdit.inputMask = "" when 1 @inputMaskLineEdit.inputMask = "+99 99 99 99 99;_" when 2 @inputMaskLineEdit.inputMask = "0000-00-00" @inputMaskLineEdit.text = "00000000" @inputMaskLineEdit.cursorPosition = 0 when 3 @inputMaskLineEdit.inputMask = ">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#" end end
# File examples/widgets/lineedits/window.rb, line 151 def slotValidatorChanged(index) case index when 0 @validatorLineEdit.validator = nil when 1 @validatorLineEdit.validator = Qt::IntValidator.new(@validatorLineEdit) when 2 @validatorLineEdit.validator = Qt::DoubleValidator.new(-999.0, 999.0, 2, @validatorLineEdit) end @validatorLineEdit.text = "" end