20#include "KoContainerHandler.h"
26KoEventHandler::KoEventHandler( TQObject* target )
30 m_target->installEventFilter(
this );
33KoEventHandler::~KoEventHandler()
37TQObject* KoEventHandler::target()
44class KoPartResizeHandlerPrivate {
46 KoPartResizeHandlerPrivate(
const TQWMatrix& matrix, KoView *view, KoChild* child,
48 m_gadget(gadget), m_view(view), m_child(child), m_parentMatrix(matrix) {
51 m_matrix = child->
matrix() * matrix;
52 m_invertParentMatrix = matrix.invert();
55 m_invert = m_matrix.invert( &ok );
57 m_mouseStart = m_invert.map( m_invertParentMatrix.map( point ) );
59 ~KoPartResizeHandlerPrivate() {}
63 TQRect m_geometryStart;
68 TQWMatrix m_parentMatrix;
69 TQWMatrix m_invertParentMatrix;
72KoPartResizeHandler::KoPartResizeHandler( TQWidget* widget,
const TQWMatrix& matrix,
KoView* view,
KoChild* child,
77 d=
new KoPartResizeHandlerPrivate(matrix, view, child, gadget, point);
80KoPartResizeHandler::~KoPartResizeHandler()
87void KoPartResizeHandler::repaint(TQRegion &rgn)
89 rgn = rgn.unite( d->m_child->frameRegion( d->m_parentMatrix,
true ) );
91 ((TQWidget*)target())->repaint( rgn );
94bool KoPartResizeHandler::eventFilter( TQObject*, TQEvent* ev )
96 if ( ev->type() == TQEvent::MouseButtonRelease )
101 else if ( ev->type() == TQEvent::MouseMove )
103 TQMouseEvent* e = (TQMouseEvent*)ev;
104 TQPoint p = d->m_invert.map( d->m_invertParentMatrix.map( e->pos() ) );
105 TQRegion rgn( d->m_child->frameRegion( d->m_parentMatrix,
true ) );
107 double x1_x, x1_y, x2_x, x2_y;
108 d->m_matrix.map(
double( p.x() ), 0.0, &x1_x, &x1_y );
109 d->m_matrix.map(
double( d->m_mouseStart.x() ), 0.0, &x2_x, &x2_y );
110 double y1_x, y1_y, y2_x, y2_y;
111 d->m_matrix.map( 0.0,
double( p.y() ), &y1_x, &y1_y );
112 d->m_matrix.map( 0.0,
double( d->m_mouseStart.y() ), &y2_x, &y2_y );
114 double dx = x2_x - x1_x;
115 double dy = x2_y - x1_y;
116 int x = int( sqrt( dx * dx + dy * dy ) * ( d->m_mouseStart.x() < p.x() ? 1.0 : -1.0 ) );
120 int y = int( sqrt( dx * dx + dy * dy ) * ( d->m_mouseStart.y() < p.y() ? 1.0 : -1.0 ) );
122 switch( d->m_gadget )
124 case KoChild::TopLeft:
126 x = TQMIN( d->m_geometryStart.width() - 1, x );
127 y = TQMIN( d->m_geometryStart.height() - 1, y );
129 d->m_child->setGeometry( TQRect( d->m_geometryStart.x() + x, d->m_geometryStart.y() + y,
130 d->m_geometryStart.width() - x, d->m_geometryStart.height() - y ) );
134 case KoChild::TopMid:
136 y = TQMIN( d->m_geometryStart.height() - 1, y );
138 d->m_child->setGeometry( TQRect( d->m_geometryStart.x(), d->m_geometryStart.y() + y,
139 d->m_geometryStart.width(), d->m_geometryStart.height() - y ) );
143 case KoChild::TopRight:
145 x = TQMAX( -d->m_geometryStart.width() + 1, x );
146 y = TQMIN( d->m_geometryStart.height() - 1, y );
148 d->m_child->setGeometry( TQRect( d->m_geometryStart.x(), d->m_geometryStart.y() + y,
149 d->m_geometryStart.width() + x, d->m_geometryStart.height() - y ) );
153 case KoChild::MidLeft:
155 x = TQMIN( d->m_geometryStart.width() - 1, x );
157 d->m_child->setGeometry( TQRect( d->m_geometryStart.x() + x, d->m_geometryStart.y(),
158 d->m_geometryStart.width() - x, d->m_geometryStart.height() ) );
162 case KoChild::MidRight:
164 x = TQMAX( -d->m_geometryStart.width() + 1, x );
166 d->m_child->setGeometry( TQRect( d->m_geometryStart.x(), d->m_geometryStart.y(),
167 d->m_geometryStart.width() + x, d->m_geometryStart.height() ) );
171 case KoChild::BottomLeft:
173 x = TQMIN( d->m_geometryStart.width() - 1, x );
174 y = TQMAX( -d->m_geometryStart.height() + 1, y );
176 d->m_child->setGeometry( TQRect( d->m_geometryStart.x() + x, d->m_geometryStart.y(),
177 d->m_geometryStart.width() - x, d->m_geometryStart.height() + y ) );
181 case KoChild::BottomMid:
183 y = TQMAX( -d->m_geometryStart.height() + 1, y );
185 d->m_child->setGeometry( TQRect( d->m_geometryStart.x(), d->m_geometryStart.y(),
186 d->m_geometryStart.width(), d->m_geometryStart.height() + y ) );
190 case KoChild::BottomRight:
192 x = TQMAX( -d->m_geometryStart.width() + 1, x );
193 y = TQMAX( -d->m_geometryStart.height() + 1, y );
195 d->m_child->setGeometry( TQRect( d->m_geometryStart.x(), d->m_geometryStart.y(),
196 d->m_geometryStart.width() + x, d->m_geometryStart.height() + y ) );
210class KoPartMoveHandlerPrivate {
212 KoPartMoveHandlerPrivate(
const TQWMatrix& matrix, KoView* view, KoChild* child,
213 const TQPoint& point) : m_view(view), m_dragChild(child),
214 m_parentMatrix(matrix) {
215 m_invertParentMatrix = matrix.invert();
216 m_mouseDragStart = m_invertParentMatrix.map( point );
217 m_geometryDragStart = m_dragChild->geometry();
218 m_rotationDragStart = m_dragChild->rotationPoint();
220 ~KoPartMoveHandlerPrivate() {}
223 KoChild* m_dragChild;
224 TQPoint m_mouseDragStart;
225 TQRect m_geometryDragStart;
226 TQPoint m_rotationDragStart;
227 TQWMatrix m_invertParentMatrix;
228 TQWMatrix m_parentMatrix;
231KoPartMoveHandler::KoPartMoveHandler( TQWidget* widget,
const TQWMatrix& matrix,
KoView* view,
KoChild* child,
232 const TQPoint& point )
236 d=
new KoPartMoveHandlerPrivate(matrix, view, child, point);
239KoPartMoveHandler::~KoPartMoveHandler()
241 d->m_dragChild->unlock();
246bool KoPartMoveHandler::eventFilter( TQObject*, TQEvent* ev )
248 if ( ev->type() == TQEvent::MouseButtonRelease )
253 else if ( ev->type() == TQEvent::MouseMove )
255 TQMouseEvent* e = (TQMouseEvent*)ev;
257 TQRegion bound = d->m_dragChild->frameRegion( d->m_parentMatrix,
true );
258 TQPoint pos = d->m_invertParentMatrix.map( e->pos() );
259 d->m_dragChild->setGeometry( TQRect( d->m_geometryDragStart.x() + pos.x() - d->m_mouseDragStart.x(),
260 d->m_geometryDragStart.y() + pos.y() - d->m_mouseDragStart.y(),
261 d->m_geometryDragStart.width(), d->m_geometryDragStart.height() ) );
262 d->m_dragChild->setRotationPoint( TQPoint( d->m_rotationDragStart.x() + pos.x() - d->m_mouseDragStart.x(),
263 d->m_rotationDragStart.y() + pos.y() - d->m_mouseDragStart.y() ) );
264 bound = bound.unite( d->m_dragChild->frameRegion( d->m_parentMatrix,
false ) );
266 ((TQWidget*)target())->repaint( bound );
276KoContainerHandler::KoContainerHandler(
KoView* view, TQWidget* widget )
282KoContainerHandler::~KoContainerHandler()
286bool KoContainerHandler::eventFilter( TQObject*, TQEvent* ev )
288 if ( ev->type() == TQEvent::KeyPress )
290 TQKeyEvent* keyEvent=(TQKeyEvent*)ev;
292 KoChild* child=m_view->selectedChild();
296 if (keyEvent->key()==TQt::Key_Delete)
301 if ( ev->type() == TQEvent::MouseButtonPress )
305 TQMouseEvent *e=
static_cast<TQMouseEvent*
>(ev);
306 KoChild *ch=child(gadget, pos, e);
308 if ( e->button() == TQt::RightButton && gadget != KoChild::NoGadget )
313 else if ( e->button() == TQt::LeftButton && gadget == KoChild::Move )
315 (void)
new KoPartMoveHandler(
static_cast<TQWidget*
>(target()), m_view->matrix(), m_view, ch, pos );
318 else if ( e->button() == TQt::LeftButton && gadget != KoChild::NoGadget )
320 (void)
new KoPartResizeHandler(
static_cast<TQWidget*
>(target()), m_view->matrix(), m_view, ch, gadget, pos );
325 else if ( ev->type() == TQEvent::MouseMove )
327 TQWidget *targetWidget =
static_cast<TQWidget*
>( target() );
330 TQMouseEvent *e=
static_cast<TQMouseEvent*
>(ev);
331 child(gadget, pos, e);
334 if ( gadget == KoChild::NoGadget )
337 if ( gadget == KoChild::TopLeft || gadget == KoChild::BottomRight )
338 targetWidget->setCursor( sizeFDiagCursor );
339 else if ( gadget == KoChild::TopRight || gadget == KoChild::BottomLeft )
340 targetWidget->setCursor( sizeBDiagCursor );
341 else if ( gadget == KoChild::TopMid || gadget == KoChild::BottomMid )
342 targetWidget->setCursor( sizeVerCursor );
343 else if ( gadget == KoChild::MidLeft || gadget == KoChild::MidRight )
344 targetWidget->setCursor( sizeHorCursor );
345 else if ( gadget == KoChild::Move )
361 pos = m_view->reverseViewTransformations( pos );
364 KoDocumentChild* docChild = m_view->selectedChild();
365 gadget = KoChild::NoGadget;
368 KoViewChild *viewChild = m_view->child( docChild->
document() );
377 if ( gadget == KoChild::NoGadget )
379 docChild = m_view->activeChild();
382 KoViewChild *viewChild = m_view->child( docChild->
document() );
395#include "KoContainerHandler.moc"
static TQCursor handCursor()
KoChild is an abstract base class that represents the geometry associated with an embedded document.
virtual Gadget gadgetHitTest(const TQPoint &p)
Different actions are taken depending on where a child frame is hit.
void lock()
Locks this child and stores the current transformation.
virtual TQWMatrix matrix() const
Gadget
The gadget generally identifies where a child has been hit (generally by the mouse pointer).
void popupMenu(KoChild *, const TQPoint &global_pos)
Emitted if the user wants to open the popup menu for some child object.
void deleteChild(KoChild *)
Emitted if the user pressed the delete key whilst a child was selected.
KoDocument * document() const
An abstract base class for event handlers.
This class is used to display a KoDocument.