{
bool ret;
d->safeLock(d->paintMutex);
- d->safeLock(d->imageMutex);
-#if 1
- d->dirty(); // xxx
-#else
- QApplication::postEvent(this, new QPaintEvent(this->rect()));
- d->dirtyFlag = false;
-#endif
- d->safeUnlock(d->imageMutex);
+ QApplication::postEvent(this, new QEvent(QEvent::User));
ret = d->paintCondition.wait(&d->paintMutex, time);
d->safeUnlock(d->paintMutex);
return ret;
d->thread->wait();
}
+void DrawingWindow::customEvent(QEvent *)
+{
+ d->imageMutex.lock();
+ if (d->dirtyFlag) {
+ QRect r = d->dirtyRect;
+ d->dirtyFlag = false;
+ d->imageMutex.unlock();
+ repaint(r);
+ } else
+ d->imageMutex.unlock();
+ d->paintMutex.lock();
+ d->paintCondition.wakeAll();
+ d->paintMutex.unlock();
+}
+
+void DrawingWindow::keyPressEvent(QKeyEvent *ev)
+{
+ bool accept = true;
+ switch (ev->key()) {
+ case Qt::Key_Escape:
+ close();
+ break;
+ default:
+ accept = false;
+ break;
+ }
+ if (accept)
+ ev->accept();
+}
+
void DrawingWindow::paintEvent(QPaintEvent *ev)
{
QPainter widgetPainter(this);
d->imageMutex.unlock();
QRect rect = ev->rect();
widgetPainter.drawImage(rect, imageCopy, rect);
- if (rect == this->rect()) {
- d->paintMutex.lock();
- d->paintCondition.wakeAll();
- d->paintMutex.unlock();
- }
}
void DrawingWindow::showEvent(QShowEvent *ev)
protected:
void closeEvent(QCloseEvent *ev);
+ void customEvent(QEvent *ev);
+ void keyPressEvent(QKeyEvent *ev);
void paintEvent(QPaintEvent *ev);
void showEvent(QShowEvent *ev);
void timerEvent(QTimerEvent *ev);
for (int yy = y; yy < y + 10; yy++) {
for (int x = 0; x < w.width; x++)
w.drawPoint(x, yy);
+ w.sync();
}
if ((y += 10) >= w.height) {
y = 0;
ci += pi;
}
cr += pr;
+// w.sync();
}
}
const int h = 700;
QApplication application(argc, argv);
- DrawingWindow dl(lines, w, h);
- dl.show();
-
- DrawingWindow dr(rectangles, w, h);
- dr.show();
-
const int nf = 1;
const int nm = 1;
DrawingWindow *dw[nf + nm];
for (int i = 0; i < nf + nm; ++i)
dw[i]->show();
+ DrawingWindow dr(rectangles, w, h);
+ dr.show();
+
+ DrawingWindow dl(lines, w, h);
+ dl.show();
+
return application.exec();
}