Example #1
0
	WeiboDialogPrivate() {
		api = new WeiboApi;
		qreal x = 6;
		QGraphicsTextItem *title = new QGraphicsTextItem(titleBar);
		title->setPos(x, 12);
		title->setDefaultTextColor(Qt::white);
		QFont f;
		f.setPixelSize(23);
		f.setBold(true);
		title->setFont(f);
		title->setPlainText(QObject::tr("New weibo (Sina)"));
		qreal w = qApp->desktop()->width()/2 - 44;
		statusEdit = new TextEdit(central);
		statusEdit->setFont(f);
		statusEdit->setDefaultTextColor(Qt::blue);
		statusEdit->document()->setDocumentMargin(22);

		qreal y = 22;
		statusEdit->setPos(x, y);
		statusEdit->document()->setTextWidth(qApp->desktop()->width()/2 - 8);
		//statusEdit->setPlainText("Write something...");
        qreal h = qApp->desktop()->height()*0.618;
		statusEdit->resize(w, h);
		y += statusEdit->size().height() + 12;
		qreal hh = qMin<qreal>(qApp->desktop()->height()*0.314/2, 40); //TODO: calculate the line edit height
		f.setBold(true);
		QGraphicsTextItem *user = new QGraphicsTextItem(central);
        f.setPixelSize(20);
		user->setFont(f);
        user->document()->setDocumentMargin(4);
		user->setDefaultTextColor(QColor(33, 33, 33));
		user->setPlainText(QObject::tr("User"));
		user->setPos(x, y);
		userEdit = new TextEdit(central);
		userEdit->setPos(x + 120, y);
        userEdit->resize(w - 120, hh);
		userEdit->setDefaultTextColor(Qt::black);
        userEdit->document()->setDocumentMargin(11);
		userEdit->document()->setTextWidth(qApp->desktop()->width()/2 - 8);
        y += hh + 2;
		QGraphicsTextItem *passwd = new QGraphicsTextItem(central);
        passwd->setFont(f);
        passwd->document()->setDocumentMargin(4);
		passwd->setDefaultTextColor(QColor(33, 33, 33));
		passwd->setPlainText(QObject::tr("Password"));
		passwd->setPos(x, y);
		passwdEdit = new TextEdit(central);
		passwdEdit->setPos(x + 120, y);
        passwdEdit->resize(w - 120, hh);
		passwdEdit->setDefaultTextColor(Qt::black);
        passwdEdit->document()->setDocumentMargin(11);
		statusEdit->setTextInteractionFlags(Qt::TextEditorInteraction);
		userEdit->setTextInteractionFlags(Qt::TextEditorInteraction);
		passwdEdit->setTextInteractionFlags(Qt::TextEditorInteraction);

        f.setPixelSize(24);
        userEdit->setFont(f);
		passwdEdit->setFont(f);
		passwdEdit->setEchoMode(TextEdit::Password);
	}
