class DropSiteWindow

Public Class Methods

new(parent = nil) click to toggle source
Calls superclass method
# File examples/draganddrop/dropsite/dropsitewindow.rb, line 32
def initialize(parent = nil)
    super(parent)
    @abstractLabel = Qt::Label.new(tr("The Drop Site example accepts drops from other "                                            "applications, and displays the MIME formats "                                            "provided by the drag object."))
    @abstractLabel.wordWrap = true
    @abstractLabel.adjustSize()

    @dropArea = DropArea.new
    connect(@dropArea, SIGNAL('changed(const QMimeData*)'),
            self, SLOT('updateFormatsTable(const QMimeData*)'))

    labels = []
    labels << tr("Format") << tr("Content")

    @formatsTable = Qt::TableWidget.new
@formatsTable.setColumnCount(2)
@formatsTable.setEditTriggers(Qt::AbstractItemView::NoEditTriggers)
@formatsTable.setHorizontalHeaderLabels(labels)
@formatsTable.horizontalHeader.setStretchLastSection(true)

    @quitButton = Qt::PushButton.new(tr("Quit"))
    @clearButton = Qt::PushButton.new(tr("Clear"))

@buttonBox = Qt::DialogButtonBox.new
@buttonBox.addButton(@clearButton, Qt::DialogButtonBox::ActionRole)
@buttonBox.addButton(@quitButton, Qt::DialogButtonBox::RejectRole)

    connect(@quitButton, SIGNAL('pressed()'), self, SLOT('close()'))
    connect(@clearButton, SIGNAL('pressed()'), @dropArea, SLOT('clear()'))

    @layout = Qt::VBoxLayout.new do |l|
                l.addWidget(@abstractLabel)
                l.addWidget(@dropArea)
                l.addWidget(@formatsTable)
                l.addWidget(@buttonBox)
        end

    setLayout(@layout)
    setWindowTitle(tr("Drop Site"))
    setMinimumSize(350, 500)
end

Public Instance Methods

updateFormatsTable(mimeData = nil) click to toggle source
# File examples/draganddrop/dropsite/dropsitewindow.rb, line 75
def updateFormatsTable(mimeData = nil)
    @formatsTable.rowCount = 0

    if mimeData.nil?
        return
        end

    formats = mimeData.formats()

    formats.each do |format|
        formatItem = Qt::TableWidgetItem.new(format)
        formatItem.flags = Qt::ItemIsEnabled
        formatItem.textAlignment = Qt::AlignTop | Qt::AlignLeft
        
        text = ""
        if format == "text/plain"
        text = mimeData.text.simplified
    elsif format == "text/html"
        text = mimeData.text.simplified
    elsif format == "text/uri-list"
        urlList = mimeData.urls
        urlList.each do |url|
            text << url.path + " "
        end
        else
            data = mimeData.data(format)
            hexdata = ""
        data.to_s.each_byte { |b| hexdata << ("%2.2x " % b) }
            text << hexdata
        end

        row = @supportedFormats.rowCount()
        @formatsTable.insertRow(row)
        @formatsTable.setItem(row, 0, Qt::TabelWidgetItem.new(format))
        @formatsTable.setItem(row, 1, Qt::TabelWidgetItem.new(text))
    end

    @formatsTable.resizeColumnToContents(0)
end