void KNoteEdit::setRichText( bool f )
{
  if ( f == acceptRichText() ) {
    return;
  }

  setAcceptRichText( f );

  if ( f ) {
    setAutoFormatting( AutoAll );
  } else {
    setAutoFormatting( AutoNone );
  }

  const QString t = toPlainText();
  if ( f ) {
    // if the note contains html source try to render it
    if ( Qt::mightBeRichText( t ) ) {
      setHtml( t );
    } else {
      setPlainText( t );
    }

    enableRichTextActions();
  } else {
    setPlainText( t );
    disableRichTextActions();
  }
}
QString KNoteEdit::text() const
{
  if ( acceptRichText() ) {
    return toHtml();
  } else {
    return toPlainText();
  }
}
void KNoteEdit::setText( const QString& text )
{
  if ( acceptRichText() && Qt::mightBeRichText( text ) ) {
    setHtml( text );
  } else {
    setPlainText( text );
  }
}
void XTextEdit::setDataWidgetMap(XDataWidgetMapper* m)
{
  disconnect(this, SIGNAL(textChanged()), this, SLOT(updateMapperData()));
  if (acceptRichText())
    m->addMapping(this, _fieldName, "html", "defaultText");
  else
    m->addMapping(this, _fieldName, "plainText", "defaultText");
  _mapper = m;
  connect(this, SIGNAL(textChanged()), this, SLOT(updateMapperData()));
}
void KNoteEdit::setTextFormat( const QTextCharFormat &f )
{
  if ( acceptRichText() ) {
    textCursor().mergeCharFormat( f );
  } else {
    QTextCursor c( document() );
    c.movePosition( QTextCursor::Start );
    c.movePosition( QTextCursor::End, QTextCursor::KeepAnchor );
    c.mergeCharFormat( f );
  }
}
Example #6
0
int QTextControl::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 38)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 38;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QString*>(_v) = toHtml(); break;
        case 1: *reinterpret_cast< bool*>(_v) = overwriteMode(); break;
        case 2: *reinterpret_cast< bool*>(_v) = acceptRichText(); break;
        case 3: *reinterpret_cast< int*>(_v) = cursorWidth(); break;
        case 4: *reinterpret_cast< Qt::TextInteractionFlags*>(_v) = textInteractionFlags(); break;
        case 5: *reinterpret_cast< bool*>(_v) = openExternalLinks(); break;
        case 6: *reinterpret_cast< bool*>(_v) = ignoreUnusedNavigationEvents(); break;
        }
        _id -= 7;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setHtml(*reinterpret_cast< QString*>(_v)); break;
        case 1: setOverwriteMode(*reinterpret_cast< bool*>(_v)); break;
        case 2: setAcceptRichText(*reinterpret_cast< bool*>(_v)); break;
        case 3: setCursorWidth(*reinterpret_cast< int*>(_v)); break;
        case 4: setTextInteractionFlags(*reinterpret_cast< Qt::TextInteractionFlags*>(_v)); break;
        case 5: setOpenExternalLinks(*reinterpret_cast< bool*>(_v)); break;
        case 6: setIgnoreUnusedNavigationEvents(*reinterpret_cast< bool*>(_v)); break;
        }
        _id -= 7;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 7;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Example #7
0
void MessageEditor::insertFromMimeData(const QMimeData *ASource)
{
	QTextDocument doc;
	emit insertDataRequest(ASource,&doc);

	if (!doc.isEmpty())
	{
		QTextCursor cursor(&doc);
		cursor.select(QTextCursor::Document);
		if (acceptRichText())
			textCursor().insertFragment(cursor.selection());
		else
			textCursor().insertText(cursor.selection().toPlainText());
	}

	ensureCursorVisible();
	setFocus();
}
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();
}