void ControlView::printMapScreenShot( QPointer<QPrintDialog> printDialog) { #ifndef QT_NO_PRINTER PrintOptionsWidget* printOptions = new PrintOptionsWidget( this ); bool const mapCoversViewport = m_marbleWidget->viewport()->mapCoversViewport(); printOptions->setBackgroundControlsEnabled( !mapCoversViewport ); bool hasLegend = m_marbleWidget->model()->legend() != 0; printOptions->setLegendControlsEnabled( hasLegend ); bool hasRoute = marbleWidget()->model()->routingManager()->routingModel()->rowCount() > 0; printOptions->setPrintRouteSummary( hasRoute ); printOptions->setPrintDrivingInstructions( hasRoute ); printOptions->setPrintDrivingInstructionsAdvice( hasRoute ); printOptions->setRouteControlsEnabled( hasRoute ); printDialog->setOptionTabs( QList<QWidget*>() << printOptions ); if ( printDialog->exec() == QDialog::Accepted ) { QTextDocument document; QString text = "<html><head><title>Marble Printout</title></head><body>"; QPalette const originalPalette = m_marbleWidget->palette(); bool const wasBackgroundVisible = m_marbleWidget->showBackground(); bool const hideBackground = !mapCoversViewport && !printOptions->printBackground(); if ( hideBackground ) { // Temporarily remove the black background and layers painting on it m_marbleWidget->setShowBackground( false ); m_marbleWidget->setPalette( QPalette ( Qt::white ) ); m_marbleWidget->update(); } if ( printOptions->printMap() ) { printMap( document, text, printDialog->printer() ); } if ( printOptions->printLegend() ) { printLegend( document, text ); } if ( printOptions->printRouteSummary() ) { printRouteSummary( document, text ); } if ( printOptions->printDrivingInstructions() ) { printDrivingInstructions( document, text ); } if ( printOptions->printDrivingInstructionsAdvice() ) { printDrivingInstructionsAdvice( document, text ); } text += "</body></html>"; document.setHtml( text ); document.print( printDialog->printer() ); if ( hideBackground ) { m_marbleWidget->setShowBackground( wasBackgroundVisible ); m_marbleWidget->setPalette( originalPalette ); m_marbleWidget->update(); } } #endif }
void GamesItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { painter->save(); QString gameName = qvariant_cast<QString>(index.data(ROLE_NAME)); QString viewers = qvariant_cast<QString>(index.data(ROLE_VIEWERS)); QString channels_nr = qvariant_cast<QString>(index.data(ROLE_CHANNEL_NR)); QRect iconRect = option.rect; QRect gameNameRect = option.rect; QRect viewersRect = option.rect; QRect viewersLegendRect = option.rect; QRect channelsRect = option.rect; QRect channelsLegendRect = option.rect; printIcon(iconRect, painter, index); setRightOf(iconRect,gameNameRect); printHeader(gameNameRect,gameName,painter); setUnder(gameNameRect, viewersLegendRect); printLegend(viewersLegendRect,viewersLegend,painter); setRightOf(viewersLegendRect,viewersRect); printText(viewersRect,viewers,painter); setRightOf(viewersRect,channelsLegendRect); printLegend(channelsLegendRect,channelsLegend,painter); setRightOf(channelsLegendRect,channelsRect); printText(channelsRect,channels_nr,painter); // focus elements drawFocus(painter, option, option.rect); painter->restore(); }
/*! \brief Paint the plot into a given rectangle. Paint the contents of a QwtPlot instance into a given rectangle. \param painter Painter \param plotRect Bounding rectangle \param pfilter Print filter \sa QwtPlotPrintFilter */ void QwtPlot::print(QPainter *painter, const QRect &plotRect, const QwtPlotPrintFilter &pfilter) const { int axisId; if ( painter == 0 || !painter->isActive() || !plotRect.isValid() || size().isNull() ) return; painter->save(); #if 1 /* PDF: In Qt4 ( <= 4.3.2 ) the scales are painted in gray instead of black. See http://trolltech.com/developer/task-tracker/index_html?id=184671&method=entry The dummy lines below work around the problem. */ const QPen pen = painter->pen(); painter->setPen(QPen(Qt::black, 1)); painter->setPen(pen); #endif // All paint operations need to be scaled according to // the paint device metrics. QwtPainter::setMetricsMap(this, painter->device()); const QwtMetricsMap &metricsMap = QwtPainter::metricsMap(); // It is almost impossible to integrate into the Qt layout // framework, when using different fonts for printing // and screen. To avoid writing different and Qt unconform // layout engines we change the widget attributes, print and // reset the widget attributes again. This way we produce a lot of // useless layout events ... pfilter.apply((QwtPlot *)this); int baseLineDists[QwtPlot::axisCnt]; if ( pfilter.options() & QwtPlotPrintFilter::PrintFrameWithScales ) { for (axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) { QwtScaleWidget *scaleWidget = (QwtScaleWidget *)axisWidget(axisId); if ( scaleWidget ) { baseLineDists[axisId] = scaleWidget->margin(); scaleWidget->setMargin(0); } } } // Calculate the layout for the print. int layoutOptions = QwtPlotLayout::IgnoreScrollbars | QwtPlotLayout::IgnoreFrames; if ( !(pfilter.options() & QwtPlotPrintFilter::PrintMargin) ) layoutOptions |= QwtPlotLayout::IgnoreMargin; if ( !(pfilter.options() & QwtPlotPrintFilter::PrintLegend) ) layoutOptions |= QwtPlotLayout::IgnoreLegend; ((QwtPlot *)this)->plotLayout()->activate(this, QwtPainter::metricsMap().deviceToLayout(plotRect), layoutOptions); if ((pfilter.options() & QwtPlotPrintFilter::PrintTitle) && (!titleLabel()->text().isEmpty())) { printTitle(painter, plotLayout()->titleRect()); } if ( (pfilter.options() & QwtPlotPrintFilter::PrintLegend) && legend() && !legend()->isEmpty() ) { printLegend(painter, plotLayout()->legendRect()); } for ( axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) { QwtScaleWidget *scaleWidget = (QwtScaleWidget *)axisWidget(axisId); if (scaleWidget) { int baseDist = scaleWidget->margin(); int startDist, endDist; scaleWidget->getBorderDistHint(startDist, endDist); printScale(painter, axisId, startDist, endDist, baseDist, plotLayout()->scaleRect(axisId)); } } QRect canvasRect = plotLayout()->canvasRect(); /* The border of the bounding rect needs to ba scaled to layout coordinates, so that it is aligned to the axes */ QRect boundingRect( canvasRect.left() - 1, canvasRect.top() - 1, canvasRect.width() + 2, canvasRect.height() + 2); boundingRect = metricsMap.layoutToDevice(boundingRect); boundingRect.setWidth(boundingRect.width() - 1); boundingRect.setHeight(boundingRect.height() - 1); canvasRect = metricsMap.layoutToDevice(canvasRect); // When using QwtPainter all sizes where computed in pixel // coordinates and scaled by QwtPainter later. This limits // the precision to screen resolution. A better solution // is to scale the maps and print in unlimited resolution. QwtScaleMap map[axisCnt]; for (axisId = 0; axisId < axisCnt; axisId++) { map[axisId].setTransformation(axisScaleEngine(axisId)->transformation()); const QwtScaleDiv &scaleDiv = *axisScaleDiv(axisId); map[axisId].setScaleInterval(scaleDiv.lBound(), scaleDiv.hBound()); double from, to; if ( axisEnabled(axisId) ) { const int sDist = axisWidget(axisId)->startBorderDist(); const int eDist = axisWidget(axisId)->endBorderDist(); const QRect &scaleRect = plotLayout()->scaleRect(axisId); if ( axisId == xTop || axisId == xBottom ) { from = metricsMap.layoutToDeviceX(scaleRect.left() + sDist); to = metricsMap.layoutToDeviceX(scaleRect.right() + 1 - eDist); } else { from = metricsMap.layoutToDeviceY(scaleRect.bottom() + 1 - eDist ); to = metricsMap.layoutToDeviceY(scaleRect.top() + sDist); } } else { int margin = plotLayout()->canvasMargin(axisId); if ( axisId == yLeft || axisId == yRight ) { margin = metricsMap.layoutToDeviceY(margin); from = canvasRect.bottom() - margin; to = canvasRect.top() + margin; } else { margin = metricsMap.layoutToDeviceX(margin); from = canvasRect.left() + margin; to = canvasRect.right() - margin; } } map[axisId].setPaintXInterval(from, to); } // The canvas maps are already scaled. QwtPainter::setMetricsMap(painter->device(), painter->device()); printCanvas(painter, boundingRect, canvasRect, map, pfilter); QwtPainter::resetMetricsMap(); ((QwtPlot *)this)->plotLayout()->invalidate(); // reset all widgets with their original attributes. if ( pfilter.options() & QwtPlotPrintFilter::PrintFrameWithScales ) { // restore the previous base line dists for (axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) { QwtScaleWidget *scaleWidget = (QwtScaleWidget *)axisWidget(axisId); if ( scaleWidget ) scaleWidget->setMargin(baseLineDists[axisId]); } } pfilter.reset((QwtPlot *)this); painter->restore(); }
//********************************************************************************************************************** vector<string> HeatMapSim::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> calcs) { try { EstOutput data; vector<double> sims; vector<string> outputNames; //make file for each calculator selected for (int k = 0; k < calcs.size(); k++) { if (m->control_pressed) { return outputNames; } string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + calcs[k]->getName() + ".heatmap.sim.svg"; m->openOutputFile(filenamesvg, outsvg); outputNames.push_back(filenamesvg); //svg image outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString((lookup.size() * 150) + 160) + " " + toString((lookup.size() * 150) + 160) + "\">\n"; outsvg << "<g>\n"; //white backround outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString((lookup.size() * 150) + 160) + "\" height=\"" + toString((lookup.size() * 150) + 160) + "\"/>"; outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString((lookup.size() * 75) - 40) + "\" y=\"25\">Heatmap at distance " + lookup[0]->getLabel() + "</text>\n"; //column labels for (int h = 0; h < lookup.size(); h++) { outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(((150 * (h+1)) ) - ((int)lookup[h]->getGroup().length() / 2)) + "\" y=\"50\">" + lookup[h]->getGroup() + "</text>\n"; outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" y=\"" + toString(((150 * (h+1)) ) - ((int)lookup[h]->getGroup().length() / 2)) + "\" x=\"50\">" + lookup[h]->getGroup() + "</text>\n"; } sims.clear(); // double biggest = -1; double biggest = 1; float scaler; //get sim for each comparison and save them so you can find the relative similairity for(int i = 0; i < (lookup.size()-1); i++){ for(int j = (i+1); j < lookup.size(); j++){ if (m->control_pressed) { outsvg.close(); return outputNames; } vector<SharedRAbundVector*> subset; subset.push_back(lookup[i]); subset.push_back(lookup[j]); //get similairity between groups data = calcs[k]->getValues(subset); sims.push_back(1.0 - data[0]); //save biggest similairity to set relative sim // if (data[0] > biggest) { biggest = data[0]; } } } //map biggest similairity found to red scaler = 255.0 / biggest; int count = 0; //output similairites to file for(int i = 0; i < (lookup.size()-1); i++){ for(int j = (i+1); j < lookup.size(); j++){ //find relative color int color = scaler * sims[count]; //draw box outsvg << "<rect fill=\"rgb(" + toString(color) + ",0,0)\" stroke=\"rgb(" + toString(color) + ",0,0)\" x=\"" + toString((i*150)+80) + "\" y=\"" + toString((j*150)+75) + "\" width=\"150\" height=\"150\"/>\n"; count++; } } int y = ((lookup.size() * 150) + 120); printLegend(y, biggest); outsvg << "</g>\n</svg>\n"; outsvg.close(); } return outputNames; } catch(exception& e) { m->errorOut(e, "HeatMapSim", "getPic"); exit(1); } }
//********************************************************************************************************************** string HeatMapSim::getPic(vector< vector<double> > dists, vector<string> groups) { try { vector<double> sims; string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "heatmap.sim.svg"; m->openOutputFile(filenamesvg, outsvg); //svg image outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString((dists.size() * 150) + 160) + " " + toString((dists.size() * 150) + 160) + "\">\n"; outsvg << "<g>\n"; //white backround outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString((dists.size() * 150) + 160) + "\" height=\"" + toString((dists.size() * 150) + 160) + "\"/>"; outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString((dists.size() * 75) - 40) + "\" y=\"25\">Heatmap for " + inputfile + "</text>\n"; //column labels for (int h = 0; h < groups.size(); h++) { outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(((150 * (h+1)) ) - ((int)groups[h].length() / 2)) + "\" y=\"50\">" + groups[h] + "</text>\n"; outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" y=\"" + toString(((150 * (h+1)) ) - ((int)groups[h].length() / 2)) + "\" x=\"50\">" + groups[h] + "</text>\n"; } double biggest = -1; float scaler; //get sim for each comparison and save them so you can find the relative similairity for(int i = 0; i < (dists.size()-1); i++){ for(int j = (i+1); j < dists.size(); j++){ if (m->control_pressed) { outsvg.close(); return filenamesvg; } float sim = 1.0 - dists[i][j]; sims.push_back(sim); //save biggest similairity to set relative sim if (sim > biggest) { biggest = sim; } } } //map biggest similairity found to red scaler = 255.0 / biggest; int count = 0; //output similairites to file for(int i = 0; i < (dists.size()-1); i++){ for(int j = (i+1); j < dists.size(); j++){ //find relative color int color = scaler * sims[count]; //draw box outsvg << "<rect fill=\"rgb(" + toString(color) + ",0,0)\" stroke=\"rgb(" + toString(color) + ",0,0)\" x=\"" + toString((i*150)+80) + "\" y=\"" + toString((j*150)+75) + "\" width=\"150\" height=\"150\"/>\n"; count++; } } int y = ((dists.size() * 150) + 120); printLegend(y, biggest); outsvg << "</g>\n</svg>\n"; outsvg.close(); return filenamesvg; } catch(exception& e) { m->errorOut(e, "HeatMapSim", "getPic"); exit(1); } }
/*! \brief Paint the plot into a given rectangle. Paint the contents of a QwtPlot instance into a given rectangle. \param painter Painter \param plotRect Bounding rectangle \param pfilter Print filter \sa QwtPlotPrintFilter */ void QwtPlot::print(QPainter *painter, const QRect &plotRect, const QwtPlotPrintFilter &pfilter) const { int axisId; if ( painter == 0 || !painter->isActive() || !plotRect.isValid() || size().isNull() ) return; painter->save(); // All paint operations need to be scaled according to // the paint device metrics. QwtPainter::setMetricsMap(this, painter->device()); const QwtMetricsMap &metricsMap = QwtPainter::metricsMap(); // It is almost impossible to integrate into the Qt layout // framework, when using different fonts for printing // and screen. To avoid writing different and Qt unconform // layout engines we change the widget attributes, print and // reset the widget attributes again. This way we produce a lot of // useless layout events ... pfilter.apply((QwtPlot *)this); int baseLineDists[QwtPlot::axisCnt]; if ( !(pfilter.options() & QwtPlotPrintFilter::PrintCanvasBackground) ) { // In case of no background we set the backbone of // the scale on the frame of the canvas. for (axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) { QwtScaleWidget *scaleWidget = (QwtScaleWidget *)axisWidget(axisId); if ( scaleWidget ) { baseLineDists[axisId] = scaleWidget->baseLineDist(); scaleWidget->setBaselineDist(0); } } } // Calculate the layout for the print. int layoutOptions = QwtPlotLayout::IgnoreScrollbars | QwtPlotLayout::IgnoreFrames; if ( !(pfilter.options() & QwtPlotPrintFilter::PrintMargin) ) layoutOptions |= QwtPlotLayout::IgnoreMargin; if ( !(pfilter.options() & QwtPlotPrintFilter::PrintLegend) ) layoutOptions |= QwtPlotLayout::IgnoreLegend; ((QwtPlot *)this)->plotLayout()->activate(this, QwtPainter::metricsMap().deviceToLayout(plotRect), layoutOptions); if ((pfilter.options() & QwtPlotPrintFilter::PrintTitle) && (!titleLabel()->text().isEmpty())) { printTitle(painter, plotLayout()->titleRect()); } if ( (pfilter.options() & QwtPlotPrintFilter::PrintLegend) && legend() && !legend()->isEmpty() ) { printLegend(painter, plotLayout()->legendRect()); } for ( axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) { QwtScaleWidget *scaleWidget = (QwtScaleWidget *)axisWidget(axisId); if (scaleWidget) { int baseDist = scaleWidget->baseLineDist(); int startDist, endDist; scaleWidget->getBorderDistHint(startDist, endDist); printScale(painter, axisId, startDist, endDist, baseDist, plotLayout()->scaleRect(axisId)); } } const QRect canvasRect = metricsMap.layoutToDevice(plotLayout()->canvasRect()); // When using QwtPainter all sizes where computed in pixel // coordinates and scaled by QwtPainter later. This limits // the precision to screen resolution. A much better solution // is to scale the maps and print in unlimited resolution. QwtArray<QwtScaleMap> map(axisCnt); for (axisId = 0; axisId < axisCnt; axisId++) { map[axisId].setTransformation(axisScaleEngine(axisId)->transformation()); const QwtScaleDiv &scaleDiv = *axisScaleDiv(axisId); map[axisId].setScaleInterval(scaleDiv.lBound(), scaleDiv.hBound()); double from, to; if ( axisEnabled(axisId) ) { const int sDist = axisWidget(axisId)->startBorderDist(); const int eDist = axisWidget(axisId)->endBorderDist(); const QRect &scaleRect = plotLayout()->scaleRect(axisId); if ( axisId == xTop || axisId == xBottom ) { from = metricsMap.layoutToDeviceX(scaleRect.left() + sDist); to = metricsMap.layoutToDeviceX(scaleRect.right() - eDist); } else { from = metricsMap.layoutToDeviceY(scaleRect.bottom() - sDist); to = metricsMap.layoutToDeviceY(scaleRect.top() + eDist); } } else { const int margin = plotLayout()->canvasMargin(axisId); const QRect &canvasRect = plotLayout()->canvasRect(); if ( axisId == yLeft || axisId == yRight ) { from = metricsMap.layoutToDeviceX(canvasRect.bottom() - margin); to = metricsMap.layoutToDeviceX(canvasRect.top() + margin); } else { from = metricsMap.layoutToDeviceY(canvasRect.left() + margin); to = metricsMap.layoutToDeviceY(canvasRect.right() - margin); } } map[axisId].setPaintXInterval(from, to); } // The canvas maps are already scaled. QwtPainter::setMetricsMap(painter->device(), painter->device()); printCanvas(painter, canvasRect, map, pfilter); QwtPainter::resetMetricsMap(); ((QwtPlot *)this)->plotLayout()->invalidate(); // reset all widgets with their original attributes. if ( !(pfilter.options() & QwtPlotPrintFilter::PrintCanvasBackground) ) { // restore the previous base line dists for (axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) { QwtScaleWidget *scaleWidget = (QwtScaleWidget *)axisWidget(axisId); if ( scaleWidget ) scaleWidget->setBaselineDist(baseLineDists[axisId]); } } pfilter.reset((QwtPlot *)this); painter->restore(); }
/*! \brief Paint the plot into a given rectangle. Paint the contents of a QwtPlot instance into a given rectangle. \param painter Painter \param plotRect Bounding rectangle \param pfilter Print filter \sa QwtPlotPrintFilter */ void QwtPlot::print(QPainter *painter, const QRect &plotRect, const QwtPlotPrintFilter &pfilter) const { int axis; if ( painter == 0 || !painter->isActive() || !plotRect.isValid() || size().isNull() ) return; painter->save(); // All paint operations need to be scaled according to // the paint device metrics. QwtPainter::setMetricsMap(this, painter->device()); #if QT_VERSION < 300 if ( painter->device()->isExtDev() ) { QPaintDeviceMetrics metrics(painter->device()); if ( metrics.logicalDpiX() == 72 && metrics.logicalDpiY() == 72 ) { // In Qt 2.x QPrinter returns hardcoded wrong metrics. // So scaling won´t work: we reset to screen resolution QwtPainter::setMetricsMap(this, this); } } #endif const QwtMetricsMap &metricsMap = QwtPainter::metricsMap(); // It is almost impossible to integrate into the Qt layout // framework, when using different fonts for printing // and screen. To avoid writing different and Qt unconform // layout engines we change the widget attributes, print and // reset the widget attributes again. This way we produce a lot of // useless layout events ... pfilter.apply((QwtPlot *)this); int baseLineDists[QwtPlot::axisCnt]; if ( !(pfilter.options() & QwtPlotPrintFilter::PrintCanvasBackground) ) { // In case of no background we set the backbone of // the scale on the frame of the canvas. for (axis = 0; axis < QwtPlot::axisCnt; axis++ ) { if ( d_scale[axis] ) { baseLineDists[axis] = d_scale[axis]->baseLineDist(); d_scale[axis]->setBaselineDist(0); } } } // Calculate the layout for the print. int layoutOptions = QwtPlotLayout::IgnoreScrollbars | QwtPlotLayout::IgnoreFrames; if ( !(pfilter.options() & QwtPlotPrintFilter::PrintMargin) ) layoutOptions |= QwtPlotLayout::IgnoreMargin; if ( !(pfilter.options() & QwtPlotPrintFilter::PrintLegend) ) layoutOptions |= QwtPlotLayout::IgnoreLegend; d_layout->activate(this, QwtPainter::metricsMap().deviceToLayout(plotRect), layoutOptions); if ((pfilter.options() & QwtPlotPrintFilter::PrintTitle) && (!d_lblTitle->text().isEmpty())) { printTitle(painter, d_layout->titleRect()); } if ( (pfilter.options() & QwtPlotPrintFilter::PrintLegend) && !d_legend->isEmpty() ) { printLegend(painter, d_layout->legendRect()); } for ( axis = 0; axis < QwtPlot::axisCnt; axis++ ) { if (d_scale[axis]) { int baseDist = d_scale[axis]->baseLineDist(); int startDist, endDist; d_scale[axis]->minBorderDist(startDist, endDist); printScale(painter, axis, startDist, endDist, baseDist, d_layout->scaleRect(axis)); } } const QRect canvasRect = metricsMap.layoutToDevice(d_layout->canvasRect()); // When using QwtPainter all sizes where computed in pixel // coordinates and scaled by QwtPainter later. This limits // the precision to screen resolution. A much better solution // is to scale the maps and print in unlimited resolution. QwtArray<QwtDiMap> map(axisCnt); for (axis = 0; axis < axisCnt; axis++) { const QwtScaleDiv &scaleDiv = d_as[axis].scaleDiv(); map[axis].setDblRange(scaleDiv.lBound(), scaleDiv.hBound(), scaleDiv.logScale()); double from, to; if ( axisEnabled(axis) ) { const int sDist = d_scale[axis]->startBorderDist(); const int eDist = d_scale[axis]->endBorderDist(); const QRect &scaleRect = d_layout->scaleRect(axis); if ( axis == xTop || axis == xBottom ) { from = metricsMap.layoutToDeviceX(scaleRect.left() + sDist); to = metricsMap.layoutToDeviceX(scaleRect.right() - eDist); } else { from = metricsMap.layoutToDeviceY(scaleRect.bottom() - sDist); to = metricsMap.layoutToDeviceY(scaleRect.top() + eDist); } } else { const int margin = plotLayout()->canvasMargin(axis); const QRect &canvasRect = plotLayout()->canvasRect(); if ( axis == yLeft || axis == yRight ) { from = metricsMap.layoutToDeviceX(canvasRect.bottom() - margin); to = metricsMap.layoutToDeviceX(canvasRect.top() + margin); } else { from = metricsMap.layoutToDeviceY(canvasRect.left() + margin); to = metricsMap.layoutToDeviceY(canvasRect.right() - margin); } } map[axis].setIntRange( qwtInt(from), qwtInt(to)); } // The maps are already scaled. QwtPainter::setMetricsMap(painter->device(), painter->device()); printCanvas(painter, canvasRect, map, pfilter); QwtPainter::resetMetricsMap(); d_layout->invalidate(); // reset all widgets with their original attributes. if ( !(pfilter.options() & QwtPlotPrintFilter::PrintCanvasBackground) ) { // restore the previous base line dists for (axis = 0; axis < QwtPlot::axisCnt; axis++ ) { if ( d_scale[axis] ) d_scale[axis]->setBaselineDist(baseLineDists[axis]); } } pfilter.reset((QwtPlot *)this); painter->restore(); }
void printTriadImage(HumdrumFile& infile, int rows, int cols) { Array<ChordQuality> cq; infile.analyzeSonorityQuality(cq); infile.analyzeRhythm("4"); Array<Array<int> > triads; triads.setSize(3); triads[0].setSize(cols); triads[0].setAll(24); triads[1].setSize(cols); triads[1].setAll(24); triads[2].setSize(cols); triads[2].setAll(24); colorindex[0] = "0 255 0"; // C major colorindex[1] = "38 255 140"; // C-sharp major colorindex[2] = "63 95 255"; // D major colorindex[3] = "228 19 83"; // E-flat major colorindex[4] = "255 0 0"; // E major colorindex[5] = "255 255 0"; // F major colorindex[6] = "192 255 0"; // F-sharp major colorindex[7] = "93 211 255"; // G major colorindex[8] = "129 50 255"; // A-flat major colorindex[9] = "205 41 255"; // A major colorindex[10] = "255 160 0"; // B-flat major colorindex[11] = "255 110 10"; // B major colorindex[12] = "0 161 0"; // C minor colorindex[13] = "15 191 90"; // C-sharp minor colorindex[14] = "37 61 181"; // D minor colorindex[15] = "184 27 75"; // E-flat minor colorindex[16] = "175 0 0"; // E minor colorindex[17] = "220 200 0"; // F minor colorindex[18] = "140 200 0"; // F-sharp minor colorindex[19] = "65 163 181"; // G minor colorindex[20] = "100 28 181"; // G-sharp minor colorindex[21] = "136 13 181"; // A minor colorindex[22] = "181 93 20"; // B-flat minor colorindex[23] = "211 107 0"; // B minor colorindex[24] = "255 255 255"; // background colorindex[25] = "0 0 0"; // silence double start; double end; int inversion; int starti; int endi; int minQ; int majQ; int i, m, j, ii; int rootindex; for (i=0; i<infile.getNumLines(); i++) { if (!infile[i].isData()) { continue; } if (strcmp(cq[i].getTypeName(), "min") == 0) { minQ = 1; } else { minQ = 0; } if (strcmp(cq[i].getTypeName(), "maj") == 0) { majQ = 1; } else { majQ = 0; } if (!(majQ || minQ)) { continue; } start = infile[i].getAbsBeat(); end = start + infile[i].getDuration(); starti = int(start / infile.getTotalDuration() * cols + 0.5); endi = int(end / infile.getTotalDuration() * cols + 0.5); if (starti < 0) { starti = 0; } if (endi < 0) { endi = 0; } if (starti >= cols) { starti = cols-1; } if (endi >= cols) { endi = cols-1; } rootindex = Convert::base40ToMidiNoteNumber(cq[i].getRoot()); if (minQ) { rootindex += 12; } inversion = cq[i].getInversion(); for (ii=starti; ii<=endi; ii++) { triads[inversion][ii] = rootindex; } } int barheight = 0; int barwidth = 0; if (barlinesQ) { barheight = 11; barwidth = cols; } int legendheight = 0; int legendwidth = 0; if (legendQ) { legendheight = 100; legendwidth = cols; } int value = 24; Matrix<int> image(rows*2, cols, value); for (i=triads.getSize()-1; i>=0; i--) { int start = int(i/2.0 * rows); for (m=0; m<rows; m++) { ii = (int)(m + start); if (ii >= image.getRowCount()) { ii = image.getRowCount() - 1; } for (j=0; j<triads[i].getSize(); j++) { if (triads[i][j] < 24) { image.cell(ii,j) = triads[i][j]; } // cout << colorindex[triads[i][j]] << " "; //cout << triads[i][j] << " "; } //cout << "\n"; } } // print Image: cout << "P3\n"; cout << cols << " " << rows*2 + barheight + legendheight << "\n"; cout << "255\n"; for (i=image.getRowCount()-1; i>=0; i--) { for (j=0; j<image.getColumnCount(); j++) { cout << colorindex[image.cell(i,j)] << ' '; } cout << "\n"; } if (barlinesQ) { printBarlines(infile, barheight, barwidth); } if (legendQ) { printLegend(legendheight, legendwidth); } }