kblackbox
kbbgraphicsitemblackbox.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 "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
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
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
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
00088 for (int i=0; i<m_lines.count(); i++)
00089 delete m_lines[i];
00090 m_lines.clear();
00091
00092
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
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
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 }