kformula

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
28#include <basicelement.h>
29#include <formulacursor.h>
30#include <formulaelement.h>
31#include <kformulacontainer.h>
32#include <kformuladocument.h>
33#include "kformulawidget.h"
34
35
36KFormulaWidget::KFormulaWidget(KFormula::Container* doc,
37 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::slotFormulaChanged(int width, int height)
121{
122 // Magic numbers just to see the cursor.
123 resize(width + 5, height + 5);
124 buffer.resize(width + 5, height + 5);
125 update();
126 //kdDebug( 40000 ) << "KFormulaWidget::slotFormulaChanged" << endl;
127}
128
132KFormula::Container* KFormulaWidget::getDocument()
133{
134 return formulaView.getDocument();
135}
136
140KFormula::FormulaCursor* KFormulaWidget::getCursor()
141{
142 return formulaView.getCursor();
143}
144
145
146void KFormulaWidget::slotSelectAll()
147{
148 formulaView.slotSelectAll();
149}
150
151void KFormulaWidget::slotCursorChanged(bool visible, bool selecting)
152{
153 emit cursorChanged(visible, selecting);
154 update();
155}
156
157#include "kformulawidget.moc"
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.
void slotFormulaChanged(int width, int height)
The formula has changed and needs to be redrawn.
KFormula::FormulaCursor * getCursor()
Our cursor.
KFormula::Container * getDocument()
The document we show.