Class: Dialog

Inherits:
Qt::Dialog show all
Defined in:
ext/ruby/qtruby/examples/network/loopback/dialog.rb,
ext/ruby/qtruby/examples/widgets/wiggly/dialog.rb,
ext/ruby/qtruby/examples/layouts/basiclayouts/dialog.rb,
ext/ruby/qtruby/examples/dialogs/standarddialogs/dialog.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

TotalBytes =
50 * 1024 * 1024
PayloadSize =
65536
NumGridRows =
3
NumButtons =
4

Instance Method Summary collapse

Methods inherited from Qt::Dialog

#exec

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) ⇒ Dialog

Returns a new instance of Dialog.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'ext/ruby/qtruby/examples/widgets/wiggly/dialog.rb', line 29

def initialize(parent = nil)
    super(parent)

    wigglyWidget = WigglyWidget.new
    lineEdit = Qt::LineEdit.new

    layout = Qt::VBoxLayout.new
    layout.addWidget(wigglyWidget)
    layout.addWidget(lineEdit)
    setLayout(layout)

    connect(lineEdit, SIGNAL('textChanged(QString)'),
            wigglyWidget, SLOT('setText(QString)'))

    lineEdit.setText(tr("Hello world!"))

    setWindowTitle(tr("Wiggly"))
    resize(360, 145)
end

Instance Method Details

#acceptConnectionObject



101
102
103
104
105
106
107
108
109
110
# File 'ext/ruby/qtruby/examples/network/loopback/dialog.rb', line 101

def acceptConnection()
    @tcpServerConnection = @tcpServer.nextPendingConnection
    connect(@tcpServerConnection, SIGNAL(:readyRead),
            self, SLOT(:updateServerProgress))
    connect(@tcpServerConnection, SIGNAL('error(QAbstractSocket::SocketError)'),
            self, SLOT('displayError(QAbstractSocket::SocketError)'))

    @serverStatusLabel.text = tr("Accepted connection")
    @tcpServer.close()
end

#createGridGroupBoxObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'ext/ruby/qtruby/examples/layouts/basiclayouts/dialog.rb', line 90

def createGridGroupBox()
    @gridGroupBox = Qt::GroupBox.new(tr("Grid layout"))
    layout = Qt::GridLayout.new

	(0...NumGridRows).each do |i|
		@labels[i] = Qt::Label.new(tr("Line %d:" % (i + 1)))
		@lineEdits[i] = Qt::LineEdit.new
		layout.addWidget(@labels[i], i, 0)
		layout.addWidget(@lineEdits[i], i, 1)
    end

    @smallEditor = Qt::TextEdit.new
    @smallEditor.setPlainText(tr("This widget takes up about two thirds of the " +
                                 "grid layout."))
    layout.addWidget(@smallEditor, 0, 2, 3, 1)

    layout.setColumnStretch(1, 10)
    layout.setColumnStretch(2, 20)
    @gridGroupBox.layout = layout
end

#createHorizontalGroupBoxObject



79
80
81
82
83
84
85
86
87
88
# File 'ext/ruby/qtruby/examples/layouts/basiclayouts/dialog.rb', line 79

def createHorizontalGroupBox()
    @horizontalGroupBox = Qt::GroupBox.new(tr("Horizontal layout"))
    layout = Qt::HBoxLayout.new

	(0...NumButtons).each do |i|
        @buttons[i] = Qt::PushButton.new(tr("Button %d" % (i + 1)))
		layout.addWidget(@buttons[i])
    end
    @horizontalGroupBox.layout = layout
end

#createMenuObject



69
70
71
72
73
74
75
76
77
# File 'ext/ruby/qtruby/examples/layouts/basiclayouts/dialog.rb', line 69

def createMenu()
    @menuBar = Qt::MenuBar.new

    @fileMenu = Qt::Menu.new(tr("&File"), self)
    @exitAction = @fileMenu.addAction(tr("E&xit"))
    @menuBar.addMenu(@fileMenu)

    connect(@exitAction, SIGNAL('triggered()'), self, SLOT('accept()'))
end

#criticalMessageObject



282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'ext/ruby/qtruby/examples/dialogs/standarddialogs/dialog.rb', line 282

def criticalMessage()
    reply = Qt::MessageBox::critical(self, tr("Qt::MessageBox.showCritical()"),
                                      @message,
                                      Qt::MessageBox::Abort,
                                      Qt::MessageBox::Retry,
                                      Qt::MessageBox::Ignore)
    if reply == Qt::MessageBox::Abort
        @criticalLabel.text = tr("Abort")
    elsif reply == Qt::MessageBox::Retry
        @criticalLabel.text = tr("Retry")
    else
        @criticalLabel.text = tr("Ignore")
    end
end

#displayError(socketError) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'ext/ruby/qtruby/examples/network/loopback/dialog.rb', line 145

