• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kblackbox

kbbgraphicsitemrayresult.cpp

Go to the documentation of this file.
00001 //
00002 // KBlackBox
00003 //
00004 // A simple game inspired by an emacs module
00005 //
00006 /***************************************************************************
00007  *   Copyright (c) 1999-2000, Robert Cimrman                               *
00008  *   cimrman3@students.zcu.cz                                              *
00009  *                                                                         *
00010  *   Copyright (c) 2007, Nicolas Roffet                                    *
00011  *   nicolas-kde@roffet.com                                                *
00012  *                                                                         *
00013  *                                                                         *
00014  *   This program is free software; you can redistribute it and/or modify  *
00015  *   it under the terms of the GNU General Public License as published by  *
00016  *   the Free Software Foundation; either version 2 of the License, or     *
00017  *   (at your option) any later version.                                   *
00018  *                                                                         *
00019  *   This program is distributed in the hope that it will be useful,       *
00020  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00021  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00022  *   GNU General Public License for more details.                          *
00023  *                                                                         *
00024  *   You should have received a copy of the GNU General Public License     *
00025  *   along with this program; if not, write to the                         *
00026  *   Free Software Foundation, Inc.,                                       *
00027  *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA               *
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 // Constructor / Destructor
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 // Public
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 // Private
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 }

kblackbox

Skip menu "kblackbox"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

API Reference

Skip menu "API Reference"
  • kblackbox
  • kgoldrunner
  • kmahjongg
  • ksquares
  • libkdegames
  •   highscore
  •   kgame
  •   kggzgames
  •   kggzmod
  •   kggznet
  • libkmahjongg
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal