class DetailsDialog

Public Class Methods

new(title, parent = nil) click to toggle source
Calls superclass method
# File examples/richtext/orderform/detailsdialog.rb, line 30
def initialize(title, parent = nil)
    super(parent)
        @orderItems = []
        @items = []
    nameLabel = Qt::Label.new(tr("Name:"))
    addressLabel = Qt::Label.new(tr("Address:"))

    @nameEdit = Qt::LineEdit.new
    @addressEdit = Qt::TextEdit.new
    @addressEdit.plainText = ""
    @offersCheckBox = Qt::CheckBox.new(tr("Send offers:"))

    setupItemsTable()

    okButton = Qt::PushButton.new(tr("OK"))
    cancelButton = Qt::PushButton.new(tr("Cancel"))
    okButton.default = true

    connect(okButton, SIGNAL('clicked()'), self, SLOT('verify()'))
    connect(cancelButton, SIGNAL('clicked()'), self, SLOT('reject()'))

    detailsLayout = Qt::GridLayout.new do |d|
                d.addWidget(nameLabel, 0, 0)
                d.addWidget(@nameEdit, 0, 1)
                d.addWidget(addressLabel, 1, 0)
                d.addWidget(@addressEdit, 1, 1)
                d.addWidget(@itemsTable, 0, 2, 2, 2)
                d.addWidget(@offersCheckBox, 2, 1, 1, 4)
        end

    buttonLayout = Qt::HBoxLayout.new do |b|
                b.addStretch(1)
                b.addWidget(okButton)
                b.addWidget(cancelButton)
        end

    self.layout = Qt::VBoxLayout.new do |m|
                m.addLayout(detailsLayout)
                m.addLayout(buttonLayout)
    end

    self.windowTitle = title
end

Public Instance Methods

orderItems() click to toggle source
# File examples/richtext/orderform/detailsdialog.rb, line 89
def orderItems()
    orderList = []

        (0...@items.length).each do |row|
        item = Array.new(2)
        item[0] = @itemsTable.item(row, 0).text
        quantity = @itemsTable.item(row, 1).data(Qt::DisplayRole).toInt
        item[1] = [0, quantity].max
        orderList.push(item)
    end

    return orderList
end
sendOffers() click to toggle source
# File examples/richtext/orderform/detailsdialog.rb, line 111
def sendOffers()
    return @offersCheckBox.checked?
end
senderAddress() click to toggle source
# File examples/richtext/orderform/detailsdialog.rb, line 107
def senderAddress()
    return @addressEdit.toPlainText
end
senderName() click to toggle source
# File examples/richtext/orderform/detailsdialog.rb, line 103
def senderName()
    return @nameEdit.text
end
setupItemsTable() click to toggle source
# File examples/richtext/orderform/detailsdialog.rb, line 74
def setupItemsTable()
    @items << tr("T-shirt") << tr("Badge") << tr("Reference book") <<
          tr("Coffee cup")

    @itemsTable = Qt::TableWidget.new(@items.length, 2)

        (0...@items.length).each do |row|
        name = Qt::TableWidgetItem.new(@items[row])
        name.flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable
        @itemsTable.setItem(row, 0, name)
        quantity = Qt::TableWidgetItem.new("1")
        @itemsTable.setItem(row, 1, quantity)
    end
end
verify() click to toggle source
# File examples/richtext/orderform/detailsdialog.rb, line 115
def verify()
    if !@nameEdit.text.empty? && !@addressEdit.toPlainText.empty?
        accept()
        return
    end

    answer = Qt::MessageBox.warning(self, tr("Incomplete Form"),
        tr("The form does not contain all the necessary information.\n" +
           "Do you want to discard it?"),
        Qt::MessageBox::Yes, Qt::MessageBox::No)

    if answer == Qt::MessageBox::Yes
        reject()
        end
end