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

kblackbox

kbbgraphicsitemblackbox.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 "kbbgraphicsitemblackbox.h"
00031 
00032 
00033 
00034 #include <QGraphicsLineItem>
00035 #include <QGraphicsRectItem>
00036 #include <QGraphicsScene>
00037 #include <QGraphicsSceneMouseEvent>
00038 #include <QGraphicsView>
00039 
00040 
00041 #include "kbbgraphicsitem.h"
00042 #include "kbbscalablegraphicwidget.h"
00043 #include "kbbthememanager.h"
00044 
00045 
00046 
00047 //
00048 // Constructor / Destructor
00049 //
00050 
00051 KBBGraphicsItemBlackBox::KBBGraphicsItemBlackBox(QGraphicsView* parent, QGraphicsScene* scene, KBBThemeManager* themeManager) : QGraphicsRectItem (0, scene)
00052 {
00053     m_columns = 1;
00054     m_rows = 1;
00055     m_widget = 0;
00056     m_scene = scene;
00057 
00058     m_background = new KBBGraphicsItem(KBBScalableGraphicWidget::blackbox, m_scene, themeManager);
00059     
00060     //Grid
00061     const KBBScalableGraphicWidget::itemType g = KBBScalableGraphicWidget::blackboxGrid;
00062     m_zValueLines = themeManager->zValue(g);
00063     m_penLines.setColor(themeManager->color(g));
00064     m_penLines.setStyle(themeManager->style(g));
00065     m_penLines.setWidthF(themeManager->width(g));
00066 }
00067 
00068 
00069 
00070 //
00071 // Public
00072 //
00073 
00074 void KBBGraphicsItemBlackBox::setSize(const int columns, const int rows)
00075 {
00076     m_background->scale(1./m_columns, 1./m_rows);
00077 
00078     if ((m_columns!=columns) || (m_rows!=rows)) {
00079         m_columns = columns;
00080         m_rows = rows;
00081         
00082         const int b = KBBScalableGraphicWidget::BORDER_SIZE;
00083         const int r = KBBScalableGraphicWidget::RATIO;
00084         
00085         setRect(b, b, m_columns*r, m_rows*r);
00086     
00087         //remove old lines
00088         for (int i=0; i<m_lines.count(); i++)
00089             delete m_lines[i];
00090         m_lines.clear();
00091     
00092         // add new lines
00093         for (int i=0; i<m_columns+1; i++)
00094             m_lines.append(new QGraphicsLineItem( b + i*r, b, b + i*r, b + m_rows*r, this, m_scene));
00095         for (int i=0; i<m_rows+1; i++)
00096             m_lines.append(new QGraphicsLineItem(  b, b + i*r, b + m_columns*r,  b + i*r, this, m_scene));
00097         
00098         // set line style
00099         for (int i=0; i<m_lines.count(); i++) {
00100             m_lines[i]->setPen(m_penLines);
00101             m_lines[i]->setZValue(m_zValueLines);
00102         }
00103         m_background->setPos(b, b);
00104     }
00105     
00106     m_background->scale(m_columns/1., m_rows/1.);
00107 }
00108 
00109 
00110 void KBBGraphicsItemBlackBox::setKBBScalableGraphicWidget(KBBScalableGraphicWidget* w)
00111 {
00112     m_widget = w;
00113 }
00114 
00115 
00116 
00117 //
00118 // Private
00119 //
00120 
00121 void KBBGraphicsItemBlackBox::mousePressEvent (QGraphicsSceneMouseEvent* event)
00122 {
00123     int x = (int)(event->pos().x() - KBBScalableGraphicWidget::BORDER_SIZE)/KBBScalableGraphicWidget::RATIO;
00124     int y = (int)(event->pos().y() - KBBScalableGraphicWidget::BORDER_SIZE)/KBBScalableGraphicWidget::RATIO;
00125     
00126     if (m_widget!=0)
00127         m_widget->mouseBoxClick(event->button(), x + y*m_columns);
00128 }

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