bool Crack::move() { m_ptIndex++; // continue cracking if(m_bCurved) { /* m_x += ((float) m_ys * cos(m_angle * DEG_TO_RAD)); m_y += ((float) m_ys * sin(m_angle * DEG_TO_RAD)); m_x += ((float) m_xs * cos(m_angle * DEG_TO_RAD - HALF_PI)); m_y += ((float) m_xs * sin(m_angle* DEG_TO_RAD - HALF_PI)); m_angle += m_angleStep; m_degreesDrawn += abs(m_angleStep); */ } // draw black crack if(m_ptIndex != m_pts.size()) { int ptX = m_pts[m_ptIndex].x(); int ptY = m_pts[m_ptIndex].y(); m_image.draw_point(ptX, ptY, 0, Artist::black.colour()); regionColor(); // safe to check if(m_bCurved && (m_degreesDrawn > 360) ) { findStart(); return false; } else if(m_cgrid[ptY*m_image.width() + ptX] == UNCRACKED) { // continue cracking m_cgrid[ptY*m_image.width() + ptX] = m_line.angle(); } else { // crack encountered (not self), stop cracking findStart(); return false; } } else { // out of bounds, stop cracking findStart(); return false; } return true; }
void Spectrograph::paintEvent(QPaintEvent *event) { Q_UNUSED(event) QPainter painter(this); painter.fillRect(rect(), Qt::black); const int numBars = m_bars.count(); // Highlight region of selected bar if (m_barSelected != NullIndex && numBars) { QRect regionRect = rect(); regionRect.setLeft(m_barSelected * rect().width() / numBars); regionRect.setWidth(rect().width() / numBars); QColor regionColor(0, 0, 64); painter.setBrush(Qt::DiagCrossPattern); painter.fillRect(regionRect, regionColor); painter.setBrush(Qt::NoBrush); } QColor barColor(0, 0, 255); QColor clipColor(255, 0, 0); // Draw the outline const QColor gridColor = barColor.darker(); QPen gridPen(gridColor); painter.setPen(gridPen); painter.drawLine(rect().topLeft(), rect().topRight()); painter.drawLine(rect().topRight(), rect().bottomRight()); painter.drawLine(rect().bottomRight(), rect().bottomLeft()); painter.drawLine(rect().bottomLeft(), rect().topLeft()); QVector<qreal> dashes; dashes << 2 << 2; gridPen.setDashPattern(dashes); painter.setPen(gridPen); // Draw vertical lines between bars if (numBars) { const int numHorizontalSections = numBars; QLine line(rect().topLeft(), rect().bottomLeft()); for (int i=1; i<numHorizontalSections; ++i) { line.translate(rect().width()/numHorizontalSections, 0); painter.drawLine(line); } } // Draw horizontal lines const int numVerticalSections = 10; QLine line(rect().topLeft(), rect().topRight()); for (int i=1; i<numVerticalSections; ++i) { line.translate(0, rect().height()/numVerticalSections); painter.drawLine(line); } barColor = barColor.lighter(); barColor.setAlphaF(0.75); clipColor.setAlphaF(0.75); // Draw the bars if (numBars) { // Calculate width of bars and gaps const int widgetWidth = rect().width(); const int barPlusGapWidth = widgetWidth / numBars; const int barWidth = 0.8 * barPlusGapWidth; const int gapWidth = barPlusGapWidth - barWidth; const int paddingWidth = widgetWidth - numBars * (barWidth + gapWidth); const int leftPaddingWidth = (paddingWidth + gapWidth) / 2; const int barHeight = rect().height() - 2 * gapWidth; for (int i=0; i<numBars; ++i) { const qreal value = m_bars[i].value; Q_ASSERT(value >= 0.0 && value <= 1.0); QRect bar = rect(); bar.setLeft(rect().left() + leftPaddingWidth + (i * (gapWidth + barWidth))); bar.setWidth(barWidth); bar.setTop(rect().top() + gapWidth + (1.0 - value) * barHeight); bar.setBottom(rect().bottom() - gapWidth); QColor color = barColor; if (m_bars[i].clipped) color = clipColor; painter.fillRect(bar, color); } } }