![]() |
|
| Lab 12: An Intro to GUI Programming | |
|
A demo of compiling and running the canvasdemo program referenced below, with the addition of a magenta "hello world" text being draw along with the polygon and quarter-ellipse it already draws. A demo of the first three requirements listed for this lab's program. This lab is a basic introduction to GUI programming. A windowed, GUI program always uses some underlying toolkit that implements all the different interaction choices. On Unix, the base windowing layer is the X windowing system and associated X toolkit, but there are many higher-level toolkits on top of this. One popular toolkit is Qt ( http://www.trolltech.com/products/index.html). Qt is a commercial product but is also free for open-source free software development. Qt is the foundation for all of KDE and its applications. Qt is a C++ toolkit, unlike many older toolkits (such as Gtk) which are based on pure C. In this lab we will do a very basic Qt application. GUI toolkits are generally among the most complex libraries to use. They usually have very deep and inter-related class hierarchies, and use advanced C++ features heavily. It would literally take years to become proficient in all of Qt's abilities. For this lab, you need to create a program that reads in a file that contains a list of point pairs (each representing a line segment) and draws the lines on a canvas. Your program should have:
In addition, for extra credit, try doing: Each of the extra credit items is worth 2pts. The input file should have 4 integers per line, being the X and Y coordinates of each line endpoint, in the order of "X1 Y1 X2 Y2". Here is a sample program that draws on a canvas. It also demonstrates calling a file chooser dialog, and creating and using a button. To compile it into an executable takes two steps: moc canvasdemo.cpp > canvasdemo.moc g++ -I/usr/lib/qt/include/ -I. canvasdemo.cpp -L/usr/lib/qt/lib -lq The executables (including moc) are contained in /usr/lib/qt3/bin. Qt implements some extra-language features -- by that I mean it "extends" C++ with some features, mainly "signals" and "slots" which are used to cause an event (a signal) and send the event to a class method (a slot). Qt translates these features into C++ using the "meta-object compiler", or moc. If you look at the source file, you will see an include directive that include's the output of this command. You can find extensive Qt documentation locally by running /usr/lib/qt3/bin/assistant and online at trolltech.com. NOTE: You will probably have to cut and paste the local file-based URL into the browser's URL textfield -- security control in the browser won't let you click on a file URL from an HTTP URL. (this goes for the links below, too) The parts of the documentation that will be most helpful are the first three overviews: the object model; signals and slots; and window geometry. Also the description of the Canvas Module (including the Canvas Items), and the initial examples in Tutorial 1, Submit the source code and a Makefile that compiles your program into an executable named "prog12". You should not submit the MOC file, but have the Makefile generate it. Design quality, code quality, and documentation quality will, as always, play a part in your grade for this assignment. |