26#include <tdeapplication.h>
29#include "basicelement.h"
30#include "formulacursor.h"
31#include "formulaelement.h"
32#include "kformulacontainer.h"
33#include "kformuladocument.h"
34#include "kformulaview.h"
36KFORMULA_NAMESPACE_BEGIN
38struct View::View_Impl {
41 : smallCursor(false), activeCursor(true), cursorHasChanged(true),
44 connect(document, TQ_SIGNAL(elementWillVanish(
BasicElement*)),
51 cursor = document->createCursor();
52 blinkTimer =
new TQTimer( view );
53 connect( blinkTimer, TQ_SIGNAL( timeout() ),
55 if ( TQApplication::cursorFlashTime() > 0 )
56 blinkTimer->start( TQApplication::cursorFlashTime() / 2 );
61 if ( TQApplication::cursorFlashTime() > 0 )
62 blinkTimer->start( TQApplication::cursorFlashTime() / 2 );
72 if ( document->activeCursor() == cursor ) {
73 document->setActiveCursor( 0 );
93 bool cursorHasChanged;
113bool& View::cursorHasChanged() {
return impl->cursorHasChanged; }
114bool& View::smallCursor() {
return impl->smallCursor; }
115bool& View::activeCursor() {
return impl->activeCursor; }
116Container* View::container()
const {
return impl->document; }
117void View::startCursorTimer() { impl->startTimer(); }
118void View::stopCursorTimer() { impl->stopTimer(); }
123 impl =
new View_Impl(doc,
this);
135 return contextStyle().layoutUnitToPixel( cursor()->
getCursorPoint() );
144void View::calcCursor()
150void View::draw(TQPainter& painter,
const TQRect& rect,
const TQColorGroup& cg)
154 container()->
draw( painter, rect, cg,
true );
155 if ( cursorVisible() ) {
156 StyleAttributes style;
157 cursor()->
draw( painter, contextStyle(), style, smallCursor(), activeCursor() );
161void View::draw(TQPainter& painter,
const TQRect& rect)
163 container()->
draw( painter, rect,
true );
164 if ( cursorVisible() ) {
165 StyleAttributes style;
166 cursor()->
draw( painter, contextStyle(), style, smallCursor(), activeCursor() );
170void View::keyPressEvent( TQKeyEvent* event )
172 container()->
input( event );
176void View::focusInEvent(TQFocusEvent*)
180 activeCursor() =
true;
182 smallCursor() =
false;
186void View::focusOutEvent(TQFocusEvent*)
189 activeCursor() =
false;
191 smallCursor() =
true;
195void View::mousePressEvent( TQMouseEvent* event )
198 mousePressEvent( event, context.pixelToLayoutUnit( event->pos() ) );
201void View::mouseReleaseEvent( TQMouseEvent* event )
204 mouseReleaseEvent( event, context.pixelToLayoutUnit( event->pos() ) );
207void View::mouseDoubleClickEvent( TQMouseEvent* event )
210 mouseDoubleClickEvent( event, context.pixelToLayoutUnit( event->pos() ) );
213void View::mouseMoveEvent( TQMouseEvent* event )
216 mouseMoveEvent( event, context.pixelToLayoutUnit( event->pos() ) );
219void View::wheelEvent( TQWheelEvent* event )
222 wheelEvent( event, context.pixelToLayoutUnit( event->pos() ) );
225void View::mousePressEvent( TQMouseEvent* event,
const PtPoint& pos )
228 mousePressEvent( event, context.ptToLayoutUnitPix( pos ) );
231void View::mouseReleaseEvent( TQMouseEvent* event,
const PtPoint& pos )
234 mouseReleaseEvent( event, context.ptToLayoutUnitPix( pos ) );
237void View::mouseDoubleClickEvent( TQMouseEvent* event,
const PtPoint& pos )
240 mouseDoubleClickEvent( event, context.ptToLayoutUnitPix( pos ) );
243void View::mouseMoveEvent( TQMouseEvent* event,
const PtPoint& pos )
246 mouseMoveEvent( event, context.ptToLayoutUnitPix( pos ) );
249void View::wheelEvent( TQWheelEvent* event,
const PtPoint& pos )
252 wheelEvent( event, context.ptToLayoutUnitPix( pos ) );
256void View::mousePressEvent( TQMouseEvent* event,
const LuPixelPoint& pos )
258 int flags = movementFlag( event->state() );
259 cursor()->mousePress( pos, flags );
263void View::mouseReleaseEvent( TQMouseEvent* event,
const LuPixelPoint& pos )
265 int flags = movementFlag( event->state() );
266 cursor()->mouseRelease( pos, flags );
270void View::mouseDoubleClickEvent( TQMouseEvent*,
const LuPixelPoint& )
272 cursor()->moveRight( WordMovement );
273 cursor()->moveLeft( SelectMovement | WordMovement );
277void View::mouseMoveEvent( TQMouseEvent* event,
const LuPixelPoint& pos )
279 int flags = movementFlag( event->state() );
280 cursor()->mouseMove( pos, flags );
284void View::wheelEvent( TQWheelEvent*,
const LuPixelPoint& )
292 cursorHasChanged() =
true;
310 activeCursor() = ! activeCursor();
314void View::slotSelectAll()
316 cursor()->moveHome(WordMovement);
317 cursor()->moveEnd(SelectMovement | WordMovement);
322void View::moveLeft(
int flag )
324 cursor()->moveLeft( flag );
328void View::moveRight(
int flag )
330 cursor()->moveRight( flag );
334void View::moveUp(
int flag )
336 cursor()->moveUp( flag );
340void View::moveDown(
int flag )
342 cursor()->moveDown( flag );
347void View::moveHome(
int flag )
349 cursor()->moveHome( flag );
353void View::moveEnd(
int flag )
355 cursor()->moveEnd( flag );
360void View::setSmallCursor(
bool small)
362 smallCursor() = small;
367 return cursor()->
isHome();
372 return cursor()->
isEnd();
375void View::eraseSelection( Direction direction )
377 DirectedRemove r( req_remove, direction );
378 container()->performRequest( &r );
381void View::addText( TQString str )
383 TextRequest r( str );
384 container()->performRequest( &r );
387void View::emitCursorChanged()
389 if (cursor()->hasChanged() || cursorHasChanged()) {
392 cursorHasChanged() =
false;
394 activeCursor() =
true;
397 emit
cursorChanged(cursorVisible(), cursor()->isSelection());
405bool View::cursorVisible()
410KFORMULA_NAMESPACE_END
412using namespace KFormula;
413#include "kformulaview.moc"
Basis of every formula element.
virtual Document * document() const
void setActiveCursor(FormulaCursor *cursor)
Sets the cursor that is to be used for any editing.
void updateMatrixActions()
If the cursor is in a matrix, the matrix actions will be enabled, otherwise disabled.
void input(TQKeyEvent *event)
General input.
void draw(TQPainter &painter, const TQRect &r, const TQColorGroup &cg, bool edit=false)
Draws the whole thing.
Contains all the style information for the formela.
ContextStyle & getContextStyle(bool edit=false)
A point whose coordinates are floating-point values ( "double"s ).
The view that shows the formula.
void cursorChanged(bool visible, bool selecting)
Is emitted every time the cursor might have changed.
TQPoint getCursorPoint() const
void slotElementWillVanish(BasicElement *)
There is an element that will disappear from the tree.
void slotFormulaLoaded(FormulaElement *)
A new formula has been loaded.
void slotBlinkCursor()
Tell the cursor to change its visibility status.
void setReadOnly(bool ro)
Puts the widget in read only mode.
virtual Container * getDocument() const
The document we show.
void slotCursorMoved(FormulaCursor *cursor)
The cursor has been moved by the container.