Class: Window
- Inherits:
-
Qt::Widget
- Object
- Qt::Base
- Qt::Widget
- Window
- Defined in:
- ext/ruby/qtruby/examples/widgets/groupbox/window.rb,
ext/ruby/qtruby/examples/opengl/hellogl/window.rb,
ext/ruby/qtruby/examples/opengl/textures/window.rb,
ext/ruby/qtruby/examples/widgets/sliders/window.rb,
ext/ruby/qtruby/examples/dialogs/findfiles/window.rb,
ext/ruby/qtruby/examples/widgets/spinboxes/window.rb,
ext/ruby/qtruby/examples/layouts/flowlayouts/window.rb,
ext/ruby/qtruby/examples/layouts/borderlayout/window.rb,
ext/ruby/qtruby/examples/painting/basicdrawing/window.rb,
ext/ruby/qtruby/examples/painting/painterpaths/window.rb,
ext/ruby/qtruby/examples/painting/transformations/window.rb,
ext/ruby/qtruby/examples/painting/concentriccircles/window.rb
Overview
** ** Copyright © 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 [email protected]. ** ** 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
Constant Summary collapse
- NumRows =
2
- NumColumns =
3
- NumRenderAreas =
9
- NumTransformedAreas =
3
Instance Method Summary collapse
- #browse ⇒ Object
- #brushChanged ⇒ Object
- #changePrecision(decimals) ⇒ Object
- #createButton(text, member) ⇒ Object
- #createComboBox(text = "") ⇒ Object
- #createControls(title) ⇒ Object
- #createDateTimeEdits ⇒ Object
- #createDoubleSpinBoxes ⇒ Object
- #createFilesTable ⇒ Object
- #createFirstExclusiveGroup ⇒ Object
- #createLabel(text) ⇒ Object
- #createNonExclusiveGroup ⇒ Object
- #createPushButtonGroup ⇒ Object
- #createSecondExclusiveGroup ⇒ Object
- #createSlider(changedSignal, setterSlot) ⇒ Object
- #createSpinBoxes ⇒ Object
- #currentGlWidget= ⇒ Object
- #currentItemData(comboBox) ⇒ Object
- #fillGradientChanged ⇒ Object
- #fillRuleChanged ⇒ Object
- #find ⇒ Object
- #findFiles(directory, files, text) ⇒ Object
-
#initialize(parent = nil) ⇒ Window
constructor
A new instance of Window.
- #operationChanged ⇒ Object
- #penChanged ⇒ Object
- #penColorChanged ⇒ Object
- #populateWithColors(comboBox) ⇒ Object
- #rotateOneStep ⇒ Object
- #setFormatString(formatString) ⇒ Object
- #setupShapes ⇒ Object
- #shapeChanged ⇒ Object
- #shapeSelected(index) ⇒ Object
- #showFiles(directory, files) ⇒ Object
Methods inherited from Qt::Widget
Methods inherited from Qt::Base
#%, #&, #*, #**, #+, #-, #-@, #/, #<, #<<, #<=, #==, #>, #>=, #>>, #QCOMPARE, #QEXPECT_FAIL, #QFAIL, #QSKIP, #QTEST, #QVERIFY, #QVERIFY2, #QWARN, #^, ancestors, #is_a?, #methods, private_slots, #protected_methods, #public_methods, q_classinfo, q_signal, q_slot, signals, #singleton_methods, slots, #|, #~
Constructor Details
#initialize(parent = nil) ⇒ Window
Returns a new instance of Window.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'ext/ruby/qtruby/examples/opengl/hellogl/window.rb', line 30 def initialize(parent = nil) super @glWidget = GLWidget.new(self) @xSlider = createSlider(SIGNAL('xRotationChanged(int)'), SLOT('setXRotation(int)')) @ySlider = createSlider(SIGNAL('yRotationChanged(int)'), SLOT('setYRotation(int)')) @zSlider = createSlider(SIGNAL('zRotationChanged(int)'), SLOT('setZRotation(int)')) self.layout = Qt::HBoxLayout.new do |m| m.addWidget(@glWidget) m.addWidget(@xSlider) m.addWidget(@ySlider) m.addWidget(@zSlider) end @xSlider.value = 15 * 16 @ySlider.value = 345 * 16 @zSlider.value = 0 * 16 self.windowTitle = tr("Hello GL") end |
Instance Method Details
#browse ⇒ Object
69 70 71 72 73 74 |
# File 'ext/ruby/qtruby/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 |
#brushChanged ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'ext/ruby/qtruby/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 |
#changePrecision(decimals) ⇒ Object
208 209 210 211 212 |
# File 'ext/ruby/qtruby/examples/widgets/spinboxes/window.rb', line 208 def changePrecision(decimals) @doubleSpinBox.decimals = decimals @scaleSpinBox.decimals = decimals @priceSpinBox.decimals = decimals end |
#createButton(text, member) ⇒ Object
153 154 155 156 157 |
# File 'ext/ruby/qtruby/examples/dialogs/findfiles/window.rb', line 153 def createButton(text, member) = Qt::PushButton.new(text) connect(, SIGNAL('clicked()'), self, member) return end |
#createComboBox(text = "") ⇒ Object
159 160 161 162 163 164 165 |
# File 'ext/ruby/qtruby/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 |
#createControls(title) ⇒ Object
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 |
# File 'ext/ruby/qtruby/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 |
#createDateTimeEdits ⇒ Object
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 |
# File 'ext/ruby/qtruby/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 |
#createDoubleSpinBoxes ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'ext/ruby/qtruby/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 |
#createFilesTable ⇒ Object
167 168 169 170 171 172 173 174 175 |
# File 'ext/ruby/qtruby/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 |
#createFirstExclusiveGroup ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'ext/ruby/qtruby/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 |
#createLabel(text) ⇒ Object
47 48 49 50 51 |
# File 'ext/ruby/qtruby/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 |
#createNonExclusiveGroup ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'ext/ruby/qtruby/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 |
#createPushButtonGroup ⇒ Object
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 |
# File 'ext/ruby/qtruby/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")) = Qt::Menu.new(self) .addAction(tr("&First Item")) .addAction(tr("&Second Item")) .addAction(tr("&Third Item")) .addAction(tr("F&ourth Item")) popupButton. = 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 |
#createSecondExclusiveGroup ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'ext/ruby/qtruby/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 |
#createSlider(changedSignal, setterSlot) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'ext/ruby/qtruby/examples/opengl/hellogl/window.rb', line 54 def createSlider(changedSignal, setterSlot) = 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(, SIGNAL('valueChanged(int)'), @glWidget, setterSlot) connect(@glWidget, changedSignal, , SLOT('setValue(int)')) return end |
#createSpinBoxes ⇒ Object
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 |
# File 'ext/ruby/qtruby/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 |
#currentGlWidget= ⇒ Object
68 69 70 |
# File 'ext/ruby/qtruby/examples/opengl/textures/window.rb', line 68 def currentGlWidget=() @currentGlWidget = sender() end |
#currentItemData(comboBox) ⇒ Object
244 245 246 |
# File 'ext/ruby/qtruby/examples/painting/painterpaths/window.rb', line 244 def currentItemData(comboBox) return comboBox.itemData(comboBox.currentIndex()) end |
#fillGradientChanged ⇒ Object
220 221 222 223 224 225 226 227 |
# File 'ext/ruby/qtruby/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 |
#fillRuleChanged ⇒ Object
212 213 214 215 216 217 218 |
# File 'ext/ruby/qtruby/examples/painting/painterpaths/window.rb', line 212 def fillRuleChanged() rule = currentItemData(@fillRuleComboBox).toInt (0...NumRenderAreas).each do |i| @renderAreas[i].fillRule = rule end end |
#find ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'ext/ruby/qtruby/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 |
#findFiles(directory, files, text) ⇒ Object
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 |
# File 'ext/ruby/qtruby/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 |
#operationChanged ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'ext/ruby/qtruby/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 |
#penChanged ⇒ Object
179 180 181 182 183 184 185 186 |
# File 'ext/ruby/qtruby/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 |
#penColorChanged ⇒ Object
229 230 231 232 233 234 235 |
# File 'ext/ruby/qtruby/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 |
#populateWithColors(comboBox) ⇒ Object
237 238 239 240 241 242 |
# File 'ext/ruby/qtruby/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 |
#rotateOneStep ⇒ Object
72 73 74 75 76 |
# File 'ext/ruby/qtruby/examples/opengl/textures/window.rb', line 72 def rotateOneStep() if !@currentGlWidget.nil? @currentGlWidget.rotateBy(+2 * 16, +2 * 16, -1 * 16) end end |
#setFormatString(formatString) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'ext/ruby/qtruby/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 |
#setupShapes ⇒ Object
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 |
# File 'ext/ruby/qtruby/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 |
#shapeChanged ⇒ Object
174 175 176 177 |
# File 'ext/ruby/qtruby/examples/painting/basicdrawing/window.rb', line 174 def shapeChanged() shape = @shapeComboBox.itemData(@shapeComboBox.currentIndex(), @idRole).toInt @renderArea.shape = shape end |
#shapeSelected(index) ⇒ Object
146 147 148 149 150 151 152 |
# File 'ext/ruby/qtruby/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 |
#showFiles(directory, files) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'ext/ruby/qtruby/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 |