Class: DropSiteWindow

Inherits:
Qt::Widget show all
Defined in:
ext/ruby/qtruby/examples/draganddrop/dropsite/dropsitewindow.rb

Instance Method Summary collapse

Methods inherited from Qt::Widget

#raise

Methods inherited from Qt::Base

#%, #&, #*, #**, #+, #-, #-@, #/, #<, #<<, #<=, #==, #>, #>=, #>>, #QCOMPARE, #QEXPECT_FAIL, #QFAIL, #QSKIP, #QTEST, #QVERIFY, #QVERIFY2, #QWARN, #^, ancestors, #is_a?, #methods, private_slots, #protected_methods, #public_methods, q_classinfo, q_signal, q_slot, signals, #singleton_methods, slots, #|, #~

Constructor Details

#initialize(parent = nil) ⇒ DropSiteWindow

Returns a new instance of DropSiteWindow.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'ext/ruby/qtruby/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

Instance Method Details

#updateFormatsTable(mimeData = nil) ⇒ Object



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
# File 'ext/ruby/qtruby/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