Class: MainWindow
- Defined in:
- ext/ruby/qtruby/examples/mainwindows/sdi/mainwindow.rb,
ext/ruby/qtruby/examples/widgets/icons/mainwindow.rb,
ext/ruby/qtruby/examples/opengl/grabber/mainwindow.rb,
ext/ruby/qtruby/examples/itemviews/chart/mainwindow.rb,
ext/ruby/qtruby/examples/mainwindows/mdi/mainwindow.rb,
ext/ruby/qtruby/examples/itemviews/puzzle/mainwindow.rb,
ext/ruby/qtruby/examples/widgets/scribble/mainwindow.rb,
ext/ruby/qtruby/examples/xml/dombookmarks/mainwindow.rb,
ext/ruby/qtruby/examples/xml/saxbookmarks/mainwindow.rb,
ext/ruby/qtruby/examples/mainwindows/menus/mainwindow.rb,
ext/ruby/qtruby/examples/richtext/calendar/mainwindow.rb,
ext/ruby/qtruby/examples/draganddrop/puzzle/mainwindow.rb,
ext/ruby/qtruby/examples/painting/svgviewer/mainwindow.rb,
ext/ruby/qtruby/examples/richtext/orderform/mainwindow.rb,
ext/ruby/qtruby/examples/itemviews/pixelator/mainwindow.rb,
ext/ruby/qtruby/examples/painting/fontsampler/mainwindow.rb,
ext/ruby/qtruby/examples/widgets/charactermap/mainwindow.rb,
ext/ruby/qtruby/examples/mainwindows/application/mainwindow.rb,
ext/ruby/qtruby/examples/mainwindows/dockwidgets/mainwindow.rb,
ext/ruby/qtruby/examples/mainwindows/recentfiles/mainwindow.rb,
ext/ruby/qtruby/examples/itemviews/simpledommodel/mainwindow.rb,
ext/ruby/qtruby/examples/richtext/syntaxhighlighter/mainwindow.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
- RAND_MAX =
2147483647
- MaxRecentFiles =
5
- @@sequenceNumber =
0
Instance Attribute Summary collapse
-
#curFile ⇒ Object
readonly
Returns the value of attribute curFile.
Instance Method Summary collapse
- #about ⇒ Object
- #aboutQt ⇒ Object
- #activeMdiChild ⇒ Object
- #addImage ⇒ Object
- #addParagraph(paragraph) ⇒ Object
- #bold ⇒ Object
- #center ⇒ Object
- #changeIcon ⇒ Object
- #changeSize ⇒ Object
- #changeStyle(checked) ⇒ Object
- #checkCurrentStyle ⇒ Object
- #chooseImage ⇒ Object
- #clearPixmap ⇒ Object
- #closeEvent(event) ⇒ Object
- #contextMenuEvent(event) ⇒ Object
- #copy ⇒ Object
- #createActions ⇒ Object
- #createContextMenu ⇒ Object
- #createDockWindows ⇒ Object
- #createIconSizeGroupBox ⇒ Object
- #createImagesGroupBox ⇒ Object
- #createLetter(name, address, orderItems, sendOffers) ⇒ Object
- #createMdiChild ⇒ Object
- #createMenus ⇒ Object
- #createPreviewGroupBox ⇒ Object
- #createSample ⇒ Object
- #createSlider(changedSignal, setterSlot) ⇒ Object
- #createStatusBar ⇒ Object
- #createToolBars ⇒ Object
- #currentPageMap ⇒ Object
- #cut ⇒ Object
- #documentWasModified ⇒ Object
- #findFonts ⇒ Object
- #findMainWindow(fileName) ⇒ Object
- #findMdiChild(fileName) ⇒ Object
- #findStyles ⇒ Object
- #fontSize=(size) ⇒ Object
- #getSize ⇒ Object
- #grabFrameBuffer ⇒ Object
- #init ⇒ Object
-
#initialize(parent = nil) ⇒ MainWindow
constructor
A new instance of MainWindow.
- #insertCalendar ⇒ Object
- #insertCharacter(character) ⇒ Object
- #insertCustomer(customer) ⇒ Object
- #italic ⇒ Object
- #justify ⇒ Object
- #leftAlign ⇒ Object
- #loadFile(fileName) ⇒ Object
- #markUnmarkFonts(state) ⇒ Object
- #maybeSave ⇒ Object
- #month=(month) ⇒ Object
- #newFile ⇒ Object
- #newLetter ⇒ Object
- #on_clearAction_triggered ⇒ Object
- #on_markAction_triggered ⇒ Object
- #on_printAction_triggered ⇒ Object
- #on_printPreviewAction_triggered ⇒ Object
- #on_unmarkAction_triggered ⇒ Object
- #open ⇒ Object
- #openDialog ⇒ Object
- #openFile(path = nil) ⇒ Object
- #openImage(fileName) ⇒ Object
- #openRecentFile ⇒ Object
- #paste ⇒ Object
- #penColor ⇒ Object
- #penWidth ⇒ Object
- #print ⇒ Object
- #printFile ⇒ Object
- #printImage ⇒ Object
- #printPage(index, painter, printer) ⇒ Object
- #readSettings ⇒ Object
- #redo ⇒ Object
- #removeAllImages ⇒ Object
- #renderer=(action) ⇒ Object
- #renderIntoPixmap ⇒ Object
- #rightAlign ⇒ Object
- #save ⇒ Object
- #saveAs ⇒ Object
- #saveFile(fileName) ⇒ Object
- #setCompleted ⇒ Object
- #setCurrentFile(fileName) ⇒ Object
- #setLineSpacing ⇒ Object
- #setParagraphSpacing ⇒ Object
- #setPixmap(pixmap) ⇒ Object
- #setupEditor ⇒ Object
- #setupFileMenu ⇒ Object
- #setupFontTree ⇒ Object
- #setupMenus ⇒ Object
- #setupModel ⇒ Object
- #setupPrinter(printer) ⇒ Object
- #setupPuzzle ⇒ Object
- #setupViews ⇒ Object
- #setupWidgets ⇒ Object
- #showAboutBox ⇒ Object
- #showFont(item) ⇒ Object
- #strippedName(fullFileName) ⇒ Object
- #undo ⇒ Object
- #updateClipboard ⇒ Object
- #updateMenus ⇒ Object
- #updateRecentFileActions ⇒ Object
- #updateStyles(item, column) ⇒ Object
- #updateView ⇒ Object
- #updateWindowMenu ⇒ Object
- #writeSettings ⇒ Object
- #year=(date) ⇒ Object
Constructor Details
#initialize(parent = nil) ⇒ MainWindow
Returns a new instance of MainWindow.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'ext/ruby/qtruby/examples/widgets/icons/mainwindow.rb', line 39 def initialize() super @centralWidget = Qt::Widget.new setCentralWidget(@centralWidget) createPreviewGroupBox() createImagesGroupBox() createIconSizeGroupBox() createActions() createMenus() createContextMenu() mainLayout = Qt::GridLayout.new mainLayout.addWidget(@imagesGroupBox, 0, 0) mainLayout.addWidget(@iconSizeGroupBox, 1, 0) mainLayout.addWidget(@previewGroupBox, 0, 1, 2, 1) @centralWidget.layout = mainLayout setWindowTitle(tr("Icons")) checkCurrentStyle() @otherRadioButton.click() resize(860, 400) end |
Instance Attribute Details
#curFile ⇒ Object (readonly)
Returns the value of attribute curFile.
35 36 37 |
# File 'ext/ruby/qtruby/examples/mainwindows/sdi/mainwindow.rb', line 35 def curFile @curFile end |
Instance Method Details
#about ⇒ Object
64 65 66 67 68 69 |
# File 'ext/ruby/qtruby/examples/widgets/icons/mainwindow.rb', line 64 def about() Qt::MessageBox.about(self, tr("About Icons"), tr("The <b>Icons</b> example illustrates how Qt renders an icon in " + "different modes (active, normal, and disabled) and states (on " + "and off) based on a set of images.")) end |
#aboutQt ⇒ Object
164 165 166 |
# File 'ext/ruby/qtruby/examples/mainwindows/menus/mainwindow.rb', line 164 def aboutQt() @infoLabel.text = tr("Invoked <b>Help|About Qt</b>") end |
#activeMdiChild ⇒ Object
344 345 346 347 348 349 350 |
# File 'ext/ruby/qtruby/examples/mainwindows/mdi/mainwindow.rb', line 344 def activeMdiChild() if @mdiArea.activeSubWindow return @mdiArea.activeSubWindow. else return nil end end |
#addImage ⇒ Object
153 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 |
# File 'ext/ruby/qtruby/examples/widgets/icons/mainwindow.rb', line 153 def addImage() fileNames = Qt::FileDialog.getOpenFileNames(self, tr("Open Images"), "", tr("Images (*.png *.xpm *.jpg);;" + "All Files (*)") ) if !fileNames.nil? fileNames.each do |fileName| row = @imagesTable.rowCount() @imagesTable.rowCount = row + 1 imageName = Qt::FileInfo.new(fileName).baseName() item0 = Qt::TableWidgetItem.new(imageName) item0.setData(Qt::UserRole, Qt::Variant.new(fileName)) item0.flags &= ~Qt::ItemIsEditable item1 = Qt::TableWidgetItem.new(tr("Normal")) item2 = Qt::TableWidgetItem.new(tr("Off")) if @guessModeStateAct.checked? if fileName.include?("_act") item1.text = tr("Active") elsif fileName.include?("_dis") item1.text = tr("Disabled") end if fileName.include?("_on") item2.text = tr("On") end end @imagesTable.setItem(row, 0, item0) @imagesTable.setItem(row, 1, item1) @imagesTable.setItem(row, 2, item2) @imagesTable.openPersistentEditor(item1) @imagesTable.openPersistentEditor(item2) item0.checkState = Qt::Checked end end end |
#addParagraph(paragraph) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'ext/ruby/qtruby/examples/mainwindows/dockwidgets/mainwindow.rb', line 167 def addParagraph(paragraph) if paragraph.empty? return end document = @textEdit.document() cursor = document.find(tr("Yours sincerely,")) if cursor.nil? return end cursor.beginEditBlock() cursor.movePosition(Qt::TextCursor::PreviousBlock, Qt::TextCursor::MoveAnchor, 2) cursor.insertBlock() cursor.insertText(paragraph) cursor.insertBlock() cursor.endEditBlock() end |
#bold ⇒ Object
125 126 127 |
# File 'ext/ruby/qtruby/examples/mainwindows/menus/mainwindow.rb', line 125 def bold() @infoLabel.text = tr("Invoked <b>Edit|Format|Bold</b>") end |
#center ⇒ Object
145 146 147 |
# File 'ext/ruby/qtruby/examples/mainwindows/menus/mainwindow.rb', line 145 def center() @infoLabel.text = tr("Invoked <b>Edit|Format|Center</b>") end |
#changeIcon ⇒ Object
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 |
# File 'ext/ruby/qtruby/examples/widgets/icons/mainwindow.rb', line 121 def changeIcon() icon = Qt::Icon.new (0...@imagesTable.rowCount).each do |row| item0 = @imagesTable.item(row, 0) item1 = @imagesTable.item(row, 1) item2 = @imagesTable.item(row, 2) if item0.checkState() == Qt::Checked if item1.text() == tr("Normal") mode = Qt::Icon::Normal elsif item1.text() == tr("Active") mode = Qt::Icon::Active else mode = Qt::Icon::Disabled end if item2.text() == tr("On") state = Qt::Icon::On else state = Qt::Icon::Off end fileName = item0.data(Qt::UserRole).toString() image = Qt::Image.new(fileName) if !image.nil? icon.addPixmap(Qt::Pixmap.fromImage(image), mode, state) end end end @previewArea.icon = icon end |
#changeSize ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'ext/ruby/qtruby/examples/widgets/icons/mainwindow.rb', line 99 def changeSize() if @otherRadioButton.checked? extent = @otherSpinBox.value else if @smallRadioButton.checked? metric = Qt::Style::PM_SmallIconSize elsif @largeRadioButton.checked? metric = Qt::Style::PM_LargeIconSize elsif @toolBarRadioButton.checked? metric = Qt::Style::PM_ToolBarIconSize elsif @listViewRadioButton.checked? metric = Qt::Style::PM_ListViewIconSize else metric = Qt::Style::PM_IconViewIconSize end extent = Qt::Application::style().pixelMetric(metric) end @previewArea.size = Qt::Size.new(extent, extent) @otherSpinBox.enabled = @otherRadioButton.checked? end |
#changeStyle(checked) ⇒ Object
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 |
# File 'ext/ruby/qtruby/examples/widgets/icons/mainwindow.rb', line 71 def changeStyle(checked) if !checked return end action = sender() style = Qt::StyleFactory.create(action.data().toString()) Qt::Application.style = style @smallRadioButton.text = tr("Small (%d x %d" % [ style.pixelMetric(Qt::Style::PM_SmallIconSize), style.pixelMetric(Qt::Style::PM_SmallIconSize) ] ) @largeRadioButton.text = tr("Large (%d x %d" % [ style.pixelMetric(Qt::Style::PM_LargeIconSize), style.pixelMetric(Qt::Style::PM_LargeIconSize) ] ) @toolBarRadioButton.text = tr("Toolbars (%d x %d" % [ style.pixelMetric(Qt::Style::PM_ToolBarIconSize), style.pixelMetric(Qt::Style::PM_ToolBarIconSize) ] ) @listViewRadioButton.text = tr("List views (%d x %d" % [ style.pixelMetric(Qt::Style::PM_ListViewIconSize), style.pixelMetric(Qt::Style::PM_ListViewIconSize) ] ) @iconViewRadioButton.text = tr("Icon views (%d x %d" % [ style.pixelMetric(Qt::Style::PM_IconViewIconSize), style.pixelMetric(Qt::Style::PM_IconViewIconSize) ] ) changeSize() end |
#checkCurrentStyle ⇒ Object
339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'ext/ruby/qtruby/examples/widgets/icons/mainwindow.rb', line 339 def checkCurrentStyle() @styleActionGroup.actions().each do |action| styleName = action.data().toString() candidate = Qt::StyleFactory.create(styleName) if candidate.().className() == Qt::Application.style().().className() action.trigger() return end end end |
#chooseImage ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'ext/ruby/qtruby/examples/itemviews/pixelator/mainwindow.rb', line 102 def chooseImage fileName = Qt::FileDialog.getOpenFileName(self, tr("Choose an image"), @currentPath, "*") if !fileName.nil? if openImage(fileName) @currentPath = fileName end end end |
#clearPixmap ⇒ Object
97 98 99 |
# File 'ext/ruby/qtruby/examples/opengl/grabber/mainwindow.rb', line 97 def clearPixmap() setPixmap(Qt::Pixmap.new) end |
#closeEvent(event) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'ext/ruby/qtruby/examples/mainwindows/mdi/mainwindow.rb', line 66 def closeEvent(event) @mdiArea.closeAllSubWindows() if activeMdiChild() event.ignore() else writeSettings() event.accept() end end |
#contextMenuEvent(event) ⇒ Object
81 82 83 84 85 86 87 |
# File 'ext/ruby/qtruby/examples/mainwindows/menus/mainwindow.rb', line 81 def contextMenuEvent(event) = Qt::Menu.new(self) .addAction(@cutAct) .addAction(@copyAct) .addAction(@pasteAct) .exec(event.globalPos()) end |
#copy ⇒ Object
119 120 121 122 123 |
# File 'ext/ruby/qtruby/examples/mainwindows/mdi/mainwindow.rb', line 119 def copy() if activeMdiChild() activeMdiChild().copy() end end |
#createActions ⇒ Object
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'ext/ruby/qtruby/examples/widgets/icons/mainwindow.rb', line 276 def createActions() @addImageAct = Qt::Action.new(tr("&Add Image..."), self) @addImageAct.shortcut = Qt::KeySequence.new(tr("Ctrl+A")) connect(@addImageAct, SIGNAL('triggered()'), self, SLOT('addImage()')) @removeAllImagesAct = Qt::Action.new(tr("&Remove All Images"), self) @removeAllImagesAct.shortcut = Qt::KeySequence.new(tr("Ctrl+R")) connect(@removeAllImagesAct, SIGNAL('triggered()'), self, SLOT('removeAllImages()')) @exitAct = Qt::Action.new(tr("&Quit"), self) @exitAct.shortcut = Qt::KeySequence.new(tr("Ctrl+Q")) connect(@exitAct, SIGNAL('triggered()'), self, SLOT('close()')) @styleActionGroup = Qt::ActionGroup.new(self) Qt::StyleFactory::keys().each do |styleName| action = Qt::Action.new(@styleActionGroup) action.text = tr("%s Style" % styleName) action.data = Qt::Variant.new(styleName) action.checkable = true connect(action, SIGNAL('triggered(bool)'), self, SLOT('changeStyle(bool)')) end @guessModeStateAct = Qt::Action.new(tr("&Guess Image Mode/State"), self) @guessModeStateAct.checkable = true @guessModeStateAct.checked = true @aboutAct = Qt::Action.new(tr("&About"), self) connect(@aboutAct, SIGNAL('triggered()'), self, SLOT('about()')) @aboutQtAct = Qt::Action.new(tr("About &Qt"), self) connect(@aboutQtAct, SIGNAL('triggered()'), $qApp, SLOT('aboutQt()')) end |
#createContextMenu ⇒ Object
333 334 335 336 337 |
# File 'ext/ruby/qtruby/examples/widgets/icons/mainwindow.rb', line 333 def createContextMenu() @imagesTable.contextMenuPolicy = Qt::ActionsContextMenu @imagesTable.addAction(@addImageAct) @imagesTable.addAction(@removeAllImagesAct) end |
#createDockWindows ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'ext/ruby/qtruby/examples/mainwindows/dockwidgets/mainwindow.rb', line 260 def createDockWindows() dock = Qt::DockWidget.new(tr("Customers"), self) dock.allowedAreas = Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea @customerList = Qt::ListWidget.new(dock) @customerList.addItems([] << "John Doe, Harmony Enterprises, 12 Lakeside, Ambleton" << "Jane Doe, Memorabilia, 23 Watersedge, Beaton" << "Tammy Shea, Tiblanka, 38 Sea Views, Carlton" << "Tim Sheen, Caraba Gifts, 48 Ocean Way, Deal" << "Sol Harvey, Chicos Coffee, 53 New Springs, Eccleston" << "Sally Hobart, Tiroli Tea, 67 Long River, Fedula") dock. = @customerList addDockWidget(Qt::RightDockWidgetArea, dock) dock = Qt::DockWidget.new(tr("Paragraphs"), self) @paragraphsList = Qt::ListWidget.new(dock) @paragraphsList.addItems([] << "Thank you for your payment which we have received today." << "Your order has been dispatched and should be with you " \ "within 28 days." << "We have dispatched those items that were in stock. The " \ "rest of your order will be dispatched once all the " \ "remaining items have arrived at our warehouse. No " \ "additional shipping charges will be made." << "You made a small overpayment (less than $5) which we " \ "will keep on account for you, or return at your request." << "You made a small underpayment (less than $1), but we have " \ "sent your order anyway. We'll add self underpayment to " \ "your next bill." << "Unfortunately you did not send enough money. Please remit " \ "an additional $. Your order will be dispatched as soon as " \ "the complete amount has been received." << "You made an overpayment (more than $5). Do you wish to " \ "buy more items, or should we return the excess to you?") dock. = @paragraphsList addDockWidget(Qt::RightDockWidgetArea, dock) connect(@customerList, SIGNAL('currentTextChanged(const QString&)'), self, SLOT('insertCustomer(const QString&)')) connect(@paragraphsList, SIGNAL('currentTextChanged(const QString&)'), self, SLOT('addParagraph(const QString&)')) end |
#createIconSizeGroupBox ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'ext/ruby/qtruby/examples/widgets/icons/mainwindow.rb', line 237 def createIconSizeGroupBox() @iconSizeGroupBox = Qt::GroupBox.new(tr("Icon Size")) @smallRadioButton = Qt::RadioButton.new @largeRadioButton = Qt::RadioButton.new @toolBarRadioButton = Qt::RadioButton.new @listViewRadioButton = Qt::RadioButton.new @iconViewRadioButton = Qt::RadioButton.new @otherRadioButton = Qt::RadioButton.new(tr("Other:")) @otherSpinBox = IconSizeSpinBox.new @otherSpinBox.range = 8..128 @otherSpinBox.value = 64 connect(@toolBarRadioButton, SIGNAL('toggled(bool)'), self, SLOT('changeSize()')) connect(@listViewRadioButton, SIGNAL('toggled(bool)'), self, SLOT('changeSize()')) connect(@iconViewRadioButton, SIGNAL('toggled(bool)'), self, SLOT('changeSize()')) connect(@smallRadioButton, SIGNAL('toggled(bool)'), self, SLOT('changeSize()')) connect(@largeRadioButton, SIGNAL('toggled(bool)'), self, SLOT('changeSize()')) connect(@otherRadioButton, SIGNAL('toggled(bool)'), self, SLOT('changeSize()')) connect(@otherSpinBox, SIGNAL('valueChanged(int)'), self, SLOT('changeSize()')) otherSizeLayout = Qt::HBoxLayout.new otherSizeLayout.addWidget(@otherRadioButton) otherSizeLayout.addWidget(@otherSpinBox) layout = Qt::GridLayout.new layout.addWidget(@smallRadioButton, 0, 0) layout.addWidget(@largeRadioButton, 1, 0) layout.addWidget(@toolBarRadioButton, 2, 0) layout.addWidget(@listViewRadioButton, 0, 1) layout.addWidget(@iconViewRadioButton, 1, 1) layout.addLayout(otherSizeLayout, 2, 1) @iconSizeGroupBox.layout = layout end |
#createImagesGroupBox ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'ext/ruby/qtruby/examples/widgets/icons/mainwindow.rb', line 209 def createImagesGroupBox() @imagesGroupBox = Qt::GroupBox.new(tr("Images")) @imagesGroupBox.setSizePolicy(Qt::SizePolicy::Expanding, Qt::SizePolicy::Expanding) labels = [] labels << tr("Image") << tr("Mode") << tr("State") @imagesTable = Qt::TableWidget.new @imagesTable.setSizePolicy(Qt::SizePolicy::Expanding, Qt::SizePolicy::Ignored) @imagesTable.selectionMode = Qt::AbstractItemView::NoSelection @imagesTable.columnCount = 3 @imagesTable.horizontalHeaderLabels = labels @imagesTable.itemDelegate = ImageDelegate.new(self) @imagesTable.horizontalHeader().resizeSection(0, 160) @imagesTable.horizontalHeader().resizeSection(1, 80) @imagesTable.horizontalHeader().resizeSection(2, 80) @imagesTable.verticalHeader().hide() connect(@imagesTable, SIGNAL('itemChanged(QTableWidgetItem*)'), self, SLOT('changeIcon()')) layout = Qt::VBoxLayout.new layout.addWidget(@imagesTable) @imagesGroupBox.layout = layout end |
#createLetter(name, address, orderItems, sendOffers) ⇒ Object
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 164 165 |
# File 'ext/ruby/qtruby/examples/richtext/orderform/mainwindow.rb', line 54 def createLetter(name, address, orderItems, sendOffers) editor = Qt::TextEdit.new tabIndex = @letters.addTab(editor, name) @letters.currentIndex = tabIndex cursor = Qt::TextCursor.new(editor.textCursor()) cursor.movePosition(Qt::TextCursor::Start) topFrame = cursor.currentFrame() topFrameFormat = topFrame.frameFormat() topFrameFormat.padding = 16 topFrame.frameFormat = topFrameFormat textFormat = Qt::TextCharFormat.new boldFormat = Qt::TextCharFormat.new boldFormat.fontWeight = Qt::Font::Bold referenceFrameFormat = Qt::TextFrameFormat.new do |r| r.border = 1 r.padding = 8 r.position = Qt::TextFrameFormat::FloatRight r.width = Qt::TextLength.new(Qt::TextLength::PercentageLength, 40) end cursor.insertFrame(referenceFrameFormat) cursor.insertText("A company", boldFormat) cursor.insertBlock() cursor.insertText("321 City Street") cursor.insertBlock() cursor.insertText("Industry Park") cursor.insertBlock() cursor.insertText("Another country") cursor.position = topFrame.lastPosition() cursor.insertText(name, textFormat) address.split("\n").each do |line| cursor.insertBlock() cursor.insertText(line) end cursor.insertBlock() cursor.insertBlock() date = Qt::Date.currentDate() cursor.insertText(tr("Date: %s" % date.toString("d MMMM yyyy")), textFormat) cursor.insertBlock() bodyFrameFormat = Qt::TextFrameFormat.new bodyFrameFormat.setWidth(Qt::TextLength.new(Qt::TextLength::PercentageLength, 100)) cursor.insertFrame(bodyFrameFormat) cursor.insertText(tr("I would like to place an order for the following " + "items:"), textFormat) cursor.insertBlock() orderTableFormat = Qt::TextTableFormat.new orderTableFormat.alignment = Qt::AlignHCenter.to_i orderTable = cursor.insertTable(1, 2, orderTableFormat) orderFrameFormat = cursor.currentFrame().frameFormat() orderFrameFormat.border = 1 cursor.currentFrame().frameFormat = orderFrameFormat cursor = orderTable.cellAt(0, 0).firstCursorPosition() cursor.insertText(tr("Product"), boldFormat) cursor = orderTable.cellAt(0, 1).firstCursorPosition() cursor.insertText(tr("Quantity"), boldFormat) (0...orderItems.length).each do |i| item = orderItems[i] row = orderTable.rows() orderTable.insertRows(row, 1) cursor = orderTable.cellAt(row, 0).firstCursorPosition() cursor.insertText(item[0], textFormat) cursor = orderTable.cellAt(row, 1).firstCursorPosition() cursor.insertText("%s" % item[1], textFormat) end cursor.position = topFrame.lastPosition() cursor.insertText(tr("Please update my records to take account of the " + "following privacy information:")) cursor.insertBlock() offersTable = cursor.insertTable(2, 2) cursor = offersTable.cellAt(0, 1).firstCursorPosition() cursor.insertText(tr("I want to receive more information about your " + "company's products and special offers."), textFormat) cursor = offersTable.cellAt(1, 1).firstCursorPosition() cursor.insertText(tr("I do not want to receive any promotional information " + "from your company."), textFormat) if sendOffers cursor = offersTable.cellAt(0, 0).firstCursorPosition() else cursor = offersTable.cellAt(1, 0).firstCursorPosition() end cursor.insertText("X", boldFormat) cursor.position = topFrame.lastPosition() cursor.insertBlock cursor.insertText(tr("Sincerely,"), textFormat) cursor.insertBlock cursor.insertBlock cursor.insertBlock cursor.insertText(name) @printAction.enabled = true end |
#createMdiChild ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 |
# File 'ext/ruby/qtruby/examples/mainwindows/mdi/mainwindow.rb', line 188 def createMdiChild() child = MdiChild.new @mdiArea.addSubWindow(child) connect(child, SIGNAL('copyAvailable(bool)'), @cutAct, SLOT('setEnabled(bool)')) connect(child, SIGNAL('copyAvailable(bool)'), @copyAct, SLOT('setEnabled(bool)')) return child end |
#createMenus ⇒ Object
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'ext/ruby/qtruby/examples/widgets/icons/mainwindow.rb', line 311 def createMenus() @fileMenu = ().addMenu(tr("&File")) @fileMenu.addAction(@addImageAct) @fileMenu.addAction(@removeAllImagesAct) @fileMenu.addSeparator() @fileMenu.addAction(@exitAct) @viewMenu = ().addMenu(tr("&View")) @styleActionGroup.actions().each do |action| @viewMenu.addAction(action) end @viewMenu.addSeparator() @viewMenu.addAction(@guessModeStateAct) ().addSeparator() @helpMenu = ().addMenu(tr("&Help")) @helpMenu.addAction(@aboutAct) @helpMenu.addAction(@aboutQtAct) end |
#createPreviewGroupBox ⇒ Object
199 200 201 202 203 204 205 206 207 |
# File 'ext/ruby/qtruby/examples/widgets/icons/mainwindow.rb', line 199 def createPreviewGroupBox() @previewGroupBox = Qt::GroupBox.new(tr("Preview")) @previewArea = IconPreviewArea.new layout = Qt::VBoxLayout.new layout.addWidget(@previewArea) @previewGroupBox.layout = layout end |
#createSample ⇒ Object
167 168 169 170 171 |
# File 'ext/ruby/qtruby/examples/richtext/orderform/mainwindow.rb', line 167 def createSample() dialog = DetailsDialog.new("Dialog with default values", self) createLetter("Mr Smith", "12 High Street\nSmall Town\nThis country", dialog.orderItems, true) end |
#createSlider(changedSignal, setterSlot) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'ext/ruby/qtruby/examples/opengl/grabber/mainwindow.rb', line 146 def createSlider(changedSignal, setterSlot) = Qt::Slider.new(Qt::Horizontal) 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 |
#createStatusBar ⇒ Object
326 327 328 |
# File 'ext/ruby/qtruby/examples/mainwindows/mdi/mainwindow.rb', line 326 def createStatusBar() statusBar().showMessage(tr("Ready")) end |
#createToolBars ⇒ Object
314 315 316 317 318 319 320 321 322 323 324 |
# File 'ext/ruby/qtruby/examples/mainwindows/mdi/mainwindow.rb', line 314 def createToolBars() @fileToolBar = addToolBar(tr("File")) @fileToolBar.addAction(@newAct) @fileToolBar.addAction(@openAct) @fileToolBar.addAction(@saveAct) @editToolBar = addToolBar(tr("Edit")) @editToolBar.addAction(@cutAct) @editToolBar.addAction(@copyAct) @editToolBar.addAction(@pasteAct) end |
#currentPageMap ⇒ Object
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'ext/ruby/qtruby/examples/painting/fontsampler/mainwindow.rb', line 279 def currentPageMap() pageMap = {} for row in 0..@ui.fontTree.topLevelItemCount familyItem = @ui.fontTree.topLevelItem(row) if familyItem.checkState(0) == Qt::Checked family = familyItem.text(0) pageMap[family] = [] end for childRow in 0..familyItem.childCount styleItem = familyItem.child(childRow) if styleItem.checkState(0) == Qt::Checked pageMap[family].append(styleItem) end end end return pageMap end |
#cut ⇒ Object
113 114 115 116 117 |
# File 'ext/ruby/qtruby/examples/mainwindows/mdi/mainwindow.rb', line 113 def cut() if activeMdiChild() activeMdiChild().cut() end end |
#documentWasModified ⇒ Object
115 116 117 |
# File 'ext/ruby/qtruby/examples/mainwindows/sdi/mainwindow.rb', line 115 def documentWasModified() setWindowModified(true) end |
#findFonts ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'ext/ruby/qtruby/examples/widgets/charactermap/mainwindow.rb', line 87 def findFonts() fontDatabase = Qt::FontDatabase.new @fontCombo.clear fontDatabase.families().each do |family| @fontCombo.addItem(family) end end |
#findMainWindow(fileName) ⇒ Object
325 326 327 328 329 330 331 332 333 334 |
# File 'ext/ruby/qtruby/examples/mainwindows/sdi/mainwindow.rb', line 325 def findMainWindow(fileName) canonicalFilePath = Qt::FileInfo.new(fileName).canonicalFilePath() $qApp.topLevelWidgets.each do || if .kind_of?(MainWindow) && .curFile == canonicalFilePath return mainWin end end return nil end |
#findMdiChild(fileName) ⇒ Object
352 353 354 355 356 357 358 359 360 361 362 |
# File 'ext/ruby/qtruby/examples/mainwindows/mdi/mainwindow.rb', line 352 def findMdiChild(fileName) canonicalFilePath = Qt::FileInfo.new(fileName).canonicalFilePath() @mdiArea.windowList().each do |window| mdiChild = window if mdiChild.currentFile() == canonicalFilePath return mdiChild end end return nil end |
#findStyles ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'ext/ruby/qtruby/examples/widgets/charactermap/mainwindow.rb', line 96 def findStyles() fontDatabase = Qt::FontDatabase.new currentItem = @styleCombo.currentText() @styleCombo.clear() fontDatabase.styles(@fontCombo.currentText()).each do |style| @styleCombo.addItem(style) end if @styleCombo.findText(currentItem) == -1 @styleCombo.currentIndex = 0 end end |
#fontSize=(size) ⇒ Object
159 160 161 162 |
# File 'ext/ruby/qtruby/examples/richtext/calendar/mainwindow.rb', line 159 def fontSize=(size) @fontSize = size insertCalendar() end |
#getSize ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'ext/ruby/qtruby/examples/opengl/grabber/mainwindow.rb', line 168 def getSize() ok = Qt::Boolean.new text = Qt::InputDialog.getText(self, tr("Grabber"), tr("Enter pixmap size:"), Qt::LineEdit::Normal, tr("%d x %d" % [@glWidget.width, @glWidget.height]), ok) if !ok return Qt::Size.new end if text =~ /([0-9]+) *x *([0-9]+)/ width = $1.to_i height = $2.to_i if width > 0 && width < 2048 && height > 0 && height < 2048 return Qt::Size.new(width, height) end end return @glWidget.size() end |
#grabFrameBuffer ⇒ Object
92 93 94 95 |
# File 'ext/ruby/qtruby/examples/opengl/grabber/mainwindow.rb', line 92 def grabFrameBuffer() image = @glWidget.grabFrameBuffer() setPixmap(Qt::Pixmap.fromImage(image)) end |
#init ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'ext/ruby/qtruby/examples/mainwindows/sdi/mainwindow.rb', line 119 def init() setAttribute(Qt::WA_DeleteOnClose) @isUntitled = true @textEdit = Qt::TextEdit.new setCentralWidget(@textEdit) createActions() createMenus() createToolBars() createStatusBar() readSettings() connect(@textEdit.document(), SIGNAL('contentsChanged()'), self, SLOT('documentWasModified()')) end |
#insertCalendar ⇒ Object
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 |
# File 'ext/ruby/qtruby/examples/richtext/calendar/mainwindow.rb', line 88 def insertCalendar() @editor.clear cursor = @editor.textCursor date = Qt::Date.new(@selectedDate.year(), @selectedDate.month(), 1) tableFormat = Qt::TextTableFormat.new do |t| t.alignment = Qt::AlignHCenter.to_i t.background = Qt::Brush.new(Qt::Color.new("#e0e0e0")) t.cellPadding = 2 t.cellSpacing = 4 end constraints = [] constraints << Qt::TextLength.new(Qt::TextLength::PercentageLength, 14) << Qt::TextLength.new(Qt::TextLength::PercentageLength, 14) << Qt::TextLength.new(Qt::TextLength::PercentageLength, 14) << Qt::TextLength.new(Qt::TextLength::PercentageLength, 14) << Qt::TextLength.new(Qt::TextLength::PercentageLength, 14) << Qt::TextLength.new(Qt::TextLength::PercentageLength, 14) << Qt::TextLength.new(Qt::TextLength::PercentageLength, 14) tableFormat.columnWidthConstraints = constraints table = cursor.insertTable(1, 7, tableFormat) frame = cursor.currentFrame frameFormat = frame.frameFormat frameFormat.border = 1 frame.frameFormat = frameFormat format = cursor.charFormat() format.fontPointSize = @fontSize boldFormat = Qt::TextCharFormat.new boldFormat.merge(format) boldFormat.fontWeight = Qt::Font::Bold highlightedFormat = Qt::TextCharFormat.new highlightedFormat.merge(boldFormat) highlightedFormat.background = Qt::Brush.new(Qt::yellow) (1..7).each do |weekDay| cell = table.cellAt(0, weekDay-1) cellCursor = cell.firstCursorPosition() cellCursor.insertText("%s" % Qt::Date.longDayName(weekDay), boldFormat) end table.insertRows(table.rows(), 1) while date.month == @selectedDate.month weekDay = date.dayOfWeek cell = table.cellAt(table.rows-1, weekDay-1) cellCursor = cell.firstCursorPosition if date == Qt::Date.currentDate cellCursor.insertText("%s" % date.day(), highlightedFormat) else cellCursor.insertText("%s" % date.day(), format) end date = date.addDays(1) if weekDay == 7 && date.month == @selectedDate.month table.insertRows(table.rows, 1) end end setWindowTitle(tr("Calendar for %s %s" % [Qt::Date.longMonthName(@selectedDate.month), @selectedDate.year])) end |
#insertCharacter(character) ⇒ Object
110 111 112 |
# File 'ext/ruby/qtruby/examples/widgets/charactermap/mainwindow.rb', line 110 def insertCharacter(character) @lineEdit.insert(character) end |
#insertCustomer(customer) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'ext/ruby/qtruby/examples/mainwindows/dockwidgets/mainwindow.rb', line 143 def insertCustomer(customer) if customer.empty? return end @customerList = customer.split(", ") document = @textEdit.document() cursor = document.find("NAME") if !cursor.nil? cursor.beginEditBlock() cursor.insertText(@customerList.at(0)) oldcursor = cursor cursor = document.find("ADDRESS") if !cursor.nil? for i in 1...@customerList.size cursor.insertBlock() cursor.insertText(@customerList.at(i)) end cursor.endEditBlock() else oldcursor.endEditBlock() end end end |
#italic ⇒ Object
129 130 131 |
# File 'ext/ruby/qtruby/examples/mainwindows/menus/mainwindow.rb', line 129 def italic() @infoLabel.text = tr("Invoked <b>Edit|Format|Italic</b>") end |
#justify ⇒ Object
141 142 143 |
# File 'ext/ruby/qtruby/examples/mainwindows/menus/mainwindow.rb', line 141 def justify() @infoLabel.text = tr("Invoked <b>Edit|Format|Justify</b>") end |
#leftAlign ⇒ Object
133 134 135 |
# File 'ext/ruby/qtruby/examples/mainwindows/menus/mainwindow.rb', line 133 def leftAlign() @infoLabel.text = tr("Invoked <b>Edit|Format|Left Align</b>") end |
#loadFile(fileName) ⇒ Object
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'ext/ruby/qtruby/examples/mainwindows/sdi/mainwindow.rb', line 272 def loadFile(fileName) file = Qt::File.new(fileName) if !file.open(Qt::File::ReadOnly | Qt::File::Text) Qt::MessageBox.warning(self, tr("SDI"), tr("Cannot read file %s:\n%s." % [fileName, file.errorString])) return end inf = Qt::TextStream.new(file) Qt::Application.overrideCursor = Qt::Cursor.new(Qt::WaitCursor) @textEdit.plainText = inf.readAll Qt::Application::restoreOverrideCursor setCurrentFile(fileName) statusBar().showMessage(tr("File loaded"), 2000) end |
#markUnmarkFonts(state) ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'ext/ruby/qtruby/examples/painting/fontsampler/mainwindow.rb', line 104 def markUnmarkFonts(state) items = @ui.fontTree.selectedItems() items.each do |item| if item.checkState(0) != state item.setCheckState(0, state) end end end |
#maybeSave ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'ext/ruby/qtruby/examples/mainwindows/sdi/mainwindow.rb', line 255 def maybeSave() if @textEdit.document().isModified() ret = Qt::MessageBox.warning(self, tr("SDI"), tr("The document has been modified.\n" + "Do you want to save your changes?"), Qt::MessageBox::Yes | Qt::MessageBox::Default, Qt::MessageBox::No, Qt::MessageBox::Cancel | Qt::MessageBox::Escape) if ret == Qt::MessageBox::Yes return save() elsif ret == Qt::MessageBox::Cancel return false end end return true end |
#month=(month) ⇒ Object
164 165 166 167 |
# File 'ext/ruby/qtruby/examples/richtext/calendar/mainwindow.rb', line 164 def month=(month) @selectedDate = Qt::Date.new(@selectedDate.year, month + 1, @selectedDate.day) insertCalendar() end |
#newFile ⇒ Object
76 77 78 79 80 |
# File 'ext/ruby/qtruby/examples/mainwindows/mdi/mainwindow.rb', line 76 def newFile() child = createMdiChild() child.newFile() child.show() end |
#newLetter ⇒ Object
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 |
# File 'ext/ruby/qtruby/examples/mainwindows/dockwidgets/mainwindow.rb', line 55 def newLetter() @textEdit.clear() cursor = Qt::TextCursor.new(@textEdit.textCursor()) cursor.movePosition(Qt::TextCursor::Start) topFrame = cursor.currentFrame() topFrameFormat = topFrame.frameFormat() topFrameFormat.padding = 16 topFrame.frameFormat = topFrameFormat textFormat = Qt::TextCharFormat.new boldFormat = Qt::TextCharFormat.new boldFormat.fontWeight = Qt::Font::Bold italicFormat = Qt::TextCharFormat.new italicFormat.fontItalic = true tableFormat = Qt::TextTableFormat.new tableFormat.border = 1 tableFormat.cellPadding = 16 tableFormat.alignment = Qt::AlignRight cursor.insertTable(1, 1, tableFormat) cursor.insertText("The Firm", boldFormat) cursor.insertBlock() cursor.insertText("321 City Street", textFormat) cursor.insertBlock() cursor.insertText("Industry Park") cursor.insertBlock() cursor.insertText("Some Country") cursor.position = topFrame.lastPosition() cursor.insertText(Qt::Date::currentDate().toString("d MMMM yyyy"), textFormat) cursor.insertBlock() cursor.insertBlock() cursor.insertText("Dear ", textFormat) cursor.insertText("NAME", italicFormat) cursor.insertText(",", textFormat) for i in 0...3 cursor.insertBlock() end cursor.insertText(tr("Yours sincerely,"), textFormat) for i in 0...3 cursor.insertBlock() end cursor.insertText("The Boss", textFormat) cursor.insertBlock() cursor.insertText("ADDRESS", italicFormat) end |
#on_clearAction_triggered ⇒ Object
88 89 90 91 92 93 94 |
# File 'ext/ruby/qtruby/examples/painting/fontsampler/mainwindow.rb', line 88 def on_clearAction_triggered() currentItem = @ui.fontTree.currentItem() @ui.fontTree.selectedItems.each do |item| fontTree.setItemSelected(item, false) end @ui.fontTree.setItemSelected(currentItem, true) end |
#on_markAction_triggered ⇒ Object
96 97 98 |
# File 'ext/ruby/qtruby/examples/painting/fontsampler/mainwindow.rb', line 96 def on_markAction_triggered() markUnmarkFonts(Qt::Checked) end |
#on_printAction_triggered ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'ext/ruby/qtruby/examples/painting/fontsampler/mainwindow.rb', line 213 def on_printAction_triggered() @pageMap = currentPageMap() if @pageMap.length == 0 return end printer = Qt::Printer.new(Qt::Printer::HighResolution) if !setupPrinter(printer) return end from = printer.fromPage() to = printer.toPage() if from <= 0 && to <= 0 from = 1 to = @pageMap.keys().length end progress = Qt::ProgressDialog.new(tr("Printing font samples..."), tr("&Cancel"), 0, @pageMap.length, self) progress.windowModality = Qt::ApplicationModal progress.windowTitle = tr("Printing") progress.minimum = from - 1 progress.maximum = to painter = Qt::Painter.new painter.begin(printer) firstPage = true for index in -1..to if !firstPage printer.newPage() end $qApp.processEvents() if progress.wasCanceled() break end printPage(index, painter, printer) progress.value = index + 1 firstPage = false end painter.end end |
#on_printPreviewAction_triggered ⇒ Object
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'ext/ruby/qtruby/examples/painting/fontsampler/mainwindow.rb', line 261 def on_printPreviewAction_triggered() @pageMap = currentPageMap() if @pageMap.length == 0 return end printer = Qt::Printer.new preview = PreviewDialog.new(printer, self) connect(preview, SIGNAL('pageRequested(int, QPainter &, QPrinter &)'), self, SLOT('printPage(int, QPainter &, QPrinter &)'), Qt::DirectConnection) preview.numberOfPages = @pageMap.length preview.exec() end |
#on_unmarkAction_triggered ⇒ Object
100 101 102 |
# File 'ext/ruby/qtruby/examples/painting/fontsampler/mainwindow.rb', line 100 def on_unmarkAction_triggered() markUnmarkFonts(Qt::Unchecked) end |
#open ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'ext/ruby/qtruby/examples/mainwindows/mdi/mainwindow.rb', line 82 def open() fileName = Qt::FileDialog.getOpenFileName(self) if !fileName.nil? existing = findMdiChild(fileName) if !existing.nil? @mdiArea.activeSubWindow = existing return end child = createMdiChild() if child.loadFile(fileName) statusBar().showMessage(tr("File loaded"), 2000) child.show() else child.close() end end end |
#openDialog ⇒ Object
173 174 175 176 177 178 179 180 |
# File 'ext/ruby/qtruby/examples/richtext/orderform/mainwindow.rb', line 173 def openDialog() dialog = DetailsDialog.new(tr("Enter Customer Details"), self) if dialog.exec == Qt::Dialog::Accepted createLetter(dialog.senderName, dialog.senderAddress, dialog.orderItems, dialog.sendOffers) end end |
#openFile(path = nil) ⇒ Object
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 |
# File 'ext/ruby/qtruby/examples/itemviews/chart/mainwindow.rb', line 84 def openFile(path = nil) if path.nil? fileName = Qt::FileDialog.getOpenFileName(self, tr("Choose a data file"), "", "*.cht") else fileName = path end if !fileName.nil? file = Qt::File.new(fileName) if file.open(Qt::File::ReadOnly | Qt::File::Text) stream = Qt::TextStream.new(file) @model.removeRows(0, @model.rowCount(Qt::ModelIndex.new), Qt::ModelIndex.new) row = 0 line = stream.readLine() while !line.nil? @model.insertRows(row, 1, Qt::ModelIndex.new()) pieces = line.split(",") @model.setData(@model.index(row, 0, Qt::ModelIndex.new), Qt::Variant.new(pieces[0])) @model.setData(@model.index(row, 1, Qt::ModelIndex.new), Qt::Variant.new(pieces[1])) @model.setData(@model.index(row, 0, Qt::ModelIndex.new), qVariantFromValue(Qt::Color.new(pieces[2])), Qt::DecorationRole) row += 1 line = stream.readLine() end file.close() statusBar().showMessage(tr("Loaded %s" % fileName), 2000) end end end |
#openImage(fileName) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'ext/ruby/qtruby/examples/itemviews/puzzle/mainwindow.rb', line 45 def openImage(path = "") fileName = path if fileName.empty? fileName = Qt::FileDialog.getOpenFileName(self, tr("Open Image"), "", "Image Files (*.png *.jpg *.bmp)") end if !fileName.nil? newImage = Qt::Pixmap.new if !newImage.load(fileName) Qt::MessageBox.warning(self, tr("Open Image"), tr("The image file could not be loaded."), Qt::MessageBox::Cancel, Qt::MessageBox::NoButton) return end @puzzleImage = newImage setupPuzzle() end end |
#openRecentFile ⇒ Object
96 97 98 99 100 101 |
# File 'ext/ruby/qtruby/examples/mainwindows/recentfiles/mainwindow.rb', line 96 def openRecentFile() action = sender() if !action.nil? loadFile(action.data().toString()) end end |
#paste ⇒ Object
125 126 127 128 129 |
# File 'ext/ruby/qtruby/examples/mainwindows/mdi/mainwindow.rb', line 125 def paste() if activeMdiChild() activeMdiChild().paste() end end |
#penColor ⇒ Object
73 74 75 76 77 78 |
# File 'ext/ruby/qtruby/examples/widgets/scribble/mainwindow.rb', line 73 def penColor() newColor = Qt::ColorDialog.getColor(Qt::Color.new(@scribbleArea.penColor)) if newColor.isValid() @scribbleArea.penColor = newColor end end |
#penWidth ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'ext/ruby/qtruby/examples/widgets/scribble/mainwindow.rb', line 80 def penWidth() ok = Qt::Boolean.new newWidth = Qt::InputDialog::getInteger(self, tr("Scribble"), tr("Select pen width:"), @scribbleArea.penWidth(), 1, 50, 1, ok) if ok @scribbleArea.penWidth = newWidth end end |
#print ⇒ Object
101 102 103 |
# File 'ext/ruby/qtruby/examples/mainwindows/menus/mainwindow.rb', line 101 def print() @infoLabel.text = tr("Invoked <b>File|Print</b>") end |
#printFile ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'ext/ruby/qtruby/examples/richtext/orderform/mainwindow.rb', line 182 def printFile() editor = @letters.currentWidget document = editor.document printer = Qt::Printer.new dialog = Qt::PrintDialog.new(printer, self) if dialog.exec != Qt::Dialog::Accepted return end document.print(printer) end |
#printImage ⇒ Object
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 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 |
# File 'ext/ruby/qtruby/examples/itemviews/pixelator/mainwindow.rb', line 130 def printImage() if @model.rowCount(Qt::ModelIndex.new()).model.columnCount(Qt::ModelIndex.new()) > 90000 answer = Qt::MessageBox::question(self, tr("Large Image Size"), tr("The printed image may be very large. Are you sure that " \ "you want to print it?"), Qt::MessageBox::Yes, Qt::MessageBox::No) if answer == Qt::MessageBox::No return end end printer = Qt::Printer.new(Qt::Printer::HighResolution) dlg = Qt::PrintDialog.new(printer, self) dlg.windowTitle = tr("Print Image") if dlg.exec != Qt::Dialog::Accepted return end painter = Qt::Painter.new painter.begin(printer) rows = @model.rowCount(Qt::ModelIndex.new) columns = @model.columnCount(Qt::ModelIndex.new) sourceWidth = (columns+1) * PixelDelegate::ItemSize sourceHeight = (rows+1) * PixelDelegate::ItemSize painter.save xscale = printer.pageRect.width/sourceWidth.to_f yscale = printer.pageRect.height/sourceHeight.to_f scale = [xscale, yscale].min painter.translate(printer.paperRect.x + printer.pageRect.width/2, printer.paperRect.y + printer.pageRect.height/2) painter.scale(scale, scale) painter.translate(-sourceWidth/2, -sourceHeight/2) option = Qt::StyleOptionViewItem.new parent = Qt::ModelIndex.new progress = Qt::ProgressDialog.new(tr("Printing..."), tr("Cancel"), 0, rows, self) y = PixelDelegate::ItemSize/2 for row in 0...rows do progress.value = row $qApp.processEvents if progress.wasCanceled break end x = PixelDelegate::ItemSize/2 for column in 0...columns do option.rect = Qt::Rect.new(x.to_i, y.to_i, PixelDelegate::ItemSize, PixelDelegate::ItemSize) @view.itemDelegate().paint(painter, option, @model.index(row, column, parent)) x += PixelDelegate::ItemSize end y += PixelDelegate::ItemSize end progress.value = rows painter.restore painter.end if progress.wasCanceled() Qt::MessageBox.information(self, tr("Printing canceled"), tr("The printing process was canceled."), Qt::MessageBox::Cancel) end end |
#printPage(index, painter, printer) ⇒ Object
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'ext/ruby/qtruby/examples/painting/fontsampler/mainwindow.rb', line 306 def printPage(index, painter, printer) family = pageMap.keys()[index] items = pageMap[family] # Find the dimensions of the text on each page. width = 0.0 height = 0.0 items.each do |item| style = item.text(0) weight = item.data(0, Qt::UserRole).to_i italic = item.data(0, Qt::UserRole + 1).toBool() # Calculate the maximum width and total height of the text. @sampleSizes.each do |size| font = Qt::Font.new(family, size, weight, italic) font = Qt::Font.new(font, painter.device()) fontMetrics = Qt::FontMetricsF.new(font) rect = fontMetrics.boundingRect( "%s %s" % [family, style]) width = [rect.width(), width].max height += rect.height() end end xScale = printer.pageRect().width() / width yScale = printer.pageRect().height() / height scale = [xScale, yScale].min remainingHeight = printer.pageRect().height()/scale - height spaceHeight = (remainingHeight/4.0) / (items.length + 1) interLineHeight = (remainingHeight/4.0) / (@sampleSizes.length * items.count()) painter.save() painter.translate(printer.pageRect().width()/2.0, printer.pageRect().height()/2.0) painter.scale(scale, scale) painter.brush = Qt::Brush.new(Qt::black) x = -width/2.0 y = -height/2.0 - remainingHeight/4.0 + spaceHeight items.each do |item| style = item.text(0) weight = item.data(0, Qt::UserRole).to_i italic = item.data(0, Qt::UserRole + 1).toBool() # Draw each line of text @sampleSizes.each do |size| font = Qt::Font.new(family, size, weight, italic) font = Qt::Font.new(font, painter.device()) fontMetrics = Qt::FontMetricsF.new(font) rect = fontMetrics.boundingRect("%s %s" % [font.family(), style]) y += rect.height() painter.font = font painter.drawText(Qt::PointF.neew(x, y), "%s %s" % [family, style]) y += interLineHeight end y += spaceHeight end painter.restore() end |
#readSettings ⇒ Object
330 331 332 333 334 335 336 |
# File 'ext/ruby/qtruby/examples/mainwindows/mdi/mainwindow.rb', line 330 def readSettings() settings = Qt::Settings.new("Trolltech", "MDI Example") pos = settings.value("pos", Qt::Variant.new(Qt::Point.new(200, 200))).toPoint() size = settings.value("size", Qt::Variant.new(Qt::Size.new(400, 400))).toSize() move(pos) resize(size) end |
#redo ⇒ Object
109 110 111 |
# File 'ext/ruby/qtruby/examples/mainwindows/menus/mainwindow.rb', line 109 def redo() @infoLabel.text = tr("Invoked <b>Edit|Redo</b>") end |
#removeAllImages ⇒ Object
194 195 196 197 |
# File 'ext/ruby/qtruby/examples/widgets/icons/mainwindow.rb', line 194 def removeAllImages() @imagesTable.rowCount = 0 changeIcon() end |
#renderer=(action) ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'ext/ruby/qtruby/examples/painting/svgviewer/mainwindow.rb', line 90 def renderer=(action) if action.objectName == "nativeAction" @area.renderer = SvgWindow::Native elsif action.objectName == "glAction" @area.renderer = SvgWindow::OpenGL elsif action.objectName == "imageAction" @area.renderer = SvgWindow::Image end end |
#renderIntoPixmap ⇒ Object
84 85 86 87 88 89 90 |
# File 'ext/ruby/qtruby/examples/opengl/grabber/mainwindow.rb', line 84 def renderIntoPixmap() size = getSize() if size.valid? pixmap = @glWidget.renderPixmap(size.width(), size.height()) setPixmap(pixmap) end end |
#rightAlign ⇒ Object
137 138 139 |
# File 'ext/ruby/qtruby/examples/mainwindows/menus/mainwindow.rb', line 137 def rightAlign() @infoLabel.text = tr("Invoked <b>Edit|Format|Right Align</b>") end |
#save ⇒ Object
101 102 103 104 105 |
# File 'ext/ruby/qtruby/examples/mainwindows/mdi/mainwindow.rb', line 101 def save() if activeMdiChild() && activeMdiChild().save() statusBar().showMessage(tr("File saved"), 2000) end end |
#saveAs ⇒ Object
107 108 109 110 111 |
# File 'ext/ruby/qtruby/examples/mainwindows/mdi/mainwindow.rb', line 107 def saveAs() if activeMdiChild() && activeMdiChild().saveAs() statusBar().showMessage(tr("File saved"), 2000) end end |
#saveFile(fileName) ⇒ Object
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 |
# File 'ext/ruby/qtruby/examples/itemviews/chart/mainwindow.rb', line 124 def saveFile() fileName = Qt::FileDialog.getSaveFileName(self, tr("Save file as"), "", "*.cht") if !fileName.nil? file = Qt::File.new(fileName) stream = Qt::TextStream.new(file) if file.open(Qt::File::WriteOnly | Qt::File::Text) (0...@model.rowCount(Qt::ModelIndex.new)).each do |row| pieces = [] pieces.push(@model.data(@model.index(row, 0, Qt::ModelIndex.new), Qt::DisplayRole).toString) pieces.push(@model.data(@model.index(row, 1, Qt::ModelIndex.new), Qt::DisplayRole).toString) pieces.push(@model.data(@model.index(row, 0, Qt::ModelIndex.new), Qt::DecorationRole).toString) stream << pieces.join(",") << "\n" end end file.close() statusBar().showMessage(tr("Saved %s" % fileName), 2000) end end |
#setCompleted ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'ext/ruby/qtruby/examples/itemviews/puzzle/mainwindow.rb', line 66 def setCompleted() Qt::MessageBox.information(self, tr("Puzzle Completed"), tr("Congratulations! You have completed the puzzle!\n" + "Click OK to start again."), Qt::MessageBox::Ok) setupPuzzle() end |
#setCurrentFile(fileName) ⇒ Object
307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'ext/ruby/qtruby/examples/mainwindows/sdi/mainwindow.rb', line 307 def setCurrentFile(fileName) @isUntitled = fileName.empty? if @isUntitled @curFile = tr("document%d.txt" % (@@sequenceNumber += 1)) else @curFile = Qt::FileInfo.new(fileName).canonicalFilePath() end @textEdit.document().modified = false setWindowModified(false) setWindowTitle(tr("%s[*] - %s" % [strippedName(@curFile), tr("SDI")])) end |
#setLineSpacing ⇒ Object
149 150 151 |
# File 'ext/ruby/qtruby/examples/mainwindows/menus/mainwindow.rb', line 149 def setLineSpacing() @infoLabel.text = tr("Invoked <b>Edit|Format|Set Line Spacing</b>") end |
#setParagraphSpacing ⇒ Object
153 154 155 |
# File 'ext/ruby/qtruby/examples/mainwindows/menus/mainwindow.rb', line 153 def setParagraphSpacing() @infoLabel.text = tr("Invoked <b>Edit|Format|Set Paragraph Spacing</b>") end |
#setPixmap(pixmap) ⇒ Object
159 160 161 162 163 164 165 166 |
# File 'ext/ruby/qtruby/examples/opengl/grabber/mainwindow.rb', line 159 def setPixmap(pixmap) @pixmapLabel.pixmap = pixmap size = pixmap.size() if size - Qt::Size.new(1, 0) == @pixmapLabelArea.maximumViewportSize size -= Qt::Size.new(1, 0) end @pixmapLabel.resize(size) end |
#setupEditor ⇒ Object
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 |
# File 'ext/ruby/qtruby/examples/richtext/syntaxhighlighter/mainwindow.rb', line 64 def setupEditor() variableFormat = Qt::TextCharFormat.new variableFormat.fontWeight = Qt::Font::Bold variableFormat.foreground = Qt::Brush.new(Qt::blue) @highlighter.addMapping('\b[A-Z_]+\b', variableFormat) singleLineCommentFormat = Qt::TextCharFormat.new singleLineCommentFormat.background = Qt::Brush.new(Qt::Color.new("#77ff77")) @highlighter.addMapping('#[^\n]*', singleLineCommentFormat) quotationFormat = Qt::TextCharFormat.new quotationFormat.background = Qt::Brush.new(Qt::cyan) quotationFormat.foreground = Qt::Brush.new(Qt::blue) @highlighter.addMapping('\".*\"', quotationFormat) functionFormat = Qt::TextCharFormat.new functionFormat.fontItalic = true functionFormat.foreground = Qt::Brush.new(Qt::blue) @highlighter.addMapping('\b[a-z0-9_]+\(.*\)', functionFormat) font = Qt::Font.new font.family = "Courier" font.fixedPitch = true font.pointSize = 10 @editor = Qt::TextEdit.new @editor.font = font @highlighter.addToDocument(@editor.document()) end |
#setupFileMenu ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'ext/ruby/qtruby/examples/richtext/syntaxhighlighter/mainwindow.rb', line 94 def setupFileMenu() fileMenu = Qt::Menu.new(tr("&File"), self) ().addMenu(fileMenu) fileMenu.addAction(tr("&New..."), self, SLOT('newFile()'), Qt::KeySequence.new(tr("Ctrl+N", "File|New"))) fileMenu.addAction(tr("&Open..."), self, SLOT('openFile()'), Qt::KeySequence.new(tr("Ctrl+O", "File|Open"))) fileMenu.addAction(tr("E&xit"), $qApp, SLOT('quit()'), Qt::KeySequence.new(tr("Ctrl+Q", "File|Exit"))) end |
#setupFontTree ⇒ Object
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 |
# File 'ext/ruby/qtruby/examples/painting/fontsampler/mainwindow.rb', line 61 def setupFontTree() database = Qt::FontDatabase.new @ui.fontTree.columnCount = 1 @ui.fontTree.headerLabels = [tr("Font")] database.families.each do |family| styles = database.styles(family) if styles.empty? continue end familyItem = Qt::TreeWidgetItem.new(@ui.fontTree) familyItem.setText(0, family) familyItem.setCheckState(0, Qt::Unchecked) styles.each do |style| styleItem = Qt::TreeWidgetItem.new(familyItem) styleItem.setText(0, style) styleItem.setCheckState(0, Qt::Unchecked) styleItem.setData(0, Qt::UserRole, Qt::Variant.new(database.weight(family, style))) styleItem.setData(0, Qt::UserRole + 1, Qt::Variant.new(database.italic(family, style))) end end end |
#setupMenus ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'ext/ruby/qtruby/examples/itemviews/puzzle/mainwindow.rb', line 99 def setupMenus() fileMenu = ().addMenu(tr("&File")) openAction = fileMenu.addAction(tr("&Open...")) openAction.shortcut = Qt::KeySequence.new(tr("Ctrl+O")) exitAction = fileMenu.addAction(tr("E&xit")) exitAction.shortcut = Qt::KeySequence.new(tr("Ctrl+Q")) gameMenu = ().addMenu(tr("&Game")) restartAction = gameMenu.addAction(tr("&Restart")) connect(openAction, SIGNAL('triggered()'), self, SLOT('openImage()')) connect(exitAction, SIGNAL('triggered()'), $qApp, SLOT('quit()')) connect(restartAction, SIGNAL('triggered()'), self, SLOT('setupPuzzle()')) end |
#setupModel ⇒ Object
59 60 61 62 63 |
# File 'ext/ruby/qtruby/examples/itemviews/chart/mainwindow.rb', line 59 def setupModel() @model = Qt::StandardItemModel.new(8, 2, self) @model.setHeaderData(0, Qt::Horizontal, Qt::Variant.new(tr("Label"))) @model.setHeaderData(1, Qt::Horizontal, Qt::Variant.new(tr("Quantity"))) end |
#setupPrinter(printer) ⇒ Object
301 302 303 304 |
# File 'ext/ruby/qtruby/examples/painting/fontsampler/mainwindow.rb', line 301 def setupPrinter(printer) dialog = Qt::PrintDialog.new(printer, self) return dialog.exec() == Qt::Dialog::Accepted end |
#setupPuzzle ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'ext/ruby/qtruby/examples/itemviews/puzzle/mainwindow.rb', line 75 def setupPuzzle() size = [@puzzleImage.width(), @puzzleImage.height()].min @puzzleImage = @puzzleImage.copy((@puzzleImage.width() - size)/2, (@puzzleImage.height() - size)/2, size, size).scaled(400, 400, Qt::IgnoreAspectRatio, Qt::SmoothTransformation) oldModel = @piecesList.model newModel = PiecesModel.new(self) @piecesList.model = newModel oldModel.dispose # srand(QCursor::pos().x() ^ QCursor::pos().y()); Kernel.srand for y in 0...5 for x in 0...5 pieceImage = @puzzleImage.copy(x*80, y*80, 80, 80) newModel.addPiece(pieceImage, Qt::Point.new(x, y)) end end @puzzleWidget.clear() end |
#setupViews ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'ext/ruby/qtruby/examples/itemviews/chart/mainwindow.rb', line 65 def setupViews() splitter = Qt::Splitter.new table = Qt::TableView.new @pieChart = PieView.new splitter.addWidget(table) splitter.addWidget(@pieChart) splitter.setStretchFactor(0, 0) splitter.setStretchFactor(1, 1) table.model = @model @pieChart.model = @model @selectionModel = Qt::ItemSelectionModel.new(@model) table.selectionModel = @selectionModel @pieChart.selectionModel = @selectionModel setCentralWidget(splitter) end |
#setupWidgets ⇒ Object
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 |
# File 'ext/ruby/qtruby/examples/itemviews/puzzle/mainwindow.rb', line 117 def setupWidgets() frame = Qt::Frame.new frameLayout = Qt::HBoxLayout.new(frame) @piecesList = Qt::ListView.new @piecesList.dragEnabled = true @piecesList.viewMode = Qt::ListView::IconMode @piecesList.iconSize = Qt::Size.new(60, 60) @piecesList.gridSize = Qt::Size.new(80, 80) @piecesList.spacing = 10 @piecesList.movement = Qt::ListView::Snap @piecesList.acceptDrops = true @piecesList.dropIndicatorShown = true model = PiecesModel.new(self) @piecesList.model = model @puzzleWidget = PuzzleWidget.new connect(@puzzleWidget, SIGNAL('puzzleCompleted()'), self, SLOT('setCompleted()'), Qt::QueuedConnection) frameLayout.addWidget(@piecesList) frameLayout.addWidget(@puzzleWidget) setCentralWidget(frame) end |
#showAboutBox ⇒ Object
203 204 205 206 207 208 |
# File 'ext/ruby/qtruby/examples/itemviews/pixelator/mainwindow.rb', line 203 def showAboutBox() Qt::MessageBox.about(self, tr("About the Pixelator example"), tr("This example demonstrates how a standard view and a custom\n" \ "delegate can be used to produce a specialized representation\n " \ "of data in a simple custom model.")) end |
#showFont(item) ⇒ Object
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 |
# File 'ext/ruby/qtruby/examples/painting/fontsampler/mainwindow.rb', line 113 def showFont(item) if item.nil? return end if !item.parent.nil? family = item.parent().text(0) style = item.text(0) weight = item.data(0, Qt::UserRole).to_i italic = item.data(0, Qt::UserRole + 1).toBool() else family = item.text(0) style = item.child(0).text(0) weight = item.child(0).data(0, Qt::UserRole).to_i italic = item.child(0).data(0, Qt::UserRole + 1).toBool() end oldText = @ui.textEdit.toPlainText.lstrip.rstrip modified = @ui.textEdit.document.modified? @ui.textEdit.clear @ui.textEdit.document.setDefaultFont(Qt::Font.new(family, 32, weight, italic)) cursor = @ui.textEdit.textCursor() blockFormat = Qt::TextBlockFormat.new blockFormat.alignment = Qt::AlignCenter cursor.insertBlock(blockFormat) if modified cursor.insertText(oldText) else cursor.insertText("%s %s" % [family, style]) end @ui.textEdit.document().modified = modified end |
#strippedName(fullFileName) ⇒ Object
321 322 323 |
# File 'ext/ruby/qtruby/examples/mainwindows/sdi/mainwindow.rb', line 321 def strippedName(fullFileName) return Qt::FileInfo.new(fullFileName).fileName() end |
#undo ⇒ Object
105 106 107 |
# File 'ext/ruby/qtruby/examples/mainwindows/menus/mainwindow.rb', line 105 def undo() @infoLabel.text = tr("Invoked <b>Edit|Undo</b>") end |
#updateClipboard ⇒ Object
114 115 116 117 |
# File 'ext/ruby/qtruby/examples/widgets/charactermap/mainwindow.rb', line 114 def updateClipboard() @clipboard.setText(@lineEdit.text, Qt::Clipboard::Clipboard) @clipboard.setText(@lineEdit.text, Qt::Clipboard::Selection) end |
#updateMenus ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'ext/ruby/qtruby/examples/mainwindows/mdi/mainwindow.rb', line 137 def updateMenus() hasMdiChild = (activeMdiChild() != nil) @saveAct.enabled = hasMdiChild @saveAsAct.enabled = hasMdiChild @pasteAct.enabled = hasMdiChild @closeAct.enabled = hasMdiChild @closeAllAct.enabled = hasMdiChild @tileAct.enabled = hasMdiChild @cascadeAct.enabled = hasMdiChild @nextAct.enabled = hasMdiChild @previousAct.enabled = hasMdiChild @separatorAct.visible = hasMdiChild hasSelection = (activeMdiChild() && activeMdiChild().textCursor().hasSelection()) @cutAct.enabled = hasSelection @copyAct.enabled = hasSelection end |
#updateRecentFileActions ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'ext/ruby/qtruby/examples/mainwindows/recentfiles/mainwindow.rb', line 236 def updateRecentFileActions() settings = Qt::Settings.new("Trolltech", "Recent Files Example") files = settings.value("recentFileList").toStringList() numRecentFiles = [files.length, MaxRecentFiles].min (0...numRecentFiles).each do |i| text = tr("&%s %s" % [i + 1, strippedName(files[i])]) @recentFileActs[i].text = text @recentFileActs[i].data = Qt::Variant.new(files[i]) @recentFileActs[i].visible = true end (numRecentFiles...MaxRecentFiles).each do |j| @recentFileActs[j].visible = false end @separatorAct.visible = numRecentFiles > 0 end |
#updateStyles(item, column) ⇒ Object
149 150 151 152 153 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 207 208 209 210 211 |
# File 'ext/ruby/qtruby/examples/painting/fontsampler/mainwindow.rb', line 149 def updateStyles(item, column) if item.nil? || column != 0 return end state = item.checkState(0) parent = item.parent if !parent.nil? # Only count style items. if state == Qt::Checked @markedCount += 1 else @markedCount -= 1 end if state == Qt::Checked && parent.checkState(0) == Qt::Unchecked # Mark parent items when child items are checked. parent.setCheckState(0, Qt::Checked) elsif state == Qt::Unchecked && parent.checkState(0) == Qt::Checked marked = false for row in 0..parent.childCount if parent.child(row).checkState(0) == Qt::Checked marked = true break end end # Unmark parent items when all child items are unchecked. if !marked parent.setCheckState(0, Qt::Unchecked) end end else row number = 0 for row in 0..item.childCount if item.child(row).checkState(0) == Qt::Checked number += 1 end end # Mark/unmark all child items when marking/unmarking top-level # items. if state == Qt::Checked && number == 0 for row in 0..item.childCount if item.child(row).checkState(0) == Qt::Unchecked item.child(row).setCheckState(0, Qt::Checked) end end elsif state == Qt::Unchecked && number > 0 for row in 0..item.childCount if item.child(row).checkState(0) == Qt::Checked item.child(row).setCheckState(0, Qt::Unchecked) end end end end @ui.printAction.enabled = @markedCount > 0 @ui.printPreviewAction.enabled = @markedCount > 0 end |
#updateView ⇒ Object
210 211 212 213 214 215 216 217 |
# File 'ext/ruby/qtruby/examples/itemviews/pixelator/mainwindow.rb', line 210 def updateView for row in 0...@model.rowCount(Qt::ModelIndex.new) do @view.resizeRowToContents(row) end for column in 0...@model.columnCount(Qt::ModelIndex.new) do @view.resizeColumnToContents(column) end end |
#updateWindowMenu ⇒ Object
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 |
# File 'ext/ruby/qtruby/examples/mainwindows/mdi/mainwindow.rb', line 156 def updateWindowMenu() @windowMenu.clear() @windowMenu.addAction(@closeAct) @windowMenu.addAction(@closeAllAct) @windowMenu.addSeparator() @windowMenu.addAction(@tileAct) @windowMenu.addAction(@cascadeAct) @windowMenu.addSeparator() @windowMenu.addAction(@nextAct) @windowMenu.addAction(@previousAct) @windowMenu.addAction(@separatorAct) windows = @mdiArea.subWindowList() @separatorAct.visible = !windows.empty? for i in 0...windows.size child = windows[i]. if i < 9 text = tr("&%s %s" % [i + 1, child.userFriendlyCurrentFile()]) else text = tr("%s %s" % [i + 1, child.userFriendlyCurrentFile()]) end action = @windowMenu.addAction(text) action.checkable = true action .checked = child == activeMdiChild() connect(action, SIGNAL('triggered()'), @windowMapper, SLOT('map()')) @windowMapper.setMapping(action, child) end end |