22 #include <tqdrawutil.h>
24 #include <tqsizegrip.h>
27 #include <tqpainter.h>
28 #include <tqpaintdevicemetrics.h>
29 #include <tqsimplerichtext.h>
30 #include <tqobjectlist.h>
32 #include <tqcheckbox.h>
35 #include <tdeapplication.h>
37 #include <tdeaction.h>
38 #include <kstdaction.h>
39 #include <kcombobox.h>
40 #include <tdetoolbar.h>
41 #include <tdepopupmenu.h>
42 #include <kxmlguibuilder.h>
43 #include <kxmlguifactory.h>
44 #include <kcolordrag.h>
45 #include <kiconeffect.h>
46 #include <tdelocale.h>
47 #include <kstandarddirs.h>
48 #include <tdemessagebox.h>
50 #include <tdeprocess.h>
51 #include <kinputdialog.h>
53 #include <tdeglobalsettings.h>
54 #include <tdefiledialog.h>
55 #include <tdeio/netaccess.h>
57 #include <libkcal/journal.h>
60 #include "knotebutton.h"
61 #include "knoteedit.h"
62 #include "knoteconfig.h"
63 #include "knotesglobalconfig.h"
64 #include "knoteconfigdlg.h"
65 #include "knotealarmdlg.h"
66 #include "knotehostdlg.h"
67 #include "knotesnetsend.h"
68 #include "knoteprinter.h"
71 #include "pushpin.xpm"
80 int KNote::s_ppOffset = 0;
82 KNote::KNote( TQDomDocument buildDoc, Journal *j, TQWidget *parent,
const char *name )
83 : TQFrame( parent, name, WStyle_Customize | WStyle_NoBorder | WDestructiveClose ),
84 m_label( 0 ), m_pushpin( 0 ), m_fold( 0 ), m_button( 0 ), m_tool( 0 ), m_editor( 0 ),
85 m_config( 0 ), m_journal( j ), m_find( 0 ),
86 m_twinConf( TDESharedConfig::openConfig(
"twinrc", true ) ),
87 m_busy( 0 ), m_deleteWhenIdle( false ), m_blockEmitDataChanged( false )
89 setAcceptDrops(
true );
90 actionCollection()->setWidget(
this );
92 setDOMDocument( buildDoc );
95 setXMLFile( instance()->instanceName() +
"ui.rc",
false,
false );
99 if ( m_journal->summary().isNull() && m_journal->dtStart().isValid() )
101 TQString s = TDEGlobal::locale()->formatDateTime( m_journal->dtStart() );
102 m_journal->setSummary( s );
107 new TDEAction( i18n(
"New"),
"document-new", 0,
108 this,TQ_SLOT(slotRequestNewNote()) , actionCollection(),
"new_note" );
109 new TDEAction( i18n(
"Rename..."),
"text", 0,
110 this, TQ_SLOT(slotRename()), actionCollection(),
"rename_note" );
111 m_readOnly =
new TDEToggleAction( i18n(
"Lock"),
"system-lock-screen" , 0,
112 this, TQ_SLOT(slotUpdateReadOnly()), actionCollection(),
"lock_note" );
113 m_readOnly->setCheckedState( KGuiItem( i18n(
"Unlock"),
"unlock" ) );
114 new TDEAction( i18n(
"Hide"),
"window-close" , Key_Escape,
115 this, TQ_SLOT(slotClose()), actionCollection(),
"hide_note" );
116 new TDEAction( i18n(
"Delete"),
"knotes_delete", 0,
117 this, TQ_SLOT(slotKill()), actionCollection(),
"delete_note" );
119 new TDEAction( i18n(
"Insert Date"),
"knotes_date", 0 ,
120 this, TQ_SLOT(slotInsDate()), actionCollection(),
"insert_date" );
121 new TDEAction( i18n(
"Set Alarm..."),
"knotes_alarm", 0 ,
122 this, TQ_SLOT(slotSetAlarm()), actionCollection(),
"set_alarm" );
124 new TDEAction( i18n(
"Send..."),
"network", 0,
125 this, TQ_SLOT(slotSend()), actionCollection(),
"send_note" );
126 new TDEAction( i18n(
"Mail..."),
"mail-send", 0,
127 this, TQ_SLOT(slotMail()), actionCollection(),
"mail_note" );
128 new TDEAction( i18n(
"Save As..."),
"document-save-as", 0,
129 this, TQ_SLOT(slotSaveAs()), actionCollection(),
"save_note" );
130 KStdAction::print(
this, TQ_SLOT(slotPrint()), actionCollection(),
"print_note" );
131 new TDEAction( i18n(
"Preferences..."),
"configure", 0,
132 this, TQ_SLOT(slotPreferences()), actionCollection(),
"configure_note" );
134 m_keepAbove =
new TDEToggleAction( i18n(
"Keep Above Others"),
"go-up", 0,
135 this, TQ_SLOT(slotUpdateKeepAboveBelow()), actionCollection(),
"keep_above" );
136 m_keepAbove->setExclusiveGroup(
"keepAB" );
138 m_keepBelow =
new TDEToggleAction( i18n(
"Keep Below Others"),
"go-down", 0,
139 this, TQ_SLOT(slotUpdateKeepAboveBelow()), actionCollection(),
"keep_below" );
140 m_keepBelow->setExclusiveGroup(
"keepAB" );
142 m_toDesktop =
new TDEListAction( i18n(
"To Desktop"), 0,
143 this, TQ_SLOT(slotPopupActionToDesktop(
int)), actionCollection(),
"to_desktop" );
144 connect( m_toDesktop->popupMenu(), TQ_SIGNAL(aboutToShow()),
this, TQ_SLOT(slotUpdateDesktopActions()) );
147 new TDEAction( i18n(
"Walk Through Notes"), 0, SHIFT+Key_BackTab,
148 this, TQ_SIGNAL(sigShowNextNote()), actionCollection(),
"walk_notes" );
151 m_label =
new TQLabel(
this );
152 m_label->setFrameStyle( NoFrame );
153 m_label->setLineWidth( 0 );
154 m_label->installEventFilter(
this );
155 setName( m_journal->summary() );
157 m_button =
new KNoteButton(
"knotes_close",
this );
158 connect( m_button, TQ_SIGNAL(clicked()),
this, TQ_SLOT(slotClose()) );
161 m_editor =
new KNoteEdit( actionCollection(),
this );
162 m_editor->setNote(
this );
163 m_editor->installEventFilter(
this );
164 m_editor->viewport()->installEventFilter(
this );
165 connect( m_editor, TQ_SIGNAL(contentsMoving(
int,
int )),
this, TQ_SLOT(slotUpdateViewport(
int,
int )));
167 KXMLGUIBuilder builder(
this );
168 KXMLGUIFactory factory( &builder,
this );
169 factory.addClient(
this );
171 m_menu =
dynamic_cast<TDEPopupMenu*
>(factory.container(
"note_context",
this ));
172 m_edit_menu =
dynamic_cast<TDEPopupMenu*
>(factory.container(
"note_edit",
this ));
173 m_tool =
dynamic_cast<TDEToolBar*
>(factory.container(
"note_tool",
this ));
176 m_tool->setIconSize( 10 );
177 m_tool->setFixedHeight( 16 );
178 m_tool->setIconText( TDEToolBar::IconOnly );
181 TQObjectList *list = m_tool->queryList(
"KComboBox" );
182 TQObjectListIt it( *list );
183 while ( it.current() != 0 )
185 KComboBox *combo = (KComboBox *)it.current();
186 TQFont font = combo->font();
187 font.setPointSize( 7 );
188 combo->setFont( font );
189 combo->setFixedHeight( 14 );
197 setFocusProxy( m_editor );
200 m_editor->setCornerWidget(
new TQSizeGrip(
this ) );
201 uint width = m_editor->cornerWidget()->width();
202 uint height = m_editor->cornerWidget()->height();
204 mask.resize( width, height );
207 array.setPoints( 3, 0, height, width, height, width, 0 );
210 p.setBrush( color1 );
211 p.drawPolygon( array );
213 m_editor->cornerWidget()->setMask( mask );
214 m_editor->cornerWidget()->setBackgroundMode( PaletteBase );
217 TQString configFile = TDEGlobal::dirs()->saveLocation(
"appdata",
"notes/" );
218 configFile += m_journal->uid();
222 bool newNote = !TDEIO::NetAccess::exists( KURL::fromPathOrURL( configFile ),
false, 0 );
224 m_config =
new KNoteConfig( TDESharedConfig::openConfig( configFile,
false,
false ) );
225 m_config->readConfig();
226 m_config->setVersion( KNOTES_VERSION );
231 KNotesGlobalConfig *globalConfig = KNotesGlobalConfig::self();
232 m_config->setBgColor( globalConfig->bgColor() );
233 m_config->setFgColor( globalConfig->fgColor() );
234 m_config->setWidth( globalConfig->width() );
235 m_config->setHeight( globalConfig->height() );
237 m_config->setFont( globalConfig->font() );
238 m_config->setTitleFont( globalConfig->titleFont() );
239 m_config->setAutoIndent( globalConfig->autoIndent() );
240 m_config->setRichText( globalConfig->richText() );
241 m_config->setTabSize( globalConfig->tabSize() );
242 m_config->setReadOnly( globalConfig->readOnly() );
244 m_config->setDesktop( globalConfig->desktop() );
245 m_config->setHideNote( globalConfig->hideNote() );
246 m_config->setPosition( globalConfig->position() );
247 m_config->setShowInTaskbar( globalConfig->showInTaskbar() );
248 m_config->setKeepAbove( globalConfig->keepAbove() );
249 m_config->setKeepBelow( globalConfig->keepBelow() );
251 m_config->writeConfig();
255 setMinimumSize( 20, 20 );
259 m_editor->setMargin( 0 );
260 m_editor->setFrameStyle( NoFrame );
261 m_editor->setBackgroundOrigin( WindowOrigin );
264 bool closeLeft =
false;
265 m_twinConf->setGroup(
"Style" );
266 if ( m_twinConf->readBoolEntry(
"CustomButtonPositions" ) )
267 closeLeft = m_twinConf->readEntry(
"ButtonsOnLeft" ).find(
'X' ) > -1;
269 TQPixmap pushpin_pix;
271 pushpin_pix = TQPixmap( TQPixmap( pushpin_xpm ).convertToImage().mirror(
true,
false ) );
273 pushpin_pix = TQPixmap( pushpin_xpm );
276 m_pushpin =
new TQLabel(
this );
277 m_pushpin->setScaledContents(
true );
278 m_pushpin->setBackgroundMode( NoBackground );
279 m_pushpin->setPixmap( pushpin_pix );
280 m_pushpin->resize( pushpin_pix.size() );
283 m_fold =
new TQLabel(
this );
284 m_fold->setScaledContents(
true );
285 m_fold->setBackgroundMode( NoBackground );
288 width = m_config->width();
289 height = m_config->height();
290 resize( width, height );
294 const TQPoint& position = m_config->position();
295 TQRect desk = kapp->desktop()->rect();
296 desk.addCoords( 10, 10, -10, -10 );
297 if ( desk.intersects( TQRect( position, TQSize( width, height ) ) ) )
301 TQString
property = m_journal->customProperty(
"KNotes",
"FgColor" );
302 if ( !property.isNull() )
303 m_config->setFgColor( TQColor( property ) );
305 m_journal->setCustomProperty(
"KNotes",
"FgColor", m_config->fgColor().name() );
307 property = m_journal->customProperty(
"KNotes",
"BgColor" );
308 if ( !property.isNull() )
309 m_config->setBgColor( TQColor( property ) );
311 m_journal->setCustomProperty(
"KNotes",
"BgColor", m_config->bgColor().name() );
313 property = m_journal->customProperty(
"KNotes",
"RichText" );
314 if ( !property.isNull() )
315 m_config->setRichText( property ==
"true" ?
true :
false );
317 m_journal->setCustomProperty(
"KNotes",
"RichText", m_config->richText() ?
"true" :
"false" );
324 m_fold->setMask( TQRegion( m_fold->pixmap()->createHeuristicMask() ) );
328 int desktop = m_config->desktop();
329 if ( desktop < 0 && desktop != NETWinInfo::OnAllDesktops )
330 desktop = KWin::currentDesktop();
333 if ( desktop != 0 && !m_config->hideNote() )
336 toDesktop( desktop );
340 if ( desktop == NETWinInfo::OnAllDesktops )
341 toDesktop( desktop );
344 m_editor->setText( m_journal->description() );
345 m_editor->setModified(
false );
347 m_readOnly->setChecked( m_config->readOnly() );
348 slotUpdateReadOnly();
350 if ( m_config->keepAbove() )
351 m_keepAbove->setChecked(
true );
352 else if ( m_config->keepBelow() )
353 m_keepBelow->setChecked(
true );
356 m_keepAbove->setChecked(
false );
357 m_keepBelow->setChecked(
false );
359 slotUpdateKeepAboveBelow();
362 TDEIconEffect effect;
363 TQPixmap icon = effect.apply( kapp->icon(), TDEIconEffect::Colorize, 1, m_config->bgColor(),
false );
364 TQPixmap miniIcon = effect.apply( kapp->miniIcon(), TDEIconEffect::Colorize, 1, m_config->bgColor(),
false );
365 KWin::setIcons( winId(), icon, miniIcon );
373 void KNote::slotRequestNewNote()
378 emit sigRequestNewNote();
381 void KNote::changeJournal(KCal::Journal *journal)
384 m_editor->setText( m_journal->description() );
385 m_label->setText( m_journal->summary() );
386 updateLabelAlignment();
391 void KNote::slotKill(
bool force )
393 m_blockEmitDataChanged =
true;
395 KMessageBox::warningContinueCancel(
this,
396 i18n(
"<qt>Do you really want to delete note <b>%1</b>?</qt>").arg( m_label->text() ),
397 i18n(
"Confirm Delete"), KGuiItem( i18n(
"&Delete"),
"edit-delete" ),
400 != KMessageBox::Continue )
402 m_blockEmitDataChanged =
false;
405 aboutToEnterEventLoop();
410 TQString configFile = TDEGlobal::dirs()->saveLocation(
"appdata",
"notes/" );
411 configFile += m_journal->uid();
413 if ( !TDEIO::NetAccess::del( KURL::fromPathOrURL( configFile ),
this ) )
414 kdError(5500) <<
"Can't remove the note config: " << configFile << endl;
416 emit sigKillNote( m_journal );
424 void KNote::saveData(
bool update)
426 m_journal->setSummary( m_label->text() );
427 m_journal->setDescription( m_editor->text() );
428 m_journal->setCustomProperty(
"KNotes",
"FgColor", m_config->fgColor().name() );
429 m_journal->setCustomProperty(
"KNotes",
"BgColor", m_config->bgColor().name() );
430 m_journal->setCustomProperty(
"KNotes",
"RichText", m_config->richText() ?
"true" :
"false" );
432 emit sigDataChanged( noteId() );
433 m_editor->setModified(
false );
437 void KNote::saveConfig()
const
439 m_config->setWidth( width() );
440 m_config->setHeight( height() );
441 m_config->setPosition( pos() );
443 NETWinInfo wm_client( tqt_xdisplay(), winId(), tqt_xrootwin(), NET::WMDesktop );
444 if ( wm_client.desktop() == NETWinInfo::OnAllDesktops || wm_client.desktop() > 0 )
445 m_config->setDesktop( wm_client.desktop() );
448 m_config->writeConfig();
451 TQString KNote::noteId()
const
453 return m_journal->uid();
456 TQDateTime KNote::getLastModified()
const
458 return m_journal->lastModified();
461 TQString KNote::name()
const
463 return m_label->text();
466 TQString KNote::text()
const
468 return m_editor->text();
471 TQString KNote::plainText()
const
473 if ( m_editor->textFormat() == RichText )
476 conv.setTextFormat( RichText );
477 conv.setText( m_editor->text() );
478 conv.setTextFormat( PlainText );
482 return m_editor->text();
485 void KNote::setName(
const TQString& name )
487 m_label->setText( name );
488 updateLabelAlignment();
494 NETWinInfo note_win( tqt_xdisplay(), winId(), tqt_xrootwin(), NET::WMDesktop );
495 note_win.setName( name.utf8() );
497 emit sigNameChanged();
500 void KNote::setText(
const TQString& text )
502 m_editor->setText( text );
506 TQColor KNote::fgColor()
const
508 return m_config->fgColor();
511 TQColor KNote::bgColor()
const
513 return m_config->bgColor();
516 void KNote::setColor(
const TQColor& fg,
const TQColor& bg )
518 bool updateJournal =
false;
519 TQString journalFg = m_journal->customProperty(
"KNotes",
"FgColor" );
520 if ( journalFg.isEmpty() || journalFg != fg.name() )
522 m_journal->setCustomProperty(
"KNotes",
"FgColor", fg.name() );
523 updateJournal =
true;
525 TQString journalbg = m_journal->customProperty(
"KNotes",
"BgColor" );
526 if ( journalbg.isEmpty() || journalbg != bg.name() )
528 m_journal->setCustomProperty(
"KNotes",
"BgColor", bg.name() );
529 updateJournal =
true;
532 m_config->setFgColor( fg );
533 m_config->setBgColor( bg );
540 m_journal->updated();
541 emit sigDataChanged(noteId());
543 m_config->writeConfig();
545 TQPalette newpalette = palette();
546 newpalette.setColor( TQColorGroup::Background, bg );
547 newpalette.setColor( TQColorGroup::Foreground, fg );
548 newpalette.setColor( TQColorGroup::Base, bg );
549 newpalette.setColor( TQColorGroup::Text, fg );
550 newpalette.setColor( TQColorGroup::Button, bg );
551 newpalette.setColor( TQColorGroup::ButtonText, fg );
557 newpalette.setColor( TQColorGroup::Midlight, bg.light(150) );
558 newpalette.setColor( TQColorGroup::Shadow, bg.dark(116) );
559 newpalette.setColor( TQColorGroup::Light, bg.light(180) );
561 newpalette.setColor( TQColorGroup::Dark, bg.dark(200) );
563 newpalette.setColor( TQColorGroup::Dark, bg.dark(108) );
564 setPalette( newpalette );
567 m_editor->setTextColor( fg );
573 TQPalette darker = palette();
574 darker.setColor( TQColorGroup::Button, bg.dark(116) );
575 m_button->setPalette( darker );
578 TDEIconEffect effect;
579 TQPixmap icon = effect.apply( kapp->icon(), TDEIconEffect::Colorize, 1, bg,
false );
580 TQPixmap miniIcon = effect.apply( kapp->miniIcon(), TDEIconEffect::Colorize, 1, bg,
false );
581 KWin::setIcons( winId(), icon, miniIcon );
584 TQColor sel = palette().color( TQPalette::Active, TQColorGroup::Base ).dark();
585 if ( sel == TQt::black )
586 sel = palette().color( TQPalette::Active, TQColorGroup::Base ).light();
588 m_editor->setSelectionAttributes( 1, sel,
true );
595 emit sigColorChanged();
598 void KNote::find(
const TQString& pattern,
long options )
601 m_find =
new KFind( pattern, options,
this );
603 connect( m_find, TQ_SIGNAL(highlight(
const TQString &,
int,
int )),
604 this, TQ_SLOT(slotHighlight(
const TQString &,
int,
int )) );
605 connect( m_find, TQ_SIGNAL(findNext()),
this, TQ_SLOT(slotFindNext()) );
607 m_find->setData( plainText() );
611 void KNote::slotFindNext()
617 KFind::Result res = m_find->find();
619 if ( res == KFind::NoMatch )
621 m_editor->removeSelection( 1 );
622 emit sigFindFinished();
629 KWin::setCurrentDesktop( KWin::windowInfo( winId() ).desktop() );
633 void KNote::slotHighlight(
const TQString& str,
int idx,
int len )
635 int paraFrom = 0, idxFrom = 0, p = 0;
636 for ( ; p < idx; ++p )
637 if ( str[p] ==
'\n' )
645 int paraTo = paraFrom, idxTo = idxFrom;
647 for ( ; p < idx + len; ++p )
649 if ( str[p] ==
'\n' )
658 m_editor->setSelection( paraFrom, idxFrom, paraTo, idxTo, 1 );
661 bool KNote::isModified()
const
663 return m_editor->isModified();
667 void KNote::sync(
const TQString& app )
669 TQByteArray sep( 1 );
675 hash.update( m_label->text().utf8() );
677 hash.update( m_editor->text().utf8() );
678 hash.hexDigest( result );
681 TDEConfig *config = m_config->config();
682 config->setGroup(
"Synchronisation" );
683 config->writeEntry( app, result.data() );
686 bool KNote::isNew(
const TQString& app )
const
688 TDEConfig *config = m_config->config();
689 config->setGroup(
"Synchronisation" );
690 TQString hash = config->readEntry( app );
691 return hash.isEmpty();
694 bool KNote::isModified(
const TQString& app )
const
696 TQByteArray sep( 1 );
700 hash.update( m_label->text().utf8() );
702 hash.update( m_editor->text().utf8() );
705 TDEConfig *config = m_config->config();
706 config->setGroup(
"Synchronisation" );
707 TQString orig = config->readEntry( app );
709 if ( hash.verify( orig.utf8() ) )
715 void KNote::setStyle(
int style )
717 if ( style == KNotesGlobalConfig::EnumStyle::Plain )
726 void KNote::slotRename()
728 m_blockEmitDataChanged =
true;
731 aboutToEnterEventLoop();
732 TQString oldName = m_label->text();
733 TQString newName = KInputDialog::getText( TQString(),
734 i18n(
"Please enter the new name:"), m_label->text(), &ok,
this );
736 m_blockEmitDataChanged =
false;
737 if ( !ok || ( oldName == newName) )
743 void KNote::slotUpdateReadOnly()
745 const bool readOnly = m_readOnly->isChecked();
747 m_editor->setReadOnly( readOnly );
748 m_config->setReadOnly( readOnly );
751 actionCollection()->action(
"configure_note" )->setEnabled( !readOnly );
752 actionCollection()->action(
"insert_date" )->setEnabled( !readOnly );
753 actionCollection()->action(
"delete_note" )->setEnabled( !readOnly );
755 actionCollection()->action(
"edit_undo" )->setEnabled( !readOnly && m_editor->isUndoAvailable() );
756 actionCollection()->action(
"edit_redo" )->setEnabled( !readOnly && m_editor->isRedoAvailable() );
757 actionCollection()->action(
"edit_cut" )->setEnabled( !readOnly && m_editor->hasSelectedText() );
758 actionCollection()->action(
"edit_paste" )->setEnabled( !readOnly );
759 actionCollection()->action(
"edit_clear" )->setEnabled( !readOnly );
760 actionCollection()->action(
"rename_note" )->setEnabled( !readOnly );
762 actionCollection()->action(
"format_bold" )->setEnabled( !readOnly );
763 actionCollection()->action(
"format_italic" )->setEnabled( !readOnly );
764 actionCollection()->action(
"format_underline" )->setEnabled( !readOnly );
765 actionCollection()->action(
"format_strikeout" )->setEnabled( !readOnly );
766 actionCollection()->action(
"format_alignleft" )->setEnabled( !readOnly );
767 actionCollection()->action(
"format_aligncenter" )->setEnabled( !readOnly );
768 actionCollection()->action(
"format_alignright" )->setEnabled( !readOnly );
769 actionCollection()->action(
"format_alignblock" )->setEnabled( !readOnly );
770 actionCollection()->action(
"format_list" )->setEnabled( !readOnly );
771 actionCollection()->action(
"format_super" )->setEnabled( !readOnly );
772 actionCollection()->action(
"format_sub" )->setEnabled( !readOnly );
773 actionCollection()->action(
"format_size" )->setEnabled( !readOnly );
774 actionCollection()->action(
"format_color" )->setEnabled( !readOnly );
779 void KNote::slotClose()
781 NETWinInfo wm_client( tqt_xdisplay(), winId(), tqt_xrootwin(), NET::WMDesktop );
782 if ( wm_client.desktop() == NETWinInfo::OnAllDesktops || wm_client.desktop() > 0 )
783 m_config->setDesktop( wm_client.desktop() );
785 m_editor->clearFocus();
786 m_config->setHideNote(
true );
787 m_config->setPosition( pos() );
793 void KNote::slotInsDate()
795 m_editor->insert( TDEGlobal::locale()->formatDateTime(TQDateTime::currentDateTime()) );
798 void KNote::slotSetAlarm()
800 m_blockEmitDataChanged =
true;
801 KNoteAlarmDlg dlg( name(),
this );
802 dlg.setIncidence( m_journal );
804 aboutToEnterEventLoop();
805 if ( dlg.exec() == TQDialog::Accepted )
806 emit sigDataChanged(noteId());
808 m_blockEmitDataChanged =
false;
811 void KNote::slotPreferences()
814 if ( KNoteConfigDlg::showDialog( noteId().utf8() ) )
818 KNoteConfigDlg *dialog =
new KNoteConfigDlg( m_config, name(),
this, noteId().utf8() );
819 connect( dialog, TQ_SIGNAL(settingsChanged()),
this, TQ_SLOT(slotApplyConfig()) );
820 connect(
this, TQ_SIGNAL(sigNameChanged()), dialog, TQ_SLOT(slotUpdateCaption()) );
824 void KNote::slotSend()
827 KNoteHostDlg hostDlg( i18n(
"Send \"%1\"").arg( name() ),
this );
828 aboutToEnterEventLoop();
829 bool ok = (hostDlg.exec() == TQDialog::Accepted);
833 TQString host = hostDlg.host();
835 if ( host.isEmpty() )
837 KMessageBox::sorry(
this, i18n(
"The host cannot be empty.") );
842 KNotesNetworkSender *sender =
new KNotesNetworkSender( host, KNotesGlobalConfig::port() );
843 sender->setSenderId( KNotesGlobalConfig::senderID() );
844 sender->setNote( name(), text() );
848 void KNote::slotMail()
851 const TQStringList cmd_list = TQStringList::split( TQChar(
' '), KNotesGlobalConfig::mailAction() );
854 for ( TQStringList::ConstIterator it = cmd_list.constBegin();
855 it != cmd_list.constEnd(); ++it )
858 mail << plainText().local8Bit();
859 else if ( *it ==
"%t" )
860 mail << m_label->text().local8Bit();
862 mail << (*it).local8Bit();
865 if ( !mail.start( TDEProcess::DontCare ) )
866 KMessageBox::sorry(
this, i18n(
"Unable to start the mail process.") );
869 void KNote::slotPrint()
872 if ( m_editor->textFormat() == PlainText )
873 content = TQStyleSheet::convertFromPlainText( m_editor->text() );
875 content = m_editor->text();
877 KNotePrinter printer;
878 printer.setMimeSourceFactory( m_editor->mimeSourceFactory() );
879 printer.setFont( m_config->font() );
880 printer.setContext( m_editor->context() );
881 printer.setStyleSheet( m_editor->styleSheet() );
882 printer.setColorGroup( colorGroup() );
883 printer.printNote( TQString(), content );
886 void KNote::slotSaveAs()
888 m_blockEmitDataChanged =
true;
889 TQCheckBox *convert = 0;
891 if ( m_editor->textFormat() == RichText )
893 convert =
new TQCheckBox( 0 );
894 convert->setText( i18n(
"Save note as plain text") );
897 KFileDialog dlg( TQString(), TQString(),
this,
"filedialog",
true, convert );
898 dlg.setOperationMode( KFileDialog::Saving );
899 dlg.setCaption( i18n(
"Save As") );
900 aboutToEnterEventLoop();
904 TQString fileName = dlg.selectedFile();
905 if ( fileName.isEmpty() )
907 m_blockEmitDataChanged =
false;
910 TQFile file( fileName );
912 if ( file.exists() &&
913 KMessageBox::warningContinueCancel(
this, i18n(
"<qt>A file named <b>%1</b> already exists.<br>"
914 "Are you sure you want to overwrite it?</qt>").arg( TQFileInfo(file).fileName() ) )
915 != KMessageBox::Continue )
917 m_blockEmitDataChanged =
false;
921 if ( file.open( IO_WriteOnly ) )
923 TQTextStream stream( &file );
925 if ( convert && convert->isChecked() )
926 stream << plainText();
930 m_blockEmitDataChanged =
false;
933 void KNote::slotPopupActionToDesktop(
int id )
941 void KNote::slotApplyConfig()
943 if ( m_config->richText() )
944 m_editor->setTextFormat( RichText );
946 m_editor->setTextFormat( PlainText );
948 m_label->setFont( m_config->titleFont() );
949 m_editor->setTextFont( m_config->font() );
950 m_editor->setTabStop( m_config->tabSize() );
951 m_editor->setAutoIndentMode( m_config->autoIndent() );
958 setColor( m_config->fgColor(), m_config->bgColor() );
960 updateLabelAlignment();
961 slotUpdateShowInTaskbar();
964 void KNote::slotUpdateKeepAboveBelow()
966 KWin::WindowInfo info( KWin::windowInfo( winId() ) );
968 if ( m_keepAbove->isChecked() )
970 m_config->setKeepAbove(
true );
971 m_config->setKeepBelow(
false );
972 KWin::setState( winId(), info.state() | NET::KeepAbove );
974 else if ( m_keepBelow->isChecked() )
976 m_config->setKeepAbove(
false );
977 m_config->setKeepBelow(
true );
978 KWin::setState( winId(), info.state() | NET::KeepBelow );
982 m_config->setKeepAbove(
false );
983 KWin::clearState( winId(), NET::KeepAbove );
985 m_config->setKeepBelow(
false );
986 KWin::clearState( winId(), NET::KeepBelow );
990 void KNote::slotUpdateShowInTaskbar()
992 if ( !m_config->showInTaskbar() )
993 KWin::setState( winId(), KWin::windowInfo(winId()).state() | NET::SkipTaskbar );
995 KWin::clearState( winId(), NET::SkipTaskbar );
998 void KNote::slotUpdateDesktopActions()
1000 NETRootInfo wm_root( tqt_xdisplay(), NET::NumberOfDesktops | NET::DesktopNames );
1001 NETWinInfo wm_client( tqt_xdisplay(), winId(), tqt_xrootwin(), NET::WMDesktop );
1003 TQStringList desktops;
1004 desktops.append( i18n(
"&All Desktops") );
1005 desktops.append( TQString() );
1007 int count = wm_root.numberOfDesktops();
1008 for (
int n = 1; n <= count; n++ )
1009 desktops.append( TQString(
"&%1 %2").arg( n ).arg( TQString::fromUtf8(wm_root.desktopName( n )) ) );
1011 m_toDesktop->setItems( desktops );
1013 if ( wm_client.desktop() == NETWinInfo::OnAllDesktops )
1014 m_toDesktop->setCurrentItem( 0 );
1016 m_toDesktop->setCurrentItem( wm_client.desktop() + 1 );
1019 void KNote::slotUpdateViewport(
int ,
int y )
1022 updateBackground( y );
1027 void KNote::toDesktop(
int desktop )
1032 if ( desktop == NETWinInfo::OnAllDesktops )
1033 KWin::setOnAllDesktops( winId(),
true );
1035 KWin::setOnDesktop( winId(), desktop );
1038 void KNote::createFold()
1040 TQPixmap fold( 15, 15 );
1041 TQPainter foldp( &fold );
1042 foldp.setPen( TQt::NoPen );
1043 foldp.setBrush( palette().active().dark() );
1044 TQPointArray foldpoints( 3 );
1045 foldpoints.putPoints( 0, 3, 0, 0, 14, 0, 0, 14 );
1046 foldp.drawPolygon( foldpoints );
1048 m_fold->setPixmap( fold );
1051 void KNote::updateLabelAlignment()
1054 TQString labelText = m_label->text();
1055 if ( m_label->fontMetrics().boundingRect( labelText ).width() > m_label->width() )
1056 m_label->setAlignment( AlignLeft );
1058 m_label->setAlignment( AlignHCenter );
1061 void KNote::updateFocus()
1065 m_label->setBackgroundColor( palette().active().shadow() );
1068 if ( !m_editor->isReadOnly() )
1070 if ( m_tool && m_tool->isHidden() && m_editor->textFormat() == TQTextEdit::RichText )
1075 m_editor->cornerWidget()->show();
1079 if ( m_tool && !m_tool->isHidden() )
1084 m_editor->cornerWidget()->hide();
1092 m_editor->cornerWidget()->hide();
1094 if ( m_tool && !m_tool->isHidden() )
1102 m_label->setBackgroundColor( palette().active().midlight() );
1106 m_label->setBackgroundColor( palette().active().background() );
1110 void KNote::updateMask()
1120 TQRegion reg( 0, s_ppOffset, w, h - s_ppOffset );
1122 const TQBitmap *pushpin_bitmap = m_pushpin->pixmap()->mask();
1123 TQRegion pushpin_reg( *pushpin_bitmap );
1124 m_pushpin->setMask( pushpin_reg );
1125 pushpin_reg.translate( m_pushpin->x(), m_pushpin->y() );
1129 TQPointArray foldpoints( 3 );
1130 foldpoints.putPoints( 0, 3, w-15, h, w, h-15, w, h );
1131 TQRegion fold( foldpoints,
false );
1132 setMask( reg.unite( pushpin_reg ).subtract( fold ) );
1135 setMask( reg.unite( pushpin_reg ) );
1138 void KNote::updateBackground(
int y_offset )
1142 m_editor->setPaper( TQBrush( colorGroup().background() ) );
1146 int w = m_editor->visibleWidth();
1147 int h = m_editor->visibleHeight();
1152 if ( y_offset == -1 )
1153 y_offset = m_editor->contentsY();
1155 y_offset = y_offset % h;
1157 TQImage grad_img( w, h, 32 );
1159 TQColor bg = palette().active().background();
1161 for (
int i = 0; i < h; ++i )
1170 int i_1 = 150 - 75 * ((i - y_offset + h) % h) / h;
1171 rgbcol = bg.light( i_1 ).rgb();
1172 for (
int j = 0; j < w; ++j )
1173 grad_img.setPixel( j, i, rgbcol );
1177 m_editor->setPaper( TQBrush( TQt::black, TQPixmap( grad_img ) ) );
1180 void KNote::updateLayout()
1182 const int headerHeight = m_label->sizeHint().height();
1183 const int margin = m_editor->margin();
1184 bool closeLeft =
false;
1186 m_twinConf->setGroup(
"Style" );
1187 if ( m_twinConf->readBoolEntry(
"CustomButtonPositions" ) )
1188 closeLeft = m_twinConf->readEntry(
"ButtonsOnLeft" ).find(
'X' ) > -1;
1192 if ( !m_editor->paper().pixmap() )
1193 setColor( palette().active().foreground(), palette().active().background() );
1196 setFrameStyle( Panel | Raised );
1199 m_pushpin->move( width() - m_pushpin->width(), 0 );
1201 m_pushpin->move( 0, 0 );
1205 if ( m_editor->paper().pixmap() )
1206 setColor( palette().active().foreground(), palette().active().background() );
1208 setFrameStyle( WinPanel | Raised );
1213 m_button->setGeometry(
1214 closeLeft ? contentsRect().x() : contentsRect().width() - headerHeight,
1215 contentsRect().y() + s_ppOffset,
1220 m_label->setGeometry(
1221 contentsRect().x(), contentsRect().y() + s_ppOffset,
1222 contentsRect().width(), headerHeight
1225 m_editor->setGeometry( TQRect(
1226 TQPoint( contentsRect().x(),
1227 contentsRect().y() + headerHeight + s_ppOffset ),
1228 TQPoint( contentsRect().right(),
1229 contentsRect().bottom() - ( m_tool ? (m_tool->isHidden() ? 0 : m_tool->height()) : 0 ) )
1233 m_tool->setGeometry(
1235 contentsRect().bottom() - m_tool->height() + 1,
1236 contentsRect().width(),
1242 m_fold->move( width() - 15, height() - 15 );
1245 m_editor->cornerWidget()->width() + margin*2,
1246 headerHeight + s_ppOffset + ( m_tool ? m_tool->height() : 0 ) +
1247 m_editor->cornerWidget()->height() + margin*2
1250 updateLabelAlignment();
1257 void KNote::drawFrame( TQPainter *p )
1259 TQRect r = frameRect();
1260 r.setTop( s_ppOffset );
1262 qDrawShadePanel( p, r, colorGroup(),
false, lineWidth() );
1264 qDrawWinPanel( p, r, colorGroup(),
false );
1267 void KNote::showEvent( TQShowEvent * )
1269 if ( m_config->hideNote() )
1272 slotUpdateKeepAboveBelow();
1273 slotUpdateShowInTaskbar();
1274 toDesktop( m_config->desktop() );
1275 move( m_config->position() );
1276 m_config->setHideNote(
false );
1280 void KNote::resizeEvent( TQResizeEvent *qre )
1282 TQFrame::resizeEvent( qre );
1286 void KNote::closeEvent( TQCloseEvent *event )
1288 if(kapp->sessionSaving())
1294 void KNote::dragEnterEvent( TQDragEnterEvent *e )
1296 if ( !m_config->readOnly() )
1297 e->accept( KColorDrag::canDecode( e ) );
1300 void KNote::dropEvent( TQDropEvent *e )
1302 if ( m_config->readOnly() )
1306 if ( KColorDrag::decode( e, bg ) )
1307 setColor( paletteForegroundColor(), bg );
1310 bool KNote::focusNextPrevChild(
bool )
1315 bool KNote::event( TQEvent *ev )
1317 if ( ev->type() == TQEvent::LayoutHint )
1323 return TQFrame::event( ev );
1326 bool KNote::eventFilter( TQObject *o, TQEvent *ev )
1328 if ( ev->type() == TQEvent::DragEnter &&
1329 KColorDrag::canDecode(
static_cast<TQDragEnterEvent *
>(ev) ) )
1331 dragEnterEvent(
static_cast<TQDragEnterEvent *
>(ev) );
1335 if ( ev->type() == TQEvent::Drop &&
1336 KColorDrag::canDecode(
static_cast<TQDropEvent *
>(ev) ) )
1338 dropEvent(
static_cast<TQDropEvent *
>(ev) );
1344 TQMouseEvent *e = (TQMouseEvent *)ev;
1346 if ( ev->type() == TQEvent::MouseButtonDblClick )
1348 if( !m_editor->isReadOnly())
1351 if ( ev->type() == TQEvent::MouseButtonPress &&
1352 (e->button() == TQt::LeftButton || e->button() == TQt::MidButton))
1354 e->button() == TQt::LeftButton ? KWin::raiseWindow( winId() )
1355 : KWin::lowerWindow( winId() );
1357 XUngrabPointer( tqt_xdisplay(), get_tqt_x_time() );
1358 NETRootInfo wm_root( tqt_xdisplay(), NET::WMMoveResize );
1359 wm_root.moveResizeRequest( winId(), e->globalX(), e->globalY(), NET::Move );
1363 #if KDE_IS_VERSION( 3, 5, 1 )
1364 if ( ev->type() == TQEvent::MouseButtonRelease )
1366 NETRootInfo wm_root( tqt_xdisplay(), NET::WMMoveResize );
1367 wm_root.moveResizeRequest( winId(), e->globalX(), e->globalY(), NET::MoveResizeCancel );
1372 if ( m_menu && ( ev->type() == TQEvent::MouseButtonPress )
1373 && ( e->button() == TQt::RightButton ) )
1375 m_menu->popup( TQCursor::pos() );
1382 if ( o == m_editor ) {
1383 if ( ev->type() == TQEvent::FocusOut ) {
1384 TQFocusEvent *fe =
static_cast<TQFocusEvent*
>(ev);
1385 if ( fe->reason() != TQFocusEvent::Popup &&
1386 fe->reason() != TQFocusEvent::Mouse ) {
1388 if ( isModified() ) {
1390 if ( !m_blockEmitDataChanged )
1394 }
else if ( ev->type() == TQEvent::FocusIn ) {
1401 if ( o == m_editor->viewport() )
1404 ev->type() == TQEvent::MouseButtonPress &&
1405 ((TQMouseEvent *)ev)->button() == TQt::RightButton )
1407 m_edit_menu->popup( TQCursor::pos() );
1415 void KNote::slotSaveData()
1420 void KNote::deleteWhenIdle()
1425 m_deleteWhenIdle =
true;
1428 void KNote::aboutToEnterEventLoop()
1433 void KNote::eventLoopLeft()
1436 if ( m_busy <= 0 && m_deleteWhenIdle )
1441 #include "knote.moc"
1442 #include "knotebutton.moc"
A dialog to request a hostname or IP address.