File indexing completed on 2024-04-21 04:02:02
0001 /* 0002 KBlackBox - A simple game inspired by an emacs module 0003 0004 SPDX-FileCopyrightText: 1999-2000 Robert Cimrman <cimrman3@students.zcu.cz> 0005 SPDX-FileCopyrightText: 2007 Nicolas Roffet <nicolas-kde@roffet.com> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 0011 #include "kbbgraphicsitemlaser.h" 0012 0013 #include <QGraphicsSceneMouseEvent> 0014 0015 0016 0017 #include "kbbscalablegraphicwidget.h" 0018 #include "kbbthememanager.h" 0019 0020 0021 0022 // 0023 // Constructor / Destructor 0024 // 0025 0026 KBBGraphicsItemLaser::KBBGraphicsItemLaser(KBBScalableGraphicWidget* parent, KBBThemeManager* themeManager, const int borderPosition, const int columns, const int rows) : KBBGraphicsItemBorder(borderPosition, columns, rows, 0), KBBGraphicsItem(((borderPosition<columns) ? KBBScalableGraphicWidget::laser0 : ((borderPosition<columns + rows) ? KBBScalableGraphicWidget::laser90 : ((borderPosition<2*columns + rows) ? KBBScalableGraphicWidget::laser180 : KBBScalableGraphicWidget::laser270))) , parent->scene(), themeManager), KBBItemWithPosition() 0027 { 0028 m_widget = parent; 0029 0030 const int radius = KBBScalableGraphicWidget::RATIO/2; 0031 if (rotationAngle()==90) { 0032 setPos(m_centerX - 3*radius, m_centerY - radius); 0033 } else if (rotationAngle()==180) { 0034 setPos(m_centerX - radius, m_centerY - 3*radius); 0035 } else { 0036 setPos(m_centerX - radius, m_centerY - radius); 0037 } 0038 0039 setAcceptHoverEvents(true); 0040 } 0041 0042 0043 0044 // 0045 // Public 0046 // 0047 0048 int KBBGraphicsItemLaser::position () 0049 { 0050 return m_borderPosition; 0051 } 0052 0053 0054 0055 // 0056 // Private 0057 // 0058 0059 void KBBGraphicsItemLaser::hoverEnterEvent (QGraphicsSceneHoverEvent*) 0060 { 0061 m_widget->drawRay(position()); 0062 } 0063 0064 0065 void KBBGraphicsItemLaser::hoverLeaveEvent (QGraphicsSceneHoverEvent*) 0066 { 0067 m_widget->removeRay(); 0068 } 0069 0070 0071 void KBBGraphicsItemLaser::mousePressEvent (QGraphicsSceneMouseEvent* event) 0072 { 0073 if (event->buttons()==Qt::LeftButton) { 0074 m_widget->mouseBorderClick(position()); 0075 } 0076 }