rendered paste body//
// C++ Implementation: ucd_desktop
//
// Description:
//
//
// Author: <Johannes Neugschwentner>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
#include "ucd_desktop.h"
#include "plasma/corona.h"
#include <QPainter>
#include <QFontMetrics>
#include <QGraphicsSceneMouseEvent>
#include <QMouseEvent>
#include <QEvent>
#include <QTimeLine>
#include <QApplication>
//Constructor
UCD_Desktop::UCD_Desktop(QObject *parent,const QStringList &args)
: Plasma::Applet(parent, args)
{
kDebug() << "entering constructor..." << endl;
kDebug() << "setting: state, type, name, width, height, setAcceptsHoverEvents=true, ghost=Null, isGhost = false" << endl;
ucd_state = "normal";
ucd_type = "controller";
ucd_name = "UCD Applet";
width = 80;
height = 100;
setAcceptsHoverEvents(true);
ghost = NULL;
isGhost = false;
}
//Destructor
UCD_Desktop::~UCD_Desktop()
{
kDebug() << "entering destructor..." << endl;
kDebug() << "destructing type: " << ucd_type << endl;
if(ucd_type == "item")
delete m_Icon;
/*
QList<UCD_Desktop*>::iterator i;
for (i = items.begin(); i != items.end(); ++i) {
(*i)->~UCD_Desktop();
}
for (i = piles.begin(); i != piles.end(); ++i) {
(*i)->~UCD_Desktop();
}
*/
kDebug() << "checking ucd_parent ... " << endl;
if(ucd_parent->ucd_type == "controller" || ucd_parent->ucd_type == "pile") {
for (int i = 0; i < ucd_parent->items.size(); ++i) {
if(ucd_parent->items.at(i) == this) {
ucd_parent->items.removeAt(i);
}
}
for (int i = 0; i < ucd_parent->piles.size(); ++i) {
if(ucd_parent->piles.at(i) == this) {
ucd_parent->piles.removeAt(i);
}
}
}
}
QRectF UCD_Desktop::boundingRect() const
{
// In this tutorial we use a fixed size
return QRectF(0,0,width,height);
}
void UCD_Desktop::paintInterface(QPainter *p,const QStyleOptionGraphicsItem *option, const QRect&)
{
kDebug() << "paintInterface..." << endl;
kDebug() << "ucd_type: " << ucd_type << endl;
if(ucd_type == "controller") {
m_Theme = new Plasma::Svg("widgets/item",this);
m_Theme->setParent(this);
m_Theme->setContentType(Plasma::Svg::ImageSet);
m_Theme->resize(boundingRect().width(),boundingRect().height());
m_Theme->paint(p,boundingRect().left(),boundingRect().top(),ucd_state);
// The we place the icon and text
p->save();
p->setPen(Qt::white);
p->drawText(boundingRect(),Qt::AlignBottom+Qt::AlignHCenter,ucd_name);
p->restore();
}
if(ucd_type == "pile") {
m_Theme = new Plasma::Svg("widgets/pile",this);
m_Theme->setParent(this);
m_Theme->setContentType(Plasma::Svg::ImageSet);
m_Theme->resize(boundingRect().width(),boundingRect().height());
m_Theme->paint(p,boundingRect().left(),boundingRect().top(),ucd_state);
// The we place the icon and text
//p->drawPixmap(20, 0, m_Icon.pixmap(boundingRect().width() - 40));
p->save();
p->setPen(Qt::black);
p->drawText(boundingRect(),Qt::AlignBottom+Qt::AlignHCenter,ucd_name);
p->restore();
}
if(ucd_type == "item") {
m_Theme = new Plasma::Svg("widgets/item",this);
m_Theme->setParent(this);
m_Icon = new KIcon("document");
m_Theme->setContentType(Plasma::Svg::ImageSet);
m_Theme->resize(boundingRect().width(),boundingRect().height());
m_Theme->paint(p,boundingRect().left(),boundingRect().top(),ucd_state);
// The we place the icon and text
p->drawPixmap(20, 0, m_Icon->pixmap(boundingRect().width() - 40));
p->save();
p->setPen(Qt::white);
p->drawText(boundingRect(),Qt::AlignBottom+Qt::AlignHCenter,ucd_name);
p->restore();
}
}
void UCD_Desktop::configure(QString type)
{
if(type == "item") {
ucd_type = "item";
ucd_name = "filename.ext";
width = 80;
height = 100;
//ucd_state = "normal";
setAcceptDrops(true);
}
if(type == "pile") {
ucd_type = "pile";
ucd_name = "pilename.ext";
width = 100;
height = 140;
//ucd_state = "normal";
//m_Icon->~KIcon();
//delete m_Icon;
setAcceptDrops(true);
}
update();
}
/*****************************************************************
****************************NEW FUNCTIONS*************************
*****************************************************************/
UCD_Desktop * UCD_Desktop::newPile(UCD_Desktop * item) {
kDebug() << "newPile - creating new pile adding first element, given as argument" << endl;
this->applet_dirty = static_cast<Plasma::Corona*>(scene())->addApplet("plasma_applet_ucd_desktop");
this->item_dirty = static_cast<UCD_Desktop*>(applet_dirty);
this->item_dirty->ucd_parent = this;
this->item_dirty->configure("pile");
this->piles.append(item_dirty);
this->item_dirty->setPos(item->pos());
this->item_dirty->ucd_pile_opened = false;
(piles.last())->addItem(item);
return this->piles.last();
}
UCD_Desktop * UCD_Desktop::newItem() {
kDebug() << "newItem - creating new Item" << endl;
this->applet_dirty = static_cast<Plasma::Corona*>(scene())->addApplet("plasma_applet_ucd_desktop");
this->item_dirty = static_cast<UCD_Desktop*>(applet_dirty);
this->item_dirty->ucd_parent = this;
this->item_dirty->configure("item");
this->items.append(item_dirty);
//this->item_dirty->setZValue((this->highestZValue()+1));
return this->items.last();
}
/*****************************************************************
**************************PILE FUNCTIONS**************************
*****************************************************************/
void UCD_Desktop::addItem(UCD_Desktop * item) {
kDebug() << "addItem - adding Item to pile __" << this->ucd_name << "__" << endl;
if(this->ucd_pile_opened)
return; //if pile is opened do not accept new Items
this->items.append(item);
item->ucd_parent->removeItemFromList(item);
item->ucd_parent = this;
item->setParentItem(this);
//item->mapToParent(this->pos());
item->setPos((this->width - item->width)/2,(this->height - item->height)/4);
item->setZValue(this->highestZValue()+1);
}
void UCD_Desktop::exchangeWith(UCD_Desktop * element) {
if(this->ucd_type == "item") {
QGraphicsItem * t_parent = this->parentItem();
UCD_Desktop * t_ucd_parent = this->ucd_parent;
UCD_Desktop * t_ghost = this->ghost;
QGraphicsItemAnimation * t_ani = this->ani;
QString t_ucd_state = this->ucd_state;
QString t_ucd_name = this->ucd_name;
QString t_ucd_type = this->ucd_type;
bool t_ucd_pile_opened = this->ucd_pile_opened;
bool t_isGhost = this->isGhost;
Plasma::Svg* t_m_Theme = this->m_Theme;
KIcon* t_m_Icon = this->m_Icon;
QPointF t_pos = this->pos();
qreal t_zval = this->zValue();
this->ucd_parent = element->ucd_parent;
this->ghost = element->ghost;
this->ani = element->ani;
this->ucd_state = element->ucd_state;
this->ucd_name = element->ucd_name;
this->ucd_type = element->ucd_type;
this->ucd_pile_opened = element->ucd_pile_opened;
this->isGhost = element->isGhost;
this->m_Theme = element->m_Theme;
this->m_Icon = element->m_Icon;
this->setZValue(element->zValue());
element->ucd_parent = t_ucd_parent;
element->ghost = t_ghost;
element->ani = t_ani;
element->ucd_state = t_ucd_state;
element->ucd_name = t_ucd_name;
element->ucd_type = t_ucd_type;
element->ucd_pile_opened = t_ucd_pile_opened;
element->isGhost = t_isGhost;
element->m_Theme = t_m_Theme;
element->m_Icon = t_m_Icon;
element->setZValue(t_zval);
if(this->ucd_parent == element->ucd_parent) {
this->setPos(element->pos());
}
if(this->ucd_parent != element->ucd_parent) {
this->setParentItem(element->parentItem());
this->setPos(element->mapToScene(element->pos()));
element->setParentItem(t_parent);
element->setPos(t_pos);
QList<UCD_Desktop*>::iterator i;
for (i = this->ucd_parent->items.begin(); i != this->ucd_parent->items.end(); ++i) {
if(*i == element) {
*i = this;
return;
}
}
for (i = element->ucd_parent->items.begin(); i != element->ucd_parent->items.end(); ++i) {
if(*i == this) {
*i = element;
return;
}
}
}
}
}
void UCD_Desktop::stretchPile(QGraphicsSceneMouseEvent * event) {
items.last()->QGraphicsItem::mousePressEvent(event);
}
/*****************************************************************
***************************EVENT CENTER***************************
*****************************************************************/
void UCD_Desktop::ucd_event(UCD_Desktop * element,QGraphicsSceneEvent * event) {
kDebug() << "Event Center: hello ..." << endl;
int i;
if(ucd_type == "controller") {
kDebug() << "UCD Desktop with type __controller__ ..." << endl;
if(event->type() == QEvent::GraphicsSceneMouseMove) {
kDebug() << "event: move, " << event->type() << endl;
if((i = collidingItem(element)) != -1) {
kDebug() << "highlighting collisioning item" << endl;
highlight(i);
}
else if((i = collidingPile(element)) != -1) {
kDebug() << "highlighting collisioning pile" << endl;
highlightPile(i);
}
else {
kDebug() << "no collision: normalizing just to be on the safe side ..." << endl;
kDebug() << "this is also the standard mechanism for deactivating highlighted items." << endl;
normalize();
}
}
if(event->type() == QEvent::GraphicsSceneMouseRelease) {
kDebug() << "event: release, " << event->type() << endl;
kDebug() << "normalizing ..." << endl;
normalize();
kDebug() << " collision detection follows ... " << endl;
if((i = collidingItem(element)) != -1) {
kDebug() << "@param-item collides with another item" << endl;
UCD_Desktop* pile = newPile(items.at(i));
pile->addItem(element);
}
else if((i = collidingPile(element)) != -1) {
kDebug() << "@param-item collides with a pile - delegating addItem" << endl;
piles.at(i)->addItem(element);
}
}
}
if(ucd_type == "pile") {
kDebug() << "UCD Desktop with type __pile__" << endl;
if(event->type() == QEvent::GraphicsSceneMousePress) {
kDebug() << "event: mouse press, " << event->type() << endl;
kDebug() << "setting ZValue to highest: " << ucd_parent->highestZValue()+1 << endl;
kDebug() << ".. and forwarding event to QGraphicsItem ???" << endl;
setZValue(ucd_parent->highestZValue()+1);
element->QGraphicsItem::mousePressEvent(dynamic_cast<QGraphicsSceneMouseEvent*>(event));
//QGraphicsItem::mousePressEvent(event);
}
if(event->type() == QEvent::GraphicsSceneMouseMove) {
kDebug() << "event: mouse move, " << event->type() << endl;
kDebug() << "forwarding event to QGraphicsItem ???" << endl;
kDebug() << "iterating through pile and adjusting item positions" << endl;
element->QGraphicsItem::mouseMoveEvent(dynamic_cast<QGraphicsSceneMouseEvent*>(event));
QList<UCD_Desktop*>::iterator i;
for (int i = 1; i < (items.size()-1); ++i) {
items.at(i)->setPos((width-element->width)/2+(element->x()/(items.size()-1)*i),(height-element->height)/4+(element->y()/(items.size()-1)*i));
}
//QGraphicsItem::mouseMoveEvent(event);
}
if(event->type() == QEvent::GraphicsSceneMouseRelease) {
kDebug() << "event: mouse release, " << event->type() << endl;
kDebug() << "forwarding event to QGraphicsItem ???" << endl;
kDebug() << "checking for collision with pile which is the actual parent pile..." << endl;
element->QGraphicsItem::mouseReleaseEvent(dynamic_cast<QGraphicsSceneMouseEvent*>(event));
int i = 0;
if((i = ucd_parent->collidingPile(element)) != -1 && ucd_parent->piles.at(i) == this) {
kDebug() << "resetting Pile and setting state to closed" << endl;
resetPile();
ucd_pile_opened = false;
}
else {
kDebug() << "no collision with parent pile -- setting pile state to opened";
ucd_pile_opened = true;
}
}
if(event->type() == QEvent::GraphicsSceneMouseDoubleClick) {
kDebug() << "event: mouse-double-click, " << event->type() << endl;
kDebug() << "resetting Pile and setting state to closed" << endl;
this->resetPile();
this->ucd_pile_opened = false;
}
if(event->type() == QEvent::GraphicsSceneHoverEnter) {
kDebug() << "event: hover enter, " << event->type() << endl;
kDebug() << "highlighting hover-enter-event" << endl;
element->setBackground("active");
}
if(event->type() == QEvent::GraphicsSceneHoverLeave) {
kDebug() << "event: hover leave, " << event->type() << endl;
kDebug() << "normalizing hover-left-element" << endl;
element->setBackground("normal");
}
}
}
qreal UCD_Desktop::highestZValue() {
QList<UCD_Desktop*>::iterator i;
qreal c = 0;
for (i = items.begin(); i != items.end(); ++i) {
if(c < (*i)->zValue()) {
c = (*i)->zValue();
}
}
for (i = piles.begin(); i != piles.end(); ++i) {
if(c < (*i)->zValue()) {
c = (*i)->zValue();
}
}
return c;
}
qreal UCD_Desktop::highestZValue(QString type) {
QList<UCD_Desktop*>::iterator i;
qreal c = 0;
if(type == "item") {
for (i = items.begin(); i != items.end(); ++i) {
if(c < (*i)->zValue()) {
c = (*i)->zValue();
}
}
}
if(type == "pile") {
for (i = piles.begin(); i != piles.end(); ++i) {
if(c < (*i)->zValue()) {
c = (*i)->zValue();
}
}
}
return c;
}
int UCD_Desktop::collidingItem(UCD_Desktop * element) {
kDebug() << "public int UCD_Desktop::collidingItem(UCD_Desktop* el)" << endl;
QList<UCD_Desktop*>::iterator i;
int c = 0;
for (i = items.begin(); i != items.end(); ++i) {
kDebug() << "... collides with *i ..." << endl;
kDebug() << "element-type: " << element->ucd_type << endl;
kDebug() << "element-parent-type: " << element->ucd_parent->ucd_type << endl;
if(element->collidesWithItem(*i) && element != (*i)) {
kDebug() << "found colliding Item ... returning int" << endl;
return c;
}
c++;
}
kDebug() << "no collision detected - returning -1 value" << endl;
return -1;
}
int UCD_Desktop::collidingPile(UCD_Desktop * element) {
QList<UCD_Desktop*>::iterator i;
int c = 0;
for (i = piles.begin(); i != piles.end(); ++i) {
if(element->collidesWithItem(*i) && element != (*i)) {
return c;
}
c++;
}
return -1;
}
void UCD_Desktop::resetPile() {
QList<UCD_Desktop*>::iterator i;
for (int i = 1; i < (items.size()); ++i) {
items.at(i)->setPos((width-items.at(i)->width)/2,(height-items.at(i)->height)/4);
}
}
void UCD_Desktop::removeItem() {
QTimeLine *timer = new QTimeLine(100);
timer->setFrameRange(0, 100);
this->ani = new QGraphicsItemAnimation;
ani->setItem(this);
ani->setTimeLine(timer);
for (int i = 0; i < 99; ++i)
ani->setScaleAt(i/100,1-1/((200-i)/50),1);
ani->setScaleAt(1,0,1);
connect(timer,SIGNAL(finished()),this,SLOT(itemRemoved()));
timer->start();
}
void UCD_Desktop::itemRemoved() {
//removeItemFromList(item);
this->ucd_parent->removeItemFromList(this);
QTimeLine *timer = new QTimeLine(100);
timer->setFrameRange(0, 100);
int xf = (this->ucd_parent->width-this->ucd_parent->items.at(0)->width)/2+(this->ucd_parent->items.at(this->ucd_parent->items.size()-1)->x()/(this->ucd_parent->items.size()-1));
int yf = (this->ucd_parent->width-this->ucd_parent->items.at(0)->width)/4+(this->ucd_parent->items.at(this->ucd_parent->items.size()-1)->y()/(this->ucd_parent->items.size()-1));
for(int i = 0; i < this->ucd_parent->items.size(); i++) {
this->ucd_parent->items.at(i)->ani = new QGraphicsItemAnimation;
this->ucd_parent->items.at(i)->ani->setItem(this->ucd_parent->items.at(i));
this->ucd_parent->items.at(i)->ani->setTimeLine(timer);
for (int j = 0; j < 99; ++j) {
this->ucd_parent->items.at(i)->ani->setPosAt(j/100,QPointF(((xf*i)-this->ucd_parent->items.at(i)->x())/(100-j),((yf*i)-this->ucd_parent->items.at(i)->y())/(100-j)));
}
this->ucd_parent->items.at(i)->ani->setPosAt(1,QPointF((xf*i),(yf*i)));
}
timer->start();
this->~UCD_Desktop();
}
void UCD_Desktop::removeItemFromList(UCD_Desktop * item) {
for(int i = 0; i < items.size(); i++) {
if(items.at(i) == item) {
kDebug() << "removing Item from list" << endl;
items.removeAt(i);
}
}
}
/*****************************************************************
***********************PAINTING FUNCTIONS*************************
*****************************************************************/
void UCD_Desktop::highlight(int i) {
QList<UCD_Desktop*>::iterator j;
for (j = items.begin(); j != items.end(); ++j) {
if(*j != items.at(i)) {
(*j)->setBackground("normal");
}
}
items.at(i)->setBackground("active");
}
void UCD_Desktop::highlightPile(int i) {
QList<UCD_Desktop*>::iterator j;
for (j = piles.begin(); j != piles.end(); ++j) {
if(*j != piles.at(i)) {
(*j)->setBackground("normal");
}
}
piles.at(i)->setBackground("active");
}
void UCD_Desktop::normalize() {
kDebug() << "normalize ..." << endl;
QList<UCD_Desktop*>::iterator j;
for (j = items.begin(); j != items.end(); ++j) {
kDebug() << "j items..." << endl;
(*j)->setBackground("normal");
}
for (j = piles.begin(); j != piles.end(); ++j) {
kDebug() << "j piles..." << endl;
(*j)->setBackground("normal");
}
kDebug() << "normalizing finished" << endl;
}
void UCD_Desktop::setBackground(QString state) {
ucd_state = state;
update();
}
/**********************************************************
*****************MOUSE EVENTS Reimplementations***********
**********************************************************/
void UCD_Desktop::contextMenuEvent( QGraphicsSceneContextMenuEvent * event ) {
if(ucd_type == "controller") {
}
else if(ucd_type == "pile") {
}
else if(ucd_type == "item") {
}
else{
QGraphicsItem::contextMenuEvent(event);
}
}
void UCD_Desktop::dragEnterEvent ( QGraphicsSceneDragDropEvent * event ) {
if(ucd_type == "controller") {
}
else if(ucd_type == "pile") {
}
else if(ucd_type == "item") {
}
else{
QGraphicsItem::dragEnterEvent(event);
}
}
void UCD_Desktop::dragLeaveEvent ( QGraphicsSceneDragDropEvent * event ) {
if(ucd_type == "controller") {
}
else if(ucd_type == "pile") {
}
else if(ucd_type == "item") {
}
else{
QGraphicsItem::dragLeaveEvent(event);
}
}
void UCD_Desktop::dragMoveEvent ( QGraphicsSceneDragDropEvent * event ) {
if(ucd_type == "controller") {
}
else if(ucd_type == "pile") {
}
else if(ucd_type == "item") {
}
else{
QGraphicsItem::dragMoveEvent(event);
}
}
void UCD_Desktop::dropEvent ( QGraphicsSceneDragDropEvent * event ) {
if(ucd_type == "controller") {
}
else if(ucd_type == "pile") {
}
else if(ucd_type == "item") {
}
else{
QGraphicsItem::dropEvent(event);
}
}
void UCD_Desktop::focusInEvent ( QFocusEvent * event ) {
if(ucd_type == "controller") {
}
else if(ucd_type == "pile") {
}
else if(ucd_type == "item") {
}
else{
QGraphicsItem::focusInEvent(event);
}
}
void UCD_Desktop::focusOutEvent ( QFocusEvent * event ) {
if(ucd_type == "controller") {
}
else if(ucd_type == "pile") {
}
else if(ucd_type == "item") {
}
else{
QGraphicsItem::focusOutEvent(event);
}
}
void UCD_Desktop::hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) {
if(ucd_type == "controller") {
}
else if(ucd_type == "pile") {
}
else if(ucd_type == "item") {
if(ucd_parent->ucd_type == "pile") {
ucd_parent->ucd_event(this,event);
return;
}
}
else{
QGraphicsItem::hoverEnterEvent(event);
}
}
void UCD_Desktop::hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) {
if(ucd_type == "controller") {
}
else if(ucd_type == "pile") {
}
else if(ucd_type == "item") {
if(ucd_parent->ucd_type == "pile") {
ucd_parent->ucd_event(this,event);
return;
}
}
else{
QGraphicsItem::hoverLeaveEvent(event);
}
}
void UCD_Desktop::hoverMoveEvent ( QGraphicsSceneHoverEvent * event ) {
if(ucd_type == "controller") {
}
else if(ucd_type == "pile") {
}
else if(ucd_type == "item") {
}
else{
QGraphicsItem::hoverMoveEvent(event);
}
}
void UCD_Desktop::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * event ) {
if(event->button() == Qt::RightButton)
return;
if(ucd_type == "controller") {
newItem();
QGraphicsItem::mouseDoubleClickEvent(event);
}
else if(ucd_type == "pile") {
resetPile();
ucd_pile_opened = false;
}
else if(ucd_type == "item") {
if(ucd_parent->ucd_type == "pile") {
if(this->zValue()==0) {
ucd_parent->ucd_event(this,event);
}
return;
}
}
else{
QGraphicsItem::mouseDoubleClickEvent(event);
}
}
void UCD_Desktop::mousePressEvent ( QGraphicsSceneMouseEvent * event ) {
kDebug() << "mousePressEvent, " << event->button() << endl;
if(event->button() == Qt::RightButton || isGhost)
return;
if(ucd_type == "controller") {
QGraphicsItem::mousePressEvent(event);
}
else if(ucd_type == "pile") {
setZValue(ucd_parent->highestZValue()+1);
QGraphicsItem::mousePressEvent(event);
}
else if(ucd_type == "item") {
kDebug() << "item clicked" << endl;
//ucd_parent->moveBy(-20,-20);
//ucd_parent->setBackground("active");
if(ucd_parent->ucd_type == "pile") {
kDebug() << "pile item clicked" << endl;
if(ucd_parent->highestZValue("item") == this->zValue()) {
ucd_parent->ucd_event(this,event);
kDebug() << " parent - event " << endl;
}
else {
kDebug() << "else --- jetzt neues item erzeugen" << endl;
UCD_Desktop * item = ucd_parent->ucd_parent->newItem();
this->ghost = item;
item->isGhost = true;
item->setPos(this->scenePos());
kDebug() << "itempos: " << item->pos() << endl;
kDebug() << "thispos: " << this->pos() << endl;
QList<UCD_Desktop*>::iterator i;
for (i = this->ucd_parent->items.begin(); i != this->ucd_parent->items.end(); ++i) {
if(*i == this) {
kDebug() << "jetzt wird pile(item = *i) zu item, *i: " << endl;
*i = item;
}
}
for (i = item->ucd_parent->items.begin(); i != item->ucd_parent->items.end(); ++i) {
if(*i == item) {
kDebug() << "jetzt wird item_parent_items(*i = item) zu this, *i: " << endl;
}
}
UCD_Desktop * t_ucd_parent = item->ucd_parent;
item->ucd_parent = this->ucd_parent;
this->ucd_parent = t_ucd_parent;
if(item->ucd_parent == this->ucd_parent)
kDebug() << " da stimmt was net mit den ponitern " << endl;
//QMouseEvent myevent(QEvent::MouseButtonPress, QPoint(event->pos().x(),event->pos().y()), Qt::LeftButton, 0,Qt::NoModifier);
//QApplication::sendEvent(item, &myevent);
//QGraphicsItem::mousePressEvent(event);
}
return;
}
setZValue(ucd_parent->highestZValue()+1);
ucd_parent->ucd_event(this,event);
QGraphicsItem::mousePressEvent(event);
}
else{
QGraphicsItem::mousePressEvent(event);
}
}
void UCD_Desktop::mouseMoveEvent ( QGraphicsSceneMouseEvent * event ) {
kDebug() << "mouseMoveEvent, " << event->button() << "isGhost: " << isGhost << endl;
if(event->button() == Qt::RightButton || isGhost)
return;
if(ucd_type == "controller") {
QGraphicsItem::mouseMoveEvent(event);
}
else if(ucd_type == "pile") {
QGraphicsItem::mouseMoveEvent(event);
}
else if(ucd_type == "item") {
if(ucd_parent->ucd_type == "pile") {
if(ucd_parent->highestZValue("item") == this->zValue()) {
ucd_parent->ucd_event(this,event);
}
return;
}
if(ghost) {
QGraphicsItem::mouseMoveEvent(event);
}
ucd_parent->ucd_event(this,event);
QGraphicsItem::mouseMoveEvent(event);
}
else{
QGraphicsItem::mouseMoveEvent(event);
}
}
void UCD_Desktop::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) {
kDebug() << "mouseReleaseEvent, " << event->button() << "ghost: " << isGhost << endl;
if(event->button() == Qt::RightButton || isGhost)
return;
if(ucd_type == "controller") {
kDebug() << "controller - nothing to be done ..." << endl;
QGraphicsItem::mouseReleaseEvent(event);
}
else if(ucd_type == "pile") {
kDebug() << "pile - nothing to be done ..." << endl;
QGraphicsItem::mouseReleaseEvent(event);
}
else if(ucd_type == "item") {
kDebug() << "item - checking parent: " << ucd_parent->ucd_type << " ..." << endl;
if(ucd_parent->ucd_type == "pile") {
kDebug() << "item is part of a pile" << endl;
if(ucd_parent->highestZValue("item") == this->zValue()) {
kDebug() << "item is topmost in pile - delegating event for further handling" << endl;
ucd_parent->ucd_event(this,event);
return;
}
kDebug() << "not topmost -- rleasing not topmost item - this is impossible: this is a ghost and no event handling should happen in this way at all" << endl;
kDebug() << "ghost: " << isGhost << endl;
return;
}
if(ghost) {
kDebug() << "released item has reference to ghost item - checking collisions ..." << endl;
int i;
if((i = ucd_parent->collidingPile(this)) != -1) {
kDebug() << "item collides with __some__ pile" << endl;
if(ucd_parent->piles.at(i) == ghost->ucd_parent) {
kDebug() << "item collides with ghost items pile" << endl;
kDebug() << "setting ghost item to state normal, destroying this item" << endl;
ghost->setBackground("normal");
ghost->isGhost = false;
this->~UCD_Desktop();
}
kDebug() << "colliding Pile is not ghost items pile -- removing ghost item, setting ghost to null" << endl;
ghost->removeItem();
ghost = NULL;
kDebug() << "forwarding event" << endl;
ucd_parent->ucd_event(this,event);
QGraphicsItem::mouseReleaseEvent(event);
return;
/*
else {
ghost->ucd_parent->removeItem(ghost);
ghost = NULL;
ucd_parent->piles.at(i)->addItem(this);
}*/
}
kDebug() << "no collision with pile detected -- removing ghost item, setting ghost to null" << endl;
ghost->removeItem();
ghost = NULL;
kDebug() << "forwarding event" << endl;
ucd_parent->ucd_event(this,event);
QGraphicsItem::mouseReleaseEvent(event);
return;
}
kDebug() << "forwarding event" << endl;
ucd_parent->ucd_event(this,event);
QGraphicsItem::mouseReleaseEvent(event);
}
else{
kDebug() << "should not happen" << endl;
QGraphicsItem::mouseReleaseEvent(event);
}
}
void UCD_Desktop::wheelEvent ( QGraphicsSceneWheelEvent * event ) {
if(ucd_type == "controller") {
}
else if(ucd_type == "pile") {
}
else if(ucd_type == "item") {
}
else{
QGraphicsItem::wheelEvent(event);
}
}
#include "ucd_desktop.moc"