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 <kdebug.h>
26//#include <tdelocale.h>
27//#include <kstdaction.h>
28
29#include "basicelement.h"
30#include "formulacursor.h"
31#include "formulaelement.h"
32#include "kformulacontainer.h"
33#include "kformuladocument.h"
34#include "kformulawidget.h"
35
36
37KFormulaWidget::KFormulaWidget(Container* doc, TQWidget* parent, const char* name, WFlags f)
38 : TQWidget(parent, name, f | WRepaintNoErase | WResizeNoErase),
39 formulaView(doc)
40{
41 connect(doc, TQ_SIGNAL(formulaChanged(int, int)),
42 this, TQ_SLOT(slotFormulaChanged(int, int)));
43 connect(&formulaView, TQ_SIGNAL(cursorChanged(bool, bool)),
44 this, TQ_SLOT(slotCursorChanged(bool, bool)));
45
46 setFocusPolicy(TQWidget::StrongFocus);
47 setBackgroundMode(NoBackground/*TQWidget::PaletteBase*/);
48
49 TQRect rect = doc->boundingRect();
50 slotFormulaChanged(rect.width(), rect.height());
51}
52
53KFormulaWidget::~KFormulaWidget()
54{
55}
56
57
59{
60 return formulaView.getCursorPoint();
61}
62
64{
65 formulaView.setReadOnly(ro);
66}
67
68
69void KFormulaWidget::paintEvent(TQPaintEvent* event)
70{
71 // Always repaint the buffer. This is not so much more work
72 // than it seems to be as each cursor movement requires a repaint.
73 TQPainter p( &buffer );
74 //p.translate( -fr.x(), -fr.y() );
75 formulaView.draw( p, event->rect(), colorGroup() );
76
77 TQPainter painter;
78 painter.begin(this);
79 painter.drawPixmap( event->rect().x(), event->rect().y(),
80 buffer, event->rect().x(), event->rect().y(), event->rect().width(), event->rect().height() );
81 painter.end();
82}
83
84void KFormulaWidget::keyPressEvent(TQKeyEvent* event)
85{
86 formulaView.keyPressEvent(event);
87}
88
89
90void KFormulaWidget::focusInEvent(TQFocusEvent* event)
91{
92 formulaView.focusInEvent(event);
93}
94
95void KFormulaWidget::focusOutEvent(TQFocusEvent* event)
96{
97 formulaView.focusOutEvent(event);
98}
99
100void KFormulaWidget::mousePressEvent(TQMouseEvent* event)
101{
102 formulaView.mousePressEvent(event);
103}
104
105void KFormulaWidget::mouseReleaseEvent(TQMouseEvent* event)
106{
107 formulaView.mouseReleaseEvent(event);
108}
109
110void KFormulaWidget::mouseDoubleClickEvent(TQMouseEvent* event)
111{
112 formulaView.mouseDoubleClickEvent(event);
113}
114
115void KFormulaWidget::mouseMoveEvent(TQMouseEvent* event)
116{
117 formulaView.mouseMoveEvent(event);
118}
119
120void KFormulaWidget::wheelEvent(TQWheelEvent* event)
121{
122 formulaView.wheelEvent(event);
123}
124
125void KFormulaWidget::slotFormulaChanged(int width, int height)
126{
127 // Magic numbers just to see the cursor.
128 resize(width + 5, height + 5);
129 buffer.resize(width + 5, height + 5);
130 // repaint is needed even if the size doesn't change.
131 //update();
132}
133
138{
139 return formulaView.getDocument();
140}
141
146{
147 return formulaView.getCursor();
148}
149
150
151void KFormulaWidget::slotSelectAll()
152{
153 formulaView.slotSelectAll();
154}
155
156void KFormulaWidget::slotCursorChanged(bool visible, bool selecting)
157{
158 emit cursorChanged(visible, selecting);
159// kdDebug( 40000 ) << "KFormulaWidget::slotCursorChanged "
160// << formulaView.getDirtyArea().x() << " "
161// << formulaView.getDirtyArea().y() << " "
162// << formulaView.getDirtyArea().width() << " "
163// << formulaView.getDirtyArea().height() << " "
164// << endl;
165 // sadly this doesn't work
166 //update(formulaView.getDirtyArea());
167 update();
168}
169
170#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)