예제 #1
0
MultiLineEdit::MultiLineEdit(QWidget *parent)
    : MultiLineEditParent(parent),
    _idx(0),
    _mode(SingleLine),
    _singleLine(true),
    _minHeight(1),
    _maxHeight(5),
    _scrollBarsEnabled(true),
    _pasteProtectionEnabled(true),
    _emacsMode(false),
    _completionSpace(0),
    _lastDocumentHeight(-1)
{
    document()->setDocumentMargin(0);

    setAcceptRichText(false);
#ifdef HAVE_KDE
    enableFindReplace(false);
#endif

#ifdef HAVE_SONNET
    new Sonnet::SpellCheckDecorator(this);
#endif

    setMode(SingleLine);
    setLineWrapEnabled(false);
    reset();

    // Prevent QTextHtmlImporter::appendNodeText from eating whitespace
    document()->setDefaultStyleSheet("span { white-space: pre-wrap; }");

    connect(this, SIGNAL(textChanged()), this, SLOT(on_textChanged()));

    _mircColorMap["00"] = "#ffffff";
    _mircColorMap["01"] = "#000000";
    _mircColorMap["02"] = "#000080";
    _mircColorMap["03"] = "#008000";
    _mircColorMap["04"] = "#ff0000";
    _mircColorMap["05"] = "#800000";
    _mircColorMap["06"] = "#800080";
    _mircColorMap["07"] = "#ffa500";
    _mircColorMap["08"] = "#ffff00";
    _mircColorMap["09"] = "#00ff00";
    _mircColorMap["10"] = "#008080";
    _mircColorMap["11"] = "#00ffff";
    _mircColorMap["12"] = "#4169e1";
    _mircColorMap["13"] = "#ff00ff";
    _mircColorMap["14"] = "#808080";
    _mircColorMap["15"] = "#c0c0c0";
}
예제 #2
0
KItemListRoleEditor::KItemListRoleEditor(QWidget *parent) :
    KTextEdit(parent),
    m_role(),
    m_blockFinishedSignal(false)
{
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setAcceptRichText(false);
    enableFindReplace(false);
    document()->setDocumentMargin(0);

    if (parent) {
        parent->installEventFilter(this);
    }

    connect(this, &KItemListRoleEditor::textChanged, this, &KItemListRoleEditor::autoAdjustSize);
}
예제 #3
0
MultiLineEdit::MultiLineEdit(QWidget *parent)
    : MultiLineEditParent(parent),
    _idx(0),
    _mode(SingleLine),
    _singleLine(true),
    _minHeight(1),
    _maxHeight(5),
    _scrollBarsEnabled(true),
    _pasteProtectionEnabled(true),
    _emacsMode(false),
    _lastDocumentHeight(-1)
{
#if QT_VERSION >= 0x040500
    document()->setDocumentMargin(0); // new in Qt 4.5 and we really don't want it here
#endif

    setAcceptRichText(false);
#ifdef HAVE_KDE
    enableFindReplace(false);
#endif

    setMode(SingleLine);
    setLineWrapEnabled(false);
    reset();

    connect(this, SIGNAL(textChanged()), this, SLOT(on_textChanged()));

    _mircColorMap["00"] = "#ffffff";
    _mircColorMap["01"] = "#000000";
    _mircColorMap["02"] = "#000080";
    _mircColorMap["03"] = "#008000";
    _mircColorMap["04"] = "#ff0000";
    _mircColorMap["05"] = "#800000";
    _mircColorMap["06"] = "#800080";
    _mircColorMap["07"] = "#ffa500";
    _mircColorMap["08"] = "#ffff00";
    _mircColorMap["09"] = "#00ff00";
    _mircColorMap["10"] = "#008080";
    _mircColorMap["11"] = "#00ffff";
    _mircColorMap["12"] = "#4169e1";
    _mircColorMap["13"] = "#ff00ff";
    _mircColorMap["14"] = "#808080";
    _mircColorMap["15"] = "#c0c0c0";
}
예제 #4
0
MultiLineEdit::MultiLineEdit(QWidget* parent)
    : MultiLineEditParent(parent)
{
    document()->setDocumentMargin(0);

    setAcceptRichText(false);
#ifdef HAVE_KDE
    enableFindReplace(false);
#endif

#if defined HAVE_SONNET && !defined HAVE_KDE
    _spellCheckDecorator = new Sonnet::SpellCheckDecorator(this);
    highlighter()->setActive(highlighter()->checkerEnabledByDefault());
#endif

    setMode(SingleLine);
    setLineWrapEnabled(false);
    reset();

    // Prevent QTextHtmlImporter::appendNodeText from eating whitespace
    document()->setDefaultStyleSheet("span { white-space: pre-wrap; }");

    connect(this, &QTextEdit::textChanged, this, &MultiLineEdit::on_textChanged);

    _mircColorMap["00"] = "#ffffff";
    _mircColorMap["01"] = "#000000";
    _mircColorMap["02"] = "#000080";
    _mircColorMap["03"] = "#008000";
    _mircColorMap["04"] = "#ff0000";
    _mircColorMap["05"] = "#800000";
    _mircColorMap["06"] = "#800080";
    _mircColorMap["07"] = "#ffa500";
    _mircColorMap["08"] = "#ffff00";
    _mircColorMap["09"] = "#00ff00";
    _mircColorMap["10"] = "#008080";
    _mircColorMap["11"] = "#00ffff";
    _mircColorMap["12"] = "#4169e1";
    _mircColorMap["13"] = "#ff00ff";
    _mircColorMap["14"] = "#808080";
    _mircColorMap["15"] = "#c0c0c0";
}
SimpleRichTextEdit::SimpleRichTextEdit(QWidget *parent)
	: KTextEdit(parent)
{
	enableFindReplace(false);
	setCheckSpellingEnabled(true);

	setAutoFormatting(KTextEdit::AutoNone);
	setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);

	QTextDocument *textDocument = document();

	QTextOption textOption;
	textOption.setAlignment(Qt::AlignCenter);
	textOption.setWrapMode(QTextOption::NoWrap);
	textDocument->setDefaultTextOption(textOption);

	QFont defaultFont = font();
	defaultFont.setPointSize(defaultFont.pointSize() + 2);
	textDocument->setDefaultFont(defaultFont);

	QString styleSheet("p {" "   display: block;" "   white-space: pre;" "   margin-top: 0px;" "   margin-bottom: 0px;" "}");
	textDocument->setDefaultStyleSheet(styleSheet);

	setTextInteractionFlags(Qt::TextEditorInteraction);

	m_actions[Undo] = new QAction(this);
	m_actions[Undo]->setIcon(QIcon::fromTheme("edit-undo"));
	m_actions[Undo]->setText(i18n("Undo"));
	m_actions[Undo]->setShortcuts(KStandardShortcut::undo());
	connect(m_actions[Undo], SIGNAL(triggered()), this, SLOT(undo()));

	m_actions[Redo] = new QAction(this);
	m_actions[Redo]->setIcon(QIcon::fromTheme("edit-redo"));
	m_actions[Redo]->setText(i18n("Redo"));
	m_actions[Redo]->setShortcuts(KStandardShortcut::redo());
	connect(m_actions[Redo], SIGNAL(triggered()), this, SLOT(redo()));

	m_actions[Cut] = new QAction(this);
	m_actions[Cut]->setIcon(QIcon::fromTheme("edit-cut"));
	m_actions[Cut]->setText(i18n("Cut"));
	m_actions[Cut]->setShortcuts(KStandardShortcut::cut());
	connect(m_actions[Cut], SIGNAL(triggered()), this, SLOT(cut()));

	m_actions[Copy] = new QAction(this);
	m_actions[Copy]->setIcon(QIcon::fromTheme("edit-copy"));
	m_actions[Copy]->setText(i18n("Copy"));
	m_actions[Copy]->setShortcuts(KStandardShortcut::copy());
	connect(m_actions[Copy], SIGNAL(triggered()), this, SLOT(copy()));

