=begin
This is a ruby version of Jim Bublitz's pytde program, translated by Richard Dale
=end

require 'Korundum'

module UIDialogs

class CustomDlg < KDE::Dialog

	slots 'dlgClicked()', 'okClicked()', 'cancelClicked()'
	
    def initialize(parent, name = "custom dlg", modal = false)
        super(parent, name, modal)

        x = 20
        y = 10

        rLbl        = TQt::Label.new("r", self)
        gLbl        = TQt::Label.new("g", self)
        bLbl        = TQt::Label.new("b", self)
        @rEd    = TQt::LineEdit.new("64", self)
        @gEd    = TQt::LineEdit.new("64", self)
        @bEd    = TQt::LineEdit.new("64", self)
        dlgBtn = TQt::PushButton.new("Set/Get Color", self)
        okBtn  = TQt::PushButton.new("OK", self)
        canBtn = TQt::PushButton.new("Cancel", self)

        rLbl.setGeometry(x, y, 25, 20)
        gLbl.setGeometry(x + 30, y, 25, 20)
        bLbl.setGeometry(x + 60, y, 25, 20)
        y = y + 20
        @rEd.setGeometry(x, y, 25, 20)
        @gEd.setGeometry(x + 30, y, 25, 20)
        @bEd.setGeometry(x + 60, y, 25, 20)
        y = y + 30
        dlgBtn.setGeometry(x, y, 90, 22)
        y = y + 30
        okBtn.setGeometry(x, y, 40, 22)
        canBtn.setGeometry(x + 50, y, 40, 22)

        connect(dlgBtn, TQ_SIGNAL("clicked()"), TQ_SLOT('dlgClicked()'))
        connect(okBtn, TQ_SIGNAL("clicked()"), TQ_SLOT('okClicked()'))
        connect(canBtn, TQ_SIGNAL("clicked()"), TQ_SLOT('cancelClicked()'))
	end
    
	def dlgClicked()
        # get some(numerical) color values from the original dialog
        red   = @rEd.text().to_i
        green = @gEd.text().to_i
        blue  = @bEd.text().to_I

        # convert the numbers to a TQt::Color
        color = TQt::Color.new(red, green, blue)

        # invoke the dialog(getColor is a 'static' call)
        # initialize with the colors from above(in color)
        # color will also hold the new value chosen in the
        # KDE::ColorDialog
        result = KDE::ColorDialog.getColor(color, self)

        # get the numerical color values back
#        red, green, blue = color.rgb()

        # update the TQt::LineEdits in the original dialog
        @rEd.setText(red.to_s)
        @gEd.setText(green.to_s)
        @bEd.setText(blue.to_s)
	end

    def okClicked()
        done(1)
	end

    def cancelClicked()
        done(0)
	end
end

class MessageDlg < KDE::Dialog

	slots 'launch(int)'
	
    def initialize(parent, name = "message dlg", modal = false)
        super(parent, name, modal)

        buttons = ["QuestionYesNo", "WarningYesNo", "WarningContinueCancel", "WarningYesNoCancel",
                   "Information", "SSLMessageBox", "Sorry", "Error", "QuestionYesNoCancel"]

        n = buttons.length

        grp = TQt::ButtonGroup.new(n, TQt::Vertical, "MessageBoxes", self, "button grp")
        grp.setGeometry(10, 10, 200, 30*n)
		(0...n).each { |i| TQt::RadioButton.new(buttons[i], grp) }

        connect(grp, TQ_SIGNAL("clicked(int)"), TQ_SLOT('launch(int)'))
	end

    def launch(which)
		which += 1 # TQt::ButtonGroup id's start at 0, but the KDE::MessageBox enum starts at 1
		
        if which == KDE::MessageBox::QuestionYesNo
            KDE::MessageBox.questionYesNo(self, "This is a questionYesNo message box\nThere is also a list version of this dialog",\
                                       "questionYesNo")

        elsif which == KDE::MessageBox::WarningYesNo
            KDE::MessageBox.warningYesNo(self, "This is a warningYesNo message box", "warningYesNo")

        elsif which == KDE::MessageBox::WarningContinueCancel
            KDE::MessageBox.warningContinueCancel(self, "This is a warningContinueCancel message box", "warningContinueCancel");

        elsif which == KDE::MessageBox::WarningYesNoCancel
            KDE::MessageBox.warningYesNoCancel(self, "This is a warningYesNoCancel message box", "warningYesNoCancel")

        elsif which == KDE::MessageBox::Information
            KDE::MessageBox.information(self, "This is an information message box", "Information")

#        elsif which == KDE::MessageBox::SSLMessageBox
#            KDE::MessageBox.SSLMessageBox(self, "This is an SSLMessageBox message box", "not implemented yet")

        elsif which == KDE::MessageBox::Sorry
            KDE::MessageBox.sorry(self, "This is a 'sorry' message box", "Sorry")

        elsif which == KDE::MessageBox::Error
            KDE::MessageBox.error(self, "No - this isn't really an error\nIt's an error message box\n", "Error")
        
		elsif which == KDE::MessageBox::QuestionYesNoCancel
            KDE::MessageBox.questionYesNoCancel(self, "No - this isn't really an error\nIt's an QuestionYesNoCancel message box\n", "QuestionYesNoCancel")
		end
	end
