lib

kformulawidget.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
3 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include <iostream>
22
23#include <tqpainter.h>
24
25#include <tdeapplication.h>
26#include <kdebug.h>
27//#include <tdelocale.h>
28//#include <kstdaction.h>
29
30#include "basicelement.h"
31#include "formulacursor.h"
32#include "formulaelement.h"
33#include "kformulacontainer.h"
34#include "kformuladocument.h"
35#include "kformulawidget.h"
36
37
38KFormulaWidget::KFormulaWidget(Container* doc, TQWidget* parent, const char* name, WFlags f)
39 : TQWidget(parent, name, f | WRepaintNoErase | WResizeNoErase),
40 formulaView(doc)
41{
42 connect(doc, TQ_SIGNAL(formulaChanged(int, int)),
43 this, TQ_SLOT(slotFormulaChanged(int, int)));
44 connect(&formulaView, TQ_SIGNAL(cursorChanged(bool, bool)),
45 this, TQ_SLOT(slotCursorChanged(bool, bool)));
46
47 setFocusPolicy(TQWidget::StrongFocus);
48 setBackgroundMode(NoBackground/*TQWidget::PaletteBase*/);
49
50 TQRect rect = doc->boundingRect();
51 slotFormulaChanged(rect.width(), rect.height());
52}
53
54KFormulaWidget::~KFormulaWidget()
55{
56}
57
58
60{
61 return formulaView.getCursorPoint();
62}
63
65{
66 formulaView.setReadOnly(ro);
67}
68
69
70void KFormulaWidget::paintEvent(TQPaintEvent* event)
71{
72 // Always repaint the buffer. This is not so much more work
73 // than it seems to be as each cursor movement requires a repaint.
74 TQPainter p( &buffer );
75 //p.translate( -fr.x(), -fr.y() );
76 formulaView.draw( p, event->rect(), colorGroup() );
77
78 TQPainter painter;
79 painter.begin(this);
80 painter.drawPixmap( event->rect().x(), event->rect().y(),
81 buffer, event->rect().x(), event->rect().y(), event->rect().width(), event->rect().height() );
82 painter.end();
83}
84
85void KFormulaWidget::keyPressEvent(TQKeyEvent* event)
86{
87 formulaView.keyPressEvent(event);
88}
89
90
91void KFormulaWidget::focusInEvent(TQFocusEvent* event)
92{
93 formulaView.focusInEvent(event);
94}
95
96void KFormulaWidget::focusOutEvent(TQFocusEvent* event)
97{
98 formulaView.focusOutEvent(event);
99}
100
101void KFormulaWidget::mousePressEvent(TQMouseEvent* event)
102{
103 formulaView.mousePressEvent(event);
104}
105
106void KFormulaWidget::mouseReleaseEvent(TQMouseEvent* event)
107{
108 formulaView.mouseReleaseEvent(event);
109}
110
111void KFormulaWidget::mouseDoubleClickEvent(TQMouseEvent* event)
112{
113 formulaView.mouseDoubleClickEvent(event);
114}
115
116void KFormulaWidget::mouseMoveEvent(TQMouseEvent* event)
117{
118 formulaView.mouseMoveEvent(event);
119}
120
121void KFormulaWidget::wheelEvent(TQWheelEvent* event)
122{
123 formulaView.wheelEvent(event);
124}
125
126void KFormulaWidget::slotFormulaChanged(int width, int height)
127{
128 // Magic numbers just to see the cursor.
129 resize(width + 5, height + 5);
130 buffer.resize(width + 5, height + 5);
131 // repaint is needed even if the size doesn't change.
132 //update();
133}
134
139{
140 return formulaView.getDocument();
141}
142
147{
148 return formulaView.getCursor();
149}
150
151
152void KFormulaWidget::slotSelectAll()
153{
154 formulaView.slotSelectAll();
155}
156
157void KFormulaWidget::slotCursorChanged(bool visible, bool selecting)
158{
159 emit cursorChanged(visible, selecting);
160// kdDebug( 40000 ) << "KFormulaWidget::slotCursorChanged "
161// << formulaView.getDirtyArea().x() << " "
162// << formulaView.getDirtyArea().y() << " "
163// << formulaView.getDirtyArea().width() << " "
164// << formulaView.getDirtyArea().height() << " "
165// << endl;
166 // sadly this doesn't work
167 //update(formulaView.getDirtyArea());
168 update();
169}
170
171#include "kformulawidget.moc"
The document.
TQRect boundingRect() const
The selection.
void setReadOnly(bool ro)
Puts the widget in read only mode.
TQPoint getCursorPoint() const
void cursorChanged(bool visible, bool selecting)
Is emitted every time the cursor might have changed.
Container * getDocument()
The document we show.
void slotFormulaChanged(int width, int height)
The formula has changed and needs to be redrawn.
FormulaCursor * getCursor()
Our cursor.
const char * name(StdAction id)