kblackbox
kbbgraphicsitemrayresult.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 "kbbgraphicsitemrayresult.h"
00031
00032
00033
00034 #include <QFont>
00035 #include <QGraphicsScene>
00036
00037
00038 #include "kbbgraphicsitem.h"
00039 #include "kbbgraphicsitemborder.h"
00040 #include "kbbitemwithposition.h"
00041 #include "kbbscalablegraphicwidget.h"
00042 #include "kbbthememanager.h"
00043
00044
00045
00046
00047
00048
00049
00050 KBBGraphicsItemRayResult::KBBGraphicsItemRayResult( KBBScalableGraphicWidget* parent, KBBThemeManager* themeManager, QGraphicsScene* scene, const int borderPosition, const int columns, const int rows, const int rayNumber) : KBBGraphicsItemBorder( borderPosition, columns, rows, KBBScalableGraphicWidget::BORDER_SIZE/2), KBBGraphicsItem(KBBScalableGraphicWidget::resultBackground, scene, themeManager), KBBItemWithPosition()
00051 {
00052 m_widget = parent;
00053 m_scene = scene;
00054 m_elementIdResultBackground = themeManager->elementId(KBBScalableGraphicWidget::resultBackground);
00055 m_elementIdResultBackgroundHighlight = themeManager->elementId(KBBScalableGraphicWidget::resultBackgroundHighlight);
00056 m_number = NULL;
00057 m_notNumber = NULL;
00058 m_pause = false;
00059
00060 float centerRadius = 3*KBBScalableGraphicWidget::RATIO/8.;
00061 float radius = KBBScalableGraphicWidget::BORDER_SIZE/4.;
00062
00063 m_opposite = this;
00064
00065 setPos(m_centerX - radius, m_centerY - radius);
00066
00067 if(rayNumber<=0) {
00068
00069 if (rayNumber==0)
00070 m_notNumber = new KBBGraphicsItem(KBBScalableGraphicWidget::resultReflection, m_scene, themeManager);
00071 else
00072 m_notNumber = new KBBGraphicsItem(KBBScalableGraphicWidget::resultHit, m_scene, themeManager);
00073 m_notNumber->translate(radius,radius);
00074 m_notNumber->rotate(rotation());
00075 m_notNumber->translate(-radius,-radius);
00076 m_notNumber->setPos(m_centerX - radius, m_centerY - radius);
00077 } else {
00078 QString text;
00079 text.setNum(rayNumber);
00080
00081 m_number = new QGraphicsSimpleTextItem ( text, this, scene);
00082 QFont font;
00083 font.setStyleHint(QFont::SansSerif);
00084 font.setWeight(QFont::DemiBold);
00085 float offset;
00086 if (rayNumber<10) {
00087 font.setPixelSize((int)(3*centerRadius/2));
00088 offset = 0.;
00089 } else {
00090 font.setPixelSize((int)(5*centerRadius/4));
00091 offset = 1.*centerRadius/6;
00092 }
00093 m_number->setFont(font);
00094 m_number->setPos(radius - centerRadius/2 - 2*offset, radius - centerRadius + offset);
00095 m_number->setZValue(themeManager->zValue(KBBScalableGraphicWidget::resultText));
00096 }
00097 setAcceptsHoverEvents(true);
00098 }
00099
00100
00101
00102
00103
00104
00105
00106 void KBBGraphicsItemRayResult::cleanDelete()
00107 {
00108 delete m_notNumber;
00109 delete m_number;
00110 delete this;
00111 }
00112
00113
00114 void KBBGraphicsItemRayResult::highlight(bool state)
00115 {
00116 if (state && !m_pause)
00117 setElementId(m_elementIdResultBackgroundHighlight);
00118 else
00119 setElementId(m_elementIdResultBackground);
00120 }
00121
00122
00123 void KBBGraphicsItemRayResult::highlightBoth(bool state)
00124 {
00125 m_opposite->highlight(state);
00126 highlight(state);
00127 }
00128
00129
00130 const int KBBGraphicsItemRayResult::position ()
00131 {
00132 return m_borderPosition;
00133 }
00134
00135
00136 void KBBGraphicsItemRayResult::setOpposite(KBBGraphicsItemRayResult* opposite)
00137 {
00138 m_opposite = opposite;
00139 }
00140
00141
00142 void KBBGraphicsItemRayResult::setPause(bool state)
00143 {
00144 if (m_number!=NULL)
00145 m_number->setVisible(!state);
00146 if (m_notNumber!=NULL)
00147 m_notNumber->setVisible(!state);
00148
00149 m_pause = state;
00150 }
00151
00152
00153
00154
00155
00156
00157
00158 void KBBGraphicsItemRayResult::hoverEnterEvent (QGraphicsSceneHoverEvent*)
00159 {
00160 highlightBoth(true);
00161 m_widget->drawRay(position());
00162 }
00163
00164
00165 void KBBGraphicsItemRayResult::hoverLeaveEvent (QGraphicsSceneHoverEvent*)
00166 {
00167 highlightBoth(false);
00168 m_widget->removeRay();
00169 }