• 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
  • notes
knote.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 "knote.h"
22 #include "noteshared/noteutils.h"
23 #include "alarms/notealarmdialog.h"
24 #include "configdialog/knotesimpleconfigdialog.h"
25 #include "print/knoteprintselectthemedialog.h"
26 #include "knotes/notes/knotebutton.h"
27 #include "utils/knoteutils.h"
28 #include "configdialog/knoteconfigdialog.h"
29 #include "knoteedit.h"
30 #include "print/knoteprinter.h"
31 #include "print/knoteprintobject.h"
32 #include "knotesglobalconfig.h"
33 
34 #include "knotedisplaysettings.h"
35 
36 #include "noteshared/attributes/notelockattribute.h"
37 #include "noteshared/attributes/notedisplayattribute.h"
38 #include "noteshared/attributes/notealarmattribute.h"
39 
40 #include "pimcommon/baloodebug/baloodebugdialog.h"
41 
42 #include <KMime/KMimeMessage>
43 
44 #include <kaction.h>
45 #include <kactioncollection.h>
46 #include <kapplication.h>
47 #include <kcombobox.h>
48 #include <kfiledialog.h>
49 #include <kglobalsettings.h>
50 #include <kicon.h>
51 #include <kiconeffect.h>
52 #include <kiconloader.h>
53 #include <kinputdialog.h>
54 #include <klocale.h>
55 #include <kmenu.h>
56 #include <kmessagebox.h>
57 #include <kselectaction.h>
58 #include <kstandardaction.h>
59 #include <kstandarddirs.h>
60 #include <ktoggleaction.h>
61 #include <ktoolbar.h>
62 #include <kwindowsystem.h>
63 #include <kxmlguibuilder.h>
64 #include <kxmlguifactory.h>
65 #include <netwm.h>
66 #include <KPrintPreview>
67 
68 #include <Akonadi/ItemModifyJob>
69 
70 #include <QBoxLayout>
71 #include <QCheckBox>
72 #include <QFile>
73 #include <QHBoxLayout>
74 #include <QLabel>
75 #include <QPixmap>
76 #include <QSize>
77 #include <QSizeGrip>
78 #include <QTextStream>
79 #include <QVBoxLayout>
80 #include <QDesktopWidget>
81 #include <QPointer>
82 #include <QFocusEvent>
83 #include <QTcpServer>
84 
85 #ifdef Q_WS_X11
86 #include <fixx11h.h>
87 #include <QX11Info>
88 #endif
89 
90 //#define DEBUG_SAVE_NOTE 1
91 
92 KNote::KNote(const QDomDocument& buildDoc, const Akonadi::Item &item, bool allowDebugBaloo, QWidget *parent )
93  : QFrame( parent, Qt::FramelessWindowHint ),
94  mItem(item),
95  m_label( 0 ),
96  m_grip( 0 ),
97  m_button( 0 ),
98  m_tool( 0 ),
99  m_editor( 0 ),
100  m_kwinConf( KSharedConfig::openConfig( QLatin1String("kwinrc") ) ),
101  mDisplayAttribute(new KNoteDisplaySettings),
102  mAllowDebugBaloo(allowDebugBaloo)
103 {
104  if ( mItem.hasAttribute<NoteShared::NoteDisplayAttribute>()) {
105  mDisplayAttribute->setDisplayAttribute(mItem.attribute<NoteShared::NoteDisplayAttribute>());
106  } else {
107  setDisplayDefaultValue();
108  //save default display value
109  }
110  setAcceptDrops( true );
111  setAttribute( Qt::WA_DeleteOnClose );
112  setDOMDocument( buildDoc );
113  setXMLFile( componentData().componentName() + QLatin1String("ui.rc"), false, false );
114 
115  // create the main layout
116  m_noteLayout = new QVBoxLayout( this );
117  m_noteLayout->setMargin( 0 );
118  createActions();
119 
120  buildGui();
121  prepare();
122 }
123 
124 KNote::~KNote()
125 {
126  delete mDisplayAttribute;
127 }
128 
129 void KNote::setDisplayDefaultValue()
130 {
131  KNoteUtils::setDefaultValue(mItem);
132  Akonadi::ItemModifyJob *job = new Akonadi::ItemModifyJob(mItem);
133 #ifdef DEBUG_SAVE_NOTE
134  qDebug()<<"setDisplayDefaultValue slotNoteSaved(KJob*)";
135 #endif
136  connect( job, SIGNAL(result(KJob*)), SLOT(slotNoteSaved(KJob*)) );
137 }
138 
139 void KNote::setChangeItem(const Akonadi::Item &item, const QSet<QByteArray> &set)
140 {
141  mItem = item;
142  if ( item.hasAttribute<NoteShared::NoteDisplayAttribute>()) {
143  mDisplayAttribute->setDisplayAttribute(item.attribute<NoteShared::NoteDisplayAttribute>());
144  }
145  if (set.contains("ATR:KJotsLockAttribute")) {
146  m_editor->setReadOnly(item.hasAttribute<NoteShared::NoteLockAttribute>());
147  }
148  if (set.contains("PLD:RFC822")) {
149  loadNoteContent(item);
150  }
151  if (set.contains("ATR:NoteDisplayAttribute")) {
152  qDebug()<<" ATR:NoteDisplayAttribute";
153  slotApplyConfig();
154  }
155  //TODO update display/content etc.
156  updateLabelAlignment();
157 }
158 
159 void KNote::slotKill( bool force )
160 {
161  if ( !force &&
162  ( KMessageBox::warningContinueCancel( this,
163  i18n( "<qt>Do you really want to delete note <b>%1</b>?</qt>",
164  m_label->text() ),
165  i18n( "Confirm Delete" ),
166  KGuiItem( i18n( "&Delete" ), QLatin1String("edit-delete") ),
167  KStandardGuiItem::cancel(),
168  QLatin1String("ConfirmDeleteNote") ) != KMessageBox::Continue ) ) {
169  return;
170  }
171 
172  Q_EMIT sigKillNote( mItem.id() );
173 }
174 
175 
176 // -------------------- public member functions -------------------- //
177 
178 void KNote::saveNote(bool force, bool sync)
179 {
180  if (!force && !m_editor->document()->isModified())
181  return;
182  bool needToSave = false;
183  NoteShared::NoteDisplayAttribute *attribute = mItem.attribute<NoteShared::NoteDisplayAttribute>( Akonadi::Entity::AddIfMissing );
184  const QPoint notePosition = pos();
185  if (attribute->position() != notePosition) {
186  needToSave = true;
187  attribute->setPosition(notePosition);
188  }
189  const QSize currentSize(QSize(width(), height()));
190  if (attribute->size() != currentSize) {
191  needToSave = true;
192  attribute->setSize(currentSize);
193  }
194 #ifdef Q_WS_X11
195  NETWinInfo wm_client( QX11Info::display(), winId(),
196  QX11Info::appRootWindow(), NET::WMDesktop );
197  if ( ( wm_client.desktop() == NETWinInfo::OnAllDesktops ) ||
198  ( wm_client.desktop() > 0 ) ) {
199  const int desktopNumber = wm_client.desktop();
200  if (attribute->desktop() != desktopNumber) {
201  needToSave = true;
202  attribute->setDesktop( desktopNumber );
203  }
204  }
205 #endif
206  if (m_editor->document()->isModified()) {
207  needToSave = true;
208  saveNoteContent();
209  }
210  if (needToSave) {
211 #ifdef DEBUG_SAVE_NOTE
212  qDebug()<<"save Note slotClose() slotNoteSaved(KJob*) : sync"<<sync;
213 #endif
214  Akonadi::ItemModifyJob *job = new Akonadi::ItemModifyJob(mItem);
215  if (sync) {
216  job->exec();
217  } else {
218 #ifdef DEBUG_SAVE_NOTE
219  qDebug()<<"save Note slotClose() slotNoteSaved(KJob*)";
220 #endif
221  connect( job, SIGNAL(result(KJob*)), SLOT(slotNoteSaved(KJob*)) );
222  }
223  }
224 }
225 
226 void KNote::slotNoteSaved(KJob *job)
227 {
228  qDebug()<<" void KNote::slotNoteSaved(KJob *job)";
229  if ( job->error() ) {
230  qDebug()<<" problem during save note:"<<job->errorString();
231  } else {
232  m_editor->document()->setModified( false );
233  }
234 }
235 
236 Akonadi::Item::Id KNote::noteId() const
237 {
238  return mItem.id();
239 }
240 
241 QString KNote::name() const
242 {
243  return m_label->text();
244 }
245 
246 QString KNote::text() const
247 {
248  return m_editor->text();
249 }
250 
251 void KNote::setName( const QString& name )
252 {
253  m_label->setText( name );
254  updateLabelAlignment();
255 
256  if ( m_editor ) { // not called from CTOR?
257  saveNote();
258  }
259 #ifdef Q_WS_X11
260  // set the window's name for the taskbar entry to be more helpful (#58338)
261  NETWinInfo note_win( QX11Info::display(), winId(), QX11Info::appRootWindow(),
262  NET::WMDesktop );
263  note_win.setName( name.toUtf8() );
264 #endif
265 
266  emit sigNameChanged(name);
267 }
268 
269 void KNote::setText( const QString& text )
270 {
271  m_editor->setText( text );
272 
273  saveNote();
274 }
275 
276 bool KNote::isDesktopAssigned() const
277 {
278  return mDisplayAttribute->rememberDesktop();
279 }
280 
281 bool KNote::isModified() const
282 {
283  return m_editor->document()->isModified();
284 }
285 
286 // ------------------ private slots (menu actions) ------------------ //
287 
288 void KNote::slotRename()
289 {
290  // pop up dialog to get the new name
291  bool ok;
292  const QString oldName = m_label->text();
293  const QString newName = KInputDialog::getText( QString::null, //krazy:exclude=nullstrassign for old broken gcc
294  i18n( "Please enter the new name:" ), m_label->text(), &ok, this );
295  if ( !ok || (oldName == newName) ) { // handle cancel
296  return;
297  }
298 
299  setName( newName );
300 }
301 
302 void KNote::slotUpdateReadOnly()
303 {
304  const bool readOnly = m_readOnly->isChecked();
305 
306  m_editor->setReadOnly( readOnly );
307 
308  if (mItem.hasAttribute<NoteShared::NoteLockAttribute>()) {
309  if (!readOnly) {
310  mItem.removeAttribute<NoteShared::NoteLockAttribute>();
311  }
312  } else {
313  if (readOnly) {
314  mItem.attribute<NoteShared::NoteLockAttribute>( Akonadi::Entity::AddIfMissing );
315  }
316  }
317  if (!mBlockSave) {
318  updateAllAttributes();
319  Akonadi::ItemModifyJob *job = new Akonadi::ItemModifyJob(mItem);
320 #ifdef DEBUG_SAVE_NOTE
321  qDebug()<<" void KNote::slotUpdateReadOnly() slotNoteSaved(KJob*)";
322 #endif
323  connect( job, SIGNAL(result(KJob*)), SLOT(slotNoteSaved(KJob*)) );
324  }
325 
326 
327  // enable/disable actions accordingly
328  actionCollection()->action( QLatin1String("configure_note") )->setEnabled( !readOnly );
329  actionCollection()->action( QLatin1String("delete_note") )->setEnabled( !readOnly );
330  actionCollection()->action( QLatin1String("format_bold") )->setEnabled( !readOnly );
331  actionCollection()->action( QLatin1String("format_italic") )->setEnabled( !readOnly );
332  actionCollection()->action( QLatin1String("format_underline") )->setEnabled( !readOnly );
333  actionCollection()->action( QLatin1String("format_strikeout") )->setEnabled( !readOnly );
334  actionCollection()->action( QLatin1String("format_alignleft") )->setEnabled( !readOnly );
335  actionCollection()->action( QLatin1String("format_aligncenter") )->setEnabled( !readOnly );
336  actionCollection()->action( QLatin1String("format_alignright") )->setEnabled( !readOnly );
337  actionCollection()->action( QLatin1String("format_alignblock" ))->setEnabled( !readOnly );
338  actionCollection()->action( QLatin1String("format_list") )->setEnabled( !readOnly );
339  actionCollection()->action( QLatin1String("format_super") )->setEnabled( !readOnly );
340  actionCollection()->action( QLatin1String("format_sub") )->setEnabled( !readOnly );
341  actionCollection()->action( QLatin1String("format_increaseindent" ))->setEnabled( !readOnly );
342  actionCollection()->action( QLatin1String("format_decreaseindent") )->setEnabled( !readOnly );
343  actionCollection()->action( QLatin1String("text_background_color") )->setEnabled( !readOnly );
344  actionCollection()->action( QLatin1String("format_size") )->setEnabled( !readOnly );
345  actionCollection()->action( QLatin1String("format_color") )->setEnabled( !readOnly );
346  actionCollection()->action( QLatin1String("rename_note") )->setEnabled( !readOnly);
347  actionCollection()->action( QLatin1String("set_alarm") )->setEnabled( !readOnly);
348  m_keepAbove->setEnabled( !readOnly);
349  m_keepBelow->setEnabled( !readOnly);
350 
351 #ifdef Q_WS_X11
352  m_toDesktop->setEnabled( !readOnly);
353 #endif
354 
355  updateFocus();
356 }
357 
358 void KNote::updateAllAttributes()
359 {
360  NoteShared::NoteDisplayAttribute *attribute = mItem.attribute<NoteShared::NoteDisplayAttribute>(Akonadi::Entity::AddIfMissing);
361 #ifdef Q_WS_X11
362  NETWinInfo wm_client( QX11Info::display(), winId(),
363  QX11Info::appRootWindow(), NET::WMDesktop );
364  if ( ( wm_client.desktop() == NETWinInfo::OnAllDesktops ) ||
365  ( wm_client.desktop() > 0 ) ) {
366  attribute->setDesktop(wm_client.desktop());
367  }
368 #endif
369  saveNoteContent();
370  attribute->setIsHidden(true);
371  attribute->setPosition(pos());
372  const QSize currentSize(QSize(width(), height()));
373  if (attribute->size() != currentSize) {
374  attribute->setSize(currentSize);
375  }
376 }
377 
378 void KNote::slotClose()
379 {
380  updateAllAttributes();
381  m_editor->clearFocus();
382  Akonadi::ItemModifyJob *job = new Akonadi::ItemModifyJob(mItem);
383 #ifdef DEBUG_SAVE_NOTE
384  qDebug()<<"slotClose() slotNoteSaved(KJob*)";
385 #endif
386  connect( job, SIGNAL(result(KJob*)), SLOT(slotNoteSaved(KJob*)) );
387  hide();
388 }
389 
390 void KNote::slotSetAlarm()
391 {
392  QPointer<NoteShared::NoteAlarmDialog> dlg = new NoteShared::NoteAlarmDialog( name(), this );
393  if (mItem.hasAttribute<NoteShared::NoteAlarmAttribute>()) {
394  dlg->setAlarm(mItem.attribute<NoteShared::NoteAlarmAttribute>()->dateTime());
395  }
396  if ( dlg->exec() ) {
397  bool needToModify = true;
398  KDateTime dateTime = dlg->alarm();
399  if (dateTime.isValid()) {
400  NoteShared::NoteAlarmAttribute *attribute = mItem.attribute<NoteShared::NoteAlarmAttribute>( Akonadi::Entity::AddIfMissing );
401  attribute->setDateTime(dateTime);
402  } else {
403  if (mItem.hasAttribute<NoteShared::NoteAlarmAttribute>()) {
404  mItem.removeAttribute<NoteShared::NoteAlarmAttribute>();
405  } else {
406  needToModify = false;
407  }
408  }
409  if (needToModify) {
410  //Verify it!
411  saveNoteContent();
412  Akonadi::ItemModifyJob *job = new Akonadi::ItemModifyJob(mItem);
413 #ifdef DEBUG_SAVE_NOTE
414  qDebug()<<"setAlarm() slotNoteSaved(KJob*)";
415 #endif
416  connect( job, SIGNAL(result(KJob*)), SLOT(slotNoteSaved(KJob*)) );
417  }
418  }
419  delete dlg;
420 }
421 
422 void KNote::saveNoteContent()
423 {
424  KMime::Message::Ptr message = mItem.payload<KMime::Message::Ptr>();
425  const QByteArray encoding( "utf-8" );
426  message->subject( true )->fromUnicodeString( name(), encoding );
427  message->contentType( true )->setMimeType( m_editor->acceptRichText() ? "text/html" : "text/plain" );
428  message->contentType()->setCharset(encoding);
429  message->contentTransferEncoding(true)->setEncoding(KMime::Headers::CEquPr);
430  message->date( true )->setDateTime( KDateTime::currentLocalDateTime() );
431  message->mainBodyPart()->fromUnicodeString( text().isEmpty() ? QString::fromLatin1( " " ) : text());
432 
433  KMime::Headers::Generic *header = new KMime::Headers::Generic( "X-Cursor-Position", message.get(), QString::number( m_editor->cursorPositionFromStart() ), "utf-8" );
434  message->setHeader( header );
435 
436  message->assemble();
437 
438  mItem.setPayload( message );
439 }
440 
441 void KNote::slotPreferences()
442 {
443  // create a new preferences dialog...
444  QPointer<KNoteSimpleConfigDialog> dialog = new KNoteSimpleConfigDialog( name(), this );
445  NoteShared::NoteDisplayAttribute *attribute = mItem.attribute<NoteShared::NoteDisplayAttribute>( Akonadi::Entity::AddIfMissing );
446  attribute->setSize(QSize(width(), height()));
447 
448  dialog->load(mItem, m_editor->acceptRichText());
449  connect( this, SIGNAL(sigNameChanged(QString)), dialog,
450  SLOT(slotUpdateCaption(QString)) );
451  if (dialog->exec() ) {
452  bool isRichText;
453  dialog->save(mItem, isRichText);
454  m_editor->setAcceptRichText(isRichText);
455  saveNoteContent();
456  Akonadi::ItemModifyJob *job = new Akonadi::ItemModifyJob(mItem);
457 #ifdef DEBUG_SAVE_NOTE
458  qDebug()<<"slotPreference slotNoteSaved(KJob*)";
459 #endif
460  connect( job, SIGNAL(result(KJob*)), SLOT(slotNoteSaved(KJob*)) );
461  }
462  delete dialog;
463 }
464 
465 void KNote::slotSend()
466 {
467  NoteShared::NoteUtils noteUtils;
468  noteUtils.sendToNetwork(this, name(), text());
469 }
470 
471 void KNote::slotMail()
472 {
473  NoteShared::NoteUtils noteUtils;
474  noteUtils.sendToMail(this, m_label->text(), m_editor->toPlainText());
475 }
476 
477 void KNote::slotPrint()
478 {
479  print(false);
480 }
481 
482 void KNote::slotPrintPreview()
483 {
484  print(true);
485 }
486 
487 void KNote::print(bool preview)
488 {
489  QString content;
490  if ( !Qt::mightBeRichText( m_editor->text() ) ) {
491  content = Qt::convertFromPlainText( m_editor->text() );
492  } else {
493  content = m_editor->text();
494  }
495  if ( isModified() ) {
496  saveNote();
497  }
498 
499  KNotesGlobalConfig *globalConfig = KNotesGlobalConfig::self();
500  QString printingTheme = globalConfig->theme();
501  if (printingTheme.isEmpty()) {
502  QPointer<KNotePrintSelectThemeDialog> dlg = new KNotePrintSelectThemeDialog(this);
503  if (dlg->exec()) {
504  printingTheme = dlg->selectedTheme();
505  }
506  delete dlg;
507  }
508  if (!printingTheme.isEmpty()) {
509  KNotePrinter printer(this);
510  QList<KNotePrintObject*> lst;
511  lst.append(new KNotePrintObject(mItem));
512  printer.setDefaultFont( mDisplayAttribute->font() );
513  printer.printNotes( lst, printingTheme, preview );
514  }
515 }
516 
517 void KNote::slotSaveAs()
518 {
519  // TODO: where to put pdf file support? In the printer??!??!
520  QCheckBox *convert = 0;
521  if ( m_editor->acceptRichText() ) {
522  convert = new QCheckBox( 0 );
523  convert->setText( i18n( "Save note as plain text" ) );
524  }
525  KUrl url;
526  QPointer<KFileDialog> dlg = new KFileDialog( url, QString(), this, convert );
527  dlg->setOperationMode( KFileDialog::Saving );
528  dlg->setCaption( i18n( "Save As" ) );
529  if( !dlg->exec() ) {
530  delete dlg;
531  return;
532  }
533 
534  const QString fileName = dlg->selectedFile();
535  const bool htmlFormatAndSaveAsHtml = (convert && !convert->isChecked());
536  delete dlg;
537  if ( fileName.isEmpty() ) {
538  return;
539  }
540 
541  QFile file( fileName );
542 
543  if ( file.exists() &&
544  KMessageBox::warningContinueCancel( this,
545  i18n( "<qt>A file named <b>%1</b> already exists.<br />"
546  "Are you sure you want to overwrite it?</qt>",
547  QFileInfo( file ).fileName() ) ) != KMessageBox::Continue ) {
548  return;
549  }
550 
551  if ( file.open( QIODevice::WriteOnly ) ) {
552  QTextStream stream( &file );
553  if ( htmlFormatAndSaveAsHtml ) {
554  QString htmlStr = m_editor->toHtml();
555  htmlStr.replace(QLatin1String("meta name=\"qrichtext\" content=\"1\""), QLatin1String("meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\""));
556  stream << htmlStr;
557  } else {
558  stream << m_editor->toPlainText();
559  }
560  }
561 }
562 
563 void KNote::slotPopupActionToDesktop( int id )
564 {
565  toDesktop( id - 1 ); // compensate for the menu separator, -1 == all desktops
566 }
567 
568 
569 // ------------------ private slots (configuration) ------------------ //
570 
571 void KNote::slotApplyConfig()
572 {
573  m_label->setFont( mDisplayAttribute->titleFont() );
574  m_editor->setTextFont( mDisplayAttribute->font() );
575  m_editor->setTabStop( mDisplayAttribute->tabSize() );
576  m_editor->setAutoIndentMode( mDisplayAttribute->autoIndent() );
577 
578  setColor( mDisplayAttribute->foregroundColor(), mDisplayAttribute->backgroundColor() );
579 
580  updateLayout();
581  slotUpdateShowInTaskbar();
582  resize(mDisplayAttribute->size());
583 }
584 
585 
586 void KNote::slotKeepAbove()
587 {
588  if ( m_keepBelow->isChecked() ) {
589  m_keepBelow->setChecked( false );
590  }
591  slotUpdateKeepAboveBelow();
592 }
593 
594 void KNote::slotKeepBelow()
595 {
596  if ( m_keepAbove->isChecked() ) {
597  m_keepAbove->setChecked( false );
598  }
599  slotUpdateKeepAboveBelow();
600 }
601 
602 void KNote::slotUpdateKeepAboveBelow(bool save)
603 {
604 #ifdef Q_WS_X11
605  unsigned long state = KWindowInfo( KWindowSystem::windowInfo( winId(), NET::WMState ) ).state();
606 #else
607  unsigned long state = 0; // neutral state, TODO
608 #endif
609  NoteShared::NoteDisplayAttribute *attribute = mItem.attribute<NoteShared::NoteDisplayAttribute>(Akonadi::Entity::AddIfMissing);
610  if ( m_keepAbove->isChecked() ) {
611  attribute->setKeepAbove(true);
612  attribute->setKeepBelow(false);
613  KWindowSystem::setState( winId(), state | NET::KeepAbove );
614  } else if ( m_keepBelow->isChecked() ) {
615  attribute->setKeepAbove(false);
616  attribute->setKeepBelow(true);
617  KWindowSystem::setState( winId(), state | NET::KeepBelow );
618  } else {
619  attribute->setKeepAbove(false);
620  attribute->setKeepBelow(false);
621  KWindowSystem::clearState( winId(), NET::KeepAbove );
622  KWindowSystem::clearState( winId(), NET::KeepBelow );
623  }
624  if (!mBlockSave && save) {
625  saveNoteContent();
626  Akonadi::ItemModifyJob *job = new Akonadi::ItemModifyJob(mItem);
627 #ifdef DEBUG_SAVE_NOTE
628  qDebug()<<"slotUpdateKeepAboveBelow slotNoteSaved(KJob*)";
629 #endif
630  connect( job, SIGNAL(result(KJob*)), SLOT(slotNoteSaved(KJob*)) );
631  }
632 }
633 
634 void KNote::slotUpdateShowInTaskbar()
635 {
636 #ifdef Q_WS_X11
637  if ( !mDisplayAttribute->showInTaskbar() ) {
638  KWindowSystem::setState( winId(), KWindowSystem::windowInfo( winId(),
639  NET::WMState ).state() | NET::SkipTaskbar );
640  } else {
641  KWindowSystem::clearState( winId(), NET::SkipTaskbar );
642  }
643 #endif
644 }
645 
646 void KNote::slotUpdateDesktopActions()
647 {
648 #ifdef Q_WS_X11
649  m_toDesktop->clear();
650  NETRootInfo wm_root( QX11Info::display(), NET::NumberOfDesktops |
651  NET::DesktopNames );
652  NETWinInfo wm_client( QX11Info::display(), winId(),
653  QX11Info::appRootWindow(), NET::WMDesktop );
654 
655  KAction *act = m_toDesktop->addAction(i18n( "&All Desktops" ));
656  if (wm_client.desktop() == NETWinInfo::OnAllDesktops) {
657  act->setChecked(true);
658  }
659  QAction *separator = new QAction(m_toDesktop);
660  separator->setSeparator(true);
661  m_toDesktop->addAction(separator);
662  const int count = wm_root.numberOfDesktops();
663  for ( int n = 1; n <= count; ++n ) {
664  KAction *desktopAct = m_toDesktop->addAction(QString::fromLatin1( "&%1 %2" ).arg( n ).arg(QString::fromUtf8( wm_root.desktopName( n ) ) ));
665  if (wm_client.desktop() == n) {
666  desktopAct->setChecked(true);
667  }
668  }
669 #endif
670 }
671 
672 
673 // -------------------- private methods -------------------- //
674 
675 void KNote::buildGui()
676 {
677  createNoteHeader();
678  createNoteEditor(QString());
679 
680  KXMLGUIBuilder builder( this );
681  KXMLGUIFactory factory( &builder, this );
682  factory.addClient( this );
683 
684  m_menu = dynamic_cast<KMenu*>( factory.container( QLatin1String("note_context"), this ) );
685  m_tool = dynamic_cast<KToolBar*>( factory.container( QLatin1String("note_tool"), this ) );
686 
687  createNoteFooter();
688 }
689 
690 void KNote::createActions()
691 {
692  // create the menu items for the note - not the editor...
693  // rename, mail, print, save as, insert date, alarm, close, delete, new note
694  KAction *action;
695 
696  action = new KAction( KIcon( QLatin1String("document-new") ), i18n( "New" ), this );
697  actionCollection()->addAction( QLatin1String("new_note"), action );
698  connect( action, SIGNAL(triggered(bool)), SLOT(slotRequestNewNote()) );
699 
700  action = new KAction( KIcon( QLatin1String("edit-rename") ), i18n( "Rename..." ), this );
701  actionCollection()->addAction( QLatin1String("rename_note"), action );
702  connect( action, SIGNAL(triggered(bool)), SLOT(slotRename()) );
703 
704  m_readOnly = new KToggleAction( KIcon( QLatin1String("object-locked") ),
705  i18n( "Lock" ), this );
706  actionCollection()->addAction( QLatin1String("lock_note"), m_readOnly );
707  connect( m_readOnly, SIGNAL(triggered(bool)),
708  SLOT(slotUpdateReadOnly()) );
709  m_readOnly->setCheckedState( KGuiItem( i18n( "Unlock" ), QLatin1String("object-unlocked") ) );
710 
711  action = new KAction( KIcon( QLatin1String("window-close") ), i18n( "Hide" ), this );
712  actionCollection()->addAction( QLatin1String("hide_note"), action );
713  connect( action, SIGNAL(triggered(bool)), SLOT(slotClose()) );
714  action->setShortcut( QKeySequence( Qt::Key_Escape ) );
715 
716  action = new KAction( KIcon( QLatin1String("edit-delete") ), i18n( "Delete" ), this );
717  actionCollection()->addAction( QLatin1String("delete_note"), action );
718  connect( action, SIGNAL(triggered(bool)), SLOT(slotKill()),Qt::QueuedConnection );
719 
720  action = new KAction( KIcon( QLatin1String("knotes_alarm") ), i18n( "Set Alarm..." ),
721  this );
722  actionCollection()->addAction( QLatin1String("set_alarm"), action );
723  connect( action, SIGNAL(triggered(bool)), SLOT(slotSetAlarm()) );
724 
725  action = new KAction( KIcon( QLatin1String("network-wired") ), i18n( "Send..." ), this );
726  actionCollection()->addAction( QLatin1String("send_note"), action );
727  connect( action, SIGNAL(triggered(bool)), SLOT(slotSend()) );
728 
729  action = new KAction( KIcon( QLatin1String("mail-send") ), i18n( "Mail..." ), this );
730  actionCollection()->addAction( QLatin1String("mail_note"), action );
731  connect( action, SIGNAL(triggered(bool)), SLOT(slotMail()) );
732 
733  action = new KAction( KIcon( QLatin1String("document-save-as") ), i18n( "Save As..." ),
734  this );
735  actionCollection()->addAction( QLatin1String("save_note"), action );
736  connect( action, SIGNAL(triggered(bool)), SLOT(slotSaveAs()) );
737  actionCollection()->addAction( KStandardAction::Print, QLatin1String("print_note"), this,
738  SLOT(slotPrint()) );
739 
740  if (KPrintPreview::isAvailable()) {
741  actionCollection()->addAction( KStandardAction::PrintPreview, QLatin1String("print_preview_note"), this,
742  SLOT(slotPrintPreview()) );
743  }
744  action = new KAction( KIcon( QLatin1String("configure") ), i18n( "Preferences..." ), this );
745  actionCollection()->addAction( QLatin1String("configure_note"), action );
746  connect( action, SIGNAL(triggered(bool)), SLOT(slotPreferences()) );
747 
748 
749  m_keepAbove = new KToggleAction( KIcon( QLatin1String("go-up") ),
750  i18n( "Keep Above Others" ), this );
751  actionCollection()->addAction( QLatin1String("keep_above"), m_keepAbove );
752  connect( m_keepAbove, SIGNAL(triggered(bool)),
753  SLOT(slotKeepAbove()) );
754 
755  m_keepBelow = new KToggleAction( KIcon( QLatin1String("go-down") ),
756  i18n( "Keep Below Others" ), this );
757  actionCollection()->addAction( QLatin1String("keep_below"), m_keepBelow );
758  connect( m_keepBelow, SIGNAL(triggered(bool)),
759  SLOT(slotKeepBelow()) );
760 
761 #ifdef Q_WS_X11
762  m_toDesktop = new KSelectAction( i18n( "To Desktop" ), this );
763  actionCollection()->addAction( QLatin1String("to_desktop"), m_toDesktop );
764  connect( m_toDesktop, SIGNAL(triggered(int)),
765  SLOT(slotPopupActionToDesktop(int)) );
766  connect( m_toDesktop->menu(), SIGNAL(aboutToShow()),
767  SLOT(slotUpdateDesktopActions()) );
768  // initially populate it, otherwise stays disabled
769  slotUpdateDesktopActions();
770 #endif
771  // invisible action to walk through the notes to make this configurable
772  action = new KAction( i18n( "Walk Through Notes" ), this );
773  actionCollection()->addAction( QLatin1String("walk_notes"), action );
774  connect( action, SIGNAL(triggered(bool)), SIGNAL(sigShowNextNote()) );
775  action->setShortcut( QKeySequence( Qt::SHIFT + Qt::Key_Backtab ) );
776 
777  actionCollection()->addAssociatedWidget( this );
778  foreach (QAction* action, actionCollection()->actions())
779  action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
780  if (mAllowDebugBaloo) {
781  //Don't translate it it's just for debugging
782  action = new KAction( QLatin1String("Debug Baloo..."), this );
783  actionCollection()->addAction( QLatin1String("debug_baloo"), action );
784  connect( action, SIGNAL(triggered(bool)), SLOT(slotDebugBaloo()) );
785  }
786 }
787 
788 void KNote::createNoteHeader()
789 {
790  // load style configuration
791  KConfigGroup styleGroup( m_kwinConf, "Style" );
792 
793  QBoxLayout::Direction headerLayoutDirection = QBoxLayout::LeftToRight;
794 
795  if ( styleGroup.readEntry( "CustomButtonPositions", false ) ) {
796  if ( styleGroup.readEntry( "ButtonsOnLeft" ).contains( QLatin1Char('X') ) ) {
797  headerLayoutDirection = QBoxLayout::RightToLeft;
798  }
799  }
800 
801  QBoxLayout *headerLayout = new QBoxLayout( headerLayoutDirection);
802 
803 
804  // create header label
805  m_label = new QLabel( this );
806  headerLayout->addWidget( m_label );
807  m_label->setFrameStyle( NoFrame );
808  m_label->setBackgroundRole( QPalette::Base );
809  m_label->setLineWidth( 0 );
810  m_label->setAutoFillBackground( true );
811  m_label->installEventFilter( this ); // receive events ( for dragging &
812  // action menu )
813  m_button = new KNoteButton( QLatin1String("knotes_close"), this );
814  headerLayout->addWidget( m_button );
815 
816  connect( m_button, SIGNAL(clicked()), this, SLOT(slotClose()) );
817 
818  m_noteLayout->addItem( headerLayout );
819 }
820 
821 void KNote::createNoteEditor(const QString &configFile)
822 {
823  m_editor = new KNoteEdit( configFile, actionCollection(), this );
824  m_noteLayout->addWidget( m_editor );
825  m_editor->setNote( this );
826  m_editor->installEventFilter( this ); // receive focus events for modified
827  setFocusProxy( m_editor );
828 }
829 
830 void KNote::slotRequestNewNote()
831 {
832  //Be sure to save before to request a new note
833  saveNote();
834  emit sigRequestNewNote();
835 }
836 
837 void KNote::createNoteFooter()
838 {
839  if ( m_tool ) {
840  m_tool->setIconSize( QSize( 10, 10 ) );
841  m_tool->setFixedHeight( 24 );
842  m_tool->setToolButtonStyle( Qt::ToolButtonIconOnly );
843  }
844 
845  // create size grip
846  QHBoxLayout *gripLayout = new QHBoxLayout;
847  m_grip = new QSizeGrip( this );
848  m_grip->setFixedSize( m_grip->sizeHint() );
849 
850  if ( m_tool ) {
851  gripLayout->addWidget( m_tool );
852  gripLayout->setAlignment( m_tool, Qt::AlignBottom | Qt::AlignLeft );
853  m_tool->hide();
854  }
855 
856  gripLayout->addWidget( m_grip );
857  gripLayout->setAlignment( m_grip, Qt::AlignBottom | Qt::AlignRight );
858  m_noteLayout->addItem( gripLayout );
859 
860  // if there was just a way of making KComboBox adhere the toolbar height...
861  if ( m_tool ) {
862  foreach ( KComboBox *combo, m_tool->findChildren<KComboBox *>() ) {
863  QFont font = combo->font();
864  font.setPointSize( 7 );
865  combo->setFont( font );
866  combo->setFixedHeight( 14 );
867  }
868  }
869 }
870 
871 void KNote::loadNoteContent(const Akonadi::Item &item)
872 {
873  KMime::Message::Ptr noteMessage = item.payload<KMime::Message::Ptr>();
874  const KMime::Headers::Subject * const subject = noteMessage ? noteMessage->subject(false) : 0;
875  setName(subject ? subject->asUnicodeString() : QString());
876  if ( noteMessage->contentType()->isHTMLText() ) {
877  m_editor->setAcceptRichText(true);
878  m_editor->setHtml(noteMessage->mainBodyPart()->decodedText());
879  } else {
880  m_editor->setAcceptRichText(false);
881  m_editor->setPlainText(noteMessage->mainBodyPart()->decodedText());
882  }
883  if ( noteMessage->headerByType( "X-Cursor-Position" ) ) {
884  m_editor->setCursorPositionFromStart( noteMessage->headerByType( "X-Cursor-Position" )->asUnicodeString().toInt() );
885  }
886 }
887 
888 void KNote::prepare()
889 {
890  mBlockSave = true;
891  loadNoteContent(mItem);
892 
893  resize(mDisplayAttribute->size());
894  const QPoint& position = mDisplayAttribute->position();
895  QRect desk = kapp->desktop()->rect();
896  desk.adjust( 10, 10, -10, -10 );
897  if ( desk.intersects( QRect( position, mDisplayAttribute->size() ) ) ) {
898  move( position ); // do before calling show() to avoid flicker
899  }
900  if (mDisplayAttribute->isHidden())
901  hide();
902  else
903  show();
904  // read configuration settings...
905  slotApplyConfig();
906 
907  if ( mItem.hasAttribute<NoteShared::NoteLockAttribute>() ) {
908  m_editor->setReadOnly(true);
909  m_readOnly->setChecked( true );
910  } else {
911  m_readOnly->setChecked( false );
912  }
913  slotUpdateReadOnly();
914  // if this is a new note put on current desktop - we can't use defaults
915  // in KConfig XT since only _changes_ will be stored in the config file
916  int desktop = mDisplayAttribute->desktop();
917 
918 #ifdef Q_WS_X11
919  if ( ( desktop < 0 && desktop != NETWinInfo::OnAllDesktops ) ||
920  !mDisplayAttribute->rememberDesktop() )
921  desktop = KWindowSystem::currentDesktop();
922 #endif
923 
924  // show the note if desired
925  if ( desktop != 0 && !mDisplayAttribute->isHidden() ) {
926  // to avoid flicker, call this before show()
927  toDesktop( desktop );
928  show();
929 
930  // because KWin forgets about that for hidden windows
931 #ifdef Q_WS_X11
932  if ( desktop == NETWinInfo::OnAllDesktops ) {
933  toDesktop( desktop );
934  }
935 #endif
936  }
937 
938  if ( mDisplayAttribute->keepAbove() ) {
939  m_keepAbove->setChecked( true );
940  } else if ( mDisplayAttribute->keepBelow() ) {
941  m_keepBelow->setChecked( true );
942  } else {
943  m_keepAbove->setChecked( false );
944  m_keepBelow->setChecked( false );
945  }
946 
947  slotUpdateKeepAboveBelow();
948  // HACK: update the icon color - again after showing the note, to make kicker
949  // aware of the new colors
950  KIconEffect effect;
951  const QColor col = mDisplayAttribute->backgroundColor();
952  const QPixmap icon = effect.apply( qApp->windowIcon().pixmap(
953  IconSize( KIconLoader::Desktop ),
954  IconSize( KIconLoader::Desktop ) ),
955  KIconEffect::Colorize,
956  1, col, false );
957 #ifdef Q_WS_X11
958  const QPixmap miniIcon = effect.apply( qApp->windowIcon().pixmap(
959  IconSize( KIconLoader::Small ),
960  IconSize( KIconLoader::Small ) ),
961  KIconEffect::Colorize,
962  1, col, false );
963  KWindowSystem::setIcons( winId(), icon, miniIcon );
964 #endif
965 
966  // set up the look&feel of the note
967  setFrameStyle( Panel | Raised );
968  setMinimumSize( 20, 20 );
969  setBackgroundRole( QPalette::Base );
970 
971  m_editor->setContentsMargins( 0, 0, 0, 0 );
972  m_editor->setBackgroundRole( QPalette::Base );
973  m_editor->setFrameStyle( NoFrame );
974  m_editor->document()->setModified( false );
975  mBlockSave = false;
976 }
977 
978 void KNote::toDesktop( int desktop )
979 {
980  if ( desktop == 0 ) {
981  return;
982  }
983 
984 #ifdef Q_WS_X11
985  if ( desktop == NETWinInfo::OnAllDesktops ) {
986  KWindowSystem::setOnAllDesktops( winId(), true );
987  } else {
988  KWindowSystem::setOnDesktop( winId(), desktop );
989  }
990 #endif
991 }
992 
993 void KNote::setColor( const QColor &fg, const QColor &bg )
994 {
995  m_editor->setColor(fg,bg);
996  QPalette p = palette();
997 
998  // better: from light(150) to light(100) to light(75)
999  // QLinearGradient g( width()/2, 0, width()/2, height() );
1000  // g.setColorAt( 0, bg );
1001  // g.setColorAt( 1, bg.dark(150) );
1002 
1003  p.setColor( QPalette::Window, bg );
1004  // p.setBrush( QPalette::Window, g );
1005  p.setColor( QPalette::Base, bg );
1006  // p.setBrush( QPalette::Base, g );
1007 
1008  p.setColor( QPalette::WindowText, fg );
1009  p.setColor( QPalette::Text, fg );
1010 
1011  p.setColor( QPalette::Button, bg.dark( 116 ) );
1012  p.setColor( QPalette::ButtonText, fg );
1013 
1014  //p.setColor( QPalette::Highlight, bg );
1015  //p.setColor( QPalette::HighlightedText, fg );
1016 
1017  // order: Light, Midlight, Button, Mid, Dark, Shadow
1018 
1019  // the shadow
1020  p.setColor( QPalette::Light, bg.light( 180 ) );
1021  p.setColor( QPalette::Midlight, bg.light( 150 ) );
1022  p.setColor( QPalette::Mid, bg.light( 150 ) );
1023  p.setColor( QPalette::Dark, bg.dark( 108 ) );
1024  p.setColor( QPalette::Shadow, bg.dark( 116 ) );
1025 
1026  setPalette( p );
1027 
1028  // darker values for the active label
1029  p.setColor( QPalette::Active, QPalette::Base, bg.dark( 116 ) );
1030 
1031  m_label->setPalette( p );
1032 
1033  // set the text color
1034  m_editor->setTextColor( fg );
1035 
1036  // update the icon color
1037  KIconEffect effect;
1038  QPixmap icon = effect.apply( qApp->windowIcon().pixmap(
1039  IconSize( KIconLoader::Desktop ),
1040  IconSize( KIconLoader::Desktop ) ),
1041  KIconEffect::Colorize, 1, bg, false );
1042  QPixmap miniIcon = effect.apply( qApp->windowIcon().pixmap(
1043  IconSize( KIconLoader::Small ),
1044  IconSize( KIconLoader::Small ) ),
1045  KIconEffect::Colorize, 1, bg, false );
1046 #ifdef Q_WS_X11
1047  KWindowSystem::setIcons( winId(), icon, miniIcon );
1048 #endif
1049  // update the color of the title
1050  updateFocus();
1051  emit sigColorChanged();
1052 }
1053 
1054 void KNote::updateLabelAlignment()
1055 {
1056  // if the name is too long to fit, left-align it, otherwise center it (#59028)
1057  const QString labelText = m_label->text();
1058  if ( m_label->fontMetrics().boundingRect( labelText ).width() > m_label->width() ) {
1059  m_label->setAlignment( Qt::AlignLeft );
1060  } else {
1061  m_label->setAlignment( Qt::AlignHCenter );
1062  }
1063 }
1064 
1065 void KNote::updateFocus()
1066 {
1067  if ( hasFocus() ) {
1068  if ( !m_editor->isReadOnly() ) {
1069  if ( m_tool && m_tool->isHidden() && m_editor->acceptRichText() ) {
1070  m_tool->show();
1071  updateLayout();
1072  }
1073  m_grip->show();
1074  } else {
1075  if ( m_tool && !m_tool->isHidden() ) {
1076  m_tool->hide();
1077  updateLayout(); // to update the minimum height
1078  }
1079  m_grip->hide();
1080  }
1081  } else {
1082  m_grip->hide();
1083 
1084  if ( m_tool && !m_tool->isHidden() ) {
1085  m_tool->hide();
1086  updateLayout(); // to update the minimum height
1087  }
1088  }
1089 }
1090 
1091 void KNote::updateLayout()
1092 {
1093  // TODO: remove later if no longer needed.
1094  updateLabelAlignment();
1095 }
1096 
1097 // -------------------- protected methods -------------------- //
1098 
1099 void KNote::contextMenuEvent( QContextMenuEvent *e )
1100 {
1101  if ( m_menu ) {
1102  m_menu->popup( e->globalPos() );
1103  }
1104 }
1105 
1106 void KNote::showEvent( QShowEvent * )
1107 {
1108  if ( mDisplayAttribute->isHidden() ) {
1109  // KWin does not preserve these properties for hidden windows
1110  slotUpdateKeepAboveBelow(false);
1111  slotUpdateShowInTaskbar();
1112  toDesktop( mDisplayAttribute->desktop() );
1113  move( mDisplayAttribute->position() );
1114  NoteShared::NoteDisplayAttribute *attr = mItem.attribute<NoteShared::NoteDisplayAttribute>( Akonadi::Entity::AddIfMissing );
1115  saveNoteContent();
1116  attr->setIsHidden(false);
1117  if (!mBlockSave) {
1118  Akonadi::ItemModifyJob *job = new Akonadi::ItemModifyJob(mItem);
1119 #ifdef DEBUG_SAVE_NOTE
1120  qDebug()<<"showEvent slotNoteSaved(KJob*)";
1121 #endif
1122  connect( job, SIGNAL(result(KJob*)), SLOT(slotNoteSaved(KJob*)) );
1123  }
1124  }
1125 }
1126 
1127 void KNote::resizeEvent( QResizeEvent *qre )
1128 {
1129  QFrame::resizeEvent( qre );
1130  updateLayout();
1131 }
1132 
1133 void KNote::closeEvent( QCloseEvent * event )
1134 {
1135  if ( kapp->sessionSaving() ) {
1136  return;
1137  }
1138  event->ignore(); //We don't want to close (and delete the widget). Just hide it
1139  slotClose();
1140 }
1141 
1142 void KNote::dragEnterEvent( QDragEnterEvent *e )
1143 {
1144  if ( !m_editor->isReadOnly() ) {
1145  e->setAccepted( e->mimeData()->hasColor() );
1146  }
1147 }
1148 
1149 void KNote::dropEvent( QDropEvent *e )
1150 {
1151  if ( m_editor->isReadOnly() ) {
1152  return;
1153  }
1154 
1155  const QMimeData *md = e->mimeData();
1156  if ( md->hasColor() ) {
1157  const QColor bg = qvariant_cast<QColor>( md->colorData() );
1158 
1159  NoteShared::NoteDisplayAttribute *attr = mItem.attribute<NoteShared::NoteDisplayAttribute>( Akonadi::Entity::AddIfMissing );
1160  saveNoteContent();
1161  attr->setBackgroundColor(bg);
1162  Akonadi::ItemModifyJob *job = new Akonadi::ItemModifyJob(mItem);
1163 #ifdef DEBUG_SAVE_NOTE
1164  qDebug()<<"dropEvent slotNoteSaved(KJob*)";
1165 #endif
1166  connect( job, SIGNAL(result(KJob*)), SLOT(slotNoteSaved(KJob*)) );
1167  }
1168 }
1169 
1170 bool KNote::event( QEvent *ev )
1171 {
1172  if ( ev->type() == QEvent::LayoutRequest ) {
1173  updateLayout();
1174  return true;
1175  } else {
1176  return QFrame::event( ev );
1177  }
1178 }
1179 
1180 bool KNote::eventFilter( QObject *o, QEvent *ev )
1181 {
1182  if ( ev->type() == QEvent::DragEnter &&
1183  static_cast<QDragEnterEvent*>( ev )->mimeData()->hasColor() ) {
1184  dragEnterEvent( static_cast<QDragEnterEvent *>( ev ) );
1185  return true;
1186  }
1187 
1188  if ( ev->type() == QEvent::Drop &&
1189  static_cast<QDropEvent *>( ev )->mimeData()->hasColor() ) {
1190  dropEvent( static_cast<QDropEvent *>( ev ) );
1191  return true;
1192  }
1193 
1194  if ( o == m_label ) {
1195  QMouseEvent *e = ( QMouseEvent * )ev;
1196 
1197  if ( ev->type() == QEvent::MouseButtonDblClick ) {
1198  if(!m_editor->isReadOnly())
1199  slotRename();
1200  }
1201 
1202  if ( ev->type() == QEvent::MouseButtonPress &&
1203  ( e->button() == Qt::LeftButton || e->button() == Qt::MidButton ) ) {
1204 #ifdef Q_WS_X11
1205  e->button() == Qt::LeftButton ? KWindowSystem::raiseWindow( winId() )
1206  : KWindowSystem::lowerWindow( winId() );
1207 
1208  XUngrabPointer( QX11Info::display(), QX11Info::appTime() );
1209  NETRootInfo wm_root( QX11Info::display(), NET::WMMoveResize );
1210  wm_root.moveResizeRequest( winId(), e->globalX(), e->globalY(),
1211  NET::Move );
1212 #endif
1213  return true;
1214  }
1215 
1216  if ( ev->type() == QEvent::MouseButtonRelease ) {
1217 #ifdef Q_WS_X11
1218  NETRootInfo wm_root( QX11Info::display(), NET::WMMoveResize );
1219  wm_root.moveResizeRequest( winId(), e->globalX(), e->globalY(),
1220  NET::MoveResizeCancel );
1221 #endif
1222  return false;
1223  }
1224 
1225  return false;
1226  }
1227 
1228  if ( o == m_editor ) {
1229  if ( ev->type() == QEvent::FocusOut ) {
1230  QFocusEvent *fe = static_cast<QFocusEvent *>( ev );
1231  if ( fe->reason() != Qt::PopupFocusReason &&
1232  fe->reason() != Qt::MouseFocusReason ) {
1233  updateFocus();
1234  if (!mBlockSave)
1235  saveNote(true);
1236  }
1237  } else if ( ev->type() == QEvent::FocusIn ) {
1238  updateFocus();
1239  }
1240 
1241  return false;
1242  }
1243 
1244  return false;
1245 }
1246 
1247 Akonadi::Item KNote::item() const
1248 {
1249  return mItem;
1250 }
1251 
1252 void KNote::slotDebugBaloo()
1253 {
1254  QPointer<PimCommon::BalooDebugDialog> dlg = new PimCommon::BalooDebugDialog;
1255  dlg->setAkonadiId(mItem.id());
1256  dlg->setAttribute( Qt::WA_DeleteOnClose );
1257  dlg->setSearchType(PimCommon::BalooDebugSearchPathComboBox::Notes);
1258  dlg->doSearch();
1259  dlg->show();
1260 }
KNote::slotKill
void slotKill(bool force=false)
Definition: knote.cpp:159
knoteprintselectthemedialog.h
QEvent
KNoteDisplaySettings::setDisplayAttribute
void setDisplayAttribute(NoteShared::NoteDisplayAttribute *attr)
Definition: knotedisplaysettings.cpp:34
QResizeEvent
QWidget
QFont::setPointSize
void setPointSize(int pointSize)
QAction::setShortcutContext
void setShortcutContext(Qt::ShortcutContext context)
QEvent::type
Type type() const
QWidget::palette
const QPalette & palette() const
KNotePrintSelectThemeDialog
Definition: knoteprintselectthemedialog.h:26
KNoteEdit::setTextFont
void setTextFont(const QFont &font)
Definition: knoteedit.cpp:322
KNotePrintObject
Definition: knoteprintobject.h:27
KNote::isModified
bool isModified() const
Definition: knote.cpp:281
QAction::setSeparator
void setSeparator(bool b)
QDropEvent::mimeData
const QMimeData * mimeData() const
QLayout::addItem
virtual void addItem(QLayoutItem *item)=0
QColor::light
QColor light(int factor) const
QPalette::setColor
void setColor(ColorGroup group, ColorRole role, const QColor &color)
KNote::~KNote
~KNote()
Definition: knote.cpp:124
QByteArray
KNoteEdit
Definition: knoteedit.h:39
QX11Info::appRootWindow
Qt::HANDLE appRootWindow(int screen)
QX11Info::display
Display * display()
QFont
KNote::showEvent
virtual void showEvent(QShowEvent *)
Definition: knote.cpp:1106
KNoteDisplaySettings::font
QFont font() const
Definition: knotedisplaysettings.cpp:84
QPointer
QRect::intersects
bool intersects(const QRect &rectangle) const
KNote::saveNote
void saveNote(bool force=false, bool sync=false)
Definition: knote.cpp:178
KNoteEdit::setColor
void setColor(const QColor &fg, const QColor &bg)
Definition: knoteedit.cpp:208
KNoteDisplaySettings::keepBelow
bool keepBelow() const
Definition: knotedisplaysettings.cpp:141
QHBoxLayout
KNote::isDesktopAssigned
bool isDesktopAssigned() const
Definition: knote.cpp:276
KNoteDisplaySettings::keepAbove
bool keepAbove() const
Definition: knotedisplaysettings.cpp:133
QWidget::setAttribute
void setAttribute(Qt::WidgetAttribute attribute, bool on)
QLabel::setAlignment
void setAlignment(QFlags< Qt::AlignmentFlag >)
KNote::slotClose
void slotClose()
Definition: knote.cpp:378
QWidget::icon
const QPixmap * icon() const
QWidget::hasFocus
bool hasFocus() const
QPoint
QMouseEvent
KNoteEdit::setAutoIndentMode
void setAutoIndentMode(bool newmode)
Definition: knoteedit.cpp:342
QFrame::setFrameStyle
void setFrameStyle(int style)
KNoteEdit::text
QString text() const
Definition: knoteedit.cpp:313
QFrame::setLineWidth
void setLineWidth(int)
KNote::sigShowNextNote
void sigShowNextNote()
QContextMenuEvent::globalPos
const QPoint & globalPos() const
KNoteButton
Definition: knotebutton.h:27
KNoteDisplaySettings
Definition: knotedisplaysettings.h:30
QMimeData
QFile
QTextStream
KNote::sigKillNote
void sigKillNote(Akonadi::Item::Id)
KNoteDisplaySettings::rememberDesktop
bool rememberDesktop() const
Definition: knotedisplaysettings.cpp:68
QColor::dark
QColor dark(int factor) const
QX11Info::appTime
unsigned long appTime()
KNoteInterface::mBlockSave
bool mBlockSave
Definition: knoteinterface.h:30
knoteconfigdialog.h
QWidget::width
int width() const
KNoteEdit::cursorPositionFromStart
int cursorPositionFromStart() const
Definition: knoteedit.cpp:704
QCloseEvent
QWidget::resize
void resize(int w, int h)
KNoteEdit::setTabStop
void setTabStop(int tabs)
Definition: knoteedit.cpp:336
QWidget::setMinimumSize
void setMinimumSize(const QSize &)
KNote::dropEvent
virtual void dropEvent(QDropEvent *)
Definition: knote.cpp:1149
Qt::convertFromPlainText
QString convertFromPlainText(const QString &plain, WhiteSpaceMode mode)
QFocusEvent::reason
Qt::FocusReason reason() const
KNote::eventFilter
virtual bool eventFilter(QObject *, QEvent *)
Definition: knote.cpp:1180
QRect
QFontMetrics::boundingRect
QRect boundingRect(QChar ch) const
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QString::number
QString number(int n, int base)
knote.h
QList::append
void append(const T &value)
knotesimpleconfigdialog.h
KNoteDisplaySettings::tabSize
int tabSize() const
Definition: knotedisplaysettings.cpp:76
QString::fromUtf8
QString fromUtf8(const char *str, int size)
QEvent::setAccepted
void setAccepted(bool accepted)
QObject::installEventFilter
void installEventFilter(QObject *filterObj)
knoteprintobject.h
KNote::slotRename
void slotRename()
Definition: knote.cpp:288
QShowEvent
QContextMenuEvent
knotebutton.h
QObject
KNoteDisplaySettings::showInTaskbar
bool showInTaskbar() const
Definition: knotedisplaysettings.cpp:125
KNoteEdit::setText
void setText(const QString &text)
Definition: knoteedit.cpp:304
QCheckBox
QMouseEvent::button
Qt::MouseButton button() const
QDropEvent
KNote::sigColorChanged
void sigColorChanged()
QWidget::setFocusProxy
void setFocusProxy(QWidget *w)
QString::isEmpty
bool isEmpty() const
knoteprinter.h
KNoteEdit::setNote
void setNote(KNote *_note)
Definition: knoteedit.cpp:248
KNote::text
QString text() const
Definition: knote.cpp:246
KNote::name
QString name() const
Definition: knote.cpp:241
knoteutils.h
KNote::resizeEvent
virtual void resizeEvent(QResizeEvent *)
Definition: knote.cpp:1127
QWidget::pos
QPoint pos() const
QVBoxLayout
QSizeGrip::sizeHint
virtual QSize sizeHint() const
QSet
QWidget::winId
WId winId() const
QLabel::text
text
KNote::item
Akonadi::Item item() const
Definition: knote.cpp:1247
QString
QList
QWidget::hide
void hide()
QColor
QLayout::setMargin
void setMargin(int margin)
QLayout::addWidget
void addWidget(QWidget *w)
QMimeData::colorData
QVariant colorData() const
KNote::setChangeItem
void setChangeItem(const Akonadi::Item &item, const QSet< QByteArray > &set=QSet< QByteArray >())
Definition: knote.cpp:139
QPixmap
QWidget::setAcceptDrops
void setAcceptDrops(bool on)
QFileInfo
KNote::event
virtual bool event(QEvent *)
Definition: knote.cpp:1170
QSize
QWidget::setFixedSize
void setFixedSize(const QSize &s)
QLatin1Char
QWidget::setFont
void setFont(const QFont &)
QDomDocument
QFrame
KNote::dragEnterEvent
virtual void dragEnterEvent(QDragEnterEvent *)
Definition: knote.cpp:1142
KNoteDisplaySettings::position
QPoint position() const
Definition: knotedisplaysettings.cpp:116
QSet::contains
bool contains(const T &value) const
KNoteDisplaySettings::size
QSize size() const
Definition: knotedisplaysettings.cpp:60
QAbstractButton::isChecked
bool isChecked() const
knotedisplaysettings.h
QLayout::setAlignment
bool setAlignment(QWidget *w, QFlags< Qt::AlignmentFlag > alignment)
QString::replace
QString & replace(int position, int n, QChar after)
KNoteUtils::setDefaultValue
KNOTES_EXPORT void setDefaultValue(Akonadi::Item &item)
Definition: knoteutils.cpp:41
KNote::closeEvent
virtual void closeEvent(QCloseEvent *)
Definition: knote.cpp:1133
KNoteDisplaySettings::autoIndent
bool autoIndent() const
Definition: knotedisplaysettings.cpp:149
QRect::width
int width() const
QWidget::fontMetrics
QFontMetrics fontMetrics() const
QDragEnterEvent
KNoteDisplaySettings::isHidden
bool isHidden() const
Definition: knotedisplaysettings.cpp:108
KNoteDisplaySettings::foregroundColor
QColor foregroundColor() const
Definition: knotedisplaysettings.cpp:52
QMouseEvent::globalX
int globalX() const
QMouseEvent::globalY
int globalY() const
QLatin1String
QKeySequence
KNote::noteId
Akonadi::Item::Id noteId() const
Definition: knote.cpp:236
KNotePrinter
Definition: knoteprinter.h:34
KNote::contextMenuEvent
virtual void contextMenuEvent(QContextMenuEvent *)
Definition: knote.cpp:1099
QAction
KNote::setName
void setName(const QString &name)
Definition: knote.cpp:251
QRect::adjust
void adjust(int dx1, int dy1, int dx2, int dy2)
KNoteDisplaySettings::backgroundColor
QColor backgroundColor() const
Definition: knotedisplaysettings.cpp:44
Qt::mightBeRichText
bool mightBeRichText(const QString &text)
QAbstractButton::setText
void setText(const QString &text)
QString::fromLatin1
QString fromLatin1(const char *str, int size)
KNote::sigRequestNewNote
void sigRequestNewNote()
QWidget::setAutoFillBackground
void setAutoFillBackground(bool enabled)
QWidget::show
void show()
KNoteSimpleConfigDialog
Definition: knotesimpleconfigdialog.h:27
QWidget::resizeEvent
virtual void resizeEvent(QResizeEvent *event)
KNote::toDesktop
void toDesktop(int desktop)
Definition: knote.cpp:978
KNoteDisplaySettings::desktop
int desktop() const
Definition: knotedisplaysettings.cpp:100
QWidget::setBackgroundRole
void setBackgroundRole(QPalette::ColorRole role)
knoteedit.h
QSizeGrip
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KNote::KNote
KNote(const QDomDocument &buildDoc, const Akonadi::Item &item, bool allowDebugBaloo=false, QWidget *parent=0)
Definition: knote.cpp:92
QWidget::actions
QList< QAction * > actions() const
QLabel
KNote::setText
void setText(const QString &text)
Definition: knote.cpp:269
QFocusEvent
QFrame::event
virtual bool event(QEvent *e)
QBoxLayout
KNoteEdit::setCursorPositionFromStart
void setCursorPositionFromStart(int pos)
Definition: knoteedit.cpp:693
KNoteDisplaySettings::titleFont
QFont titleFont() const
Definition: knotedisplaysettings.cpp:92
QPalette
QWidget::height
int height() const
QMimeData::hasColor
bool hasColor() const
KNote::sigNameChanged
void sigNameChanged(const QString &)
QRect::rect
void rect(int *x, int *y, int *width, int *height) const
QString::toUtf8
QByteArray toUtf8() const
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