[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kopete-devel
Subject:    Re: [kopete-devel] Turning on/off auto spell checking from the
From:       Matt Rogers <mattr () kde ! org>
Date:       2005-06-13 0:46:57
Message-ID: 200506121947.00190.mattr () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


On Sunday 12 June 2005 07:26 pm, Matt Rogers wrote:
> Hi,
>
> I'd like to add an item to the chat window's settings menu that will allow
> the user to enable or disable automatic spell checking from there.
>
> This seems like a logical place to put it and so I hope there are no
> objections. I almost have a patch ready and will submit it when i'm done
> with it.
>
> Matt

Ok, here's the patch. Please review and indicate whether or not y'all would 
think this would be useful.

Thanks,
Matt

["chatwindow-spell-check-setting.patch" (text/x-diff)]

Index: kopetechatwindow.rc
===================================================================
--- kopetechatwindow.rc	(revision 424493)
+++ kopetechatwindow.rc	(working copy)
@@ -1,5 +1,5 @@
 <!DOCTYPE kpartgui>
-<kpartgui version="28" name="kopetechatwindow">
+<kpartgui version="30" name="kopetechatwindow">
 	<MenuBar>
 		<Menu noMerge="1" name="file">
 			<text>&amp;Chat</text>
@@ -37,6 +37,7 @@
 				<Action name="options_membersright" />
 				<Action name="options_togglemembers" />
 			</Menu>
+			<Action name="enable_auto_spell_check" />
 			<Action append="show_merge" name="options_styles"/>
 			<Action append="configure_merge" name="settings_prefs" />
 		</Menu>
Index: chatview.cpp
===================================================================
--- chatview.cpp	(revision 424713)
+++ chatview.cpp	(working copy)
@@ -735,10 +735,7 @@ void ChatView::slotMarkMessageRead()
 
 void ChatView::slotToggleRtfToolbar( bool enabled )
 {
-	if ( enabled )
-		m_mainWindow->toolBar( "formatToolBar" )->show();
-	else
-		m_mainWindow->toolBar( "formatToolBar" )->hide();
+	emit rtfEnabled( this, enabled );
 }
 
 void ChatView::slotContactStatusChanged( Kopete::Contact *contact, const \
                Kopete::OnlineStatus &newStatus, const Kopete::OnlineStatus \
                &oldStatus )
Index: kopetechatwindow.cpp
===================================================================
--- kopetechatwindow.cpp	(revision 424493)
+++ kopetechatwindow.cpp	(working copy)
@@ -376,7 +376,10 @@ void KopeteChatWindow::initActions(void)
 	toggleMembers = new KToggleAction( i18n( "Show" ), QString::null, 0,
 		this, SLOT( slotToggleViewMembers() ), coll, "options_togglemembers" );
 	toggleMembers->setCheckedState(i18n("Hide"));
-
+	toggleAutoSpellCheck = new KToggleAction( i18n( "Automatic Spell Checking" ), \
QString::null, 0, +		this, SLOT( toggleAutoSpellChecking() ), coll, \
"enable_auto_spell_check" ); +	toggleAutoSpellCheck->setChecked( true );
+	
 	actionSmileyMenu = new KopeteEmoticonAction( coll, "format_smiley" );
 	actionSmileyMenu->setDelayed( false );
 	connect(actionSmileyMenu, SIGNAL(activated(const QString &)), this, \
SLOT(slotSmileyActivated(const QString &))); @@ -479,6 +482,32 @@ void \
KopeteChatWindow::slotToggleViewMem  updateMembersActions();
 }
 
