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 <kfinddialog.h>
52 #include <kinputdialog.h>
54 #include <tdeglobalsettings.h>
55 #include <tdefiledialog.h>
56 #include <tdeio/netaccess.h>
58 #include <libkcal/journal.h>
61 #include "knotebutton.h"
62 #include "knoteedit.h"
63 #include "knoteconfig.h"
64 #include "knotesglobalconfig.h"
65 #include "knoteconfigdlg.h"
66 #include "knotealarmdlg.h"
67 #include "knotehostdlg.h"
68 #include "knotesnetsend.h"
69 #include "knoteprinter.h"
72 #include "pushpin.xpm"
81 int KNote::s_ppOffset = 0;
83 KNote::KNote( TQDomDocument buildDoc, Journal *j, TQWidget *parent,
const char *name )
84 : TQFrame( parent, name, WStyle_Customize | WStyle_NoBorder | WDestructiveClose ),
85 m_label( 0 ), m_pushpin( 0 ), m_fold( 0 ), m_button( 0 ), m_tool( 0 ), m_editor( 0 ),
86 m_config( 0 ), m_journal( j ), m_find( 0 ),
87 m_twinConf( TDESharedConfig::openConfig(
"twinrc", true ) ),
88 m_busy( 0 ), m_deleteWhenIdle( false ), m_blockEmitDataChanged( false )
90 setAcceptDrops(
true );
91 actionCollection()->setWidget(
this );
93 setDOMDocument( buildDoc );
96 setXMLFile( instance()->instanceName() +
"ui.rc",
false,
false );
100 if ( m_journal->summary().isNull() && m_journal->dtStart().isValid() )
102 TQString s = TDEGlobal::locale()->formatDateTime( m_journal->dtStart() );
103 m_journal->setSummary( s );
108 new TDEAction( i18n(
"New"),
"document-new", 0,
109 TQT_TQOBJECT(
this),TQT_SLOT(slotRequestNewNote()) , actionCollection(),
"new_note" );
110 new TDEAction( i18n(
"Rename..."),
"text", 0,
111 TQT_TQOBJECT(
this), TQT_SLOT(slotRename()), actionCollection(),
"rename_note" );
112 m_readOnly =
new TDEToggleAction( i18n(
"Lock"),
"system-lock-screen" , 0,
113 TQT_TQOBJECT(
this), TQT_SLOT(slotUpdateReadOnly()), actionCollection(),
"lock_note" );
114 m_readOnly->setCheckedState( KGuiItem( i18n(
"Unlock"),
"unlock" ) );
115 new TDEAction( i18n(
"Hide"),
"window-close" , Key_Escape,
116 TQT_TQOBJECT(
this), TQT_SLOT(slotClose()), actionCollection(),
"hide_note" );
117 new TDEAction( i18n(
"Delete"),
"knotes_delete", 0,
118 TQT_TQOBJECT(
this), TQT_SLOT(slotKill()), actionCollection(),
"delete_note" );
120 new TDEAction( i18n(
"Insert Date"),
"knotes_date", 0 ,
121 TQT_TQOBJECT(
this), TQT_SLOT(slotInsDate()), actionCollection(),
"insert_date" );
122 new TDEAction( i18n(
"Set Alarm..."),
"knotes_alarm", 0 ,
123 TQT_TQOBJECT(
this), TQT_SLOT(slotSetAlarm()), actionCollection(),
"set_alarm" );
125 new TDEAction( i18n(
"Send..."),
"network", 0,
126 TQT_TQOBJECT(
this), TQT_SLOT(slotSend()), actionCollection(),
"send_note" );
127 new TDEAction( i18n(
"Mail..."),
"mail-send", 0,
128 TQT_TQOBJECT(
this), TQT_SLOT(slotMail()), actionCollection(),
"mail_note" );
129 new TDEAction( i18n(
"Save As..."),
"document-save-as", 0,
130 TQT_TQOBJECT(
this), TQT_SLOT(slotSaveAs()), actionCollection(),
"save_note" );
131 KStdAction::find( TQT_TQOBJECT(
this), TQT_SLOT(slotOpenFindDialog()), actionCollection() );
132 KStdAction::print( TQT_TQOBJECT(
this), TQT_SLOT(slotPrint()), actionCollection(),
"print_note" );
133 new TDEAction( i18n(
"Preferences..."),
"configure", 0,
134 TQT_TQOBJECT(
this), TQT_SLOT(slotPreferences()), actionCollection(),
"configure_note" );
136 m_keepAbove =
new TDEToggleAction( i18n(
"Keep Above Others"),
"go-up", 0,
137 TQT_TQOBJECT(
this), TQT_SLOT(slotUpdateKeepAboveBelow()), actionCollection(),
"keep_above" );
138 m_keepAbove->setExclusiveGroup(
"keepAB" );
140 m_keepBelow =
new TDEToggleAction( i18n(
"Keep Below Others"),
"go-down", 0,
141 TQT_TQOBJECT(
this), TQT_SLOT(slotUpdateKeepAboveBelow()), actionCollection(),
"keep_below" );
142 m_keepBelow->setExclusiveGroup(
"keepAB" );
144 m_toDesktop =
new TDEListAction( i18n(
"To Desktop"), 0,
145 TQT_TQOBJECT(
this), TQT_SLOT(slotPopupActionToDesktop(
int)), actionCollection(),
"to_desktop" );
146 connect( m_toDesktop->popupMenu(), TQT_SIGNAL(aboutToShow()), TQT_TQOBJECT(
this), TQT_SLOT(slotUpdateDesktopActions()) );
149 new TDEAction( i18n(
"Walk Through Notes"), 0, SHIFT+Key_BackTab,
150 TQT_TQOBJECT(
this), TQT_SIGNAL(sigShowNextNote()), actionCollection(),
"walk_notes" );
153 m_label =
new TQLabel(
this );
154 m_label->setFrameStyle( NoFrame );
155 m_label->setLineWidth( 0 );
156 m_label->installEventFilter(
this );
157 setName( m_journal->summary() );
159 m_button =
new KNoteButton(
"knotes_close",
this );
160 connect( m_button, TQT_SIGNAL(clicked()), TQT_TQOBJECT(
this), TQT_SLOT(slotClose()) );
163 m_editor =
new KNoteEdit( actionCollection(),
this );
164 m_editor->setNote(
this );
165 m_editor->installEventFilter(
this );
166 m_editor->viewport()->installEventFilter(
this );
167 connect( m_editor, TQT_SIGNAL(contentsMoving(
int,
int )), TQT_TQOBJECT(
this), TQT_SLOT(slotUpdateViewport(
int,
int )));
169 KXMLGUIBuilder builder(
this );
170 KXMLGUIFactory factory( &builder, TQT_TQOBJECT(
this) );
171 factory.addClient(
this );
173 m_menu =
dynamic_cast<TDEPopupMenu*
>(factory.container(
"note_context",
this ));
174 m_edit_menu =
dynamic_cast<TDEPopupMenu*
>(factory.container(
"note_edit",
this ));
175 m_tool =
dynamic_cast<TDEToolBar*
>(factory.container(
"note_tool",
this ));
178 m_tool->setIconSize( 10 );
179 m_tool->setFixedHeight( 16 );
180 m_tool->setIconText( TDEToolBar::IconOnly );
183 TQObjectList *list = m_tool->queryList(
"KComboBox" );
184 TQObjectListIt it( *list );
185 while ( it.current() != 0 )
187 KComboBox *combo = (KComboBox *)it.current();
188 TQFont font = combo->font();
189 font.setPointSize( 7 );
190 combo->setFont( font );
191 combo->setFixedHeight( 14 );
199 setFocusProxy( m_editor );
202 m_editor->setCornerWidget(
new TQSizeGrip(
this ) );
203 uint width = m_editor->cornerWidget()->width();
204 uint height = m_editor->cornerWidget()->height();
206 mask.resize( width, height );
209 array.setPoints( 3, 0, height, width, height, width, 0 );
212 p.setBrush( color1 );
213 p.drawPolygon( array );
215 m_editor->cornerWidget()->setMask( mask );
216 m_editor->cornerWidget()->setBackgroundMode( PaletteBase );
219 TQString configFile = TDEGlobal::dirs()->saveLocation(
"appdata",
"notes/" );
220 configFile += m_journal->uid();
224 bool newNote = !TDEIO::NetAccess::exists( KURL::fromPathOrURL( configFile ),
false, 0 );
226 m_config =
new KNoteConfig( TDESharedConfig::openConfig( configFile,
false,
false ) );
227 m_config->readConfig();
228 m_config->setVersion( KNOTES_VERSION );
233 KNotesGlobalConfig *globalConfig = KNotesGlobalConfig::self();
234 m_config->setBgColor( globalConfig->bgColor() );
235 m_config->setFgColor( globalConfig->fgColor() );
236 m_config->setWidth( globalConfig->width() );
237 m_config->setHeight( globalConfig->height() );
239 m_config->setFont( globalConfig->font() );
240 m_config->setTitleFont( globalConfig->titleFont() );
241 m_config->setAutoIndent( globalConfig->autoIndent() );
242 m_config->setRichText( globalConfig->richText() );
243 m_config->setTabSize( globalConfig->tabSize() );
244 m_config->setReadOnly( globalConfig->readOnly() );
246 m_config->setDesktop( globalConfig->desktop() );
247 m_config->setHideNote( globalConfig->hideNote() );
248 m_config->setPosition( globalConfig->position() );
249 m_config->setShowInTaskbar( globalConfig->showInTaskbar() );
250 m_config->setKeepAbove( globalConfig->keepAbove() );
251 m_config->setKeepBelow( globalConfig->keepBelow() );
253 m_config->writeConfig();
257 setMinimumSize( 20, 20 );
261 m_editor->setMargin( 0 );
262 m_editor->setFrameStyle( NoFrame );
263 m_editor->setBackgroundOrigin( WindowOrigin );
266 bool closeLeft =
false;
267 m_twinConf->setGroup(
"Style" );
268 if ( m_twinConf->readBoolEntry(
"CustomButtonPositions" ) )
269 closeLeft = m_twinConf->readEntry(
"ButtonsOnLeft" ).find(
'X' ) > -1;
271 TQPixmap pushpin_pix;
273 pushpin_pix = TQPixmap( TQPixmap( pushpin_xpm ).convertToImage().mirror(
true,
false ) );
275 pushpin_pix = TQPixmap( pushpin_xpm );
278 m_pushpin =
new TQLabel(
this );
279 m_pushpin->setScaledContents(
true );
280 m_pushpin->setBackgroundMode( NoBackground );
281 m_pushpin->setPixmap( pushpin_pix );
282 m_pushpin->resize( pushpin_pix.size() );
285 m_fold =
new TQLabel(
this );
286 m_fold->setScaledContents(
true );
287 m_fold->setBackgroundMode( NoBackground );
290 width = m_config->width();
291 height = m_config->height();
292 resize( width, height );
296 const TQPoint& position = m_config->position();
297 TQRect desk = kapp->desktop()->rect();
298 desk.addCoords( 10, 10, -10, -10 );
299 if ( desk.intersects( TQRect( position, TQSize( width, height ) ) ) )
303 TQString
property = m_journal->customProperty(
"KNotes",
"FgColor" );
304 if ( !property.isNull() )
305 m_config->setFgColor( TQColor( property ) );
307 m_journal->setCustomProperty(
"KNotes",
"FgColor", m_config->fgColor().name() );
309 property = m_journal->customProperty(
"KNotes",
"BgColor" );
310 if ( !property.isNull() )
311 m_config->setBgColor( TQColor( property ) );
313 m_journal->setCustomProperty(
"KNotes",
"BgColor", m_config->bgColor().name() );
315 property = m_journal->customProperty(
"KNotes",
"RichText" );
316 if ( !property.isNull() )
317 m_config->setRichText( property ==
"true" ?
true :
false );
319 m_journal->setCustomProperty(
"KNotes",
"RichText", m_config->richText() ?
"true" :
"false" );
326 m_fold->setMask( TQRegion( m_fold->pixmap()->createHeuristicMask() ) );
330 int desktop = m_config->desktop();
331 if ( desktop < 0 && desktop != NETWinInfo::OnAllDesktops )
332 desktop = KWin::currentDesktop();
335 if ( desktop != 0 && !m_config->hideNote() )
338 toDesktop( desktop );
342 if ( desktop == NETWinInfo::OnAllDesktops )
343 toDesktop( desktop );
346 m_editor->setText( m_journal->description() );
347 m_editor->setModified(
false );
349 m_readOnly->setChecked( m_config->readOnly() );
350 slotUpdateReadOnly();
352 if ( m_config->keepAbove() )
353 m_keepAbove->setChecked(
true );
354 else if ( m_config->keepBelow() )
355 m_keepBelow->setChecked(
true );
358 m_keepAbove->setChecked(
false );
359 m_keepBelow->setChecked(
false );
361 slotUpdateKeepAboveBelow();
364 TDEIconEffect effect;
365 TQPixmap icon = effect.apply( kapp->icon(), TDEIconEffect::Colorize, 1, m_config->bgColor(), false );
366 TQPixmap miniIcon = effect.apply( kapp->miniIcon(), TDEIconEffect::Colorize, 1, m_config->bgColor(), false );
367 KWin::setIcons( winId(), icon, miniIcon );
375 void KNote::slotRequestNewNote()
380 emit sigRequestNewNote();
383 void KNote::changeJournal(KCal::Journal *journal)
386 m_editor->setText( m_journal->description() );
387 m_label->setText( m_journal->summary() );
388 updateLabelAlignment();
393 void KNote::slotKill(
bool force )
395 m_blockEmitDataChanged =
true;
397 KMessageBox::warningContinueCancel(
this,
398 i18n(
"<qt>Do you really want to delete note <b>%1</b>?</qt>").arg( m_label->text() ),
399 i18n(
"Confirm Delete"), KGuiItem( i18n(
"&Delete"),
"edit-delete" ),
402 != KMessageBox::Continue )
404 m_blockEmitDataChanged =
false;
407 aboutToEnterEventLoop();
412 TQString configFile = TDEGlobal::dirs()->saveLocation(
"appdata",
"notes/" );
413 configFile += m_journal->uid();
415 if ( !TDEIO::NetAccess::del( KURL::fromPathOrURL( configFile ),
this ) )
416 kdError(5500) <<
"Can't remove the note config: " << configFile << endl;
418 emit sigKillNote( m_journal );
426 void KNote::saveData(
bool update)
428 m_journal->setSummary( m_label->text() );
429 m_journal->setDescription( m_editor->text() );
430 m_journal->setCustomProperty(
"KNotes",
"FgColor", m_config->fgColor().name() );
431 m_journal->setCustomProperty(
"KNotes",
"BgColor", m_config->bgColor().name() );
432 m_journal->setCustomProperty(
"KNotes",
"RichText", m_config->richText() ?
"true" :
"false" );
434 emit sigDataChanged( noteId() );
435 m_editor->setModified(
false );
439 void KNote::saveConfig()
const
441 m_config->setWidth( width() );
442 m_config->setHeight( height() );
443 m_config->setPosition( pos() );
445 NETWinInfo wm_client( tqt_xdisplay(), winId(), tqt_xrootwin(), NET::WMDesktop );
446 if ( wm_client.desktop() == NETWinInfo::OnAllDesktops || wm_client.desktop() > 0 )
447 m_config->setDesktop( wm_client.desktop() );
450 m_config->writeConfig();
453 TQString KNote::noteId()
const
455 return m_journal->uid();
458 TQString KNote::name()
const
460 return m_label->text();
463 TQString KNote::text()
const
465 return m_editor->text();
468 TQString KNote::plainText()
const
470 if ( m_editor->textFormat() == RichText )
473 conv.setTextFormat( RichText );
474 conv.setText( m_editor->text() );
475 conv.setTextFormat( PlainText );
479 return m_editor->text();
482 void KNote::setName(
const TQString& name )
484 m_label->setText( name );
485 updateLabelAlignment();
491 NETWinInfo note_win( tqt_xdisplay(), winId(), tqt_xrootwin(), NET::WMDesktop );
492 note_win.setName( name.utf8() );
494 emit sigNameChanged();
497 void KNote::setText(
const TQString& text )
499 m_editor->setText( text );
503 TQColor KNote::fgColor()
const
505 return m_config->fgColor();
508 TQColor KNote::bgColor()
const
510 return m_config->bgColor();
513 void KNote::setColor(
const TQColor& fg,
const TQColor& bg )
515 bool updateJournal =
false;
516 TQString journalFg = m_journal->customProperty(
"KNotes",
"FgColor" );
517 if ( journalFg.isEmpty() || journalFg != fg.name() )
519 m_journal->setCustomProperty(
"KNotes",
"FgColor", fg.name() );
520 updateJournal =
true;
522 TQString journalbg = m_journal->customProperty(
"KNotes",
"BgColor" );
523 if ( journalbg.isEmpty() || journalbg != bg.name() )
525 m_journal->setCustomProperty(
"KNotes",
"BgColor", bg.name() );
526 updateJournal =
true;
529 m_config->setFgColor( fg );
530 m_config->setBgColor( bg );
537 m_journal->updated();
538 emit sigDataChanged(noteId());
540 m_config->writeConfig();
542 TQPalette newpalette = palette();
543 newpalette.setColor( TQColorGroup::Background, bg );
544 newpalette.setColor( TQColorGroup::Foreground, fg );
545 newpalette.setColor( TQColorGroup::Base, bg );
546 newpalette.setColor( TQColorGroup::Text, fg );
547 newpalette.setColor( TQColorGroup::Button, bg );
548 newpalette.setColor( TQColorGroup::ButtonText, fg );
554 newpalette.setColor( TQColorGroup::Midlight, bg.light(150) );
555 newpalette.setColor( TQColorGroup::Shadow, bg.dark(116) );
556 newpalette.setColor( TQColorGroup::Light, bg.light(180) );
558 newpalette.setColor( TQColorGroup::Dark, bg.dark(200) );
560 newpalette.setColor( TQColorGroup::Dark, bg.dark(108) );
561 setPalette( newpalette );
564 m_editor->setTextColor( fg );
570 TQPalette darker = palette();
571 darker.setColor( TQColorGroup::Button, bg.dark(116) );
572 m_button->setPalette( darker );
575 TDEIconEffect effect;
576 TQPixmap icon = effect.apply( kapp->icon(), TDEIconEffect::Colorize, 1, bg, false );
577 TQPixmap miniIcon = effect.apply( kapp->miniIcon(), TDEIconEffect::Colorize, 1, bg, false );
578 KWin::setIcons( winId(), icon, miniIcon );
581 TQColor sel = palette().color( TQPalette::Active, TQColorGroup::Base ).dark();
582 if ( sel == TQt::black )
583 sel = palette().color( TQPalette::Active, TQColorGroup::Base ).light();
585 m_editor->setSelectionAttributes( 1, sel,
true );
592 emit sigColorChanged();
595 void KNote::slotOpenFindDialog()
597 KFindDialog findDia(
this,
"find_dialog" );
598 findDia.setHasSelection(
false );
599 findDia.setHasCursor(
false );
600 findDia.setSupportsBackwardsFind(
false );
602 if ( (findDia.exec() != TQDialog::Accepted) || findDia.pattern().isEmpty() )
605 find( findDia.pattern(), findDia.options(), true );
608 void KNote::find(
const TQString& pattern,
long options,
bool isLocal )
610 if(m_find)
delete m_find;
611 m_find =
new KFind( pattern, options,
this );
612 if(isLocal) m_find->setName(
"local");
614 connect( m_find, TQT_SIGNAL(highlight(
const TQString &,
int,
int )),
615 TQT_TQOBJECT(
this), TQT_SLOT(slotHighlight(
const TQString &,
int,
int )) );
616 connect( m_find, TQT_SIGNAL(findNext()), TQT_TQOBJECT(
this), TQT_SLOT(slotFindNext()) );
618 m_find->setData( plainText() );
622 void KNote::slotFindNext()
628 KFind::Result res = m_find->find();
630 if ( res == KFind::NoMatch )
632 m_editor->removeSelection( 1 );
633 if(TQString(m_find->name()) ==
"local")
634 m_find->displayFinalDialog();
635 else emit sigFindFinished();
642 KWin::setCurrentDesktop( KWin::windowInfo( winId() ).desktop() );
646 void KNote::slotHighlight(
const TQString& str,
int idx,
int len )
648 int paraFrom = 0, idxFrom = 0, p = 0;
649 for ( ; p < idx; ++p )
650 if ( str[p] ==
'\n' )
658 int paraTo = paraFrom, idxTo = idxFrom;
660 for ( ; p < idx + len; ++p )
662 if ( str[p] ==
'\n' )
671 m_editor->setSelection( paraFrom, idxFrom, paraTo, idxTo, 1 );
674 bool KNote::isModified()
const
676 return m_editor->isModified();
680 void KNote::sync(
const TQString& app )
682 TQByteArray sep( 1 );
688 hash.update( m_label->text().utf8() );
690 hash.update( m_editor->text().utf8() );
691 hash.hexDigest( result );
694 TDEConfig *config = m_config->config();
695 config->setGroup(
"Synchronisation" );
696 config->writeEntry( app, result.data() );
699 bool KNote::isNew(
const TQString& app )
const
701 TDEConfig *config = m_config->config();
702 config->setGroup(
"Synchronisation" );
703 TQString hash = config->readEntry( app );
704 return hash.isEmpty();
707 bool KNote::isModified(
const TQString& app )
const
709 TQByteArray sep( 1 );
713 hash.update( m_label->text().utf8() );
715 hash.update( m_editor->text().utf8() );
718 TDEConfig *config = m_config->config();
719 config->setGroup(
"Synchronisation" );
720 TQString orig = config->readEntry( app );
722 if ( hash.verify( orig.utf8() ) )
728 void KNote::setStyle(
int style )
730 if ( style == KNotesGlobalConfig::EnumStyle::Plain )
739 void KNote::slotRename()
741 m_blockEmitDataChanged =
true;
744 aboutToEnterEventLoop();
745 TQString oldName = m_label->text();
746 TQString newName = KInputDialog::getText( TQString(),
747 i18n(
"Please enter the new name:"), m_label->text(), &ok, this );
749 m_blockEmitDataChanged =
false;
750 if ( !ok || ( oldName == newName) )
756 void KNote::slotUpdateReadOnly()
758 const bool readOnly = m_readOnly->isChecked();
760 m_editor->setReadOnly( readOnly );
761 m_config->setReadOnly( readOnly );
764 actionCollection()->action(
"configure_note" )->setEnabled( !readOnly );
765 actionCollection()->action(
"insert_date" )->setEnabled( !readOnly );
766 actionCollection()->action(
"delete_note" )->setEnabled( !readOnly );
768 actionCollection()->action(
"edit_undo" )->setEnabled( !readOnly && m_editor->isUndoAvailable() );
769 actionCollection()->action(
"edit_redo" )->setEnabled( !readOnly && m_editor->isRedoAvailable() );
770 actionCollection()->action(
"edit_cut" )->setEnabled( !readOnly && m_editor->hasSelectedText() );
771 actionCollection()->action(
"edit_paste" )->setEnabled( !readOnly );
772 actionCollection()->action(
"edit_clear" )->setEnabled( !readOnly );
773 actionCollection()->action(
"rename_note" )->setEnabled( !readOnly );
775 actionCollection()->action(
"format_bold" )->setEnabled( !readOnly );
776 actionCollection()->action(
"format_italic" )->setEnabled( !readOnly );
777 actionCollection()->action(
"format_underline" )->setEnabled( !readOnly );
778 actionCollection()->action(
"format_strikeout" )->setEnabled( !readOnly );
779 actionCollection()->action(
"format_alignleft" )->setEnabled( !readOnly );
780 actionCollection()->action(
"format_aligncenter" )->setEnabled( !readOnly );
781 actionCollection()->action(
"format_alignright" )->setEnabled( !readOnly );
782 actionCollection()->action(
"format_alignblock" )->setEnabled( !readOnly );
783 actionCollection()->action(
"format_list" )->setEnabled( !readOnly );
784 actionCollection()->action(
"format_super" )->setEnabled( !readOnly );
785 actionCollection()->action(
"format_sub" )->setEnabled( !readOnly );
786 actionCollection()->action(
"format_size" )->setEnabled( !readOnly );
787 actionCollection()->action(
"format_color" )->setEnabled( !readOnly );
792 void KNote::slotClose()
794 NETWinInfo wm_client( tqt_xdisplay(), winId(), tqt_xrootwin(), NET::WMDesktop );
795 if ( wm_client.desktop() == NETWinInfo::OnAllDesktops || wm_client.desktop() > 0 )
796 m_config->setDesktop( wm_client.desktop() );
798 m_editor->clearFocus();
799 m_config->setHideNote(
true );
800 m_config->setPosition( pos() );
806 void KNote::slotInsDate()
808 m_editor->insert( TDEGlobal::locale()->formatDateTime(TQDateTime::currentDateTime()) );
811 void KNote::slotSetAlarm()
813 m_blockEmitDataChanged =
true;
814 KNoteAlarmDlg dlg( name(),
this );
815 dlg.setIncidence( m_journal );
817 aboutToEnterEventLoop();
818 if ( dlg.exec() == TQDialog::Accepted )
819 emit sigDataChanged(noteId());
821 m_blockEmitDataChanged =
false;
824 void KNote::slotPreferences()
827 if ( KNoteConfigDlg::showDialog( noteId().utf8() ) )
831 KNoteConfigDlg *dialog =
new KNoteConfigDlg( m_config, name(),
this, noteId().utf8() );
832 connect( dialog, TQT_SIGNAL(settingsChanged()), TQT_TQOBJECT(
this), TQT_SLOT(slotApplyConfig()) );
833 connect(
this, TQT_SIGNAL(sigNameChanged()), dialog, TQT_SLOT(slotUpdateCaption()) );
837 void KNote::slotSend()
840 KNoteHostDlg hostDlg( i18n(
"Send \"%1\"").arg( name() ),
this );
841 aboutToEnterEventLoop();
842 bool ok = (hostDlg.exec() == TQDialog::Accepted);
846 TQString host = hostDlg.host();
848 if ( host.isEmpty() )
850 KMessageBox::sorry(
this, i18n(
"The host cannot be empty.") );
855 KNotesNetworkSender *sender =
new KNotesNetworkSender( host, KNotesGlobalConfig::port() );
856 sender->setSenderId( KNotesGlobalConfig::senderID() );
857 sender->setNote( name(), text() );
861 void KNote::slotMail()
864 const TQStringList cmd_list = TQStringList::split( TQChar(
' '), KNotesGlobalConfig::mailAction() );
867 for ( TQStringList::ConstIterator it = cmd_list.constBegin();
868 it != cmd_list.constEnd(); ++it )
871 mail << plainText().local8Bit();
872 else if ( *it ==
"%t" )
873 mail << m_label->text().local8Bit();
875 mail << (*it).local8Bit();
878 if ( !mail.start( TDEProcess::DontCare ) )
879 KMessageBox::sorry(
this, i18n(
"Unable to start the mail process.") );
882 void KNote::slotPrint()
885 if ( m_editor->textFormat() == PlainText )
886 content = TQStyleSheet::convertFromPlainText( m_editor->text() );
888 content = m_editor->text();
890 KNotePrinter printer;
891 printer.setMimeSourceFactory( m_editor->mimeSourceFactory() );
892 printer.setFont( m_config->font() );
893 printer.setContext( m_editor->context() );
894 printer.setStyleSheet( m_editor->styleSheet() );
895 printer.setColorGroup( colorGroup() );
896 printer.printNote( TQString(), content );
899 void KNote::slotSaveAs()
901 m_blockEmitDataChanged =
true;
902 TQCheckBox *convert = 0;
904 if ( m_editor->textFormat() == RichText )
906 convert =
new TQCheckBox( 0 );
907 convert->setText( i18n(
"Save note as plain text") );
910 KFileDialog dlg( TQString(), TQString(),
this,
"filedialog",
true, convert );
911 dlg.setOperationMode( KFileDialog::Saving );
912 dlg.setCaption( i18n(
"Save As") );
913 aboutToEnterEventLoop();
917 TQString fileName = dlg.selectedFile();
918 if ( fileName.isEmpty() )
920 m_blockEmitDataChanged =
false;
923 TQFile file( fileName );
925 if ( file.exists() &&
926 KMessageBox::warningContinueCancel(
this, i18n(
"<qt>A file named <b>%1</b> already exists.<br>"
927 "Are you sure you want to overwrite it?</qt>").arg( TQFileInfo(file).fileName() ) )
928 != KMessageBox::Continue )
930 m_blockEmitDataChanged =
false;
934 if ( file.open( IO_WriteOnly ) )
936 TQTextStream stream( &file );
938 if ( convert && convert->isChecked() )
939 stream << plainText();
943 m_blockEmitDataChanged =
false;
946 void KNote::slotPopupActionToDesktop(
int id )
954 void KNote::slotApplyConfig()
956 if ( m_config->richText() )
957 m_editor->setTextFormat( RichText );
959 m_editor->setTextFormat( PlainText );
961 m_label->setFont( m_config->titleFont() );
962 m_editor->setTextFont( m_config->font() );
963 m_editor->setTabStop( m_config->tabSize() );
964 m_editor->setAutoIndentMode( m_config->autoIndent() );
971 setColor( m_config->fgColor(), m_config->bgColor() );
973 updateLabelAlignment();
974 slotUpdateShowInTaskbar();
977 void KNote::slotUpdateKeepAboveBelow()
979 KWin::WindowInfo info( KWin::windowInfo( winId() ) );
981 if ( m_keepAbove->isChecked() )
983 m_config->setKeepAbove(
true );
984 m_config->setKeepBelow(
false );
985 KWin::setState( winId(), info.state() | NET::KeepAbove );
987 else if ( m_keepBelow->isChecked() )
989 m_config->setKeepAbove(
false );
990 m_config->setKeepBelow(
true );
991 KWin::setState( winId(), info.state() | NET::KeepBelow );
995 m_config->setKeepAbove(
false );
996 KWin::clearState( winId(), NET::KeepAbove );
998 m_config->setKeepBelow(
false );
999 KWin::clearState( winId(), NET::KeepBelow );
1003 void KNote::slotUpdateShowInTaskbar()
1005 if ( !m_config->showInTaskbar() )
1006 KWin::setState( winId(), KWin::windowInfo(winId()).state() | NET::SkipTaskbar );
1008 KWin::clearState( winId(), NET::SkipTaskbar );
1011 void KNote::slotUpdateDesktopActions()
1013 NETRootInfo wm_root( tqt_xdisplay(), NET::NumberOfDesktops | NET::DesktopNames );
1014 NETWinInfo wm_client( tqt_xdisplay(), winId(), tqt_xrootwin(), NET::WMDesktop );
1016 TQStringList desktops;
1017 desktops.append( i18n(
"&All Desktops") );
1018 desktops.append( TQString() );
1020 int count = wm_root.numberOfDesktops();
1021 for (
int n = 1; n <= count; n++ )
1022 desktops.append( TQString(
"&%1 %2").arg( n ).arg( TQString::fromUtf8(wm_root.desktopName( n )) ) );
1024 m_toDesktop->setItems( desktops );
1026 if ( wm_client.desktop() == NETWinInfo::OnAllDesktops )
1027 m_toDesktop->setCurrentItem( 0 );
1029 m_toDesktop->setCurrentItem( wm_client.desktop() + 1 );
1032 void KNote::slotUpdateViewport(
int ,
int y )
1035 updateBackground( y );
1040 void KNote::toDesktop(
int desktop )
1045 if ( desktop == NETWinInfo::OnAllDesktops )
1046 KWin::setOnAllDesktops( winId(),
true );
1048 KWin::setOnDesktop( winId(), desktop );
1051 void KNote::createFold()
1053 TQPixmap fold( 15, 15 );
1054 TQPainter foldp( &fold );
1055 foldp.setPen( TQt::NoPen );
1056 foldp.setBrush( palette().active().dark() );
1057 TQPointArray foldpoints( 3 );
1058 foldpoints.putPoints( 0, 3, 0, 0, 14, 0, 0, 14 );
1059 foldp.drawPolygon( foldpoints );
1061 m_fold->setPixmap( fold );
1064 void KNote::updateLabelAlignment()
1067 TQString labelText = m_label->text();
1068 if ( m_label->fontMetrics().boundingRect( labelText ).width() > m_label->width() )
1069 m_label->setAlignment( AlignLeft );
1071 m_label->setAlignment( AlignHCenter );
1074 void KNote::updateFocus()
1078 m_label->setBackgroundColor( palette().active().shadow() );
1081 if ( !m_editor->isReadOnly() )
1083 if ( m_tool && m_tool->isHidden() && m_editor->textFormat() == TQTextEdit::RichText )
1088 m_editor->cornerWidget()->show();
1092 if ( m_tool && !m_tool->isHidden() )
1097 m_editor->cornerWidget()->hide();
1105 m_editor->cornerWidget()->hide();
1107 if ( m_tool && !m_tool->isHidden() )
1115 m_label->setBackgroundColor( palette().active().midlight() );
1119 m_label->setBackgroundColor( palette().active().background() );
1123 void KNote::updateMask()
1133 TQRegion reg( 0, s_ppOffset, w, h - s_ppOffset );
1135 const TQBitmap *pushpin_bitmap = m_pushpin->pixmap()->mask();
1136 TQRegion pushpin_reg( *pushpin_bitmap );
1137 m_pushpin->setMask( pushpin_reg );
1138 pushpin_reg.translate( m_pushpin->x(), m_pushpin->y() );
1142 TQPointArray foldpoints( 3 );
1143 foldpoints.putPoints( 0, 3, w-15, h, w, h-15, w, h );
1144 TQRegion fold( foldpoints,
false );
1145 setMask( reg.unite( pushpin_reg ).subtract( fold ) );
1148 setMask( reg.unite( pushpin_reg ) );
1151 void KNote::updateBackground(
int y_offset )
1155 m_editor->setPaper( TQBrush( colorGroup().background() ) );
1159 int w = m_editor->visibleWidth();
1160 int h = m_editor->visibleHeight();
1165 if ( y_offset == -1 )
1166 y_offset = m_editor->contentsY();
1168 y_offset = y_offset % h;
1170 TQImage grad_img( w, h, 32 );
1172 TQColor bg = palette().active().background();
1174 for (
int i = 0; i < h; ++i )
1183 int i_1 = 150 - 75 * ((i - y_offset + h) % h) / h;
1184 rgbcol = bg.light( i_1 ).rgb();
1185 for (
int j = 0; j < w; ++j )
1186 grad_img.setPixel( j, i, rgbcol );
1190 m_editor->setPaper( TQBrush( TQt::black, TQPixmap( grad_img ) ) );
1193 void KNote::updateLayout()
1195 const int headerHeight = m_label->sizeHint().height();
1196 const int margin = m_editor->margin();
1197 bool closeLeft =
false;
1199 m_twinConf->setGroup(
"Style" );
1200 if ( m_twinConf->readBoolEntry(
"CustomButtonPositions" ) )
1201 closeLeft = m_twinConf->readEntry(
"ButtonsOnLeft" ).find(
'X' ) > -1;
1205 if ( !m_editor->paper().pixmap() )
1206 setColor( palette().active().foreground(), palette().active().background() );
1209 setFrameStyle( Panel | Raised );
1212 m_pushpin->move( width() - m_pushpin->width(), 0 );
1214 m_pushpin->move( 0, 0 );
1218 if ( m_editor->paper().pixmap() )
1219 setColor( palette().active().foreground(), palette().active().background() );
1221 setFrameStyle( WinPanel | Raised );
1226 m_button->setGeometry(
1227 closeLeft ? contentsRect().x() : contentsRect().width() - headerHeight,
1228 contentsRect().y() + s_ppOffset,
1233 m_label->setGeometry(
1234 contentsRect().x(), contentsRect().y() + s_ppOffset,
1235 contentsRect().width(), headerHeight
1238 m_editor->setGeometry( TQRect(
1239 TQPoint( contentsRect().x(),
1240 contentsRect().y() + headerHeight + s_ppOffset ),
1241 TQPoint( contentsRect().right(),
1242 contentsRect().bottom() - ( m_tool ? (m_tool->isHidden() ? 0 : m_tool->height()) : 0 ) )
1246 m_tool->setGeometry(
1248 contentsRect().bottom() - m_tool->height() + 1,
1249 contentsRect().width(),
1255 m_fold->move( width() - 15, height() - 15 );
1258 m_editor->cornerWidget()->width() + margin*2,
1259 headerHeight + s_ppOffset + ( m_tool ? m_tool->height() : 0 ) +
1260 m_editor->cornerWidget()->height() + margin*2
1263 updateLabelAlignment();
1270 void KNote::drawFrame( TQPainter *p )
1272 TQRect r = frameRect();
1273 r.setTop( s_ppOffset );
1275 qDrawShadePanel( p, r, colorGroup(),
false, lineWidth() );
1277 qDrawWinPanel( p, r, colorGroup(),
false );
1280 void KNote::showEvent( TQShowEvent * )
1282 if ( m_config->hideNote() )
1285 slotUpdateKeepAboveBelow();
1286 slotUpdateShowInTaskbar();
1287 toDesktop( m_config->desktop() );
1288 move( m_config->position() );
1289 m_config->setHideNote(
false );
1293 void KNote::resizeEvent( TQResizeEvent *qre )
1295 TQFrame::resizeEvent( qre );
1299 void KNote::closeEvent( TQCloseEvent *event )
1301 if(kapp->sessionSaving())
1307 void KNote::dragEnterEvent( TQDragEnterEvent *e )
1309 if ( !m_config->readOnly() )
1310 e->accept( KColorDrag::canDecode( e ) );
1313 void KNote::dropEvent( TQDropEvent *e )
1315 if ( m_config->readOnly() )
1319 if ( KColorDrag::decode( e, bg ) )
1320 setColor( paletteForegroundColor(), bg );
1323 bool KNote::focusNextPrevChild(
bool )
1328 bool KNote::event( TQEvent *ev )
1330 if ( ev->type() == TQEvent::LayoutHint )
1336 return TQFrame::event( ev );
1339 bool KNote::eventFilter( TQObject *o, TQEvent *ev )
1341 if ( ev->type() == TQEvent::DragEnter &&
1342 KColorDrag::canDecode( static_cast<TQDragEnterEvent *>(ev) ) )
1344 dragEnterEvent( static_cast<TQDragEnterEvent *>(ev) );
1348 if ( ev->type() == TQEvent::Drop &&
1349 KColorDrag::canDecode( static_cast<TQDropEvent *>(ev) ) )
1351 dropEvent( static_cast<TQDropEvent *>(ev) );
1355 if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(m_label) )
1357 TQMouseEvent *e = (TQMouseEvent *)ev;
1359 if ( ev->type() == TQEvent::MouseButtonDblClick )
1361 if( !m_editor->isReadOnly())
1364 if ( ev->type() == TQEvent::MouseButtonPress &&
1365 (e->button() == Qt::LeftButton || e->button() == Qt::MidButton))
1367 e->button() == Qt::LeftButton ? KWin::raiseWindow( winId() )
1368 : KWin::lowerWindow( winId() );
1370 XUngrabPointer( tqt_xdisplay(), GET_QT_X_TIME() );
1371 NETRootInfo wm_root( tqt_xdisplay(), NET::WMMoveResize );
1372 wm_root.moveResizeRequest( winId(), e->globalX(), e->globalY(), NET::Move );
1376 #if KDE_IS_VERSION( 3, 5, 1 )
1377 if ( ev->type() == TQEvent::MouseButtonRelease )
1379 NETRootInfo wm_root( tqt_xdisplay(), NET::WMMoveResize );
1380 wm_root.moveResizeRequest( winId(), e->globalX(), e->globalY(), NET::MoveResizeCancel );
1385 if ( m_menu && ( ev->type() == TQEvent::MouseButtonPress )
1386 && ( e->button() == Qt::RightButton ) )
1388 m_menu->popup( TQCursor::pos() );
1395 if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(m_editor) ) {
1396 if ( ev->type() == TQEvent::FocusOut ) {
1397 TQFocusEvent *fe = TQT_TQFOCUSEVENT(ev);
1398 if ( fe->reason() != TQFocusEvent::Popup &&
1399 fe->reason() != TQFocusEvent::Mouse ) {
1401 if ( isModified() ) {
1403 if ( !m_blockEmitDataChanged )
1407 }
else if ( ev->type() == TQEvent::FocusIn ) {
1414 if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(m_editor->viewport()) )
1417 ev->type() == TQEvent::MouseButtonPress &&
1418 ((TQMouseEvent *)ev)->button() == Qt::RightButton )
1420 m_edit_menu->popup( TQCursor::pos() );
1428 void KNote::slotSaveData()
1433 void KNote::deleteWhenIdle()
1438 m_deleteWhenIdle =
true;
1441 void KNote::aboutToEnterEventLoop()
1446 void KNote::eventLoopLeft()
1449 if ( m_busy <= 0 && m_deleteWhenIdle )
1454 #include "knote.moc"
1455 #include "knotebutton.moc"
A dialog to request a hostname or IP address.