Ejemplo n.º 1
0
void SearchReplace::slotSearch()
{
//	if (m_itemMode)
//		m_doc->view()->slotDoCurs(false);
	slotDoSearch();
	if (m_itemMode)
	{
//		m_doc->view()->slotDoCurs(true);
		m_item->update();
	}
}
Ejemplo n.º 2
0
void SearchReplace::slotSearch()
{
//	if (SMode)
//		Doc->view()->slotDoCurs(false);
	slotDoSearch();
	if (SMode)
	{
//		Doc->view()->slotDoCurs(true);
		Item->update();
	}
}
Ejemplo n.º 3
0
void SearchReplace::slotDoReplace()
{
	if (m_itemMode)
	{
		QString repl, sear;
		int cs, cx;
		int textLen = 0;
		if (RText->isChecked())
		{
			repl = RTextVal->text();
			sear = STextVal->text();
			textLen = m_item->itemText.lengthOfSelection();
			if (textLen == repl.length())
			{
				for (cs = 0; cs < textLen; ++cs)
					m_item->itemText.replaceChar(m_replStart+cs, repl[cs]);
			}
			else
			{
				if (textLen < repl.length())
				{
					for (cs = 0; cs < textLen; ++cs)
						m_item->itemText.replaceChar(m_replStart+cs, repl[cs]);
					for (cx = cs; cx < repl.length(); ++cx)
						m_item->itemText.insertChars(m_replStart+cx, repl.mid(cx,1), true);
				}
				else
				{
					for (cs = 0; cs < repl.length(); ++cs)
						m_item->itemText.replaceChar(m_replStart+cs, repl[cs]);
					m_item->itemText.removeChars(m_replStart+cs, textLen - cs);
				}
			}
			m_item->itemText.deselectAll();
			if (repl.length() > 0)
			{
				m_item->itemText.select(m_replStart, repl.length());
				m_item->itemText.setCursorPosition(m_replStart + repl.length());
			}
		}
		if (RStyle->isChecked())
		{
			int oldMode = m_doc->appMode;
			m_doc->appMode = modeEdit;
			m_doc->itemSelection_SetNamedParagraphStyle(m_doc->paragraphStyles()[RStyleVal->currentIndex()].name());
			m_doc->appMode = oldMode;
		}
		if (RAlign->isChecked())
		{
			int oldMode = m_doc->appMode;
			m_doc->appMode = modeEdit;
			m_doc->itemSelection_SetAlignment(RAlignVal->currentIndex());
			m_doc->appMode = oldMode;
		}
		if (RFill->isChecked())
			m_doc->itemSelection_SetFillColor(RFillVal->currentText());
		if (RFillS->isChecked())
			m_doc->itemSelection_SetFillShade(RFillSVal->getValue());
		if (RStroke->isChecked())
			m_doc->itemSelection_SetStrokeColor(RStrokeVal->currentText());
		if (RStrokeS->isChecked())
			m_doc->itemSelection_SetStrokeShade(RStrokeSVal->getValue());
		if (RFont->isChecked())
			m_doc->itemSelection_SetFont(RFontVal->currentText());
		if (RSize->isChecked())
			m_doc->itemSelection_SetFontSize(qRound(RSizeVal->value() * 10.0));
		if (REffect->isChecked() && (m_item->itemText.lengthOfSelection() > 0))
		{
			int s = REffVal->getStyle() & ScStyle_UserStyles;
			m_doc->currentStyle.charStyle().setFeatures(static_cast<StyleFlag>(s).featureList()); // ???
			for (int a = 0; a < m_item->itemText.length(); ++a)
			{
				if (m_item->itemText.selected(a))
				{
//                    StyleFlag fl = m_item->itemText.charStyle(a).effects();
//					fl &= static_cast<StyleFlag>(~1919);
//					fl |= static_cast<StyleFlag>(s);
//					m_item->itemText.item(a)->setFeatures(fl.featureList());
					CharStyle newFeatures;
					newFeatures.setFeatures(static_cast<StyleFlag>(s).featureList());
					m_item->itemText.applyCharStyle(a, 1, newFeatures);
				}
			}
		}
		m_item->itemText.deselectAll();
	}
	else if (m_doc->scMW()->CurrStED != NULL)
	{
		StoryEditor* se = m_doc->scMW()->CurrStED;
		if (RText->isChecked())
		{
			disconnect(se->Editor, SIGNAL(cursorPositionChanged()), se, SLOT(updateProps()));
			int SelStart = se->Editor->textCursor().selectionStart();
			int SelEnd = se->Editor->textCursor().selectionEnd();
//			se->Editor->insChars(RTextVal->text());
			se->Editor->textCursor().setPosition(SelStart);
			se->Editor->textCursor().setPosition(SelEnd, QTextCursor::KeepAnchor);
			se->Editor->textCursor().removeSelectedText();
//FIXME		se->Editor->setEffects(se->Editor->CurrentEffects);
			QString newText = RTextVal->text();
			se->Editor->insertPlainText(newText);
			if (newText.length() > 0)
			{
				QTextCursor textCursor = se->Editor->textCursor();
				textCursor.setPosition(SelStart);
				textCursor.setPosition(SelStart + newText.length(), QTextCursor::KeepAnchor);
				se->Editor->setTextCursor(textCursor);
			}
			connect(se->Editor, SIGNAL(cursorPositionChanged()), se, SLOT(updateProps()));
//			se->newAlign(se->Editor->currentParaStyle);
		}
		if (RStyle->isChecked())
			se->newStyle(m_doc->paragraphStyles()[RStyleVal->currentIndex()].name());
		if (RAlign->isChecked())
			se->newAlign(RAlignVal->currentIndex());
		if (RFill->isChecked())
			se->newTxFill(RFillVal->currentIndex(), -1);
		if (RFillS->isChecked())
			se->newTxFill(-1, RFillSVal->getValue());
		if (RStroke->isChecked())
			se->newTxStroke(RStrokeVal->currentIndex(), -1);
		if (RStrokeS->isChecked())
			se->newTxStroke(-1, RStrokeSVal->getValue());
		if (RFont->isChecked())
			se->newTxFont(RFontVal->currentText());
		if (RSize->isChecked())
			se->newTxSize(RSizeVal->value());
		if (REffect->isChecked())
			se->newTxStyle(REffVal->getStyle());

		QTextCursor textCursor = se->Editor->textCursor();
		int selStart = textCursor.selectionStart();
		int selEnd   = textCursor.selectionEnd();
		int selPos   = qMax(selStart, selEnd);
		textCursor.setPosition(selPos);
		se->Editor->setTextCursor(textCursor);
	}
	DoReplace->setEnabled(false);
	AllReplace->setEnabled(false);
	slotDoSearch();
}