+void KopeteChatWindow::toggleAutoSpellChecking()
+{
+	if ( !m_activeView )
+		return;
+
+	bool currentSetting = m_activeView->editPart()->autoSpellCheckEnabled();
+	m_activeView->editPart()->toggleAutoSpellCheck( !currentSetting );
+	updateSpellCheckAction();
+}
+
+void KopeteChatWindow::updateSpellCheckAction()
+{
+	if ( !m_activeView )
+		return;
+
+	if ( m_activeView->editPart()->richTextEnabled() )
+		toggleAutoSpellCheck->setEnabled( false );
+	else
+		toggleAutoSpellCheck->setEnabled( true );
+
+	if ( m_activeView->editPart()->autoSpellCheckEnabled() )
+		toggleAutoSpellCheck->setChecked( true );
+	else
+		toggleAutoSpellCheck->setChecked( false );
+}
+
 void KopeteChatWindow::slotHistoryUp()
 {
 	if( m_activeView )
@@ -656,7 +685,8 @@ void KopeteChatWindow::attachChatView( C
 	connect( newView, SIGNAL(captionChanged( bool)), this, SLOT(slotSetCaption(bool)) \
);  connect( newView, SIGNAL(messageSuccess( ChatView* )), this, \
SLOT(slotStopAnimation( ChatView* )) );  connect( newView, SIGNAL(updateStatusIcon( \
                const ChatView* )), this, SLOT(slotUpdateCaptionIcons( const \
                ChatView* )) );
-
+	connect( newView, SIGNAL(rtfEnabled( ChatView*, bool ) ), this, SLOT( \
slotRTFEnabled( ChatView*, bool ) ) ); +	updateSpellCheckAction();
 	checkDetachEnable();
 }
 
@@ -840,7 +870,7 @@ void KopeteChatWindow::setActiveView( QW
 	setCaption( m_activeView->caption() );
 	setStatus( m_activeView->statusText() );
 	m_activeView->setFocus();
-
+	updateSpellCheckAction();
 	slotUpdateSendEnabled();
 }
 
@@ -1026,6 +1056,18 @@ void KopeteChatWindow::slotSmileyActivat
 	//we are adding space around the emoticon becasue our parser only display emoticons \
not in a word.  }
 