#if !defined(QT_NO_CLIPBOARD)
	m_actions[Paste] = new QAction(this);
	m_actions[Paste]->setIcon(QIcon::fromTheme("edit-paste"));
	m_actions[Paste]->setText(i18n("Paste"));
	m_actions[Paste]->setShortcuts(KStandardShortcut::paste());
	connect(m_actions[Paste], SIGNAL(triggered()), this, SLOT(paste()));
#endif

	m_actions[Delete] = new QAction(this);
	m_actions[Delete]->setIcon(QIcon::fromTheme("edit-delete"));
	m_actions[Delete]->setText(i18n("Delete"));
	m_actions[Delete]->setShortcut(QKeySequence::Delete);
	connect(m_actions[Delete], SIGNAL(triggered()), this, SLOT(deleteText()));

	m_actions[Clear] = new QAction(this);
	m_actions[Clear]->setIcon(QIcon::fromTheme("edit-clear"));
	m_actions[Clear]->setText(i18nc("@action:inmenu Clear all text", "Clear"));
	connect(m_actions[Clear], SIGNAL(triggered()), this, SLOT(undoableClear()));

	m_actions[SelectAll] = new QAction(this);
	m_actions[SelectAll]->setIcon(QIcon::fromTheme("edit-select-all"));
	m_actions[SelectAll]->setText(i18n("Select All"));
	m_actions[SelectAll]->setShortcut(QKeySequence::SelectAll);
	connect(m_actions[SelectAll], SIGNAL(triggered()), this, SLOT(selectAll()));

	m_actions[ToggleBold] = new QAction(this);
	m_actions[ToggleBold]->setIcon(QIcon::fromTheme("format-text-bold"));
	m_actions[ToggleBold]->setText(i18nc("@action:inmenu Toggle bold style", "Bold"));
	m_actions[ToggleBold]->setShortcut(QKeySequence("Ctrl+B"));
	connect(m_actions[ToggleBold], SIGNAL(triggered()), this, SLOT(toggleFontBold()));

	m_actions[ToggleItalic] = new QAction(this);
	m_actions[ToggleItalic]->setIcon(QIcon::fromTheme("format-text-italic"));
	m_actions[ToggleItalic]->setText(i18nc("@action:inmenu Toggle italic style", "Italic"));
	m_actions[ToggleItalic]->setShortcut(QKeySequence("Ctrl+I"));
	connect(m_actions[ToggleItalic], SIGNAL(triggered()), this, SLOT(toggleFontItalic()));

	m_actions[ToggleUnderline] = new QAction(this);
	m_actions[ToggleUnderline]->setIcon(QIcon::fromTheme("format-text-underline"));
	m_actions[ToggleUnderline]->setText(i18nc("@action:inmenu Toggle underline style", "Underline"));
	m_actions[ToggleUnderline]->setShortcut(QKeySequence("Ctrl+U"));
	connect(m_actions[ToggleUnderline], SIGNAL(triggered()), this, SLOT(toggleFontUnderline()));

	m_actions[ToggleStrikeOut] = new QAction(this);
	m_actions[ToggleStrikeOut]->setIcon(QIcon::fromTheme("format-text-strikethrough"));
	m_actions[ToggleStrikeOut]->setText(i18nc("@action:inmenu Toggle strike through style", "Strike Through"));
	m_actions[ToggleStrikeOut]->setShortcut(QKeySequence("Ctrl+T"));
	connect(m_actions[ToggleStrikeOut], SIGNAL(triggered()), this, SLOT(toggleFontStrikeOut()));

	m_actions[ChangeTextColor] = new QAction(this);
	m_actions[ChangeTextColor]->setIcon(QIcon::fromTheme("format-text-color"));
	m_actions[ChangeTextColor]->setText(i18nc("@action:inmenu Change Text Color", "Text Color"));
	m_actions[ChangeTextColor]->setShortcut(QKeySequence("Ctrl+Shift+C"));
	connect(m_actions[ChangeTextColor], SIGNAL(triggered()), this, SLOT(changeTextColor()));

	m_actions[CheckSpelling] = new QAction(this);
	m_actions[CheckSpelling]->setIcon(QIcon::fromTheme("tools-check-spelling"));
	m_actions[CheckSpelling]->setText(i18n("Check Spelling..."));
	connect(m_actions[CheckSpelling], SIGNAL(triggered()), this, SLOT(checkSpelling()));

	m_actions[ToggleAutoSpellChecking] = new QAction(this);
	m_actions[ToggleAutoSpellChecking]->setText(i18n("Auto Spell Check"));
	m_actions[ToggleAutoSpellChecking]->setCheckable(true);
	connect(m_actions[ToggleAutoSpellChecking], SIGNAL(triggered()), this, SLOT(toggleAutoSpellChecking()));

	m_actions[AllowTabulations] = new QAction(this);
	m_actions[AllowTabulations]->setText(i18n("Allow Tabulations"));
	connect(m_actions[AllowTabulations], SIGNAL(triggered()), this, SLOT(toggleTabChangesFocus()));

	QMenu *menu = createStandardContextMenu();
	menu->setParent(this);
	QList<QAction *> actions = menu->actions();
	m_insertUnicodeControlCharMenu = 0;
	for(QList<QAction *>::ConstIterator it = actions.constBegin(), end = actions.constEnd(); it != end; ++it) {
		if((*it)->menu()) {
			// this depends on Qt private implementation but at least is guaranteed
			// to behave reasonably if that implementation changes in the future.
			if(!strcmp((*it)->menu()->metaObject()->className(), "QUnicodeControlCharacterMenu")) {
				m_insertUnicodeControlCharMenu = (*it)->menu();
				break;
			}
		}
	}
}