/**@brief displays a new screen to indicate that the player has won the game */
void Game::display_end_screen() {
    level->input->releaseKeyboard();
    level->clear();
    delete level;
    level = nullptr;

    //clear the screen from the level
    scene = new QGraphicsScene();
    setScene(scene);

    //next create the end screen text
    QGraphicsTextItem* endText = new QGraphicsTextItem(QString("You defeated all the demons! Congratulations Champion!"));
    //set font and size
    QFont endFont ("Adventure", 25);
    endText->setFont(endFont);
    //position the text
    int endXPos = this->width()/2 - endText->boundingRect().width()/2;
    int endYPos = 150;
    endText->setPos(endXPos, endYPos);
    //add it to the scene
    scene->addItem(endText);


    //create back to main menu button
    Button* returnToMenu = new Button(QString("Return to Menu"));
    //position button
    int returnXPos = this->width()/2 - returnToMenu->boundingRect().width()/2;
    int returnYPos = 425;
    returnToMenu->setPos(returnXPos, returnYPos);
    //connect this button to quit the game
    QObject::connect(returnToMenu, SIGNAL(clicked()), this, SLOT(displayMainMenu()));
    scene->addItem(returnToMenu);
}
Example #3
0
QRectF Visualizer::putWord(QString word, float x, float y, bool isOnTop, int pos, QMap<int, QVector<int> > map) {
    QGraphicsTextItem *wordItem = new QGraphicsTextItem(QString(word));
    if(selWordRef.isActive()) {
        if(selWordRef.isOnTop() == isOnTop) {
            if(selWordRef.getPos() == pos) {
                wordItem->setDefaultTextColor(QColor("red"));
            }
        } else {
            QMapIterator<int, QVector<int> > i(map);
            while(i.hasNext()) {
                i.next();
                qDebug() << i.key() << " --- " << selWordRef.getPos() - 1;
            }
            QVector<int> targets = map[selWordRef.getPos() - 1];
            if(targets.contains(pos)) {
                wordItem->setDefaultTextColor(QColor("orange"));
            }
        }
    }
    wordItem->setFont(font);
    wordItem->setPos(x, y);
    wordItem->setData(IS_ON_TOP_KEY, QVariant(isOnTop));
    wordItem->setData(POS_KEY, QVariant(pos));
    QRectF rect = wordItem->boundingRect();
    scene->addItem(wordItem);
    return rect;
}
BattleAbilitySelection::BattleAbilitySelection(QGraphicsItem *parent)
	: QGraphicsPixmapItem(parent), _currentBattler(0), _abilities(0),	_abilityIndex(0),
	_messageItem(0), _items(0), _activeItems(0), _state(ACTIONSELECTION), _action(BattleAction::ATTACK), _currentItem(0) {

		createWindow();
		QFont font ("Times", 12, QFont::Bold);

		_messageItem = new QGraphicsTextItem(this);
		_messageItem->setTextWidth(boundingRect().width() - 50);
		_messageItem->setDefaultTextColor(Qt::white);
		_messageItem->setFont(font);
		_messageItem->setPos(25, 10);

		int x = 25, y = 40;
		for (int i = 0; i < 4; i++) {
			QGraphicsTextItem *item = new QGraphicsTextItem(this);
			item->hide();
			item->setTextWidth(boundingRect().width() - 25);
			item->setDefaultTextColor(Qt::white);
			item->setFont(font);
			item->setPos(x, y);
			y += 30;

			_items.append(item);
		}
}
Example #5
0
void fillItemFromText(QGraphicsItemGroup *item, const CLBoundingBox *pBB, const CLText *pText, const CLGroup *group, const CLRenderResolver* resolver)
{
  double x = pBB->getPosition().getX() + pText->getX().getAbsoluteValue() + pText->getX().getRelativeValue() / 100.0 * pBB->getDimensions().getWidth();
  double y = pBB->getPosition().getY() + pText->getY().getAbsoluteValue() + pText->getY().getRelativeValue() / 100.0 * pBB->getDimensions().getHeight();

  QGraphicsTextItem* result = new QGraphicsTextItem(pText->getText().c_str());
  result ->setPos(x, y);

  if (pText->isSetStroke())
    {
      result->setDefaultTextColor(getColor(pText->getStroke(), resolver));
    }
  else if (group->isSetStroke())
    {
      result->setDefaultTextColor(getColor(group->getStroke(), resolver));
    }

  QFont *font = getFont(pText, group, resolver, pBB);

  if (font != NULL)
    {
      result->setFont(*font);

      adjustPosition(result, pBB, pText, group);

      delete font;
    }

  transform(result, pText, group);
  item->addToGroup(result);
}
Plansza::Plansza(int liczbaGraczy, QObject *parent)
    : QGraphicsScene(parent), _liczbaGraczy(liczbaGraczy)
{
    _stol = vector<Karta>(liczbaGraczy);
	_deklaracje = vector<int>(liczbaGraczy);
	_wziete = vector<int>(liczbaGraczy);
	_punkty = vector<int>(liczbaGraczy, 0);

    karty = QVector<QVector<KartaSprite*> >(liczbaGraczy);

    _nrLewy = 1;

    // deklaracje Items

    QFont font;
    font.setBold(true);
    font.setPixelSize(25);
    QGraphicsTextItem *item;
    for (int i = 0; i < liczbaGraczy; i++) {
        item = new QGraphicsTextItem;
        item->setPlainText(tr("?"));
        item->setFont(font);
        item->setPos(0, i*50);
        addItem(item);
        deklaracjeItems.push_back(item);
    }

    setBackgroundBrush(Qt::green);
    //setSceneRect(0, 0, 1000, 1000);
}
/**@brief creates a new display to indicate that the player has lost and needs to restart */
void Game::display_game_over() {
    qDebug() << "game over.";

    level->input->releaseKeyboard();
    level->clear();
    delete level;
    level = nullptr;

    //clear the screen from the level
    scene = new QGraphicsScene();
    setScene(scene);

    //next create the Game Over text
    QGraphicsTextItem* gameOverText = new QGraphicsTextItem(QString("You Perished. Game Over."));
    //set font and size
    QFont game_over_font ("28 Days Later", 25);
    gameOverText->setFont(game_over_font);
    //position the text
    int gameOverXPos = this->width()/2 - gameOverText->boundingRect().width()/2;
    int gameOverYPos = 150;
    gameOverText->setPos(gameOverXPos, gameOverYPos);
    //add it to the scene
    scene->addItem(gameOverText);


    //create back to main menu button
    Button* returnToMenu = new Button(QString("Return to Menu"));
    //position button
    int returnXPos = this->width()/2 - returnToMenu->boundingRect().width()/2;
    int returnYPos = 425;
    returnToMenu->setPos(returnXPos, returnYPos);
    //connect this button to quit the game
    QObject::connect(returnToMenu, SIGNAL(clicked()), this, SLOT(displayMainMenu()));
    scene->addItem(returnToMenu);
}
Example #8
0
SEXP
scene_addText(SEXP scene, SEXP x, SEXP y, SEXP labels, SEXP html)
{
    QGraphicsScene* s = unwrapQObject(scene, QGraphicsScene);
    int nlab = length(labels);
    int i, n = length(x);
    for (i = 0; i < n; i++) {
	QGraphicsTextItem *ti = s->addText(QString());
	ti->setFont(QFont("Arial"));
	if (LOGICAL(html)[0]) {
	    ti->setHtml(QString::fromLocal8Bit(CHAR(asChar(STRING_ELT(labels, i % nlab)))));
	    ti->setOpenExternalLinks(true);
	    ti->setToolTip("I am HTML!");
	}
	else {
	    ti->setPlainText(QString::fromLocal8Bit(CHAR(asChar(STRING_ELT(labels, i % nlab)))));
	}
	ti->setPos(REAL(x)[i], REAL(y)[i]);
	ti->setFlags(QGraphicsItem::ItemIsMovable | 
		     QGraphicsItem::ItemIsSelectable | 
		     QGraphicsItem::ItemIsFocusable | 
		     QGraphicsItem::ItemIgnoresTransformations);
    }
    return R_NilValue;
}
/**@brief shows a set of instructions for the user to understand gameplay */
void Game::display_instructions() {
    //start by clearing the scene from the Main Menu
    scene->clear();

    //next we create the instructions portion
    QGraphicsTextItem* instructionsText =
            new QGraphicsTextItem (QString("You are about to embark on an epic quest champion! In order to protect the\n"
                                           "Emerald Dream, you must cleanse the land of demons. Use WASD or the arrow\n"
                                           "keys to move around and Spacebar to fire your wrath attack. At any time you\n"
                                           "can hit escape if the battle becomes too intense. Beware of the demons, if they\n"
                                           "cross the threshold this will lower your health. If your health reaches 0, you\n"
                                           "lose the game. If you kill 10 of the demons, you win! You have all you need\n"
                                           "now fulfill your druidic duties! May Elune be with you!"));
    //set the font and size
    QFont instructFont ("Lithos Pro", 17);
    instructionsText->setFont(instructFont);
    //position the text
    int instructXPos = this->width()/2 - instructionsText->boundingRect().width()/2;
    int instructYPos = 150;
    instructionsText->setPos(instructXPos, instructYPos);
    //add it to the scene
    scene->addItem(instructionsText);

    //create the Back to Main Menu Button
    Button* returnToMenu = new Button(QString("Return to Menu"));
    //position button
    int returnXPos = this->width()/2 - returnToMenu->boundingRect().width()/2;
    int returnYPos = 425;
    returnToMenu->setPos(returnXPos, returnYPos);
    //connect this button to quit the game
    QObject::connect(returnToMenu, SIGNAL(clicked()), this, SLOT(displayMainMenu()));
    scene->addItem(returnToMenu);

}
Example #10
0
ParticipantInfoDialog::ParticipantInfoDialog(Participant* participant, QWidget* parent, bool showRemove)
        : PopupDialog( parent ), m_participant(participant)
{
    setMinimumWidth(400);
    setMinimumHeight(160);
    this->setSizeGripEnabled(false);

    QGraphicsPixmapItem* image = new QGraphicsPixmapItem( participant->pixmap().scaled(80, 80, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), widget() );
    image->setPos( 8, 8 );
    QGraphicsLineItem* line = new QGraphicsLineItem( widget() );
    line->setPen( QPen( QColor( 100, 100, 100 ) ) );
    line->setLine( 8, 110, width() - 2 * 8, 110 );
    int buttonRight = width() - 10;
    QPushButton* button = new QPushButton();
    button->setText(tr("New Wave"));
    QGraphicsProxyWidget* item = scene()->addWidget(button);
    item->setParentItem( widget() );
    item->setPos( buttonRight - item->preferredWidth(), height() - 10 - item->preferredHeight() );
    buttonRight -= item->preferredWidth() + 10;

    //Adds remove button if parent is a waveview
    if (showRemove)
    {
        QPushButton* removeFromWaveButton = new QPushButton();
        removeFromWaveButton->setText(tr("Remove"));
        QGraphicsProxyWidget* removeItem = scene()->addWidget(removeFromWaveButton);
        removeItem->setParentItem( widget() );
        removeItem->setPos( buttonRight - removeItem->preferredWidth(), height() - 10 - removeItem->preferredHeight() );
        buttonRight -= removeItem->preferredWidth() + 10;
        connect( removeFromWaveButton, SIGNAL(clicked()),SLOT(removeParticipant()));
    }

    QPushButton* button2 = new QPushButton();
    button2->setText(tr("Close"));
    QGraphicsProxyWidget* item2 = scene()->addWidget(button2);
    item2->setParentItem( widget() );
    item2->setPos( buttonRight - item2->preferredWidth(), height() - 10 - item2->preferredHeight() );
    QGraphicsTextItem* text = new QGraphicsTextItem( participant->name(), widget() );
    text->setPos( 110, 10 );
    text->setFont( QFont( "Arial", 18, QFont::Bold ) );
    text = new QGraphicsTextItem( tr("Address") + ": " + participant->address(), widget() );
    text->setPos( 110, 50 );
    text->setFont( QFont( "Arial", 11 ) );

    connect( button, SIGNAL(clicked()), SLOT(newWave()));
    connect( button2, SIGNAL(clicked()), SLOT(close()));
}
Example #11
0
  void Scene2D::setFont(const QFont &font) {
    myFont = font;

    QGraphicsTextItem *item =
        qgraphicsitem_cast<InputTextItem *>(selectedItems().first());
    //At this point the selection can change so the first selected item might not be a DiagramTextItem
    if (item)
      item->setFont(myFont);
  }