+void KopeteChatWindow::slotRTFEnabled( ChatView* cv, bool enabled)
+{
+	if ( cv != m_activeView )
+		return;
+
+	if ( enabled )
+		toolBar( "formatToolBar" )->show();
+	else
+		toolBar( "formatToolBar" )->hide();
+	updateSpellCheckAction();
+}
+
 bool KopeteChatWindow::queryClose()
 {
 	bool canClose = true;
Index: chatview.h
===================================================================
--- chatview.h	(revision 424713)
+++ chatview.h	(working copy)
@@ -289,6 +289,11 @@ signals:
 	 */
 	void windowCreated();
 
+	/**
+	 * Emitted when the state of RTF has changed
+	 */
+	void rtfEnabled( ChatView*, bool );
+
 private slots:
 	void slotRemoteTypingTimeout();
 	void slotPropertyChanged( Kopete::Contact *contact, const QString &key, const \
                QVariant &oldValue, const QVariant &newValue  );
Index: chattexteditpart.cpp
===================================================================
--- chattexteditpart.cpp	(revision 424493)
+++ chattexteditpart.cpp	(working copy)
@@ -25,6 +25,7 @@
 #include <kcompletion.h>
 #include <kdebug.h>
 #include <ktextedit.h>
+#include <ksyntaxhighlighter.h>
 
 #include <qtimer.h>
 #include <qregexp.h>
@@ -32,6 +33,7 @@
 ChatTextEditPart::ChatTextEditPart( Kopete::ChatSession *session, QWidget *parent, \
const char *name )  : KopeteRichTextEditPart( parent, name, \
session->protocol()->capabilities() ), m_session(session)  {
+	m_autoSpellCheckEnabled = true;
 	historyPos = -1;
 	
 	mComplete = new KCompletion();
@@ -76,6 +78,32 @@ KTextEdit *ChatTextEditPart::edit()
 	return static_cast<KTextEdit*>(widget());
 }
 
+void ChatTextEditPart::toggleAutoSpellCheck( bool enabled )
+{
+	if ( richTextEnabled() )
+		enabled = false;
+
+	m_autoSpellCheckEnabled = enabled;
+	if ( spellHighlighter() )
+	{
+		spellHighlighter()->setAutomatic( enabled );
+		spellHighlighter()->setActive( enabled );
+	}
+	edit()->setCheckSpellingEnabled( enabled );
+}
+
+bool ChatTextEditPart::autoSpellCheckEnabled() const
+{
+	return m_autoSpellCheckEnabled;
+}
+
+KDictSpellingHighlighter* ChatTextEditPart::spellHighlighter()
+{
+	QSyntaxHighlighter *qsh = edit()->syntaxHighlighter();
+	KDictSpellingHighlighter* kdsh = dynamic_cast<KDictSpellingHighlighter*>( qsh );
+	return kdsh;
+}
+
 // NAUGHTY, BAD AND WRONG! (but needed to fix nick complete bugs)
 #include <private/qrichtext_p.h>
 class EvilTextEdit : public KTextEdit
Index: kopetechatwindow.h
===================================================================
--- kopetechatwindow.h	(revision 424493)
+++ kopetechatwindow.h	(working copy)
@@ -152,6 +152,7 @@ private:
 	KToggleAction* membersLeft;
 	KToggleAction* membersRight;
 	KToggleAction* toggleMembers;
+	KToggleAction* toggleAutoSpellCheck;
 
 	KopeteEmoticonAction *actionSmileyMenu;
 	KActionMenu *actionActionMenu;
@@ -208,6 +209,9 @@ private slots:
 	void slotToggleViewMembers();
 	void slotEnableUpdateBg() { updateBg = true; }
 
+	void toggleAutoSpellChecking();
+	void slotRTFEnabled( ChatView*, bool );
+
 	void slotSetCaption( bool );
 	void slotUpdateCaptionIcons( const ChatView * );
 	void slotChatClosed();
@@ -216,6 +220,9 @@ private slots:
 	void slotNickComplete();
 	void slotCloseChat( QWidget* );
 
+private:
+	void updateSpellCheckAction();
+
 protected:
 	virtual void closeEvent( QCloseEvent *e );
 	virtual void windowActivationChange( bool );
Index: chattexteditpart.h
===================================================================
--- chattexteditpart.h	(revision 424493)
+++ chattexteditpart.h	(working copy)
@@ -25,6 +25,7 @@
 class QTimer;
 
 class KCompletion;
+class KDictSpellingHighlighter;
 
 namespace Kopete
 {
@@ -82,6 +83,18 @@ public:
 	 * @return This part's main widget
 	 */
 	KTextEdit *edit();
+
+	/** 
+	 * Enable or Disable the automatic spell checking
+	 * @param enabled the state that auto spell checking should beee
+	 */
+	void toggleAutoSpellCheck( bool enabled );
+
+	/**
+	 * Get the state of auto spell checking
+	 * @return true if auto spell checking is turned on, false otherwise
+	 */
+	bool autoSpellCheckEnabled() const;
 	
 public slots:
 	/**
@@ -165,6 +178,9 @@ private slots:
 	 * Update completion to follow changes in users' nicknames
 	 */
 	void slotPropertyChanged( Kopete::Contact *, const QString &key, const QVariant \
&oldValue, const QVariant &newValue  ); +
+private:
+	KDictSpellingHighlighter* spellHighlighter();
 	
 private:
 	Kopete::ChatSession *m_session;
@@ -185,6 +201,7 @@ private:
 	
 	QTimer *m_typingRepeatTimer;
 	QTimer *m_typingStopTimer;
+	bool m_autoSpellCheckEnabled;
 };
 
 #endif


[Attachment #8 (application/pgp-signature)]

_______________________________________________
kopete-devel mailing list
kopete-devel@kde.org
https://mail.kde.org/mailman/listinfo/kopete-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic