void MenuEquipmentScreen::initialize(BattleCharacterItem *character, Inventory *inventory) { QFont font("Times", 12, QFont::Bold); QBrush brush(Qt::white); _state = EQUIPPED_SELECTION; // Set character and inventory _character = character; _inventory = inventory; // Set the character's equipment QPointF position(_equippedEquipmentItem->pos().x(), _equippedEquipmentItem->pos().y() + 40); QStringList equipmentHeaders; equipmentHeaders << "Main Hand: " << "Off Hand: " << "Helmet: " << "Torso: " << "Leggings: " << "Gloves: " << "Boots: " << "Earring: " << "Necklace: " << "Ring: "; QVector<EquipmentPiece*> equipment = _character->getEquipment()->getEquipment(); _currentEquippedEquipmentPiece = equipment.at(0); _equippedEquipmentItem->setText("Equipment of " + _character->getName()); for (int i = 0; i < equipment.size(); i++) { QString itemText; itemText.append(equipmentHeaders.at(i)); if (!!equipment.at(i)) itemText.append(equipment.at(i)->getName()); QGraphicsSimpleTextItem *item = new QGraphicsSimpleTextItem(this); item->setText(itemText); item->setBrush(brush); item->setFont(font); item->setPos(position); _equippedEquipmentItems.append(item); position.setY(position.y() + 20); } setCurrentEquippedItem(_equippedEquipmentItems.at(0), equipment.at(0)); // Set Image if (_character->getCharacter()->getBattleImage().second != QString()) { QPixmap battlerImage = _character->getCharacter()->getBattleImage().first; if ((battlerImage.width() > _characterImage->boundingRect().width()) || (battlerImage.height() > _characterImage->boundingRect().height())) battlerImage = battlerImage.scaled(QSize(200, 200), Qt::KeepAspectRatio); QPixmap frame(200, 200); frame.fill(Qt::transparent); QPainter painter(&frame); painter.setCompositionMode(QPainter::CompositionMode_SourceOver); QPoint position(0, 0); position.setX(frame.width()/2 - battlerImage.width()/2); position.setY(frame.height()/2 - battlerImage.height()/2); painter.drawPixmap(position, battlerImage); painter.end(); _characterImage->setPixmap(frame); } else { QPixmap image(200, 200); image.fill(Qt::transparent); _characterImage->setPixmap(image); } }
void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QPixmap& pixmap) { const IconMetrics& iconMetrics = defaultIconMetrics(); QGraphicsPixmapItem *iconItem = 0; double yValue = title->boundingRect().height() + iconMetrics.spacing; Q_FOREACH (ToolTip t, toolTips) { yValue += t.second->boundingRect().height(); } if (entryToolTip.second) { yValue += entryToolTip.second->boundingRect().height(); } iconItem = new QGraphicsPixmapItem(this); if (!icon.isNull()) { iconItem->setPixmap(icon.pixmap(iconMetrics.sz_small, iconMetrics.sz_small)); } else if (!pixmap.isNull()) { iconItem->setPixmap(pixmap); } const int sp2 = iconMetrics.spacing * 2; iconItem->setPos(sp2, yValue); QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem(toolTip, this); textItem->setPos(sp2 + iconMetrics.sz_small + sp2, yValue); textItem->setBrush(QBrush(Qt::white)); textItem->setFlag(ItemIgnoresTransformations); toolTips.push_back(qMakePair(iconItem, textItem)); }
asd::Waypoint* asd::Waypoint::Builder::build() { asd::Waypoint *waypoint = new asd::Waypoint; // // Properties // waypoint->setPen(properties_.pen()); waypoint->setBrush(properties_.brush()); waypoint->setZValue(properties_.zlayer()); qreal size = properties_.size(); waypoint->setRect(-size/2, -size/2, size, size); if (!name_.isEmpty()) { QGraphicsSimpleTextItem *text = new QGraphicsSimpleTextItem(waypoint); text->setPen(Qt::NoPen); text->setBrush(properties_.pen().brush()); text->setText(name_); } waypoint->setPos(location_); return waypoint; }
void MenuEquipmentScreen::equippedItemSelected() { // Reset updated stats and equipment list _updatedStatsItem->setText(QString()); for (int i = 0; i < _updatedStatsItems.size(); i++) delete _updatedStatsItems.at(i); _updatedStatsItems.clear(); _equipmentList.clear(); _equipmentStringList.clear(); _currentSelectedEquipmentString = 0; _currentEquipmentListItem = 0; _equipmentListItem->setText(QString()); for (int i = 0; i < _activeEquipmentListItems.size(); i++) delete _activeEquipmentListItems.at(i); _activeEquipmentListItems.clear(); // Build the equipmentlist QVector<QPair<EquipmentPiece*, int>> equipment = _inventory->getEquipment(); for (int i = 0; i < equipment.size();) { if (!equipmentFilter(equipment.at(i).first)) equipment.remove(i); else { _equipmentList.append(equipment.at(i).first); i++; } } // Set the equipment list QFont font ("Times", 12, QFont::Bold); QBrush brush(Qt::white); QPointF position(_equipmentListItem->pos().x(), _equipmentListItem->pos().y() + 20); _currentSelectedEquipmentString = 0; _equipmentStringList.append(QString("Clear equipment slot")); for (int i = 0; i < _equipmentList.size(); i++) _equipmentStringList.append(_equipmentList.at(i)->getName()); _equipmentListItem->setText("Select equipment:"); for (int i = 0; i < qMin<int>(_equipmentStringList.size(), 8); i++) { QGraphicsSimpleTextItem *item = new QGraphicsSimpleTextItem(_equipmentListPanel); item->setBrush(brush); item->setFont(font); item->setText(_equipmentStringList.at(i)); item->setPos(position); position.setY(position.y() + 20); _activeEquipmentListItems.append(item); } setCurrentEquipmentItem(_activeEquipmentListItems.first(), 0); _state = MenuEquipmentScreen::EQUIPMENT_SELECTION; }
void TimeScene::drawTime(DateTime currentDay, DTime time, QModelIndex index, int groupLevel) { QSize size = sizeHint(index); int bordermargin = (size.height() * .1) / 2; QBrush b; QPen pen(QColor(0, 0, 150)); QBrush textBrush; if (groupLevel == 2) { b = QBrush(Qt::white); pen = QPen(QColor(0, 0, 150)); textBrush = QBrush(Qt::darkBlue); } if (groupLevel == 1) { b = QBrush(Qt::lightGray); pen = QPen(QColor(0, 0, 50)); textBrush = QBrush(Qt::blue); } if (groupLevel == 0) { b = QBrush(Qt::darkGray); pen = QPen(QColor(100, 100, 200)); textBrush = QBrush(Qt::white); } int daysToStart = _startDate.daysTo(currentDay); int x1 = daysToStart * _dayWidth; int y1 = _currentY + bordermargin; int x2 = x1 + _dayWidth; int y2 = _currentY + size.height() - bordermargin; // QGraphicsRectItem* item = this->addRect(x1, y1, (x2 - x1), (y2 - y1), pen, b); QRect rect(x1, y1, (x2 - x1), (y2 - y1)); GraphicsRectItem* item = new GraphicsRectItem(rect, index); this->addItem(item); item->setPen(pen); item->setBrush(b); item->setZValue(1); item->setAcceptHoverEvents(true); connect(item, SIGNAL(itemHoverEnter(QModelIndex)), this, SLOT(receiveItemHoverEnter(QModelIndex))); connect(item, SIGNAL(itemHoverLeave(QModelIndex)), this, SLOT(receiveItemHoverLeave(QModelIndex))); QFont font("Arial", 8); font.setBold((groupLevel <= 1)); font.setItalic((groupLevel == 0)); QGraphicsSimpleTextItem* text = addSimpleText(time.toQString(), font); text->setBrush(textBrush); text->setPos(x1 + 2, y1 + 1); text->setVisible(true); text->setZValue(1); }
void GraphViewer::onSceneMouseRelease(QGraphicsSceneMouseEvent *mouseEvent) { // need to put the connecting line on the background otherwise it is detected under the mouse _drawingEdge->setZValue(EDGE_LINE_Z); QGraphicsItem * item = _scene.itemAt(mouseEvent->scenePos(), QTransform()); if (qgraphicsitem_cast<QGraphicsEllipseItem*>(item) || qgraphicsitem_cast<QGraphicsSimpleTextItem*>(item)) { QGraphicsEllipseItem* vertex = qgraphicsitem_cast<QGraphicsEllipseItem*>(item->parentItem()); if (!vertex) vertex = qgraphicsitem_cast<QGraphicsEllipseItem*>(item); if (vertex) { double x = _drawingEdge->transform().dx(); double y = _drawingEdge->transform().dy(); _drawingEdge->setLine(0.0,0.0, vertex->scenePos().x()-x, vertex->scenePos().y()-y); _drawingEdge->setZValue(EDGE_LINE_Z); if (_drawingEdge->data(KEY_EDGE_VERTEX1) == vertex->data(KEY_EDGE_VERTEX1)) _scene.removeItem(_drawingEdge); else { int defaultWeight = 1; _drawingEdge->setData(KEY_EDGE_VERTEX2, vertex->data(KEY_VERTEX_ID)); _drawingEdge->setData(KEY_EDGE_WEIGHT, defaultWeight); // draw edge weight QGraphicsSimpleTextItem * edgeWeight = _scene.addSimpleText(QString("%1").arg(defaultWeight)); edgeWeight->setParentItem(_drawingEdge); edgeWeight->setBrush(Qt::blue); QLineF line = _drawingEdge->line(); edgeWeight->setTransform( QTransform::fromScale(0.005, 0.005) * QTransform::fromTranslate(line.x2()*0.5, line.y2()*0.5) ); edgeWeight->setZValue(EDGE_TEXT_Z); // add to graph edges _edges << _drawingEdge; } } } else { _scene.removeItem(_drawingEdge); } _isDrawingEdge=false; _drawingEdge=0; }
GameProcessor::GameProcessor(YagwScene &ygws) : scene(ygws), player(0), disclaimer(0), gia(*this, ygws.width(), ygws.height(), player), cfg(ConfManager("config.cfg")), playerFire(0) { QObject::connect(&scene, SIGNAL(newEntity(Entity*)), this, SLOT(loadEntity(Entity*))); QObject::connect(&scene, SIGNAL(newFire(Entity*)), this, SLOT(loadFire(Entity*))); QObject::connect(&scene, SIGNAL(phase2()), this, SLOT(advance())); GameProcessor::affDelimiters(); QObject::connect(&scene, SIGNAL(forwardKeyPressEvent(QKeyEvent*)), this, SLOT(keyPressEvent(QKeyEvent*))); GameProcessor::createDisclaimer("Press RETURN to start"); QGraphicsSimpleTextItem *txt = this->scene.addSimpleText("Lives:"); // attention on perd le pointeur. a changer. QFont font; QPen pen(Qt::red, 1, Qt::DashLine, Qt::RoundCap, Qt::RoundJoin); font.setBold(true); font.setPointSize(20); txt->setFont(font); txt->setBrush(Qt::red); txt->setPen(pen); txt->setPos(WINSIZE_X / 2 + 5,- WINSIZE_Y / 2 + 10); QString str("Score:\n"); str += QString::number(Score::get_instance()->getScore()) + QString::fromAscii("\nMax:\n") + QString::number(Score::get_instance()->getMax()); txt = this->scene.addSimpleText(str); txt->setFont(font); txt->setBrush(Qt::red); txt->setPen(pen); txt->setPos(WINSIZE_X / 2 + 5,- WINSIZE_Y / 2 + 200); this->score = txt; //GameProcessor::affGrid(); }
void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon) { QGraphicsPixmapItem *iconItem = 0; double yValue = title->boundingRect().height() + SPACING; Q_FOREACH (ToolTip t, toolTips) { yValue += t.second->boundingRect().height(); } if (!icon.isNull()) { iconItem = new QGraphicsPixmapItem(icon.pixmap(ICON_SMALL, ICON_SMALL), this); iconItem->setPos(SPACING, yValue); } QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem(toolTip, this); textItem->setPos(SPACING + ICON_SMALL + SPACING, yValue); textItem->setBrush(QBrush(Qt::white)); textItem->setFlag(ItemIgnoresTransformations); toolTips.push_back(qMakePair(iconItem, textItem)); expand(); }
void MenuMainScreen::createOptions() { QFont font ("Times", 12, QFont::Bold); QBrush brush(Qt::white); QStringList options; options << "Character" << "Equipment" << "Abilities" << "Inventory" << "Exit"; int x = 25, y = 40; for (int i = 0; i < options.size(); i++) { QGraphicsSimpleTextItem *item = new QGraphicsSimpleTextItem(options.at(i), _optionsPanel); item->setBrush(brush); item->setFont(font); item->setPos(x, y); _options.append(item); y += 30; } setCurrentOption(_options.at(0)); }
void MenuEquipmentScreen::setCurrentEquippedItem(QGraphicsSimpleTextItem *item, EquipmentPiece *equipment) { QBrush whiteBrush(Qt::white); QBrush yellowBrush(Qt::yellow); QFont font("Times", 12, QFont::Bold); if (!!_currentEquippedEquipmentItem) _currentEquippedEquipmentItem->setBrush(whiteBrush); _currentEquippedEquipmentItem = item; _currentEquippedEquipmentItem->setBrush(yellowBrush); _currentEquippedEquipmentPiece = equipment; // Reset the current selected equipped item _equippedStatsItem->setText(QString()); for (int i = 0; i < _equippedStatsItems.size(); i++) delete _equippedStatsItems.at(i); _equippedStatsItems.clear(); // If the current slot contains an equipment piece if (!!_currentEquippedEquipmentPiece) { QPointF position(_equippedStatsItem->pos().x(), _equippedStatsItem->pos().y() + 20); _equippedStatsItem->setText("Attributes of " + equipment->getName()); QVector<QPair<Attribute*, int>> attributes = equipment->getAttributes(); for (int i = 0; i < attributes.size(); i++) { QPair<Attribute*, int> it = attributes.at(i); QString itemText(it.first->getName() + " + " + QString::number(it.second)); QGraphicsSimpleTextItem *item = new QGraphicsSimpleTextItem(_equipmentStatsPanel); item->setText(itemText); item->setBrush(whiteBrush); item->setFont(font); item->setPos(position); _equippedStatsItems.append(item); position.setY(position.y() + 20); } } else _equippedStatsItem->setText("No equipment selected"); }
void HomeScreen::initSprite() { _sprite = new QGraphicsWidget(); QGraphicsItem* item; QGraphicsSimpleTextItem* text; QGraphicsProxyWidget* proxy; QLabel* label; QFont font; item = new QGraphicsPixmapItem(); item->setParentItem(_sprite); item->setPos((BACKGROUND_W - (400.0f / 0.75f)) * 0.5f, BACKGROUND_H - 400.0f); _avatar = static_cast<QGraphicsPixmapItem*>(item); item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_TITLE)); item->setParentItem(_sprite); item->setPos(232.0f, 128.0f); font = QFont("Arial"); font.setPixelSize(12); font.setWeight(QFont::Normal); font.setStretch(80); text = new QGraphicsSimpleTextItem("http://conanchen.com/Kinetris"); text->setBrush(QColor::fromRgb(0xFF, 0xFF, 0xFF)); text->setFont(font); text->setParentItem(_sprite); text->setPos(248.0f, 264.0f - 3.0f); label = new QLabel(); label->resize(784, 24); label->setStyleSheet("background-color: transparent; color: #FFFFFF;"); label->setAlignment(Qt::AlignTop | Qt::AlignHCenter); proxy = new QGraphicsProxyWidget(); proxy->setParentItem(_sprite); proxy->setWidget(label); proxy->setPos(248.0f, 592.0f - 6.0f); _sprite_status = proxy; _status = label; }
QList<QGraphicsItem*> DefaultVisualization::createStringItems(const stromx::runtime::Data & data, const VisualizationState::Properties & properties) { using namespace stromx::runtime; QVariant colorVariant = properties.value("color", Colors::DEFAULT); QColor color = colorVariant.value<QColor>(); QList<QGraphicsItem*> items; try { const String & string = stromx::runtime::data_cast<String>(data); QGraphicsSimpleTextItem* item = new QGraphicsSimpleTextItem(QString::fromStdString(string)); QBrush brush = item->brush(); brush.setColor(color); item->setBrush(brush); items.append(item); } catch(stromx::runtime::BadCast&) { } return items; }
void VisualMatrix::initSprite() { _sprite = new QGraphicsWidget(); QGraphicsItem* item; QGraphicsWidget* widget; QGraphicsRectItem* rect; QGraphicsColorizeEffect* effect; QGraphicsSimpleTextItem* text; QGraphicsProxyWidget* proxy; QLabel* label; QFont font; // Frame { item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_FRAME_BG)); item->setParentItem(_sprite); item->setPos(0.0f, 0.0f); } // Frame { item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_FRAME_MG)); item->setParentItem(_sprite); item->setPos(0.0f, 0.0f); } // Avatar { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 10, BLOCK_LARGE * 20); widget->setFlags(QGraphicsItem::ItemClipsChildrenToShape); widget->setParentItem(_sprite); widget->setPos(170.0f, 50.0f); item = new QGraphicsPixmapItem(); item->setParentItem(widget); item->setPos(((BLOCK_LARGE * 10) - (320.0f / 0.75f)) * 0.5f, (BLOCK_LARGE * 20) - 320.0f); _avatar = widget; } // Help { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 10, BLOCK_LARGE * 20); widget->setFlags(QGraphicsItem::ItemClipsChildrenToShape); widget->setParentItem(_sprite); widget->setPos(170.0f, 50.0f); rect = new QGraphicsRectItem(0.0f, 0.0f, BLOCK_LARGE * 10, BLOCK_LARGE * 20); rect->setBrush(QBrush(QColor::fromRgb(0x00, 0x00, 0x00, 0xC0))); rect->setParentItem(widget); font = QApplication::font(); font.setFamily("Arial"); font.setPixelSize(16); font.setWeight(QFont::Bold); font.setStretch(80); text = new QGraphicsSimpleTextItem(tr("Slide left and right: Move.")); text->setBrush(QColor::fromRgb(0xC0, 0xC0, 0xC0)); text->setFont(font); text->setParentItem(widget); text->setPos(((BLOCK_LARGE * 10) - text->boundingRect().width()) * 0.5f, 217.0f - 6.0f); text = new QGraphicsSimpleTextItem(tr("Swipe up: Hold. Swipe down: Drop.")); text->setBrush(QColor::fromRgb(0xC0, 0xC0, 0xC0)); text->setFont(font); text->setParentItem(widget); text->setPos(((BLOCK_LARGE * 10) - text->boundingRect().width()) * 0.5f, 237.0f - 6.0f); text = new QGraphicsSimpleTextItem(tr("Pull back, and make circles: Rotate.")); text->setBrush(QColor::fromRgb(0xC0, 0xC0, 0xC0)); text->setFont(font); text->setParentItem(widget); text->setPos(((BLOCK_LARGE * 10) - text->boundingRect().width()) * 0.5f, 257.0f - 6.0f); // widget->setVisible(false); _sprite_help = widget; } // Lines { rect = new QGraphicsRectItem(120.0f - 1.0f, 220.0f - 1.0f, 8.0f + 2.0f, 144.0f + 2.0f); rect->setBrush(QBrush(LoaderThread::instance()->getCachedPixmap(IMAGE_LINES_PROGRESS))); rect->setParentItem(_sprite); _sprite_lines = rect; } // Frame { item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_FRAME_FG)); item->setParentItem(_sprite); item->setPos(0.0f, 0.0f); } // Field { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 10, BLOCK_LARGE * 20); widget->setFlags(QGraphicsItem::ItemClipsChildrenToShape); widget->setParentItem(_sprite); widget->setPos(170.0f, 50.0f); _sprite_field = widget; _sprite_space.fill(NULL, _rows * _cols); } // Ghost { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 4, BLOCK_LARGE * 4); widget->setParentItem(_sprite_field); widget->setPos(BLOCK_LARGE * getShapePositionInField(18, 3)); for (int i = 0; i < 4; ++i) { item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_BLOCK_GHOST)); item->setParentItem(widget); } _sprite_ghost = widget; } // Tetromino { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 4, BLOCK_LARGE * 4); widget->setParentItem(_sprite_field); widget->setPos(BLOCK_LARGE * getShapePositionInField(18, 3)); widget->setZValue(1.0f); effect = new QGraphicsColorizeEffect(widget); effect->setColor(QColor::fromRgb(0xFF, 0xFF, 0xFF)); effect->setStrength(0.0f); widget->setGraphicsEffect(effect); for (int i = 0; i < 4; ++i) { item = new QGraphicsPixmapItem(); item->setParentItem(widget); } _sprite_tetromino = widget; } // Hold { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 4, BLOCK_LARGE * 2); widget->setScale(BLOCK_SMALL / BLOCK_LARGE); widget->setParentItem(_sprite); widget->setPos(56.0f, 108.0f + BLOCK_SMALL); effect = new QGraphicsColorizeEffect(widget); effect->setColor(QColor::fromRgb(0xFF, 0xFF, 0xFF)); effect->setStrength(0.0f); widget->setGraphicsEffect(effect); for (int i = 0; i < 4; ++i) { item = new QGraphicsPixmapItem(); item->setParentItem(widget); } _sprite_hold = widget; } // Hold fail { item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_FAIL)); item->setScale(BLOCK_SMALL / BLOCK_LARGE); item->setParentItem(_sprite); item->setPos(56.0f + (BLOCK_SMALL * 3), 108.0f + (BLOCK_SMALL * 3)); item->setVisible(false); _sprite_holdFail = item; } // Next { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 4, BLOCK_LARGE * 2); widget->setScale(BLOCK_SMALL / BLOCK_LARGE); widget->setParentItem(_sprite); widget->setPos(460.0f, 108.0f + BLOCK_SMALL); effect = new QGraphicsColorizeEffect(widget); effect->setColor(QColor::fromRgb(0xFF, 0xFF, 0xFF)); effect->setStrength(0.0f); widget->setGraphicsEffect(effect); for (int i = 0; i < 4; ++i) { item = new QGraphicsPixmapItem(); item->setParentItem(widget); } _sprite_next << widget; } // Next { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 4, BLOCK_LARGE * 2); widget->setScale(BLOCK_SMALL / BLOCK_LARGE); widget->setParentItem(_sprite); widget->setPos(460.0f, 228.0f + BLOCK_SMALL); effect = new QGraphicsColorizeEffect(widget); effect->setColor(QColor::fromRgb(0xFF, 0xFF, 0xFF)); effect->setStrength(0.0f); widget->setGraphicsEffect(effect); for (int i = 0; i < 4; ++i) { item = new QGraphicsPixmapItem(); item->setParentItem(widget); } _sprite_next << widget; } // Next { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 4, BLOCK_LARGE * 2); widget->setScale(BLOCK_SMALL / BLOCK_LARGE); widget->setParentItem(_sprite); widget->setPos(460.0f, 292.0f + BLOCK_SMALL); effect = new QGraphicsColorizeEffect(widget); effect->setColor(QColor::fromRgb(0xFF, 0xFF, 0xFF)); effect->setStrength(0.0f); widget->setGraphicsEffect(effect); for (int i = 0; i < 4; ++i) { item = new QGraphicsPixmapItem(); item->setParentItem(widget); } _sprite_next << widget; } // Font { font = QApplication::font(); font.setCapitalization(QFont::AllUppercase); } // Hold { text = new QGraphicsSimpleTextItem(tr("Hold")); text->setBrush(QColor::fromRgb(0x00, 0x00, 0x00)); text->setFont(font); text->setParentItem(_sprite); text->setPos(56.0f, 80.0f - 6.0f); } // Next { text = new QGraphicsSimpleTextItem(tr("Next")); text->setBrush(QColor::fromRgb(0x00, 0x00, 0x00)); text->setFont(font); text->setParentItem(_sprite); text->setPos(526.0f - text->boundingRect().width(), 80.0f - 6.0f); } // Level { text = new QGraphicsSimpleTextItem(tr("Level")); text->setBrush(QColor::fromRgb(0x00, 0x00, 0x00)); text->setFont(font); text->setParentItem(_sprite); text->setPos(56.0f, 316.0f - 6.0f); } // Level { label = new QLabel(); label->resize(48, 24); label->setStyleSheet("background-color: transparent; color: #FFFFFF;"); label->setAlignment(Qt::AlignTop | Qt::AlignLeft); proxy = new QGraphicsProxyWidget(); proxy->setParentItem(_sprite); proxy->setWidget(label); proxy->setPos(56.0f, 344.0f - 6.0f); _sprite_level = label; } // Score { text = new QGraphicsSimpleTextItem(tr("Score")); text->setBrush(QColor::fromRgb(0x00, 0x00, 0x00)); text->setFont(font); text->setParentItem(_sprite); text->setPos(176.0f, 564.0f - 6.0f); } // Score { label = new QLabel(); label->resize(148, 24); label->setStyleSheet("background-color: transparent; color: #FFFFFF;"); label->setAlignment(Qt::AlignTop | Qt::AlignRight); proxy = new QGraphicsProxyWidget(); proxy->setParentItem(_sprite); proxy->setWidget(label); proxy->setPos(256.0f, 564.0f - 6.0f); _sprite_score = label; } // Countdown { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 10, BLOCK_LARGE * 20); widget->setFlags(QGraphicsItem::ItemClipsChildrenToShape); widget->setParentItem(_sprite); widget->setPos(170.0f, 50.0f); rect = new QGraphicsRectItem(0.0f, 0.0f, BLOCK_LARGE * 10, BLOCK_LARGE * 20); rect->setBrush(QBrush(QColor::fromRgb(0x00, 0x00, 0x00, 0xC0))); rect->setParentItem(widget); item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_COUNT[0])); item->setParentItem(widget); item->setPos(77.0f, 197.0f); item->setVisible(false); _sprite_count << item; item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_COUNT[1])); item->setParentItem(widget); item->setPos(77.0f, 197.0f); item->setVisible(false); _sprite_count << item; item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_COUNT[2])); item->setParentItem(widget); item->setPos(77.0f, 197.0f); item->setVisible(false); _sprite_count << item; widget->setVisible(false); _sprite_countdown = widget; } // Game over { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 10, BLOCK_LARGE * 20); widget->setFlags(QGraphicsItem::ItemClipsChildrenToShape); widget->setParentItem(_sprite); widget->setPos(170.0f, 50.0f); widget->setZValue(8.0f); rect = new QGraphicsRectItem(0.0f, 0.0f, BLOCK_LARGE * 10, BLOCK_LARGE * 20); rect->setBrush(QBrush(QColor::fromRgb(0x00, 0x00, 0x00, 0xC0))); rect->setParentItem(widget); item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_OVER)); item->setParentItem(widget); item->setPos(4.0f, 172.0f); rect = new QGraphicsRectItem(0.0f, 0.0f, BLOCK_LARGE * 10, BLOCK_LARGE * 20); rect->setBrush(QBrush(QColor::fromRgb(0xFF, 0xFF, 0xFF))); rect->setParentItem(widget); _sprite_overFlash = rect; widget->setVisible(false); _sprite_over = widget; } }
void UpdColor() { text->setBrush(grobjs->player_text_brush[color]); }
CalendarGraphicsItem::CalendarGraphicsItem(CalendarControl * cc, QGraphicsItem * parent) : QGraphicsRectItem(0.0, 0.0, __width, __height, parent) { _controller = cc; QDate today = QDate::currentDate(); QDate firstMonthDay = QDate(today.year(), today.month(), 1); QDate firstCalendarDay = firstMonthDay.addDays(firstMonthDay.dayOfWeek() * -1); if(firstMonthDay.dayOfWeek() < 2) firstCalendarDay = firstCalendarDay.addDays(-7); _selectedDay = today; QString prev = QObject::tr("<"); QString prevprev = QObject::tr("<<"); QString next = QObject::tr(">"); QString nextnext = QObject::tr(">>"); QGraphicsSimpleTextItem * textItem; QGraphicsRectItem * rectItem; rectItem = new QGraphicsRectItem(0.0, 0.0, __width, __titleHeight, this); rectItem->setBrush(blackFill); _items.insert("titleBackground", rectItem); textItem = new QGraphicsSimpleTextItem(today.toString("MMMM yyyy"), this); textItem->setFont(monthfont); textItem->setZValue(2); textItem->setBrush(whiteFill); QPointF ct = rectItem->boundingRect().center(); QRectF rt = textItem->boundingRect(); textItem->setPos(ct.x() - (rt.width() / 2), ct.y() - (rt.height() / 2)); _items.insert("title", textItem); qreal offset = 0.1 * __dpi; qreal nw = 0; GraphicsTextButtonItem * tbtnItem = 0; tbtnItem = new GraphicsTextButtonItem(prevprev, this); tbtnItem->setFont(navfont); tbtnItem->setZValue(3); tbtnItem->setBrush(Qt::lightGray); tbtnItem->setRolloverBrush(Qt::green); tbtnItem->scale(0.5, 1); tbtnItem->setReceiver(this); rt = tbtnItem->boundingRect(); tbtnItem->setPos(offset, ct.y() - (rt.height() / 2)); nw = rt.width(); _items.insert("fastrewind", tbtnItem); tbtnItem = new GraphicsTextButtonItem(nextnext, this); tbtnItem->setFont(navfont); tbtnItem->setZValue(3); tbtnItem->setBrush(Qt::lightGray); tbtnItem->setRolloverBrush(Qt::green); tbtnItem->scale(0.5, 1); tbtnItem->setReceiver(this); rt = tbtnItem->boundingRect(); tbtnItem->setPos(rectItem->boundingRect().right() - offset - (rt.width() / 2), ct.y() - (rt.height() / 2)); nw = qMax(nw, rt.width()) / 2; offset += (nw * 1.5); _items.insert("fastforward", tbtnItem); tbtnItem = new GraphicsTextButtonItem(prev, this); tbtnItem->setFont(navfont); tbtnItem->setZValue(3); tbtnItem->setBrush(Qt::lightGray); tbtnItem->setRolloverBrush(Qt::green); tbtnItem->scale(0.5, 1); tbtnItem->setReceiver(this); rt = tbtnItem->boundingRect(); tbtnItem->setPos(offset, ct.y() - (rt.height() / 2)); _items.insert("rewind", tbtnItem); tbtnItem = new GraphicsTextButtonItem(next, this); tbtnItem->setFont(navfont); tbtnItem->setZValue(3); tbtnItem->setBrush(Qt::lightGray); tbtnItem->setRolloverBrush(Qt::green); tbtnItem->scale(0.5, 1); tbtnItem->setReceiver(this); rt = tbtnItem->boundingRect(); tbtnItem->setPos(rectItem->boundingRect().right() - offset - (rt.width() / 2), ct.y() - (rt.height() / 2)); _items.insert("forward", tbtnItem); QDate date; qreal dayWidth = __width / 7.0; QApplication::setOverrideCursor(Qt::WaitCursor); for(int wday = 0; wday < 7; wday++) { for(int week = 0; week < 6; week++) { date = firstCalendarDay.addDays((7 * week) + wday); if(0 == week) { rectItem = new QGraphicsRectItem(wday * dayWidth, 0.5 * __dpi, dayWidth, 0.25 * __dpi, this); _items.insert(QString("weekday%1").arg(week), rectItem); textItem = new QGraphicsSimpleTextItem(date.toString("dddd"), this); textItem->setFont(wdayfont); textItem->setZValue(2); ct = rectItem->boundingRect().center(); rt = textItem->boundingRect(); textItem->setPos(ct.x() - (rt.width() / 2), ct.y() - (rt.height() / 2)); _items.insert(QString("weekday%1Text").arg(week), textItem); } QBrush fill; QBrush dayFill = blackFill; if(date == _selectedDay) fill = selectedFill; else if(date.month() != today.month()) { fill = nonMonthFill; dayFill = nonMonthDayFill; } else if(date == today) fill = todayFill; else if(date.dayOfWeek() > 5) fill = weekendFill; rectItem = new QGraphicsRectItem(wday * dayWidth, (0.75 + (1.25 * week)) * __dpi, dayWidth, 1.25 * __dpi, this); rectItem->setBrush(fill); _items.insert(QString("day%1").arg((7 * week) + wday), rectItem); rt = QRectF(rectItem->pos(), rectItem->boundingRect().size()); double offset = rt.width() / 3; textItem = new QGraphicsSimpleTextItem(QString::number(date.day()), this); textItem->setFont(dayfont); textItem->setZValue(2); textItem->setBrush(dayFill); textItem->setPos(rectItem->boundingRect().topLeft()); textItem->moveBy(5.0, 5.0); _items.insert(QString("day%1Number").arg((7 * week) + wday), textItem); rt = QRectF(textItem->pos(), textItem->boundingRect().size()); QString additionalText; if(_controller) additionalText = _controller->contents(date); textItem = new QGraphicsSimpleTextItem(additionalText, this); textItem->setFont(notesfont); textItem->setZValue(2); textItem->setBrush(dayFill); textItem->setPos(rt.left() + offset, rt.top() + (rt.height() * 1.5)); _items.insert(QString("day%1Text").arg((7 * week) + wday), textItem); } } QApplication::restoreOverrideCursor(); }
void CalendarGraphicsItem::setSelectedDay(const QDate & sDate) { //if(sDate == _selectedDay) // return; _selectedDay = sDate; QDate today = QDate::currentDate(); QDate firstMonthDay = QDate(_selectedDay.year(), _selectedDay.month(), 1); QDate firstCalendarDay = firstMonthDay.addDays(firstMonthDay.dayOfWeek() * -1); if(firstMonthDay.dayOfWeek() < 2) firstCalendarDay = firstCalendarDay.addDays(-7); QGraphicsRectItem * titleBackground = static_cast<QGraphicsRectItem*>(_items["titleBackground"]); QGraphicsSimpleTextItem * title = static_cast<QGraphicsSimpleTextItem*>(_items["title"]); if(title && titleBackground) { title->setText(_selectedDay.toString("MMMM yyyy")); QPointF ct = titleBackground->boundingRect().center(); QRectF rt = title->boundingRect(); title->setPos(ct.x() - (rt.width() / 2), ct.y() - (rt.height() / 2)); } QDate date; QApplication::setOverrideCursor(Qt::WaitCursor); for(int wday = 0; wday < 42; wday++) { date = firstCalendarDay.addDays(wday); QBrush fill; QBrush dayFill = blackFill; if(date == _selectedDay) fill = selectedFill; else if(date.month() != _selectedDay.month()) { fill = nonMonthFill; dayFill = nonMonthDayFill; } else if(date == today) fill = todayFill; else if(date.dayOfWeek() > 5) fill = weekendFill; QString additionalText; if(_controller) additionalText = _controller->contents(date); QGraphicsRectItem * ri = static_cast<QGraphicsRectItem*>(_items[QString("day%1").arg(wday)]); if(ri) ri->setBrush(fill); QGraphicsSimpleTextItem * si = static_cast<QGraphicsSimpleTextItem*>(_items[QString("day%1Number").arg(wday)]); if(si) { si->setText(QString::number(date.day())); si->setBrush(dayFill); } QGraphicsSimpleTextItem * si2 = static_cast<QGraphicsSimpleTextItem*>(_items[QString("day%1Text").arg(wday)]); if(si2) { si2->setText(additionalText); si2->setBrush(dayFill); } } QApplication::restoreOverrideCursor(); if(_controller) _controller->setSelectedDay(_selectedDay); }
void MenuEquipmentScreen::setCurrentEquipmentItem(QGraphicsSimpleTextItem *item, EquipmentPiece *equipment) { // Set brushes QBrush whiteBrush(Qt::white); QBrush yellowBrush(Qt::yellow); QBrush greenBrush(Qt::green); QBrush redBrush(Qt::red); QFont font("Times", 12, QFont::Bold); // Set current item if (!!_currentEquipmentListItem) _currentEquipmentListItem->setBrush(whiteBrush); _currentEquipmentListItem = item; _currentEquipmentListItem->setBrush(yellowBrush); // Reset the updated equipment stats _updatedStatsItem->setText(QString()); for (int i = 0; i < _updatedStatsItems.size(); i++) delete _updatedStatsItems.at(i); _updatedStatsItems.clear(); // Set the updated equipment stats QPointF position(_updatedStatsItem->pos().x(), _updatedStatsItem->pos().y() + 20); _updatedStatsItem->setText("Preview:"); QVector<QPair<Attribute*, int>> currentEquipped(0); if (!!_currentEquippedEquipmentPiece) currentEquipped = _currentEquippedEquipmentPiece->getAttributes(); QVector<QPair<Attribute*, int>> previewEquipped(0); if (!!equipment) previewEquipped = equipment->getAttributes(); // First go over all of the currently equipped // attributes for comparison. for (int i = 0; i < currentEquipped.size(); i++) { QPair<Attribute*, int> it1 = currentEquipped.at(i); QPair<Attribute*, int> it2(0, 0); for (int j = 0; j < previewEquipped.size();) { if (previewEquipped.at(j).first == it1.first) { it2 = previewEquipped.at(j); previewEquipped.remove(j); break; } else { j++; } } QGraphicsSimpleTextItem *item = new QGraphicsSimpleTextItem(_updatedStatsPanel); item->setText(it1.first->getName() + " + " + QString::number(it2.second)); item->setFont(font); item->setPos(position); // Set brush if (it1.second > it2.second) item->setBrush(redBrush); else if (it1.second < it2.second) item->setBrush(greenBrush); else item->setBrush(whiteBrush); position.setY(position.y() + 20); _updatedStatsItems.append(item); } // Go over all the attributes of the considered // Equipment Piece for comparison. for (int i = 0; i < previewEquipped.size(); i++) { QPair<Attribute*, int> it = previewEquipped.at(i); QGraphicsSimpleTextItem *item = new QGraphicsSimpleTextItem(_updatedStatsPanel); item->setText(it.first->getName() + " + " + QString::number(it.second)); item->setFont(font); item->setBrush(greenBrush); item->setPos(position); position.setY(position.y() + 20); _updatedStatsItems.append(item); } }
void LogScene::getTaskItem(const QModelIndex &index) { Task* task = _model->task(index); Calendar* calendar = task->project()->projectDefaultCalendar(); int hoursInDay = calendar->endHour().hour() - calendar->startHour().hour(); std::vector<TaskLog*>* logs =task->logs(); double startHour = 0;//calendar->startHour().hour(); double endHour = 24;//calendar->endHour().hour() + 1; double minuteSize = (double)24*BLOCKSIZE / (double)((endHour - startHour) * 60); int red = 0; for (std::vector<TaskLog*>::iterator iter = logs->begin(); iter != logs->end(); iter++) { TaskLog* log = *iter; QSize size = sizeHint(index); int bordermargin = (size.height() * .4) / 2; int daysToStart = _startDate.daysTo(*log->start); double x1 = (double)daysToStart * (double)_dayWidth; DTime logStartTime = log->start->time(); double y1 = (double)(logStartTime.totalMinutes() - (startHour*60)) * minuteSize; double x2 = (daysToStart + 1) * (double)_dayWidth; DTime logEndTime = log->end->time(); if (log->end->getDay() != log->start->getDay()) { logEndTime = DTime(23, 59, 59); } double y2 = (double)(logEndTime.totalMinutes() - (startHour*60)) * minuteSize; QBrush b(task->taskColor());//QImage(":/img/task_bar.png"));//(QPixmap(":/img/task_bar.png")); red += 20; QColor penColor((task->taskColor().red() < 100) ? 0: (task->taskColor().red() - 100), (task->taskColor().green() < 100) ? 0: (task->taskColor().green() - 100), (task->taskColor().blue() < 100) ? 0: (task->taskColor().blue() - 100)); QPen pen(penColor); if (log->activeLog) { pen.setWidth(3); } QGraphicsItem* item = this->addRect(x1, y1, (x2 - x1), (y2 - y1), pen, b); item->setZValue(1); if ((y2 - y1) > 20) { QFont f("Arial", 8); f.setWeight(QFont::Light); QBrush brush(penColor); std::string description = *task->shortDescription(); int textY = y1 + 5; while (description.length() > 0) { std::string label; if (description.length() > 15) { label = description.substr(0, 15); description = description.substr(15); if ((label.at(label.length() - 1) != ' ') && (description.at(0) != ' ')) { int pos; if ((pos = label.rfind(' ')) != std::string::npos) { description = label.substr(pos) + description; label = label.substr(0, pos); } } } else { label = description; description = ""; } label = label.erase(label.find_last_not_of(" \n\r\t")+1); description = description.erase(description.find_last_not_of(" \n\r\t")+1); if ((textY + 20) < y2) { QGraphicsSimpleTextItem* text = this->addSimpleText(tr(label.c_str())); text->setPos(x1 + 10, textY); //text->rotate(90); text->setVisible(true); text->setBrush(brush); text->setFont(f); text->setZValue(2); textY += 15; } else { break; } } } _currentY += sizeHint(index).height(); } delete(logs); }
void ScheduleScreen::createScheduleScene() { QPen pen(Qt::blue); QBrush brush(Qt::black); QFont font = this->font(); font.setBold(true); QFontMetrics fm(font); weekHeight = (scene->height()/7.0)-(scene->height()*.025); pointArea.setRect(fm.boundingRect("Wed").width()+20, 15, scene->width(), weekHeight*7); timeWidth = ((pointArea.width() - pointArea.left())/4.0)-((pointArea.width() - pointArea.left())/4.0)/16; timeBlockWidth = timeWidth/24.0; //15 min increments pointArea.adjust(0,0,-timeBlockWidth, 0); QDate date = QDate::fromString("Sun", "ddd"); for(int a = 0;a<7;a++) { pen.setColor(QColor(110+40*(a%2),110+40*(a%2),110+40*(a%2))); brush.setColor(QColor(120+40*(a%2),120+40*(a%2),120+40*(a%2))); scene->addRect(0,pointArea.top()+a*weekHeight,pointArea.width(),weekHeight, pen, brush); pen.setColor(QColor(150,150,150)); brush.setColor(QColor(180,180,180)); scene->addRect(0,pointArea.top()+a*weekHeight,pointArea.left(),weekHeight-1, pen, brush); date = date.addDays(1); QString dateString = date.toString("ddd"); pen.setColor(QColor(50,50,50)); QPushButton* b = new QPushButton; connect(b, SIGNAL(clicked(bool)), this, SLOT(disableRow(bool))); b->setFlat(true); b->setFont(font); b->setFocusPolicy(Qt::NoFocus); b->setMaximumWidth(pointArea.left()-4); b->setMaximumHeight(weekHeight-4); QPalette buttonPalette(QColor(180,180,180)); //buttonPalette.setColor(QPalette::Active, QPalette::Button, QColor(180,180,180)); b->setPalette(buttonPalette); b->setCheckable(true); b->setChecked(true); b->setText(dateString); b->setProperty("dayNumber", date.dayOfWeek()-1); QGraphicsProxyWidget* textItem = new QGraphicsProxyWidget; textItem->setWidget(b); scene->addItem(textItem); textItem->setPos(pointArea.left()/2 - textItem->boundingRect().width()/2, pointArea.top()+ a*weekHeight + weekHeight/2 - textItem->boundingRect().height()/2); } scene->addLine(pointArea.left(), pointArea.top()+1, pointArea.left(), scene->height()-1); for(int a = 0;a<5;a++) { pen.setColor(QColor(110+40*(a%2),110+40*(a%2),110+40*(a%2))); brush.setColor(QColor(120+40*(a%2),120+40*(a%2),120+40*(a%2))); QString timeString = formatHourString(QTime(((a)*6)%24,0), m_globalSettings->timeFormat()); pen.setColor(QColor(200,200,200)); brush.setColor(QColor(200,200,200)); QGraphicsSimpleTextItem* textItem = scene->addSimpleText(timeString, font); textItem->setBrush(brush); textItem->setPos(timeBlockWidth*3+pointArea.left()+timeWidth*a - textItem->boundingRect().width()/2, pointArea.bottom() +6); pen.setColor(QColor(188,188,188)); pen.setStyle(Qt::DashLine); scene->addLine(timeBlockWidth*3+pointArea.left()+timeWidth*a, pointArea.top()+1, timeBlockWidth*3+pointArea.left()+timeWidth*a, pointArea.bottom()+3, pen); } }
void Gui::createLaserDistanceObjects() { // set colors colorHelpLine = Qt::gray; colorHelpLineText = Qt::gray; //-------------------------------------------------------------- // create the FRONT laser line distances with text //-------------------------------------------------------------- laserDistanceLineListFront = new QList <QGraphicsEllipseItem*>(); laserDistanceTextFront = new QList <QGraphicsSimpleTextItem*>(); // create and add twelve semi circles and text for (int i=0; i<LASERDISTANCECIRCLES; i++) { // create semi circles // position doesn't matter, because of moving circles in setLaserDistancePosition()! So we just take 0,0 here. QGraphicsEllipseItem *semiCircle = new QGraphicsEllipseItem(0, 0, LASERDISTANCEFIRSTCIRCLE + (i*LASERDISTANCEDISTANCE), LASERDISTANCEFIRSTCIRCLE + (i*LASERDISTANCEDISTANCE)); // create an (empty) text QGraphicsSimpleTextItem *text = new QGraphicsSimpleTextItem(); // set the start angle of the circle semiCircle->setStartAngle(180*16); // set the span angle of the circle semiCircle->setSpanAngle(180*16); // set semiCircle color semiCircle->setPen(QPen(colorHelpLine)); // set text color text->setBrush(QBrush(colorHelpLine)); // setting to the highest layer level semiCircle->setZValue(4); text->setZValue(4); // add semiCircle to QList laserDistanceLineListFront->append(semiCircle); laserDistanceTextFront->append(text); // add semiCircle to scene scene->addItem(semiCircle); // add text to scene scene->addItem(text); } //-------------------------------------------------------------- // create the REAR laser line distances with text //-------------------------------------------------------------- laserDistanceLineListRear = new QList <QGraphicsEllipseItem*>(); laserDistanceTextRear = new QList <QGraphicsSimpleTextItem*>(); // create and add twelve semi circles and text for (int i=0; i<LASERDISTANCECIRCLES; i++) { // create semi circles // position doesn't matter, because of moving circles in setLaserDistancePosition()! So we just take 0,0 here. QGraphicsEllipseItem *semiCircle = new QGraphicsEllipseItem(0, 0, LASERDISTANCEFIRSTCIRCLE + (i*LASERDISTANCEDISTANCE), LASERDISTANCEFIRSTCIRCLE + (i*LASERDISTANCEDISTANCE)); // create an (empty) text QGraphicsSimpleTextItem *text = new QGraphicsSimpleTextItem(); // set the start angle of the circle semiCircle->setStartAngle(0); // set the span angle of the circle semiCircle->setSpanAngle(180*16); // set semiCircle color semiCircle->setPen(QPen(colorHelpLine)); // set text color text->setBrush(QBrush(colorHelpLine)); // setting to the highest layer level semiCircle->setZValue(4); text->setZValue(4); // add semiCircle to QList laserDistanceLineListRear->append(semiCircle); laserDistanceTextRear->append(text); // add semiCircle to scene scene->addItem(semiCircle); // add text to scene scene->addItem(text); } }
void TerrainProfileGraph::drawAxes(double yMin, double yMax, double yScale, double xMax, QRect &out_field) { QBrush axesBrush(_axesColor); // Create min/max text items QGraphicsSimpleTextItem* yMinText = new QGraphicsSimpleTextItem(QString::number(yMin)); yMinText->setBrush(axesBrush); yMinText->setFont(_graphFont); QGraphicsSimpleTextItem* yMaxText = new QGraphicsSimpleTextItem(QString::number(yMax)); yMaxText->setBrush(axesBrush); yMaxText->setFont(_graphFont); QGraphicsSimpleTextItem* xMaxText = new QGraphicsSimpleTextItem(QString::number(xMax)); xMaxText->setBrush(axesBrush); xMaxText->setFont(_graphFont); // Calculate positioning offsets and set out_field to actual graph bounds double fontHalfHeight = yMinText->boundingRect().height() / 2.0; int textSpacing = 8; int xOffset = (int)osg::maximum(yMinText->boundingRect().width(), yMaxText->boundingRect().width()) + textSpacing; int yOffset = (int)xMaxText->boundingRect().height() + textSpacing; int xAxisY = _graphHeight - yOffset; out_field.setCoords(xOffset, (int)fontHalfHeight, _graphWidth, xAxisY); // Draw background rectangle _scene->addRect(out_field, QPen(Qt::NoPen), QBrush(_fieldColor))->setZValue(FIELD_Z); // Add min/max text items to the scene yMinText->setPos(xOffset - textSpacing - yMinText->boundingRect().width(), xAxisY - fontHalfHeight); yMinText->setZValue(AXES_Z); _scene->addItem(yMinText); yMaxText->setPos(xOffset - textSpacing - yMaxText->boundingRect().width(), 0); yMaxText->setZValue(AXES_Z); _scene->addItem(yMaxText); xMaxText->setPos(_graphWidth - xMaxText->boundingRect().width(), _graphHeight - xMaxText->boundingRect().height()); xMaxText->setZValue(AXES_Z); _scene->addItem(xMaxText); // Draw the main axes and x-axis end cap _scene->addLine(xOffset, fontHalfHeight, xOffset, xAxisY + 5, _axesPen)->setZValue(AXES_Z); _scene->addLine(xOffset - 5, xAxisY, _graphWidth, xAxisY, _axesPen)->setZValue(AXES_Z); _scene->addLine(_graphWidth, xAxisY - 5, _graphWidth, xAxisY + 5, _axesPen)->setZValue(AXES_Z); // Draw horizontal graph lines double yGraphScale = (yScale / (yMax - yMin)) * out_field.height(); double graphLineY = xAxisY - yGraphScale; for (double y = yMin + yScale; y <= yMax; y += yScale) { _scene->addLine(xOffset - 5, graphLineY, _graphWidth, graphLineY, _axesPen)->setZValue(AXES_Z);; if (y != yMax) { QGraphicsSimpleTextItem* yText = new QGraphicsSimpleTextItem(QString::number(y)); yText->setBrush(axesBrush); yText->setFont(_graphFont); yText->setPos(xOffset - textSpacing - yText->boundingRect().width(), graphLineY - fontHalfHeight); yText->setZValue(AXES_Z); _scene->addItem(yText); } graphLineY -= yGraphScale; } }
bool ZipplXmlReader::read( QIODevice *dev ) { setDevice( dev ); bool res = true; bool metaMode = false; mCurrParent = 0; mCurrSpot = 0; QGraphicsScene *scene = mGraphWidget->scene(); int spotID = 0; while (!atEnd()) { readNext(); if( isStartElement() ) { qDebug() << "XML name: " << name(); if( name() == "presentation") { // presentation mode: debug & presentation QString mode = attributes().value("mode").toString(); if( !mode.isEmpty() ) mMode = mode; mPath = attributes().value("path").toString(); if( !mPath.endsWith('/') ) mPath += "/"; qreal dx = qrealAttrib("width") / -2.0; qreal dy = qrealAttrib("height") / -2.0; QRectF rect( dx, dy, -2.0*dx, -2.0*dy ); scene->setSceneRect( rect ); } else if( name() == "meta" ) { metaMode = true; } else if( name() == "title" && metaMode ) { mPresentationTitle = readElementText(); } else if( name() == "description" && metaMode ) { mPresentationDescr = readElementText(); } else if( name() == "date" && metaMode ) { mPresentationDate = readElementText(); } else if( name() == "name" && metaMode ) { mAuthorName = readElementText(); } else if( name() == "email" && metaMode ) { mAuthorEmail = readElementText(); } else if( name() == "tocentry" ) { if( mCurrSpot ) { mCurrSpot->setData( TOCENTRY, readElementText() ); } } else if( name() == "spot" ) { if( mCurrParent != 0 ) { qDebug() << "Strange: Current Parent should be zero here!"; } QGraphicsRectItem *rectItem = new QGraphicsRectItem( ); rectItem->setPen( pen( rectItem->pen(), QColor("#aeaeae") )); mCurrParent = rectItem; mCurrSpot = rectItem; mCurrParent->setData( ID, QVariant( spotID++ )); mCurrParent->setPos( position() ); rectItem->setBrush( brush( rectItem->brush() ) ); scene->addItem( mCurrParent ); mSpots.append( mCurrParent ); // Prepare the hidden items list GraphicsItemList list; mHiddenItems.insert( mCurrParent, list ); } else if( name() == "hidden" ) { QGraphicsRectItem *rectItem = new QGraphicsRectItem( mCurrParent, scene ); rectItem->setPen( QPen( QColor( 240, 240, 240 ))); // append this hidden item to the list of hiddens of the parent spot. GraphicsItemList list = mHiddenItems[mCurrSpot]; list.append( rectItem ); mHiddenItems[mCurrSpot] = list; mCurrParent = rectItem; mCurrParent->setData( ID, QVariant( spotID++ )); } else if( name() == "rect" ) { if( mCurrParent ) { // within a spot qDebug() << "Creating a rectangle!"; QGraphicsRectItem *rectItem = new QGraphicsRectItem( mCurrParent, scene ); qreal width = qrealAttrib( "width" ); qreal height = qrealAttrib( "height" ); QPointF pos = position(); if( width > 0 && height > 0 ) { rectItem->setRect( pos.x(), pos.y(), width, height ); } else { rectItem->setPos( pos ); } rectItem->setPen( pen( rectItem->pen() ) ); mCurrParent = rectItem; } } else if( name() == "circle" ) { QPointF pos = position(); QGraphicsEllipseItem *ellipse = new QGraphicsEllipseItem( mCurrParent, scene ); // ellipse->setBrush( getBrush() ); qreal r = 2.0 * qrealAttrib( "r" ); QRectF rect( pos, QSizeF( r, r ) ); ellipse->setPen( pen( ellipse->pen() ) ); ellipse->setRect( rect ); } else if( name() == "text" ) { QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem( mCurrParent, scene ); QString font = attributes().value("font").toString(); QString size = attributes().value("size").toString(); QFont currFont = textItem->font(); if( !font.isEmpty() ) { currFont.setFamily( font ); textItem->setFont( currFont ); } if( !size.isEmpty() ) { currFont.setPointSize( size.toInt() ); textItem->setFont( currFont ); } textItem->setPos( position() ); // set the brush QBrush b( textItem->brush() ); b.setColor( color() ); textItem->setBrush( b ); QString text = readElementText(); textItem->setText( text ); } else if( name() == "image" ) { if( handleImg( scene ) ) { } } } else if( isEndElement() ) { qDebug( ) << "XML CLOSE: " << name().toString(); if( name() == "spot" || name() == "toc" ) { QRectF rect = mCurrParent->childrenBoundingRect(); rect.setX(0); rect.setY(0); qgraphicsitem_cast<QGraphicsRectItem*>(mCurrParent)->setRect( rect); mCurrParent = 0; } else if( name() == "rect" ) { QGraphicsRectItem *item = qgraphicsitem_cast<QGraphicsRectItem*>(mCurrParent); if( item->rect().isEmpty() ) item->setRect( mCurrParent->childrenBoundingRect() ); mCurrParent = mCurrParent->parentItem(); } else if( name() == "hidden") { mCurrParent->setOpacity( 0.0 ); mCurrParent = mCurrParent->parentItem(); } else if( name() == "meta" ) { metaMode = false; } } } createToc( scene ); return res; }
void TerrainProfileGraph::drawHoverCursor(const QPointF& position) { if (_hoverLine) { _scene->removeItem(_hoverLine); delete _hoverLine; _hoverLine = 0L; } if (_graphField.width() < 2 || _graphField.height() < 2) return; double xPos = position.x() < _graphField.x() ? _graphField.x() : (position.x() > _graphField.x() + _graphField.width() ? _graphField.x() + _graphField.width() : position.x()); QLineF vLine(xPos, _graphField.y(), xPos, _graphField.y() + _graphField.height()); QPointF* intersect = new QPointF; bool foundIntersect = false; for (int i=0; i < _graphLines.count(); i++) { if (vLine.intersect(_graphLines[i], intersect) == QLineF::BoundedIntersection) { foundIntersect = true; break; } } if (foundIntersect) { // Draw the upper line segment. Also serves as the parent item. _hoverLine = new QGraphicsLineItem(xPos, _graphField.y(), xPos, intersect->y() - 3); _hoverLine->setPen(_hoverPen); _hoverLine->setZValue(OVERLAY_Z); _scene->addItem(_hoverLine); // Draw the box around the intersect point QGraphicsRectItem* hoverBox = new QGraphicsRectItem(xPos - 3, intersect->y() - 3, 6, 6); hoverBox->setPen(_hoverPen); hoverBox->setBrush(Qt::NoBrush); hoverBox->setZValue(OVERLAY_Z); hoverBox->setParentItem(_hoverLine); // Draw the lower line segment QGraphicsLineItem* lowerLine = new QGraphicsLineItem(xPos, intersect->y() + 3, xPos, _graphField.y() + _graphField.height() + 5); lowerLine->setPen(_hoverPen); lowerLine->setZValue(OVERLAY_Z); lowerLine->setParentItem(_hoverLine); // Draw the text and background double y = (1.0 - ((intersect->y() - _graphField.y()) / _graphField.height())) * (_graphMaxY - _graphMinY) + _graphMinY; int textOffset = 10; QGraphicsSimpleTextItem* hoverText = new QGraphicsSimpleTextItem(QString::number(y) + tr("m")); hoverText->setBrush(QBrush(_axesColor)); hoverText->setFont(_graphFont); hoverText->setZValue(OVERLAY_Z); if (intersect->x() + textOffset + hoverText->boundingRect().width() < _graphField.x() + _graphField.width()) hoverText->setPos(intersect->x() + textOffset, intersect->y() - hoverText->boundingRect().height()); else hoverText->setPos(intersect->x() - textOffset - hoverText->boundingRect().width(), intersect->y() - hoverText->boundingRect().height()); QGraphicsRectItem* hoverTextBackground = new QGraphicsRectItem(hoverText->x() - 3, hoverText->y() - 1, hoverText->boundingRect().width() + 6, hoverText->boundingRect().height() + 1); hoverTextBackground->setPen(_axesPen); hoverTextBackground->setBrush(QBrush(_graphColor)); hoverTextBackground->setZValue(OVERLAY_Z); hoverTextBackground->setParentItem(_hoverLine); hoverText->setParentItem(_hoverLine); // Update callback if (_positionCallback.valid()) { double distanceFactor = ((xPos - _graphField.x()) / (double)_graphField.width()); osg::Vec3d worldStart, worldEnd; _calculator->getStart(ALTMODE_ABSOLUTE).toWorld(worldStart); _calculator->getEnd(ALTMODE_ABSOLUTE).toWorld(worldEnd); double worldX = (worldEnd.x() - worldStart.x()) * distanceFactor + worldStart.x(); double worldY = (worldEnd.y() - worldStart.y()) * distanceFactor + worldStart.y(); double worldZ = (worldEnd.z() - worldStart.z()) * distanceFactor + worldStart.z(); GeoPoint mapPos; mapPos.fromWorld(_calculator->getStart().getSRS(), osg::Vec3d(worldX, worldY, worldZ)); _positionCallback->updatePosition(mapPos.y(), mapPos.x(), hoverText->text().toStdString()); } } else { // No intersect found so just draw the full line at xPos _hoverLine = new QGraphicsLineItem(xPos, _graphField.y(), xPos, _graphField.y() + _graphField.height() + 5); _hoverLine->setPen(_hoverPen); _hoverLine->setZValue(OVERLAY_Z); _scene->addItem(_hoverLine); } // Draw distance text double x = ((xPos - _graphField.x()) / _graphField.width()) * _totalDistance; BoxedSimpleTextItem* distanceText = new BoxedSimpleTextItem(QString::number(x / 1000.0, 'f', 2) + tr("km"), _backgroundColor); distanceText->setBrush(QBrush(_axesColor)); distanceText->setFont(_graphFont); distanceText->setZValue(OVERLAY_Z); if(xPos - 2 - distanceText->boundingRect().width() > _graphField.x()) { distanceText->setPos(xPos - 2 - distanceText->boundingRect().width(), _graphField.y() + _graphField.height() + 2); } else { distanceText->setPos(xPos + 2, _graphField.y() + _graphField.height() + 2); } distanceText->setParentItem(_hoverLine); // Draw selection box drawSelectionBox(xPos); delete intersect; }