本文整理汇总了C++中QPainter::end方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::end方法的具体用法?C++ QPainter::end怎么用?C++ QPainter::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::end方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
ImageArea::ImageArea(const bool &isOpen, const QString &filePath, QWidget *parent) :
QWidget(parent), mIsEdited(false), mIsPaint(false), mIsResize(false)
{
setMouseTracking(true);
mRightButtonPressed = false;
mFilePath.clear();
makeFormatsFilters();
initializeImage();
mZoomFactor = 1;
mAdditionalTools = new AdditionalTools(this);
mUndoStack = new QUndoStack(this);
mUndoStack->setUndoLimit(DataSingleton::Instance()->getHistoryDepth());
if(isOpen && filePath.isEmpty())
{
open();
}
else if(isOpen && !filePath.isEmpty())
{
open(filePath);
}
else
{
QPainter *painter = new QPainter(mImage);
painter->fillRect(0, 0,
DataSingleton::Instance()->getBaseSize().width(),
DataSingleton::Instance()->getBaseSize().height(),
Qt::white);
painter->end();
resize(mImage->rect().right() + 6,
mImage->rect().bottom() + 6);
}
QTimer *autoSaveTimer = new QTimer(this);
autoSaveTimer->setInterval(DataSingleton::Instance()->getAutoSaveInterval() * 1000);
connect(autoSaveTimer, SIGNAL(timeout()), this, SLOT(autoSave()));
connect(mAdditionalTools, SIGNAL(sendNewImageSize(QSize)), this, SIGNAL(sendNewImageSize(QSize)));
autoSaveTimer->start();
SelectionInstrument *selectionInstrument = new SelectionInstrument(this);
connect(selectionInstrument, SIGNAL(sendEnableCopyCutActions(bool)), this, SIGNAL(sendEnableCopyCutActions(bool)));
connect(selectionInstrument, SIGNAL(sendEnableSelectionInstrument(bool)), this, SIGNAL(sendEnableSelectionInstrument(bool)));
// Instruments handlers
mInstrumentsHandlers.fill(0, (int)INSTRUMENTS_COUNT);
mInstrumentsHandlers[CURSOR] = selectionInstrument;
mInstrumentsHandlers[PEN] = new PencilInstrument(this);
mInstrumentsHandlers[LINE] = new LineInstrument(this);
mInstrumentsHandlers[ERASER] = new EraserInstrument(this);
mInstrumentsHandlers[RECTANGLE] = new RectangleInstrument(this);
mInstrumentsHandlers[ELLIPSE] = new EllipseInstrument(this);
mInstrumentsHandlers[FILL] = new FillInstrument(this);
mInstrumentsHandlers[SPRAY] = new SprayInstrument(this);
mInstrumentsHandlers[MAGNIFIER] = new MagnifierInstrument(this);
mInstrumentsHandlers[COLORPICKER] = new ColorpickerInstrument(this);
mInstrumentsHandlers[CURVELINE] = new CurveLineInstrument(this);
mInstrumentsHandlers[TEXT] = new TextInstrument(this);
// Effects handlers
mEffectsHandlers.fill(0, (int)EFFECTS_COUNT);
mEffectsHandlers[NEGATIVE] = new NegativeEffect(this);
mEffectsHandlers[GRAY] = new GrayEffect(this);
mEffectsHandlers[BINARIZATION] = new BinarizationEffect(this);
mEffectsHandlers[GAUSSIANBLUR] = new GaussianBlurEffect(this);
mEffectsHandlers[GAMMA] = new GammaEffect(this);
mEffectsHandlers[SHARPEN] = new SharpenEffect(this);
mEffectsHandlers[CUSTOM] = new CustomEffect(this);
}
示例2: if
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QImage PoleFigureImageUtilities::Create3ImagePoleFigure(UInt8ArrayType* i0, UInt8ArrayType* i1, UInt8ArrayType* i2,
PoleFigureConfiguration_t& config, int32_t layout)
{
// Create a QImage that is the width of the first 2 images and the height of the first and third
QImage img0 = PoleFigureImageUtilities::CreateQImageFromRgbaArray(i0, config.imageDim, true);
QImage img1 = PoleFigureImageUtilities::CreateQImageFromRgbaArray(i1, config.imageDim, true);
QImage img2 = PoleFigureImageUtilities::CreateQImageFromRgbaArray(i2, config.imageDim, true);
// Create the Scalar Bar image
QImage scalarBar = PoleFigureImageUtilities::GenerateScalarBar(img0.width(), img0.height(), config);
int pImageWidth = 0;
int pImageHeight = 0;
QPoint pos1;
QPoint pos2;
QPoint pos3;
QPoint pos4;
if(layout == SIMPL::Layout::Horizontal)
{
pImageWidth = img0.width() * 4;
pImageHeight = img0.height();
pos1 = QPoint(0, 0);
pos2 = QPoint(img0.width(), 0);
pos3 = QPoint(img0.width() * 2, 0);
pos4 = QPoint(img0.width() * 3, 0);
}
else if(layout == SIMPL::Layout::Vertical)
{
pImageWidth = img0.width();
pImageHeight = img0.height() * 4;
pos1 = QPoint(0, 0);
pos2 = QPoint(0, img0.height());
pos3 = QPoint(0, img0.height() * 2);
pos4 = QPoint(0, img0.height() * 3);
}
else if(layout == SIMPL::Layout::Square)
{
pImageWidth = img0.width() + img1.width();
pImageHeight = img0.height() + img2.height();
pos1 = QPoint(0, 0);
pos2 = QPoint(pImageWidth / 2, 0);
pos3 = QPoint(0, pImageHeight / 2);
pos4 = QPoint(pImageWidth / 2, pImageHeight / 2);
}
QImage pImage(pImageWidth, pImageHeight, QImage::Format_ARGB32_Premultiplied);
pImage.fill(0xFFFFFFFF); // All white background
// Create a Painter backed by a QImage to draw into
QPainter painter;
painter.begin(&pImage);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.drawImage(pos1, img0); // Draw the first image in the upper Left
painter.drawImage(pos2, img1); // Draw the second image in the upper right
painter.drawImage(pos3, img2); // Draw the third image in the lower Left
painter.drawImage(pos4, scalarBar); // Draw the Scalar Bar
painter.end();
// Scale the image down to 225 pixels
return pImage;
}
示例3: btnExportClicked
void MainWindow::btnExportClicked()
{
QList<QChar> charset;
if (chkLowerAZ->isChecked())
for (char c = 'a'; c <= 'z'; c++)
charset.append(c);
if (chkUpperAZ->isChecked())
for (char c = 'A'; c <= 'Z'; c++)
charset.append(c);
if (chkNumbers->isChecked())
for (char c = '0'; c <= '9'; c++)
charset.append(c);
QString str = ldtCharacters->text();
for (QString::const_iterator itr(str.begin()); itr != str.end(); itr++)
if (!charset.contains(*itr))
charset.append(*itr);
qSort(charset);
// Render characters
QFont font = fontSelector->currentFont();
font.setPixelSize(font.pointSize());
QFontMetrics metrics = QFontMetrics(font);
QTextCodec *codec = QTextCodec::codecForName("utf-8");
QString glyphs;
QString fontName = QString("font_%1%2")
.arg(font.family().toLower())
.arg(font.pixelSize())
.replace(' ', '_');
QString fontstruct = QString(
"const struct glib_font %1 = {\n"
" .charcount = %2,\n"
" .size = %3,\n"
" .glyphs = {\n ")
.arg(fontName)
.arg(charset.size())
.arg(font.pixelSize());
QListIterator<QChar> itr(charset);
while (itr.hasNext()) {
QChar c = itr.next();
if (c == ' ') {
// Add space character
fontstruct += QString("{.utf8 = 0x20, .x = %1, .y = 0, .bitmap = NULL}")
.arg(metrics.width(' '));
} else {
QRect boundingRect = metrics.boundingRect(c);
QImage image = QImage(boundingRect.width(), boundingRect.height(),
QImage::Format_Mono);
image.fill(Qt::color1);
QPainter p;
p.begin(&image);
p.setFont(font);
p.setWindow(metrics.boundingRect(c));
p.drawText(0, 0, c);
p.end();
QString utf8 = codec->fromUnicode(c).toHex();
glyphs += renderGlyph(utf8, image);
fontstruct += QString("{.utf8 = 0x%1, .x = %2, .y = %3, .bitmap = &glyph_%1}")
.arg(utf8)
.arg(boundingRect.x() + 1)
.arg(boundingRect.y() - metrics.descent() + 1); // +1 for the base line
}
if (itr.hasNext())
fontstruct += ",\n ";
}
fontstruct += "\n }\n};\n";
glyphs = "#include <liblcd/glib.h>\n\n" + glyphs + "\n" + fontstruct;
QString filename = QFileDialog::getSaveFileName(this,
tr("Save Font"), fontName + ".c", tr("Source Files (*.c *.cpp)"));
if (!filename.isEmpty()) {
if (!(filename.endsWith(".c") || filename.endsWith(".cpp")))
filename += ".c";
QFile file(filename);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return;
QTextStream out(&file);
//.........这里部分代码省略.........
示例4: bgPixmap
SplashScreen::SplashScreen(QWidget *parent) :
QWidget(parent)
{
QRect rec = QApplication::desktop()->screenGeometry();
int screenWidth = rec.width();
int screenHeight = rec.height();
this->setWindowFlags(Qt::FramelessWindowHint);
this->setGeometry(0,screenHeight/2-150,screenWidth,300);
QPixmap bgPixmap(screenWidth,300);
QLinearGradient bgGradient(QPointF(0, 0), QPointF(screenWidth, 0));
bgGradient.setColorAt(0, QColor("#6c3d94"));
bgGradient.setColorAt(1, QColor("#a13469"));
//#3c3c3b
QRect rect_linear(0,0,screenWidth,300);
QPainter *painter = new QPainter(&bgPixmap);
painter->fillRect(rect_linear, bgGradient);
painter->end();
bg = new QLabel(this);
bg->setPixmap(bgPixmap);
bg->setGeometry(0,0,screenWidth,300);
splashImage = new QLabel(this);
QPixmap newPixmap;
if(GetBoolArg("-testnet")) {
newPixmap.load(":/images/splash_testnet");
}
else {
newPixmap.load(":/images/splash");
}
splashImage->setPixmap(newPixmap);
splashImage->move(screenWidth/2-567/2,50);
QFont smallFont; smallFont.setPixelSize(12);
versionLabel = new QLabel(this);
versionLabel->setStyleSheet("QLabel { color: #3C3C3B; }");
versionLabel->setFont(smallFont);
versionLabel->setText(QString::fromStdString(FormatFullVersion()).split("-")[0]);
versionLabel->setFixedSize(1000,30);
versionLabel->move(screenWidth/2-108,220);
QFont largeFont; largeFont.setPixelSize(20);
label = new QLabel(this);
label->setStyleSheet("QLabel { color: #FFFFFF; }");
label->setFont(largeFont);
label->setText("...");
label->setFixedSize(1000,30);
label->move(screenWidth/2-108,260);
}
示例5: GenerateScalarBar
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QImage PoleFigureImageUtilities::GenerateScalarBar(int imageWidth, int imageHeight, PoleFigureConfiguration_t& config)
{
int numColors = config.numColors;
QImage pImage(imageWidth, imageHeight, QImage::Format_ARGB32_Premultiplied);
pImage.fill(0xFFFFFFFF); // All white background
// Create a Painter backed by a QImage to draw into
QPainter painter;
painter.begin(&pImage);
painter.setRenderHint(QPainter::Antialiasing, true);
int penWidth = 1;
#if 0
// DRAW A BORDER AROUND THE IMAGE FOR DEBUGGING
QColor c(RgbColor::dRgb(255, 0, 0, 255));
painter.setPen(QPen(c, penWidth, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin));
painter.drawLine(0, 0, imageWidth, 0); // Top
painter.drawLine(0, 0, 0, imageHeight); // Left
painter.drawLine(imageWidth, 0, imageWidth, imageHeight); // Right
painter.drawLine(0, imageHeight, imageWidth, imageHeight); // Bottom
//-----------------
#endif
//Get all the colors that we will need
QVector<SIMPL::Rgb> colorTable(numColors);
QVector<float> colors(3 * numColors, 0.0);
SIMPLColorTable::GetColorTable(numColors, colors); // Generate the color table values
float r = 0.0, g = 0.0, b = 0.0;
for (int i = 0; i < numColors; i++) // Convert them to QRgbColor values
{
r = colors[3 * i];
g = colors[3 * i + 1];
b = colors[3 * i + 2];
colorTable[i] = RgbColor::dRgb(r * 255, g * 255, b * 255, 255);
}
// Now start from the bottom and draw colored lines up the scale bar
// A Slight Indentation for the scalar bar
float margin = 0.05f;
float scaleBarRelativeWidth = 0.10f;
float scaleBarRelativeHeight = 1.0f - (margin * 2);
int colorHeight = int( (imageHeight * scaleBarRelativeHeight) / numColors);
QPointF topLeft(imageWidth * margin, imageHeight * margin);
QSizeF size(imageWidth * scaleBarRelativeWidth, imageHeight * scaleBarRelativeHeight);
int yLinePos = topLeft.y();
QPointF start = topLeft;
QPointF end = topLeft;
for(int i = numColors - 1; i >= 0; i--)
{
QColor c(colorTable[i]);
painter.setPen(QPen(c, penWidth, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin));
for(int j = 0; j < colorHeight; j++)
{
start.setY(yLinePos);
end.setX(topLeft.x() + (imageWidth * scaleBarRelativeWidth));
end.setY(yLinePos);
painter.drawLine(start, end);
yLinePos++;
}
}
// Draw the border of the scale bar
size = QSizeF(imageWidth * scaleBarRelativeWidth, numColors * colorHeight); // Add two pixel to the height so we don't over write part of the scale bar
QRectF scaleBorder(topLeft, size);
penWidth = 2;
painter.setPen(QPen(QColor(0, 0, 0, 255), penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
painter.drawRect(scaleBorder);
// Draw the Text Labels of the Scale Bar
int startFontPtSize = 10;
QFont font("Ariel", startFontPtSize, QFont::Bold);
QFontMetrics metrics(font);
int fontPixelsHeight = metrics.height();
while(fontPixelsHeight < colorHeight * 2)
{
startFontPtSize++;
font = QFont("Ariel", startFontPtSize, QFont::Bold);
metrics = QFontMetrics(font);
fontPixelsHeight = metrics.height();
}
painter.setFont(font);
// Draw some more information to the right of the Scale Bar
QString maxStr = QString::number(config.maxScale, 'f', 3);
painter.drawText(topLeft.x() + (imageWidth * scaleBarRelativeWidth) + 10, topLeft.y() + fontPixelsHeight, maxStr);
QString minStr = QString::number(config.minScale, 'f', 3);
painter.drawText(topLeft.x() + (imageWidth * scaleBarRelativeWidth) + 10, topLeft.y() + size.height(), minStr);
//.........这里部分代码省略.........
示例6: paintEvent
//.........这里部分代码省略.........
tabS.moveTo( rectTab.x()+nDiameter, rectTab.y() );
arcRect.moveTo(rectTab.topLeft());
tabPath.arcTo( arcRect, -270, 90 );
tabS.arcTo( arcRect, -270, 90 );
arcRect.moveTo(rectTab.x(), rectTab.bottom()-nDiameter);
tabPath.arcTo( arcRect, -180, 90 );
tabS.arcTo( arcRect, -180, 90 );
tabPath.moveTo( rectTab.left()+nDiameter, rectTab.bottom() );
tabPath.lineTo( rectTab.right(), rectTab.bottom() );
//tabS.closeSubpath();
}
QColor colorBody;
if (bNotify && (m_nBlinkCount % 2 == 0))
{
colorBody = QColor(252, 209, 211);
}
else
{
if (bActive)
colorBody = QColor(255, 255, 255);
else
colorBody = QColor(0xF5, 0xF5, 0xF5);
}
painter.fillPath( tabPath, QBrush(colorBody) );
QColor colorStart = bActive ? g_TabDefaultColor[i] : (bHover ? QColor(255, 190, 60, 200) : QColor(255, 255, 255, 200));
QColor colorEnd(255, 255, 255, 200);
QRectF rectTabTip;
rectTabTip = tabS.boundingRect();
QLinearGradient gradTip;
if (m_bHorz)
{
gradTip.setStart(rectTabTip.center().x(), rectTabTip.top());
gradTip.setFinalStop(rectTabTip.center().x(), rectTabTip.bottom());
}
else
{
gradTip.setStart(rectTabTip.left(), rectTabTip.center().y());
gradTip.setFinalStop(rectTabTip.right(), rectTabTip.center().y());
}
gradTip.setColorAt( 0, colorStart );
gradTip.setColorAt( 1.f, colorEnd );
painter.setBrush(Qt::NoBrush);
painter.setPen( QPen(QColor(160,160,160,100), 2.f) );
painter.drawPath( tabPath );
painter.setPen( QPen(QColor(160,160,160)) );
painter.drawPath( tabPath );
painter.setPen( Qt::white );
if( bActive )
painter.drawLine( rectTab.bottomLeft(), rectTab.bottomRight() );
painter.fillPath( tabS, QBrush(gradTip) );
if (bActive || bHover)
{
painter.setPen( colorStart );
painter.drawPath( tabS );
}
QRectF rectText;
float fTextOffset = 0.f;
if (m_bHorz)
{
rectText.setX((float)rectTab.x() + fTextOffset);
rectText.setY((float)rectTab.y() + nDiameter/2);
rectText.setWidth((float)rectTab.width() - fTextOffset);
rectText.setHeight((float)rectTab.height() - nDiameter/2);
}
else
{
rectText.setX((float)rectTab.x() + nDiameter/2 + fTextOffset);
rectText.setY((float)rectTab.y());
rectText.setWidth((float)rectTab.width() - nDiameter/2 - fTextOffset);
rectText.setHeight((float)rectTab.height());
}
QFont fnt( font() );
fnt.setBold(bActive);
painter.setFont( fnt );
int flags = Qt::AlignCenter|Qt::AlignVCenter|Qt::TextSingleLine;
painter.setPen( QColor(80,80,80) );
painter.drawText( rectText, flags, tabText(i) );
if( m_nBlinkIndex == i && m_bBlinkFalg )
{
painter.fillPath( tabPath, QColor(240,240,0,128) );
}
}
painter.end();
}
示例7: render
void Printer::render(int Pages = 0)
{
// keep original preferences
QPointer<ProfileWidget2> profile = MainWindow::instance()->graphics();
int profileFrameStyle = profile->frameStyle();
int animationOriginal = prefs.animation_speed;
double fontScale = profile->getFontPrintScale();
double printFontScale = 1.0;
// apply printing settings to profile
profile->setFrameStyle(QFrame::NoFrame);
profile->setPrintMode(true, !printOptions->color_selected);
profile->setToolTipVisibile(false);
prefs.animation_speed = 0;
// render the Qwebview
QPainter painter;
QRect viewPort(0, 0, pageSize.width(), pageSize.height());
painter.begin(paintDevice);
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
// get all refereces to diveprofile class in the Html template
QWebElementCollection collection = webView->page()->mainFrame()->findAllElements(".diveprofile");
QSize originalSize = profile->size();
if (collection.count() > 0) {
printFontScale = (double)collection.at(0).geometry().size().height() / (double)profile->size().height();
profile->resize(collection.at(0).geometry().size());
}
profile->setFontPrintScale(printFontScale);
int elemNo = 0;
for (int i = 0; i < Pages; i++) {
// render the base Html template
webView->page()->mainFrame()->render(&painter, QWebFrame::ContentsLayer);
// render all the dive profiles in the current page
while (elemNo < collection.count() && collection.at(elemNo).geometry().y() < viewPort.y() + viewPort.height()) {
// dive id field should be dive_{{dive_no}} se we remove the first 5 characters
QString diveIdString = collection.at(elemNo).attribute("id");
int diveId = diveIdString.remove(0, 5).toInt(0, 10);
putProfileImage(collection.at(elemNo).geometry(), viewPort, &painter, get_dive_by_uniq_id(diveId), profile);
elemNo++;
}
// scroll the webview to the next page
webView->page()->mainFrame()->scroll(0, pageSize.height());
viewPort.adjust(0, pageSize.height(), 0, pageSize.height());
// rendering progress is 4/5 of total work
emit(progessUpdated((i * 80.0 / Pages) + done));
if (i < Pages - 1 && printMode == Printer::PRINT)
static_cast<QPrinter*>(paintDevice)->newPage();
}
painter.end();
// return profle settings
profile->setFrameStyle(profileFrameStyle);
profile->setPrintMode(false);
profile->setFontPrintScale(fontScale);
profile->setToolTipVisibile(true);
profile->resize(originalSize);
prefs.animation_speed = animationOriginal;
//replot the dive after returning the settings
profile->plotDive(0, true);
}
示例8: on_chooseCube_editingFinished
void MainWindow::on_chooseCube_editingFinished()
{
ui->divideButton->clicked();
ui->picLabelRoi->clear();
int num_cube = ui->chooseCube->value();
if(num_cube > 0 && num_cube <= cubeRow * cubeCol)
{
//find cube in pic
int num_row = (num_cube - 1) / cubeCol;//start at 0
int num_col = (num_cube - 1) % cubeCol; // start at 0
//qDebug() << "row,col:" << num_row << num_col;
chooseCubeColor = image_resize(cv::Rect(num_col*3,num_row*3,3,3));//cube what we choose
// //painting roi
// float multiple = (float)imgScaled.width() / (float)image_resize.size().width;
// QPicture picture0;
// QPainter painter0;
// QPen pen_roi;
// pen_roi.setColor(Qt::red);
// pen_roi.setWidth(2);
// painter0.begin(&picture0);
// painter0.setPen(pen_roi);
// //painting red Roi
// painter0.drawRect(QRectF(num_col*3*multiple,num_row*3*multiple,3*multiple,3*multiple));
// //qDebug() << QRectF(num_col*3*multiple,num_row*3*multiple,3*multiple,3*multiple);
// painter0.end();
// picture0.save("draw_roi.pic");
// ui->picLabelRoi->setPicture(picture0);
//painting cube
QPicture picture;
QPainter painter;
QPen pen_cube;
pen_cube.setColor(Qt::black);
pen_cube.setWidth(2);
painter.begin(&picture);
painter.setPen(pen_cube);
QBrush brush(Qt::SolidPattern);
//painting choose cube
int block_size = 40;
for(int i = 0; i < 9; i++)
{
//qDebug() << "RGB:" << chooseCubeColor.at<Vec3b>(i/3,i%3).val[0]<<chooseCubeColor.at<Vec3b>(i/3,i%3).val[1]<<chooseCubeColor.at<Vec3b>(i/3,i%3).val[2];
brush.setColor(QColor(chooseCubeColor.at<Vec3b>(i/3,i%3).val[0],chooseCubeColor.at<Vec3b>(i/3,i%3).val[1],chooseCubeColor.at<Vec3b>(i/3,i%3).val[2]));//RGB 3 channels
painter.setBrush(brush);
painter.drawRoundRect(QRect(block_size*i%(block_size*3),block_size*(i/3),block_size,block_size));
}
painter.end();
picture.save("draw_cube.pic");
ui->showCubeChoose->setPicture(picture);
//store colors of cube
for(int i = 0; i < 9; i++)
{
QColor qcolor = QColor(chooseCubeColor.at<Vec3b>(i/3,i%3).val[0],chooseCubeColor.at<Vec3b>(i/3,i%3).val[1],chooseCubeColor.at<Vec3b>(i/3,i%3).val[2]);//RGB 3 channels
int color_num;
if(qcolor == colorTable_cube[0])
color_num = 0;
else if(qcolor == colorTable_cube[1])
color_num = 1;
else if(qcolor == colorTable_cube[2])
color_num = 2;
else if(qcolor == colorTable_cube[3])
color_num = 3;
else if(qcolor == colorTable_cube[4])
color_num = 4;
else if(qcolor == colorTable_cube[5])
color_num = 5;
else
color_num = -1;
col[i] = RubikColor(color_num);
//qDebug() << "color:" << color_num;
}
dlg.setRubikColor(col);
}
else
{
int ret = QMessageBox::warning(this, "Warning", "Please choose the cube you want to make!", QMessageBox::Abort);
if (ret == QMessageBox::Abort)
qDebug() << "WARNING!!";
}
}
示例9: bandageImage
int bandageImage(QStringList arguments)
{
QTextStream out(stdout);
QTextStream err(stderr);
if (checkForHelp(arguments))
{
printImageUsage(&out, false);
return 0;
}
if (checkForHelpAll(arguments))
{
printImageUsage(&out, true);
return 0;
}
if (arguments.size() < 2)
{
printImageUsage(&err, false);
return 1;
}
QString graphFilename = arguments.at(0);
arguments.pop_front();
if (!checkIfFileExists(graphFilename))
{
err << "Bandage error: " << graphFilename << " does not exist" << endl;
return 1;
}
QString imageSaveFilename = arguments.at(0);
arguments.pop_front();
QString imageFileExtension = imageSaveFilename.right(4);
bool pixelImage;
if (imageFileExtension == ".png" || imageFileExtension == ".jpg")
pixelImage = true;
else if (imageFileExtension == ".svg")
pixelImage = false;
else
{
err << "Bandage error: the output filename must end in .png, .jpg or .svg" << endl;
return 1;
}
QString error = checkForInvalidImageOptions(arguments);
if (error.length() > 0)
{
err << "Bandage error: " << error << endl;
return 1;
}
bool loadSuccess = g_assemblyGraph->loadGraphFromFile(graphFilename);
if (!loadSuccess)
{
err << "Bandage error: could not load " << graphFilename << endl;
return 1;
}
int width = 0;
int height = 0;
parseImageOptions(arguments, &width, &height);
//For Bandage image, it is necessary to position node labels at the
//centre of the node, not the visible centre(s). This is because there
//is no viewport.
g_settings->positionTextNodeCentre = true;
//Since frame rate performance doesn't matter for a fixed image, set the
//default node outline to a nonzero value.
g_settings->outlineThickness = 0.3;
bool blastUsed = isOptionPresent("--query", &arguments);
if (blastUsed)
{
if (!createBlastTempDirectory())
{
err << "Error creating temporary directory for BLAST files" << endl;
return 1;
}
QString blastError = g_blastSearch->doAutoBlastSearch();
if (blastError != "")
{
err << blastError << endl;
return 1;
}
}
QString errorTitle;
QString errorMessage;
std::vector<DeBruijnNode *> startingNodes = g_assemblyGraph->getStartingNodes(&errorTitle, &errorMessage,
g_settings->doubleMode,
g_settings->startingNodes,
"all");
//.........这里部分代码省略.........
示例10: fillPixmap
void dialogAnalog::fillPixmap(CData *data, QPen *dataPen)
{
mainwindow->analogMutex.lock();
TAnalog_Data plot,next_plot;
QPainter painter;
int heightPerField = lastPixmap.height() / NbBits;
painter.begin(&lastPixmap);
painter.setPen(*dataPen);
QVector< QVector<QPoint> > polyline(64);
Qt::CheckState csMarker = chkBShowMarker->checkState();
for (int j=1;j<data->size();j++)
{
plot = data->Read(j-1);
next_plot = data->Read(j);
int current = heightPerField;
int X1,Y1,X2,Y2;
X1=StateToX(plot.state);
X2=StateToX(next_plot.state);
// Crop to the visible area
if (!( (j>1) && ( (X2<0) || ( X1>frame_dataview->width())))) {
for (int jj=0;jj<NbBits;jj++)
{
//#define READ_BIT(b,p) ( ((b)>>(p)) & 0x01 ? 1 :0 )
Y1= current - READ_BIT(plot.values,jj)* 3 * heightPerField / 5;
Y2= current - READ_BIT(next_plot.values,jj)* 3 * heightPerField / 5;
//painter.drawLine(X1,Y1,X2,Y1);
//painter.drawLine(X2,Y1,X2,Y2);
polyline[jj].append( QPoint(X1,Y1) );
polyline[jj].append( QPoint(X2,Y1) );
current += heightPerField;
}
// plot the Markers
// Need to optimize
if ( plot.marker && (csMarker == Qt::Checked) ) {
QPen pen((Qt::white));
pen.setStyle(Qt::DotLine);
painter.setPen(pen);
painter.drawLine(X1,12,X1,height());
// set font ------------------------------------------------------------------------------------
QFont textFont;
textFont.setPixelSize(10);
painter.setFont(textFont);
painter.drawText(X1, 11, QString::number(plot.marker,10));
painter.setPen(*dataPen);
}
}
}
if (polyline.size()) {
for (int jj=0;jj<NbBits;jj++)
{
if (polyline[jj].size())
painter.drawPolyline(polyline[jj].data(),polyline[jj].size());
}
}
painter.end();
mainwindow->analogMutex.unlock();
}
示例11: TriggerMapRendering
void DBThread::TriggerMapRendering()
{
RenderMapRequest request;
{
QMutexLocker locker(&mutex);
request=currentRenderRequest;
if (!doRender) {
return;
}
renderBreaker->Reset();
}
if (currentImage==NULL ||
currentImage->width()!=(int)request.width ||
currentImage->height()!=(int)request.height) {
delete currentImage;
currentImage=new QImage(QSize(request.width,request.height),QImage::Format_RGB32);
}
currentLon=request.lon;
currentLat=request.lat;
currentAngle=request.angle;
currentMagnification=request.magnification;
QPainter p;
if (database->IsOpen() &&
styleConfig) {
osmscout::MapParameter drawParameter;
osmscout::AreaSearchParameter searchParameter;
searchParameter.SetBreaker(renderBreakerRef);
searchParameter.SetMaximumAreaLevel(4);
searchParameter.SetUseMultithreading(currentMagnification.GetMagnification()<=osmscout::Magnification::magCity);
std::list<std::string> paths;
paths.push_back(iconDirectory.toLocal8Bit().data());
drawParameter.SetIconPaths(paths);
drawParameter.SetPatternPaths(paths);
drawParameter.SetDebugPerformance(true);
drawParameter.SetOptimizeWayNodes(osmscout::TransPolygon::quality);
drawParameter.SetOptimizeAreaNodes(osmscout::TransPolygon::quality);
drawParameter.SetRenderSeaLand(true);
drawParameter.SetBreaker(renderBreakerRef);
double fs = drawParameter.GetFontSize();
QSettings s;
double fsMul = s.value("fontSize", 1).toDouble();
qDebug()<<"FontSize: "<<fs;
qDebug()<<"DPI:" << dpi;
fs*=(dpi/50)*fsMul; //for 100DPI, multiply by 1.5
drawParameter.SetFontSize(fs);
std::cout << std::endl;
osmscout::StopClock overallTimer;
projection.Set(currentLon,
currentLat,
currentAngle,
currentMagnification,
dpi,
request.width,
request.height);
osmscout::StopClock dataRetrievalTimer;
mapService->GetObjects(searchParameter,
styleConfig,
projection,
data);
if (drawParameter.GetRenderSeaLand()) {
mapService->GetGroundTiles(projection,
data.groundTiles);
}
dataRetrievalTimer.Stop();
osmscout::StopClock drawTimer;
p.begin(currentImage);
p.setRenderHint(QPainter::Antialiasing);
p.setRenderHint(QPainter::TextAntialiasing);
p.setRenderHint(QPainter::SmoothPixmapTransform);
painter->DrawMap(projection,
drawParameter,
data,
&p);
p.end();
drawTimer.Stop();
//.........这里部分代码省略.........
示例12: paintEvent
void RulerT::paintEvent(QPaintEvent *)
{
double xl;
QPainter p;
p.begin(this);
p.drawLine(0, 24, width(), 24);
p.translate(-offset, 0);
p.setBrush(Qt::black);
p.setFont(font());
p.setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
for (xl = 0; xl < width()+offset; xl += iter)
{
if (xl < offset)
continue;
p.drawLine(qRound(xl), 18, qRound(xl), 24);
}
for (xl = 0; xl < width()+(iter2/2)+offset; xl += iter2)
{
if (xl < offset)
continue;
p.drawLine(qRound(xl), 11, qRound(xl), 24);
switch (unitIndex)
{
case 2:
{
QString tx = "";
int num1 = static_cast<int>(xl / iter2);
if (num1 != 0)
tx = QString::number(num1);
double frac = (xl / iter2) - num1;
if ((frac > 0.24) && (frac < 0.26))
tx += QChar(0xBC);
if ((frac > 0.49) && (frac < 0.51))
tx += QChar(0xBD);
if ((frac > 0.74) && (frac < 0.76))
tx += QChar(0xBE);
p.drawText(qRound(xl+2), 17, tx);
break;
}
case 3:
p.drawText(qRound(xl+2), 17, QString::number(xl / iter));
break;
default:
p.drawText(qRound(xl+2), 17, QString::number(xl / iter * 10));
break;
}
}
if (tabValues.count() != 0)
{
for (int yg = 0; yg < static_cast<int>(tabValues.count()); yg++)
{
if (yg == actTab)
p.setPen(QPen(Qt::red, 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
else
p.setPen(QPen(Qt::black, 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
switch (static_cast<int>(tabValues[yg].tabType))
{
case 0:
p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23);
p.drawLine(qRound(tabValues[yg].tabPosition), 23, qRound(tabValues[yg].tabPosition+8), 23);
break;
case 1:
p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23);
p.drawLine(qRound(tabValues[yg].tabPosition), 23, qRound(tabValues[yg].tabPosition-8), 23);
break;
case 2:
case 3:
p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23);
p.drawLine(qRound(tabValues[yg].tabPosition-4), 23, qRound(tabValues[yg].tabPosition+4), 23);
p.drawLine(qRound(tabValues[yg].tabPosition+3), 20, qRound(tabValues[yg].tabPosition+2), 20);
break;
case 4:
p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23);
p.drawLine(qRound(tabValues[yg].tabPosition-4), 23, qRound(tabValues[yg].tabPosition+4), 23);
break;
default:
break;
}
}
}
if (haveInd)
{
p.setPen(QPen(Qt::blue, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
p.setBrush(Qt::blue);
QPolygon cr;
cr.setPoints(3, qRound(firstLine+leftIndent), 12, qRound(firstLine+leftIndent-4), 0, qRound(firstLine+leftIndent+4), 0);
p.drawPolygon(cr);
QPolygon cr2;
cr2.setPoints(3, qRound(leftIndent), 12, qRound(leftIndent+4), 24, qRound(leftIndent-4), 24);
p.drawPolygon(cr2);
}
p.end();
}
示例13: createDiagram
QImage* QgsPieDiagramFactory::createDiagram( int size, const QgsFeature& f, const QgsRenderContext& renderContext ) const
{
QgsAttributeMap dataValues = f.attributeMap();
double sizeScaleFactor = diagramSizeScaleFactor( renderContext );
//create transparent QImage
int imageSideLength = size * sizeScaleFactor * renderContext.rasterScaleFactor() + 2 * mMaximumPenWidth + 2 * mMaximumGap;
QImage* diagramImage = new QImage( QSize( imageSideLength, imageSideLength ), QImage::Format_ARGB32_Premultiplied );
diagramImage->fill( qRgba( 0, 0, 0, 0 ) ); //transparent background
QPainter p;
p.begin( diagramImage );
p.setRenderHint( QPainter::Antialiasing );
p.setPen( Qt::NoPen );
//calculate sum of data values
double sum = 0;
QList<double> valueList; //cash the values to use them in drawing later
QgsAttributeMap::const_iterator value_it;
QList<QgsDiagramCategory>::const_iterator it = mCategories.constBegin();
for ( ; it != mCategories.constEnd(); ++it )
{
value_it = dataValues.find( it->propertyIndex() );
valueList.push_back( value_it->toDouble() );
if ( value_it != dataValues.constEnd() )
{
sum += value_it->toDouble();
}
}
if ( doubleNear( sum, 0.0 ) )
{
p.end();
delete diagramImage;
return 0;
}
//draw pies
int totalAngle = 0;
int currentAngle, currentGap;
int xGapOffset = 0;
int yGapOffset = 0;
QList<QgsDiagramCategory>::const_iterator category_it = mCategories.constBegin();
QList<double>::const_iterator valueList_it = valueList.constBegin();
for ( ; category_it != mCategories.constEnd() && valueList_it != valueList.constEnd(); ++category_it, ++valueList_it )
{
p.setPen( category_it->pen() );
currentAngle = ( int )(( *valueList_it ) / sum * 360 * 16 );
p.setBrush( category_it->brush() );
xGapOffset = 0;
yGapOffset = 0;
currentGap = category_it->gap();
if ( currentGap != 0 )
{
//qt angles are degrees*16
gapOffsetsForPieSlice( currentGap, totalAngle + currentAngle / 2, xGapOffset, yGapOffset );
}
p.drawPie( mMaximumPenWidth * renderContext.rasterScaleFactor() + mMaximumGap + xGapOffset, mMaximumPenWidth * renderContext.rasterScaleFactor() + mMaximumGap - yGapOffset, sizeScaleFactor * renderContext.rasterScaleFactor() * size, sizeScaleFactor * renderContext.rasterScaleFactor() * size, totalAngle, currentAngle );
totalAngle += currentAngle;
}
p.end();
return diagramImage;
}
示例14: on_divideButton_clicked
void MainWindow::on_divideButton_clicked()
{
cubeRow = ui->cubeRow->value();
cubeCol = ui->cubeCol->value();
if(cubeRow*cubeCol >= 4 && !filename.isEmpty() && image_origin.rows >= cubeRow*3 && image_origin.cols >= cubeCol*3)
{
//I. divide image
//1.prepare
//int largeSquare = (int)floor(sqrt(cubeNum));//get the largest square that can be made
//qDebug() << "largeSquare:" <<largeSquare;
float picRatio = (float)image_origin.rows / (float)image_origin.cols;//row行数col列数
//qDebug() << "picRatio:" <<picRatio;
float cubeRatio = (float)cubeRow / (float)cubeCol;
int scale, fixedCol, fixedRow;
if(picRatio >= cubeRatio)//row long
{
scale = image_origin.cols/(cubeCol*3);//img size devide cube's totol col
fixedRow = scale*cubeRow*3;//set the size corresponding cube's
fixedCol = scale*cubeCol*3;
}
else//col long
{
scale = image_origin.rows/(cubeRow*3);
fixedRow = scale*cubeRow*3;
fixedCol = scale*cubeCol*3;
}
int removeRows = image_origin.rows - fixedRow;
int removeCols = image_origin.cols - fixedCol;
//qDebug()<<"scale:"<<scale<<" row:"<<fixedRow<<" col:"<<fixedCol<<" Original resolution:"<<image_origin.rows<<image_origin.cols<<" remove:"<<removeRows<<removeCols;
int removeRows_top,removeRows_down,removeCols_left,removeCols_right;
if(removeRows%2 != 0)//the remove num of rows is not even number
{
//up need remove one more than down
removeRows_top = removeRows/2 + 1;
removeRows_down = removeRows/2;
}
else
removeRows_top = removeRows_down = removeRows/2;
if(removeCols%2 != 0)//the remove num of cols is not even number
{
//left need remove one more than right
removeCols_left = removeCols/2 + 1;
removeCols_right = removeCols/2;
}
else
removeCols_left = removeCols_right = removeCols/2;
//qDebug()<<"removeRow_fixed:"<<removeRows_top<<removeRows_down<<"removeCol_fixed:"<<removeCols_left<<removeCols_right;
cv::Mat fixedImage = image_origin(Rect(removeCols_left,removeRows_top,fixedCol,fixedRow));//改好大小的图片
//resize the image
cv::Size dsize = cv::Size(cubeCol*3,cubeRow*3);//Image resolution of the match cube ratio
//cv::Mat image_resize = fixedImage;
cv::resize(fixedImage, image_resize, dsize);
image_resize = changeRubixColor(image_resize);
cv::cvtColor(image_resize, image_resize, CV_BGR2RGB);
//image_resize---->this is what we want!!!!
QImage QimgResize = QImage((const unsigned char*)(image_resize.data),image_resize.cols,image_resize.rows, image_resize.cols*image_resize.channels(), QImage::Format_RGB888);
//qDebug() << "QimgResizeRect:" << QimgResize.rect();
ui->picLabel->clear();
imgScaled = QimgResize.scaled(ui->picLabel->size(),Qt::KeepAspectRatio);
//qDebug() << "imgScaledRect:" << imgScaled.rect();
ui->picLabel->setPixmap(QPixmap::fromImage(imgScaled));//image insert into label
/*--------------------------drawing grids----------------------------*/
QPicture picture;
QPainter painter;
QPen pen_thick,pen_thin;
pen_thick.setWidth(3);
pen_thick.setColor(Qt::gray);
pen_thin.setWidth(1);
pen_thin.setColor(Qt::gray);
painter.begin(&picture);
picture.setBoundingRect(imgScaled.rect()); //set the boundary of painting
//draw col line
painter.setPen(pen_thin);
for(int i = 0; i <= cubeCol*3; i++)
painter.drawLine(QLineF((float)imgScaled.rect().width()/cubeCol/3.0*i, 0, (float)imgScaled.rect().width()/cubeCol/3.0*i, imgScaled.rect().height()));
painter.setPen(pen_thick);
for(int i = 0; i <= cubeCol; i++)
painter.drawLine(QLineF((float)imgScaled.rect().width()/cubeCol*i, 0, (float)imgScaled.rect().width()/cubeCol*i, imgScaled.rect().height()));
//draw row line
painter.setPen(pen_thin);
for(int i = 0; i <= cubeRow*3; i++)
painter.drawLine(QLineF(0, (float)imgScaled.rect().height()/cubeRow/3.0*i, imgScaled.rect().width(), (float)imgScaled.rect().height()/cubeRow/3.0*i));
painter.setPen(pen_thick);
for(int i = 0; i <= cubeRow; i++)
painter.drawLine(QLineF(0, (float)imgScaled.rect().height()/cubeRow*i, imgScaled.rect().width(), (float)imgScaled.rect().height()/cubeRow*i));
painter.end();
picture.save("draw_record.pic");
ui->picLabelUp->setPicture(picture);
}
else if(cubeRow*cubeCol < 4)
{
int ret = QMessageBox::warning(this, "Warning", "The number of cubes is at least four!", QMessageBox::Abort);
//.........这里部分代码省略.........
示例15: rect
void
PlayField::mouseMoveEvent(QMouseEvent *e) {
lastMouseXPos_ = e->x();
lastMouseYPos_ = e->y();
if (!dragInProgress_) return highlight();
int old_x = dragX_, old_y = dragY_;
dragX_ = lastMouseXPos_ - mousePosX_;
dragY_ = lastMouseYPos_ - mousePosY_;
{
int x = pixel2x(dragX_ + size_/2);
int y = pixel2y(dragY_ + size_/2);
if (x >= 0 && x < levelMap_->width() &&
y >= 0 && y < levelMap_->height() &&
pathFinder_.canDragTo(x, y)) {
x = x2pixel(x);
y = y2pixel(y);
if (dragX_ >= x - size_/4 &&
dragX_ < x + size_/4 &&
dragY_ >= y - size_/4 &&
dragY_ < y + size_/4) {
dragX_ = x;
dragY_ = y;
}
}
}
if (dragX_ == old_x && dragY_ == old_y) return;
QRect rect(dragX_, dragY_, size_, size_);
dragXpm_= QPixmap(size_, size_);
QPainter paint;
paint.begin(&dragXpm_);
paint.setBackground(palette().color(backgroundRole()));
paint.setBrushOrigin(- dragX_, - dragY_);
paint.translate((double) (- dragX_), (double) (- dragY_));
paintPainter(paint, rect);
paint.end();
dragImage_ = dragXpm_.toImage();
for (int yy=0; yy<size_; yy++) {
for (int xx=0; xx<size_; xx++) {
QRgb rgb1 = imageData_->objectImg().pixel(xx, yy);
int r1 = qRed(rgb1);
int g1 = qGreen(rgb1);
int b1 = qBlue(rgb1);
if (r1 != g1 || r1 != b1 || r1 == 255) {
QRgb rgb2 = dragImage_.pixel(xx, yy);
int r2 = qRed(rgb2);
int g2 = qGreen(rgb2);
int b2 = qBlue(rgb2);
r2 = (int) (0.75 * r1 + 0.25 * r2 + 0.5);
g2 = (int) (0.75 * g1 + 0.25 * g2 + 0.5);
b2 = (int) (0.75 * b1 + 0.25 * b2 + 0.5);
dragImage_.setPixel(xx, yy, qRgb(r2, g2, b2));
}
}
}
paint.begin(this);
// the following line is a workaround for a bug in Qt 2.0.1
// (and possibly earlier versions)
paint.setBrushOrigin(0, 0);
dragXpm_ = QPixmap::fromImage(dragImage_,
Qt::OrderedDither|Qt::OrderedAlphaDither|
Qt::ColorOnly|Qt::AvoidDither);
paint.drawPixmap(dragX_, dragY_, dragXpm_);
{
int dx = dragX_ - old_x;
int dy = dragY_ - old_y;
int y2 = old_y;
if (dy > 0) {
paintPainterClip(paint, old_x, old_y, size_, dy);
// NOTE: clipping is now activated in the QPainter paint
y2 += dy;
} else if (dy < 0) {
paintPainterClip(paint, old_x, old_y+size_+dy, size_, -dy);
// NOTE: clipping is now activated in the QPainter paint
dy = -dy;
}
if (dx > 0) {
paintPainterClip(paint, old_x, y2, dx, size_-dy);
// NOTE: clipping is now activated in the QPainter paint
} else if (dx < 0) {
paintPainterClip(paint, old_x+size_+dx, y2, -dx, size_-dy);
// NOTE: clipping is now activated in the QPainter paint
}
}
paint.end();
}