diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-11-08 12:31:36 -0600 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-11-08 12:31:36 -0600 |
commit | d796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch) | |
tree | 6e3dcca4f77e20ec8966c666aac7c35bd4704053 /tools/designer/examples/metric | |
download | tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip |
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'tools/designer/examples/metric')
-rw-r--r-- | tools/designer/examples/metric/main.cpp | 12 | ||||
-rw-r--r-- | tools/designer/examples/metric/metric.pro | 12 | ||||
-rw-r--r-- | tools/designer/examples/metric/metric.ui | 366 | ||||
-rw-r--r-- | tools/designer/examples/metric/metric.ui.h | 72 |
4 files changed, 462 insertions, 0 deletions
diff --git a/tools/designer/examples/metric/main.cpp b/tools/designer/examples/metric/main.cpp new file mode 100644 index 000000000..d7a20ab40 --- /dev/null +++ b/tools/designer/examples/metric/main.cpp @@ -0,0 +1,12 @@ +#include <qapplication.h> +#include "metric.h" + +int main( int argc, char ** argv ) +{ + TQApplication a( argc, argv ); + ConversionForm *w = new ConversionForm; + w->show(); + a.setMainWidget( w ); + a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( tquit() ) ); + return a.exec(); +} diff --git a/tools/designer/examples/metric/metric.pro b/tools/designer/examples/metric/metric.pro new file mode 100644 index 000000000..3dfc3fd6a --- /dev/null +++ b/tools/designer/examples/metric/metric.pro @@ -0,0 +1,12 @@ +TEMPLATE = app +LANGUAGE = C++ + +SOURCES += main.cpp +unix { + UI_DIR = .ui + MOC_DIR = .moc + OBJECTS_DIR = .obj +} +FORMS = metric.ui +CONFIG += qt warn_on release +DBFILE = metric.db diff --git a/tools/designer/examples/metric/metric.ui b/tools/designer/examples/metric/metric.ui new file mode 100644 index 000000000..aba8c2ef0 --- /dev/null +++ b/tools/designer/examples/metric/metric.ui @@ -0,0 +1,366 @@ +<!DOCTYPE UI><UI version="3.1" stdsetdef="1"> +<class>ConversionForm</class> +<widget class="TQDialog"> + <property name="name"> + <cstring>ConversionForm</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>320</width> + <height>217</height> + </rect> + </property> + <property name="caption"> + <string>Metric Conversion</string> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQLayoutWidget"> + <property name="name"> + <cstring>Layout4</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQLayoutWidget" row="4" column="1"> + <property name="name"> + <cstring>Layout3</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>Spacer3</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>0</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="TQSpinBox"> + <property name="name"> + <cstring>decimalsSpinBox</cstring> + </property> + <property name="maxValue"> + <number>6</number> + </property> + <property name="value"> + <number>3</number> + </property> + </widget> + </hbox> + </widget> + <widget class="TQComboBox" row="1" column="1"> + <item> + <property name="text"> + <string>Kilometers</string> + </property> + </item> + <item> + <property name="text"> + <string>Meters</string> + </property> + </item> + <item> + <property name="text"> + <string>Centimeters</string> + </property> + </item> + <item> + <property name="text"> + <string>Millimeters</string> + </property> + </item> + <property name="name"> + <cstring>fromComboBox</cstring> + </property> + </widget> + <widget class="TQLabel" row="3" column="0"> + <property name="name"> + <cstring>TextLabel4</cstring> + </property> + <property name="text"> + <string>Result:</string> + </property> + </widget> + <widget class="TQLabel" row="1" column="0"> + <property name="name"> + <cstring>TextLabel2</cstring> + </property> + <property name="text"> + <string>Convert &From:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>fromComboBox</cstring> + </property> + </widget> + <widget class="TQLabel" row="2" column="0"> + <property name="name"> + <cstring>TextLabel3</cstring> + </property> + <property name="text"> + <string>Convert &To:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>toComboBox</cstring> + </property> + </widget> + <widget class="TQLabel" row="4" column="0"> + <property name="name"> + <cstring>TextLabel1_2</cstring> + </property> + <property name="text"> + <string>&Decimals:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>decimalsSpinBox</cstring> + </property> + </widget> + <widget class="TQLabel" row="0" column="0"> + <property name="name"> + <cstring>TextLabel1</cstring> + </property> + <property name="text"> + <string>Enter &Number:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>numberLineEdit</cstring> + </property> + </widget> + <widget class="TQLabel" row="3" column="1"> + <property name="name"> + <cstring>resultLineEdit</cstring> + </property> + <property name="paletteBackgroundColor"> + <color> + <red>255</red> + <green>255</green> + <blue>0</blue> + </color> + </property> + <property name="font"> + <font> + <bold>1</bold> + </font> + </property> + <property name="frameShape"> + <enum>WinPanel</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="text"> + <string></string> + </property> + <property name="alignment"> + <set>AlignVCenter|AlignRight</set> + </property> + </widget> + <widget class="TQLineEdit" row="0" column="1"> + <property name="name"> + <cstring>numberLineEdit</cstring> + </property> + <property name="font"> + <font> + <bold>1</bold> + </font> + </property> + <property name="alignment"> + <set>AlignRight</set> + </property> + </widget> + <widget class="TQComboBox" row="2" column="1"> + <item> + <property name="text"> + <string>Miles</string> + </property> + </item> + <item> + <property name="text"> + <string>Yards</string> + </property> + </item> + <item> + <property name="text"> + <string>Feet</string> + </property> + </item> + <item> + <property name="text"> + <string>Inches</string> + </property> + </item> + <property name="name"> + <cstring>toComboBox</cstring> + </property> + </widget> + </grid> + </widget> + <spacer> + <property name="name"> + <cstring>Spacer2</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>0</height> + </size> + </property> + </spacer> + <widget class="TQLayoutWidget"> + <property name="name"> + <cstring>Layout3</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQPushButton"> + <property name="name"> + <cstring>clearButton</cstring> + </property> + <property name="text"> + <string>&Clear</string> + </property> + </widget> + <widget class="TQPushButton"> + <property name="name"> + <cstring>calculateButton</cstring> + </property> + <property name="text"> + <string>Calculate</string> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>Spacer27</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>0</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="TQPushButton"> + <property name="name"> + <cstring>tquitButton</cstring> + </property> + <property name="text"> + <string>&Quit</string> + </property> + </widget> + </hbox> + </widget> + </vbox> +</widget> +<connections> + <connection> + <sender>clearButton</sender> + <signal>clicked()</signal> + <receiver>numberLineEdit</receiver> + <slot>clear()</slot> + </connection> + <connection> + <sender>tquitButton</sender> + <signal>clicked()</signal> + <receiver>ConversionForm</receiver> + <slot>close()</slot> + </connection> + <connection> + <sender>calculateButton</sender> + <signal>clicked()</signal> + <receiver>ConversionForm</receiver> + <slot>convert()</slot> + </connection> + <connection> + <sender>clearButton</sender> + <signal>clicked()</signal> + <receiver>resultLineEdit</receiver> + <slot>clear()</slot> + </connection> + <connection> + <sender>decimalsSpinBox</sender> + <signal>valueChanged(int)</signal> + <receiver>ConversionForm</receiver> + <slot>convert()</slot> + </connection> + <connection> + <sender>fromComboBox</sender> + <signal>activated(int)</signal> + <receiver>ConversionForm</receiver> + <slot>convert()</slot> + </connection> + <connection> + <sender>toComboBox</sender> + <signal>activated(int)</signal> + <receiver>ConversionForm</receiver> + <slot>convert()</slot> + </connection> + <connection> + <sender>clearButton</sender> + <signal>released()</signal> + <receiver>numberLineEdit</receiver> + <slot>setFocus()</slot> + </connection> + <connection> + <sender>calculateButton</sender> + <signal>clicked()</signal> + <receiver>numberLineEdit</receiver> + <slot>setFocus()</slot> + </connection> +</connections> +<tabstops> + <tabstop>numberLineEdit</tabstop> + <tabstop>fromComboBox</tabstop> + <tabstop>toComboBox</tabstop> + <tabstop>decimalsSpinBox</tabstop> + <tabstop>clearButton</tabstop> + <tabstop>calculateButton</tabstop> + <tabstop>tquitButton</tabstop> +</tabstops> +<includes> + <include location="local" impldecl="in implementation">metric.ui.h</include> +</includes> +<slots> + <slot>convert()</slot> +</slots> +<functions> + <function access="private">init()</function> +</functions> +<pixmapinproject/> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/tools/designer/examples/metric/metric.ui.h b/tools/designer/examples/metric/metric.ui.h new file mode 100644 index 000000000..7d9db780a --- /dev/null +++ b/tools/designer/examples/metric/metric.ui.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** ui.h extension file, included from the uic-generated form implementation. +** +** If you wish to add, delete or rename functions respectively slots use +** TQt Designer which will update this file, preserving your code. Create an +** init() function in place of a constructor, and a destroy() function in +** place of a destructor. +*****************************************************************************/ + +#include <qvalidator.h> + +void ConversionForm::init() +{ + numberLineEdit->setValidator( new TQDoubleValidator( numberLineEdit ) ); + numberLineEdit->setText( "10" ); + convert(); + numberLineEdit->selectAll(); +} + +void ConversionForm::convert() +{ + enum MetricUnits { + Kilometers, + Meters, + Centimeters, + Millimeters + }; + enum OldUnits { + Miles, + Yards, + Feet, + Inches + }; + + // Retrieve the input + double input = numberLineEdit->text().toDouble(); + double scaledInput = input; + + // internally convert the input to millimeters + switch ( fromComboBox->currentItem() ) { + case Kilometers: + scaledInput *= 1000000; + break; + case Meters: + scaledInput *= 1000; + break; + case Centimeters: + scaledInput *= 10; + break; + } + + //convert to inches + double result = scaledInput * 0.0393701; + + switch ( toComboBox->currentItem() ) { + case Miles: + result /= 63360; + break; + case Yards: + result /= 36; + break; + case Feet: + result /= 12; + break; + } + + // set the result + int decimals = decimalsSpinBox->value(); + resultLineEdit->setText( TQString::number( result, 'f', decimals ) ); + numberLineEdit->setText( TQString::number( input, 'f', decimals ) ); +} + |