def displayError(socketError)
    if socketError == Qt::TcpSocket::RemoteHostClosedError
        return
	end

    Qt::MessageBox.information(self, tr("Network error"),
                             tr("The following error occurred: %s." %
                                 tcpClient.errorString))

    @tcpClient.close
    @tcpServer.close
    @clientProgressBar.reset
    @serverProgressBar.reset
    @clientStatusLabel.text = tr("Client ready")
    @serverStatusLabel.text = tr("Server ready")
    @startButton.enabled = true
    Qt::Application.restoreOverrideCursor
end

#errorMessageObject



329
330
331
332
333
334
335
336
337
338
339
# File 'ext/ruby/qtruby/examples/dialogs/standarddialogs/dialog.rb', line 329

def errorMessage()
    @errorMessageDialog.showMessage(
            tr("This dialog shows and remembers error messages. " +
               "If the checkbox is checked (as it is by default), " +
               "the shown message will be shown again, " +
               "but if the user unchecks the box the message " +
               "will not appear again if Qt::ErrorMessage.showMessage() " +
               "is called with the same message."))
    @errorLabel.text = tr("If the box is unchecked, the message " +
                           "won't appear again.")
end

#informationMessageObject



297
298
299
300
# File 'ext/ruby/qtruby/examples/dialogs/standarddialogs/dialog.rb', line 297

def informationMessage()
    Qt::MessageBox::information(self, tr("Qt::MessageBox.showInformation()"), @message)
    @informationLabel.text = tr("Closed with OK or Esc")
end

#questionMessageObject



302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'ext/ruby/qtruby/examples/dialogs/standarddialogs/dialog.rb', line 302

def questionMessage()
    reply = Qt::MessageBox.question(self, tr("Qt::MessageBox.showQuestion()"),
                                      @message,
                                      Qt::MessageBox::Yes,
                                      Qt::MessageBox::No,
                                      Qt::MessageBox::Cancel)
    if reply == Qt::MessageBox::Yes
        @questionLabel.text = tr("Yes")
    elsif reply == Qt::MessageBox::No
        @questionLabel.text = tr("No")
    else
        @questionLabel.text = tr("Cancel")
    end
end

#setColorObject



224
225
226
227
228
229
230
# File 'ext/ruby/qtruby/examples/dialogs/standarddialogs/dialog.rb', line 224

def setColor()
    color = Qt::ColorDialog.getColor(Qt::Color.new(Qt::green), self)
    if color.isValid()
        @colorLabel.text = color.name
        @colorLabel.palette = Qt::Palette.new(color)
    end
end

#setDoubleObject



193
194
195
196
197
198
199
200
# File 'ext/ruby/qtruby/examples/dialogs/standarddialogs/dialog.rb', line 193

def setDouble()
    ok = Qt::Boolean.new
    d = Qt::InputDialog.getDouble(self, tr("Qt::InputDialog.getDouble()"),
                                       tr("Amount:"), 37.56, -10000, 10000, 2, ok)
    if ok
        @doubleLabel.text = "$%f" % d
    end
end

#setExistingDirectoryObject



240
241
242
243
244
245
246
247
248
249
# File 'ext/ruby/qtruby/examples/dialogs/standarddialogs/dialog.rb', line 240

def setExistingDirectory()
    directory = Qt::FileDialog.getExistingDirectory(self,
                                tr("Qt::FileDialog.getExistingDirectory()"),
                                @directoryLabel.text,
                                Qt::FileDialog::DontResolveSymlinks |
                                Qt::FileDialog::ShowDirsOnly)
    if !directory.nil?
        @directoryLabel.text = directory
    end
end

#setFontObject



232
233
234
235
236
237
238
# File 'ext/ruby/qtruby/examples/dialogs/standarddialogs/dialog.rb', line 232

def setFont()
    ok = Qt::Boolean.new
    font = Qt::FontDialog.getFont(ok, Qt::Font.new(@fontLabel.text), self)
    if ok
        @fontLabel.text = font.key()
    end
end

#setIntegerObject



184
185
186
187
188
189
190
191
# File 'ext/ruby/qtruby/examples/dialogs/standarddialogs/dialog.rb', line 184

def setInteger()
    ok = Qt::Boolean.new
    i = Qt::InputDialog.getInteger(self, tr("Qt::InputDialog.getInteger()"),
                                     tr("Percentage:"), 25, 0, 100, 1, ok)
    if ok
        @integerLabel.text = tr("%d%" % i)
    end
end

#setItemObject



202
203
204
205
206
207
208
209
210
211
212
# File 'ext/ruby/qtruby/examples/dialogs/standarddialogs/dialog.rb', line 202

def setItem()
    items = []
    items << tr("Spring") << tr("Summer") << tr("Fall") << tr("Winter")

    ok = Qt::Boolean.new
    item = Qt::InputDialog.getItem(self, tr("Qt::InputDialog.getItem()"),
                                         tr("Season:"), items, 0, false, ok)
    if ok && !item.nil?
        @itemLabel.text = item
    end
end

#setOpenFileNameObject



251
252
253
254
255
256
257
258
259
# File 'ext/ruby/qtruby/examples/dialogs/standarddialogs/dialog.rb', line 251

