24#include <tqpopupmenu.h>
25#include <tqtextedit.h>
30#include <kiconloader.h>
32#include <kstdaction.h>
36#include <kformulacontainer.h>
37#include <kformuladocument.h>
39#include "formulastring.h"
42#include "kformula_doc.h"
43#include "kformula_factory.h"
44#include "kformula_view.h"
45#include "kformula_view_iface.h"
46#include "kformulawidget.h"
49bool KFormulaPartView::first_window =
true;
51KFormulaPartView::KFormulaPartView(
KFormulaDoc* _doc, TQWidget* _parent,
const char* _name)
52 : KoView( _doc, _parent, _name ), m_pDoc(_doc)
54 setInstance(KFormulaFactory::global());
55 if ( !_doc->isReadWrite() )
56 setXMLFile(
"kformula_readonly.rc");
58 setXMLFile(
"kformula.rc");
63 scrollview =
new TQScrollView(
this,
"scrollview");
64 formulaWidget =
new KFormulaWidget(_doc->getFormula(), scrollview->viewport(),
"formulaWidget");
65 scrollview->addChild(formulaWidget);
67 scrollview->viewport()->setFocusProxy( scrollview );
68 scrollview->viewport()->setFocusPolicy( TQWidget::WheelFocus );
69 scrollview->setFocusPolicy( TQWidget::NoFocus );
70 formulaWidget->setFocus();
73 formulaWidget->setReadOnly(
true);
75 KFormula::Container* formula = m_pDoc->getFormula();
76 KFormula::Document* document = m_pDoc->getDocument();
79 cutAction = KStdAction::cut(document->wrapper(), TQ_SLOT(cut()), actionCollection());
80 copyAction = KStdAction::copy(document->wrapper(), TQ_SLOT(copy()), actionCollection());
81 pasteAction = KStdAction::paste(document->wrapper(), TQ_SLOT(paste()), actionCollection());
82 cutAction->setEnabled(
false);
83 copyAction->setEnabled(
false);
86 KStdAction::tipOfDay(
this, TQ_SLOT( slotShowTip() ), actionCollection() );
89 addBracketAction = document->wrapper()->getAddBracketAction();
90 addFractionAction = document->wrapper()->getAddFractionAction();
91 addRootAction = document->wrapper()->getAddRootAction();
92 addSumAction = document->wrapper()->getAddSumAction();
93 addProductAction = document->wrapper()->getAddProductAction();
94 addIntegralAction = document->wrapper()->getAddIntegralAction();
95 addMatrixAction = document->wrapper()->getAddMatrixAction();
96 addUpperLeftAction = document->wrapper()->getAddUpperLeftAction();
97 addLowerLeftAction = document->wrapper()->getAddLowerLeftAction();
98 addUpperRightAction = document->wrapper()->getAddUpperRightAction();
99 addLowerRightAction = document->wrapper()->getAddLowerRightAction();
100 addGenericUpperAction = document->wrapper()->getAddGenericUpperAction();
101 addGenericLowerAction = document->wrapper()->getAddGenericLowerAction();
102 removeEnclosingAction = document->wrapper()->getRemoveEnclosingAction();
104 (void) KStdAction::selectAll(formulaWidget, TQ_SLOT(slotSelectAll()), actionCollection());
107 KStdAction::preferences(
this, TQ_SLOT(configure()), actionCollection(),
"configure" );
114 TDEFontSizeAction* actionTextSize =
new TDEFontSizeAction(i18n(
"Size" ),0,
115 actionCollection(),
"formula_textsize");
116 actionTextSize->setFontSize( m_pDoc->getFormula()->fontSize() );
118 connect( actionTextSize, TQ_SIGNAL( fontSizeChanged(
int ) ),
this, TQ_SLOT( sizeSelected(
int ) ) );
119 connect( formula, TQ_SIGNAL( baseSizeChanged(
int ) ), actionTextSize, TQ_SLOT( setFontSize(
int ) ) );
140 formulaStringAction =
new TDEAction( i18n(
"Edit Formula String..." ),
142 this, TQ_SLOT( formulaString() ),
143 actionCollection(),
"formula_formulastring" );
145 connect(formulaWidget, TQ_SIGNAL(cursorChanged(
bool,
bool)),
146 this, TQ_SLOT(cursorChanged(
bool,
bool)));
148 connect( formula, TQ_SIGNAL( statusMsg(
const TQString& ) ),
149 this, TQ_SLOT( slotActionStatusText(
const TQString& ) ) );
151 if ( !_doc->isEmbedded() && first_window ) {
152 TQTimer::singleShot( 200,
this, TQ_SLOT(slotShowTipOnStart()) );
153 first_window =
false;
158KFormulaPartView::~KFormulaPartView()
163DCOPObject* KFormulaPartView::dcopObject()
166 m_dcop =
new KformulaViewIface(
this );
172void KFormulaPartView::focusInEvent(TQFocusEvent*)
174 formulaWidget->setFocus();
177void KFormulaPartView::updateReadWrite(
bool readwrite)
180 setEnabled(readwrite);
183void KFormulaPartView::slotShowTipOnStart() {
184 KTipDialog::showTip(
this );
187void KFormulaPartView::slotShowTip() {
188 KTipDialog::showTip(
this, TQString(),
true );
192void KFormulaPartView::setEnabled(
bool enabled)
194 addBracketAction->setEnabled(enabled);
195 addFractionAction->setEnabled(enabled);
196 addRootAction->setEnabled(enabled);
197 addSumAction->setEnabled(enabled);
198 addIntegralAction->setEnabled(enabled);
199 addMatrixAction->setEnabled(enabled);
200 addUpperLeftAction->setEnabled(enabled);
201 addLowerLeftAction->setEnabled(enabled);
202 addUpperRightAction->setEnabled(enabled);
203 addLowerRightAction->setEnabled(enabled);
204 addGenericUpperAction->setEnabled(enabled);
205 addGenericLowerAction->setEnabled(enabled);
206 removeEnclosingAction->setEnabled(enabled);
209void KFormulaPartView::resizeEvent( TQResizeEvent * )
211 scrollview->setGeometry(0, 0, width(), height());
215void KFormulaPartView::setupPrinter(KPrinter&)
219void KFormulaPartView::print(KPrinter& printer)
221 m_pDoc->getFormula()->print(printer);
224const KFormula::View* KFormulaPartView::formulaView()
const {
return formulaWidget->view(); }
225KFormula::View* KFormulaPartView::formulaView() {
return formulaWidget->view(); }
227void KFormulaPartView::cursorChanged(
bool visible,
bool selecting)
229 cutAction->setEnabled(visible && selecting);
230 copyAction->setEnabled(visible && selecting);
232 removeEnclosingAction->setEnabled(!selecting);
237 scrollview->ensureVisible(x, y);
240 KFormula::Document* doc = document()->getDocument();
241 doc->wrapper()->getFormatBoldAction()->setEnabled( selecting );
242 doc->wrapper()->getFormatItalicAction()->setEnabled( selecting );
243 doc->wrapper()->getFontFamilyAction()->setEnabled( selecting );
245 doc->wrapper()->getFormatBoldAction()->setChecked(
false );
246 doc->wrapper()->getFormatItalicAction()->setChecked(
false );
247 doc->wrapper()->getFontFamilyAction()->setCurrentItem( 0 );
251void KFormulaPartView::formulaString()
253 FormulaString dia(
this );
254 dia.textWidget->setText( document()->getFormula()->formulaString() );
260void KFormulaPartView::sizeSelected(
int size )
262 document()->getFormula()->setFontSize( size );
263 formulaWidget->setFocus();
266TQStringList KFormulaPartView::readFormulaString( TQString text )
269 TQDomDocument formula = parser.parse();
270 TQStringList errorList = parser.errorList();
272 formulaView()->slotSelectAll();
273 document()->getFormula()->paste( formula, i18n(
"Read Formula String" ) );
278void KFormulaPartView::configure()
284#include "kformula_view.moc"