00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 class KPrinter;
00022
00023 #include <qpainter.h>
00024 #include <qpopupmenu.h>
00025 #include <qtextedit.h>
00026 #include <qtimer.h>
00027
00028 #include <kaction.h>
00029 #include <kdebug.h>
00030 #include <kiconloader.h>
00031 #include <klocale.h>
00032 #include <kstdaction.h>
00033 #include <ktip.h>
00034
00035
00036 #include <kformulacontainer.h>
00037 #include <kformuladocument.h>
00038
00039 #include "formulastring.h"
00040 #include "fsparser.h"
00041 #include "kfconfig.h"
00042 #include "kformula_doc.h"
00043 #include "kformula_factory.h"
00044 #include "kformula_view.h"
00045 #include "kformula_view_iface.h"
00046 #include "kformulawidget.h"
00047
00048
00049 bool KFormulaPartView::first_window = true;
00050
00051 KFormulaPartView::KFormulaPartView(KFormulaDoc* _doc, QWidget* _parent, const char* _name)
00052 : KoView( _doc, _parent, _name ), m_pDoc(_doc)
00053 {
00054 setInstance(KFormulaFactory::global());
00055 if ( !_doc->isReadWrite() )
00056 setXMLFile("kformula_readonly.rc");
00057 else
00058 setXMLFile("kformula.rc");
00059
00060 m_dcop = 0;
00061 dcopObject();
00062
00063 scrollview = new QScrollView(this, "scrollview");
00064 formulaWidget = new KFormulaWidget(_doc->getFormula(), scrollview->viewport(), "formulaWidget");
00065 scrollview->addChild(formulaWidget);
00066
00067 scrollview->viewport()->setFocusProxy( scrollview );
00068 scrollview->viewport()->setFocusPolicy( WheelFocus );
00069 scrollview->setFocusPolicy( NoFocus );
00070 formulaWidget->setFocus();
00071
00072
00073 formulaWidget->setReadOnly(true);
00074
00075 KFormula::Container* formula = m_pDoc->getFormula();
00076 KFormula::Document* document = m_pDoc->getDocument();
00077
00078
00079 cutAction = KStdAction::cut(document->wrapper(), SLOT(cut()), actionCollection());
00080 copyAction = KStdAction::copy(document->wrapper(), SLOT(copy()), actionCollection());
00081 pasteAction = KStdAction::paste(document->wrapper(), SLOT(paste()), actionCollection());
00082 cutAction->setEnabled(false);
00083 copyAction->setEnabled(false);
00084
00085
00086 KStdAction::tipOfDay( this, SLOT( slotShowTip() ), actionCollection() );
00087
00088
00089 addBracketAction = document->wrapper()->getAddBracketAction();
00090 addFractionAction = document->wrapper()->getAddFractionAction();
00091 addRootAction = document->wrapper()->getAddRootAction();
00092 addSumAction = document->wrapper()->getAddSumAction();
00093 addProductAction = document->wrapper()->getAddProductAction();
00094 addIntegralAction = document->wrapper()->getAddIntegralAction();
00095 addMatrixAction = document->wrapper()->getAddMatrixAction();
00096 addUpperLeftAction = document->wrapper()->getAddUpperLeftAction();
00097 addLowerLeftAction = document->wrapper()->getAddLowerLeftAction();
00098 addUpperRightAction = document->wrapper()->getAddUpperRightAction();
00099 addLowerRightAction = document->wrapper()->getAddLowerRightAction();
00100 addGenericUpperAction = document->wrapper()->getAddGenericUpperAction();
00101 addGenericLowerAction = document->wrapper()->getAddGenericLowerAction();
00102 removeEnclosingAction = document->wrapper()->getRemoveEnclosingAction();
00103
00104 (void) KStdAction::selectAll(formulaWidget, SLOT(slotSelectAll()), actionCollection());
00105
00106
00107 KStdAction::preferences( this, SLOT(configure()), actionCollection(), "configure" );
00108
00109
00110
00111
00112
00113
00114 KFontSizeAction* actionTextSize = new KFontSizeAction(i18n( "Size" ),0,
00115 actionCollection(),"formula_textsize");
00116 actionTextSize->setFontSize( m_pDoc->getFormula()->fontSize() );
00117
00118 connect( actionTextSize, SIGNAL( fontSizeChanged( int ) ), this, SLOT( sizeSelected( int ) ) );
00119 connect( formula, SIGNAL( baseSizeChanged( int ) ), actionTextSize, SLOT( setFontSize( int ) ) );
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 formulaStringAction = new KAction( i18n( "Edit Formula String..." ),
00141 0,
00142 this, SLOT( formulaString() ),
00143 actionCollection(), "formula_formulastring" );
00144
00145 connect(formulaWidget, SIGNAL(cursorChanged(bool, bool)),
00146 this, SLOT(cursorChanged(bool, bool)));
00147
00148 connect( formula, SIGNAL( statusMsg( const QString& ) ),
00149 this, SLOT( slotActionStatusText( const QString& ) ) );
00150
00151 if ( !_doc->isEmbedded() && first_window ) {
00152 QTimer::singleShot( 200, this, SLOT(slotShowTipOnStart()) );
00153 first_window = false;
00154 }
00155 }
00156
00157
00158 KFormulaPartView::~KFormulaPartView()
00159 {
00160 delete m_dcop;
00161 }
00162
00163 DCOPObject* KFormulaPartView::dcopObject()
00164 {
00165 if ( !m_dcop )
00166 m_dcop = new KformulaViewIface( this );
00167
00168 return m_dcop;
00169 }
00170
00171
00172 void KFormulaPartView::focusInEvent(QFocusEvent*)
00173 {
00174 formulaWidget->setFocus();
00175 }
00176
00177 void KFormulaPartView::updateReadWrite(bool readwrite)
00178 {
00179 formulaWidget->setReadOnly(!readwrite);
00180 setEnabled(readwrite);
00181 }
00182
00183 void KFormulaPartView::slotShowTipOnStart() {
00184 KTipDialog::showTip( this );
00185 }
00186
00187 void KFormulaPartView::slotShowTip() {
00188 KTipDialog::showTip( this, QString::null, true );
00189 }
00190
00191
00192 void KFormulaPartView::setEnabled(bool enabled)
00193 {
00194 addBracketAction->setEnabled(enabled);
00195 addFractionAction->setEnabled(enabled);
00196 addRootAction->setEnabled(enabled);
00197 addSumAction->setEnabled(enabled);
00198 addIntegralAction->setEnabled(enabled);
00199 addMatrixAction->setEnabled(enabled);
00200 addUpperLeftAction->setEnabled(enabled);
00201 addLowerLeftAction->setEnabled(enabled);
00202 addUpperRightAction->setEnabled(enabled);
00203 addLowerRightAction->setEnabled(enabled);
00204 addGenericUpperAction->setEnabled(enabled);
00205 addGenericLowerAction->setEnabled(enabled);
00206 removeEnclosingAction->setEnabled(enabled);
00207 }
00208
00209 void KFormulaPartView::resizeEvent( QResizeEvent * )
00210 {
00211 scrollview->setGeometry(0, 0, width(), height());
00212 }
00213
00214
00215 void KFormulaPartView::setupPrinter(KPrinter&)
00216 {
00217 }
00218
00219 void KFormulaPartView::print(KPrinter& printer)
00220 {
00221 m_pDoc->getFormula()->print(printer);
00222 }
00223
00224 const KFormula::View* KFormulaPartView::formulaView() const { return formulaWidget->view(); }
00225 KFormula::View* KFormulaPartView::formulaView() { return formulaWidget->view(); }
00226
00227 void KFormulaPartView::cursorChanged(bool visible, bool selecting)
00228 {
00229 cutAction->setEnabled(visible && selecting);
00230 copyAction->setEnabled(visible && selecting);
00231
00232 removeEnclosingAction->setEnabled(!selecting);
00233
00234 if (visible) {
00235 int x = formulaWidget->getCursorPoint().x();
00236 int y = formulaWidget->getCursorPoint().y();
00237 scrollview->ensureVisible(x, y);
00238 }
00239
00240 KFormula::Document* doc = document()->getDocument();
00241 doc->wrapper()->getFormatBoldAction()->setEnabled( selecting );
00242 doc->wrapper()->getFormatItalicAction()->setEnabled( selecting );
00243 doc->wrapper()->getFontFamilyAction()->setEnabled( selecting );
00244 if ( !selecting ) {
00245 doc->wrapper()->getFormatBoldAction()->setChecked( false );
00246 doc->wrapper()->getFormatItalicAction()->setChecked( false );
00247 doc->wrapper()->getFontFamilyAction()->setCurrentItem( 0 );
00248 }
00249 }
00250
00251 void KFormulaPartView::formulaString()
00252 {
00253 FormulaString dia( this );
00254 dia.textWidget->setText( document()->getFormula()->formulaString() );
00255 if ( dia.exec() ) {
00256
00257 }
00258 }
00259
00260 void KFormulaPartView::sizeSelected( int size )
00261 {
00262 document()->getFormula()->setFontSize( size );
00263 formulaWidget->setFocus();
00264 }
00265
00266 QStringList KFormulaPartView::readFormulaString( QString text )
00267 {
00268 FormulaStringParser parser( document()->getDocument()->getSymbolTable(), text );
00269 QDomDocument formula = parser.parse();
00270 QStringList errorList = parser.errorList();
00271
00272 formulaView()->slotSelectAll();
00273 document()->getFormula()->paste( formula, i18n( "Read Formula String" ) );
00274
00275 return errorList;
00276 }
00277
00278 void KFormulaPartView::configure()
00279 {
00280 KFConfig configDia( this );
00281 configDia.exec();
00282 }
00283
00284 #include "kformula_view.moc"