diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2009-03-19 00:44:55 -0400 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2009-03-19 00:44:55 -0400 |
commit | ebac51218a9a95e40779f45b7a2a4a37b49c3807 (patch) | |
tree | af6f7bb4de510e5ca31a07edb5c5cb23c371468d /sigmodr | |
parent | 775579fd2c4508f6eb61290b048fddea5f009432 (diff) | |
download | sigen-ebac51218a9a95e40779f45b7a2a4a37b49c3807.tar.gz sigen-ebac51218a9a95e40779f45b7a2a4a37b49c3807.tar.xz sigen-ebac51218a9a95e40779f45b7a2a4a37b49c3807.zip |
Update EffectItem to work with MapItem
Diffstat (limited to 'sigmodr')
-rw-r--r-- | sigmodr/widgets/CMakeLists.txt | 2 | ||||
-rw-r--r-- | sigmodr/widgets/EffectItem.cpp | 103 | ||||
-rw-r--r-- | sigmodr/widgets/EffectItem.h | 25 |
3 files changed, 62 insertions, 68 deletions
diff --git a/sigmodr/widgets/CMakeLists.txt b/sigmodr/widgets/CMakeLists.txt index a113ace0..a9b6bbbf 100644 --- a/sigmodr/widgets/CMakeLists.txt +++ b/sigmodr/widgets/CMakeLists.txt @@ -10,6 +10,7 @@ set(sigmodrwidgets_HEADERS BadgeUI.h CoinListUI.h CoinListItemUI.h + EffectItem.h EggGroupUI.h GameUI.h Global.h @@ -50,6 +51,7 @@ set(sigmodrwidgets_SRCS BadgeUI.cpp CoinListUI.cpp CoinListItemUI.cpp + EffectItem.cpp EggGroupUI.cpp GameUI.cpp GlobalScriptUI.cpp diff --git a/sigmodr/widgets/EffectItem.cpp b/sigmodr/widgets/EffectItem.cpp index e297ebb0..b8146634 100644 --- a/sigmodr/widgets/EffectItem.cpp +++ b/sigmodr/widgets/EffectItem.cpp @@ -19,98 +19,85 @@ #include "EffectItem.h" // Sigmod includes -#include "../sigmod/MapEffect.h" -#include "../sigmod/Sigmod.h" -#include "../sigmod/Sprite.h" - -// KDE includes -#include <KColorScheme> +#include <sigmod/MapEffect.h> // Qt includes #include <QtGui/QPainter> #include <QtGui/QStyle> #include <QtGui/QStyleOptionGraphicsItem> -Sigmodr::EffectItem::EffectItem(Sigmod::MapEffect* effect, QObject* parent) : - QObject(parent), +using namespace Sigmod; +using namespace Sigmodr::Widgets; + +EffectItem::EffectItem(MapEffect* effect, QGraphicsScene* parent) : + MapItem(true, parent), m_effect(effect) { connect(m_effect, SIGNAL(changed()), this, SLOT(effectChanged())); effectChanged(); setZValue(INT_MAX); - setAcceptHoverEvents(true); + QGraphicsSimpleTextItem* item = new QGraphicsSimpleTextItem(QString::number(m_effect->id()), this); + QSizeF size = item->boundingRect().size() / 2; + item->setPos(-size.width(), -size.height()); + m_label = new QGraphicsSimpleTextItem(m_effect->name(), this); + resetLabel(); } -QRectF Sigmodr::EffectItem::boundingRect() const +QRectF EffectItem::boundingRect() const { - return m_pixmap.rect(); + return m_effect->area(); } -void Sigmodr::EffectItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +void EffectItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { + Q_UNUSED(option) Q_UNUSED(widget) - if (!(flags() & QGraphicsItem::ItemIsSelectable)) - { - QPixmap temp(m_pixmap.size()); - temp.fill(Qt::transparent); - QPainter p; - p.begin(&temp); - p.setCompositionMode(QPainter::CompositionMode_DestinationIn); - p.fillRect(temp.rect(), QColor(0, 0, 0, 127)); - p.end(); - painter->drawPixmap(0, 0, temp); - } - painter->drawPixmap(0, 0, m_pixmap); - if (option->state & QStyle::State_MouseOver) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::View, (flags() & QGraphicsItem::ItemIsSelectable) ? KColorScheme::ActiveText : KColorScheme::InactiveText).brush((flags() & QGraphicsItem::ItemIsSelectable) ? QPalette::Active : QPalette::Inactive), 1)); - painter->drawText(m_pixmap.rect(), Qt::AlignHCenter | Qt::AlignVCenter, m_effect->name()); - } - if (option->state & QStyle::State_HasFocus) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::FocusColor).brush(QPalette::Active), 6)); - painter->drawRect(m_pixmap.rect()); - } - else if (option->state & QStyle::State_Selected) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::ActiveBackground).brush(QPalette::Active), 6)); - painter->drawRect(m_pixmap.rect()); - } - else if ((option->state & QStyle::State_MouseOver) && (flags() & QGraphicsItem::ItemIsSelectable)) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::HoverColor).brush(QPalette::Active), 6)); - painter->drawRect(m_pixmap.rect()); - } + makeTransparent(painter, 127); + painter->setBrush(QBrush(Qt::red)); + painter->setPen(QPen(Qt::black, 2)); + painter->drawRect(m_effect->area()); } -void Sigmodr::EffectItem::changeSprite(const int spriteId) -{ - const Sigmod::Sprite* sprite = m_effect->sigmod()->spriteById(spriteId); - if (sprite) - m_pixmap.loadFromData(sprite->sprite()); - update(); -} - -void Sigmodr::EffectItem::mousePressEvent(QGraphicsSceneMouseEvent* event) +void EffectItem::mousePressEvent(QGraphicsSceneMouseEvent* event) { QGraphicsItem::mousePressEvent(event); update(); } -void Sigmodr::EffectItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) +void EffectItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) { QGraphicsItem::mouseMoveEvent(event); - m_effect->setPosition(scenePos().toPoint()); + QRect area = m_effect->area(); + area.setTopLeft(scenePos().toPoint()); + m_effect->setArea(area); } -void Sigmodr::EffectItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) +void EffectItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) { QGraphicsItem::mouseReleaseEvent(event); update(); } -void Sigmodr::EffectItem::effectChanged() +void EffectItem::resizeBy(const QPointF& size) { - setPos(m_effect->position()); + QRect area = m_effect->area(); + area.setBottomRight(area.bottomRight() + size.toPoint()); + m_effect->setArea(area); + MapItem::resizeBy(size); + resetLabel(); update(); } + +void EffectItem::effectChanged() +{ + setPos(m_effect->area().topLeft()); + m_label->setText(m_effect->name()); + resetLabel(); + update(); +} + +void EffectItem::resetLabel() +{ + QSizeF size = m_label->boundingRect().size() / 2 - m_effect->area().size() / 2; + m_label->setPos(-size.width(), -size.height()); +} diff --git a/sigmodr/widgets/EffectItem.h b/sigmodr/widgets/EffectItem.h index b13ffda1..d8cd986a 100644 --- a/sigmodr/widgets/EffectItem.h +++ b/sigmodr/widgets/EffectItem.h @@ -1,5 +1,5 @@ /* - * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * Copyright 2008-2009 Ben Boeckel <MathStuf@gmail.com> * * 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 @@ -15,11 +15,11 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SIGMODR_EFFECTITEM -#define SIGMODR_EFFECTITEM +#ifndef SIGMODRWIDGETS_EFFECTITEM +#define SIGMODRWIDGETS_EFFECTITEM -// Qt includes -#include <QtGui/QGraphicsItem> +// Sigmodr widget includes +#include "MapItem.h" // Forward declarations namespace Sigmod @@ -29,28 +29,33 @@ class MapEffect; namespace Sigmodr { -class EffectItem : public QObject, public QGraphicsItem +namespace Widgets +{ +class SIGMODRWIDGETS_NO_EXPORT EffectItem : public MapItem { Q_OBJECT public: - EffectItem(Sigmod::MapEffect* effect, QObject* parent); + EffectItem(Sigmod::MapEffect* effect, QGraphicsScene* parent); QRectF boundingRect() const; void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); - public slots: - void changeSprite(const int spriteId); protected: void mousePressEvent(QGraphicsSceneMouseEvent* event); void mouseMoveEvent(QGraphicsSceneMouseEvent* event); void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); + + void resizeBy(const QPointF& size); protected slots: void effectChanged(); private: - QPixmap m_pixmap; + void resetLabel(); + Sigmod::MapEffect* m_effect; + QGraphicsSimpleTextItem* m_label; }; } +} #endif |