void MainWindow::slotAddTextItem()      //在场景中加入一个文字图元
{
    QFont font("Times",16);
    QGraphicsTextItem *item = new QGraphicsTextItem("Hello Qt");
    item->setFont(font);
    item->setFlag(QGraphicsItem::ItemIsMovable);
    item->setDefaultTextColor(QColor(qrand()%256,qrand()%256,qrand()%256));
    scene->addItem(item);
    item->setPos((qrand()%int(scene->sceneRect().width()))-200,(qrand()%int(scene->sceneRect().height()))-200);
}
Example #13
0
void PetriScene::setFont(const QFont &font)
{
    myFont = font;
    if(isItemOfType(PetriTextItem::Type))
    {
        QGraphicsTextItem *item = qgraphicsitem_cast<QGraphicsTextItem*>(selectedItems().first());
        if(item)
            item->setFont(myFont);
    }
}
Example #14
0
void Game::displayText( QString text, int x, int y, int fontSize, QColor color )
{
    QGraphicsTextItem *gameName = new QGraphicsTextItem(text);
    QFont font;
    font.setPointSize(fontSize);
    gameName->setDefaultTextColor(color);
    gameName->setPos(x,y);
    gameName->setFont(font);
    mGraphicsScenePtr->addItem(gameName);
}
Example #15
0
//! [4]
void DiagramScene::setFont(const QFont &font)
{
    myFont = font;

    if (isItemChange(DiagramTextItem::Type)) {
        QGraphicsTextItem *item = qgraphicsitem_cast<DiagramTextItem *>(selectedItems().first());
        //At this point the selection can change so the first selected item might not be a DiagramTextItem
        if (item)
            item->setFont(myFont);
    }
}
Example #16
0
void DiagramScene::setFont(const QFont &font)
{
    myFont = font;

    if (isItemChange(DiagramTextItem::Type)) {
        QGraphicsTextItem *item =
            qgraphicsitem_cast<DiagramTextItem *>(selectedItems().first());
        if (item)
            item->setFont(myFont);
    }
}
Example #17
0
void TextTools::setFont()
{
    QGraphicsTextItem * item = _cover->selectedTextItem();
    if (item == 0)
    {
        QMessageBox::warning(this,"Kein Text markiert","Es wurde kein Text ausgewählt.");
        return;
    }
    bool * ok;
    QFont font = item->font();
    item->setFont(QFontDialog::getFont(ok,font));
}
Example #18
0
void BbScene::testAddText()
{
	QGraphicsTextItem* item = new QGraphicsTextItem;

	QFont font = QFont("Microsoft YaHei");
	font.setPointSize(20);
	item->setFont(font);
	item->setPlainText("I am a clever mouse");
	item->setPos(0, 0);

	addItem(item);
}
Example #19
0
QGraphicsTextItem* TlinearChart::getTextItem(int fontSize) {
	QGraphicsTextItem *item = new QGraphicsTextItem();
	QFont f;
	f.setPixelSize(fontSize);
	item->setFont(f);
	QColor C(palette().text().color());
	C.setAlpha(75);
	Tcolor::merge(C, palette().base().color());
	item->setDefaultTextColor(C);
	scene->addItem(item);
	item->setZValue(15);
	return item;
}
Example #20
0
/**@brief sets up the Main Menu before gameplay begins */
void Game::displayMainMenu() {
    //clear scene in case someone comes from the instructions
    scene->clear();

    //need to remove current background to allow level to set background
    this->setBackgroundBrush(Qt::NoBrush);
    //load in background photo
    this->setBackgroundBrush(QBrush(QImage(":/images/emeraldDream.jpg").scaled(1024,768)));

    //start by creating Title Text
    QGraphicsTextItem* titleText = new QGraphicsTextItem(QString("Protect the Emerald Dream"));
    QFont titleFont ("Adventure", 50); //sets title font and size
    titleText->setFont(titleFont);
    //now we position the text
    int titleXPos = this->width()/2 - titleText->boundingRect().width()/2;
    int titleYPos = 150;
    titleText->setPos(titleXPos, titleYPos);
    //now we add it to the scene
    scene->addItem(titleText);

    //next we create the Play Button
    Button* playButton = new Button(QString("Play"));
    //now we position the button
    int buttonXPos = this->width()/2 - playButton->boundingRect().width()/2;
    int buttonYPos = 275;
    playButton->setPos(buttonXPos, buttonYPos);
    //connect this button to start the game
    QObject::connect(playButton, SIGNAL(clicked()), this, SLOT(start()));
    //now we add it to the scene
    scene->addItem(playButton);

    //create the Instructions Button
    Button* instructionsButton = new Button(QString("Instructions"));
    //position button
    int instructXPos = this->width()/2 - instructionsButton->boundingRect().width()/2;
    int instructYPos = 350;
    instructionsButton->setPos(instructXPos, instructYPos);
    //connect this button to show instructions
    QObject::connect(instructionsButton, SIGNAL(clicked()), this, SLOT(display_instructions()));
    scene->addItem(instructionsButton);

    //create the Quit Button
    Button* quitButton = new Button(QString("Quit"));
    //position button
    int quitXPos = this->width()/2 - quitButton->boundingRect().width()/2;
    int quitYPos = 425;
    quitButton->setPos(quitXPos, quitYPos);
    //connect this button to quit the game
    QObject::connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
    scene->addItem(quitButton);
}
Example #21
0
void MainMenu::displayMainMenu()
{
    QGraphicsTextItem * titleText = new QGraphicsTextItem(tr("Starlight"));
    QFont titleFont("calibri", 50);
    titleText->setFont(titleFont);

    int titleX = this->width() / 2 - titleText->boundingRect().width() /2;
    int titleY = 50;
    titleText->setPos(titleX, titleY);
    scene_->addItem(titleText);

    Button * playButton = new Button(tr("Play"));

    int playX = this->width() / 2 - playButton->boundingRect().width() /2;
    int playY = 150;
    playButton->setPos(playX, playY);
    connect(playButton, &Button::clicked, this, &MainMenu::start);

    scene_->addItem(playButton);


    Button * rulesButton = new Button(tr("Rules"));

    int ruleX = this->width() / 2 - rulesButton->boundingRect().width() / 2;
    int ruleY = 225;
    rulesButton->setPos(ruleX, ruleY);
    connect(rulesButton, &Button::clicked, this, &MainMenu::help);

    scene_->addItem(rulesButton);


    Button * editorButton = new Button(tr("Editor"));

    int editX = this->width() / 2 - editorButton->boundingRect().width() /2;
    int editY = 300;
    editorButton->setPos(editX, editY);
    connect(editorButton, &Button::clicked, this, &MainMenu::editor);

    scene_->addItem(editorButton);


    Button * quitButton = new Button(tr("Exit"));

    int quitX = this->width() / 2 - quitButton->boundingRect().width() /2;
    int quitY = 375;
    quitButton->setPos(quitX, quitY);
    connect(quitButton, &Button::clicked, this, &QGraphicsView::close);

    scene_->addItem(quitButton);
}
Example #22
0
void
RCanvas::text(double x, double y, QString s, double rot, double , QPen p, QFont f)
{
    // add height too
    QFontMetrics fm(f);

    QGraphicsTextItem *t = new QGraphicsTextItem(s);
    t->setFont(f);
    t->setPos(x,-y-fm.height());
    t->setRotation(rot);
    t->setDefaultTextColor(p.color());

    scene->addItem(t);

}
Example #23
0
GanttMachine::GanttMachine(const QString &id, QGraphicsItem *parent) :
    QGraphicsItem(parent),
    m_id(id),
    m_cMax(0)
{   
    QGraphicsTextItem* text = new QGraphicsTextItem(m_id, this);
    text->setPos(0, GanttChart::machineHeight/2);
    text->setFont(QFont("Arial", 12, QFont::Normal, false));


    QGraphicsLineItem* line = new QGraphicsLineItem(GanttChart::machineHorizontalOffset, 0, GanttChart::machineHorizontalOffset, GanttChart::machineHeight, this);
    QPen pen(Qt::black, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
    line->setPen(pen);

    m_arrow = new Arrow(this);
    m_arrow->setPen(pen);
}
    void addBoxedItem(QGraphicsItem* item, QString title) {
        QGraphicsRectItem* box = createBox();
        item->setParentItem(box);

        QString htmlTitle = QString("<center>%1</center>").arg(title);
        QGraphicsTextItem *textItem = new QGraphicsTextItem();
        textItem->setDefaultTextColor(Qt::blue);
        QFont font;
        font.setPixelSize(10);
        textItem->setFont(font);

        textItem->setHtml(htmlTitle);

        textItem->setTextWidth(WIDTH);
        textItem->setParentItem(box);
        textItem->moveBy(0, 110);
        nextPosition();
    }
Example #25
0
void GameScene::displayPoints(long p_wonPoints, qreal p_xPos, qreal p_yPos)
{
    // Launch a singleShot timer
    QTimer::singleShot(1000, this, SLOT(hidePoints()));

    // Add a label in the list of won points Labels
    m_wonPointsLabels.prepend(new QGraphicsTextItem(QString::number(p_wonPoints)));
    addItem(m_wonPointsLabels.first());

    // Temporary reference to the first item in the list
    QGraphicsTextItem *tempRef = m_wonPointsLabels.first();

    // Positioning and customization of the point label
    tempRef->setDefaultTextColor(QColor(QLatin1Literal("#FFFF00")));
    tempRef->setFont(QFont(QLatin1Literal("Helvetica"), 15, QFont::Normal, false));
    tempRef->setPos(p_xPos - (tempRef->boundingRect().width() / 2), p_yPos - (tempRef->boundingRect().height() / 2));
    tempRef->setZValue(-1);
}
void GamePlay::displayGameOver(int highScore)
{
    for (size_t i = 0, n=scene->items().size();i<n;i++)
        scene->items()[i]->setEnabled(false);
    timer->stop();
    QGraphicsRectItem *panel = new QGraphicsRectItem(160,120,300,320);
    QBrush brush;
    brush.setStyle(Qt::SolidPattern);
    brush.setColor(Qt::yellow);
    panel->setBrush(brush);
    panel->setOpacity(0.65);
    scene->addItem(panel);
    QGraphicsTextItem *gameOverText = new QGraphicsTextItem(QString("GAME OVER!\nYour score:")+QString::number(highScore));
    gameOverText->setDefaultTextColor(Qt::magenta);
    gameOverText->setFont(QFont("Pixelette",20));
    gameOverText->setPos(185,160);
    scene->addItem(gameOverText);
}
Example #27
0
void Game::gameOver()
{
    QGraphicsTextItem *gameOverLabel = new QGraphicsTextItem;
    if (isWin)
    {
        gameOverLabel->setPlainText(QString("You Win"));
    }
    else
    {
        gameOverLabel->setPlainText(QString("Game Over"));
    }
    gameOverLabel->setDefaultTextColor(Qt::black);
    gameOverLabel->setFont(QFont("times", 24));
    gameOverLabel->setPos(-100, -250);

    scene->addItem(gameOverLabel);
    timer->stop();
}
void LegendItem::addId(int i) {
    QGraphicsTextItem* id = new QGraphicsTextItem(this);
    id->setHtml(QString("[%1]").arg(i));
    id->setFont(getFont());

    int idXPos = 0;
    int idYPos = _currHeight + _space;

    if (id->boundingRect().width() > rect().width()) {
      idXPos = (int)(0 - id->boundingRect().width() / 2);
    } else {
      idXPos = (int)((rect().width() - id->boundingRect().width()) / 2);
    }

    id->setPos(idXPos, idYPos);

    _currHeight += _space + (int)(id->boundingRect().height());
}
void BattleCharacterStatus::valueChanged(QString name) {
	BattleCharacterItem *character = 0;
	QGraphicsTextItem *infoItem = 0;
	for (int i = 0; i < _characters.size(); i++) {
		BattleCharacterItem *it = _characters.at(i);
		if (!!it && (it->getName() == name)) {
			character = it;
			infoItem = _info.at(i);
			break;
		}
	}

	if (!!character) {
		QString infoString;
		infoString += character->getCharacter()->getName() + QString(":\n");
		infoString += QString("Health: ") + QString::number(character->getHealth().second) + QString(" / ") + QString::number(character->getMaxHealth().second) + QString("\t");
		infoString += QString("Energy: ") + QString::number(character->getEnergy().second) + QString(" / ") + QString::number(character->getMaxEnergy().second);


		double percentage = (double)character->getHealth().second / (double)character->getMaxHealth().second * 100;

		if (percentage > 60)
			infoItem->setDefaultTextColor(Qt::green);
		else if ((percentage <= 60) && (percentage > 25))
			infoItem->setDefaultTextColor(Qt::yellow);
		else if ((percentage <= 25) && (percentage > 0))
			infoItem->setDefaultTextColor(Qt::red);
		else
			infoItem->setDefaultTextColor(Qt::gray);

		infoItem->setPlainText(infoString);
		QFont font("Times", 12, QFont::Bold);
		infoItem->setFont(font);

		QTextBlockFormat format;
		format.setAlignment(Qt::AlignLeft);
		QTextCursor cursor = infoItem->textCursor();
		cursor.select(QTextCursor::Document);
		cursor.mergeBlockFormat(format);
		cursor.clearSelection();
		infoItem->setTextCursor(cursor);
	}
}
Example #30
0
double 
RSceneDevice::StrWidthUTF8(char *str,
			   R_GE_gcontext *gc)
{
    if (debug) Rprintf("RSceneDevice::StrWidthUTF8\n");
    double cex = gc->cex;
    double ps = gc->ps;
    double lineheight = gc->lineheight;
    int fontface = gc->fontface;
    char* fontfamily = gc->fontfamily;
    QString qstr = QString::fromUtf8(str);
    QGraphicsTextItem *text = new QGraphicsTextItem(str, 0);
    text->setFont(r2qFont(fontfamily, fontface, 
			  ps, cex, lineheight,
			  defaultFamily()));
    QRectF brect = text->boundingRect();
    delete text;
    return brect.width();
}