00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "KoSearchDia.h"
00023 #include "KoTextParag.h"
00024
00025 #include <KoGlobal.h>
00026 #include <KoTextObject.h>
00027 #include <KoTextView.h>
00028
00029 #include <kcolorbutton.h>
00030 #include <kcommand.h>
00031 #include <kdebug.h>
00032 #include <qfontcombobox.h>
00033 #include <klocale.h>
00034 #include <kseparator.h>
00035
00036 #include <q3buttongroup.h>
00037 #include <QCheckBox>
00038 #include <QComboBox>
00039 #include <QRadioButton>
00040 #include <QRegExp>
00041 #include <QSpinBox>
00042 #include <QLayout>
00043
00044 #include <Q3GridLayout>
00045 #include <Q3ValueList>
00046
00047 KoSearchContext::KoSearchContext()
00048 {
00049 m_family = "times";
00050 m_color = Qt::black;
00051 m_backGroundColor = Qt::black;
00052
00053 m_size = 12;
00054 m_vertAlign = KoTextFormat::AlignNormal;
00055 m_optionsMask = 0;
00056 m_options = KFind::FromCursor | KReplaceDialog::PromptOnReplace;
00057 m_underline = KoTextFormat::U_NONE;
00058 m_strikeOut = KoTextFormat::S_NONE;
00059 m_attribute = KoTextFormat::ATT_NONE;
00060 m_language = QString::null;
00061 }
00062
00063 KoSearchContext::~KoSearchContext()
00064 {
00065 }
00066
00067
00068 KoSearchContextUI::KoSearchContextUI( KoSearchContext *ctx, QWidget *parent )
00069 : QObject(parent), m_ctx(ctx), m_parent(parent)
00070 {
00071 m_bOptionsShown = false;
00072 m_btnShowOptions = new QPushButton( i18n("Show Formatting Options"), parent );
00073 connect( m_btnShowOptions, SIGNAL( clicked() ), SLOT( slotShowOptions() ) );
00074
00075 m_grid = new Q3GridLayout( m_parent, 1, 1, 0, 6 );
00076 m_grid->addWidget( m_btnShowOptions, 0, 0 );
00077 m_btnShowOptions->setEnabled( true );
00078 }
00079
00080 void KoSearchContextUI::slotShowOptions()
00081 {
00082 KoFormatDia * dlg = new KoFormatDia( m_parent, i18n("Formatting Options"), m_ctx );
00083 if ( dlg->exec())
00084 {
00085 dlg->ctxOptions( );
00086 m_bOptionsShown = true;
00087 }
00088
00089 delete dlg;
00090 }
00091
00092 void KoSearchContextUI::setCtxOptions( long options )
00093 {
00094 if ( m_bOptionsShown )
00095 {
00096 options |= m_ctx->m_options;
00097 }
00098 m_ctx->m_options = options;
00099 }
00100
00101 void KoSearchContextUI::setCtxHistory( const QStringList & history )
00102 {
00103 m_ctx->m_strings = history;
00104 }
00105
00106 KoSearchDia::KoSearchDia( QWidget * parent,const char *name, KoSearchContext *find, bool hasSelection, bool hasCursor )
00107 : KFindDialog( parent, name, find->m_options, find->m_strings )
00108 {
00109
00110 m_findUI = new KoSearchContextUI( find, findExtension() );
00111 setHasSelection(hasSelection);
00112 setHasCursor(hasCursor);
00113 }
00114
00115 void KoSearchDia::slotOk()
00116 {
00117 KFindDialog::slotOk();
00118
00119
00120 if ( optionSelected() )
00121 m_findUI->setCtxOptions( options() );
00122 m_findUI->setCtxHistory( findHistory() );
00123 }
00124
00125 KoReplaceDia::KoReplaceDia( QWidget *parent, const char *name, KoSearchContext *find, KoSearchContext *replace, bool hasSelection, bool hasCursor )
00126 : KReplaceDialog( parent, name, find->m_options, find->m_strings, replace->m_strings )
00127 {
00128
00129 m_findUI = new KoSearchContextUI( find, findExtension() );
00130 m_replaceUI = new KoSearchContextUI( replace, replaceExtension() );
00131
00132 setHasSelection(hasSelection);
00133 setHasCursor(hasCursor);
00134 }
00135
00136 void KoReplaceDia::slotOk()
00137 {
00138 KReplaceDialog::slotOk();
00139
00140
00141 m_findUI->setCtxHistory( findHistory() );
00142 if ( optionFindSelected() )
00143 m_findUI->setCtxOptions( KReplaceDialog::options() );
00144
00145 m_replaceUI->setCtxHistory( replacementHistory() );
00146 if ( optionReplaceSelected() )
00147 m_replaceUI->setCtxOptions( KReplaceDialog::options() );
00148 }
00149
00150
00151
00152 KoFindReplace::KoFindReplace( QWidget * parent, KoSearchDia * dialog, const Q3ValueList<KoTextObject *> & lstObject, KoTextView* textView )
00153 : m_find( new KoTextFind( dialog->pattern(), dialog->options(), this, parent ) ),
00154 m_replace( 0L ),
00155 m_searchContext( *dialog->searchContext() ),
00156 m_replaceContext(),
00157 m_searchContextEnabled( dialog->optionSelected() ),
00158 m_doCounting( true ),
00159 m_macroCmd( 0L ),
00160 m_offset( 0 ),
00161 m_textIterator( lstObject, textView, dialog->options() ),
00162 m_lastTextObjectHighlighted( 0 )
00163 {
00164 connectFind( m_find );
00165 }
00166
00167 KoFindReplace::KoFindReplace( QWidget * parent, KoReplaceDia * dialog, const Q3ValueList<KoTextObject *> & lstObject, KoTextView* textView )
00168 : m_find( 0L ),
00169 m_replace( new KoTextReplace( dialog->pattern(), dialog->replacement(), dialog->options(), this, parent ) ),
00170 m_searchContext( *dialog->searchContext() ),
00171 m_replaceContext( *dialog->replaceContext() ),
00172 m_searchContextEnabled( dialog->optionFindSelected() ),
00173 m_doCounting( true ),
00174 m_macroCmd( 0L ),
00175 m_offset( 0 ),
00176 m_textIterator( lstObject, textView, dialog->options() ),
00177 m_lastTextObjectHighlighted( 0 )
00178 {
00179 connectFind( m_replace );
00180 connect( m_replace, SIGNAL( replace( const QString &, int , int, int ) ),
00181 this, SLOT( replace( const QString &, int , int,int ) ) );
00182 }
00183
00184 void KoFindReplace::connectFind( KFind* find )
00185 {
00186 connect( find, SIGNAL( optionsChanged() ),
00187 this, SLOT( optionsChanged() ) );
00188 connect( find, SIGNAL( dialogClosed() ),
00189 this, SLOT( dialogClosed() ) );
00190
00191
00192 connect( find, SIGNAL( highlight( const QString &, int, int ) ),
00193 this, SLOT( highlight( const QString &, int, int ) ) );
00194
00195 connect( find, SIGNAL( findNext() ),
00196 this, SLOT( slotFindNext() ) );
00197 m_bInit = true;
00198 m_currentParagraphModified = false;
00199 m_matchingIndex = -1;
00200
00201
00202 connect( &m_textIterator, SIGNAL( currentParagraphModified( int, int, int ) ),
00203 this, SLOT( slotCurrentParagraphModified( int, int, int ) ) );
00204 }
00205
00206 KoFindReplace::~KoFindReplace()
00207 {
00208 removeHighlight();
00209
00210 delete m_find;
00211 delete m_replace;
00212 }
00213
00214 void KoFindReplace::optionsChanged()
00215 {
00216 m_textIterator.setOptions( options() );
00217 }
00218
00219 void KoFindReplace::dialogClosed()
00220 {
00221 removeHighlight();
00222 emitUndoRedo();
00223
00224
00225 m_doCounting = false;
00226 }
00227
00228 void KoFindReplace::removeHighlight()
00229 {
00230 if ( m_lastTextObjectHighlighted )
00231 m_lastTextObjectHighlighted->removeHighlight(true);
00232 m_lastTextObjectHighlighted = 0L;
00233 }
00234
00235 void KoFindReplace::emitUndoRedo()
00236 {
00237
00238
00239
00240
00241 if(m_macroCmd)
00242 emitNewCommand(m_macroCmd);
00243 m_macroCmd = 0L;
00244 }
00245
00255 bool KoFindReplace::findNext()
00256 {
00257 KFind::Result res = KFind::NoMatch;
00258 while ( res == KFind::NoMatch && !m_textIterator.atEnd() ) {
00259
00260 if ( needData() || m_currentParagraphModified ) {
00261 if ( !m_bInit && !m_currentParagraphModified ) {
00262 ++m_textIterator;
00263 if ( m_textIterator.atEnd() )
00264 break;
00265 }
00266 m_bInit = false;
00267 QPair<int, QString> c = m_textIterator.currentTextAndIndex();
00268 m_offset = c.first;
00269 if ( !m_currentParagraphModified )
00270 setData( c.second );
00271 else
00272 setData( c.second, m_matchingIndex );
00273 m_currentParagraphModified = false;
00274 }
00275
00276 if ( m_find )
00277
00278 res = m_find->find();
00279 else
00280 res = m_replace->replace();
00281 }
00282
00283
00284 if ( res == KFind::NoMatch )
00285 {
00286 emitUndoRedo();
00287 removeHighlight();
00288 if ( shouldRestart() ) {
00289 m_textIterator.setOptions( m_textIterator.options() & ~KFind::FromCursor );
00290 m_textIterator.restart();
00291 m_bInit = true;
00292 if ( m_find )
00293 m_find->resetCounts();
00294 else
00295 m_replace->resetCounts();
00296 return findNext();
00297 }
00298 else {
00299 if ( m_find )
00300 m_find->closeFindNextDialog();
00301 else
00302 m_replace->closeReplaceNextDialog();
00303 }
00304 return false;
00305 }
00306 return true;
00307 }
00308
00309 void KoFindReplace::slotFindNext()
00310 {
00311 bool ret = findNext();
00312 Q_UNUSED(ret);
00313 }
00314
00315 bool KoFindReplace::findPrevious()
00316 {
00317 int opt = options();
00318 bool forw = ! ( options() & KFind::FindBackwards );
00319 if ( forw )
00320 setOptions( opt | KFind::FindBackwards );
00321 else
00322 setOptions( opt & ~KFind::FindBackwards );
00323
00324 bool ret = findNext();
00325
00326 setOptions( opt );
00327
00328 return ret;
00329 }
00330
00331 long KoFindReplace::options() const
00332 {
00333 return m_find ? m_find->options() : m_replace->options();
00334 }
00335
00336 void KoFindReplace::setOptions(long opt)
00337 {
00338 if ( m_find )
00339 m_find->setOptions(opt);
00340 else
00341 m_replace->setOptions(opt);
00342 m_textIterator.setOptions( opt );
00343 }
00344
00345 void KoFindReplace::slotCurrentParagraphModified( int, int pos, int )
00346 {
00347 if ( pos >= m_offset )
00348 m_currentParagraphModified = true;
00349
00350 }
00351
00352
00353 void KoFindReplace::highlight( const QString &, int matchingIndex, int matchingLength )
00354 {
00355 m_matchingIndex = matchingIndex;
00356 if ( m_lastTextObjectHighlighted )
00357 m_lastTextObjectHighlighted->removeHighlight(true);
00358 m_lastTextObjectHighlighted = m_textIterator.currentTextObject();
00359
00360 KDialog* dialog = m_find ? m_find->findNextDialog() : m_replace->replaceNextDialog();
00361 highlightPortion(m_textIterator.currentParag(), m_offset + matchingIndex, matchingLength, m_lastTextObjectHighlighted->textDocument(), dialog );
00362 }
00363
00364
00365 void KoFindReplace::replace( const QString &text, int matchingIndex,
00366 int replacementLength, int matchedLength )
00367 {
00368
00369 m_matchingIndex = matchingIndex;
00370 int index = m_offset + matchingIndex;
00371
00372
00373 if ( (options() & KReplaceDialog::PromptOnReplace) == 0 )
00374 highlight( text, matchingIndex, matchedLength );
00375
00376 KoTextObject* currentTextObj = m_textIterator.currentTextObject();
00377 KoTextDocument * textdoc = currentTextObj->textDocument();
00378 KoTextCursor cursor( textdoc );
00379 cursor.setParag( m_textIterator.currentParag() );
00380 cursor.setIndex( index );
00381
00382
00383 currentTextObj->setNeedSpellCheck(true);
00384 if ( m_replaceContext.m_optionsMask )
00385 {
00386 replaceWithAttribut( &cursor, index );
00387 }
00388
00389 bool repaint = options() & KReplaceDialog::PromptOnReplace;
00390
00391
00392 QString rep = text.mid( matchingIndex, replacementLength );
00393
00394
00395 disconnect( &m_textIterator, SIGNAL( currentParagraphModified( int, int, int ) ),
00396 this, SLOT( slotCurrentParagraphModified( int, int, int ) ) );
00397
00398 KCommand *cmd = currentTextObj->replaceSelectionCommand(
00399 &cursor, rep, QString::null,
00400 KoTextDocument::HighlightSelection,
00401 repaint ? KoTextObject::DefaultInsertFlags : KoTextObject::DoNotRepaint );
00402
00403 connect( &m_textIterator, SIGNAL( currentParagraphModified( int, int, int ) ),
00404 this, SLOT( slotCurrentParagraphModified( int, int, int ) ) );
00405
00406 if( cmd )
00407 macroCommand()->addCommand(cmd);
00408 }
00409
00410 void KoFindReplace::replaceWithAttribut( KoTextCursor * cursor, int index )
00411 {
00412 KoTextFormat * lastFormat = m_textIterator.currentParag()->at( index )->format();
00413 KoTextFormat * newFormat = new KoTextFormat(*lastFormat);
00414 int flags = 0;
00415 if (m_replaceContext.m_optionsMask & KoSearchContext::Bold)
00416 {
00417 flags |= KoTextFormat::Bold;
00418 newFormat->setBold( (bool)(m_replaceContext.m_options & KoSearchContext::Bold) );
00419 }
00420 if (m_replaceContext.m_optionsMask & KoSearchContext::Size)
00421 {
00422 flags |= KoTextFormat::Size;
00423 newFormat->setPointSize( m_replaceContext.m_size );
00424
00425 }
00426 if ( m_replaceContext.m_optionsMask & KoSearchContext::Family)
00427 {
00428 flags |= KoTextFormat::Family;
00429 newFormat->setFamily( m_replaceContext.m_family );
00430 }
00431 if ( m_replaceContext.m_optionsMask & KoSearchContext::Color)
00432 {
00433 flags |= KoTextFormat::Color;
00434 newFormat->setColor( m_replaceContext.m_color );
00435 }
00436 if ( m_replaceContext.m_optionsMask & KoSearchContext::Italic)
00437 {
00438 flags |= KoTextFormat::Italic;
00439 newFormat->setItalic( (bool)(m_replaceContext.m_options & KoSearchContext::Italic) );
00440 }
00441 if ( m_replaceContext.m_optionsMask & KoSearchContext::Underline)
00442 {
00443 flags |= KoTextFormat::ExtendUnderLine;
00444 newFormat->setUnderlineType( m_replaceContext.m_underline );
00445
00446 }
00447 if ( m_replaceContext.m_optionsMask & KoSearchContext::VertAlign)
00448 {
00449 flags |= KoTextFormat::VAlign;
00450 newFormat->setVAlign( m_replaceContext.m_vertAlign);
00451 }
00452 if ( m_replaceContext.m_optionsMask & KoSearchContext::StrikeOut)
00453 {
00454 flags |= KoTextFormat::StrikeOut;
00455 newFormat->setStrikeOutType( m_replaceContext.m_strikeOut);
00456 }
00457 if ( m_replaceContext.m_optionsMask & KoSearchContext::BgColor)
00458 {
00459 newFormat->setTextBackgroundColor(m_replaceContext.m_backGroundColor);
00460 flags |= KoTextFormat::TextBackgroundColor;
00461 }
00462 if (m_replaceContext.m_optionsMask & KoSearchContext::Shadow)
00463 {
00464 flags |= KoTextFormat::ShadowText;
00465
00466 if ( m_replaceContext.m_options & KoSearchContext::Shadow )
00467 newFormat->setShadow( 1, 1, Qt::gray );
00468 else
00469 newFormat->setShadow( 0, 0, QColor() );
00470 }
00471 if (m_replaceContext.m_optionsMask & KoSearchContext::WordByWord)
00472 {
00473 flags |= KoTextFormat::WordByWord;
00474 newFormat->setWordByWord( (bool)(m_replaceContext.m_options & KoSearchContext::WordByWord) );
00475 }
00476 if (m_replaceContext.m_optionsMask & KoSearchContext::Language)
00477 {
00478 flags |= KoTextFormat::Language;
00479 newFormat->setLanguage( m_replaceContext.m_language );
00480 }
00481
00482
00483 KCommand *cmd = m_textIterator.currentTextObject()->setFormatCommand( cursor, &lastFormat ,newFormat,flags , false, KoTextDocument::HighlightSelection );
00484
00485 if( cmd )
00486 macroCommand()->addCommand(cmd);
00487 }
00488
00489 KMacroCommand* KoFindReplace::macroCommand()
00490 {
00491
00492 if(!m_macroCmd)
00493 m_macroCmd = new KMacroCommand(i18n("Replace Text"));
00494 return m_macroCmd;
00495 }
00496
00497 void KoFindReplace::setActiveWindow()
00498 {
00499 KDialog* dialog = m_find ? m_find->findNextDialog() : m_replace->replaceNextDialog();
00500 if ( dialog )
00501 dialog->activateWindow();
00502 }
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00515
00516 KoTextFind::KoTextFind( const QString &pattern, long options, KoFindReplace *_findReplace, QWidget *parent )
00517 : KFind( pattern, options, parent),
00518 m_findReplace( _findReplace)
00519 {
00520 }
00521
00522 KoTextFind::~KoTextFind()
00523 {
00524 }
00525
00526 bool KoTextFind::validateMatch( const QString &text, int index, int matchedlength )
00527 {
00528 return m_findReplace->validateMatch( text, index, matchedlength );
00529 }
00530
00531 KoTextReplace::KoTextReplace(const QString &pattern, const QString &replacement, long options, KoFindReplace *_findReplace, QWidget *parent )
00532 : KReplace( pattern, replacement, options, parent),
00533 m_findReplace( _findReplace)
00534 {
00535 }
00536
00537 KoTextReplace::~KoTextReplace()
00538 {
00539 }
00540
00541 bool KoTextReplace::validateMatch( const QString &text, int index, int matchedlength )
00542 {
00543 return m_findReplace->validateMatch( text, index, matchedlength );
00544 }
00545
00546 KoFormatDia::KoFormatDia( QWidget* parent, const QString & _caption, KoSearchContext *_ctx , const char* name)
00547 : KDialog( parent ),
00548 m_ctx(_ctx)
00549 {
00550 setCaption( _caption );
00551 setModal( true );
00552 setObjectName( name );
00553 setButtons( Ok|Cancel|User1 |User2 );
00554 setModal( true );
00555
00556 QWidget *page = new QWidget( this );
00557 setMainWidget(page);
00558 setButtonText( KDialog::User1, i18n("Reset") );
00559 setButtonText( KDialog::User2, i18n("Clear") );
00560
00561 connect( this, SIGNAL( user1Clicked() ), this, SLOT(slotReset()));
00562 connect( this, SIGNAL( user2Clicked() ), this, SLOT(slotClear()));
00563
00564 Q3GridLayout *m_grid = new Q3GridLayout( page, 15, 2, 0, 6 );
00565 m_checkFamily = new QCheckBox( i18n( "Family:" ),page );
00566 m_checkSize = new QCheckBox( i18n( "Size:" ), page );
00567 m_checkColor = new QCheckBox( i18n( "Color:" ), page );
00568 m_checkBgColor = new QCheckBox( i18n( "Background color:" ), page );
00569 m_checkBold = new QCheckBox( i18n( "Bold:" ), page );
00570 m_checkItalic = new QCheckBox( i18n( "Italic:" ),page );
00571 m_checkShadow = new QCheckBox( i18n( "Shadow:" ), page );
00572 m_checkWordByWord = new QCheckBox( i18n( "Word by word:" ), page );
00573
00574 m_checkUnderline = new QCheckBox( i18n( "Underline:" ), page);
00575 m_underlineItem = new QComboBox( page );
00576
00577
00578 m_underlineItem->addItems( KoTextFormat::underlineTypeList() );
00579 m_underlineItem->setCurrentIndex( (int)m_ctx->m_underline );
00580
00581 m_checkStrikeOut= new QCheckBox( i18n( "Strikeout:" ), page);
00582
00583 m_strikeOutItem = new QComboBox( page );
00584 m_strikeOutItem->addItems( KoTextFormat::strikeOutTypeList() );
00585 m_strikeOutItem->setCurrentIndex( (int)m_ctx->m_strikeOut );
00586
00587
00588 m_checkFontAttribute = new QCheckBox( i18n( "Capitalization:" ), page);
00589 m_fontAttributeItem = new QComboBox( page );
00590 m_fontAttributeItem->addItems( KoTextFormat::fontAttributeList() );
00591 m_fontAttributeItem->setCurrentIndex( (int)m_ctx->m_attribute );
00592
00593 m_checkLanguage = new QCheckBox( i18n( "Language:" ), page);
00594 m_languageItem = new QComboBox( page );
00595 m_languageItem->addItems( KoGlobal::listOfLanguages() );
00596 m_languageItem->setItemText( 0, KoGlobal::languageFromTag( m_ctx->m_language ) );
00597
00598
00599 m_checkVertAlign = new QCheckBox( i18n( "Vertical alignment:" ), page );
00600
00601 m_familyItem = new QFontComboBox(page);
00602 m_familyItem->setCurrentFont(m_ctx->m_family);
00603
00604 m_sizeItem = new QSpinBox( page );
00605 m_sizeItem->setMaximum( 100 );
00606 m_sizeItem->setMinimum( 4 );
00607 m_sizeItem->setValue( m_ctx->m_size );
00608
00609 m_colorItem = new KColorButton( page );
00610 m_colorItem->setColor( m_ctx->m_color );
00611
00612 m_bgColorItem = new KColorButton( page );
00613 m_bgColorItem->setColor( m_ctx->m_backGroundColor);
00614
00615
00616
00617 Q3ButtonGroup *grpBold = new Q3ButtonGroup( 1, Qt::Vertical, page );
00618 grpBold->setRadioButtonExclusive( true );
00619 grpBold->layout();
00620 m_boldYes=new QRadioButton( i18n("Yes"), grpBold );
00621 m_boldNo=new QRadioButton( i18n("No"), grpBold );
00622
00623 Q3ButtonGroup *grpItalic = new Q3ButtonGroup( 1, Qt::Vertical, page );
00624 grpItalic->setRadioButtonExclusive( true );
00625 grpItalic->layout();
00626 m_italicYes=new QRadioButton( i18n("Yes"), grpItalic );
00627 m_italicNo=new QRadioButton( i18n("No"), grpItalic );
00628
00629 Q3ButtonGroup *grpShadow = new Q3ButtonGroup( 1, Qt::Vertical, page );
00630 grpShadow->setRadioButtonExclusive( true );
00631 grpShadow->layout();
00632 m_shadowYes=new QRadioButton( i18n("Yes"), grpShadow );
00633 m_shadowNo=new QRadioButton( i18n("No"), grpShadow );
00634
00635 Q3ButtonGroup *grpWordByWord = new Q3ButtonGroup( 1, Qt::Vertical, page );
00636 grpWordByWord->setRadioButtonExclusive( true );
00637 grpWordByWord->layout();
00638 m_wordByWordYes=new QRadioButton( i18n("Yes"), grpWordByWord );
00639 m_wordByWordNo=new QRadioButton( i18n("No"), grpWordByWord );
00640
00641
00642 m_vertAlignItem = new QComboBox( page );
00643 m_vertAlignItem->setEditable( false );
00644 m_vertAlignItem->addItem( i18n( "Normal" ) );
00645 m_vertAlignItem->addItem( i18n( "Subscript" ) );
00646 m_vertAlignItem->addItem( i18n( "Superscript" ) );
00647 m_vertAlignItem->setCurrentIndex( (int)m_ctx->m_vertAlign );
00648
00649 m_grid->addWidget( m_checkFamily, 1, 0 );
00650 m_grid->addWidget( m_checkSize, 2, 0 );
00651 m_grid->addWidget( m_checkColor, 3, 0 );
00652 m_grid->addWidget( m_checkBgColor, 4, 0);
00653 m_grid->addWidget( m_checkBold, 5, 0 );
00654 m_grid->addWidget( m_checkItalic, 6, 0 );
00655 m_grid->addWidget( m_checkStrikeOut, 7, 0 );
00656 m_grid->addWidget( m_checkUnderline, 8, 0 );
00657 m_grid->addWidget( m_checkVertAlign, 9, 0 );
00658 m_grid->addWidget( m_checkShadow, 10, 0 );
00659 m_grid->addWidget( m_checkWordByWord, 11, 0 );
00660 m_grid->addWidget( m_checkFontAttribute, 12, 0 );
00661
00662 m_grid->addWidget( m_familyItem, 1, 1 );
00663 m_grid->addWidget( m_sizeItem, 2, 1 );
00664 m_grid->addWidget( m_colorItem, 3, 1 );
00665 m_grid->addWidget( m_bgColorItem, 4, 1);
00666 m_grid->addWidget( grpBold, 5, 1 );
00667 m_grid->addWidget( grpItalic, 6, 1 );
00668
00669 m_grid->addWidget( m_strikeOutItem, 7, 1 );
00670 m_grid->addWidget( m_underlineItem, 8, 1 );
00671
00672 m_grid->addWidget( m_vertAlignItem, 9, 1 );
00673 m_grid->addWidget( grpShadow, 10, 1 );
00674 m_grid->addWidget( grpWordByWord, 11, 1 );
00675
00676 m_grid->addWidget( m_fontAttributeItem, 12, 1);
00677
00678 m_grid->addWidget( m_checkLanguage, 13, 0);
00679 m_grid->addWidget( m_languageItem, 13, 1);
00680
00681 KSeparator *tmpSep = new KSeparator( page );
00682 m_grid->addMultiCellWidget( tmpSep, 14, 14, 0, 1 );
00683
00684
00685 QObject::connect( m_checkFamily, SIGNAL( toggled( bool ) ), m_familyItem, SLOT( setEnabled( bool ) ) );
00686 QObject::connect( m_checkSize, SIGNAL( toggled( bool ) ), m_sizeItem, SLOT( setEnabled( bool ) ) );
00687 QObject::connect( m_checkColor, SIGNAL( toggled( bool ) ), m_colorItem, SLOT( setEnabled( bool ) ) );
00688 QObject::connect( m_checkBgColor, SIGNAL( toggled( bool ) ), m_bgColorItem, SLOT( setEnabled( bool ) ) );
00689
00690 QObject::connect( m_checkBold, SIGNAL( toggled( bool ) ), m_boldYes, SLOT( setEnabled( bool ) ) );
00691 QObject::connect( m_checkItalic, SIGNAL( toggled( bool ) ), m_italicYes, SLOT( setEnabled( bool ) ) );
00692 QObject::connect( m_checkStrikeOut, SIGNAL( toggled( bool ) ), m_strikeOutItem, SLOT( setEnabled( bool ) ) );
00693 QObject::connect( m_checkShadow, SIGNAL( toggled( bool ) ), m_shadowYes, SLOT( setEnabled( bool ) ) );
00694 QObject::connect( m_checkWordByWord, SIGNAL( toggled( bool ) ), m_wordByWordYes, SLOT( setEnabled( bool ) ) );
00695 QObject::connect( m_checkFontAttribute, SIGNAL( toggled( bool ) ), m_fontAttributeItem, SLOT( setEnabled( bool ) ) );
00696 QObject::connect( m_checkLanguage, SIGNAL( toggled( bool ) ), m_languageItem, SLOT( setEnabled( bool ) ) );
00697
00698
00699 QObject::connect( m_checkBold, SIGNAL( toggled( bool ) ), m_boldNo, SLOT( setEnabled( bool ) ) );
00700 QObject::connect( m_checkItalic, SIGNAL( toggled( bool ) ), m_italicNo, SLOT( setEnabled( bool ) ) );
00701 QObject::connect( m_checkShadow, SIGNAL( toggled( bool ) ), m_shadowNo, SLOT( setEnabled( bool ) ) );
00702 QObject::connect( m_checkWordByWord, SIGNAL( toggled( bool ) ), m_wordByWordNo, SLOT( setEnabled( bool ) ) );
00703
00704
00705 QObject::connect( m_checkVertAlign, SIGNAL( toggled( bool ) ), m_vertAlignItem, SLOT( setEnabled( bool ) ) );
00706
00707 QObject::connect( m_checkUnderline, SIGNAL( toggled( bool ) ), m_underlineItem, SLOT( setEnabled( bool ) ) );
00708
00709 slotReset();
00710 }
00711
00712 void KoFormatDia::slotClear()
00713 {
00714 m_ctx->m_optionsMask = 0;
00715 m_ctx->m_options = 0;
00716 slotReset();
00717 }
00718
00719 void KoFormatDia::slotReset()
00720 {
00721 m_checkFamily->setChecked( m_ctx->m_optionsMask & KoSearchContext::Family );
00722 m_familyItem->setEnabled(m_checkFamily->isChecked());
00723
00724 m_checkSize->setChecked( m_ctx->m_optionsMask & KoSearchContext::Size );
00725 m_sizeItem->setEnabled(m_checkSize->isChecked());
00726
00727 m_checkColor->setChecked( m_ctx->m_optionsMask & KoSearchContext::Color );
00728 m_colorItem->setEnabled(m_checkColor->isChecked());
00729
00730 m_checkBgColor->setChecked( m_ctx->m_optionsMask & KoSearchContext::BgColor );
00731 m_bgColorItem->setEnabled(m_checkBgColor->isChecked());
00732
00733
00734 m_checkBold->setChecked( m_ctx->m_optionsMask & KoSearchContext::Bold );
00735 m_boldYes->setEnabled(m_checkBold->isChecked());
00736 m_boldNo->setEnabled(m_checkBold->isChecked());
00737
00738 m_checkShadow->setChecked( m_ctx->m_optionsMask & KoSearchContext::Shadow );
00739 m_shadowYes->setEnabled(m_checkShadow->isChecked());
00740 m_shadowNo->setEnabled(m_checkShadow->isChecked());
00741
00742 m_checkWordByWord->setChecked( m_ctx->m_optionsMask & KoSearchContext::WordByWord );
00743 m_wordByWordYes->setEnabled(m_checkWordByWord->isChecked());
00744 m_wordByWordNo->setEnabled(m_checkWordByWord->isChecked());
00745
00746
00747 m_checkStrikeOut->setChecked( m_ctx->m_optionsMask & KoSearchContext::StrikeOut );
00748 m_strikeOutItem->setEnabled( m_checkStrikeOut->isChecked());
00749
00750
00751 m_checkItalic->setChecked( m_ctx->m_optionsMask & KoSearchContext::Italic );
00752 m_italicNo->setEnabled(m_checkItalic->isChecked());
00753 m_italicYes->setEnabled(m_checkItalic->isChecked());
00754
00755 m_checkUnderline->setChecked( m_ctx->m_optionsMask & KoSearchContext::Underline );
00756 m_underlineItem->setEnabled(m_checkUnderline->isChecked());
00757
00758 m_checkVertAlign->setChecked( m_ctx->m_optionsMask & KoSearchContext::VertAlign );
00759 m_vertAlignItem->setEnabled(m_checkVertAlign->isChecked());
00760
00761 m_checkFontAttribute->setChecked( m_ctx->m_optionsMask & KoSearchContext::Attribute );
00762 m_fontAttributeItem->setEnabled(m_checkFontAttribute->isChecked());
00763
00764
00765 m_checkLanguage->setChecked( m_ctx->m_optionsMask & KoSearchContext::Language );
00766 m_languageItem->setEnabled(m_checkLanguage->isChecked());
00767
00768
00769 if (m_ctx->m_options & KoSearchContext::Bold)
00770 m_boldYes->setChecked( true );
00771 else
00772 m_boldNo->setChecked( true );
00773
00774 if (m_ctx->m_options & KoSearchContext::Italic)
00775 m_italicYes->setChecked( true );
00776 else
00777 m_italicNo->setChecked( true );
00778
00779 if (m_ctx->m_options & KoSearchContext::Shadow)
00780 m_shadowYes->setChecked( true );
00781 else
00782 m_shadowNo->setChecked( true );
00783
00784 if (m_ctx->m_options & KoSearchContext::WordByWord)
00785 m_wordByWordYes->setChecked( true );
00786 else
00787 m_wordByWordNo->setChecked( true );
00788
00789 }
00790
00791 void KoFormatDia::ctxOptions( )
00792 {
00793 long optionsMask = 0;
00794 long options = 0;
00795 if ( m_checkFamily->isChecked() )
00796 optionsMask |= KoSearchContext::Family;
00797 if ( m_checkSize->isChecked() )
00798 optionsMask |= KoSearchContext::Size;
00799 if ( m_checkColor->isChecked() )
00800 optionsMask |= KoSearchContext::Color;
00801 if ( m_checkBgColor->isChecked() )
00802 optionsMask |= KoSearchContext::BgColor;
00803 if ( m_checkBold->isChecked() )
00804 optionsMask |= KoSearchContext::Bold;
00805 if ( m_checkItalic->isChecked() )
00806 optionsMask |= KoSearchContext::Italic;
00807 if ( m_checkUnderline->isChecked() )
00808 optionsMask |= KoSearchContext::Underline;
00809 if ( m_checkVertAlign->isChecked() )
00810 optionsMask |= KoSearchContext::VertAlign;
00811 if ( m_checkStrikeOut->isChecked() )
00812 optionsMask |= KoSearchContext::StrikeOut;
00813 if ( m_checkShadow->isChecked() )
00814 optionsMask |= KoSearchContext::Shadow;
00815 if ( m_checkWordByWord->isChecked() )
00816 optionsMask |= KoSearchContext::WordByWord;
00817 if ( m_checkLanguage->isChecked() )
00818 optionsMask |= KoSearchContext::Language;
00819
00820
00821 if ( m_boldYes->isChecked() )
00822 options |= KoSearchContext::Bold;
00823 if ( m_italicYes->isChecked() )
00824 options |= KoSearchContext::Italic;
00825 if ( m_shadowYes->isChecked() )
00826 options |= KoSearchContext::Shadow;
00827 if ( m_wordByWordYes->isChecked() )
00828 options |= KoSearchContext::WordByWord;
00829
00830
00831 m_ctx->m_optionsMask = optionsMask;
00832 m_ctx->m_family = m_familyItem->currentText();
00833 m_ctx->m_size = m_sizeItem->cleanText().toInt();
00834 m_ctx->m_color = m_colorItem->color();
00835 m_ctx->m_backGroundColor = m_bgColorItem->color();
00836 m_ctx->m_vertAlign = (KoTextFormat::VerticalAlignment)m_vertAlignItem->currentIndex();
00837 m_ctx->m_underline = (KoTextFormat::UnderlineType)m_underlineItem->currentIndex();
00838 m_ctx->m_strikeOut = (KoTextFormat::StrikeOutType)m_strikeOutItem->currentIndex();
00839 m_ctx->m_attribute = (KoTextFormat::AttributeStyle)m_fontAttributeItem->currentIndex();
00840 m_ctx->m_language = KoGlobal::listTagOfLanguages()[m_languageItem->currentIndex()];
00841
00842 m_ctx->m_options = options;
00843 }
00844
00845
00846 bool KoFindReplace::validateMatch( const QString & , int index, int matchedlength )
00847 {
00848 if ( !m_searchContextEnabled || !m_searchContext.m_optionsMask )
00849 return true;
00850 KoTextString * s = currentParag()->string();
00851 for ( int i = index ; i < index+matchedlength ; ++i )
00852 {
00853 KoTextStringChar & ch = s->at(i);
00854 KoTextFormat *format = ch.format();
00855 if (m_searchContext.m_optionsMask & KoSearchContext::Bold)
00856 {
00857 if ( (!format->font().bold() && (m_searchContext.m_options & KoSearchContext::Bold)) || (format->font().bold() && ((m_searchContext.m_options & KoSearchContext::Bold)==0)))
00858 return false;
00859 }
00860 if (m_searchContext.m_optionsMask & KoSearchContext::Shadow)
00861 {
00862 bool hasShadow = format->shadowDistanceX() != 0 || format->shadowDistanceY() != 0;
00863 if ( (!hasShadow && (m_searchContext.m_options & KoSearchContext::Shadow))
00864 || (hasShadow && ((m_searchContext.m_options & KoSearchContext::Shadow)==0)) )
00865 return false;
00866 }
00867
00868 if (m_searchContext.m_optionsMask & KoSearchContext::WordByWord)
00869 {
00870 if ( (!format->wordByWord() && (m_searchContext.m_options & KoSearchContext::WordByWord)) || (format->wordByWord() && ((m_searchContext.m_options & KoSearchContext::WordByWord)==0)))
00871 return false;
00872 }
00873
00874
00875 if (m_searchContext.m_optionsMask & KoSearchContext::Size)
00876 {
00877 if ( format->font().pointSize() != m_searchContext.m_size )
00878 return false;
00879 }
00880 if ( m_searchContext.m_optionsMask & KoSearchContext::Family)
00881 {
00882 if (format->font().family() != m_searchContext.m_family)
00883 return false;
00884 }
00885 if ( m_searchContext.m_optionsMask & KoSearchContext::Color)
00886 {
00887 if (format->color() != m_searchContext.m_color)
00888 return false;
00889 }
00890 if ( m_searchContext.m_optionsMask & KoSearchContext::BgColor)
00891 {
00892 if (format->textBackgroundColor() != m_searchContext.m_backGroundColor)
00893 return false;
00894 }
00895
00896 if ( m_searchContext.m_optionsMask & KoSearchContext::Italic)
00897 {
00898 if ( (!format->font().italic() && (m_searchContext.m_options & KoSearchContext::Italic)) || (format->font().italic() && ((m_searchContext.m_options & KoSearchContext::Italic)==0)))
00899 return false;
00900
00901 }
00902 if ( m_searchContext.m_optionsMask & KoSearchContext::Underline)
00903 {
00904 if ( format->underlineType() != m_searchContext.m_underline )
00905 return false;
00906 }
00907 if ( m_searchContext.m_optionsMask & KoSearchContext::StrikeOut)
00908 {
00909 if ( format->strikeOutType() != m_searchContext.m_strikeOut )
00910 return false;
00911 }
00912
00913 if ( m_searchContext.m_optionsMask & KoSearchContext::VertAlign)
00914 {
00915 if ( format->vAlign() != m_searchContext.m_vertAlign )
00916 return false;
00917 }
00918 if ( m_searchContext.m_optionsMask & KoSearchContext::Language)
00919 {
00920 if ( format->language() != m_searchContext.m_language )
00921 return false;
00922 }
00923
00924 if ( m_searchContext.m_optionsMask & KoSearchContext::Attribute)
00925 {
00926 if ( format->attributeFont() != m_searchContext.m_attribute )
00927 return false;
00928 }
00929
00930 }
00931 return true;
00932 }
00933
00934 bool KoFindReplace::shouldRestart()
00935 {
00936 if ( m_find )
00937 return m_find->shouldRestart( true , m_doCounting );
00938 else
00939 return m_replace->shouldRestart( true , m_doCounting );
00940 }
00941
00942 #include "KoSearchDia.moc"