Example #1
0
KreTextEdit::KreTextEdit( QWidget *parent ):
	KTextEdit( parent )//, KCompletionBase()
{
	KCompletion * comp = completionObject(); //creates the completion object
	comp->setIgnoreCase( true );

	completing = false;

	QString spellCheckingConfigFileName = KStandardDirs::locateLocal( "config",
		KCmdLineArgs::aboutData()->appName() + "rc" );

	KConfig localConfig( spellCheckingConfigFileName, KConfig::SimpleConfig );
	KConfigGroup localGroup( &localConfig, "Spelling" );

	//If we don't have our local configuration for spell checking, fall back to
	//user's global configuration.
	if ( !localConfig.hasGroup( "Spelling" ) ) {
		KConfig globalSonnetConfig( KStandardDirs::locateLocal( "config", "sonnetrc" ) );
		KConfigGroup globalGroup( &globalSonnetConfig, "Spelling" );
		globalGroup.copyTo( &localGroup );
		localConfig.sync();
		KConfigGroup group( KGlobal::config(), "Spelling" );
		globalGroup.copyTo( &group );
	}

	setSpellCheckingConfigFileName( spellCheckingConfigFileName );

	if ( localGroup.readEntry( "checkerEnabledByDefault", false ) )
		setCheckSpellingEnabled( true );
	else
		setCheckSpellingEnabled( false );

	//connect( this, SIGNAL( clicked( int, int ) ), SLOT( haltCompletion() ) );
}
Example #2
0
MyEditor::MyEditor( TQWidget *parent, const char *name )
                : KTextEdit( parent, name )
{
        setTextFormat(PlainText);
	setCheckSpellingEnabled (true);
        setAcceptDrops(true);
}
Example #3
0
void MultiLineEdit::setSpellCheckEnabled(bool enable)
{
#ifdef HAVE_KDE
    setCheckSpellingEnabled(enable);
#else
    Q_UNUSED(enable)
#endif
}
Example #4
0
MsgTextEdit::MsgTextEdit(MsgEdit *edit, QWidget *parent)
        : TextEdit(parent)
{
    m_edit = edit;
    setBackground(CorePlugin::m_plugin->getEditBackground());
    setForeground(CorePlugin::m_plugin->getEditForeground(), true);
#if defined(USE_KDE)
#if KDE_IS_VERSION(3,2,0)
    setCheckSpellingEnabled(CorePlugin::m_plugin->getEnableSpell());
#endif
#endif
}
KNoteEdit::KNoteEdit( KActionCollection *actions, QWidget *parent )
  : KTextEdit( parent ), m_note( 0 )
{
  setAcceptDrops( true );
  setWordWrapMode( QTextOption::WordWrap );
  setLineWrapMode( WidgetWidth );
  if ( acceptRichText() ) {
    setAutoFormatting( AutoAll );
  } else {
    setAutoFormatting( AutoNone );
  }
  setCheckSpellingEnabled( true );

  // create the actions modifying the text format
  m_textBold  = new KToggleAction( KIcon( "format-text-bold" ), i18n( "Bold" ),
                                   this );
  actions->addAction( "format_bold", m_textBold );
  m_textBold->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_B ) );
  m_textItalic  = new KToggleAction( KIcon( "format-text-italic" ),
                                    i18n( "Italic" ), this );
  actions->addAction( "format_italic", m_textItalic );
  m_textItalic->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_I ) );
  m_textUnderline  = new KToggleAction( KIcon( "format-text-underline" ),
                                        i18n( "Underline" ), this );
  actions->addAction( "format_underline", m_textUnderline );
  m_textUnderline->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_U ) );
  m_textStrikeOut  = new KToggleAction( KIcon( "format-text-strikethrough" ),
                                        i18n( "Strike Out" ), this );
  actions->addAction( "format_strikeout", m_textStrikeOut );
  m_textStrikeOut->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_S ) );

  connect( m_textBold, SIGNAL(toggled(bool)), SLOT(textBold(bool)) );
  connect( m_textItalic, SIGNAL(toggled(bool)),
           SLOT(setFontItalic(bool)) );
  connect( m_textUnderline, SIGNAL(toggled(bool)),
           SLOT(setFontUnderline(bool)) );
  connect( m_textStrikeOut, SIGNAL(toggled(bool)),
           SLOT(textStrikeOut(bool)) );

  m_textAlignLeft = new KToggleAction( KIcon( "format-justify-left" ),
                                       i18n( "Align Left" ), this );
  actions->addAction( "format_alignleft", m_textAlignLeft );
  connect( m_textAlignLeft, SIGNAL(triggered(bool)),
           SLOT(textAlignLeft()) );
  m_textAlignLeft->setShortcut( QKeySequence( Qt::ALT + Qt::Key_L ) );
  m_textAlignLeft->setChecked( true ); // just a dummy, will be updated later
  m_textAlignCenter  = new KToggleAction( KIcon( "format-justify-center" ),
                                          i18n( "Align Center" ), this );
  actions->addAction( "format_aligncenter", m_textAlignCenter );
  connect( m_textAlignCenter, SIGNAL(triggered(bool)),
          SLOT(textAlignCenter()) );
  m_textAlignCenter->setShortcut( QKeySequence( Qt::ALT + Qt::Key_C ) );
  m_textAlignRight = new KToggleAction( KIcon( "format-justify-right" ),
                                        i18n( "Align Right" ), this );
  actions->addAction( "format_alignright", m_textAlignRight );
  connect( m_textAlignRight, SIGNAL(triggered(bool)),
           SLOT(textAlignRight()) );
  m_textAlignRight->setShortcut( QKeySequence( Qt::ALT + Qt::Key_R ) );
  m_textAlignBlock = new KToggleAction( KIcon( "format-justify-fill" ),
                                        i18n( "Align Block" ), this );
  actions->addAction( "format_alignblock", m_textAlignBlock );
  connect( m_textAlignBlock, SIGNAL(triggered(bool)),
           SLOT(textAlignBlock()) );
  m_textAlignBlock->setShortcut( QKeySequence( Qt::ALT + Qt::Key_B ) );

  QActionGroup *group = new QActionGroup( this );
  group->addAction( m_textAlignLeft );
  group->addAction( m_textAlignCenter );
  group->addAction( m_textAlignRight );
  group->addAction( m_textAlignBlock );

  m_textList  = new KToggleAction( KIcon( "format-list-ordered" ), i18n( "List" ), this );
  actions->addAction( "format_list", m_textList );
  connect( m_textList, SIGNAL(triggered(bool)), SLOT(textList()) );

  m_textSuper  = new KToggleAction( KIcon( "format-text-superscript" ),
                                    i18n( "Superscript" ), this );
  actions->addAction( "format_super", m_textSuper );
  connect( m_textSuper, SIGNAL(triggered(bool)),
           SLOT(textSuperScript()) );
  m_textSub  = new KToggleAction( KIcon( "format-text-subscript" ), i18n( "Subscript" ),
                                  this );
  actions->addAction( "format_sub", m_textSub );
  connect( m_textSub, SIGNAL(triggered(bool)), SLOT(textSubScript()) );


  m_textIncreaseIndent = new KAction( KIcon( "format-indent-more" ),
                                      i18n( "Increase Indent" ), this );
  actions->addAction( "format_increaseindent", m_textIncreaseIndent );
  m_textIncreaseIndent->setShortcut( QKeySequence( Qt::CTRL + Qt::ALT +
                                                   Qt::Key_I ) );
  connect( m_textIncreaseIndent, SIGNAL(triggered(bool)),
           SLOT(textIncreaseIndent()) );

  m_textDecreaseIndent = new KAction(  KIcon( "format-indent-less" ),
                                       i18n( "Decrease Indent" ), this );
  actions->addAction( "format_decreaseindent", m_textDecreaseIndent );
  m_textDecreaseIndent->setShortcut( QKeySequence( Qt::CTRL + Qt::ALT +
                                                   Qt::Key_D ) );
  connect( m_textDecreaseIndent, SIGNAL(triggered(bool)), SLOT(
           textDecreaseIndent() ) );

  group = new QActionGroup( this );
  group->addAction( m_textIncreaseIndent );
  group->addAction( m_textDecreaseIndent );

  QPixmap pix( ICON_SIZE, ICON_SIZE );
  pix.fill( Qt::black ); // just a dummy, gets updated before widget is shown
  m_textColor  = new KAction( i18n( "Text Color..." ), this );
  actions->addAction( "format_color", m_textColor );
  m_textColor->setIcon( pix );
  connect( m_textColor, SIGNAL(triggered(bool)), SLOT(slotTextColor()) );

  KAction *act = new KAction(KIcon( "format-fill-color" ), i18n( "Text Background Color..." ), this );
  actions->addAction( "text_background_color", act );
  connect( act, SIGNAL(triggered(bool)), SLOT(slotTextBackgroundColor()) );

  m_textFont  = new KFontAction( i18n( "Text Font" ), this );
  actions->addAction( "format_font", m_textFont );
  connect( m_textFont, SIGNAL(triggered(QString)),
           this, SLOT(setFontFamily(QString)) );

  m_textSize  = new KFontSizeAction( i18n( "Text Size" ), this );
  actions->addAction( "format_size", m_textSize );
  connect( m_textSize, SIGNAL(fontSizeChanged(int)),
           this, SLOT(setTextFontSize(int)) );

  // QTextEdit connections
  connect( this, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
           SLOT(slotCurrentCharFormatChanged(QTextCharFormat)) );
  connect( this, SIGNAL(cursorPositionChanged()),
           SLOT(slotCursorPositionChanged()) );
  slotCurrentCharFormatChanged( currentCharFormat() );
  slotCursorPositionChanged();
}
void
SimpleRichTextEdit::toggleAutoSpellChecking()
{
	setCheckSpellingEnabled(!checkSpellingEnabled());
}
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;
			}
		}
	}
}
void TextEdit::settingsChanged()
{
    setCheckSpellingEnabled(BehaviorSettings::enableSpellChecker());
}