Files
Upsilon/apps/calculation/history_view_cell.cpp
Émilie Feral b101308922 [apps/calculation] Rename calcul->calculation
Change-Id: I57ca7353516cee2da33470a8a0f622a21c3fe7e9
2016-10-25 17:55:28 +02:00

60 lines
1.7 KiB
C++

#include "history_view_cell.h"
#include <assert.h>
#include <string.h>
namespace Calculation {
HistoryViewCell::HistoryViewCell() :
m_calculation(nullptr),
m_highlighted(false),
m_result(BufferTextView(1.0f, 0.5f))
{
}
int HistoryViewCell::numberOfSubviews() const {
return 1;
}
View * HistoryViewCell::subviewAtIndex(int index) {
assert(index == 0);
return &m_result;
}
void HistoryViewCell::layoutSubviews() {
KDCoordinate width = bounds().width();
KDCoordinate height = bounds().height();
// Position the result
KDSize prettyPrintSize = KDSize(0,0);
if (m_calculation && m_calculation->layout() != nullptr) {
prettyPrintSize = m_calculation->layout()->size();
}
KDRect resultFrame(prettyPrintSize.width(), 0, width - prettyPrintSize.width(), height);
m_result.setFrame(resultFrame);
}
void HistoryViewCell::setCalculation(Calculation * calculation) {
m_calculation = calculation;
char buffer[7];
m_calculation->evaluation()->convertFloatToText(buffer, 14, 7);
m_result.setText(buffer);
}
void HistoryViewCell::setHighlighted(bool highlight) {
m_highlighted = highlight;
KDColor backgroundColor = m_highlighted ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor;
m_result.setBackgroundColor(backgroundColor);
markRectAsDirty(bounds());
}
void HistoryViewCell::drawRect(KDContext * ctx, KDRect rect) const {
// Select background color
KDColor backgroundColor = m_highlighted ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor;
ctx->fillRect(rect, backgroundColor);
// Draw the pretty print
if (m_calculation && m_calculation->layout() != nullptr) {
m_calculation->layout()->draw(ctx, KDPointZero, KDColorBlack, backgroundColor);
}
}
}