Object Oriented Programming and Data Structures
Spring Semester 2013
 
Paint

Project 1: Paint

Assigned : Feb 11
Due : Mar 8

 

Quick Links

  1. Displaying X applications to PC running Xwin32
  2. Sample solution (Only runs on Linux)
  3. Icon BMP files for the project
  4. Qt all class
  5. Qt Designer
  6. Marking scheme

Project Description

In this assignment, you will implement a (simplified) "Paint" for drawing based on the solution of lab 5, "Bitmaps and mouse click events". You will use object-oriented technique to implement "Paint". After this project, you are expected to learn how to develop a Qt GUI program and look for materials by yourself from the Qt API Reference.

About Qt

Qt is a multiplatform C++ GUI toolkit created and maintained byTrolltech. It provides application developers with all the functionality needed to build applications with state-of-the-art graphical user interfaces. Qt is fully object-oriented, easily extensible, and allows true component programming.

Qt is supported on the following platforms:

MS/Windows -- 95, 98, NT 4.0, ME, 2000, and XP
Unix/X11 -- Linux, Sun Solaris, HP-UX, Compaq Tru64 UNIX, IBM AIX, SGI IRIX and a wide range of others
Macintosh -- Mac OS X
Embedded -- Linux platforms with framebuffer support.
Qt is released in different editions:

The Qt Free Edition is available for Unix/X11, Macintosh and Embedded Linux. The Free Edition is for the development of Free and Open Source software only.

To use Qt, you need to inherit the classes of Qt for your application.

Project Requirement

Create a menu bar that support the following functions:

--Create a new image
--Load a bitmap file
--Save current image as bitmap file
--Allow user to choose Foreground and Background color
--Support 1 level undo and redo
--Clear the image
--Allow user to resize the image
--Display the toolbar

Create a tool bar that contains shortcuts of tools. You need to inherit from Qt::QToolBar to implement your own toolbar and handle the event when the toolbar is redraw.

Overload the following mouse event handler to handle the corresponding mouse events:

//Left click: Drawing, Right Click: popup the properties dialog of current tool
void mousePressEvent (QMouseEvent *);

//Draw the image when user dragging the mouse after Left Click
void mouseMoveEvent (QMouseEvent *);

//Confirm the drawing
void mouseReleaseEvent (QMouseEvent *);

//For terminate the drawing of polyline
void mouseDoubleClickEvent(QMouseEvent *);

To draw on an image, you need to see the API of QPainter, QPen, QBrush and QPixmap. Note the differences between drawing on a widget and an image.

There are four kinds of tools: Pen, Line, Eraser and Rectangle. For each kind of tools, create a properties dialog that allow user to modify the properties of tool. You need to inherit from QDialog to implement your own dialog, and use QRadioButton, QButtonGroup and QSlider to implement the slider and button.

If you are using QT designer for implementation, please choose 2 of the following to implement:

  1. Multiple level undo and redo. (Hint: Use STL)
  2. Display the status bar, which tracks the mouse position and display them here
  3. Implement the scroll bar
  4. Implement the function Zoom in and Zoom out
  5. Implement a mean filter and median filter.

If you have any difficulties in understanding the project requirement, please see the sample solution.

Hints

  1. Think carefully before implementation.
  2. Use QPixmap to store the image
  3. Implement a dialog for each kind of tools separately, each dialog should contains its own attribute, e.g.QPen(QBrush) for drawing.
  4. Understand the coordinate system of Qt, (0,0) represent the top left cornor. The coordinate system between QPixmap and QWidget is different. Usually, you need to subtract the height of menu bar and tool bar to get the correct coordinates for drawing.
  5. Use two QPixmap variables for implement "undo" and "redo"
  6. See the example code in Qt API if you still have difficulties in understanding the Qt API
  7. Beware of syntax and logical errors.
  8. Thoroughly test and fix all the bugs before submission.

Grading Scheme

A main objective of this course is to learn and practise good design principles so that you can eventually write very large programs comfortably and professionally. As such, you should not just turn in a program that works.You are expected to have a good design too so that your program is comprehensible and can be extended easily in case the specification changes later.Whether you like it or not, it is a fact in life that user requirements keep changing while a program is being developed.Your design should be flexible enough to cater for such possibilities.You should describe your design clearly in a separate file, named README.txt.

As it is always the case, you should use meaningful identifier names in your program so that other people can understand your code easily.You are also expected to break your program into functionally distinct pieces kept in different files, with the C++ source files compiled separately.Brief yet informative comments should be added throughout the program to improve its comprehensibility.

The grading scheme is as follows:

  • Program correctness in satisfying specification (85%)
  • Object-oriented programming style and use of separate compilation (10%)
  • Documentation and comprehensibility (5%)

What to submit

  1. All the source code (.cpp and .h), but not the object code or executable
  2. Makefile and README.txt
  3. Zip (1) and (2) inside a file called paint.zip and upload the file to CASS before 23:59 on the due date. Warning: If your submitted project fails to compile, your assignment will be treated as late (late policy will apply).
   design by Yu Wing TAI, maintenance by Chi Keung Tang. CS 2012h Object Oriented Programming and Data Structures
Spring Semester 2013
 
 
  Last modified: Fri Feb 4 17:15:19 HKT 2013