class MdiChild

Attributes

currentFile[R]

Public Class Methods

new() click to toggle source
Calls superclass method
# File examples/mainwindows/mdi/mdichild.rb, line 34
def initialize()
        super
    setAttribute(Qt::WA_DeleteOnClose)
    @isUntitled = true
end

Public Instance Methods

closeEvent(event) click to toggle source
# File examples/mainwindows/mdi/mdichild.rb, line 111
def closeEvent(event)
    if maybeSave()
        event.accept()
    else
        event.ignore()
    end
end
documentWasModified() click to toggle source
# File examples/mainwindows/mdi/mdichild.rb, line 119
def documentWasModified()
    setWindowModified(document().isModified())
end
loadFile(fileName) click to toggle source
# File examples/mainwindows/mdi/mdichild.rb, line 51
def loadFile(fileName)
    file = Qt::File.new(fileName)
    if !file.open(Qt::File::ReadOnly | Qt::File::Text)
        Qt::MessageBox.warning(self, tr("MDI"),
                             tr("Cannot read file %s:\n%s." % [fileName, file.errorString]))
        return false
    end

    inf = Qt::TextStream.new(file)
    Qt::Application.overrideCursor = Qt::Cursor.new(Qt::WaitCursor)
    setPlainText(inf.readAll())
    Qt::Application.restoreOverrideCursor()

    setCurrentFile(fileName)

    connect(document(), SIGNAL('contentsChanged()'),
            self, SLOT('documentWasModified()'))

    return true
end
maybeSave() click to toggle source
# File examples/mainwindows/mdi/mdichild.rb, line 123
def maybeSave()
    if document().isModified()
        ret = Qt::MessageBox::warning(self, tr("MDI"),
                     tr("'%s' has been modified.\n" \
                        "Do you want to save your changes?" % 
                      userFriendlyCurrentFile()),
                     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
newFile() click to toggle source
# File examples/mainwindows/mdi/mdichild.rb, line 40
def newFile()
    @@sequenceNumber = 1

    @isUntitled = true
    @currentFile = tr("document%s.txt" % @@sequenceNumber += 1)
    setWindowTitle(@currentFile + "[*]")

    connect(document(), SIGNAL('contentsChanged()'),
            self, SLOT('documentWasModified()'))
end
save() click to toggle source
# File examples/mainwindows/mdi/mdichild.rb, line 72
def save()
    if @isUntitled
        return saveAs()
    else
        return saveFile(@currentFile)
    end
end
saveAs() click to toggle source
# File examples/mainwindows/mdi/mdichild.rb, line 80
def saveAs()
    fileName = Qt::FileDialog.getSaveFileName(self, tr("Save As"),
                                                    @currentFile)
    if not fileName or fileName.empty?
        return false
        end

    return saveFile(fileName)
end
saveFile(fileName) click to toggle source
# File examples/mainwindows/mdi/mdichild.rb, line 90
def saveFile(fileName)
    file = Qt::File.new(fileName)
    if !file.open(Qt::File::WriteOnly | Qt::File::Text)
        Qt::MessageBox::warning(self, tr("MDI"),
                             tr("Cannot write file %s:\n%s." % [fileName, file.errorString]))
        return false
    end

    outf = Qt::TextStream.new(file)
    Qt::Application.setOverrideCursor(Qt::WaitCursor)
    outf << toPlainText()
    Qt::Application.restoreOverrideCursor()

    setCurrentFile(fileName)
    return true
end
setCurrentFile(fileName) click to toggle source
# File examples/mainwindows/mdi/mdichild.rb, line 141
def setCurrentFile(fileName)
    @currentFile = Qt::FileInfo.new(fileName).canonicalFilePath()
    @isUntitled = false
    document().modified = false
    setWindowModified(false)
    setWindowTitle(userFriendlyCurrentFile() + "[*]")
end
strippedName(fullFileName) click to toggle source
# File examples/mainwindows/mdi/mdichild.rb, line 149
def strippedName(fullFileName)
    return Qt::FileInfo.new(fullFileName).fileName()
end
userFriendlyCurrentFile() click to toggle source
# File examples/mainwindows/mdi/mdichild.rb, line 107
def userFriendlyCurrentFile()
    return strippedName(@currentFile)
end