def setOpenFileName()
    fileName = Qt::FileDialog.getOpenFileName(self,
                                tr("Qt::FileDialog.getOpenFileName()"),
                                @openFileNameLabel.text,
                                tr("All Files (*);;Text Files (*.txt)"))
    if !fileName.nil?
        @openFileNameLabel.text = fileName
    end
end

#setOpenFileNamesObject



261
262
263
264
265
266
267
268
269
270
# File 'ext/ruby/qtruby/examples/dialogs/standarddialogs/dialog.rb', line 261

def setOpenFileNames()
    files = Qt::FileDialog.getOpenFileNames(
                                self, tr("Qt::FileDialog.getOpenFileNames()"),
                                @openFilesPath,
                                tr("All Files (*);;Text Files (*.txt)"))
    if files.length != 0
        @openFilesPath = files[0]
        @openFileNamesLabel.text = "[%s]" % files.join(", ")
    end
end

#setSaveFileNameObject



272
273
274
275
276
277
278
279
280
# File 'ext/ruby/qtruby/examples/dialogs/standarddialogs/dialog.rb', line 272

def setSaveFileName()
    fileName = Qt::FileDialog.getSaveFileName(self,
                                tr("Qt::FileDialog.getSaveFileName()"),
                                @saveFileNameLabel.text,
                                tr("All Files (*);;Text Files (*.txt)"))
    if !fileName.nil?
        @saveFileNameLabel.text = fileName
    end
end

#setTextObject



214
215
216
217
218
219
220
221
222
# File 'ext/ruby/qtruby/examples/dialogs/standarddialogs/dialog.rb', line 214

def setText()
    ok = Qt::Boolean.new
    text = Qt::InputDialog.getText(self, tr("Qt::InputDialog.getText()"),
                                         tr("User name:"), Qt::LineEdit::Normal,
                                         Qt::Dir::home().dirName(), ok)
    if ok && !text.nil?
        @textLabel.text = text
    end
end

#startObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'ext/ruby/qtruby/examples/network/loopback/dialog.rb', line 77

def start()
    @startButton.enabled = false

    Qt::Application.overrideCursor = Qt::Cursor.new(Qt::WaitCursor)

    @bytesWritten = 0
    @bytesReceived = 0

    while !@tcpServer.isListening && !@tcpServer.listen do
        ret = Qt::MessageBox.critical(self, tr("Loopback"),
                                        tr("Unable to start the test: %s." % @tcpServer.errorString),
                                        Qt::MessageBox::Retry,
					                    Qt::MessageBox::Cancel)
        if ret == Qt::MessageBox::Cancel
            return
		end
    end

    @serverStatusLabel.text = tr("Listening")
    @clientStatusLabel.text = tr("Connecting")
    @tcpClient.connectToHost(Qt::HostAddress.new(Qt::HostAddress::LocalHost), 
							@tcpServer.serverPort)
end

#startTransferObject



112
113
114
115
# File 'ext/ruby/qtruby/examples/network/loopback/dialog.rb', line 112

def startTransfer()
    @bytesToWrite = TotalBytes - @tcpClient.write(Qt::ByteArray.new('@' * PayloadSize))
    @clientStatusLabel.text = tr("Connected")
end

#updateClientProgress(numBytes) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
# File 'ext/ruby/qtruby/examples/network/loopback/dialog.rb', line 133

def updateClientProgress(numBytes)
    @bytesWritten += numBytes
    if @bytesToWrite > 0
        @bytesToWrite -= @tcpClient.write(Qt::ByteArray.new('@' * [@bytesToWrite, PayloadSize].min))
	end

    @clientProgressBar.maximum = TotalBytes
    @clientProgressBar.value = @bytesWritten
    @clientStatusLabel.text = tr("Sent %dMB" % 
                                 (@bytesWritten / (1024 * 1024)) )
end

#updateServerProgressObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'ext/ruby/qtruby/examples/network/loopback/dialog.rb', line 117

def updateServerProgress()
    @bytesReceived += @tcpServerConnection.bytesAvailable
    @tcpServerConnection.readAll()

    @serverProgressBar.maximum = TotalBytes
    @serverProgressBar.value = @bytesReceived
    @serverStatusLabel.text = tr("Received %dMB" %
                                  (@bytesReceived / (1024 * 1024)))

    if @bytesReceived == TotalBytes
        @tcpServerConnection.close
        @startButton.enabled = true
        Qt::Application.restoreOverrideCursor
    end
end

#warningMessageObject



317
318
319
320
321
322
323
324
325
326
327
# File 'ext/ruby/qtruby/examples/dialogs/standarddialogs/dialog.rb', line 317

def warningMessage()
    reply = Qt::MessageBox.warning(self, tr("Qt::MessageBox.showWarning()"),
                                     @message,
                                     tr("Save &Again"),
                                     tr("&Continue"))
    if reply == 0
        @warningLabel.text = tr("Save Again")
    else
        @warningLabel.text = tr("Continue")
    end
end