Skip to content

Commit

Permalink
Cosmetic
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Sep 7, 2015
1 parent a538ea7 commit c607856
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <iscore/widgets/GraphicsItem.hpp>
#include <QGraphicsScene>

static const constexpr int slotSpacing = 0;

RackPresenter::RackPresenter(const RackModel& model,
RackView* view,
QObject* parent):
Expand Down Expand Up @@ -56,7 +58,7 @@ qreal RackPresenter::height() const

for(const auto& slot : slotmodels)
{
totalHeight += slot.height() + 5.;
totalHeight += slot.height() + slotSpacing;
}

return totalHeight;
Expand Down Expand Up @@ -161,7 +163,7 @@ void RackPresenter::updateShape()
auto& slotPres = slotmodels.at(slotId);
slotPres.setWidth(width());
slotPres.setVerticalPosition(currentSlotY);
currentSlotY += slotPres.height() + 5; // Separation between slots
currentSlotY += slotPres.height() + slotSpacing; // Separation between slots
}

// Horizontal shape
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,35 @@ class ConstraintView;
class ConstraintHeader : public QGraphicsObject
{
public:
enum class State {
Hidden, // No rack, we show nothing
RackHidden, // There is at least a hidden rack in the constraint
RackShown // There is a rack currently shown
};

using QGraphicsObject::QGraphicsObject;
static constexpr int headerHeight() { return 25; }
static const QFont font;

void setWidth(double width);
void setText(const QString &text);

void setState(State s)
{
if(s == m_state)
return;

if(m_state == State::Hidden)
show();
else if(s == State::Hidden)
hide();

m_state = s;
update();
}

protected:
State m_state{};
double m_width{};
QString m_text;
};
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void ConstraintPresenter::updateHeight()
{
if(m_viewModel.isRackShown())
{
m_view->setHeight(rack()->height() + 60);
m_view->setHeight(rack()->height() + 50);
}
// TODO else if(rack but not shown)
else
Expand Down Expand Up @@ -195,14 +195,15 @@ void ConstraintPresenter::on_rackShown(const Id<RackModel>& rackId)
clearRackPresenter();
createRackPresenter(m_viewModel.model().racks.at(rackId));

m_header->show();
m_header->setState(ConstraintHeader::State::RackShown);
updateHeight();
}

void ConstraintPresenter::on_rackHidden()
{
clearRackPresenter();

m_header->setState(ConstraintHeader::State::RackHidden);
updateHeight();
}

Expand All @@ -211,6 +212,7 @@ void ConstraintPresenter::on_rackRemoved()
m_header->hide();
clearRackPresenter();

m_header->setState(ConstraintHeader::State::Hidden);
updateHeight();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,30 @@
#include <QPainter>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QApplication>
QRectF TemporalConstraintHeader::boundingRect() const
{
return {0, 0, m_width, ConstraintHeader::headerHeight()};
}

void TemporalConstraintHeader::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setPen(Qt::white);
if(m_state == State::RackHidden)
{
auto rect = boundingRect();
painter->fillRect(rect, QColor::fromRgba(qRgba(0, 127, 229, 76)));

// Fake timenode continuation
auto color = qApp->palette("ScenarioPalette").base().color();
QPen pen{color, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin};
painter->setPen(pen);
painter->drawLine(rect.topLeft(), rect.bottomLeft());
painter->drawLine(rect.topRight(), rect.bottomRight());
painter->drawLine(rect.bottomLeft(), rect.bottomRight());
}
// Header
painter->setFont(font);
painter->setPen(Qt::white);

QFontMetrics fm(font);
int textWidth = fm.width(m_text);
Expand Down Expand Up @@ -46,4 +60,9 @@ void TemporalConstraintHeader::paint(QPainter *painter, const QStyleOptionGraphi
double w = m_width - x;
double h = ConstraintHeader::headerHeight();
painter->drawText(x,y,w,h, Qt::AlignLeft, m_text);

if(m_width > 20)
painter->drawLine(
boundingRect().bottomLeft() + QPointF{10, -5},
boundingRect().bottomRight() + QPointF{-10, -5});
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void TemporalConstraintView::paint(
int max_w = static_cast<int>(maxWidth());
int def_w = static_cast<int>(defaultWidth());

// Draw the stuff present if there is a rack
// Draw the stuff present if there is a rack *in the model* ?
if(presenter().rack())
{
// Background
Expand Down

0 comments on commit c607856

Please sign in to comment.