diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2009-03-19 01:00:28 -0400 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2009-03-19 01:00:39 -0400 |
commit | 980c0f9c267fd981d228b2872639b269e9f7d86d (patch) | |
tree | bed2cd0068527f95a5e3fada57244f56c557217f /sigmodr | |
parent | 8428d02f797f51bee3ccd61a765b6cd560dea4a6 (diff) | |
download | sigen-980c0f9c267fd981d228b2872639b269e9f7d86d.tar.gz sigen-980c0f9c267fd981d228b2872639b269e9f7d86d.tar.xz sigen-980c0f9c267fd981d228b2872639b269e9f7d86d.zip |
Update the WarpItem
Diffstat (limited to 'sigmodr')
-rw-r--r-- | sigmodr/widgets/CMakeLists.txt | 2 | ||||
-rw-r--r-- | sigmodr/widgets/WarpItem.cpp | 106 | ||||
-rw-r--r-- | sigmodr/widgets/WarpItem.h | 22 |
3 files changed, 59 insertions, 71 deletions
diff --git a/sigmodr/widgets/CMakeLists.txt b/sigmodr/widgets/CMakeLists.txt index 4789f189..48a709d0 100644 --- a/sigmodr/widgets/CMakeLists.txt +++ b/sigmodr/widgets/CMakeLists.txt @@ -44,6 +44,7 @@ set(sigmodrwidgets_HEADERS TypechartModel.h TypeUI.h ValidationDialog.h + WarpItem.h WeatherUI.h ) set(sigmodrwidgets_SRCS @@ -85,6 +86,7 @@ set(sigmodrwidgets_SRCS TypechartModel.cpp TypeUI.cpp ValidationDialog.cpp + WarpItem.cpp WeatherUI.cpp ) diff --git a/sigmodr/widgets/WarpItem.cpp b/sigmodr/widgets/WarpItem.cpp index bf1f2385..013be6a7 100644 --- a/sigmodr/widgets/WarpItem.cpp +++ b/sigmodr/widgets/WarpItem.cpp @@ -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 @@ -19,105 +19,83 @@ #include "WarpItem.h" // Sigmod includes -#include "../sigmod/MapWarp.h" -#include "../sigmod/Sigmod.h" - -// KDE includes -#include <KColorScheme> +#include <sigmod/MapWarp.h> // Qt includes -#include <QtGui/QGraphicsSceneMouseEvent> #include <QtGui/QPainter> #include <QtGui/QStyle> #include <QtGui/QStyleOptionGraphicsItem> -Sigmodr::WarpItem::WarpItem(Sigmod::MapWarp* warp, QObject* parent) : - QObject(parent), +using namespace Sigmod; +using namespace Sigmodr::Widgets; + +WarpItem::WarpItem(MapWarp* warp, QGraphicsScene* parent) : + MapItem(true, parent), m_warp(warp) { connect(m_warp, SIGNAL(changed()), this, SLOT(warpChanged())); warpChanged(); setZValue(INT_MAX); - setAcceptHoverEvents(true); + QGraphicsSimpleTextItem* item = new QGraphicsSimpleTextItem(QString::number(m_warp->id()), this); + QSizeF size = item->boundingRect().size() / 2; + item->setPos(-size.width(), -size.height()); + m_label = new QGraphicsSimpleTextItem(this); + resetLabel(); } -QRectF Sigmodr::WarpItem::boundingRect() const +QRectF WarpItem::boundingRect() const { return m_warp->area(); } -void Sigmodr::WarpItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +void WarpItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { + Q_UNUSED(option) Q_UNUSED(widget) - if (m_warp->area().size().isValid()) - return; - if (!(flags() & QGraphicsItem::ItemIsSelectable)) - { - QPixmap temp(m_warp->area().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->setBrush(KStatefulBrush(KColorScheme::View, KColorScheme::ActiveBackground).brush(QPalette::Active)); + makeTransparent(painter, 127); + painter->setBrush(QBrush(Qt::green)); + painter->setPen(QPen(Qt::black, 2)); painter->drawRect(m_warp->area()); - 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_warp->area(), Qt::AlignHCenter | Qt::AlignVCenter, m_warp->name()); - } - if (option->state & QStyle::State_HasFocus) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::FocusColor).brush(QPalette::Active), 6)); - painter->drawRect(m_warp->area()); - } - else if (option->state & QStyle::State_Selected) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::ActiveBackground).brush(QPalette::Active), 6)); - painter->drawRect(m_warp->area()); - } - 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_warp->area()); - } } -void Sigmodr::WarpItem::mousePressEvent(QGraphicsSceneMouseEvent* event) +void WarpItem::mousePressEvent(QGraphicsSceneMouseEvent* event) { QGraphicsItem::mousePressEvent(event); update(); } -void Sigmodr::WarpItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) +void WarpItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) { - if (event->modifiers() & Qt::ShiftModifier) - { - QRect rect = m_warp->area(); - QPointF diff = event->scenePos() - event->lastScenePos(); - rect.setSize(rect.size() + QSize(diff.x(), diff.y())); - m_warp->setArea(rect); - } - else - { - QGraphicsItem::mouseMoveEvent(event); - QRect rect = m_warp->area(); - rect.setTopLeft(scenePos().toPoint()); - m_warp->setArea(rect); - } + QGraphicsItem::mouseMoveEvent(event); + QRect area = m_warp->area(); + area.setTopLeft(scenePos().toPoint()); + m_warp->setArea(area); } -void Sigmodr::WarpItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) +void WarpItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) { QGraphicsItem::mouseReleaseEvent(event); update(); } -void Sigmodr::WarpItem::warpChanged() +void WarpItem::resizeBy(const QPointF& size) +{ + QRect area = m_warp->area(); + area.setBottomRight(area.bottomRight() + size.toPoint()); + m_warp->setArea(area); + MapItem::resizeBy(size); +} + +void WarpItem::warpChanged() { setPos(m_warp->area().topLeft()); + resetLabel(); update(); } + +void WarpItem::resetLabel() +{ + m_label->setText(m_warp->name()); + QSizeF size = m_label->boundingRect().size() / 2 - m_warp->area().size() / 2; + m_label->setPos(-size.width(), -size.height()); +} diff --git a/sigmodr/widgets/WarpItem.h b/sigmodr/widgets/WarpItem.h index c9bf9eb2..0b04acd0 100644 --- a/sigmodr/widgets/WarpItem.h +++ b/sigmodr/widgets/WarpItem.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_WARPITEM -#define SIGMODR_WARPITEM +#ifndef SIGMODRWIDGETS_WARPITEM +#define SIGMODRWIDGETS_WARPITEM -// Qt includes -#include <QtGui/QGraphicsItem> +// Sigmodr widget includes +#include "MapItem.h" // Forward declarations namespace Sigmod @@ -29,12 +29,14 @@ class MapWarp; namespace Sigmodr { -class WarpItem : public QObject, public QGraphicsItem +namespace Widgets +{ +class SIGMODRWIDGETS_NO_EXPORT WarpItem : public MapItem { Q_OBJECT public: - WarpItem(Sigmod::MapWarp* warp, QObject* parent); + WarpItem(Sigmod::MapWarp* warp, QGraphicsScene* parent); QRectF boundingRect() const; @@ -43,11 +45,17 @@ class WarpItem : public QObject, public QGraphicsItem void mousePressEvent(QGraphicsSceneMouseEvent* event); void mouseMoveEvent(QGraphicsSceneMouseEvent* event); void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); + + void resizeBy(const QPointF& size); protected slots: void warpChanged(); private: + void resetLabel(); + Sigmod::MapWarp* m_warp; + QGraphicsSimpleTextItem* m_label; }; } +} #endif |