CS-321 Lab 4: Lines, Buttons, Color, and Polygons

Overview

In this lab, you will be addressing some of the common issues associated with working in a graphical user interface; specifically adding code to work with buttons. You will also introduce polygons as an additional shape that your program can contain and display. Polygons are a particular case of a class of shapes that exhibit variability in their size (i.e., number of vertices). Bezier curves, which you'll learn about shortly, is a type of curve that uses a variable number of control points in its definition.

Since there are other shapes besides polygons that have a variable number of vertexes, it wouldn't be good to reinvent the wheel (e.g., file reading and writing code) for each one. Therefore, you must derive your Polygon class from another new abstract class you define called VariableShape that encapsulates common elements and behavior of polygons, polylines, Bezier curves, etc.

The VariableShape class must be generic enough to be used later as a base class for other shapes that are similarly defined by a variable number of vertexes or control points. This abstract class should implement the behavior common to all concrete classes derived from it, such as Read, Write, and AddNode. Any derived class, such as Polygon, will still need to implement methods such as constructors, the destructor, and operator=, but it can use the equivalent abstract base class methods to do the actual work. You also need to override Draw and Clone in the derived concrete class.

Here is the UML class diagram illustrating the relationship between the classes:

 

Activities

  1. Continue to ignore the virtual functions from Shell concerning Zoom, Unzoom, and Reset.
     
  2. Review the Qt documentation on both QPushButtons and Signals and Slots.
     
  3. Add three buttons to the mainLayout widget of the Shell in your derived shell class constructor—one to put the Shell in Point drawing mode, one to put the Shell in Line drawing mode, and a third to put it in Polygon drawing mode.
  4. Add a style command to the command parser that allows the user to select one of the 5 Qt PenStyles.
  5. Add a color command to the command line parser that invokes the QColorDialog
  6. After adding the Polygon button to your shell, you must develop a mechanism for specifying polygons using the mouse. It is recommended that you keep the points specified by the user in a container and only create a polygon object and Add() it to your image when the user indicates that the polygon is finished by double-clicking.
  7. For drawing lines, use the QPainter::drawLIne() method. "A" level grade: When a line has a slope 0<m<1, implement Bresenham's algorithm (this is actually pretty easy) to draw the line as a series of points using QPainter::drawPoint(). For other slopes, use drawLine(). This must be done by the 2nd week of lab.
     
  8. Optional (5 pts extra): Add the option (via the command line parser) to choose odd-even or non-zero-winding for the polygon fill.
     
  9. MANDATORY: Commenting source code is an important aspect of software development, whether you're a CE or SE. When you program conditional logic, every if, else, switch, and while should be commented.
  10. MANDATORY: Symbolic constants should be used whenever possible in place of literals. The QT library provides symbolic constants to represent many different types of values (color, for example). QT also defines symbolic constants for events types, such as PAINT. Use symbolic constants rather than literal values in your Draw method (for example) to make it clear (along with comments) what each section of code is used for.

Hints

Demonstrations (during both week 6 and 7 labs)

You will need to demonstrate your modified user interface to me during the week 6 lab meeting. At a minimum, this should include the 3 new buttons you must add (Point, Line and Polygon). When these buttons are pressed, they should minimally put your program into Point or Line drawing mode. You do not have to implement Polygon support during the first week. This milestone must be reached by the week 6 lab; otherwise, late points will begin to incur.

You will need to demonstrate your completed project to me during the week 7 lab meeting.

Lab assignment (due the day of Lab 5)

This is a 2 week lab.

Fix all errors from your previous lab!

Submit your assignment following these instructions:
  1. In addition to your Word report file, I only want:
    Lab3DerivedShell.cpp
    Line.cpp
    VariableShape.cpp
    VariableShape.h
    Polygon.cpp
    Polygon.h
  2. Use webCT to submit your assignment ("Lab 4"). Do not zip the files.
  3. Record the time (in minutes) you spent on this lab in the FAST system for weeks 5 and 6.
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.