In this lab, you will be building upon a pre-written graphical user interface class referred to as the shell. It uses Qt (a graphics library) to provide a simple graphical user interface (GUI) with a drawing area, buttons, menu, and command line. Your projects from here on will work within this shell.
The graphics shell replaces the test program you used and extended in Lab 2. Here, you will create a new class (containing a main() function) called Lab3DerivedShell which inherits behavior (virtual methods) from the Shell class. The updated UML static class diagram is as follows:
Follow these instructions to download and build the shell on your Linux workstation:
Become familiar with the various features of the GUI shell and note that it simply generates event-driven callbacks which do little more than cout before returning. ((I.e., there is no functionality yet.)
You do not have to make any modifications at all to the Shell class. Instead, you are to derive a class (Lab3DerivedShell) from the Shell class to add functionality that supports the drawing of white points on the black background of the drawing area using both the built-in command line and the mouse. As a minimum you will need to bring in your Lab 2 classes (NOTE: you will find it necessary to update some of these classes) and, in Lab3DerivedShell, override and add functionality to the following virtual functions of Shell:
Note: It is not (yet) necessary to handle loading and saving, but these features will be required in future labs, so you might want to get a start on them (and you already know how to do this from Lab 2).
When the Lab3DerivedShell::Draw method is called, you must check the source of the event by examining the QEvent. When an "exposure" event such as a paint event comes in, call the Redraw method in your image class. As the calls cascade and the Draw methods of your shape-derived classes get called, you must actually draw the shapes by using methods of the QPainter class. When the drawing window is initially created by the GUI shell it will automatically generate a paint event.
When a "button press" event occurs (actually press or release -- your choice) you will have to use a dynamic_cast to convert the QEvent to a QMouseEvent to determine the mouse information contained therein. After determining the mouse location create a point object and add it to your image and draw it. Note: Upon referencing QPainter you will find that you need a QWidget. The protected drawArea member of the Shell class, which you inherit within your Lab3DerivedShell class, is a QWidget object, so use that.
For the present, ignore the resize event.
Your professor will be more than happy to consult with you on an individual basis, but many of the details are left for you to research on your own.
More information on Qt can be found in the following places:
You will need to demonstrate your project to the instructor during the Lab 4 session. The demonstration will count for 25% of your lab grade.
Extend your UML diagrams from Lab 2 to reflect the changes you make in Lab 3. Use EA to prepare a UML class diagram and a UML sequence diagram.
Your UML static class diagram must replicate the diagram shown above and more fully depict the relationship between the classes you have developed or extended in this lab, as well as any pre-defined classes you use (e.g. QPainter). Specifically, you must change the diagram to accurately reflect
You must create a UML sequence diagram containing enough detail to support the illustration of the interaction among your objects in response to a paint event.
Paste images of your UML Class and Sequence diagrams into your lab report document.
This is a 1 week lab.
You must submit a quality lab report along with your program. Use this Word document as a template for your report, carefully following the instructions within.
Submit your assignment following these instructions:Be sure to keep copies of all your files, in case something gets lost.
Your lab grade will be determined by the following factors:
Program qualityIf you have any questions, consult me.
This lab was originally developed by Prof. Henry Welch,
with modifications by Prof. Eric Durant.
And even more modifications by Prof. Mark Hornick.
This page was last updated on Wednesday 28 February 2007 09/29/2006.