• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

knotes

  • sources
  • kde-4.14
  • kdepim
  • knotes
knoteedit.cpp
Go to the documentation of this file.
1 /*******************************************************************
2  KNotes -- Notes for the KDE project
3 
4  Copyright (c) 1997-2013, The KNotes Developers
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  as published by the Free Software Foundation; either version 2
9  of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *******************************************************************/
20 
21 #include "knoteedit.h"
22 #include "notes/knote.h"
23 #include "noteshared/editor/noteeditorutils.h"
24 #include "pimcommon/util/editorutil.h"
25 #include "knotesglobalconfig.h"
26 
27 #include <kaction.h>
28 #include <kactioncollection.h>
29 #include <kcolordialog.h>
30 #include <kdebug.h>
31 #include <kfontaction.h>
32 #include <kfontsizeaction.h>
33 #include <kicon.h>
34 #include <klocale.h>
35 #include <kmenu.h>
36 #include <kstandardaction.h>
37 #include <ktoggleaction.h>
38 #include <kurl.h>
39 
40 #include <QFont>
41 #include <QPixmap>
42 #include <QKeyEvent>
43 
44 static const short ICON_SIZE = 10;
45 
46 
47 KNoteEdit::KNoteEdit( const QString &configFile, KActionCollection *actions, QWidget *parent )
48  : PimCommon::CustomTextEdit(configFile, parent ),
49  m_note( 0 ),
50  m_actions( actions )
51 {
52  setAcceptDrops( true );
53  setWordWrapMode( QTextOption::WordWrap );
54  setLineWrapMode( WidgetWidth );
55  if ( acceptRichText() ) {
56  setAutoFormatting( AutoAll );
57  } else {
58  setAutoFormatting( AutoNone );
59  }
60 
61  // create the actions modifying the text format
62  m_textBold = new KToggleAction( KIcon( QLatin1String("format-text-bold") ), i18n( "Bold" ),
63  this );
64  actions->addAction( QLatin1String("format_bold"), m_textBold );
65  m_textBold->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_B ) );
66  m_textItalic = new KToggleAction( KIcon( QLatin1String("format-text-italic") ),
67  i18n( "Italic" ), this );
68  actions->addAction( QLatin1String("format_italic"), m_textItalic );
69  m_textItalic->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_I ) );
70  m_textUnderline = new KToggleAction( KIcon( QLatin1String("format-text-underline") ),
71  i18n( "Underline" ), this );
72  actions->addAction( QLatin1String("format_underline"), m_textUnderline );
73  m_textUnderline->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_U ) );
74  m_textStrikeOut = new KToggleAction( KIcon( QLatin1String("format-text-strikethrough") ),
75  i18n( "Strike Out" ), this );
76  actions->addAction( QLatin1String("format_strikeout"), m_textStrikeOut );
77  m_textStrikeOut->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_S ) );
78 
79  connect( m_textBold, SIGNAL(toggled(bool)), SLOT(textBold(bool)) );
80  connect( m_textItalic, SIGNAL(toggled(bool)),
81  SLOT(setFontItalic(bool)) );
82  connect( m_textUnderline, SIGNAL(toggled(bool)),
83  SLOT(setFontUnderline(bool)) );
84  connect( m_textStrikeOut, SIGNAL(toggled(bool)),
85  SLOT(textStrikeOut(bool)) );
86 
87  m_textAlignLeft = new KToggleAction( KIcon( QLatin1String("format-justify-left") ),
88  i18n( "Align Left" ), this );
89  actions->addAction( QLatin1String("format_alignleft"), m_textAlignLeft );
90  connect( m_textAlignLeft, SIGNAL(triggered(bool)),
91  SLOT(textAlignLeft()) );
92  m_textAlignLeft->setShortcut( QKeySequence( Qt::ALT + Qt::Key_L ) );
93  m_textAlignLeft->setChecked( true ); // just a dummy, will be updated later
94  m_textAlignCenter = new KToggleAction( KIcon( QLatin1String("format-justify-center") ),
95  i18n( "Align Center" ), this );
96  actions->addAction( QLatin1String("format_aligncenter"), m_textAlignCenter );
97  connect( m_textAlignCenter, SIGNAL(triggered(bool)),
98  SLOT(textAlignCenter()) );
99  m_textAlignCenter->setShortcut( QKeySequence( Qt::ALT + Qt::Key_C ) );
100  m_textAlignRight = new KToggleAction( KIcon( QLatin1String("format-justify-right") ),
101  i18n( "Align Right" ), this );
102  actions->addAction( QLatin1String("format_alignright"), m_textAlignRight );
103  connect( m_textAlignRight, SIGNAL(triggered(bool)),
104  SLOT(textAlignRight()) );
105  m_textAlignRight->setShortcut( QKeySequence( Qt::ALT + Qt::Key_R ) );
106  m_textAlignBlock = new KToggleAction( KIcon( QLatin1String("format-justify-fill") ),
107  i18n( "Align Block" ), this );
108  actions->addAction( QLatin1String("format_alignblock"), m_textAlignBlock );
109  connect( m_textAlignBlock, SIGNAL(triggered(bool)),
110  SLOT(textAlignBlock()) );
111  m_textAlignBlock->setShortcut( QKeySequence( Qt::ALT + Qt::Key_B ) );
112 
113  QActionGroup *group = new QActionGroup( this );
114  group->addAction( m_textAlignLeft );
115  group->addAction( m_textAlignCenter );
116  group->addAction( m_textAlignRight );
117  group->addAction( m_textAlignBlock );
118 
119  m_textList = new KToggleAction( KIcon( QLatin1String("format-list-ordered") ), i18n( "List" ), this );
120  actions->addAction( QLatin1String("format_list"), m_textList );
121  connect( m_textList, SIGNAL(triggered(bool)), SLOT(textList()) );
122 
123  m_textSuper = new KToggleAction( KIcon( QLatin1String("format-text-superscript") ),
124  i18n( "Superscript" ), this );
125  actions->addAction( QLatin1String("format_super"), m_textSuper );
126  connect( m_textSuper, SIGNAL(triggered(bool)),
127  SLOT(textSuperScript()) );
128  m_textSub = new KToggleAction( KIcon( QLatin1String("format-text-subscript") ), i18n( "Subscript" ),
129  this );
130  actions->addAction( QLatin1String("format_sub"), m_textSub );
131  connect( m_textSub, SIGNAL(triggered(bool)), SLOT(textSubScript()) );
132 
133 
134  m_textIncreaseIndent = new KAction( KIcon( QLatin1String("format-indent-more") ),
135  i18n( "Increase Indent" ), this );
136  actions->addAction( QLatin1String("format_increaseindent"), m_textIncreaseIndent );
137  m_textIncreaseIndent->setShortcut( QKeySequence( Qt::CTRL + Qt::ALT +
138  Qt::Key_I ) );
139  connect( m_textIncreaseIndent, SIGNAL(triggered(bool)),
140  SLOT(textIncreaseIndent()) );
141 
142  m_textDecreaseIndent = new KAction( KIcon( QLatin1String("format-indent-less") ),
143  i18n( "Decrease Indent" ), this );
144  actions->addAction( QLatin1String("format_decreaseindent"), m_textDecreaseIndent );
145  m_textDecreaseIndent->setShortcut( QKeySequence( Qt::CTRL + Qt::ALT +
146  Qt::Key_D ) );
147  connect( m_textDecreaseIndent, SIGNAL(triggered(bool)), SLOT(
148  textDecreaseIndent() ) );
149 
150  group = new QActionGroup( this );
151  group->addAction( m_textIncreaseIndent );
152  group->addAction( m_textDecreaseIndent );
153 
154  QPixmap pix( ICON_SIZE, ICON_SIZE );
155  pix.fill( Qt::black ); // just a dummy, gets updated before widget is shown
156  m_textColor = new KAction( i18n( "Text Color..." ), this );
157  actions->addAction( QLatin1String("format_color"), m_textColor );
158  m_textColor->setIcon( pix );
159  connect( m_textColor, SIGNAL(triggered(bool)), SLOT(slotTextColor()) );
160 
161  KAction *act = new KAction(KIcon( QLatin1String("format-fill-color") ), i18n( "Text Background Color..." ), this );
162  actions->addAction( QLatin1String("text_background_color"), act );
163  connect( act, SIGNAL(triggered(bool)), SLOT(slotTextBackgroundColor()) );
164 
165  m_textFont = new KFontAction( i18n( "Text Font" ), this );
166  actions->addAction( QLatin1String("format_font"), m_textFont );
167  connect( m_textFont, SIGNAL(triggered(QString)),
168  this, SLOT(setFontFamily(QString)) );
169 
170  m_textSize = new KFontSizeAction( i18n( "Text Size" ), this );
171  actions->addAction( QLatin1String("format_size"), m_textSize );
172  connect( m_textSize, SIGNAL(fontSizeChanged(int)),
173  this, SLOT(setTextFontSize(int)) );
174 
175  KAction *action = new KAction( i18n("Uppercase"), this );
176  actions->addAction( QLatin1String("change_to_uppercase"), action );
177  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotUpperCase()) );
178 
179  action = new KAction( i18n("Sentence case"), this );
180  actions->addAction( QLatin1String("change_to_sentencecase"), action );
181  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotSentenceCase()) );
182 
183  action = new KAction( i18n("Lowercase"), this );
184  actions->addAction( QLatin1String("change_to_lowercase"), action );
185  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotLowerCase()) );
186 
187  action = new KAction( KIcon( QLatin1String("knotes_date") ), i18n( "Insert Date" ), this );
188  actions->addAction( QLatin1String("insert_date"), action );
189  connect( action, SIGNAL(triggered(bool)), SLOT(slotInsertDate()) );
190 
191  action = new KAction( KIcon( QLatin1String("checkmark") ), i18n( "Insert Checkmark" ), this );
192  actions->addAction( QLatin1String("insert_checkmark"), action );
193  connect( action, SIGNAL(triggered(bool)), SLOT(slotInsertCheckMark()) );
194 
195  // QTextEdit connections
196  connect( this, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
197  SLOT(slotCurrentCharFormatChanged(QTextCharFormat)) );
198  connect( this, SIGNAL(cursorPositionChanged()),
199  SLOT(slotCursorPositionChanged()) );
200  slotCurrentCharFormatChanged( currentCharFormat() );
201  slotCursorPositionChanged();
202 }
203 
204 KNoteEdit::~KNoteEdit()
205 {
206 }
207 
208 void KNoteEdit::setColor(const QColor &fg, const QColor &bg)
209 {
210  mDefaultBackgroundColor = bg;
211  mDefaultForegroundColor = fg;
212 
213  QPalette p = palette();
214 
215  // better: from light(150) to light(100) to light(75)
216  // QLinearGradient g( width()/2, 0, width()/2, height() );
217  // g.setColorAt( 0, bg );
218  // g.setColorAt( 1, bg.dark(150) );
219 
220  p.setColor( QPalette::Window, bg );
221  // p.setBrush( QPalette::Window, g );
222  p.setColor( QPalette::Base, bg );
223  // p.setBrush( QPalette::Base, g );
224 
225  p.setColor( QPalette::WindowText, fg );
226  p.setColor( QPalette::Text, fg );
227 
228  p.setColor( QPalette::Button, bg.dark( 116 ) );
229  p.setColor( QPalette::ButtonText, fg );
230 
231  //p.setColor( QPalette::Highlight, bg );
232  //p.setColor( QPalette::HighlightedText, fg );
233 
234  // order: Light, Midlight, Button, Mid, Dark, Shadow
235 
236  // the shadow
237  p.setColor( QPalette::Light, bg.light( 180 ) );
238  p.setColor( QPalette::Midlight, bg.light( 150 ) );
239  p.setColor( QPalette::Mid, bg.light( 150 ) );
240  p.setColor( QPalette::Dark, bg.dark( 108 ) );
241  p.setColor( QPalette::Shadow, bg.dark( 116 ) );
242 
243  setPalette( p );
244 
245  setTextColor( fg );
246 }
247 
248 void KNoteEdit::setNote( KNote *_note )
249 {
250  m_note = _note;
251 }
252 
253 void KNoteEdit::slotSentenceCase()
254 {
255  QTextCursor cursor = textCursor();
256  PimCommon::EditorUtil editorUtil;
257  editorUtil.sentenceCase(cursor);
258 }
259 
260 void KNoteEdit::slotUpperCase()
261 {
262  QTextCursor cursor = textCursor();
263  PimCommon::EditorUtil editorUtil;
264  editorUtil.upperCase(cursor);
265 }
266 
267 void KNoteEdit::slotLowerCase()
268 {
269  QTextCursor cursor = textCursor();
270  PimCommon::EditorUtil editorUtil;
271  editorUtil.lowerCase(cursor);
272 }
273 
274 void KNoteEdit::mousePopupMenuImplementation(const QPoint& pos)
275 {
276  QMenu *popup = mousePopupMenu();
277  if ( popup ) {
278  QTextCursor cursor = textCursor();
279  if (!isReadOnly() ) {
280  if (cursor.hasSelection()) {
281  popup->addSeparator();
282  QMenu *changeCaseMenu = new QMenu(i18n("Change case..."), popup);
283  QAction * act = m_actions->action(QLatin1String("change_to_sentencecase"));
284  changeCaseMenu->addAction(act);
285  act = m_actions->action(QLatin1String("change_to_lowercase"));
286  changeCaseMenu->addAction(act);
287  act = m_actions->action(QLatin1String("change_to_uppercase"));
288  changeCaseMenu->addAction(act);
289  popup->addMenu(changeCaseMenu);
290  }
291  popup->addSeparator();
292  QAction *act = m_actions->action(QLatin1String("insert_date"));
293  popup->addAction(act);
294  popup->addSeparator();
295  act = m_actions->action(QLatin1String("insert_checkmark"));
296  popup->addAction(act);
297  }
298  aboutToShowContextMenu(popup);
299  popup->exec( pos );
300  delete popup;
301  }
302 }
303 
304 void KNoteEdit::setText( const QString& text )
305 {
306  if ( acceptRichText() && Qt::mightBeRichText( text ) ) {
307  setHtml( text );
308  } else {
309  setPlainText( text );
310  }
311 }
312 
313 QString KNoteEdit::text() const
314 {
315  if ( acceptRichText() ) {
316  return toHtml();
317  } else {
318  return toPlainText();
319  }
320 }
321 
322 void KNoteEdit::setTextFont( const QFont &font )
323 {
324  setCurrentFont( font );
325 
326  // make this font default so that if user deletes note content
327  // font is remembered
328  document()->setDefaultFont( font );
329 }
330 
331 void KNoteEdit::setTextFontSize( int size )
332 {
333  setFontPointSize( size );
334 }
335 
336 void KNoteEdit::setTabStop( int tabs )
337 {
338  QFontMetrics fm( font() );
339  setTabStopWidth( fm.width( QLatin1Char('x') ) * tabs );
340 }
341 
342 void KNoteEdit::setAutoIndentMode( bool newmode )
343 {
344  m_autoIndentMode = newmode;
345 }
346 
347 
350 void KNoteEdit::setRichText( bool f )
351 {
352  if ( f == acceptRichText() ) {
353  return;
354  }
355 
356  setAcceptRichText( f );
357 
358  if ( f ) {
359  setAutoFormatting( AutoAll );
360  } else {
361  setAutoFormatting( AutoNone );
362  }
363 
364  const QString t = toPlainText();
365  if ( f ) {
366  // if the note contains html source try to render it
367  if ( Qt::mightBeRichText( t ) ) {
368  setHtml( t );
369  } else {
370  setPlainText( t );
371  }
372 
373  enableRichTextActions(true);
374  } else {
375  setPlainText( t );
376  enableRichTextActions(false);
377  }
378 }
379 
380 void KNoteEdit::textBold( bool b )
381 {
382  if (!acceptRichText())
383  return;
384 
385  QTextCharFormat f;
386  f.setFontWeight( b ? QFont::Bold : QFont::Normal );
387  mergeCurrentCharFormat( f );
388 }
389 
390 void KNoteEdit::textStrikeOut( bool s )
391 {
392  if (!acceptRichText())
393  return;
394 
395  QTextCharFormat f;
396  f.setFontStrikeOut( s );
397  mergeCurrentCharFormat( f );
398 }
399 
400 void KNoteEdit::slotTextColor()
401 {
402  if (!acceptRichText())
403  return;
404 
405  if ( m_note )
406  m_note->setBlockSave( true );
407  QColor c = textColor();
408  if ( KColorDialog::getColor( c, mDefaultForegroundColor, this ) ) {
409  setTextColor( c.isValid() ? c : mDefaultForegroundColor);
410  }
411  if ( m_note )
412  m_note->setBlockSave( false );
413 }
414 
415 void KNoteEdit::slotTextBackgroundColor()
416 {
417  if (!acceptRichText())
418  return;
419 
420  if ( m_note )
421  m_note->setBlockSave( true );
422  QColor c = textBackgroundColor();
423  if ( KColorDialog::getColor( c, mDefaultBackgroundColor, this ) ) {
424  setTextBackgroundColor( c.isValid() ? c : mDefaultBackgroundColor );
425  }
426  if ( m_note )
427  m_note->setBlockSave( false );
428 }
429 
430 void KNoteEdit::textAlignLeft()
431 {
432  if (!acceptRichText())
433  return;
434  setAlignment( Qt::AlignLeft );
435  m_textAlignLeft->setChecked( true );
436 }
437 
438 void KNoteEdit::textAlignCenter()
439 {
440  if (!acceptRichText())
441  return;
442  setAlignment( Qt::AlignCenter );
443  m_textAlignCenter->setChecked( true );
444 }
445 
446 void KNoteEdit::textAlignRight()
447 {
448  if (!acceptRichText())
449  return;
450  setAlignment( Qt::AlignRight );
451  m_textAlignRight->setChecked( true );
452 }
453 
454 void KNoteEdit::textAlignBlock()
455 {
456  if (!acceptRichText())
457  return;
458  setAlignment( Qt::AlignJustify );
459  m_textAlignBlock->setChecked( true );
460 }
461 
462 void KNoteEdit::textList()
463 {
464  if (!acceptRichText())
465  return;
466  QTextCursor c = textCursor();
467  c.beginEditBlock();
468 
469  if ( m_textList->isChecked() ) {
470  QTextListFormat lf;
471  QTextBlockFormat bf = c.blockFormat();
472 
473  lf.setIndent( bf.indent() + 1 );
474  bf.setIndent( 0 );
475 
476  lf.setStyle( QTextListFormat::ListDisc );
477 
478  c.setBlockFormat( bf );
479  c.createList( lf );
480  } else {
481  QTextBlockFormat bf;
482  bf.setObjectIndex( -1 );
483  c.setBlockFormat( bf );
484 
485  }
486 
487  c.endEditBlock();
488 }
489 
490 void KNoteEdit::textSuperScript()
491 {
492  if (!acceptRichText())
493  return;
494  QTextCharFormat f;
495  if ( m_textSuper->isChecked() ) {
496  if ( m_textSub->isChecked() )
497  m_textSub->setChecked( false );
498  f.setVerticalAlignment( QTextCharFormat::AlignSuperScript );
499  } else {
500  f.setVerticalAlignment( QTextCharFormat::AlignNormal );
501  }
502  mergeCurrentCharFormat( f );
503 }
504 
505 void KNoteEdit::textSubScript()
506 {
507  if (!acceptRichText())
508  return;
509  QTextCharFormat f;
510  if ( m_textSub->isChecked() ) {
511  if ( m_textSuper->isChecked() )
512  m_textSuper->setChecked( false );
513  f.setVerticalAlignment( QTextCharFormat::AlignSubScript );
514  } else {
515  f.setVerticalAlignment( QTextCharFormat::AlignNormal );
516  }
517  mergeCurrentCharFormat( f );
518 }
519 
520 void KNoteEdit::textIncreaseIndent()
521 {
522  if (!acceptRichText())
523  return;
524  QTextBlockFormat f = textCursor().blockFormat();
525  f.setIndent( f.indent() + 1 );
526  textCursor().setBlockFormat( f );
527 }
528 
529 void KNoteEdit::textDecreaseIndent()
530 {
531  if (!acceptRichText())
532  return;
533  QTextBlockFormat f = textCursor().blockFormat();
534  short int curIndent = f.indent();
535 
536  if ( curIndent > 0 ) {
537  f.setIndent( curIndent - 1 );
538  }
539  textCursor().setBlockFormat( f );
540 }
541 
542 
545 void KNoteEdit::keyPressEvent( QKeyEvent *e )
546 {
547  KTextEdit::keyPressEvent( e );
548 
549  if ( m_autoIndentMode &&
550  ( ( e->key() == Qt::Key_Return ) || ( e->key() == Qt::Key_Enter ) ) ) {
551  autoIndent();
552  }
553 }
554 
555 void KNoteEdit::focusInEvent( QFocusEvent *e )
556 {
557  KTextEdit::focusInEvent( e );
558 
559  setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded );
560  setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
561 }
562 
563 void KNoteEdit::focusOutEvent( QFocusEvent *e )
564 {
565  setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
566  setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
567 
568  KTextEdit::focusOutEvent( e );
569 }
570 
573 void KNoteEdit::slotCurrentCharFormatChanged( const QTextCharFormat &f )
574 {
575  if (!acceptRichText())
576  return;
577 
578  // font changes
579  m_textFont->setFont( f.fontFamily() );
580  m_textSize->setFontSize( (f.fontPointSize()>0 ) ? ( int ) f.fontPointSize() :10);
581 
582  m_textBold->setChecked( f.font().bold() );
583  m_textItalic->setChecked( f.fontItalic() );
584  m_textUnderline->setChecked( f.fontUnderline() );
585  m_textStrikeOut->setChecked( f.fontStrikeOut() );
586 
587  // color changes
588  QPixmap pix( ICON_SIZE, ICON_SIZE );
589  pix.fill( f.foreground().color() );
590  m_textColor->QAction::setIcon( pix );
591 
592  // vertical alignment changes
593  QTextCharFormat::VerticalAlignment va = f.verticalAlignment();
594  if ( va == QTextCharFormat::AlignNormal ) {
595  m_textSuper->setChecked( false );
596  m_textSub->setChecked( false );
597  } else if ( va == QTextCharFormat::AlignSuperScript ) {
598  m_textSuper->setChecked( true );
599  } else if ( va == QTextCharFormat::AlignSubScript ) {
600  m_textSub->setChecked( true );
601  }
602 }
603 
604 
605 void KNoteEdit::slotCursorPositionChanged()
606 {
607  if (!acceptRichText())
608  return;
609  // alignment changes
610  const Qt::Alignment a = alignment();
611  if ( a & Qt::AlignLeft ) {
612  m_textAlignLeft->setChecked( true );
613  } else if ( a & Qt::AlignHCenter ) {
614  m_textAlignCenter->setChecked( true );
615  } else if ( a & Qt::AlignRight ) {
616  m_textAlignRight->setChecked( true );
617  } else if ( a & Qt::AlignJustify ) {
618  m_textAlignBlock->setChecked( true );
619  }
620 }
621 
624 void KNoteEdit::autoIndent()
625 {
626  QTextCursor c = textCursor();
627  QTextBlock b = c.block();
628 
629  QString string;
630  while ( ( b.previous().length() > 0 ) && string.trimmed().isEmpty() ) {
631  b = b.previous();
632  string = b.text();
633  }
634 
635  if ( string.trimmed().isEmpty() ) {
636  return;
637  }
638 
639  // This routine returns the whitespace before the first non white space
640  // character in string.
641  // It is assumed that string contains at least one non whitespace character
642  // ie \n \r \t \v \f and space
643  QString indentString;
644 
645  const int len = string.length();
646  int i = 0;
647  while ( i < len && string.at( i ).isSpace() ) {
648  indentString += string.at( i++ );
649  }
650 
651  if ( !indentString.isEmpty() ) {
652  c.insertText( indentString );
653  }
654 }
655 
656 void KNoteEdit::enableRichTextActions(bool enabled)
657 {
658  m_textColor->setEnabled( enabled );
659  m_textFont->setEnabled( enabled );
660  m_textSize->setEnabled( enabled );
661 
662  m_textBold->setEnabled( enabled );
663  m_textItalic->setEnabled( enabled );
664  m_textUnderline->setEnabled( enabled );
665  m_textStrikeOut->setEnabled( enabled );
666 
667  m_textAlignLeft->setEnabled( enabled );
668  m_textAlignCenter->setEnabled( enabled );
669  m_textAlignRight->setEnabled( enabled );
670  m_textAlignBlock->setEnabled( enabled );
671 
672  m_textList->setEnabled( enabled );
673  m_textSuper->setEnabled( enabled );
674  m_textSub->setEnabled( enabled );
675 
676  m_textIncreaseIndent->setEnabled( enabled );
677  m_textDecreaseIndent->setEnabled( enabled );
678 }
679 
680 void KNoteEdit::slotInsertDate()
681 {
682  NoteShared::NoteEditorUtils noteEditorUtils;
683  noteEditorUtils.insertDate(this);
684 }
685 
686 void KNoteEdit::slotInsertCheckMark()
687 {
688  QTextCursor cursor = textCursor();
689  NoteShared::NoteEditorUtils noteEditorUtils;
690  noteEditorUtils.addCheckmark(cursor);
691 }
692 
693 void KNoteEdit::setCursorPositionFromStart( int pos )
694 {
695  if ( pos > 0 ) {
696  QTextCursor cursor = textCursor();
697  //Fix html pos cursor
698  cursor.setPosition( qMin( pos, cursor.document()->characterCount ()-1) );
699  setTextCursor( cursor );
700  ensureCursorVisible();
701  }
702 }
703 
704 int KNoteEdit::cursorPositionFromStart() const
705 {
706  return textCursor().position();
707 }
KNoteEdit::textBold
void textBold(bool)
Definition: knoteedit.cpp:380
KNoteEdit::focusInEvent
void focusInEvent(QFocusEvent *)
Definition: knoteedit.cpp:555
QWidget
KNoteEdit::slotTextColor
void slotTextColor()
Definition: knoteedit.cpp:400
QTextBlock::previous
QTextBlock previous() const
QTextCursor
KNoteEdit::setTextFont
void setTextFont(const QFont &font)
Definition: knoteedit.cpp:322
KNoteEdit::slotTextBackgroundColor
void slotTextBackgroundColor()
Definition: knoteedit.cpp:415
QActionGroup
QColor::light
QColor light(int factor) const
KNoteEdit::textAlignLeft
void textAlignLeft()
Definition: knoteedit.cpp:430
QPixmap::fill
void fill(const QColor &color)
QPalette::setColor
void setColor(ColorGroup group, ColorRole role, const QColor &color)
QTextCharFormat::fontStrikeOut
bool fontStrikeOut() const
KNoteEdit::textAlignRight
void textAlignRight()
Definition: knoteedit.cpp:446
QTextDocument::characterCount
int characterCount() const
QTextCharFormat::fontUnderline
bool fontUnderline() const
KNoteEdit::slotInsertDate
void slotInsertDate()
Definition: knoteedit.cpp:680
QTextFormat::setObjectIndex
void setObjectIndex(int index)
QFont
QTextListFormat::setStyle
void setStyle(Style style)
QTextCursor::createList
QTextList * createList(const QTextListFormat &format)
QTextBlockFormat
QTextFormat::foreground
QBrush foreground() const
QTextCharFormat::fontItalic
bool fontItalic() const
KNote
Definition: knote.h:48
QMenu::addAction
void addAction(QAction *action)
KNoteEdit::textList
void textList()
Definition: knoteedit.cpp:462
KNoteEdit::setColor
void setColor(const QColor &fg, const QColor &bg)
Definition: knoteedit.cpp:208
QTextCharFormat::font
QFont font() const
ICON_SIZE
static const short ICON_SIZE
Definition: knoteedit.cpp:44
QActionGroup::addAction
QAction * addAction(QAction *action)
QTextCharFormat::setFontStrikeOut
void setFontStrikeOut(bool strikeOut)
QPoint
QFontMetrics
KNoteEdit::setAutoIndentMode
void setAutoIndentMode(bool newmode)
Definition: knoteedit.cpp:342
KNoteEdit::text
QString text() const
Definition: knoteedit.cpp:313
Qt::Alignment
typedef Alignment
KNoteInterface::setBlockSave
void setBlockSave(bool b)
Definition: knoteinterface.cpp:26
QColor::dark
QColor dark(int factor) const
QFont::bold
bool bold() const
QTextListFormat::setIndent
void setIndent(int indentation)
QBrush::color
const QColor & color() const
KNoteEdit::cursorPositionFromStart
int cursorPositionFromStart() const
Definition: knoteedit.cpp:704
KNoteEdit::setTextFontSize
void setTextFontSize(int)
Definition: knoteedit.cpp:331
KNoteEdit::setTabStop
void setTabStop(int tabs)
Definition: knoteedit.cpp:336
QTextCharFormat::fontPointSize
qreal fontPointSize() const
QTextCursor::hasSelection
bool hasSelection() const
knote.h
QTextBlockFormat::setIndent
void setIndent(int indentation)
KNoteEdit::setRichText
void setRichText(bool)
public slots
Definition: knoteedit.cpp:350
KNoteEdit::~KNoteEdit
~KNoteEdit()
Definition: knoteedit.cpp:204
KNoteEdit::KNoteEdit
KNoteEdit(const QString &configFile, KActionCollection *actions, QWidget *parent=0)
Definition: knoteedit.cpp:47
QTextCharFormat::setVerticalAlignment
void setVerticalAlignment(VerticalAlignment alignment)
KNoteEdit::focusOutEvent
void focusOutEvent(QFocusEvent *)
Definition: knoteedit.cpp:563
KNoteEdit::setText
void setText(const QString &text)
Definition: knoteedit.cpp:304
QTextCursor::endEditBlock
void endEditBlock()
QTextListFormat
QTextCursor::insertText
void insertText(const QString &text)
QString::isEmpty
bool isEmpty() const
KNoteEdit::mousePopupMenuImplementation
void mousePopupMenuImplementation(const QPoint &pos)
Definition: knoteedit.cpp:274
QTextCursor::document
QTextDocument * document() const
KNoteEdit::setNote
void setNote(KNote *_note)
Definition: knoteedit.cpp:248
QTextCursor::setBlockFormat
void setBlockFormat(const QTextBlockFormat &format)
QMenu::addSeparator
QAction * addSeparator()
QTextBlockFormat::indent
int indent() const
QString
KNoteEdit::keyPressEvent
void keyPressEvent(QKeyEvent *)
protected methods
Definition: knoteedit.cpp:545
KNoteEdit::textSubScript
void textSubScript()
Definition: knoteedit.cpp:505
QColor
QMenu::exec
QAction * exec()
KNoteEdit::textStrikeOut
void textStrikeOut(bool)
Definition: knoteedit.cpp:390
QPixmap
QTextCharFormat
QKeyEvent::key
int key() const
QTextCursor::block
QTextBlock block() const
QMenu
QLatin1Char
QTextCursor::beginEditBlock
void beginEditBlock()
QFontMetrics::width
int width(const QString &text, int len) const
QTextBlock::text
QString text() const
QTextCharFormat::setFontWeight
void setFontWeight(int weight)
QKeyEvent
QLatin1String
QKeySequence
QTextBlock
QMenu::addMenu
QAction * addMenu(QMenu *menu)
QString::at
const QChar at(int position) const
QTextCharFormat::verticalAlignment
VerticalAlignment verticalAlignment() const
QAction
KNoteEdit::textAlignCenter
void textAlignCenter()
Definition: knoteedit.cpp:438
QString::length
int length() const
Qt::mightBeRichText
bool mightBeRichText(const QString &text)
KNoteEdit::textDecreaseIndent
void textDecreaseIndent()
Definition: knoteedit.cpp:529
KNoteEdit::textSuperScript
void textSuperScript()
Definition: knoteedit.cpp:490
knoteedit.h
KNoteEdit::textIncreaseIndent
void textIncreaseIndent()
Definition: knoteedit.cpp:520
KNoteEdit::textAlignBlock
void textAlignBlock()
Definition: knoteedit.cpp:454
QTextCharFormat::fontFamily
QString fontFamily() const
QFocusEvent
KNoteEdit::setCursorPositionFromStart
void setCursorPositionFromStart(int pos)
Definition: knoteedit.cpp:693
QTextCursor::blockFormat
QTextBlockFormat blockFormat() const
QPalette
QColor::isValid
bool isValid() const
QTextBlock::length
int length() const
QTextCursor::setPosition
void setPosition(int pos, MoveMode m)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:28 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knotes

Skip menu "knotes"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal