X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fintroitem.cpp;h=2034640877f26942e582655c66f2aaade5baa6d1;hb=547fdcb0706bbf3271b627c8064227b5ed47398c;hp=98e0baf98f6dc7ab3458cd3fcdf39264dae7abb0;hpb=ed2d2be7df35e807173b39f467b3c2471fda8397;p=impuzzle diff --git a/src/introitem.cpp b/src/introitem.cpp index 98e0baf..2034640 100644 --- a/src/introitem.cpp +++ b/src/introitem.cpp @@ -1,5 +1,24 @@ +/* + Image Puzzle - A set your pieces straight game + Copyright (C) 2009 Timo Härkönen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + #include "introitem.h" #include "defines.h" +#include "mainwindow.h" #include #include @@ -21,21 +40,72 @@ void IntroItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q_UNUSED(widget) painter->save(); + painter->setRenderHint(QPainter::Antialiasing, true); + painter->setPen(Qt::NoPen); + + //const int dots = 96; + + //int hstep = boundingRect().width() / dots; + //int vstep = boundingRect().height() / dots; + + //QColor colors[3] = {QColor(255, 255, 255), QColor(0, 0, 0), QColor(127, 127, 127)}; + + /*for(int i = 0; i < dots; ++i) { + for(int j = 0; j < dots; ++j) { + painter->setBrush(QBrush(colors[qrand() % 2])); + painter->drawRect(QRect(QPoint(i * hstep, j * vstep), + QPoint((i+1) * hstep, (j+1) * vstep))); + } + }*/ painter->setBrush(Qt::NoBrush); painter->setPen(Qt::black); + QFont font = painter->font(); + font.setPointSize(72); + font.setBold(true); + painter->setFont(font); + // Get font metrics QFontMetricsF fontMetricsF(painter->font()); QRectF textRectF = fontMetricsF.boundingRect(text_); - int horizontalIntend = (IMAGE_WIDTH - textRectF.width()) / 2; - int verticalIntend = (IMAGE_HEIGHT - textRectF.height()) / 2; + int horizontalIntend = (boundingRect().width() - textRectF.width()) / 2 - 10; + int verticalIntend = (boundingRect().height() - textRectF.height()) / 2 - 10; + // Draw rect behind the text + painter->setBrush(QBrush(QColor(0,0,0,192))); + painter->setPen(Qt::NoPen); + painter->drawRect(boundingRect() + .adjusted(0, verticalIntend, 5, -verticalIntend)); + + painter->setPen(Qt::black); + painter->setBrush(Qt::NoBrush); // Draw text aligned to the center of boundingRect + QPen pen = painter->pen(); + pen.setCosmetic(true); + pen.setColor(QColor(255,20,0,192)); + + painter->setPen(pen); painter->drawText(boundingRect() .adjusted(horizontalIntend, verticalIntend,-horizontalIntend, -verticalIntend), text_); + pen.setColor(QColor(Qt::white)); + painter->setPen(pen); + font.setPointSize(12); + painter->setFont(font); + + QString txt = QString("Version %1").arg(IMPUZZLE_VERSION); + + QFontMetricsF fm(painter->font()); + QRectF trect = fm.boundingRect(txt); + + QTextOption textOption; + textOption.setAlignment(Qt::AlignRight); + + painter->drawText(boundingRect().adjusted(0, verticalIntend * 2 - trect.height(), -trect.width(), 0), + txt, textOption); + painter->restore(); } @@ -52,3 +122,10 @@ void IntroItem::setText(const QString &txt) update(); } } + +void IntroItem::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Q_UNUSED(event); + + MainWindow::instance()->newGameClicked(); +}