void GraphColumn::DrawField(BField* field, BRect rect, BView* parent) { int number = ((BIntegerField*)field)->Value(); if (number > 100) number = 100; else if (number < 0) number = 0; BRect graphRect(rect); graphRect.InsetBy(5, 3); parent->StrokeRect(graphRect); if (number > 0) { graphRect.InsetBy(1, 1); float val = graphRect.Width() * (float) number / 100; graphRect.right = graphRect.left + val; parent->SetHighColor(0, 0, 190); parent->FillRect(graphRect); } parent->SetDrawingMode(B_OP_INVERT); parent->SetHighColor(128, 128, 128); char numstr[256]; sprintf(numstr, "%d%%", number); float width = be_plain_font->StringWidth(numstr); parent->MovePenTo(rect.left + rect.Width() / 2 - width / 2, rect.bottom - FontHeight()); parent->DrawString(numstr); }
// Move relative graph use point p as a vector void AppWindow::MoveGraphRect(BPoint p) { float delta; BRect rect = view->Bounds(), graphRect(view->graph->GetRect()); if ((p.x == 0) && (p.y == 0)) return; delta = (graphRect.right-graphRect.left) * p.x / (rect.right-rect.left); graphRect.right += delta; graphRect.left += delta; delta = (graphRect.bottom-graphRect.top) * p.y / (rect.bottom-rect.top); graphRect.top += delta; graphRect.bottom += delta; UpdateGraphRect(graphRect); view->Invalidate(); }
// Zoom in or out void AppWindow::Zoom(float factor) { double m, d; BRect graphRect(view->graph->GetRect()); d = factor * (graphRect.bottom - graphRect.top) / 2.0; m = (graphRect.bottom + graphRect.top) / 2.0; graphRect.bottom = m + d; graphRect.top = m - d; d = factor * (graphRect.right - graphRect.left) / 2.0; m = (graphRect.right + graphRect.left) / 2.0; graphRect.left = m - d; graphRect.right = m + d; UpdateGraphRect(graphRect); view->Invalidate(); }
void CIndicator::drawGraph(QPainter *painter) { painter->save(); painter->setPen(QPen(Qt::transparent,INDICATOR_PEN_WIDTH)); QLinearGradient graphGradient(m_rectTopLeft,QPointF(m_rectTopLeft.x(),m_rectBottomRight.y())); graphGradient.setColorAt(0.0,forecolor); painter->setBrush(graphGradient); qreal dY=(qreal)(m_rectTopLeft.y()-m_rectBottomRight.y())/100; qreal yValue=dY*m_currValue; QPointF topLeftPot(m_rectTopLeft.x()+INDICATOR_PEN_WIDTH,m_rectBottomRight.y()+yValue); QPointF bottomRightPot(m_rectBottomRight.x()-INDICATOR_PEN_WIDTH,m_rectBottomRight.y()); QRectF graphRect(topLeftPot,bottomRightPot); painter->drawRect(graphRect); QString strCurrValue; strCurrValue=tr("%1").arg((m_currValue)); if(m_currValue<10) { lcd[0]->setValue(0); lcd[1]->setValue(0); lcd[2]->setValue(m_currValue); } else if(m_currValue < 100 && m_currValue >= 10) { lcd[0]->setValue(0); lcd[1]->setValue(strCurrValue.at(0).digitValue()); lcd[2]->setValue(strCurrValue.at(1).digitValue()); } else { lcd[0]->setValue(1); lcd[1]->setValue(0); lcd[2]->setValue(0); } painter->restore(); }
void CThermoMeterItem::drawGraph(QPainter *painter) { painter->save(); qreal bucketHeight=m_bucketRect.height(); qreal increment=(qreal)bucketHeight/100; QPointF bottomRightPot(m_bucketRect.bottomRight()); qreal currentY=m_currentValue*increment; QPointF topLeftPot(m_bucketRect.topLeft().x(),m_bucketRect.bottomLeft().y()-currentY); QRectF graphRect(topLeftPot,bottomRightPot); painter->setPen(Qt::NoPen); QLinearGradient graphGradient(graphRect.topLeft(),graphRect.topRight()); painter->setOpacity(0.7); graphGradient.setColorAt(0.0,this->graphcolor); painter->setBrush(graphGradient); painter->drawRect(graphRect); painter->restore(); }