22 #include "noteshared/noteutils.h"
23 #include "alarms/notealarmdialog.h"
32 #include "knotesglobalconfig.h"
36 #include "noteshared/attributes/notelockattribute.h"
37 #include "noteshared/attributes/notedisplayattribute.h"
38 #include "noteshared/attributes/notealarmattribute.h"
40 #include "pimcommon/baloodebug/baloodebugdialog.h"
42 #include <KMime/KMimeMessage>
45 #include <kactioncollection.h>
46 #include <kapplication.h>
47 #include <kcombobox.h>
48 #include <kfiledialog.h>
49 #include <kglobalsettings.h>
51 #include <kiconeffect.h>
52 #include <kiconloader.h>
53 #include <kinputdialog.h>
56 #include <kmessagebox.h>
57 #include <kselectaction.h>
58 #include <kstandardaction.h>
59 #include <kstandarddirs.h>
60 #include <ktoggleaction.h>
62 #include <kwindowsystem.h>
63 #include <kxmlguibuilder.h>
64 #include <kxmlguifactory.h>
66 #include <KPrintPreview>
68 #include <Akonadi/ItemModifyJob>
73 #include <QHBoxLayout>
78 #include <QTextStream>
79 #include <QVBoxLayout>
80 #include <QDesktopWidget>
82 #include <QFocusEvent>
93 :
QFrame( parent, Qt::FramelessWindowHint ),
100 m_kwinConf( KSharedConfig::openConfig(
QLatin1String(
"kwinrc") ) ),
102 mAllowDebugBaloo(allowDebugBaloo)
104 if ( mItem.hasAttribute<NoteShared::NoteDisplayAttribute>()) {
105 mDisplayAttribute->
setDisplayAttribute(mItem.attribute<NoteShared::NoteDisplayAttribute>());
107 setDisplayDefaultValue();
112 setDOMDocument( buildDoc );
113 setXMLFile( componentData().componentName() +
QLatin1String(
"ui.rc"),
false,
false );
126 delete mDisplayAttribute;
129 void KNote::setDisplayDefaultValue()
132 Akonadi::ItemModifyJob *job =
new Akonadi::ItemModifyJob(mItem);
133 #ifdef DEBUG_SAVE_NOTE
134 qDebug()<<
"setDisplayDefaultValue slotNoteSaved(KJob*)";
136 connect( job, SIGNAL(result(KJob*)), SLOT(slotNoteSaved(KJob*)) );
142 if ( item.hasAttribute<NoteShared::NoteDisplayAttribute>()) {
143 mDisplayAttribute->
setDisplayAttribute(item.attribute<NoteShared::NoteDisplayAttribute>());
145 if (set.
contains(
"ATR:KJotsLockAttribute")) {
146 m_editor->setReadOnly(item.hasAttribute<NoteShared::NoteLockAttribute>());
149 loadNoteContent(item);
151 if (set.
contains(
"ATR:NoteDisplayAttribute")) {
152 qDebug()<<
" ATR:NoteDisplayAttribute";
156 updateLabelAlignment();
162 ( KMessageBox::warningContinueCancel(
this,
163 i18n(
"<qt>Do you really want to delete note <b>%1</b>?</qt>",
165 i18n(
"Confirm Delete" ),
167 KStandardGuiItem::cancel(),
168 QLatin1String(
"ConfirmDeleteNote") ) != KMessageBox::Continue ) ) {
180 if (!force && !m_editor->document()->isModified())
182 bool needToSave =
false;
183 NoteShared::NoteDisplayAttribute *attribute = mItem.attribute<NoteShared::NoteDisplayAttribute>( Akonadi::Entity::AddIfMissing );
185 if (attribute->position() != notePosition) {
187 attribute->setPosition(notePosition);
190 if (attribute->size() != currentSize) {
192 attribute->setSize(currentSize);
197 if ( ( wm_client.desktop() == NETWinInfo::OnAllDesktops ) ||
198 ( wm_client.desktop() > 0 ) ) {
199 const int desktopNumber = wm_client.desktop();
200 if (attribute->desktop() != desktopNumber) {
202 attribute->setDesktop( desktopNumber );
206 if (m_editor->document()->isModified()) {
211 #ifdef DEBUG_SAVE_NOTE
212 qDebug()<<
"save Note slotClose() slotNoteSaved(KJob*) : sync"<<sync;
214 Akonadi::ItemModifyJob *job =
new Akonadi::ItemModifyJob(mItem);
218 #ifdef DEBUG_SAVE_NOTE
219 qDebug()<<
"save Note slotClose() slotNoteSaved(KJob*)";
221 connect( job, SIGNAL(result(KJob*)), SLOT(slotNoteSaved(KJob*)) );
226 void KNote::slotNoteSaved(KJob *job)
228 qDebug()<<
" void KNote::slotNoteSaved(KJob *job)";
229 if ( job->error() ) {
230 qDebug()<<
" problem during save note:"<<job->errorString();
232 m_editor->document()->setModified(
false );
243 return m_label->
text();
248 return m_editor->
text();
254 updateLabelAlignment();
263 note_win.setName( name.
toUtf8() );
283 return m_editor->document()->isModified();
293 const QString newName = KInputDialog::getText( QString::null,
294 i18n(
"Please enter the new name:" ), m_label->
text(), &ok, this );
295 if ( !ok || (oldName == newName) ) {
302 void KNote::slotUpdateReadOnly()
304 const bool readOnly = m_readOnly->isChecked();
306 m_editor->setReadOnly( readOnly );
308 if (mItem.hasAttribute<NoteShared::NoteLockAttribute>()) {
310 mItem.removeAttribute<NoteShared::NoteLockAttribute>();
314 mItem.attribute<NoteShared::NoteLockAttribute>( Akonadi::Entity::AddIfMissing );
318 updateAllAttributes();
319 Akonadi::ItemModifyJob *job =
new Akonadi::ItemModifyJob(mItem);
320 #ifdef DEBUG_SAVE_NOTE
321 qDebug()<<
" void KNote::slotUpdateReadOnly() slotNoteSaved(KJob*)";
323 connect( job, SIGNAL(result(KJob*)), SLOT(slotNoteSaved(KJob*)) );
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);
352 m_toDesktop->setEnabled( !readOnly);
358 void KNote::updateAllAttributes()
360 NoteShared::NoteDisplayAttribute *attribute = mItem.attribute<NoteShared::NoteDisplayAttribute>(Akonadi::Entity::AddIfMissing);
364 if ( ( wm_client.desktop() == NETWinInfo::OnAllDesktops ) ||
365 ( wm_client.desktop() > 0 ) ) {
366 attribute->setDesktop(wm_client.desktop());
370 attribute->setIsHidden(
true);
371 attribute->setPosition(
pos());
373 if (attribute->size() != currentSize) {
374 attribute->setSize(currentSize);
380 updateAllAttributes();
381 m_editor->clearFocus();
382 Akonadi::ItemModifyJob *job =
new Akonadi::ItemModifyJob(mItem);
383 #ifdef DEBUG_SAVE_NOTE
384 qDebug()<<
"slotClose() slotNoteSaved(KJob*)";
386 connect( job, SIGNAL(result(KJob*)), SLOT(slotNoteSaved(KJob*)) );
390 void KNote::slotSetAlarm()
393 if (mItem.hasAttribute<NoteShared::NoteAlarmAttribute>()) {
394 dlg->setAlarm(mItem.attribute<NoteShared::NoteAlarmAttribute>()->dateTime());
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);
403 if (mItem.hasAttribute<NoteShared::NoteAlarmAttribute>()) {
404 mItem.removeAttribute<NoteShared::NoteAlarmAttribute>();
406 needToModify =
false;
412 Akonadi::ItemModifyJob *job =
new Akonadi::ItemModifyJob(mItem);
413 #ifdef DEBUG_SAVE_NOTE
414 qDebug()<<
"setAlarm() slotNoteSaved(KJob*)";
416 connect( job, SIGNAL(result(KJob*)), SLOT(slotNoteSaved(KJob*)) );
422 void KNote::saveNoteContent()
424 KMime::Message::Ptr message = mItem.payload<KMime::Message::Ptr>();
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() );
434 message->setHeader( header );
438 mItem.setPayload( message );
441 void KNote::slotPreferences()
445 NoteShared::NoteDisplayAttribute *attribute = mItem.attribute<NoteShared::NoteDisplayAttribute>( Akonadi::Entity::AddIfMissing );
448 dialog->load(mItem, m_editor->acceptRichText());
450 SLOT(slotUpdateCaption(
QString)) );
451 if (dialog->exec() ) {
453 dialog->save(mItem, isRichText);
454 m_editor->setAcceptRichText(isRichText);
456 Akonadi::ItemModifyJob *job =
new Akonadi::ItemModifyJob(mItem);
457 #ifdef DEBUG_SAVE_NOTE
458 qDebug()<<
"slotPreference slotNoteSaved(KJob*)";
460 connect( job, SIGNAL(result(KJob*)), SLOT(slotNoteSaved(KJob*)) );
465 void KNote::slotSend()
467 NoteShared::NoteUtils noteUtils;
468 noteUtils.sendToNetwork(
this,
name(),
text());
471 void KNote::slotMail()
473 NoteShared::NoteUtils noteUtils;
474 noteUtils.sendToMail(
this, m_label->
text(), m_editor->toPlainText());
477 void KNote::slotPrint()
482 void KNote::slotPrintPreview()
487 void KNote::print(
bool preview)
493 content = m_editor->
text();
499 KNotesGlobalConfig *globalConfig = KNotesGlobalConfig::self();
500 QString printingTheme = globalConfig->theme();
504 printingTheme = dlg->selectedTheme();
508 if (!printingTheme.
isEmpty()) {
512 printer.setDefaultFont( mDisplayAttribute->
font() );
513 printer.printNotes( lst, printingTheme, preview );
517 void KNote::slotSaveAs()
521 if ( m_editor->acceptRichText() ) {
523 convert->
setText( i18n(
"Save note as plain text" ) );
527 dlg->setOperationMode( KFileDialog::Saving );
528 dlg->setCaption( i18n(
"Save As" ) );
534 const QString fileName = dlg->selectedFile();
535 const bool htmlFormatAndSaveAsHtml = (convert && !convert->
isChecked());
541 QFile file( fileName );
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 ) {
551 if ( file.open( QIODevice::WriteOnly ) ) {
553 if ( htmlFormatAndSaveAsHtml ) {
554 QString htmlStr = m_editor->toHtml();
558 stream << m_editor->toPlainText();
563 void KNote::slotPopupActionToDesktop(
int id )
571 void KNote::slotApplyConfig()
581 slotUpdateShowInTaskbar();
586 void KNote::slotKeepAbove()
588 if ( m_keepBelow->isChecked() ) {
589 m_keepBelow->setChecked(
false );
591 slotUpdateKeepAboveBelow();
594 void KNote::slotKeepBelow()
596 if ( m_keepAbove->isChecked() ) {
597 m_keepAbove->setChecked(
false );
599 slotUpdateKeepAboveBelow();
602 void KNote::slotUpdateKeepAboveBelow(
bool save)
605 unsigned long state = KWindowInfo( KWindowSystem::windowInfo(
winId(), NET::WMState ) ).state();
607 unsigned long state = 0;
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 );
619 attribute->setKeepAbove(
false);
620 attribute->setKeepBelow(
false);
621 KWindowSystem::clearState(
winId(), NET::KeepAbove );
622 KWindowSystem::clearState(
winId(), NET::KeepBelow );
626 Akonadi::ItemModifyJob *job =
new Akonadi::ItemModifyJob(mItem);
627 #ifdef DEBUG_SAVE_NOTE
628 qDebug()<<
"slotUpdateKeepAboveBelow slotNoteSaved(KJob*)";
630 connect( job, SIGNAL(result(KJob*)), SLOT(slotNoteSaved(KJob*)) );
634 void KNote::slotUpdateShowInTaskbar()
638 KWindowSystem::setState(
winId(), KWindowSystem::windowInfo(
winId(),
639 NET::WMState ).state() | NET::SkipTaskbar );
641 KWindowSystem::clearState(
winId(), NET::SkipTaskbar );
646 void KNote::slotUpdateDesktopActions()
649 m_toDesktop->clear();
655 KAction *act = m_toDesktop->addAction(i18n(
"&All Desktops" ));
656 if (wm_client.desktop() == NETWinInfo::OnAllDesktops) {
657 act->setChecked(
true);
661 m_toDesktop->addAction(separator);
662 const int count = wm_root.numberOfDesktops();
663 for (
int n = 1; n <= count; ++n ) {
665 if (wm_client.desktop() == n) {
666 desktopAct->setChecked(
true);
675 void KNote::buildGui()
680 KXMLGUIBuilder builder(
this );
681 KXMLGUIFactory factory( &builder,
this );
682 factory.addClient(
this );
684 m_menu =
dynamic_cast<KMenu*
>( factory.container(
QLatin1String(
"note_context"),
this ) );
685 m_tool =
dynamic_cast<KToolBar*
>( factory.container(
QLatin1String(
"note_tool"),
this ) );
690 void KNote::createActions()
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()) );
700 action =
new KAction( KIcon(
QLatin1String(
"edit-rename") ), i18n(
"Rename..." ),
this );
701 actionCollection()->addAction(
QLatin1String(
"rename_note"), action );
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") ) );
711 action =
new KAction( KIcon(
QLatin1String(
"window-close") ), i18n(
"Hide" ),
this );
712 actionCollection()->addAction(
QLatin1String(
"hide_note"), action );
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 );
720 action =
new KAction( KIcon(
QLatin1String(
"knotes_alarm") ), i18n(
"Set Alarm..." ),
722 actionCollection()->addAction(
QLatin1String(
"set_alarm"), action );
723 connect( action, SIGNAL(triggered(
bool)), SLOT(slotSetAlarm()) );
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()) );
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()) );
733 action =
new KAction( KIcon(
QLatin1String(
"document-save-as") ), i18n(
"Save As..." ),
735 actionCollection()->addAction(
QLatin1String(
"save_note"), action );
736 connect( action, SIGNAL(triggered(
bool)), SLOT(slotSaveAs()) );
737 actionCollection()->addAction( KStandardAction::Print,
QLatin1String(
"print_note"),
this,
740 if (KPrintPreview::isAvailable()) {
741 actionCollection()->addAction( KStandardAction::PrintPreview,
QLatin1String(
"print_preview_note"),
this,
742 SLOT(slotPrintPreview()) );
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()) );
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()) );
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()) );
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()) );
769 slotUpdateDesktopActions();
772 action =
new KAction( i18n(
"Walk Through Notes" ),
this );
773 actionCollection()->addAction(
QLatin1String(
"walk_notes"), action );
775 action->setShortcut(
QKeySequence( Qt::SHIFT + Qt::Key_Backtab ) );
777 actionCollection()->addAssociatedWidget(
this );
780 if (mAllowDebugBaloo) {
782 action =
new KAction(
QLatin1String(
"Debug Baloo..."),
this );
783 actionCollection()->addAction(
QLatin1String(
"debug_baloo"), action );
784 connect( action, SIGNAL(triggered(
bool)), SLOT(slotDebugBaloo()) );
788 void KNote::createNoteHeader()
791 KConfigGroup styleGroup( m_kwinConf,
"Style" );
793 QBoxLayout::Direction headerLayoutDirection = QBoxLayout::LeftToRight;
795 if ( styleGroup.readEntry(
"CustomButtonPositions",
false ) ) {
796 if ( styleGroup.readEntry(
"ButtonsOnLeft" ).contains(
QLatin1Char(
'X') ) ) {
797 headerLayoutDirection = QBoxLayout::RightToLeft;
805 m_label =
new QLabel(
this );
818 m_noteLayout->
addItem( headerLayout );
821 void KNote::createNoteEditor(
const QString &configFile)
823 m_editor =
new KNoteEdit( configFile, actionCollection(),
this );
826 m_editor->installEventFilter(
this );
830 void KNote::slotRequestNewNote()
837 void KNote::createNoteFooter()
840 m_tool->setIconSize(
QSize( 10, 10 ) );
841 m_tool->setFixedHeight( 24 );
842 m_tool->setToolButtonStyle( Qt::ToolButtonIconOnly );
852 gripLayout->
setAlignment( m_tool, Qt::AlignBottom | Qt::AlignLeft );
857 gripLayout->
setAlignment( m_grip, Qt::AlignBottom | Qt::AlignRight );
858 m_noteLayout->
addItem( gripLayout );
862 foreach ( KComboBox *combo, m_tool->findChildren<KComboBox *>() ) {
865 combo->setFont( font );
866 combo->setFixedHeight( 14 );
871 void KNote::loadNoteContent(
const Akonadi::Item &item)
873 KMime::Message::Ptr noteMessage = item.payload<KMime::Message::Ptr>();
874 const KMime::Headers::Subject *
const subject = noteMessage ? noteMessage->subject(
false) : 0;
876 if ( noteMessage->contentType()->isHTMLText() ) {
877 m_editor->setAcceptRichText(
true);
878 m_editor->setHtml(noteMessage->mainBodyPart()->decodedText());
880 m_editor->setAcceptRichText(
false);
881 m_editor->setPlainText(noteMessage->mainBodyPart()->decodedText());
883 if ( noteMessage->headerByType(
"X-Cursor-Position" ) ) {
888 void KNote::prepare()
891 loadNoteContent(mItem);
896 desk.
adjust( 10, 10, -10, -10 );
907 if ( mItem.hasAttribute<NoteShared::NoteLockAttribute>() ) {
908 m_editor->setReadOnly(
true);
909 m_readOnly->setChecked(
true );
911 m_readOnly->setChecked(
false );
913 slotUpdateReadOnly();
916 int desktop = mDisplayAttribute->
desktop();
919 if ( ( desktop < 0 && desktop != NETWinInfo::OnAllDesktops ) ||
921 desktop = KWindowSystem::currentDesktop();
925 if ( desktop != 0 && !mDisplayAttribute->
isHidden() ) {
932 if ( desktop == NETWinInfo::OnAllDesktops ) {
939 m_keepAbove->setChecked(
true );
940 }
else if ( mDisplayAttribute->
keepBelow() ) {
941 m_keepBelow->setChecked(
true );
943 m_keepAbove->setChecked(
false );
944 m_keepBelow->setChecked(
false );
947 slotUpdateKeepAboveBelow();
952 const QPixmap icon = effect.apply( qApp->windowIcon().pixmap(
953 IconSize( KIconLoader::Desktop ),
954 IconSize( KIconLoader::Desktop ) ),
955 KIconEffect::Colorize,
958 const QPixmap miniIcon = effect.apply( qApp->windowIcon().pixmap(
959 IconSize( KIconLoader::Small ),
960 IconSize( KIconLoader::Small ) ),
961 KIconEffect::Colorize,
963 KWindowSystem::setIcons(
winId(), icon, miniIcon );
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 );
980 if ( desktop == 0 ) {
985 if ( desktop == NETWinInfo::OnAllDesktops ) {
986 KWindowSystem::setOnAllDesktops(
winId(),
true );
988 KWindowSystem::setOnDesktop(
winId(), desktop );
993 void KNote::setColor(
const QColor &fg,
const QColor &bg )
1003 p.
setColor( QPalette::Window, bg );
1008 p.
setColor( QPalette::WindowText, fg );
1012 p.
setColor( QPalette::ButtonText, fg );
1029 p.
setColor( QPalette::Active, QPalette::Base, bg.
dark( 116 ) );
1034 m_editor->setTextColor( fg );
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 );
1047 KWindowSystem::setIcons(
winId(), icon, miniIcon );
1054 void KNote::updateLabelAlignment()
1065 void KNote::updateFocus()
1068 if ( !m_editor->isReadOnly() ) {
1069 if ( m_tool && m_tool->isHidden() && m_editor->acceptRichText() ) {
1075 if ( m_tool && !m_tool->isHidden() ) {
1084 if ( m_tool && !m_tool->isHidden() ) {
1091 void KNote::updateLayout()
1094 updateLabelAlignment();
1108 if ( mDisplayAttribute->
isHidden() ) {
1110 slotUpdateKeepAboveBelow(
false);
1111 slotUpdateShowInTaskbar();
1114 NoteShared::NoteDisplayAttribute *attr = mItem.attribute<NoteShared::NoteDisplayAttribute>( Akonadi::Entity::AddIfMissing );
1116 attr->setIsHidden(
false);
1118 Akonadi::ItemModifyJob *job =
new Akonadi::ItemModifyJob(mItem);
1119 #ifdef DEBUG_SAVE_NOTE
1120 qDebug()<<
"showEvent slotNoteSaved(KJob*)";
1122 connect( job, SIGNAL(result(KJob*)), SLOT(slotNoteSaved(KJob*)) );
1135 if ( kapp->sessionSaving() ) {
1144 if ( !m_editor->isReadOnly() ) {
1151 if ( m_editor->isReadOnly() ) {
1159 NoteShared::NoteDisplayAttribute *attr = mItem.attribute<NoteShared::NoteDisplayAttribute>( Akonadi::Entity::AddIfMissing );
1161 attr->setBackgroundColor(bg);
1162 Akonadi::ItemModifyJob *job =
new Akonadi::ItemModifyJob(mItem);
1163 #ifdef DEBUG_SAVE_NOTE
1164 qDebug()<<
"dropEvent slotNoteSaved(KJob*)";
1166 connect( job, SIGNAL(result(KJob*)), SLOT(slotNoteSaved(KJob*)) );
1172 if ( ev->
type() == QEvent::LayoutRequest ) {
1182 if ( ev->
type() == QEvent::DragEnter &&
1188 if ( ev->
type() == QEvent::Drop &&
1189 static_cast<QDropEvent *
>( ev )->mimeData()->hasColor() ) {
1190 dropEvent( static_cast<QDropEvent *>( ev ) );
1194 if ( o == m_label ) {
1197 if ( ev->
type() == QEvent::MouseButtonDblClick ) {
1198 if(!m_editor->isReadOnly())
1202 if ( ev->
type() == QEvent::MouseButtonPress &&
1203 ( e->
button() == Qt::LeftButton || e->
button() == Qt::MidButton ) ) {
1205 e->
button() == Qt::LeftButton ? KWindowSystem::raiseWindow(
winId() )
1206 : KWindowSystem::lowerWindow(
winId() );
1216 if ( ev->
type() == QEvent::MouseButtonRelease ) {
1220 NET::MoveResizeCancel );
1228 if ( o == m_editor ) {
1229 if ( ev->
type() == QEvent::FocusOut ) {
1231 if ( fe->
reason() != Qt::PopupFocusReason &&
1232 fe->
reason() != Qt::MouseFocusReason ) {
1237 }
else if ( ev->
type() == QEvent::FocusIn ) {
1252 void KNote::slotDebugBaloo()
1255 dlg->setAkonadiId(mItem.id());
1256 dlg->setAttribute( Qt::WA_DeleteOnClose );
1257 dlg->setSearchType(PimCommon::BalooDebugSearchPathComboBox::Notes);
void slotKill(bool force=false)
void setDisplayAttribute(NoteShared::NoteDisplayAttribute *attr)
void setPointSize(int pointSize)
void setShortcutContext(Qt::ShortcutContext context)
void setTextFont(const QFont &font)
void setSeparator(bool b)
const QMimeData * mimeData() const
virtual void addItem(QLayoutItem *item)=0
QColor light(int factor) const
void setColor(ColorGroup group, ColorRole role, const QColor &color)
Qt::HANDLE appRootWindow(int screen)
virtual void showEvent(QShowEvent *)
bool intersects(const QRect &rectangle) const
void saveNote(bool force=false, bool sync=false)
void setColor(const QColor &fg, const QColor &bg)
bool isDesktopAssigned() const
void setAlignment(QFlags< Qt::AlignmentFlag >)
void setAutoIndentMode(bool newmode)
void setFrameStyle(int style)
void sigKillNote(Akonadi::Item::Id)
bool rememberDesktop() const
QColor dark(int factor) const
int cursorPositionFromStart() const
void setTabStop(int tabs)
virtual void dropEvent(QDropEvent *)
QString convertFromPlainText(const QString &plain, WhiteSpaceMode mode)
Qt::FocusReason reason() const
virtual bool eventFilter(QObject *, QEvent *)
QRect boundingRect(QChar ch) const
QString number(int n, int base)
void append(const T &value)
QString fromUtf8(const char *str, int size)
void setAccepted(bool accepted)
void installEventFilter(QObject *filterObj)
bool showInTaskbar() const
void setText(const QString &text)
void setNote(KNote *_note)
virtual void resizeEvent(QResizeEvent *)
virtual QSize sizeHint() const
Akonadi::Item item() const
void setMargin(int margin)
QVariant colorData() const
void setChangeItem(const Akonadi::Item &item, const QSet< QByteArray > &set=QSet< QByteArray >())
virtual bool event(QEvent *)
virtual void dragEnterEvent(QDragEnterEvent *)
bool contains(const T &value) const
bool setAlignment(QWidget *w, QFlags< Qt::AlignmentFlag > alignment)
QString & replace(int position, int n, QChar after)
KNOTES_EXPORT void setDefaultValue(Akonadi::Item &item)
virtual void closeEvent(QCloseEvent *)
QColor foregroundColor() const
Akonadi::Item::Id noteId() const
virtual void contextMenuEvent(QContextMenuEvent *)
void setName(const QString &name)
void adjust(int dx1, int dy1, int dx2, int dy2)
QColor backgroundColor() const
bool mightBeRichText(const QString &text)
void setText(const QString &text)
QString fromLatin1(const char *str, int size)
void toDesktop(int desktop)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KNote(const QDomDocument &buildDoc, const Akonadi::Item &item, bool allowDebugBaloo=false, QWidget *parent=0)
void setText(const QString &text)
virtual bool event(QEvent *e)
void setCursorPositionFromStart(int pos)
void sigNameChanged(const QString &)
void rect(int *x, int *y, int *width, int *height) const
QByteArray toUtf8() const