本文整理汇总了C++中QPainter::drawPixmap方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::drawPixmap方法的具体用法?C++ QPainter::drawPixmap怎么用?C++ QPainter::drawPixmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::drawPixmap方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: analyze
void NyanCatAnalyzer::analyze(QPainter& p, const Analyzer::Scope& s,
bool new_frame) {
// Discard the second half of the transform
const int scope_size = s.size() / 2;
if ((new_frame && is_playing_) ||
(buffer_[0].isNull() && buffer_[1].isNull())) {
// Transform the music into rainbows!
for (int band = 0; band < kRainbowBands; ++band) {
float* band_start = history_ + band * kHistorySize;
// Move the history of each band across by 1 frame.
memmove(band_start, band_start + 1, (kHistorySize - 1) * sizeof(float));
}
// Now accumulate the scope data into each band. Should maybe use a series
// of band pass filters for this, so bands can leak into neighbouring bands,
// but for now it's a series of separate square filters.
const int samples_per_band = scope_size / kRainbowBands;
int sample = 0;
for (int band = 0; band < kRainbowBands; ++band) {
float accumulator = 0.0;
for (int i = 0; i < samples_per_band; ++i) {
accumulator += s[sample++];
}
history_[(band + 1) * kHistorySize - 1] = accumulator * band_scale_[band];
}
// Create polylines for the rainbows.
QPointF polyline[kRainbowBands * kHistorySize];
QPointF* dest = polyline;
float* source = history_;
const float top_of_cat = float(height()) / 2 - float(kCatHeight) / 2;
for (int band = 0; band < kRainbowBands; ++band) {
// Calculate the Y position of this band.
const float y =
float(kCatHeight) / (kRainbowBands + 1) * (band + 0.5) + top_of_cat;
// Add each point in the line.
for (int x = 0; x < kHistorySize; ++x) {
*dest = QPointF(px_per_frame_ * x, y + *source * kPixelScale);
++dest;
++source;
}
}
// Do we have to draw the whole rainbow into the buffer?
if (buffer_[0].isNull()) {
for (int i = 0; i < 2; ++i) {
buffer_[i] = QPixmap(QSize(width() + x_offset_, height()));
buffer_[i].fill(background_brush_.color());
}
current_buffer_ = 0;
QPainter buffer_painter(&buffer_[0]);
buffer_painter.setRenderHint(QPainter::Antialiasing);
for (int band = kRainbowBands - 1; band >= 0; --band) {
buffer_painter.setPen(colors_[band]);
buffer_painter.drawPolyline(&polyline[band * kHistorySize],
kHistorySize);
buffer_painter.drawPolyline(&polyline[band * kHistorySize],
kHistorySize);
}
} else {
const int last_buffer = current_buffer_;
current_buffer_ = (current_buffer_ + 1) % 2;
// We can just shuffle the buffer along a bit and draw the new frame's
// data.
QPainter buffer_painter(&buffer_[current_buffer_]);
buffer_painter.setRenderHint(QPainter::Antialiasing);
buffer_painter.drawPixmap(
0, 0, buffer_[last_buffer], px_per_frame_, 0,
x_offset_ + available_rainbow_width_ - px_per_frame_, 0);
buffer_painter.fillRect(
x_offset_ + available_rainbow_width_ - px_per_frame_, 0,
kCatWidth - kRainbowOverlap + px_per_frame_, height(),
background_brush_);
for (int band = kRainbowBands - 1; band >= 0; --band) {
buffer_painter.setPen(colors_[band]);
buffer_painter.drawPolyline(&polyline[(band + 1) * kHistorySize - 3],
3);
}
}
}
// Draw the buffer on to the widget
p.drawPixmap(0, 0, buffer_[current_buffer_], x_offset_, 0, 0, 0);
// Draw nyan cat (he's been waiting for this for 75 lines).
// Nyan nyan nyan nyan.
if (!is_playing_) {
// Ssshhh!
p.drawPixmap(SleepingCatDestRect(), cat_, SleepingCatSourceRect());
} else {
p.drawPixmap(CatDestRect(), cat_, CatSourceRect());
//.........这里部分代码省略.........
示例2: makeBasicPixmap
void TwoPlayerTimingGameWidget::makeBasicPixmap(
#ifdef USE_PIXMAP
QPixmap& pixmap,
#else
QPainter* painter,
#endif
int width,
int height)
{
#ifdef USE_PIXMAP
pixmap = QPixmap(width, height);
// Fill the pixmap with black background
pixmap.fill(Qt::black);
// Get the painter
QPainter *painter = new QPainter(&pixmap);
#else
painter->fillRect(0,0,width,height,QColor(0,0,0));
#endif
double xRate = 1.0 * width / LOGICAL_WIDTH;
double yRate = 1.0 * height / LOGICAL_HEIGHT;
// if (beginAnim > 0)
// {
// }
// else
{
painter->translate(GAME1_X_TO * xRate, 0);
painter->rotate(90);
if (game1)
{
#ifdef USE_PIXMAP
QPixmap tmp;
game1->makePixmap(tmp, GAME1_WIDTH * yRate, GAME1_HEIGHT * xRate);
painter->drawPixmap(0, 0, tmp);
#else
game1->makePixmap(painter, GAME1_WIDTH * yRate, GAME1_HEIGHT * xRate);
#endif
}
else
{
painter->setOpacity(0.5);
drawPixmapAt(painter, game1End, yRate, xRate, QPointF(0, 0), true, false);
painter->setOpacity(1);
}
painter->rotate(-90);
painter->translate(-GAME1_X_TO * xRate, 0);
painter->translate(GAME2_X_FROM * xRate, LOGICAL_HEIGHT * yRate);
painter->rotate(-90);
if (game2)
{
#ifdef USE_PIXMAP
QPixmap tmp;
game2->makePixmap(tmp, GAME2_WIDTH * yRate, GAME2_HEIGHT * xRate);
painter->drawPixmap(0, 0, tmp);
#else
game2->makePixmap(painter, GAME2_WIDTH * yRate, GAME2_HEIGHT * xRate);
#endif
}
else
{
painter->setOpacity(0.5);
drawPixmapAt(painter, game2End, yRate, xRate, QPointF(0, 0), true, false);
painter->setOpacity(1);
}
painter->rotate(90);
painter->translate(-GAME2_X_FROM * xRate, -LOGICAL_HEIGHT * yRate);
if (endAnim >= 0)
{
painter->scale(xRate, yRate);
painter->setOpacity(qMin(1.0, 1.0 * (END_ENIM_LAST - endAnim) * 2 / END_ENIM_LAST));
QPointF gFrom = QPointF(frameCount * 3, 0);
QPointF gTo = QPointF(frameCount * 3 - 100, -100);
QLinearGradient gradient = QLinearGradient(gFrom, gTo);
gradient.setColorAt(0, LINENEAR_COLOR_0);
gradient.setColorAt(1, LINENEAR_COLOR_1);
gradient.setSpread(QGradient::ReflectSpread);
QBrush brush = QBrush(gradient);
painter->setPen(QPen(brush, 4));
painter->translate((GAME1_X_FROM + GAME1_X_TO) / 2,
LOGICAL_HEIGHT / 2);
painter->rotate(90);
if (result1 > result2)
{
painter->drawPath(youWin);
painter->fillPath(youWin, brush);
}
else if (result1 < result2)
{
painter->drawPath(youLose);
painter->fillPath(youLose, brush);
}
else
//.........这里部分代码省略.........
示例3: CreateScreenshot
//.........这里部分代码省略.........
QPixmap tSourcePixmap;
// screen capturing
#if !defined(APPLE) || defined(HOMER_QT5)
tSourcePixmap = QPixmap::grabWindow(mWidget->winId(), mGrabOffsetX, mGrabOffsetY, tCaptureResX, tCaptureResY);
#else
CGImageRef tOSXWindowImage = CGWindowListCreateImage(CGRectInfinite, kCGWindowListOptionOnScreenOnly, mWidget->winId(), kCGWindowImageDefault);
tSourcePixmap = QPixmap::fromMacCGImageRef(tOSXWindowImage).copy(mGrabOffsetX, mGrabOffsetY, tCaptureResX, tCaptureResY);
CGImageRelease(tOSXWindowImage);
#endif
//####################################################################
//### SCALING to source resolution
//####################################################################
if ((tSourcePixmap.width() != mSourceResX) || (tSourcePixmap.height() != mSourceResY))
{// we have to adapt the assumed source resolution
//LOG(LOG_VERBOSE, "Have to rescale from %d*%d to %d*%d", tSourcePixmap.width(), tSourcePixmap.height(), mSourceResX, mSourceResY);
tSourcePixmap = tSourcePixmap.scaled(mSourceResX, mSourceResY);
}
//####################################################################
//### MOUSE VISUALIZATION
//####################################################################
if (mMouseVisualization)
{
QPoint tMousePos = QCursor::pos();
if ((tMousePos.x() < tSourcePixmap.width()) && (tMousePos.y() < tSourcePixmap.height()))
{// mouse is in visible area
int tMousePosInSourcePixmapX = mSourceResX * tMousePos.x() / tCaptureResX;
int tMousePosInSourcePixmapY = mSourceResY * tMousePos.y() / tCaptureResY;
//LOG(LOG_VERBOSE, "Mouse position: %d*%d", tMousePosInSourcePixmapX, tMousePosInSourcePixmapY);
QPainter *tPainter = new QPainter(&tSourcePixmap);
//TODO: add support for click visualization
tPainter->drawPixmap(tMousePosInSourcePixmapX, tMousePosInSourcePixmapY, QPixmap(":/images/MouseBlack.png").scaled(16, 32));
delete tPainter;
}
}
if(!tSourcePixmap.isNull())
{
// record screenshot via ffmpeg
if (mRecording)
{
if ((tRGBFrame = AllocFrame()) == NULL)
{
LOG(LOG_ERROR, "Unable to allocate memory for RGB frame");
}else
{
QImage tSourceImage = QImage((unsigned char*)mOriginalScreenshot, mSourceResX, mSourceResY, QImage::Format_RGB32);
QPainter *tSourcePainter = new QPainter(&tSourceImage);
tSourcePainter->drawPixmap(0, 0, tSourcePixmap);
delete tSourcePainter;
// Assign appropriate parts of buffer to image planes in tRGBFrame
FillFrame(tRGBFrame, mOriginalScreenshot, PIX_FMT_RGB32, mSourceResX, mSourceResY);
// set frame number in corresponding entries within AVFrame structure
tRGBFrame->pts = mRecorderChunkNumber;
tRGBFrame->coded_picture_number = mRecorderChunkNumber;
tRGBFrame->display_picture_number = mRecorderChunkNumber;
mRecorderChunkNumber++;
// emulate set FPS
tRGBFrame->pts = GetPtsFromFpsEmulator();
// re-encode the frame and write it to file
示例4: paintEvent
void ArthurFrame::paintEvent(QPaintEvent *e)
{
#ifdef Q_WS_QWS
static QPixmap *static_image = 0;
#else
static QImage *static_image = 0;
#endif
QPainter painter;
if (preferImage()
#ifdef QT_OPENGL_SUPPORT
&& !m_use_opengl
#endif
) {
if (!static_image || static_image->size() != size()) {
delete static_image;
#ifdef Q_WS_QWS
static_image = new QPixmap(size());
#else
static_image = new QImage(size(), QImage::Format_RGB32);
#endif
}
painter.begin(static_image);
int o = 10;
QBrush bg = palette().brush(QPalette::Background);
painter.fillRect(0, 0, o, o, bg);
painter.fillRect(width() - o, 0, o, o, bg);
painter.fillRect(0, height() - o, o, o, bg);
painter.fillRect(width() - o, height() - o, o, o, bg);
} else {
#ifdef QT_OPENGL_SUPPORT
if (m_use_opengl) {
painter.begin(glw);
painter.fillRect(QRectF(0, 0, glw->width(), glw->height()), palette().color(backgroundRole()));
} else {
painter.begin(this);
}
#else
painter.begin(this);
#endif
}
painter.setClipRect(e->rect());
painter.setRenderHint(QPainter::Antialiasing);
QPainterPath clipPath;
QRect r = rect();
qreal left = r.x() + 1;
qreal top = r.y() + 1;
qreal right = r.right();
qreal bottom = r.bottom();
qreal radius2 = 8 * 2;
clipPath.moveTo(right - radius2, top);
clipPath.arcTo(right - radius2, top, radius2, radius2, 90, -90);
clipPath.arcTo(right - radius2, bottom - radius2, radius2, radius2, 0, -90);
clipPath.arcTo(left, bottom - radius2, radius2, radius2, 270, -90);
clipPath.arcTo(left, top, radius2, radius2, 180, -90);
clipPath.closeSubpath();
painter.save();
painter.setClipPath(clipPath, Qt::IntersectClip);
painter.drawTiledPixmap(rect(), m_tile);
// client painting
paint(&painter);
painter.restore();
painter.save();
if (m_show_doc)
paintDescription(&painter);
painter.restore();
int level = 180;
painter.setPen(QPen(QColor(level, level, level), 2));
painter.setBrush(Qt::NoBrush);
painter.drawPath(clipPath);
if (preferImage()
#ifdef QT_OPENGL_SUPPORT
&& !m_use_opengl
#endif
) {
painter.end();
painter.begin(this);
#ifdef Q_WS_QWS
painter.drawPixmap(e->rect(), *static_image, e->rect());
#else
painter.drawImage(e->rect(), *static_image, e->rect());
#endif
}
#ifdef QT_OPENGL_SUPPORT
if (m_use_opengl && (inherits("PathDeformRenderer") || inherits("PathStrokeRenderer") || inherits("CompositionRenderer") || m_show_doc))
//.........这里部分代码省略.........
示例5: drawButton
/*!\reimp
*/
void QRadioButton::drawButton( QPainter *paint )
{
QPainter *p = paint;
const QColorGroup & g = colorGroup();
int x, y;
QFontMetrics fm = fontMetrics();
QSize lsz = fm.size(ShowPrefix, text());
QSize sz = style().exclusiveIndicatorSize();
x = text().isEmpty() ? 1 : 0;
y = (height() - lsz.height() + fm.height() - sz.height())/2;
#ifndef QT_NO_TEXTSTREAM
#define SAVE_RADIOBUTTON_PIXMAPS
#endif
#if defined(SAVE_RADIOBUTTON_PIXMAPS)
QString pmkey; // pixmap key
int kf = 0;
if ( isDown() )
kf |= 1;
if ( isOn() )
kf |= 2;
if ( isEnabled() )
kf |= 4;
QTextOStream os(&pmkey);
os << "$qt_radio_" << style().className() << "_"
<< palette().serialNumber() << "_" << kf;
QPixmap *pm = QPixmapCache::find( pmkey );
if ( pm ) { // pixmap exists
drawButtonLabel( p );
p->drawPixmap( x, y, *pm );
return;
}
bool use_pm = TRUE;
QPainter pmpaint;
int wx, wy;
if ( use_pm ) {
pm = new QPixmap( sz ); // create new pixmap
CHECK_PTR( pm );
pmpaint.begin( pm );
p = &pmpaint; // draw in pixmap
wx=x; wy=y; // save x,y coords
x = y = 0;
p->setBackgroundColor( g.background() );
}
#endif
#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
style().drawExclusiveIndicator(p, x, y, sz.width(), sz.height(), g, isOn(), isDown(), isEnabled() );
#if defined(SAVE_RADIOBUTTON_PIXMAPS)
if ( use_pm ) {
pmpaint.end();
if ( backgroundPixmap() || backgroundMode() == X11ParentRelative ) {
QBitmap bm( pm->size() );
bm.fill( color0 );
pmpaint.begin( &bm );
style().drawExclusiveIndicatorMask( &pmpaint, 0, 0, bm.width(), bm.height(), isOn() );
pmpaint.end();
pm->setMask( bm );
}
p = paint; // draw in default device
p->drawPixmap( wx, wy, *pm );
if (!QPixmapCache::insert(pmkey, pm) ) // save in cache
delete pm;
}
#endif
drawButtonLabel( p );
}
示例6: p
void ribi::Chess::QtChessBoardWidget::DrawChessBoard(
QPainter& painter,
const Chess::BoardWidget * const widget)
{
const int w = widget->GetWidth();
const int h = widget->GetHeight();
//Draw the plain chessboard
DrawChessBoard(
painter,
widget->GetLeft(),
widget->GetTop(),
w,
h,
widget->GetBoard().get());
//Draw the selected square
static const Chess::QtResources r;
const int square_w = w / 8;
const int square_h = h / 8;
const boost::shared_ptr<const Chess::Square> selected = widget->GetSelector()->GetSelected();
if (selected)
{
TRACE_FUNC();
const int x_co = selected->GetFile().ToInt() * square_w;
const int y_co = selected->GetRank().ToInt() * square_h;
if (widget->GetBoard()->GetPiece(selected))
{
const std::string filename = Chess::Resources::Find(
widget->GetBoard()->GetPiece(selected),
Chess::SquareSelector::m_selected_color,
true);
TRACE(filename);
assert(fileio::FileIo().IsRegularFile(filename));
const QPixmap p(filename.c_str());
painter.drawPixmap(x_co,y_co,square_w,square_h,p);
}
else
{
assert(!"Should not get here");
}
//Draw the possible moves
const std::vector<boost::shared_ptr<Move> > moves = widget->GetBoard()->GetMoves(selected);
for(const boost::shared_ptr<Move> move: moves)
{
if (move->To())
{
const int x_co = move->To()->GetFile().ToInt() * square_w;
const int y_co = move->To()->GetRank().ToInt() * square_h;
if (widget->GetBoard()->GetPiece(move->To()))
{
const std::string filename = Chess::Resources::Find(
widget->GetBoard()->GetPiece(move->To()),
Chess::SquareSelector::m_moves_color);
assert(fileio::FileIo().IsRegularFile(filename));
const QPixmap p(filename.c_str());
painter.drawPixmap(x_co,y_co,square_w,square_h,p);
}
else
{
const boost::shared_ptr<Square> square {
SquareFactory().Create(move->To()->GetFile(),move->To()->GetRank())
};
const std::string filename
= Chess::Resources::Find(
square,
Chess::SquareSelector::m_moves_color);
assert(fileio::FileIo().IsRegularFile(filename));
const QPixmap p(filename.c_str());
painter.drawPixmap(x_co,y_co,square_w,square_h,p);
}
}
}
}
//Draw cursor
const boost::shared_ptr<const Chess::Square> cursor = widget->GetSelector()->GetCursor();
assert(cursor);
{
const int x_co = cursor->GetFile().ToInt() * square_w;
const int y_co = cursor->GetRank().ToInt() * square_h;
if (widget->GetBoard()->GetPiece(cursor))
{
const std::string filename = Chess::Resources::Find(widget->GetBoard()->GetPiece(cursor),
Chess::SquareSelector::m_cursor_color,
selected && *selected == *cursor );
assert(fileio::FileIo().IsRegularFile(filename));
const QPixmap p(filename.c_str());
painter.drawPixmap(x_co,y_co,square_w,square_h,p);
}
else
{
const std::string filename
= Chess::Resources::Find(
cursor,
Chess::SquareSelector::m_cursor_color);
assert(fileio::FileIo().IsRegularFile(filename));
const QPixmap p(filename.c_str());
//.........这里部分代码省略.........
示例7: paintEvent
void LightMaps::paintEvent(QPaintEvent *event)
{
QPainter p;
p.begin(this);
m_normalMap->render(&p, event->rect());
p.setPen(Qt::black);
p.drawText(rect(), Qt::AlignBottom | Qt::TextWordWrap,
"Map data CCBYSA 2009 OpenStreetMap.org contributors");
p.end();
if (zoomed) {
int dim = qMin(width(), height());
int magnifierSize = qMin(MAX_MAGNIFIER, dim * 2 / 3);
int radius = magnifierSize / 2;
int ring = radius - 15;
QSize box = QSize(magnifierSize, magnifierSize);
// reupdate our mask
if (maskPixmap.size() != box) {
maskPixmap = QPixmap(box);
maskPixmap.fill(Qt::transparent);
QRadialGradient g;
g.setCenter(radius, radius);
g.setFocalPoint(radius, radius);
g.setRadius(radius);
g.setColorAt(1.0, QColor(255, 255, 255, 0));
g.setColorAt(0.5, QColor(128, 128, 128, 255));
QPainter mask(&maskPixmap);
mask.setRenderHint(QPainter::Antialiasing);
mask.setCompositionMode(QPainter::CompositionMode_Source);
mask.setBrush(g);
mask.setPen(Qt::NoPen);
mask.drawRect(maskPixmap.rect());
mask.setBrush(QColor(Qt::transparent));
mask.drawEllipse(g.center(), ring, ring);
mask.end();
}
QPoint center = dragPos - QPoint(0, radius);
center = center + QPoint(0, radius / 2);
QPoint corner = center - QPoint(radius, radius);
QPoint xy = center * 2 - QPoint(radius, radius);
// only set the dimension to the magnified portion
if (zoomPixmap.size() != box) {
zoomPixmap = QPixmap(box);
zoomPixmap.fill(Qt::lightGray);
}
if (true) {
QPainter p(&zoomPixmap);
p.translate(-xy);
m_largeMap->render(&p, QRect(xy, box));
p.end();
}
QPainterPath clipPath;
clipPath.addEllipse(center, ring, ring);
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
p.setClipPath(clipPath);
p.drawPixmap(corner, zoomPixmap);
p.setClipping(false);
p.drawPixmap(corner, maskPixmap);
p.setPen(Qt::gray);
p.drawPath(clipPath);
}
if (invert) {
QPainter p(this);
p.setCompositionMode(QPainter::CompositionMode_Difference);
p.fillRect(event->rect(), Qt::white);
p.end();
}
}
示例8: PrintPixmap
/* Prints a QPixmap, optionally displaying the print setup dialog first */
void PrintPixmap(QPixmap pixmap, bool displayDialog, QWidget *pParent, QPrinter *pPrinter)
{
bool deletePrinter = false;
if (pixmap.isNull() == true)
{
return;
}
// Create a printer device. Analogous to a Windows device context
if (pPrinter == NULL)
{
deletePrinter = true;
pPrinter = new QPrinter();
if (pPrinter == NULL)
{
return;
}
}
bool bPrint = true;
if (displayDialog)
{
QPrintDialog dlg(pPrinter, pParent);
if (dlg.exec() == QDialog::Rejected)
{
bPrint = false;
}
}
if (bPrint == true)
{
double dAspect = 1.0; // the aspect ratio of the pixmap = width / height
dAspect = static_cast<double>(pixmap.width()) / static_cast<double>(pixmap.height());
// the QPainter provides an interface for drawing to a device, analogous
// to Windows GDI, with the printer being the device context in this case
QPainter p;
if (p.begin(pPrinter) == false)
{
if (deletePrinter)
{
delete pPrinter;
}
return;
}
QRect rcViewport = p.viewport(); // the printable area in device coords
// Determine how large we can make the pixmap on the paper without
// losing any of it off the edges of the paper. iPrintWidth and iPrintHeight
// will be the size of the pixmap on the paper, in printer device coords.
int iPrintWidth = rcViewport.width();
int iPrintHeight = rcViewport.height();
double pAspect = static_cast<double>(iPrintWidth) /
static_cast<double>(iPrintHeight); // aspect ratio of the paper
// unless the aspect ratios of the paper and pixmap are equal, we will have unused
// space above and below or left and right of the printed image.
double ratioAspects = pAspect / dAspect;
if (ratioAspects > 1.0)
{
// paper is wider than the image: empty space left and right
// reduce iPrintWidth accordingly
iPrintWidth = iPrintWidth / ratioAspects;
}
else
{
// paper is taller than the image: empty space above and below
// reduce iPrintHeight accordingly
iPrintHeight = iPrintHeight * ratioAspects;
}
// specify the pixel dimensions of the pixmap
p.setWindow(pixmap.rect());
// specify the location and size to draw the pixmap on the paper
p.setViewport(rcViewport.left() + (rcViewport.width() - iPrintWidth) / 2,
rcViewport.top() + (rcViewport.height() - iPrintHeight) / 2,
iPrintWidth, iPrintHeight);
// draw the pixmap to the print device
p.drawPixmap(0, 0, pixmap);
// tell the printer that we are done; this will trigger a form feed
p.end();
}
if (deletePrinter)
{
delete pPrinter;
}
}
示例9: PaintPlatform
void Right_platform::PaintPlatform (QPainter &p){
static QPixmap pix(":/Platform/Resources/Right_Platform.png");
p.drawPixmap(x,y,143,Height,pix);
}
示例10: bomb
/*! Событие нажатия какой-либо клавиши мыши
* \param [in|out] pe Указатель на событие мыши
*/
/*virtual*/ void bomb_item::mousePressEvent(QGraphicsSceneMouseEvent* pe)
{
dynamic_cast<Field*>(this->scene())->sendStartGame();
//Если нажата левая кнопка мыши
if(pe->button() == Qt::LeftButton && !isFlagged && !isPressed)
{
cur_block = block_pressed;
isPressed = true;
if(type == 'b')
{//если бомба, заканчиваем игру
//Дорисовываем бомбу
QPixmap img = block_pressed;
QPixmap bomb(":/Saper/bomb.png");
bomb = bomb.scaled(cur_block.size());
QPainter pr;
pr.begin(&img);
pr.drawPixmap(bomb.rect(),bomb);
pr.end();
cur_block = img;
//Меняем тип
type = 'B';
//Сообщаем о проигрыше
dynamic_cast<Field*>(this->scene())->sendEndGame();
}
else if(type != '0')
{
QPixmap img = block_pressed;
QPainter pr;
pr.begin(&img);
pr.setFont(QFont("Times",20,QFont::Normal));
int r,g,b;
r = g = b = 0;
//Выставлем цвет цифре смешивая цвета rgb
if(type == '1' || type == '3' || type == '5' || type == '7')
b = 110;
if(type == '2' || type == '3' || type == '6' || type == '7')
g = 130;
if(type == '4' || type == '5' || type == '6' || type == '7')
r = 130;
pr.setPen(QColor(r,g,b));
pr.drawText(img.rect(),QString(type),QTextOption(Qt::AlignCenter));
pr.end();
cur_block = img;
}
else
{//Пустая клетка
//Открываем соседние клетки
//Вычисляем размеры блока
int picHeight = this->cur_block.height();
int picWidth = this->cur_block.width();
float x = this->pos().x();
float y = this->pos().y();
//Проходим по координатам вокруг клетки
for(int i =-picHeight; i <= picHeight; i += picHeight)
{
for(int j =-picWidth; j <= picWidth; j += picWidth)
{
if(i || j)
{//Середину не проверяем
//Отправляем ивент о нажатии выбраной клетке
QGraphicsItem * item = this->scene()->itemAt(x+(float)j,y+(float)i,QTransform());
if(item != NULL)
this->scene()->sendEvent(item,pe);
}
}
}
}
//Добавляем в открытые, этот блок
dynamic_cast<Field*>(this->scene())->openBlock(); //Открываем блок
if(dynamic_cast<Field*>(this->scene())->checkLastMines())//Проверяем окончена ли игра
dynamic_cast<Field*>(this->scene())->sendEndGame(2);//Если победа, то сообщаем
}
else if(pe->button() == Qt::RightButton && !isPressed)
{
//Рисуем флажок
if(!isFlagged)
{
isFlagged = true;
QPixmap img = block;
QPixmap flag(":/Saper/flag.png");
flag = flag.scaled(cur_block.size());
QPainter pr;
pr.begin(&img);
pr.drawPixmap(flag.rect(),flag);
pr.end();
cur_block = img;
}
else
{
//Убираем флажок если он был
cur_block = block;
isPressed = isFlagged = false;
}
dynamic_cast<Field*>(this->scene())->sendMines(isFlagged);
//.........这里部分代码省略.........
示例11: drawShape
void Widget::drawShape( QPainter &p )
{
// initPainter(p);
p.drawPixmap( int(x()), int(y()), QPixmap::grabWidget( widget() ) );
// deinitPainter(p);
}