void Elevator::zeroOccupancy()
{
    mOccupancy = 0;

    textItem()->hide();
    textItem()->setPlainText("0");
    centerTextItem();
    ellipseItem()->hide();
}
void Elevator::incrementOccupancy()
{
    ++mOccupancy;

    if ( !textItem()->isVisible() ) textItem()->show();
    textItem()->setPlainText( QString::number(mOccupancy) );
    if ( !ellipseItem()->isVisible() ) ellipseItem()->show();

    centerTextItem();
}
Beispiel #3
0
TextItem::TextItem() : RectItem(), alignment(Qt::AlignHCenter) {
    textItem = new InternalTextItem (this);
    textItem->setTextInteractionFlags(Qt::TextEditorInteraction);

    // This item is focusable and passes the focus on to the child item
    setFlag (QGraphicsItem::ItemIsFocusable);
    setFocusProxy(textItem);

    setFiltersChildEvents(true);
    setInternalAlignment(Qt::AlignHCenter);

    centerTextItem();
}
Beispiel #4
0
TextItem::TextItem(const QPointF& pos, QGraphicsItem * parent) :
        RectItem(QRectF(pos.x(), pos.y(), 50, 30), parent), alignment(Qt::AlignHCenter) {

    textItem = new InternalTextItem (this);
    textItem->setTextInteractionFlags(Qt::TextEditorInteraction);

    // This item is focusable and passes the focus on to the child item
    setFlag (QGraphicsItem::ItemIsFocusable);
    setFocusProxy(textItem);

    setFiltersChildEvents(true);
    setInternalAlignment(Qt::AlignHCenter);

    centerTextItem();
}
Elevator::Elevator(Simulation& simulation, int number, QGraphicsScene &scene, const QPolygonF &elevatorPolygon) :
    mSimulation(simulation),
    mNumber(number),
    mOccupancy(0),
    mState(NORMAL_STATE),
    mScene(scene),
    mPolygonItem(0),
    mTextItem(0),
    mEllipseItem(0),
    mAwayTextItem(0),
    mBrokenTextItem(0),
    mIsAllowedLeave(false),
    mIsSimulationStopped(false),
    mLeaveTimer(this)
{
    // Constructs leave timer
    mLeaveTimer.setSingleShot(true);
    QObject::connect(&mLeaveTimer, SIGNAL(timeout()), this, SLOT(onLeave()));

    // Polygon item
    mPolygonItem = mScene.addPolygon(elevatorPolygon);
    mPolygonItem->setPos( Simulation::ELEVATOR_SPACE + (mNumber * Simulation::ELEVATOR_FULL_WIDTH), 0 );
    mPolygonItem->setBrush(Qt::yellow);

    // Text item
    mTextItem = mScene.addText("0");
    centerTextItem();
    mTextItem->hide();

    // Ellipse item
    mEllipseItem = mScene.addEllipse(Simulation::ELEVATOR_SPACE + 15 + (mNumber * Simulation::ELEVATOR_FULL_WIDTH), 40,
                                     Simulation::PERSON_WIDTH, Simulation::PERSON_HEIGHT);
    mEllipseItem->setBrush(Qt::green);
    mEllipseItem->hide();

    // Away text item
    mAwayTextItem = mScene.addText("Away");
    centerAwayTextItem();
    mAwayTextItem->hide();

    // Broken text item
    mBrokenTextItem = mScene.addText("Broken");
    centerBrokenTextItem();
    mBrokenTextItem->hide();
}
Beispiel #6
0
void TextItem::readExternal(QXmlStreamReader& reader) {
    RectItem::readExternal(reader);
    reader.readNext();  // skip characters

    // read the text
    QXmlStreamReader::TokenType type = reader.readNext();
    if (type == QXmlStreamReader::StartElement && reader.name() == "Text") {
        // get the font
        QString fontDesc = reader.attributes().value("font").toString();
        QFont font;
        font.fromString(fontDesc);

        // get the alignment
        alignment = static_cast<Qt::Alignment>(reader.attributes().value("align").toInt());
        switch(alignment) {
            case Qt::AlignLeft : break;
            case Qt::AlignHCenter : break;
            case Qt::AlignRight : break;
            default : alignment = Qt::AlignLeft; break;
        }

        // get the color
        QString color = reader.attributes().value("textColor").toString();

        // read text and set it (before activating the properties, especially the alignment!)
        reader.readNext();
        textItem->setPlainText(reader.text().toString());

        // activate properties
        textItem->setFont(font);
        textItem->setAlignment(alignment);
        textItem->setDefaultTextColor(QColor(color));

        // layout the text
        centerTextItem();
    }
}
Beispiel #7
0
void TextItem::moveHandle(AbstractEditHandle editHandle, const QPointF& scenePos) {
    RectItem::moveHandle(editHandle, scenePos);
    centerTextItem();
}
Beispiel #8
0
void TextItem::setText(const QString& text) {
    textItem->setPlainText(text);
    centerTextItem();
    setInternalAlignment(alignment);
}
Beispiel #9
0
void TextItem::setInternalFont(const QFont& font) {
    textItem->setFont(font);
    centerTextItem();
}