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 {
40 View_Impl(Container* doc, View* view)
41 : smallCursor(false), activeCursor(true), cursorHasChanged(true),
44 connect(document, TQ_SIGNAL(elementWillVanish(BasicElement*)),
46 connect(document, TQ_SIGNAL(formulaLoaded(FormulaElement*)),
48 connect(document, TQ_SIGNAL(cursorMoved(FormulaCursor*)),
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;
108 FormulaCursor* cursor;
113bool& View::cursorHasChanged() {
return impl->cursorHasChanged; }
114bool& View::smallCursor() {
return impl->smallCursor; }
115bool& View::activeCursor() {
return impl->activeCursor; }
117void View::startCursorTimer() { impl->startTimer(); }
118void View::stopCursorTimer() { impl->stopTimer(); }
123 impl =
new View_Impl(doc,
this);
124 cursor()->calcCursorSize( contextStyle(), smallCursor() );
135 return contextStyle().layoutUnitToPixel( cursor()->
getCursorPoint() );
140 cursor()->setReadOnly(ro);
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*)
179 container()->setActiveCursor(cursor());
180 activeCursor() =
true;
182 smallCursor() =
false;
186void View::focusOutEvent(TQFocusEvent*)
189 activeCursor() =
false;
191 smallCursor() =
true;
195void View::mousePressEvent( TQMouseEvent* event )
197 const ContextStyle& context = contextStyle();
198 mousePressEvent( event, context.pixelToLayoutUnit( event->pos() ) );
201void View::mouseReleaseEvent( TQMouseEvent* event )
203 const ContextStyle& context = contextStyle();
204 mouseReleaseEvent( event, context.pixelToLayoutUnit( event->pos() ) );
207void View::mouseDoubleClickEvent( TQMouseEvent* event )
209 const ContextStyle& context = contextStyle();
210 mouseDoubleClickEvent( event, context.pixelToLayoutUnit( event->pos() ) );
213void View::mouseMoveEvent( TQMouseEvent* event )
215 const ContextStyle& context = contextStyle();
216 mouseMoveEvent( event, context.pixelToLayoutUnit( event->pos() ) );
219void View::wheelEvent( TQWheelEvent* event )
221 const ContextStyle& context = contextStyle();
222 wheelEvent( event, context.pixelToLayoutUnit( event->pos() ) );
225void View::mousePressEvent( TQMouseEvent* event,
const PtPoint& pos )
227 const ContextStyle& context = contextStyle();
228 mousePressEvent( event, context.ptToLayoutUnitPix( pos ) );
231void View::mouseReleaseEvent( TQMouseEvent* event,
const PtPoint& pos )
233 const ContextStyle& context = contextStyle();
234 mouseReleaseEvent( event, context.ptToLayoutUnitPix( pos ) );
237void View::mouseDoubleClickEvent( TQMouseEvent* event,
const PtPoint& pos )
239 const ContextStyle& context = contextStyle();
240 mouseDoubleClickEvent( event, context.ptToLayoutUnitPix( pos ) );
243void View::mouseMoveEvent( TQMouseEvent* event,
const PtPoint& pos )
245 const ContextStyle& context = contextStyle();
246 mouseMoveEvent( event, context.ptToLayoutUnitPix( pos ) );
249void View::wheelEvent( TQWheelEvent* event,
const PtPoint& pos )
251 const ContextStyle& context = contextStyle();
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;
299 cursor()->formulaLoaded(formula);
304 cursor()->elementWillVanish(element);
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()) {
391 cursor()->clearChangedFlag();
392 cursorHasChanged() =
false;
393 cursor()->calcCursorSize( contextStyle(), smallCursor() );
394 activeCursor() =
true;
397 emit
cursorChanged(cursorVisible(), cursor()->isSelection());
402 return container()->document()->getContextStyle();
405bool View::cursorVisible()
407 return !cursor()->isReadOnly() || cursor()->isSelection();
410KFORMULA_NAMESPACE_END
412using namespace KFormula;
413#include "kformulaview.moc"
Basis of every formula element.
virtual Document * document() const
void updateMatrixActions()
If the cursor is in a matrix, the matrix actions will be enabled, otherwise disabled.
Contains all the style information for the formela.
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.