1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/doc/tutorial2.doc:13 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>chart/optionsform.cpp Example File</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>chart/optionsform.cpp Example File</h1>
|
---|
33 |
|
---|
34 |
|
---|
35 | <pre>#include "optionsform.h"
|
---|
36 |
|
---|
37 | #include <<a href="qbuttongroup-h.html">qbuttongroup.h</a>>
|
---|
38 | #include <<a href="qcombobox-h.html">qcombobox.h</a>>
|
---|
39 | #include <<a href="qfontdialog-h.html">qfontdialog.h</a>>
|
---|
40 | #include <<a href="qframe-h.html">qframe.h</a>>
|
---|
41 | #include <<a href="qimage-h.html">qimage.h</a>>
|
---|
42 | #include <<a href="qlabel-h.html">qlabel.h</a>>
|
---|
43 | #include <<a href="qlayout-h.html">qlayout.h</a>>
|
---|
44 | #include <<a href="qpushbutton-h.html">qpushbutton.h</a>>
|
---|
45 | #include <<a href="qradiobutton-h.html">qradiobutton.h</a>>
|
---|
46 | #include <<a href="qspinbox-h.html">qspinbox.h</a>>
|
---|
47 |
|
---|
48 | #include "images/options_horizontalbarchart.xpm"
|
---|
49 | #include "images/options_piechart.xpm"
|
---|
50 | #include "images/options_verticalbarchart.xpm"
|
---|
51 |
|
---|
52 |
|
---|
53 | <a name="f176"></a>OptionsForm::OptionsForm( <a href="qwidget.html">QWidget</a>* parent, const char* name,
|
---|
54 | bool modal, WFlags f )
|
---|
55 | : <a href="qdialog.html">QDialog</a>( parent, name, modal, f )
|
---|
56 | {
|
---|
57 | <a href="qwidget.html#setCaption">setCaption</a>( "Chart -- Options" );
|
---|
58 | <a href="qwidget.html#resize">resize</a>( 320, 290 );
|
---|
59 |
|
---|
60 | optionsFormLayout = new <a href="qvboxlayout.html">QVBoxLayout</a>( this, 11, 6 );
|
---|
61 |
|
---|
62 | chartTypeLayout = new <a href="qhboxlayout.html">QHBoxLayout</a>( 0, 0, 6 );
|
---|
63 |
|
---|
64 | chartTypeTextLabel = new <a href="qlabel.html">QLabel</a>( "&Chart Type", this );
|
---|
65 | chartTypeLayout-><a href="qboxlayout.html#addWidget">addWidget</a>( chartTypeTextLabel );
|
---|
66 |
|
---|
67 | chartTypeComboBox = new <a href="qcombobox.html">QComboBox</a>( FALSE, this );
|
---|
68 | chartTypeComboBox-><a href="qcombobox.html#insertItem">insertItem</a>( QPixmap( options_piechart ), "Pie Chart" );
|
---|
69 | chartTypeComboBox-><a href="qcombobox.html#insertItem">insertItem</a>( QPixmap( options_verticalbarchart ),
|
---|
70 | "Vertical Bar Chart" );
|
---|
71 | chartTypeComboBox-><a href="qcombobox.html#insertItem">insertItem</a>( QPixmap( options_horizontalbarchart ),
|
---|
72 | "Horizontal Bar Chart" );
|
---|
73 | chartTypeLayout-><a href="qboxlayout.html#addWidget">addWidget</a>( chartTypeComboBox );
|
---|
74 | optionsFormLayout-><a href="qboxlayout.html#addLayout">addLayout</a>( chartTypeLayout );
|
---|
75 |
|
---|
76 | fontLayout = new <a href="qhboxlayout.html">QHBoxLayout</a>( 0, 0, 6 );
|
---|
77 |
|
---|
78 | fontPushButton = new <a href="qpushbutton.html">QPushButton</a>( "&Font...", this );
|
---|
79 | fontLayout-><a href="qboxlayout.html#addWidget">addWidget</a>( fontPushButton );
|
---|
80 | <a href="qspaceritem.html">QSpacerItem</a>* spacer = new <a href="qspaceritem.html">QSpacerItem</a>( 0, 0,
|
---|
81 | QSizePolicy::Expanding,
|
---|
82 | QSizePolicy::Minimum );
|
---|
83 | fontLayout-><a href="qboxlayout.html#addItem">addItem</a>( spacer );
|
---|
84 |
|
---|
85 | fontTextLabel = new <a href="qlabel.html">QLabel</a>( this ); // Must be set by caller via setFont()
|
---|
86 | fontLayout-><a href="qboxlayout.html#addWidget">addWidget</a>( fontTextLabel );
|
---|
87 | optionsFormLayout-><a href="qboxlayout.html#addLayout">addLayout</a>( fontLayout );
|
---|
88 |
|
---|
89 | addValuesFrame = new <a href="qframe.html">QFrame</a>( this );
|
---|
90 | addValuesFrame-><a href="qframe.html#setFrameShape">setFrameShape</a>( QFrame::StyledPanel );
|
---|
91 | addValuesFrame-><a href="qframe.html#setFrameShadow">setFrameShadow</a>( QFrame::Sunken );
|
---|
92 | addValuesFrameLayout = new <a href="qvboxlayout.html">QVBoxLayout</a>( addValuesFrame, 11, 6 );
|
---|
93 |
|
---|
94 | addValuesButtonGroup = new <a href="qbuttongroup.html">QButtonGroup</a>( "Show Values", addValuesFrame );
|
---|
95 | addValuesButtonGroup-><a href="qgroupbox.html#setColumnLayout">setColumnLayout</a>(0, Qt::Vertical );
|
---|
96 | addValuesButtonGroup-><a href="qwidget.html#layout">layout</a>()->setSpacing( 6 );
|
---|
97 | addValuesButtonGroup-><a href="qwidget.html#layout">layout</a>()->setMargin( 11 );
|
---|
98 | addValuesButtonGroupLayout = new <a href="qvboxlayout.html">QVBoxLayout</a>(
|
---|
99 | addValuesButtonGroup-><a href="qwidget.html#layout">layout</a>() );
|
---|
100 | addValuesButtonGroupLayout-><a href="qlayoutitem.html#setAlignment">setAlignment</a>( Qt::AlignTop );
|
---|
101 |
|
---|
102 | noRadioButton = new <a href="qradiobutton.html">QRadioButton</a>( "&No", addValuesButtonGroup );
|
---|
103 | noRadioButton-><a href="qradiobutton.html#setChecked">setChecked</a>( TRUE );
|
---|
104 | addValuesButtonGroupLayout-><a href="qboxlayout.html#addWidget">addWidget</a>( noRadioButton );
|
---|
105 |
|
---|
106 | yesRadioButton = new <a href="qradiobutton.html">QRadioButton</a>( "&Yes", addValuesButtonGroup );
|
---|
107 | addValuesButtonGroupLayout-><a href="qboxlayout.html#addWidget">addWidget</a>( yesRadioButton );
|
---|
108 |
|
---|
109 | asPercentageRadioButton = new <a href="qradiobutton.html">QRadioButton</a>( "As &Percentage",
|
---|
110 | addValuesButtonGroup );
|
---|
111 | addValuesButtonGroupLayout-><a href="qboxlayout.html#addWidget">addWidget</a>( asPercentageRadioButton );
|
---|
112 | addValuesFrameLayout-><a href="qboxlayout.html#addWidget">addWidget</a>( addValuesButtonGroup );
|
---|
113 |
|
---|
114 | decimalPlacesLayout = new <a href="qhboxlayout.html">QHBoxLayout</a>( 0, 0, 6 );
|
---|
115 |
|
---|
116 | decimalPlacesTextLabel = new <a href="qlabel.html">QLabel</a>( "&Decimal Places", addValuesFrame );
|
---|
117 | decimalPlacesLayout-><a href="qboxlayout.html#addWidget">addWidget</a>( decimalPlacesTextLabel );
|
---|
118 |
|
---|
119 | decimalPlacesSpinBox = new <a href="qspinbox.html">QSpinBox</a>( addValuesFrame );
|
---|
120 | decimalPlacesSpinBox-><a href="qspinbox.html#setMinValue">setMinValue</a>( 0 );
|
---|
121 | decimalPlacesSpinBox-><a href="qspinbox.html#setMaxValue">setMaxValue</a>( 9 );
|
---|
122 | decimalPlacesLayout-><a href="qboxlayout.html#addWidget">addWidget</a>( decimalPlacesSpinBox );
|
---|
123 |
|
---|
124 | addValuesFrameLayout-><a href="qboxlayout.html#addLayout">addLayout</a>( decimalPlacesLayout );
|
---|
125 |
|
---|
126 | optionsFormLayout-><a href="qboxlayout.html#addWidget">addWidget</a>( addValuesFrame );
|
---|
127 |
|
---|
128 | buttonsLayout = new <a href="qhboxlayout.html">QHBoxLayout</a>( 0, 0, 6 );
|
---|
129 | spacer = new <a href="qspaceritem.html">QSpacerItem</a>( 0, 0,
|
---|
130 | QSizePolicy::Expanding, QSizePolicy::Minimum );
|
---|
131 | buttonsLayout-><a href="qboxlayout.html#addItem">addItem</a>( spacer );
|
---|
132 |
|
---|
133 | okPushButton = new <a href="qpushbutton.html">QPushButton</a>( "OK", this );
|
---|
134 | okPushButton-><a href="qpushbutton.html#setDefault">setDefault</a>( TRUE );
|
---|
135 | buttonsLayout-><a href="qboxlayout.html#addWidget">addWidget</a>( okPushButton );
|
---|
136 |
|
---|
137 | cancelPushButton = new <a href="qpushbutton.html">QPushButton</a>( "Cancel", this );
|
---|
138 | buttonsLayout-><a href="qboxlayout.html#addWidget">addWidget</a>( cancelPushButton );
|
---|
139 | optionsFormLayout-><a href="qboxlayout.html#addLayout">addLayout</a>( buttonsLayout );
|
---|
140 |
|
---|
141 | <a href="qobject.html#connect">connect</a>( fontPushButton, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( chooseFont() ) );
|
---|
142 | <a href="qobject.html#connect">connect</a>( okPushButton, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( <a href="qdialog.html#accept">accept</a>() ) );
|
---|
143 | <a href="qobject.html#connect">connect</a>( cancelPushButton, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( <a href="qdialog.html#reject">reject</a>() ) );
|
---|
144 |
|
---|
145 | chartTypeTextLabel-><a href="qlabel.html#setBuddy">setBuddy</a>( chartTypeComboBox );
|
---|
146 | decimalPlacesTextLabel-><a href="qlabel.html#setBuddy">setBuddy</a>( decimalPlacesSpinBox );
|
---|
147 | }
|
---|
148 |
|
---|
149 |
|
---|
150 | void <a name="f177"></a>OptionsForm::chooseFont()
|
---|
151 | {
|
---|
152 | bool ok;
|
---|
153 | <a href="qfont.html">QFont</a> font = QFontDialog::<a href="qfontdialog.html#getFont">getFont</a>( &ok, m_font, this );
|
---|
154 | if ( ok )
|
---|
155 | <a href="qwidget.html#setFont">setFont</a>( font );
|
---|
156 | }
|
---|
157 |
|
---|
158 |
|
---|
159 | void OptionsForm::<a href="qwidget.html#setFont">setFont</a>( <a href="qfont.html">QFont</a> font )
|
---|
160 | {
|
---|
161 | <a href="qstring.html">QString</a> label = font.<a href="qfont.html#family">family</a>() + " " +
|
---|
162 | QString::<a href="qstring.html#number">number</a>( font.<a href="qfont.html#pointSize">pointSize</a>() ) + "pt";
|
---|
163 | if ( font.<a href="qfont.html#bold">bold</a>() )
|
---|
164 | label += " Bold";
|
---|
165 | if ( font.<a href="qfont.html#italic">italic</a>() )
|
---|
166 | label += " Italic";
|
---|
167 | fontTextLabel-><a href="qlabel.html#setText">setText</a>( label );
|
---|
168 | m_font = font;
|
---|
169 | }
|
---|
170 | </pre><!-- eof -->
|
---|
171 | <p><address><hr><div align=center>
|
---|
172 | <table width=100% cellspacing=0 border=0><tr>
|
---|
173 | <td>Copyright © 2007
|
---|
174 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
175 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
176 | </table></div></address></body>
|
---|
177 | </html>
|
---|