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(); }
MRichTextEdit::MRichTextEdit(QWidget *parent) : QWidget(parent) { setupUi(this); m_lastBlockList = 0; f_textedit->setTabStopWidth(40); connect(f_textedit, SIGNAL(currentCharFormatChanged(QTextCharFormat)), this, SLOT(slotCurrentCharFormatChanged(QTextCharFormat))); connect(f_textedit, SIGNAL(cursorPositionChanged()), this, SLOT(slotCursorPositionChanged())); m_fontsize_h1 = 18; m_fontsize_h2 = 16; m_fontsize_h3 = 14; m_fontsize_h4 = 12; fontChanged(f_textedit->font()); bgColorChanged(f_textedit->textColor()); // paragraph formatting m_paragraphItems << tr("Standard") << tr("Heading 1") << tr("Heading 2") << tr("Heading 3") << tr("Heading 4") << tr("Monospace"); f_paragraph->addItems(m_paragraphItems); connect(f_paragraph, SIGNAL(activated(int)), this, SLOT(textStyle(int))); // undo & redo f_undo->setShortcut(QKeySequence::Undo); f_redo->setShortcut(QKeySequence::Redo); connect(f_textedit->document(), SIGNAL(undoAvailable(bool)), f_undo, SLOT(setEnabled(bool))); connect(f_textedit->document(), SIGNAL(redoAvailable(bool)), f_redo, SLOT(setEnabled(bool))); f_undo->setEnabled(f_textedit->document()->isUndoAvailable()); f_redo->setEnabled(f_textedit->document()->isRedoAvailable()); connect(f_undo, SIGNAL(clicked()), f_textedit, SLOT(undo())); connect(f_redo, SIGNAL(clicked()), f_textedit, SLOT(redo())); // cut, copy & paste f_cut->setShortcut(QKeySequence::Cut); f_copy->setShortcut(QKeySequence::Copy); f_paste->setShortcut(QKeySequence::Paste); f_cut->setEnabled(false); f_copy->setEnabled(false); connect(f_cut, SIGNAL(clicked()), f_textedit, SLOT(cut())); connect(f_copy, SIGNAL(clicked()), f_textedit, SLOT(copy())); connect(f_paste, SIGNAL(clicked()), f_textedit, SLOT(paste())); connect(f_textedit, SIGNAL(copyAvailable(bool)), f_cut, SLOT(setEnabled(bool))); connect(f_textedit, SIGNAL(copyAvailable(bool)), f_copy, SLOT(setEnabled(bool))); #ifndef QT_NO_CLIPBOARD connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(slotClipboardDataChanged())); #endif // link f_link->setShortcut(Qt::CTRL + Qt::Key_L); connect(f_link, SIGNAL(clicked(bool)), this, SLOT(textLink(bool))); // bold, italic & underline f_bold->setShortcut(Qt::CTRL + Qt::Key_B); f_italic->setShortcut(Qt::CTRL + Qt::Key_I); f_underline->setShortcut(Qt::CTRL + Qt::Key_U); connect(f_bold, SIGNAL(clicked()), this, SLOT(textBold())); connect(f_italic, SIGNAL(clicked()), this, SLOT(textItalic())); connect(f_underline, SIGNAL(clicked()), this, SLOT(textUnderline())); connect(f_strikeout, SIGNAL(clicked()), this, SLOT(textStrikeout())); // lists f_list_bullet->setShortcut(Qt::CTRL + Qt::Key_Minus); f_list_ordered->setShortcut(Qt::CTRL + Qt::Key_Equal); connect(f_list_bullet, SIGNAL(clicked(bool)), this, SLOT(listBullet(bool))); connect(f_list_ordered, SIGNAL(clicked(bool)), this, SLOT(listOrdered(bool))); // indentation f_indent_dec->setShortcut(Qt::CTRL + Qt::Key_Comma); f_indent_inc->setShortcut(Qt::CTRL + Qt::Key_Period); connect(f_indent_inc, SIGNAL(clicked()), this, SLOT(increaseIndentation())); connect(f_indent_dec, SIGNAL(clicked()), this, SLOT(decreaseIndentation())); // font size QFontDatabase db; foreach(int size, db.standardSizes()) { f_fontsize->addItem(QString::number(size)); } connect(f_fontsize, SIGNAL(activated(QString)), this, SLOT(textSize(QString))); f_fontsize->setCurrentIndex(f_fontsize->findText(QString::number(QApplication::font().pointSize()))); // text background color QPixmap pix(16, 16); pix.fill(QApplication::palette().background().color()); f_bgcolor->setIcon(pix); connect(f_bgcolor, SIGNAL(clicked()), this, SLOT(textBgColor())); // images connect(f_image, SIGNAL(clicked()), this, SLOT(insertImage())); }