CS-321 Lab 3
Introduction to the Graphics Shell


Course Objectives Addressed

Overview

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:

Preliminary activity: Shell Library Set Up

Follow these instructions to download and build the shell on your Linux workstation:

Lab Activity

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:

Since you are inheriting Lab3DerivedShell from Shell, the overridden Draw method of Lab3DerivedShell is activated whenever any event occurs in the drawing window. (The Draw method is analogous to an Java ActionListener which subscribes to many events). This includes button presses and motions of the mouse, resizing, and exposures (when any part of the window is suddenly uncovered). The source of the various events is passed to the Draw method via the QEvent parameter.

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:

Demonstration (during Lab 4)

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.

UML Class and Sequence Diagrams

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.

Lab submission (due by 11am day of lab 4)

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:
  1. I want only your .cpp, .h, .pro, and Word report files.
  2. Use webCT to submit your assignment ("Lab 3: Introduction to the Graphics Shell").
  3. Record the time (in minutes) you spent on this lab in the FAST system for week 4.
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 quality Report quality

If 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 09/29/2006.