summaryrefslogtreecommitdiffstats
path: root/qtruby/rubylib/examples/qt-examples/chart/optionsform.rb
blob: a83fe8284dfc5f3c690edd9defb2725d94a1b300 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
74
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
class OptionsForm < TQt::Dialog
    slots 'chooseFont()'
    
    attr_reader :chartTypeComboBox, 
	:noRadioButton, 
	:yesRadioButton, 
	:asPercentageRadioButton,
	:decimalPlacesSpinBox,
	:font
    
    def initialize( parent = nil, name = "options form",
                            modal = false, f = 0 )
        super( parent, name, modal, f )
        setCaption( "Chart -- Options" )
        resize( 320, 290 )
    
        @optionsFormLayout = TQt::VBoxLayout.new( self, 11, 6 )
    
        @chartTypeLayout = TQt::HBoxLayout.new( nil, 0, 6 )
    
        @chartTypeTextLabel = TQt::Label.new( "&Chart Type", self )
        @chartTypeLayout.addWidget( @chartTypeTextLabel )
    
        @chartTypeComboBox = TQt::ComboBox.new( false, self )
        @chartTypeComboBox.insertItem( TQt::Pixmap.new( "images/options_piechart.xpm" ), "Pie Chart" )
        @chartTypeComboBox.insertItem( TQt::Pixmap.new( "images/options_verticalbarchart.xpm" ),
                                    "Vertical Bar Chart" )
        @chartTypeComboBox.insertItem( TQt::Pixmap.new( "images/options_horizontalbarchart.xpm" ),
                                    "Horizontal Bar Chart" )
        @chartTypeLayout.addWidget( @chartTypeComboBox )
        @optionsFormLayout.addLayout( @chartTypeLayout )
    
        @fontLayout = TQt::HBoxLayout.new( nil, 0, 6 )
    
        @fontPushButton = TQt::PushButton.new( "&Font...", self )
        @fontLayout.addWidget( @fontPushButton )
        @spacer = TQt::SpacerItem.new( 0, 0, TQt::SizePolicy::Expanding,
                                            TQt::SizePolicy::Minimum )
        @fontLayout.addItem( @spacer )
    
        @fontTextLabel = TQt::Label.new( self ) # Must be set by caller via setFont()
        @fontLayout.addWidget( @fontTextLabel )
        @optionsFormLayout.addLayout( @fontLayout )
    
        @addValuesFrame = TQt::Frame.new( self )
        @addValuesFrame.setFrameShape( TQt::Frame::StyledPanel )
        @addValuesFrame.setFrameShadow( TQt::Frame::Sunken )
        @addValuesFrameLayout = TQt::VBoxLayout.new( @addValuesFrame, 11, 6 )
    
        @addValuesButtonGroup = TQt::ButtonGroup.new( "Show Values", @addValuesFrame )
        @addValuesButtonGroup.setColumnLayout(0, TQt::Vertical )
        @addValuesButtonGroup.layout().setSpacing( 6 )
        @addValuesButtonGroup.layout().setMargin( 11 )
        @addValuesButtonGroupLayout = TQt::VBoxLayout.new(
                                            @addValuesButtonGroup.layout() )
        @addValuesButtonGroupLayout.setAlignment( TQt::AlignTop )
    
        @noRadioButton = TQt::RadioButton.new( "&No", @addValuesButtonGroup )
        @noRadioButton.setChecked( true )
        @addValuesButtonGroupLayout.addWidget( @noRadioButton )
    
        @yesRadioButton = TQt::RadioButton.new( "&Yes", @addValuesButtonGroup )
        @addValuesButtonGroupLayout.addWidget( 	@yesRadioButton )
    
        @asPercentageRadioButton = TQt::RadioButton.new( "As &Percentage",
                                                    @addValuesButtonGroup )
        @addValuesButtonGroupLayout.addWidget( @asPercentageRadioButton )
        @addValuesFrameLayout.addWidget( @addValuesButtonGroup )
    
        @decimalPlacesLayout = TQt::HBoxLayout.new( nil, 0, 6 )
    
        @decimalPlacesTextLabel = TQt::Label.new( "&Decimal Places", @addValuesFrame )
        @decimalPlacesLayout.addWidget( @decimalPlacesTextLabel )
    
        @decimalPlacesSpinBox = TQt::SpinBox.new( @addValuesFrame )
        @decimalPlacesSpinBox.setMinValue( 0 )
        @decimalPlacesSpinBox.setMaxValue( 9 )
        @decimalPlacesLayout.addWidget( @decimalPlacesSpinBox )
    
        @addValuesFrameLayout.addLayout( @decimalPlacesLayout )
    
        @optionsFormLayout.addWidget( @addValuesFrame )
    
        @buttonsLayout = TQt::HBoxLayout.new( nil, 0, 6 )
        @spacer = TQt::SpacerItem.new( 0, 0,
                                TQt::SizePolicy::Expanding, TQt::SizePolicy::Minimum )
        @buttonsLayout.addItem( @spacer )
    
        @okPushButton = TQt::PushButton.new( "OK", self )
        @okPushButton.setDefault( true )
        @buttonsLayout.addWidget( @okPushButton )
    
        @cancelPushButton = TQt::PushButton.new( "Cancel", self )
        @buttonsLayout.addWidget( @cancelPushButton )
        @optionsFormLayout.addLayout( @buttonsLayout )
    
        connect( @fontPushButton, TQ_SIGNAL( 'clicked()' ), self, TQ_SLOT( 'chooseFont()' ) )
        connect( @okPushButton, TQ_SIGNAL( 'clicked()' ), self, TQ_SLOT( 'accept()' ) )
        connect( @cancelPushButton, TQ_SIGNAL( 'clicked()' ), self, TQ_SLOT( 'reject()' ) )
    
        @chartTypeTextLabel.setBuddy( @chartTypeComboBox )
        @decimalPlacesTextLabel.setBuddy( @decimalPlacesSpinBox )
    end
    
    
    def chooseFont()
        ok = TQt::Boolean.new
        font = TQt::FontDialog.getFont( ok, @font, self )
        if !ok.nil?
            setFont( font )
        end
    end
    
    
    def font=( font )
        label = font.family() + " " + font.pointSize().to_s + "pt"
        if font.bold()
            label += " Bold"
        end
        if font.italic()
            label += " Italic"
        end
        @fontTextLabel.setText( label )
        @font = font
    end

end