summaryrefslogtreecommitdiffstats
path: root/qtruby/rubylib/examples/qt-examples/chart/optionsform.rb
blob: 6b2eeac49f00cbe4976c61e768fdd789e5cfd9ac (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 < Qt::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 = Qt::VBoxLayout.new( self, 11, 6 )
    
        @chartTypeLayout = Qt::HBoxLayout.new( nil, 0, 6 )
    
        @chartTypeTextLabel = Qt::Label.new( "&Chart Type", self )
        @chartTypeLayout.addWidget( @chartTypeTextLabel )
    
        @chartTypeComboBox = Qt::ComboBox.new( false, self )
        @chartTypeComboBox.insertItem( Qt::Pixmap.new( "images/options_piechart.xpm" ), "Pie Chart" )
        @chartTypeComboBox.insertItem( Qt::Pixmap.new( "images/options_verticalbarchart.xpm" ),
                                    "Vertical Bar Chart" )
        @chartTypeComboBox.insertItem( Qt::Pixmap.new( "images/options_horizontalbarchart.xpm" ),
                                    "Horizontal Bar Chart" )
        @chartTypeLayout.addWidget( @chartTypeComboBox )
        @optionsFormLayout.addLayout( @chartTypeLayout )
    
        @fontLayout = Qt::HBoxLayout.new( nil, 0, 6 )
    
        @fontPushButton = Qt::PushButton.new( "&Font...", self )
        @fontLayout.addWidget( @fontPushButton )
        @spacer = Qt::SpacerItem.new( 0, 0, Qt::SizePolicy::Expanding,
                                            Qt::SizePolicy::Minimum )
        @fontLayout.addItem( @spacer )
    
        @fontTextLabel = Qt::Label.new( self ) # Must be set by caller via setFont()
        @fontLayout.addWidget( @fontTextLabel )
        @optionsFormLayout.addLayout( @fontLayout )
    
        @addValuesFrame = Qt::Frame.new( self )
        @addValuesFrame.setFrameShape( Qt::Frame::StyledPanel )
        @addValuesFrame.setFrameShadow( Qt::Frame::Sunken )
        @addValuesFrameLayout = Qt::VBoxLayout.new( @addValuesFrame, 11, 6 )
    
        @addValuesButtonGroup = Qt::ButtonGroup.new( "Show Values", @addValuesFrame )
        @addValuesButtonGroup.setColumnLayout(0, Qt::Vertical )
        @addValuesButtonGroup.layout().setSpacing( 6 )
        @addValuesButtonGroup.layout().setMargin( 11 )
        @addValuesButtonGroupLayout = Qt::VBoxLayout.new(
                                            @addValuesButtonGroup.layout() )
        @addValuesButtonGroupLayout.setAlignment( Qt::AlignTop )
    
        @noRadioButton = Qt::RadioButton.new( "&No", @addValuesButtonGroup )
        @noRadioButton.setChecked( true )
        @addValuesButtonGroupLayout.addWidget( @noRadioButton )
    
        @yesRadioButton = Qt::RadioButton.new( "&Yes", @addValuesButtonGroup )
        @addValuesButtonGroupLayout.addWidget( 	@yesRadioButton )
    
        @asPercentageRadioButton = Qt::RadioButton.new( "As &Percentage",
                                                    @addValuesButtonGroup )
        @addValuesButtonGroupLayout.addWidget( @asPercentageRadioButton )
        @addValuesFrameLayout.addWidget( @addValuesButtonGroup )
    
        @decimalPlacesLayout = Qt::HBoxLayout.new( nil, 0, 6 )
    
        @decimalPlacesTextLabel = Qt::Label.new( "&Decimal Places", @addValuesFrame )
        @decimalPlacesLayout.addWidget( @decimalPlacesTextLabel )
    
        @decimalPlacesSpinBox = Qt::SpinBox.new( @addValuesFrame )
        @decimalPlacesSpinBox.setMinValue( 0 )
        @decimalPlacesSpinBox.setMaxValue( 9 )
        @decimalPlacesLayout.addWidget( @decimalPlacesSpinBox )
    
        @addValuesFrameLayout.addLayout( @decimalPlacesLayout )
    
        @optionsFormLayout.addWidget( @addValuesFrame )
    
        @buttonsLayout = Qt::HBoxLayout.new( nil, 0, 6 )
        @spacer = Qt::SpacerItem.new( 0, 0,
                                Qt::SizePolicy::Expanding, Qt::SizePolicy::Minimum )
        @buttonsLayout.addItem( @spacer )
    
        @okPushButton = Qt::PushButton.new( "OK", self )
        @okPushButton.setDefault( true )
        @buttonsLayout.addWidget( @okPushButton )
    
        @cancelPushButton = Qt::PushButton.new( "Cancel", self )
        @buttonsLayout.addWidget( @cancelPushButton )
        @optionsFormLayout.addLayout( @buttonsLayout )
    
        connect( @fontPushButton, SIGNAL( 'clicked()' ), self, SLOT( 'chooseFont()' ) )
        connect( @okPushButton, SIGNAL( 'clicked()' ), self, SLOT( 'accept()' ) )
        connect( @cancelPushButton, SIGNAL( 'clicked()' ), self, SLOT( 'reject()' ) )
    
        @chartTypeTextLabel.setBuddy( @chartTypeComboBox )
        @decimalPlacesTextLabel.setBuddy( @decimalPlacesSpinBox )
    end
    
    
    def chooseFont()
        ok = Qt::Boolean.new
        font = Qt::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