class MainWindow
Constants
- MaxRecentFiles
- RAND_MAX
Attributes
curFile[R]
Public Class Methods
new(parent = nil)
click to toggle source
Calls superclass method
# File examples/draganddrop/puzzle/mainwindow.rb, line 37 def initialize(parent = nil) super(parent) setupMenus() setupWidgets() setSizePolicy(Qt::SizePolicy.new(Qt::SizePolicy::Fixed, Qt::SizePolicy::Fixed)) setWindowTitle(tr("Puzzle")) @puzzleImage = Qt::Pixmap.new end
Public Instance Methods
about()
click to toggle source
# File examples/mainwindows/application/mainwindow.rb, line 94 def about() Qt::MessageBox.about(self, tr("About Application"), tr("The <b>Application</b> example demonstrates how to " + "write modern GUI applications using Qt, with a menu bar, " + "toolbars, and a status bar.")) end
aboutQt()
click to toggle source
# File examples/mainwindows/menus/mainwindow.rb, line 164 def aboutQt() @infoLabel.text = tr("Invoked <b>Help|About Qt</b>") end
activeMdiChild()
click to toggle source
# File examples/mainwindows/mdi/mainwindow.rb, line 344 def activeMdiChild() if @mdiArea.activeSubWindow return @mdiArea.activeSubWindow.widget else return nil end end
addImage()
click to toggle source
# File 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)
click to toggle source
# File 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()
click to toggle source
# File examples/mainwindows/menus/mainwindow.rb, line 125 def bold() @infoLabel.text = tr("Invoked <b>Edit|Format|Bold</b>") end
center()
click to toggle source
# File examples/mainwindows/menus/mainwindow.rb, line 145 def center() @infoLabel.text = tr("Invoked <b>Edit|Format|Center</b>") end
changeIcon()
click to toggle source
# File 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()
click to toggle source
# File 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)
click to toggle source
# File 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()
click to toggle source
# File 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.metaObject().className() == Qt::Application.style().metaObject().className() action.trigger() return end end end
chooseImage()
click to toggle source
# File 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()
click to toggle source
# File examples/opengl/grabber/mainwindow.rb, line 97 def clearPixmap() setPixmap(Qt::Pixmap.new) end
closeEvent(event)
click to toggle source
# File examples/mainwindows/application/mainwindow.rb, line 52 def closeEvent(event) if maybeSave() writeSettings() event.accept() else event.ignore() end end
contextMenuEvent(event)
click to toggle source
# File examples/mainwindows/menus/mainwindow.rb, line 81 def contextMenuEvent(event) menu = Qt::Menu.new(self) menu.addAction(@cutAct) menu.addAction(@copyAct) menu.addAction(@pasteAct) menu.exec(event.globalPos()) end
copy()
click to toggle source
# File examples/mainwindows/mdi/mainwindow.rb, line 119 def copy() if activeMdiChild() activeMdiChild().copy() end end
createActions()
click to toggle source
# File examples/mainwindows/application/mainwindow.rb, line 105 def createActions() @newAct = Qt::Action.new(Qt::Icon.new("images/new.png"), tr("&New"), self) @newAct.shortcut = Qt::KeySequence.new( tr("Ctrl+N") ) @newAct.statusTip = tr("Create a file.new") connect(@newAct, SIGNAL('triggered()'), self, SLOT('newFile()')) @openAct = Qt::Action.new(Qt::Icon.new("images/open.png"), tr("&Open..."), self) @openAct.shortcut = Qt::KeySequence.new( tr("Ctrl+O") ) @openAct.statusTip = tr("Open an existing file") connect(@openAct, SIGNAL('triggered()'), self, SLOT('open()')) @saveAct = Qt::Action.new(Qt::Icon.new("images/save.png"), tr("&Save"), self) @saveAct.shortcut = Qt::KeySequence.new( tr("Ctrl+S") ) @saveAct.statusTip = tr("Save the document to disk") connect(@saveAct, SIGNAL('triggered()'), self, SLOT('save()')) @saveAsAct = Qt::Action.new(tr("Save &As..."), self) @saveAsAct.statusTip = tr("Save the document under a name.new") connect(@saveAsAct, SIGNAL('triggered()'), self, SLOT('saveAs()')) @exitAct = Qt::Action.new(tr("E&xit"), self) @exitAct.shortcut = Qt::KeySequence.new( tr("Ctrl+Q") ) @exitAct.statusTip = tr("Exit the application") connect(@exitAct, SIGNAL('triggered()'), self, SLOT('close()')) @cutAct = Qt::Action.new(Qt::Icon.new("images/cut.png"), tr("Cu&t"), self) @cutAct.shortcut = Qt::KeySequence.new( tr("Ctrl+X") ) @cutAct.setStatusTip(tr("Cut the current selection's contents to the " + "clipboard")) connect(@cutAct, SIGNAL('triggered()'), @textEdit, SLOT('cut()')) @copyAct = Qt::Action.new(Qt::Icon.new("images/copy.png"), tr("&Copy"), self) @copyAct.shortcut = Qt::KeySequence.new( tr("Ctrl+C") ) @copyAct.setStatusTip(tr("Copy the current selection's contents to the " + "clipboard")) connect(@copyAct, SIGNAL('triggered()'), @textEdit, SLOT('copy()')) @pasteAct = Qt::Action.new(Qt::Icon.new("images/paste.png"), tr("&Paste"), self) @pasteAct.shortcut = Qt::KeySequence.new( tr("Ctrl+V") ) @pasteAct.setStatusTip(tr("Paste the clipboard's contents into the current " + "selection")) connect(@pasteAct, SIGNAL('triggered()'), @textEdit, SLOT('paste()')) @aboutAct = Qt::Action.new(tr("&About"), self) @aboutAct.statusTip = tr("Show the application's About box") connect(@aboutAct, SIGNAL('triggered()'), self, SLOT('about()')) @aboutQtAct = Qt::Action.new(tr("About &Qt"), self) @aboutQtAct.statusTip = tr("Show the Qt library's About box") connect(@aboutQtAct, SIGNAL('triggered()'), $qApp, SLOT('aboutQt()')) @cutAct.enabled = false @copyAct.enabled = false connect(@textEdit, SIGNAL('copyAvailable(bool)'), @cutAct, SLOT('setEnabled(bool)')) connect(@textEdit, SIGNAL('copyAvailable(bool)'), @copyAct, SLOT('setEnabled(bool)')) end
createContextMenu()
click to toggle source
# File examples/widgets/icons/mainwindow.rb, line 333 def createContextMenu() @imagesTable.contextMenuPolicy = Qt::ActionsContextMenu @imagesTable.addAction(@addImageAct) @imagesTable.addAction(@removeAllImagesAct) end
createDockWindows()
click to toggle source
# File 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.widget = @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.widget = @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()
click to toggle source
# File 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()
click to toggle source
# File 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)
click to toggle source
# File 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()
click to toggle source
# File 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()
click to toggle source
# File examples/mainwindows/application/mainwindow.rb, line 164 def createMenus() @fileMenu = menuBar().addMenu(tr("&File")) @fileMenu.addAction(@newAct) @fileMenu.addAction(@openAct) @fileMenu.addAction(@saveAct) @fileMenu.addAction(@saveAsAct) @fileMenu.addSeparator() @fileMenu.addAction(@exitAct) @editMenu = menuBar().addMenu(tr("&Edit")) @editMenu.addAction(@cutAct) @editMenu.addAction(@copyAct) @editMenu.addAction(@pasteAct) menuBar().addSeparator() @helpMenu = menuBar().addMenu(tr("&Help")) @helpMenu.addAction(@aboutAct) @helpMenu.addAction(@aboutQtAct) end
createPreviewGroupBox()
click to toggle source
# File 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()
click to toggle source
# File 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)
click to toggle source
# File examples/opengl/grabber/mainwindow.rb, line 146 def createSlider(changedSignal, setterSlot) slider = 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(slider, SIGNAL('valueChanged(int)'), @glWidget, setterSlot) connect(@glWidget, changedSignal, slider, SLOT('setValue(int)')) return slider end
createStatusBar()
click to toggle source
# File examples/mainwindows/application/mainwindow.rb, line 197 def createStatusBar() statusBar().showMessage(tr("Ready")) end
createToolBars()
click to toggle source
# File examples/mainwindows/application/mainwindow.rb, line 185 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()
click to toggle source
# File examples/painting/fontsampler/mainwindow.rb, line 279 def currentPageMap() pageMap = {} for row in 0..(@ui.fontTree.topLevelItemCount - 1) familyItem = @ui.fontTree.topLevelItem(row) if familyItem.checkState(0) == Qt::Checked family = familyItem.text(0) pageMap[family] = [] end for childRow in 0..(familyItem.childCount - 1) styleItem = familyItem.child(childRow) if styleItem.checkState(0) == Qt::Checked pageMap[family] << styleItem end end end return pageMap end
cut()
click to toggle source
# File examples/mainwindows/mdi/mainwindow.rb, line 113 def cut() if activeMdiChild() activeMdiChild().cut() end end
documentWasModified()
click to toggle source
# File examples/mainwindows/application/mainwindow.rb, line 101 def documentWasModified() setWindowModified(true) end
findFonts()
click to toggle source
# File 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)
click to toggle source
# File examples/mainwindows/sdi/mainwindow.rb, line 325 def findMainWindow(fileName) canonicalFilePath = Qt::FileInfo.new(fileName).canonicalFilePath() $qApp.topLevelWidgets.each do |widget| if widget.kind_of?(MainWindow) && widget.curFile == canonicalFilePath return mainWin end end return nil end
findMdiChild(fileName)
click to toggle source
# File examples/mainwindows/mdi/mainwindow.rb, line 352 def findMdiChild(fileName) canonicalFilePath = Qt::FileInfo.new(fileName).canonicalFilePath() @mdiArea.subWindowList().each do |window| mdiChild = window.widget if mdiChild.currentFile() == canonicalFilePath return window end end return nil end
findStyles()
click to toggle source
# File 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)
click to toggle source
# File examples/richtext/calendar/mainwindow.rb, line 159 def fontSize=(size) @fontSize = size insertCalendar() end
getSize()
click to toggle source
# File 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()
click to toggle source
# File examples/opengl/grabber/mainwindow.rb, line 92 def grabFrameBuffer() image = @glWidget.grabFrameBuffer() setPixmap(Qt::Pixmap.fromImage(image)) end
init()
click to toggle source
# File 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()
click to toggle source
# File 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)
click to toggle source
# File examples/widgets/charactermap/mainwindow.rb, line 110 def insertCharacter(character) @lineEdit.insert(character) end
insertCustomer(customer)
click to toggle source
# File 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()
click to toggle source
# File examples/mainwindows/menus/mainwindow.rb, line 129 def italic() @infoLabel.text = tr("Invoked <b>Edit|Format|Italic</b>") end
justify()
click to toggle source
# File examples/mainwindows/menus/mainwindow.rb, line 141 def justify() @infoLabel.text = tr("Invoked <b>Edit|Format|Justify</b>") end
leftAlign()
click to toggle source
# File examples/mainwindows/menus/mainwindow.rb, line 133 def leftAlign() @infoLabel.text = tr("Invoked <b>Edit|Format|Left Align</b>") end
loadFile(fileName)
click to toggle source
# File examples/mainwindows/application/mainwindow.rb, line 232 def loadFile(fileName) file = Qt::File.new(fileName) if !file.open(Qt::File::ReadOnly | Qt::File::Text) Qt::MessageBox.warning(self, tr("Application"), tr("Cannot read file %s:\n%s." % [fileName, file.errorString]) ) return end inf = Qt::TextStream.new(file) Qt::Application.setOverrideCursor(Qt::Cursor.new(Qt::WaitCursor)) @textEdit.plainText = inf.readAll() Qt::Application.restoreOverrideCursor() setCurrentFile(fileName) statusBar().showMessage(tr("File loaded"), 2000) end
markUnmarkFonts(state)
click to toggle source
# File 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()
click to toggle source
# File examples/mainwindows/application/mainwindow.rb, line 215 def maybeSave() if @textEdit.document().isModified() ret = Qt::MessageBox::warning(self, tr("Application"), 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)
click to toggle source
# File examples/richtext/calendar/mainwindow.rb, line 164 def month=(month) @selectedDate = Qt::Date.new(@selectedDate.year, month + 1, @selectedDate.day) insertCalendar() end
newFile()
click to toggle source
# File examples/mainwindows/application/mainwindow.rb, line 61 def newFile() if maybeSave() @textEdit.clear() setCurrentFile("") end end
newLetter()
click to toggle source
# File 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()
click to toggle source
# File examples/painting/fontsampler/mainwindow.rb, line 88 def on_clearAction_triggered() currentItem = @ui.fontTree.currentItem() @ui.fontTree.selectedItems.each do |item| @ui.fontTree.setItemSelected(item, false) end @ui.fontTree.setItemSelected(currentItem, true) end
on_markAction_triggered()
click to toggle source
# File examples/painting/fontsampler/mainwindow.rb, line 96 def on_markAction_triggered() markUnmarkFonts(Qt::Checked) end
on_printAction_triggered()
click to toggle source
# File 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()
click to toggle source
# File 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.setNumberOfPages = @pageMap.length preview.exec() end
on_unmarkAction_triggered()
click to toggle source
# File examples/painting/fontsampler/mainwindow.rb, line 100 def on_unmarkAction_triggered() markUnmarkFonts(Qt::Unchecked) end
open()
click to toggle source
# File examples/mainwindows/application/mainwindow.rb, line 68 def open() if maybeSave() fileName = Qt::FileDialog.getOpenFileName(self) if !fileName.nil? loadFile(fileName) end end end
openDialog()
click to toggle source
# File 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)
click to toggle source
# File 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(path = "")
click to toggle source
# File examples/draganddrop/puzzle/mainwindow.rb, line 47 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()
click to toggle source
# File examples/mainwindows/recentfiles/mainwindow.rb, line 96 def openRecentFile() action = sender() if !action.nil? loadFile(action.data().toString()) end end
paste()
click to toggle source
# File examples/mainwindows/mdi/mainwindow.rb, line 125 def paste() if activeMdiChild() activeMdiChild().paste() end end
penColor()
click to toggle source
# File 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()
click to toggle source
# File 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()
click to toggle source
# File examples/mainwindows/dockwidgets/mainwindow.rb, line 102 def print() document = @textEdit.document() printer = Qt::Printer.new dlg = Qt::PrintDialog.new(printer, self) if dlg.exec() != Qt::Dialog::Accepted return end document.print(printer) statusBar().showMessage(tr("Ready"), 2000) end
printFile()
click to toggle source
# File 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()
click to toggle source
# File 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)
click to toggle source
# File examples/painting/fontsampler/mainwindow.rb, line 306 def printPage(index, painter, printer) pageMap = currentPageMap() 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.new(x, y), "%s %s" % [family, style]) y += interLineHeight end y += spaceHeight end painter.restore() end
readSettings()
click to toggle source
# File examples/mainwindows/application/mainwindow.rb, line 201 def readSettings() settings = Qt::Settings.new("Trolltech", "Application 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() resize(size) move(pos) end
redo()
click to toggle source
# File examples/mainwindows/menus/mainwindow.rb, line 109 def redo() @infoLabel.text = tr("Invoked <b>Edit|Redo</b>") end
removeAllImages()
click to toggle source
# File examples/widgets/icons/mainwindow.rb, line 194 def removeAllImages() @imagesTable.rowCount = 0 changeIcon() end
renderIntoPixmap()
click to toggle source
# File 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
renderer=(action)
click to toggle source
# File 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
rightAlign()
click to toggle source
# File examples/mainwindows/menus/mainwindow.rb, line 137 def rightAlign() @infoLabel.text = tr("Invoked <b>Edit|Format|Right Align</b>") end
save()
click to toggle source
# File examples/mainwindows/application/mainwindow.rb, line 77 def save() if @curFile.empty? return saveAs() else return saveFile(@curFile) end end
saveAs()
click to toggle source
# File examples/mainwindows/application/mainwindow.rb, line 85 def saveAs() fileName = Qt::FileDialog.getSaveFileName(self) if fileName.nil? return false end return saveFile(fileName) end
saveFile()
click to toggle source
# File 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()
click to toggle source
# File examples/draganddrop/puzzle/mainwindow.rb, line 68 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)
click to toggle source
# File examples/mainwindows/application/mainwindow.rb, line 268 def setCurrentFile(fileName) @curFile = fileName @textEdit.document().modified = false setWindowModified(false) if @curFile.empty? shownName = "untitled.txt" else shownName = strippedName(@curFile) end setWindowTitle(tr("%s[*] - %s" % [shownName, tr("Application")])) end
setLineSpacing()
click to toggle source
# File examples/mainwindows/menus/mainwindow.rb, line 149 def setLineSpacing() @infoLabel.text = tr("Invoked <b>Edit|Format|Set Line Spacing</b>") end
setParagraphSpacing()
click to toggle source
# File examples/mainwindows/menus/mainwindow.rb, line 153 def setParagraphSpacing() @infoLabel.text = tr("Invoked <b>Edit|Format|Set Paragraph Spacing</b>") end
setPixmap(pixmap)
click to toggle source
# File 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()
click to toggle source
# File 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()
click to toggle source
# File examples/richtext/syntaxhighlighter/mainwindow.rb, line 94 def setupFileMenu() fileMenu = Qt::Menu.new(tr("&File"), self) menuBar().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()
click to toggle source
# File 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()
click to toggle source
# File examples/draganddrop/puzzle/mainwindow.rb, line 104 def setupMenus() fileMenu = menuBar().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 = menuBar().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()
click to toggle source
# File 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)
click to toggle source
# File examples/painting/fontsampler/mainwindow.rb, line 301 def setupPrinter(printer) dialog = Qt::PrintDialog.new(printer, self) return dialog.exec() == Qt::Dialog::Accepted end
setupPuzzle()
click to toggle source
# File examples/draganddrop/puzzle/mainwindow.rb, line 77 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) @piecesList.clear() (0...5).each do |y| (0...5).each do |x| pieceImage = @puzzleImage.copy(x*80, y*80, 80, 80) @piecesList.addPiece(pieceImage, Qt::Point.new(x, y)) end end Kernel.srand (0...@piecesList.count).each do |i| if (2.0*rand(RAND_MAX)/(RAND_MAX+1.0)).to_i == 1 item = @piecesList.takeItem(i) @piecesList.insertItem(0, item) end end @puzzleWidget.clear() end
setupViews()
click to toggle source
# File 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()
click to toggle source
# File examples/draganddrop/puzzle/mainwindow.rb, line 122 def setupWidgets() frame = Qt::Frame.new frameLayout = Qt::HBoxLayout.new(frame) @piecesList = PiecesList.new @puzzleWidget = PuzzleWidget.new connect(@puzzleWidget, SIGNAL('puzzleCompleted()'), self, SLOT('setCompleted()'), Qt::QueuedConnection) frameLayout.addWidget(@piecesList) frameLayout.addWidget(@puzzleWidget) setCentralWidget(frame) end
showAboutBox()
click to toggle source
# File 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)
click to toggle source
# File 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)
click to toggle source
# File examples/mainwindows/application/mainwindow.rb, line 282 def strippedName(fullFileName) return Qt::FileInfo.new(fullFileName).fileName() end
undo()
click to toggle source
# File examples/mainwindows/dockwidgets/mainwindow.rb, line 138 def undo() document = @textEdit.document() document.undo() end
updateClipboard()
click to toggle source
# File 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()
click to toggle source
# File 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()
click to toggle source
# File 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)
click to toggle source
# File 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 - 1) 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 - 1) 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 - 1) 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 - 1) 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()
click to toggle source
# File 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()
click to toggle source
# File 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].widget 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
writeSettings()
click to toggle source
# File examples/mainwindows/application/mainwindow.rb, line 209 def writeSettings() settings = Qt::Settings.new("Trolltech", "Application Example") settings.setValue("pos", Qt::Variant.new(pos())) settings.setValue("size", Qt::Variant.new(size())) end
year=(date)
click to toggle source
# File examples/richtext/calendar/mainwindow.rb, line 169 def year=(date) @selectedDate = Qt::Date.new(date.year, @selectedDate.month, @selectedDate.day) insertCalendar() end