• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

kblackbox

  • sources
  • kde-4.14
  • kdegames
  • kblackbox
kbbgraphicsitemblackbox.cpp
Go to the documentation of this file.
1 //
2 // KBlackBox
3 //
4 // A simple game inspired by an emacs module
5 //
6 /***************************************************************************
7  * Copyright (c) 1999-2000, Robert Cimrman *
8  * cimrman3@students.zcu.cz *
9  * *
10  * Copyright (c) 2007, Nicolas Roffet *
11  * nicolas-kde@roffet.com *
12  * *
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  * This program is distributed in the hope that it will be useful, *
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22  * GNU General Public License for more details. *
23  * *
24  * You should have received a copy of the GNU General Public License *
25  * along with this program; if not, write to the *
26  * Free Software Foundation, Inc., *
27  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA *
28  ***************************************************************************/
29 
30 #include "kbbgraphicsitemblackbox.h"
31 
32 
33 
34 #include <QGraphicsLineItem>
35 #include <QGraphicsRectItem>
36 #include <QGraphicsScene>
37 #include <QGraphicsSceneMouseEvent>
38 #include <QGraphicsView>
39 
40 
41 #include "kbbgraphicsitem.h"
42 #include "kbbscalablegraphicwidget.h"
43 #include "kbbthememanager.h"
44 
45 
46 
47 //
48 // Constructor / Destructor
49 //
50 
51 KBBGraphicsItemBlackBox::KBBGraphicsItemBlackBox(QGraphicsView* parent, QGraphicsScene* scene, KBBThemeManager* themeManager) : QGraphicsRectItem (0, scene)
52 {
53  m_columns = 1;
54  m_rows = 1;
55  m_widget = 0;
56  m_scene = scene;
57 
58  m_background = new KBBGraphicsItem(KBBScalableGraphicWidget::blackbox, m_scene, themeManager);
59 
60  //Grid
61  const KBBScalableGraphicWidget::itemType g = KBBScalableGraphicWidget::blackboxGrid;
62  m_zValueLines = themeManager->zValue(g);
63  m_penLines.setColor(themeManager->color(g));
64  m_penLines.setStyle(themeManager->style(g));
65  m_penLines.setWidthF(themeManager->width(g));
66 }
67 
68 
69 
70 //
71 // Public
72 //
73 
74 void KBBGraphicsItemBlackBox::setSize(const int columns, const int rows)
75 {
76  m_background->scale(1./m_columns, 1./m_rows);
77 
78  if ((m_columns!=columns) || (m_rows!=rows)) {
79  m_columns = columns;
80  m_rows = rows;
81 
82  const int b = KBBScalableGraphicWidget::BORDER_SIZE;
83  const int r = KBBScalableGraphicWidget::RATIO;
84 
85  setRect(b, b, m_columns*r, m_rows*r);
86 
87  //remove old lines
88  for (int i=0; i<m_lines.count(); i++)
89  delete m_lines[i];
90  m_lines.clear();
91 
92  // add new lines
93  for (int i=0; i<m_columns+1; i++)
94  m_lines.append(new QGraphicsLineItem( b + i*r, b, b + i*r, b + m_rows*r, this, m_scene));
95  for (int i=0; i<m_rows+1; i++)
96  m_lines.append(new QGraphicsLineItem( b, b + i*r, b + m_columns*r, b + i*r, this, m_scene));
97 
98  // set line style
99  for (int i=0; i<m_lines.count(); i++) {
100  m_lines[i]->setPen(m_penLines);
101  m_lines[i]->setZValue(m_zValueLines);
102  }
103  m_background->setPos(b, b);
104  }
105 
106  m_background->scale(m_columns/1., m_rows/1.);
107 }
108 
109 
110 void KBBGraphicsItemBlackBox::setKBBScalableGraphicWidget(KBBScalableGraphicWidget* w)
111 {
112  m_widget = w;
113 }
114 
115 
116 
117 //
118 // Private
119 //
120 
121 void KBBGraphicsItemBlackBox::mousePressEvent (QGraphicsSceneMouseEvent* event)
122 {
123  int x = (int)(event->pos().x() - KBBScalableGraphicWidget::BORDER_SIZE)/KBBScalableGraphicWidget::RATIO;
124  int y = (int)(event->pos().y() - KBBScalableGraphicWidget::BORDER_SIZE)/KBBScalableGraphicWidget::RATIO;
125 
126  if (m_widget!=0)
127  m_widget->mouseBoxClick(event->button(), x + y*m_columns);
128 }
QList::clear
void clear()
QGraphicsItem::x
qreal x() const
QGraphicsItem::y
qreal y() const
QPen::setStyle
void setStyle(Qt::PenStyle style)
KBBThemeManager::width
qreal width(const KBBScalableGraphicWidget::itemType itemType)
Get the width of the item.
Definition: kbbthememanager.cpp:191
QGraphicsScene
kbbgraphicsitem.h
KBBGraphicsItem
Graphic item of the scalable graphic widget.
Definition: kbbgraphicsitem.h:44
KBBScalableGraphicWidget
Scalable graphic central widget for KBlackBox.
Definition: kbbscalablegraphicwidget.h:62
KBBThemeManager::zValue
int zValue(const KBBScalableGraphicWidget::itemType itemType)
Get the relative height of the item.
Definition: kbbthememanager.cpp:197
QGraphicsItem::scene
QGraphicsScene * scene() const
QGraphicsRectItem::setRect
void setRect(const QRectF &rectangle)
QList::count
int count(const T &value) const
QPointF::x
qreal x() const
QPointF::y
qreal y() const
QList::append
void append(const T &value)
QGraphicsLineItem
QGraphicsSceneMouseEvent
QGraphicsItem::setPos
void setPos(const QPointF &pos)
QGraphicsObject::scale
scale
QPen::setWidthF
void setWidthF(qreal width)
kbbscalablegraphicwidget.h
KBBScalableGraphicWidget::BORDER_SIZE
static int const BORDER_SIZE
Distance between the black box and the widget border.
Definition: kbbscalablegraphicwidget.h:74
QGraphicsSceneMouseEvent::button
Qt::MouseButton button() const
KBBGraphicsItemBlackBox::setKBBScalableGraphicWidget
void setKBBScalableGraphicWidget(KBBScalableGraphicWidget *w)
Set the KBBScalableGraphicWidget.
Definition: kbbgraphicsitemblackbox.cpp:110
kbbgraphicsitemblackbox.h
QPen::setColor
void setColor(const QColor &color)
KBBThemeManager::color
QColor color(const KBBScalableGraphicWidget::itemType itemType)
Get the color of the item.
Definition: kbbthememanager.cpp:75
KBBScalableGraphicWidget::blackbox
Definition: kbbscalablegraphicwidget.h:92
KBBScalableGraphicWidget::mouseBoxClick
void mouseBoxClick(const Qt::MouseButton button, int boxPosition)
Definition: kbbscalablegraphicwidget.cpp:210
KBBScalableGraphicWidget::blackboxGrid
Definition: kbbscalablegraphicwidget.h:93
KBBGraphicsItemBlackBox::KBBGraphicsItemBlackBox
KBBGraphicsItemBlackBox(QGraphicsView *parent, QGraphicsScene *scene, KBBThemeManager *themeManager)
Constructor.
Definition: kbbgraphicsitemblackbox.cpp:51
QGraphicsRectItem
KBBScalableGraphicWidget::RATIO
static int const RATIO
Width and height of a single square on the black box.
Definition: kbbscalablegraphicwidget.h:81
KBBThemeManager
Theme manager of the scalable graphic widget.
Definition: kbbthememanager.h:51
QGraphicsSceneMouseEvent::pos
QPointF pos() const
QGraphicsView
KBBThemeManager::style
Qt::PenStyle style(const KBBScalableGraphicWidget::itemType itemType)
Get the pen style of the item.
Definition: kbbthememanager.cpp:176
KBBScalableGraphicWidget::itemType
itemType
Every graphic items.
Definition: kbbscalablegraphicwidget.h:89
kbbthememanager.h
KBBGraphicsItemBlackBox::setSize
void setSize(const int columns, const int rows)
Define the (new) size of the black box.
Definition: kbbgraphicsitemblackbox.cpp:74
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kblackbox

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

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal