#include <hoverpoints.h>
Inheritance diagram for HoverPoints:


Definition at line 31 of file hoverpoints.h.
Definition at line 35 of file hoverpoints.h.
00035 { 00036 CircleShape, 00037 RectangleShape 00038 };
Definition at line 40 of file hoverpoints.h.
00040 { 00041 LockToLeft = 0x01, 00042 LockToRight = 0x02, 00043 LockToTop = 0x04, 00044 LockToBottom = 0x08 00045 };
Definition at line 53 of file hoverpoints.h.
00053 { 00054 NoConnection, 00055 LineConnection, 00056 CurveConnection 00057 };
| HoverPoints::HoverPoints | ( | QWidget * | widget, | |
| PointShape | shape | |||
| ) |
Definition at line 33 of file hoverpoints.cpp.
References QObject::connect(), CurveConnection, QObject::installEventFilter(), m_connectionPen, m_connectionType, m_currentIndex, m_editable, m_enabled, m_pointBrush, m_pointPen, m_pointSize, m_shape, m_sortType, m_widget, NoSort, pointsChanged(), SIGNAL, and SLOT.
00034 : QObject(widget) 00035 { 00036 m_widget = widget; 00037 widget->installEventFilter(this); 00038 00039 m_connectionType = CurveConnection; 00040 m_sortType = NoSort; 00041 m_shape = shape; 00042 m_pointPen = QPen(QColor(255, 255, 255, 191), 1); 00043 m_connectionPen = QPen(QColor(255, 255, 255, 127), 2); 00044 m_pointBrush = QBrush(QColor(191, 191, 191, 127)); 00045 m_pointSize = QSize(11, 11); 00046 m_currentIndex = -1; 00047 m_editable = true; 00048 m_enabled = true; 00049 00050 connect(this, SIGNAL(pointsChanged(const QPolygonF &)), 00051 m_widget, SLOT(update())); 00052 }
Here is the call graph for this function:

