24#include <tqapplication.h>
25#include <tqpointarray.h>
31#include "kexirelationview.h"
32#include "kexirelationviewtable.h"
33#include "kexirelationviewconnection.h"
34#include <kexidb/tableschema.h>
35#include <kexidb/utils.h>
41KexiRelationViewConnection::KexiRelationViewConnection(
42 KexiRelationViewTableContainer *masterTbl, KexiRelationViewTableContainer *detailsTbl,
48 m_masterTable = masterTbl;
49 if(!masterTbl || !detailsTbl)
51 kdDebug() <<
"KexiRelationViewConnection::KexiRelationViewConnection(): expect sig11" << endl;
52 kdDebug() <<
"KexiRelationViewConnection::KexiRelationViewConnection()" << masterTbl << endl;
53 kdDebug() <<
"KexiRelationViewConnection::KexiRelationViewConnection()" << detailsTbl << endl;
56 m_detailsTable = detailsTbl;
57 m_masterField = c.masterField;
58 m_detailsField = c.detailsField;
63KexiRelationViewConnection::~KexiRelationViewConnection()
68KexiRelationViewConnection::drawConnection(TQPainter *p)
70 p->setPen(m_parent->palette().active().foreground());
71 int sx = m_masterTable->x() + m_masterTable->width() + m_parent->contentsX();
72 int sy = m_masterTable->globalY(m_masterField);
73 int rx = m_detailsTable->x() + m_parent->contentsX();
74 int ry = m_detailsTable->globalY(m_detailsField);
78 int side1x=0, side1y=sy - fm.height(),
79 sideNx=0, sideNy=ry - fm.height();
81 TQChar sideNChar(0x221E);
82 uint sideNCharWidth = 2+2+ fm.width( sideNChar );
83 TQChar side1Char(
'1');
84 uint side1CharWidth = 2+2+ fm.width( side1Char );
85 p->setBrush(p->pen().color());
87 if(m_masterTable->x() < m_detailsTable->x())
90 p->drawLine(rx - sideNCharWidth, ry, rx, ry);
92 pa.setPoint(0, rx - 4, ry - 3);
93 pa.setPoint(1, rx - 4, ry + 3);
94 pa.setPoint(2, rx - 1, ry);
95 p->drawPolygon(pa,
true);
98 p->drawLine(sx, sy - 1, sx + side1CharWidth -1, sy - 1);
99 p->drawLine(sx, sy, sx + side1CharWidth -1, sy);
100 p->drawLine(sx, sy + 1, sx + side1CharWidth -1, sy + 1);
105 sideNx = rx - sideNCharWidth - 1;
116 p->drawLine(sx + side1CharWidth, sy, rx - sideNCharWidth, ry);
128 int lx = rx + m_detailsTable->width();
129 int rx = sx - m_masterTable->width();
132 p->drawLine(lx, ry, lx + sideNCharWidth, ry);
134 pa.setPoint(0, lx + 3, ry - 3);
135 pa.setPoint(1, lx + 3, ry + 3);
136 pa.setPoint(2, lx, ry);
137 p->drawPolygon(pa,
true);
145 p->drawLine(rx - side1CharWidth +1, sy - 1, rx, sy - 1);
146 p->drawLine(rx - side1CharWidth +1, sy + 1, rx, sy + 1);
147 p->drawLine(rx - side1CharWidth +1, sy, rx, sy);
149 side1x = rx - side1CharWidth;
162 p->drawLine(lx + sideNCharWidth, ry, rx - side1CharWidth, sy);
172 p->drawText(side1x, side1y, side1CharWidth, fm.height(), TQt::AlignCenter, side1Char);
173 p->drawText(sideNx, sideNy, sideNCharWidth, fm.height(), TQt::AlignCenter, sideNChar);
180KexiRelationViewConnection::connectionRect()
182 int sx = m_masterTable->x() + m_parent->contentsX();
183 int rx = m_detailsTable->x() + m_parent->contentsX();
184 int ry = m_detailsTable->globalY(m_detailsField);
185 int sy = m_masterTable->globalY(m_masterField);
187 int width, leftX, rightX;
193 width = m_masterTable->width();
199 width = m_detailsTable->width();
203 int dx = TQABS((leftX + width) - rightX);
204 int dy = TQABS(sy - ry) + 2;
206 int top = TQMIN(sy, ry);
207 int left = leftX + width;
211 TQRect rect(left - 150, top - 150, dx + 150, dy + 150);
220KexiRelationViewConnection::matchesPoint(
const TQPoint &p,
int tolerance)
222 TQRect we = connectionRect();
234 int sx = m_masterTable->x() + m_masterTable->width();
235 int sy = m_masterTable->globalY(m_masterField);
236 int rx = m_detailsTable->x();
237 int ry = m_detailsTable->globalY(m_detailsField);
246 x1 = m_detailsTable->x() + m_detailsTable->width();
247 x2 = m_masterTable->x();
259 float mag = sqrt(mx * mx + my * my);
260 float u = (((p.x() - x1)*(x2 - x1))+((p.y() - y1)*(y2 - y1)))/(mag * mag);
261 kdDebug() <<
"KexiRelationViewConnection::matchesPoint(): u: " << u << endl;
263 float iX = x1 + u * (x2 - x1);
264 float iY = y1 + u * (y2 - y1);
265 kdDebug() <<
"KexiRelationViewConnection::matchesPoint(): px: " << p.x() << endl;
266 kdDebug() <<
"KexiRelationViewConnection::matchesPoint(): py: " << p.y() << endl;
267 kdDebug() <<
"KexiRelationViewConnection::matchesPoint(): ix: " << iX << endl;
268 kdDebug() <<
"KexiRelationViewConnection::matchesPoint(): iy: " << iY << endl;
270 float dX = iX - p.x();
271 float dY = iY - p.y();
273 kdDebug() <<
"KexiRelationViewConnection::matchesPoint(): dx: " << dX << endl;
274 kdDebug() <<
"KexiRelationViewConnection::matchesPoint(): dy: " << dY << endl;
276 float distance = sqrt(dX * dX + dY * dY);
277 kdDebug() <<
"KexiRelationViewConnection::matchesPoint(): distance: " << distance << endl;
279 if(distance <= tolerance)
286KexiRelationViewConnection::toString()
const
290 if (m_masterTable && m_masterTable->schema()->table()) {
291 str += (TQString(m_masterTable->schema()->name()) +
"." + m_masterField);
293 if (m_detailsTable && m_detailsTable->schema()->table()) {
295 str += (TQString(m_detailsTable->schema()->name()) +
"." + m_detailsField);
provides a view for displaying relations between database tables.
KEXICORE_EXPORT TQFont smallFont(TQWidget *init=0)