31.12.2014 Views

Paskaitų konspektai - Matematikos ir Informatikos fakultetas ...

Paskaitų konspektai - Matematikos ir Informatikos fakultetas ...

Paskaitų konspektai - Matematikos ir Informatikos fakultetas ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Screen::Screen(QWidget* parent, const char* name)<br />

: QWidget(parent, name)<br />

{<br />

c<strong>ir</strong>cle = new C<strong>ir</strong>cle(150, 100, 50);<br />

rectangle = new Rectangle(250, 50, 400, 100);<br />

tree = new Composite();<br />

tree->addShape(new Rectangle(600, 300, 20, 200));<br />

tree->addShape(new C<strong>ir</strong>cle(610, 250, 50));<br />

Composite* tailAndHead = new Composite();<br />

tailAndHead->addShape(new Rectangle(100, 380, 20, 20));<br />

tailAndHead->addShape(new C<strong>ir</strong>cle(280, 350, 50));<br />

}<br />

dog = new Composite();<br />

dog->addShape(new Rectangle(100, 400, 200, 20));<br />

dog->addShape(new Rectangle(100, 420, 20, 40));<br />

dog->addShape(new Rectangle(280, 420, 20, 40));<br />

dog->addShape(tailAndHead);<br />

Schematiškai objektus gal÷tume pavaizduoti taip:<br />

c<strong>ir</strong>cle<br />

rectangle<br />

tailAndHead<br />

tree<br />

dog<br />

Dar aprašykime dvi globalias funkcijas, kurių p<strong>ir</strong>moje piešia perstumtą figūrą, o<br />

antroji piešia punktyrinį r÷melį apie figūrą:<br />

void paintMoved (QPainter* p, Shape* shape, int dx, int dy)<br />

{<br />

shape->setLocation(shape->getX()+dx, shape->getY()+dy);<br />

shape->paint(p);<br />

shape->setLocation(shape->getX()-dx, shape->getY()-dy);<br />

}<br />

void paintBorder (QPainter* p, Shape* shape)<br />

{<br />

int x = shape->getX();<br />

int y = shape->getY();<br />

int w = shape->getWidth();<br />

int h = shape->getHeight();<br />

p->setPen(Qt::DotLine);<br />

p->drawRect(x-2, y-2, w+4, h+4);<br />

p->setPen(Qt::SolidLine);<br />

}<br />

100

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!