end


def UIDialogs.dlgTDEAboutDialog(parent)
    dlg = KDE::AboutDialog.new(parent, 'about dialog', false)
    dlg.setLogo(TQt::Pixmap.new("rbtestimage.png"))
    dlg.setTitle("UISampler for Korundum")
    dlg.setAuthor("Jim Bublitz", "jbublitz@nwinternet.com", "http://www.riverbankcomputing.co.uk",
                    "\n\nPyKDE -- Python bindings\n\tfor KDE")
    dlg.setMaintainer("Richard Dale", "Richard_Dale@tipitina.demon.co.uk", "http://developer.kde.org/language-bindings/ruby/",\
                    "\n\nKorundum -- Ruby bindings\n\tfor KDE")
    dlg.addContributor("KDE bindings list", "kde-bindings@kde.org", nil, nil)

    dlg.show()
end


def UIDialogs.dlgKBugReport(parent)
    dlg = KDE::BugReport.new(parent)
    dlg.exec()
end

def UIDialogs.dlgTDEAboutKDE(parent)
    dlg = KDE::AboutKDE.new(parent, "about kde", false)
    dlg.show()
end

def UIDialogs.dlgKColorDialog(parent)
    dlg = KDE::ColorDialog.new(parent, "color dlg", false)
    dlg.show()
end

def UIDialogs.dlgKDialog(parent)
    dlg = CustomDlg.new(parent)
    dlg.show()
end

def UIDialogs.dlgKDialogBase(parent)
    caption = "KDialogBase sample"
    text_ = "This is a KDialogBase example"
    dlg =   KDE::DialogBase.new(parent, "sample_dialog", false, caption,
            KDE::DialogBase::Ok | KDE::DialogBase::Cancel, KDE::DialogBase::Ok, true )

    page  = dlg.makeVBoxMainWidget();

    # making 'page' the parent inserts the widgets in
    # the VBox created above
    label = TQt::Label.new( caption, page, "caption" );

    lineedit = TQt::LineEdit.new(text_, page, "lineedit" );
    lineedit.setMinimumWidth(dlg.fontMetrics().maxWidth()*20);

    label0 = TQt::Label.new("Border widths", page)
#    widths = dlg.getBorderWidths()
#    labelA = TQt::Label.new("Upper Left X: " + widths[0].to_s, page)
#    labelB = TQt::Label.new("Upper Left Y: " + widths[0].to_s, page)
#    labelC = TQt::Label.new("Lower Right X: " + str(c), page)
#    labelD = TQt::Label.new("Lower Right Y: " + str(d), page)

    dlg.show()
end

def UIDialogs.dlgTDEFontDialog(parent)
    dlg = KDE::FontDialog.new(parent, "font dlg", false, false)
    dlg.show()
end

def UIDialogs.dlgKKeyDialog(parent)
    # This really doesn't do anything except pop up the dlg
    keys = KDE::Accel.new(parent)
#    keys.insertItem( i18n( "Zoom in" ), "Zoom in", "+" )
    keys.readSettings();
    KDE::KeyDialog.configure(keys, true)
end

def UIDialogs.dlgKInputDialog(parent)
	ok = TQt::Boolean.new
    result = KDE::InputDialog.getText("Enter text", "", "<Your input here>", ok)
#    puts "result: %s" % result
#    puts "ok: %s" % ok

    # pop up another dlg to show what happened in the KDE::LineEditDlg
    if !ok.nil?
        KDE::MessageBox.information(parent, "OK was pressed\nText: " + result, "KDE::InputDialog result")
    else
        KDE::MessageBox.information(parent, "Cancel pressed\nText", "KDE::InputDialog result")
	end
end

def UIDialogs.dlgKMessageBox(parent)
    dlg = MessageDlg.new(parent)
    dlg.show()
end

def UIDialogs.dlgKPasswordDialog(parent)
	password = ""
    result = KDE::PasswordDialog.getPassword(password, "Enter password(just a test)")
	puts "password: #{password}"
end

def UIDialogs.dlgKWizard(parent)
    wiz = KDE::Wizard.new(parent)

    page1 = TQt::Widget.new(wiz)
    p1Lbl = TQt::Label.new("This is page 1", page1)
    p1Lbl.setGeometry(20, 20, 100, 20)
    page2 = TQt::Widget.new(wiz)
    p2Lbl = TQt::Label.new("This is page 2", page2)
    p2Lbl.setGeometry(50, 20, 100, 20)
    page3 = TQt::Widget.new(wiz)
    p3Lbl = TQt::Label.new("This is page 3", page3)
    p3Lbl.setGeometry(80, 20, 100, 20)

    wiz.addPage(page1, "Page 1")
    wiz.addPage(page2, "Page 2")
    wiz.addPage(page3, "Page 3")
    wiz.show()
end

if $0 == __FILE__
    puts
    puts "Please run uisampler.rb"
    puts
end

end
