kblackbox
kbbgraphicsitemball.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "kbbgraphicsitemball.h"
00031
00032
00033
00034 #include <QGraphicsSceneHoverEvent>
00035 #include <QTimer>
00036
00037
00038 #include "kbbgraphicsiteminteractioninfo.h"
00039 #include "kbbgraphicsitemonbox.h"
00040 #include "kbbscalablegraphicwidget.h"
00041 #include "kbbthememanager.h"
00042
00043
00044
00045
00046
00047
00048
00049 KBBGraphicsItemBall::KBBGraphicsItemBall(KBBScalableGraphicWidget::itemType itemType, KBBScalableGraphicWidget* parent, KBBThemeManager* themeManager, int boxPosition, int columns, int rows) : KBBGraphicsItemOnBox( itemType, parent, themeManager, boxPosition, columns, rows)
00050 {
00051 m_timer = NULL;
00052 m_ballType = itemType;
00053 m_themeManager = themeManager;
00054
00055 setAcceptsHoverEvents(true);
00056
00057 for (int i=0; i<8;i++)
00058 m_interactionInfos[i] = NULL;
00059 }
00060
00061
00062 KBBGraphicsItemBall::~KBBGraphicsItemBall()
00063 {
00064 removeInteractionInfos();
00065 }
00066
00067
00068
00069
00070
00071
00072
00073 void KBBGraphicsItemBall::showInteractions()
00074 {
00075 delete m_timer;
00076 m_timer = NULL;
00077
00078 const int offsetX[8] = {0, 1, 2, 2, 2, 1, 0, 0};
00079 const int offsetY[8] = {0, 0, 0, 1, 2, 2, 2, 1};
00080 qreal posX;
00081 qreal posY;
00082
00083
00084 for (int i=0; i<8;i++) {
00085 posX = x() - KBBScalableGraphicWidget::RATIO/2 + offsetX[i]*KBBScalableGraphicWidget::RATIO;
00086 posY = y() - KBBScalableGraphicWidget::RATIO/2 + offsetY[i]*KBBScalableGraphicWidget::RATIO;
00087 KBBScalableGraphicWidget::itemType type = KBBScalableGraphicWidget::interactionInfoDeflection;
00088 if (i%2 == 1)
00089 type = KBBScalableGraphicWidget::interactionInfoHit;
00090 m_interactionInfos[i] = new KBBGraphicsItemInteractionInfo(m_widget, m_themeManager, type, posX, posY, i*45 );
00091 }
00092
00093
00094 const KBBScalableGraphicWidget::itemType r = KBBScalableGraphicWidget::interactionInfoReflection;
00095 const KBBScalableGraphicWidget::itemType rS = KBBScalableGraphicWidget::interactionInfoReflectionSym;
00096 if (position()<m_columns) {
00097 m_interactionInfos[0]->setType(r);
00098 m_interactionInfos[2]->setType(rS);
00099 }
00100 if (position()>=m_columns*(m_rows-1)) {
00101 m_interactionInfos[4]->setType(r);
00102 m_interactionInfos[6]->setType(rS);
00103 }
00104 if (position()%m_columns == 0) {
00105 m_interactionInfos[6]->setType(r);
00106 m_interactionInfos[0]->setType(rS);
00107 }
00108 if (position()%m_columns == (m_columns-1)) {
00109 m_interactionInfos[2]->setType(r);
00110 m_interactionInfos[4]->setType(rS);
00111 }
00112
00113
00114 const KBBScalableGraphicWidget::itemType n = KBBScalableGraphicWidget::interactionInfoNothing;
00115 if (position()==0)
00116 m_interactionInfos[0]->setType(n);
00117 if (position()==m_columns-1)
00118 m_interactionInfos[2]->setType(n);
00119 if (position()==m_rows*m_columns-1)
00120 m_interactionInfos[4]->setType(n);
00121 if (position()==(m_rows-1)*m_columns)
00122 m_interactionInfos[6]->setType(n);
00123 }
00124
00125
00126
00127
00128
00129
00130
00131 void KBBGraphicsItemBall::hoverEnterEvent (QGraphicsSceneHoverEvent*)
00132 {
00133 if (m_timer==NULL) {
00134 m_timer = new QTimer(this);
00135 connect(m_timer, SIGNAL(timeout()), this, SLOT(showInteractions()));
00136 m_timer->start(TIME_TO_WAIT_BEFORE_SHOWING_INTERACTIONS);
00137 }
00138 }
00139
00140
00141 void KBBGraphicsItemBall::hoverLeaveEvent (QGraphicsSceneHoverEvent*)
00142 {
00143 delete m_timer;
00144 m_timer = NULL;
00145 removeInteractionInfos();
00146 }
00147
00148
00149 void KBBGraphicsItemBall::removeInteractionInfos()
00150 {
00151 for (int i=0; i<8;i++) {
00152 delete m_interactionInfos[i];
00153 m_interactionInfos[i] = NULL;
00154 }
00155 }
00156
00157 #include "kbbgraphicsitemball.moc"