// basic Qt drawing template - student defines drawMyPicture function #include #include #include #include #include #include #include #define XBOUND 400 #define YBOUND 400 class mywindow : public QWidget /* a template for a type of window */ { Q_OBJECT private: QPainter * brush; /* an object that can do some graphics */ QPainter * pbrush; // printing QPrinter printer; QPixmap * buffer; int proceed; QMenuBar *menu; QPopupMenu *printop; void drawMyPicture(); // to be defined by student /* a function that Qt expects to be defined */ void paintEvent(QPaintEvent *) { brush->begin(this); // prepares the brush drawMyPicture(); brush->flush(); bitBlt(buffer,0,0,this,0,0,XBOUND,YBOUND); brush->end(); // stops the "brush" session } public slots: void printpic() { proceed = printer.setup(); if (proceed) { // pbrush->setPen(red); pbrush->drawEllipse(10,20,100,100); pbrush->begin(&printer); pbrush->drawPixmap(0,0,*buffer); pbrush->end(); } } public: mywindow() /* constructor for the window template */ { setGeometry(200, 100, XBOUND, YBOUND); /* set position and size of program */ brush = new QPainter; // creates the brush object pbrush = new QPainter; buffer = new QPixmap(XBOUND,YBOUND); menu = new QMenuBar(this); printop = new QPopupMenu(); printop->insertItem("Print Pict", this, SLOT(printpic())); printop->insertItem("quit", qApp, SLOT(quit())); menu->insertItem("file",printop); } }; int main(int argc, char **argv) // main is entry point of entire program { QApplication theprogram(argc, argv); // but the real program is a Qt one mywindow thewindow; // that uses a window! theprogram.setMainWidget(&thewindow); // sets the main window thewindow.show(); // shows and executes the Qt app. theprogram.exec(); return 0; // exits gracefully } #include "drawing.moc"