Filters events if this object has been installed as an event filter for the watched object.
In your reimplementation of this function, if you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false.
Example:
class MainWindow : public QMainWindow { public: MainWindow(); protected: bool eventFilter(QObject *obj, QEvent *ev); private: QTextEdit *textEdit; }; MainWindow::MainWindow() { textEdit = new QTextEdit; setCentralWidget(textEdit); textEdit->installEventFilter(this); } bool MainWindow::eventFilter(QObject *obj, QEvent *event) { if (obj == textEdit) { if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); qDebug() << "Ate key press" << keyEvent->key(); return true; } else { return false; } } else { // pass the event on to the parent class return QMainWindow::eventFilter(obj, event); } }
Notice in the example above that unhandled events are passed to the base class's eventFilter() function, since the base class might have reimplemented eventFilter() for its own internal purposes.
Reimplemented from QObject.
Definition at line 64 of file hoverpoints.cpp.
References QVector< T >::at(), CircleShape, QObject::event(), firePointChange(), QSize::height(), i, index, QVector< T >::insert(), Qt::LeftButton, m_currentIndex, m_editable, m_enabled, m_locks, m_points, m_shape, m_sortType, m_widget, QEvent::MouseButtonPress, QEvent::MouseButtonRelease, QEvent::MouseMove, movePoint(), object, QResizeEvent::oldSize(), p, QEvent::Paint, paintPoints(), path, pointBoundingRect(), QVector< T >::remove(), QEvent::Resize, Qt::RightButton, QCoreApplication::sendEvent(), QResizeEvent::size(), QVector< T >::size(), QSize::width(), QPointF::x(), XSort, QPointF::y(), and YSort.
00065 { 00066 if (object == m_widget && m_enabled) { 00067 switch (event->type()) { 00068 00069 case QEvent::MouseButtonPress: 00070 { 00071 QMouseEvent *me = (QMouseEvent *) event; 00072 00073 QPointF clickPos = me->pos(); 00074 int index = -1; 00075 for (int i=0; i<m_points.size(); ++i) { 00076 QPainterPath path; 00077 if (m_shape == CircleShape) 00078 path.addEllipse(pointBoundingRect(i)); 00079 else 00080 path.addRect(pointBoundingRect(i)); 00081 00082 if (path.contains(clickPos)) { 00083 index = i; 00084 break; 00085 } 00086 } 00087 00088 if (me->button() == Qt::LeftButton) { 00089 if (index == -1) { 00090 if (!m_editable) 00091 return false; 00092 int pos = 0; 00093 // Insert sort for x or y 00094 if (m_sortType == XSort) { 00095 for (int i=0; i<m_points.size(); ++i) 00096 if (m_points.at(i).x() > clickPos.x()) { 00097 pos = i; 00098 break; 00099 } 00100 } else if (m_sortType == YSort) { 00101 for (int i=0; i<m_points.size(); ++i) 00102 if (m_points.at(i).y() > clickPos.y()) { 00103 pos = i; 00104 break; 00105 } 00106 } 00107 00108 m_points.insert(pos, clickPos); 00109 m_locks.insert(pos, 0); 00110 m_currentIndex = pos; 00111 firePointChange(); 00112 } else { 00113 m_currentIndex = index; 00114 } 00115 return true; 00116 00117 } else if (me->button() == Qt::RightButton) { 00118 if (index >= 0 && m_editable) { 00119 if (m_locks[index] == 0) { 00120 m_locks.remove(index); 00121 m_points.remove(index); 00122 } 00123 firePointChange(); 00124 return true; 00125 } 00126 } 00127 00128 } 00129 break; 00130 00131 case QEvent::MouseButtonRelease: 00132 m_currentIndex = -1; 00133 break; 00134 00135 case QEvent::MouseMove: 00136 if (m_currentIndex >= 0) 00137 movePoint(m_currentIndex, ((QMouseEvent *)event)->pos()); 00138 break; 00139 00140 case QEvent::Resize: 00141 { 00142 QResizeEvent *e = (QResizeEvent *) event; 00143 if (e->oldSize().width() == 0 || e->oldSize().height() == 0) 00144 break; 00145 double stretch_x = e->size().width() / double(e->oldSize().width()); 00146 double stretch_y = e->size().height() / double(e->oldSize().height()); 00147 for (int i=0; i<m_points.size(); ++i) { 00148 QPointF p = m_points[i]; 00149 movePoint(i, QPointF(p.x() * stretch_x, p.y() * stretch_y), false); 00150 } 00151 00152 firePointChange(); 00153 break; 00154 } 00155 00156 case QEvent::Paint: 00157 { 00158 QWidget *that_widget = m_widget; 00159 m_widget = 0; 00160 QApplication::sendEvent(object, event); 00161 m_widget = that_widget; 00162 paintPoints(); 00163 #ifdef QT_OPENGL_SUPPORT 00164 ArthurFrame *af = qobject_cast<ArthurFrame *>(that_widget); 00165 if (af && af->usesOpenGL()) 00166 af->glWidget()->swapBuffers(); 00167 #endif 00168 return true; 00169 } 00170 default: 00171 break; 00172 } 00173 } 00174 00175 return false; 00176 }
Here is the call graph for this function:

| void HoverPoints::paintPoints | ( | ) |
Definition at line 179 of file hoverpoints.cpp.
References QPainter::Antialiasing, QVector< T >::at(), CircleShape, CurveConnection, i, m_connectionPen, m_connectionType, m_pointBrush, m_pointPen, m_points, m_shape, m_widget, NoConnection, Qt::NoPen, p, path, pointBoundingRect(), QVector< T >::size(), QPen::style(), QPointF::x(), and QPointF::y().
Referenced by eventFilter().
00180 { 00181 QPainter p; 00182 #ifdef QT_OPENGL_SUPPORT 00183 ArthurFrame *af = qobject_cast<ArthurFrame *>(m_widget); 00184 if (af && af->usesOpenGL()) 00185 p.begin(af->glWidget()); 00186 else 00187 p.begin(m_widget); 00188 #else 00189 p.begin(m_widget); 00190 #endif 00191 00192 p.setRenderHint(QPainter::Antialiasing); 00193 00194 if (m_connectionPen.style() != Qt::NoPen && m_connectionType != NoConnection) { 00195 p.setPen(m_connectionPen); 00196 00197 if (m_connectionType == CurveConnection) { 00198 QPainterPath path; 00199 path.moveTo(m_points.at(0)); 00200 for (int i=1; i<m_points.size(); ++i) { 00201 QPointF p1 = m_points.at(i-1); 00202 QPointF p2 = m_points.at(i); 00203 double distance = p2.x() - p1.x(); 00204 00205 path.cubicTo(p1.x() + distance / 2, p1.y(), 00206 p1.x() + distance / 2, p2.y(), 00207 p2.x(), p2.y()); 00208 } 00209 p.drawPath(path); 00210 } else { 00211 p.drawPolyline(m_points); 00212 } 00213 } 00214 00215 p.setPen(m_pointPen); 00216 p.setBrush(m_pointBrush); 00217 00218 for (int i=0; i<m_points.size(); ++i) { 00219 QRectF bounds = pointBoundingRect(i); 00220 if (m_shape == CircleShape) 00221 p.drawEllipse(bounds); 00222 else 00223 p.drawRect(bounds); 00224 } 00225 }
Here is the call graph for this function:

| QRectF HoverPoints::boundingRect | ( | ) | const [inline] |
Definition at line 134 of file hoverpoints.h.
References QRectF::isEmpty(), m_bounds, m_widget, and QWidget::rect().
Referenced by movePoint(), setBoundingRect(), and setPoints().
00135 { 00136 if (m_bounds.isEmpty()) 00137 return m_widget->rect(); 00138 else 00139 return m_bounds; 00140 }
Here is the call graph for this function:

| void HoverPoints::setBoundingRect | ( | const QRectF & | boundingRect | ) | [inline] |
Definition at line 66 of file hoverpoints.h.
References boundingRect(), and m_bounds.
Referenced by XFormView::resizeEvent(), and XFormView::XFormView().
00066 { m_bounds = boundingRect; }
Here is the call graph for this function:

| QPolygonF HoverPoints::points | ( | ) | const [inline] |
Definition at line 68 of file hoverpoints.h.
References m_points.
Referenced by ShadeWidget::colorAt(), GradientRenderer::paint(), ShadeWidget::points(), setPoints(), XFormView::setRotation(), and XFormView::timerEvent().
00068 { return m_points; }
| void HoverPoints::setPoints | ( | const QPolygonF & | points | ) |
Definition at line 245 of file hoverpoints.cpp.
References QVector< T >::at(), bound_point(), boundingRect(), QVector< T >::clear(), QVector< T >::fill(), i, m_locks, m_points, points(), QVector< T >::resize(), and QVector< T >::size().
Referenced by GradientRenderer::GradientRenderer(), XFormView::reset(), set_shade_points(), GradientWidget::setDefault(), XFormView::setRotation(), ShadeWidget::ShadeWidget(), XFormView::timerEvent(), XFormView::updateCtrlPoints(), and XFormView::XFormView().
00246 { 00247 m_points.clear(); 00248 for (int i=0; i<points.size(); ++i) 00249 m_points << bound_point(points.at(i), boundingRect(), 0); 00250 00251 m_locks.clear(); 00252 if (m_points.size() > 0) { 00253 m_locks.resize(m_points.size()); 00254 00255 m_locks.fill(0); 00256 } 00257 }
Here is the call graph for this function:

| QSizeF HoverPoints::pointSize | ( | ) | const [inline] |
| void HoverPoints::setPointSize | ( | const QSizeF & | size | ) | [inline] |
Definition at line 72 of file hoverpoints.h.
References m_pointSize, and size.
Referenced by GradientRenderer::GradientRenderer(), and XFormView::XFormView().
00072 { m_pointSize = size; }
| SortType HoverPoints::sortType | ( | ) | const [inline] |
| void HoverPoints::setSortType | ( | SortType | sortType | ) | [inline] |
Definition at line 75 of file hoverpoints.h.
References m_sortType.
Referenced by ShadeWidget::ShadeWidget().
00075 { m_sortType = sortType; }
| ConnectionType HoverPoints::connectionType | ( | ) | const [inline] |
Definition at line 77 of file hoverpoints.h.
References m_connectionType.
00077 { return m_connectionType; }
| void HoverPoints::setConnectionType | ( | ConnectionType | connectionType | ) | [inline] |
Definition at line 78 of file hoverpoints.h.
References m_connectionType.
Referenced by GradientRenderer::GradientRenderer(), and XFormView::XFormView().
00078 { m_connectionType = connectionType; }
| void HoverPoints::setConnectionPen | ( | const QPen & | pen | ) | [inline] |
Definition at line 80 of file hoverpoints.h.
References m_connectionPen.
Referenced by XFormView::XFormView().
00080 { m_connectionPen = pen; }
| void HoverPoints::setShapePen | ( | const QPen & | pen | ) | [inline] |
Definition at line 81 of file hoverpoints.h.
References m_pointPen.
Referenced by XFormView::XFormView().
00081 { m_pointPen = pen; }
| void HoverPoints::setShapeBrush | ( | const QBrush & | brush | ) | [inline] |
Definition at line 82 of file hoverpoints.h.
References m_pointBrush.
Referenced by XFormView::XFormView().
00082 { m_pointBrush = brush; }
| void HoverPoints::setPointLock | ( | int | pos, | |
| LockType | lock | |||
| ) | [inline] |
Definition at line 84 of file hoverpoints.h.
References m_locks.
Referenced by set_shade_points(), and ShadeWidget::ShadeWidget().
00084 { m_locks[pos] = lock; }
| void HoverPoints::setEditable | ( | bool | editable | ) | [inline] |
Definition at line 86 of file hoverpoints.h.
References m_editable.
Referenced by GradientRenderer::GradientRenderer(), and XFormView::XFormView().
00086 { m_editable = editable; }
| bool HoverPoints::editable | ( | ) | const [inline] |
| void HoverPoints::setEnabled | ( | bool | enabled | ) | [slot] |
Definition at line 55 of file hoverpoints.cpp.
References m_enabled, m_widget, and QWidget::update().
Referenced by setDisabled().
00056 { 00057 if (m_enabled != enabled) { 00058 m_enabled = enabled; 00059 m_widget->update(); 00060 } 00061 }
| void HoverPoints::setDisabled | ( | bool | disabled | ) | [inline, slot] |
Definition at line 91 of file hoverpoints.h.
References setEnabled().
00091 { setEnabled(!disabled); }
| void HoverPoints::pointsChanged | ( | const QPolygonF & | points | ) | [signal] |
Referenced by firePointChange(), and HoverPoints().
| void HoverPoints::firePointChange | ( | ) |
Definition at line 279 of file hoverpoints.cpp.
References QVector< T >::begin(), emit, QVector< T >::end(), i, m_currentIndex, m_points, m_sortType, NoSort, pointsChanged(), qSort(), QVector< T >::size(), x_less_than(), XSort, y_less_than(), and YSort.
Referenced by eventFilter(), movePoint(), XFormView::reset(), and XFormView::timerEvent().
00280 { 00281 // printf("HoverPoints::firePointChange(), current=%d\n", m_currentIndex); 00282 00283 if (m_sortType != NoSort) { 00284 00285 QPointF oldCurrent; 00286 if (m_currentIndex != -1) { 00287 oldCurrent = m_points[m_currentIndex]; 00288 } 00289 00290 if (m_sortType == XSort) 00291 qSort(m_points.begin(), m_points.end(), x_less_than); 00292 else if (m_sortType == YSort) 00293 qSort(m_points.begin(), m_points.end(), y_less_than); 00294 00295 // Compensate for changed order... 00296 if (m_currentIndex != -1) { 00297 for (int i=0; i<m_points.size(); ++i) { 00298 if (m_points[i] == oldCurrent) { 00299 m_currentIndex = i; 00300 break; 00301 } 00302 } 00303 } 00304 00305 // printf(" - firePointChange(), current=%d\n", m_currentIndex); 00306 00307 } 00308 00309 // for (int i=0; i<m_points.size(); ++i) { 00310 // printf(" - point(%2d)=[%.2f, %.2f], lock=%d\n", 00311 // i, m_points.at(i).x(), m_points.at(i).y(), m_locks.at(i)); 00312 // } 00313 00314 emit pointsChanged(m_points); 00315 }
Here is the call graph for this function:

| QRectF HoverPoints::pointBoundingRect | ( | int | i | ) | const [inline, private] |
Definition at line 124 of file hoverpoints.h.
References QVector< T >::at(), h, QSizeF::height(), m_points, m_pointSize, p, w, QSizeF::width(), x, and y.
Referenced by eventFilter(), and paintPoints().
00125 { 00126 QPointF p = m_points.at(i); 00127 double w = m_pointSize.width(); 00128 double h = m_pointSize.height(); 00129 double x = p.x() - w / 2; 00130 double y = p.y() - h / 2; 00131 return QRectF(x, y, w, h); 00132 }
Here is the call graph for this function:

| void HoverPoints::movePoint | ( | int | i, | |
| const QPointF & | newPos, | |||
| bool | emitChange = true | |||
| ) | [private] |
Definition at line 260 of file hoverpoints.cpp.
References QVector< T >::at(), bound_point(), boundingRect(), firePointChange(), m_locks, and m_points.
Referenced by eventFilter().
00261 { 00262 m_points[index] = bound_point(point, boundingRect(), m_locks.at(index)); 00263 if (emitUpdate) 00264 firePointChange(); 00265 }
Here is the call graph for this function:

QWidget* HoverPoints::m_widget [private] |
Definition at line 103 of file hoverpoints.h.
Referenced by boundingRect(), eventFilter(), HoverPoints(), paintPoints(), and setEnabled().
QPolygonF HoverPoints::m_points [private] |
Definition at line 105 of file hoverpoints.h.
Referenced by eventFilter(), firePointChange(), movePoint(), paintPoints(), pointBoundingRect(), points(), and setPoints().
QRectF HoverPoints::m_bounds [private] |
PointShape HoverPoints::m_shape [private] |
Definition at line 107 of file hoverpoints.h.
Referenced by eventFilter(), HoverPoints(), and paintPoints().
SortType HoverPoints::m_sortType [private] |
Definition at line 108 of file hoverpoints.h.
Referenced by eventFilter(), firePointChange(), HoverPoints(), setSortType(), and sortType().
ConnectionType HoverPoints::m_connectionType [private] |
Definition at line 109 of file hoverpoints.h.
Referenced by connectionType(), HoverPoints(), paintPoints(), and setConnectionType().
QVector<uint> HoverPoints::m_locks [private] |
Definition at line 111 of file hoverpoints.h.
Referenced by eventFilter(), movePoint(), setPointLock(), and setPoints().
QSizeF HoverPoints::m_pointSize [private] |
Definition at line 113 of file hoverpoints.h.
Referenced by HoverPoints(), pointBoundingRect(), pointSize(), and setPointSize().
int HoverPoints::m_currentIndex [private] |
Definition at line 114 of file hoverpoints.h.
Referenced by eventFilter(), firePointChange(), and HoverPoints().
bool HoverPoints::m_editable [private] |
Definition at line 115 of file hoverpoints.h.
Referenced by editable(), eventFilter(), HoverPoints(), and setEditable().
bool HoverPoints::m_enabled [private] |
Definition at line 116 of file hoverpoints.h.
Referenced by eventFilter(), HoverPoints(), and setEnabled().
QPen HoverPoints::m_pointPen [private] |
Definition at line 118 of file hoverpoints.h.
Referenced by HoverPoints(), paintPoints(), and setShapePen().
QBrush HoverPoints::m_pointBrush [private] |
Definition at line 119 of file hoverpoints.h.
Referenced by HoverPoints(), paintPoints(), and setShapeBrush().
QPen HoverPoints::m_connectionPen [private] |
Definition at line 120 of file hoverpoints.h.
Referenced by HoverPoints(), paintPoints(), and setConnectionPen().
1.5.1