void QVideoWidget::paintEvent(QPaintEvent *) { if( img.isNull() ) return; //qDebug() << "scaled.topLeft()" << scaled; QImage scaledImg; QPainter painter(this); if( mouseIn ){ QString sx("x:%1"), sy("y:%1"); if(Ui::crosshairReal){ QPoint pos = (mouse-scaled.topLeft()) * ratio; sx = sx.arg(pos.x()); sy = sy.arg(pos.y()); mutex.lock(); QImage imgCopy = img.copy(); mutex.unlock(); QPainter painterImg(&imgCopy); painterImg.drawPixmap(pos-QPoint(15, 15), QPixmap(":/icons/crosshair")); painterImg.drawLine(0, pos.y(), pos.x()-15, pos.y()); painterImg.drawLine(pos.x()+16, pos.y(), imgCopy.width(), pos.y()); painterImg.drawLine(pos.x(), 0, pos.x(), pos.y()-15); painterImg.drawLine(pos.x(), pos.y()+16, pos.x(), imgCopy.height()); painterImg.end(); scaledImg = imgCopy.scaled(this->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); painter.drawImage(scaled.topLeft(), scaledImg); }else{ QPointF pos = QPointF(mouse-scaled.topLeft()) * ratio; sx = sx.arg(pos.x()); sy = sy.arg(pos.y()); mutex.lock(); scaledImg = img.scaled(this->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); mutex.unlock(); painter.drawImage(scaled.topLeft(), scaledImg); painter.drawPixmap(mouse-QPoint(15, 15), QPixmap(":/icons/crosshair")); painter.drawLine(scaled.left(), mouse.y(), mouse.x()-15, mouse.y()); painter.drawLine(mouse.x()+16, mouse.y(), scaled.right(), mouse.y()); painter.drawLine(mouse.x(), scaled.top(), mouse.x(), mouse.y()-15); painter.drawLine(mouse.x(), mouse.y()+16, mouse.x(), scaled.bottom()); } QFont font(painter.font()); font.setPixelSize(15); painter.setFont(font); painter.fillRect( 0, 0, 70, 35, Qt::white ); painter.drawText( 1, 16, sx ); painter.drawText( 1, 32, sy ); }else{ mutex.lock(); scaledImg = img.scaled(this->size(), Qt::KeepAspectRatio, Ui::forceHighQuality ? Qt::SmoothTransformation : Qt::FastTransformation); mutex.unlock(); painter.drawImage(scaled.topLeft(), scaledImg); } painter.end(); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); int listenfd, connfd; socklen_t addrlen; char buff[MAXLINE]; SettingData setting; char ch; cout << "Set setting?(y/n): "; cout.flush(); while(1) { cin >> ch; if (ch == 'n') { if (!setting.Load()) { setting.Set(); } break; } else if (ch == 'y') { setting.Set(); break; } else { cout << "Error value"; continue; } } QPrinter printer; QPainter painterPrint(&printer); listenfd = Tcp_listen(setting.GetIP(), setting.GetPort(), &addrlen); for ( ; ; ) { QPixmap image(setting.GetAddress()); QPainter painterImg(&image); painterImg.setPen(setting.GetColor()); painterImg.setFont(QFont(setting.GetFont(), setting.GetFontSize())); connfd = Accept(listenfd, NULL, NULL); Read(connfd, buff, strlen(buff)); painterImg.drawText(setting.GetRect(), Qt::AlignLeft | Qt::AlignTop, buff); painterPrint.drawPixmap(setting.GetRect(), image); painterImg.end(); snprintf(buff, MAXLINE, "successful"); Write(connfd, buff, strlen(buff)); Close(connfd); } painterPrint.end(); return 0; }