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

List:       kopete-devel
Subject:    [kopete-devel] changeGlobalStatusMessage and changeGlobalNickname
From:       adrian <iamcalvo () gmail ! com>
Date:       2007-04-24 1:03:42
Message-ID: 200704240303.43386.iamcalvo () gmail ! com
[Download RAW message or body]

Hi kopete developers!

I'm Adrián Medraño Calvo. This is my first contribution to the KDE Project 
I'm leaving here for review, so critics are almost required :).

What does this patch do?
- Creates Kopete::UI::KSaveLineEdit class, a QLineEdit with the ability to 
save it's contents with a mouse click and show changes-saved or 
changes-not-saved state.
- Creates Kopete::KLineEditAction, an action that requires inline text input 
(not a dialog).
- Makes editGlobalIdentityToolbar and setStatusMessage use KLineEditAction.
- Removes some krazy complains (kopetewindow.cpp duplicated includes, 
contactlist->contactList).
- Fixes some broken funcionality:
	- selecting "No message" in globalStatusMessageMenu didn't work because
		Kopete::Away::setGlobalAwayMessage didn't allow empty qstrings (this is the
		change I'm less confident about).
	- selecting any previous globalStatusMessage didn't work because all had same 
		index assigned: 0, as "No message".

Questions:

keditlineaction: 
- I measured by eye(?¿!) Qlabel margins for imitating menu items and hardcoded 
them(wahwhawha!), is there any global value that could be used instead?
- is the clear-focus-when-saved behaviour ok?

kopetewindow.cpp&kopeteeditglobalidentitfywidget.cpp:
- Are the icon("edit") and text("Edit") wanted and accurate for 
actionChangeGlobalNickname?
- Are the icon("document-new") and the text("New") wanted and accurate for 
actionChangeGlobalStatusMessage?

Sure i forget lots of questions :).
Bye!

["lineedit.patch" (text/x-diff)]

Index: kopete/kopete/kopetewindow.h
===================================================================
--- kopete/kopete/kopetewindow.h	(revision 656768)
+++ kopete/kopete/kopetewindow.h	(working copy)
@@ -155,7 +155,7 @@
 	 */
 	void slotBuildStatusMessageMenu();
 	void slotStatusMessageSelected( int i );
-	void slotNewStatusMessageEntered();
+	void slotNewStatusMessageEntered( const QString &newMessage );
 
 	/**
 	 * Show the set global status message menu when clicking on the icon in the status \
                bar.
Index: kopete/kopete/kopeteeditglobalidentitywidget.h
===================================================================
--- kopete/kopete/kopeteeditglobalidentitywidget.h	(revision 656768)
+++ kopete/kopete/kopeteeditglobalidentitywidget.h	(working copy)
@@ -70,13 +70,9 @@
 	 */
 	void photoClicked();
 	/**
-	 * The nickname was changed, display the text in red to display the change.
-	 */
-	void lineNicknameTextChanged(const QString &text);
-	/**
 	 * User press Return/Enter in the KLineEdit, commit the new nickname.
 	 */
-	void changeNickname();
+	void changeNickname(const QString &newGlobalNickname);
 
 	/**
 	 * @internal
Index: kopete/kopete/kopetewindow.cpp
===================================================================
--- kopete/kopete/kopetewindow.cpp	(revision 656768)
+++ kopete/kopete/kopetewindow.cpp	(working copy)
@@ -51,7 +51,6 @@
 #include <kedittoolbar.h>
 #include <kmenubar.h>
 #include <kstatusbar.h>
-#include <kglobalaccel.h>
 #include <kwm.h>
 #include <kdeversion.h>
 #include <kinputdialog.h>
@@ -68,6 +67,7 @@
 #include "addressbooklinkwidget.h"
 #include "ui_groupkabcselectorwidget.h"
 #include "kabcexport.h"
+#include "klineeditaction.h"
 #include "kopeteappearancesettings.h"
 #include "kopeteapplication.h"
 #include "kopeteaccount.h"
@@ -110,19 +110,19 @@
 {
 public:
 	Private()
-	 : contactlist(0), actionAddContact(0), actionDisconnect(0), \
actionExportContacts(0), +	 : contactList(0), actionAddContact(0), \
actionDisconnect(0), actionExportContacts(0),  actionAwayMenu(0), actionDockMenu(0), \
selectAway(0), selectBusy(0), actionSetAvailable(0),  actionSetInvisible(0), \
actionPrefs(0), actionQuit(0), actionSave(0), menubarAction(0),  statusbarAction(0), \
actionShowOffliners(0), actionShowEmptyGroups(0), editGlobalIdentityWidget(0),  \
                docked(0), hidden(false), deskRight(0), statusBarWidget(0), tray(0), \
                autoHide(false),
-	autoHideTimeout(0), autoHideTimer(0), addContactMapper(0),
-	globalStatusMessage(0), globalStatusMessageMenu(0), newMessageEdit(0)
+	autoHideTimeout(0), autoHideTimer(0), addContactMapper(0), globalStatusMessage(0),
+	globalStatusMessageMenu(0), actionChangeGlobalStatusMessage(0)
 	{}
 
 	~Private()
 	{}
 
-	KopeteContactListView *contactlist;
+	KopeteContactListView *contactList;
 
 	// Some Actions
 	KActionMenu *actionAddContact;
@@ -162,7 +162,7 @@
 	QHash<const Kopete::Account*, KopeteAccountStatusBarIcon*> accountStatusBarIcons;
 	KSqueezedTextLabel *globalStatusMessage;
 	KMenu *globalStatusMessageMenu;
-	QLineEdit *newMessageEdit;
+	Kopete::KLineEditAction *actionChangeGlobalStatusMessage;
 	QString globalStatusMessageStored;
 };
 
@@ -180,7 +180,7 @@
  * 1) user quit - KopeteWindow::slotQuit() was called, calls \
                KopeteApplication::quitKopete(),
  *                which closes all chatwindows and the KopeteWindow.  The last \
                window to close
  *                shuts down the PluginManager in queryExit().  When the \
                PluginManager has completed its
- *                shutdown, the app is finally deref()ed, and the contactlist and \
accountmanager + *                shutdown, the app is finally deref()ed, and the \
                contactList and accountmanager
  *                are saved.
  *                and calling KApplication::quit()
  * 2) session   - KopeteWindow and all chatwindows are closed by KApplication \
session management. @@ -223,7 +223,7 @@
 	// --------------------------------------------------------------------------------
 	initView();
 	initActions();
-	d->contactlist->initActions(actionCollection());
+	d->contactList->initActions(actionCollection());
 	initSystray();
 	// --------------------------------------------------------------------------------
 
@@ -266,8 +266,8 @@
 
 void KopeteWindow::initView()
 {
-	d->contactlist = new KopeteContactListView(this);
-	setCentralWidget(d->contactlist);
+	d->contactList = new KopeteContactListView(this);
+	setCentralWidget(d->contactList);
 }
 
 void KopeteWindow::initActions()
@@ -354,7 +354,7 @@
 	// quick search bar
 	QLabel *searchLabel = new QLabel( i18n("Se&arch:"), 0 );
 	searchLabel->setObjectName( QLatin1String("kde toolbar widget") );
-	QWidget *searchBar = new Kopete::UI::ListView::SearchLine( 0, d->contactlist );
+	QWidget *searchBar = new Kopete::UI::ListView::SearchLine( 0, d->contactList );
 	searchLabel->setBuddy( searchBar );
 	KAction *quickSearch = new KAction( i18n("Quick Search Bar"), this );
         actionCollection()->addAction( "quicksearch_bar", quickSearch );
@@ -376,6 +376,9 @@
 	setStatusMenu->setDelayed( false );
 	connect( setStatusMenu->menu(), SIGNAL( aboutToShow() ), \
SLOT(slotBuildStatusMessageMenu() ) );  
+	d->actionChangeGlobalStatusMessage = new Kopete::KLineEditAction( \
KIcon("document-new"), i18n("New"), this ); +	connect( \
d->actionChangeGlobalStatusMessage, SIGNAL( triggered(QString) ), SLOT( \
slotNewStatusMessageEntered(QString) ) ); +
 	// sync actions, config and prefs-dialog
 	connect ( Kopete::AppearanceSettings::self(), SIGNAL(configChanged()), this, \
SLOT(slotConfigChanged()) );  slotConfigChanged();
@@ -988,43 +991,32 @@
 	//Find out which menu asked us to be built
 	QObject * senderObj = const_cast<QObject *>( sender() );
 	d->globalStatusMessageMenu = static_cast<KMenu *>( senderObj );
+
+	disconnect( d->globalStatusMessageMenu, SIGNAL( activated( int ) ), this,
+		SLOT( slotStatusMessageSelected( int ) ) );
+
 	d->globalStatusMessageMenu->clear();
 
 	connect( d->globalStatusMessageMenu, SIGNAL( activated( int ) ),
 		SLOT( slotStatusMessageSelected( int ) ) );
 
 	d->globalStatusMessageMenu->addTitle( i18n("Status Message") );
-	//BEGIN: Add new message widget to the Set Status Message Menu.
-	KHBox * newMessageBox = new KHBox( 0 );
-	newMessageBox->setMargin( 1 );
-	QLabel * newMessagePix = new QLabel( newMessageBox );
-	newMessagePix->setPixmap( SmallIcon( "edit" ) );
-	QLabel * newMessageLabel = new QLabel( i18n( "Add " ), newMessageBox );
-	d->newMessageEdit = new QLineEdit( newMessageBox );
-	newMessageBox->setFocusProxy( d->newMessageEdit );
-	newMessageBox->setFocusPolicy( Qt::ClickFocus );
-	newMessageLabel->setFocusProxy( d->newMessageEdit );
-	newMessageLabel->setBuddy( d->newMessageEdit );
-	newMessageLabel->setFocusPolicy( Qt::ClickFocus );
-	newMessagePix->setFocusProxy( d->newMessageEdit );
-	newMessagePix->setFocusPolicy( Qt::ClickFocus );
-	connect( d->newMessageEdit, SIGNAL( returnPressed() ), SLOT( \
slotNewStatusMessageEntered() ) );  
-	KAction *newMessageAction = new KAction( KIcon("edit"), i18n("New Message..."), \
                this ); //, "new_message" );
-	newMessageAction->setDefaultWidget( newMessageBox );
+	d->globalStatusMessageMenu->addAction( d->actionChangeGlobalStatusMessage );
 
-	d->globalStatusMessageMenu->addAction( newMessageAction );
-	//END
-
 	// NOTE: The following code still use insertItem because it require the behavior of \
those (-DarkShock)  int i = 0;
-	d->globalStatusMessageMenu->insertItem( SmallIcon( "list-remove" ), i18n( "No \
Message" ), i++ ); +	d->globalStatusMessageMenu->insertItem( KIcon( "list-remove" ), \
i18n( "No Message" ), i++ );  d->globalStatusMessageMenu->addSeparator();
 
 	QStringList awayMessages = Kopete::Away::getInstance()->getMessages();
+
+	// put the current global status message in the lineedit
+	d->actionChangeGlobalStatusMessage->setSavedText( \
Kopete::Away::getInstance()->message() ); +
 	foreach(QString message, awayMessages)
 	{
-		d->globalStatusMessageMenu->insertItem( KStringHandler::rsqueeze( message ), i );
+		d->globalStatusMessageMenu->insertItem( KStringHandler::rsqueeze( message ), i++ \
);  }
 	//connect( m_globalStatusMessageMenu, SIGNAL( aboutToHide() ), \
m_globalStatusMessageMenu, SLOT( deleteLater() ) );  
@@ -1041,13 +1033,12 @@
 		setStatusMessage(  Kopete::Away::getInstance()->getMessage( i - 1 ) );
 }
 
-void KopeteWindow::slotNewStatusMessageEntered()
+void KopeteWindow::slotNewStatusMessageEntered( const QString &newMessage )
 {
 	d->globalStatusMessageMenu->close();
-	QString newMessage = d->newMessageEdit->text();
 	if ( !newMessage.isEmpty() )
 		Kopete::Away::getInstance()->addMessage( newMessage );
-	setStatusMessage( d->newMessageEdit->text() );
+	setStatusMessage( newMessage );
 }
 
 void KopeteWindow::slotGlobalStatusMessageIconClicked( const QPoint &position )
Index: kopete/kopete/kopeteeditglobalidentitywidget.cpp
===================================================================
--- kopete/kopete/kopeteeditglobalidentitywidget.cpp	(revision 656768)
+++ kopete/kopete/kopeteeditglobalidentitywidget.cpp	(working copy)
@@ -39,6 +39,7 @@
 #include "kopetemetacontact.h"
 #include "kopetepicture.h"
 #include "avatarselectordialog.h"
+#include "klineeditaction.h"
 
 
 ClickableLabel::ClickableLabel(QWidget *parent)
@@ -60,16 +61,15 @@
 {
 public:
 	Private()
-	 : labelPicture(0L), lineNickname(0L), lineStatusMessage(0L), mainLayout(0L), \
iconSize(22, 22) +	 : labelPicture(0L), actionChangeGlobalNickname(0L), \
lineStatusMessage(0L), mainLayout(0L), iconSize(22, 22)  {}
 		
 	QPointer<Kopete::MetaContact> myself;
 	ClickableLabel *labelPicture;
-	KLineEdit *lineNickname;
+	Kopete::KLineEditAction *actionChangeGlobalNickname;
 	KLineEdit *lineStatusMessage;
 	QHBoxLayout *mainLayout;
 	QSize iconSize;
-	QString lastNickname;
 };
 
 KopeteEditGlobalIdentityWidget::KopeteEditGlobalIdentityWidget(QWidget *parent) 
@@ -105,7 +105,8 @@
 void KopeteEditGlobalIdentityWidget::createGUI()
 {
 	d->mainLayout = new QHBoxLayout(this);
-	
+	d->mainLayout->setContentsMargins(0,0,0,0);
+
 	// The picture label
 	d->labelPicture = new ClickableLabel(this);
 	d->labelPicture->setMinimumSize(d->iconSize);
@@ -115,12 +116,10 @@
 	connect(d->labelPicture, SIGNAL(clicked()), this, SLOT(photoClicked()));
 	
 	// The nickname lineEdit
-	d->lineNickname = new KLineEdit(this);
-	d->mainLayout->addWidget(d->lineNickname);
+	d->actionChangeGlobalNickname = new Kopete::KLineEditAction(KIcon("edit"), \
i18n("Edit"), this); \
+	d->mainLayout->addWidget(d->actionChangeGlobalNickname->createWidget(this));  // \
                Update the nickname when the user press return.
-	connect(d->lineNickname, SIGNAL(returnPressed()), this, SLOT(changeNickname()));
-	// Show the nickname text in red when they are change.
-	connect(d->lineNickname, SIGNAL(textChanged(const QString&)), this, \
SLOT(lineNicknameTextChanged(const QString& ))); \
+	connect(d->actionChangeGlobalNickname, SIGNAL(triggered(QString)), this, \
SLOT(changeNickname(QString)));  }
 
 void KopeteEditGlobalIdentityWidget::updateGUI(const QString &key, const QVariant \
&value) @@ -146,8 +145,7 @@
 	else if(key == Kopete::Global::Properties::self()->nickName().key())
 	{
 		// Update the nickname
-		d->lastNickname = value.toString();
-		d->lineNickname->setText(value.toString());
+		d->actionChangeGlobalNickname->setSavedText(value.toString());
 	}
 }
 
@@ -166,34 +164,14 @@
 	d->myself->setPhoto( KUrl(dialog->selectedAvatarPath()) );
 }
 
-void KopeteEditGlobalIdentityWidget::lineNicknameTextChanged(const QString &text)
+void KopeteEditGlobalIdentityWidget::changeNickname(const QString& \
newGlobalNickname)  {
-	// Display the nickname in red if they are any change. 
-	if(text != d->lastNickname)
+	if(!newGlobalNickname.isEmpty() && newGlobalNickname != d->myself->displayName())
 	{
-		QPalette palette;
-    	palette.setColor(d->lineNickname->foregroundRole(), Qt::red);
-		d->lineNickname->setPalette(palette);
-	}
-	// The nickname re-become like it was before, reset the palette.
-	else
-	{
-		d->lineNickname->setPalette(QPalette());
-	}
-}
+		kDebug(14000) << k_funcinfo << "Updating global nickname with " << \
newGlobalNickname << endl;  
-void KopeteEditGlobalIdentityWidget::changeNickname()
-{
-	if( !d->lineNickname->text().isEmpty() && d->lineNickname->text() != \
                d->myself->displayName() )
-	{
-		kDebug(14000) << k_funcinfo << "Updating global nickname..." << endl;
-
-		// Reset the text color since the nickname is now updated.
-		d->lineNickname->setPalette(QPalette());
-
 		// Set the new nickname and set the DisplayName source Custom.
-		d->lastNickname = d->lineNickname->text();
-		d->myself->setDisplayName(d->lineNickname->text());
+		d->myself->setDisplayName(newGlobalNickname);
 		d->myself->setDisplayNameSource(Kopete::MetaContact::SourceCustom);
 	}
 }
Index: kopete/libkopete/kopeteaway.cpp
===================================================================
--- kopete/libkopete/kopeteaway.cpp	(revision 656768)
+++ kopete/libkopete/kopeteaway.cpp	(working copy)
@@ -199,12 +199,9 @@
 
 void Kopete::Away::setGlobalAwayMessage(const QString &message)
 {
-	if( !message.isEmpty() )
-	{
-		kDebug(14010) << k_funcinfo <<
-			"Setting global away message: " << message << endl;
-		d->awayMessage = message;
-	}
+	kDebug(14010) << k_funcinfo <<
+		"Setting global away message: " << message << endl;
+	d->awayMessage = message;
 }
 
 void Kopete::Away::setAutoAwayMessage(const QString &message)
Index: kopete/libkopete/klineeditaction.cpp
===================================================================
--- kopete/libkopete/klineeditaction.cpp	(revision 0)
+++ kopete/libkopete/klineeditaction.cpp	(revision 0)
@@ -0,0 +1,120 @@
+/*
+    klineeditaction.cpp - Text input involving action
+
+    Copyright (c) 2007     by Adrián Medraño Calvo        <kdedev@gmail.com>
+    Kopete    (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
+
+    *************************************************************************
+    *                                                                       *
+    * This library is free software; you can redistribute it and/or         *
+    * modify it under the terms of the GNU Lesser General Public            *
+    * License as published by the Free Software Foundation; either          *
+    * version 2 of the License, or (at your option) any later version.      *
+    *                                                                       *
+    *************************************************************************
+*/
+
+#include "klineeditaction.h"
+
+#include "ksavelineedit.h"
+#include <khbox.h>
+
+#include <QtGui/QLabel>
+
+#include "klineeditaction.moc"
+
+namespace Kopete
+{
+
+//BEGIN KLineEditAction::Private
+class KLineEditAction::Private
+{
+public:
+	Private();
+	QLabel *iconLabel;
+	QLabel *messageLabel;
+	Kopete::UI::KSaveLineEdit *messageEdit;
+};
+
+KLineEditAction::Private::Private()
+: iconLabel(0)
+, messageLabel(0)
+, messageEdit(0)
+{}
+//END KLineEditAction::Private
+
+KLineEditAction::KLineEditAction(QObject* parent)
+: KAction(parent)
+, d(new Private)
+{}
+
+KLineEditAction::KLineEditAction(const QString& text, QObject *parent)
+: KAction(text, parent)
+, d(new Private)
+{}
+
+KLineEditAction::KLineEditAction(const KIcon& icon, const QString& text, QObject \
*parent) +: KAction(icon, text, parent)
+, d(new Private)
+{}
+
+KLineEditAction::~KLineEditAction()
+{
+	delete d;
+}
+
+QWidget* KLineEditAction::createWidget(QWidget* _parent)
+{
+	KHBox* widget = new KHBox(_parent);
+
+	if(!icon().isNull()){
+		d->iconLabel = new QLabel(widget);
+		d->iconLabel->setFocusProxy(widget);
+		d->iconLabel->setFocusPolicy(Qt::ClickFocus);
+		d->iconLabel->setPixmap(icon().pixmap(QSize(16,16)));
+		//FIXME: warning! eye-measured hardcoded values ahead.
+		// If we are in a menu we imitate menuitem style
+		if(_parent->inherits("QMenu")){
+			d->iconLabel->setContentsMargins(0,0,8,0);
+		} else {
+			d->iconLabel->setContentsMargins(0,0,4,0);
+		};
+	};
+
+	if(!text().isNull()){
+		d->messageLabel = new QLabel(text(), widget);
+		//FIXME: warning! eye-measured hardcoded values ahead.
+		d->messageLabel->setContentsMargins(0,0,4,0);
+		d->messageLabel->setFocusProxy(widget);
+		d->messageLabel->setBuddy(d->messageEdit);
+		d->messageLabel->setFocusPolicy(Qt::ClickFocus);
+	};
+
+	d->messageEdit = new Kopete::UI::KSaveLineEdit(widget);
+	
+	widget->setMargin(1);
+	widget->setFocusProxy(d->messageEdit);
+	widget->setFocusPolicy(Qt::ClickFocus);
+	
+	connect(d->messageEdit, SIGNAL(textSaved(QString)), this, SLOT(textSaved()));
+	connect(d->messageEdit, SIGNAL(textSaved(QString)), this, \
SIGNAL(triggered(QString))); +
+	return widget;
+}
+
+QString KLineEditAction::savedText() const
+{
+	return d->messageEdit->savedText();
+}
+
+void KLineEditAction::setSavedText(const QString& newText)
+{
+	d->messageEdit->setSavedText(newText);
+}
+
+void KLineEditAction::textSaved()
+{
+	d->messageEdit->clearFocus();
+}
+
+}
Index: kopete/libkopete/klineeditaction.h
===================================================================
--- kopete/libkopete/klineeditaction.h	(revision 0)
+++ kopete/libkopete/klineeditaction.h	(revision 0)
@@ -0,0 +1,58 @@
+/*
+    klineeditaction.h - Text input involving action
+
+    Copyright (c) 2007     by Adrián Medraño Calvo        <kdedev@gmail.com>
+    Kopete    (c) 2002-2007 by the Kopete developers <kopete-devel@kde.org>
+
+    *************************************************************************
+    *                                                                       *
+    * This library is free software; you can redistribute it and/or         *
+    * modify it under the terms of the GNU Lesser General Public            *
+    * License as published by the Free Software Foundation; either          *
+    * version 2 of the License, or (at your option) any later version.      *
+    *                                                                       *
+    *************************************************************************
+*/
+
+#ifndef KLINEEDITACTION_H
+#define KLINEEDITACTION_H
+#include <kaction.h>
+#include <kopete_export.h>
+
+class KHBox;
+class QLabel;
+
+namespace Kopete
+{
+namespace UI
+{
+class KSaveLineEdit;
+} // end namespace UI
+
+class KOPETE_EXPORT KLineEditAction : public KAction
+{
+	Q_OBJECT
+	Q_PROPERTY (QString savedText READ savedText WRITE setSavedText STORED false)
+public:
+	KLineEditAction(QObject* parent);
+	KLineEditAction(const QString& text, QObject *parent);
+	KLineEditAction(const KIcon& icon, const QString& text, QObject *parent);
+	virtual ~KLineEditAction();
+
+	QString savedText() const;
+	void setSavedText(const QString&);
+
+	virtual QWidget* createWidget(QWidget* parent);
+private Q_SLOTS:
+	void textSaved();
+Q_SIGNALS:
+	void triggered(QString);
+
+private:
+	class Private;
+	Private *const d;
+};
+
+} // end namespace Kopete
+
+#endif // KLINEEDITACTION_H
Index: kopete/libkopete/CMakeLists.txt
===================================================================
--- kopete/libkopete/CMakeLists.txt	(revision 656768)
+++ kopete/libkopete/CMakeLists.txt	(working copy)
@@ -39,6 +39,7 @@
   ui/kopetestdaction.cpp
   ui/kopeteview.cpp
   ui/kopeteviewplugin.cpp
+  ui/ksavelineedit.cpp
   ui/metacontactselectorwidget.cpp
   ui/webcamwidget.cpp
 )
@@ -53,6 +54,7 @@
    ${kopete_ui_SRCS}
    ${kopete_contactlist_SRCS}
    kabcpersistence.cpp
+   klineeditaction.cpp
    kopeteaccount.cpp
    kopeteaccountmanager.cpp
    kopeteavatarmanager.cpp
@@ -148,6 +150,7 @@
  ui/kopetestdaction.h
  ui/kopeteview.h
  ui/kopeteviewplugin.h
+ ui/ksavelineedit.h
 DESTINATION ${INCLUDE_INSTALL_DIR}/kopete/ui )
 
 
@@ -165,6 +168,7 @@
   ${CMAKE_CURRENT_BINARY_DIR}/kopetebehaviorsettings.h
   ${CMAKE_CURRENT_BINARY_DIR}/kopetegeneralsettings.h
   kabcpersistence.h
+  klineeditaction.h
   kopeteaccount.h
   kopeteaccountmanager.h
   kopeteavatarmanager.h
Index: kopete/libkopete/ui/ksavelineedit.h
===================================================================
--- kopete/libkopete/ui/ksavelineedit.h	(revision 0)
+++ kopete/libkopete/ui/ksavelineedit.h	(revision 0)
@@ -0,0 +1,69 @@
+/*
+    ksavelineedit.h - Mouse saveable QLineEdit
+
+    Copyright (c) 2007     by Adrián Medraño Calvo        <kdedev@gmail.com>
+    Kopete    (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
+
+    *************************************************************************
+    *                                                                       *
+    * This library is free software; you can redistribute it and/or         *
+    * modify it under the terms of the GNU Lesser General Public            *
+    * License as published by the Free Software Foundation; either          *
+    * version 2 of the License, or (at your option) any later version.      *
+    *                                                                       *
+    *************************************************************************
+*/
+
+#ifndef KSAVELINEEDIT_H
+#define KSAVELINEEDIT_H
+
+#include <QtGui/QLineEdit>
+
+class QLabel;
+
+namespace Kopete
+{
+namespace UI
+{
+
+/** 
+ *	WARNING: Most code stolen from KLineEdit's clearButton feature.
+ **/
+
+class KSaveLineEdit : public QLineEdit
+{
+	Q_OBJECT
+	Q_PROPERTY(QString savedText READ savedText WRITE setSavedText)
+
+	public:
+		KSaveLineEdit(QWidget *parent);
+
+		void setSaveButtonShown(bool enable);
+		bool isSaveButtonShown();
+
+		QString savedText() const;
+		void setSavedText(const QString&);
+
+	signals:
+		void textSaved(QString);
+
+	private slots:
+		void updateSaveButtonIcon(const QString& text);
+		void updateSaveButton();
+		void slotSaveText();
+
+	protected:
+		void resizeEvent(QResizeEvent* ev);
+		void mouseReleaseEvent(QMouseEvent* e);
+		void mousePressEvent(QMouseEvent* e);
+
+	private:
+		class Private;
+		Private *const d;
+};
+
+} // end namespace UI
+
+} // end namespace Kopete
+
+#endif // KSAVELINEEDIT_H
Index: kopete/libkopete/ui/ksavelineedit.cpp
===================================================================
--- kopete/libkopete/ui/ksavelineedit.cpp	(revision 0)
+++ kopete/libkopete/ui/ksavelineedit.cpp	(revision 0)
@@ -0,0 +1,195 @@
+/*
+    ksavelineedit.cpp - Mouse saveable QLineEdit
+
+    Copyright (c) 2007      by Adrián Medraño Calvo       <kdedev@gmail.com>
+    Kopete    (c) 2002-2004 by the Kopete developers  <kopete-devel@kde.org>
+
+    *************************************************************************
+    *                                                                       *
+    * This library is free software; you can redistribute it and/or         *
+    * modify it under the terms of the GNU Lesser General Public            *
+    * License as published by the Free Software Foundation; either          *
+    * version 2 of the License, or (at your option) any later version.      *
+    *                                                                       *
+    *************************************************************************
+*/
+
+#include "ksavelineedit.h"
+
+#include <kiconloader.h>
+#include <klocale.h>
+
+#include <QtGui/QLabel>
+#include <QtGui/QStyle>
+#include <QtGui/QMouseEvent>
+#include <QtGui/QApplication>
+
+#include "ksavelineedit.moc"
+
+namespace Kopete
+{
+namespace UI
+{
+
+//BEGIN KSaveLineEdit::Private
+class KSaveLineEdit::Private
+{
+public:
+	Private();
+	QLabel *saveButton;
+	int saveButtonState;
+	bool clickInSave;
+	QString savedText;
+};
+
+KSaveLineEdit::Private::Private()
+: saveButton(0)
+, saveButtonState(-1)
+, clickInSave(false)
+, savedText(QString())
+{}
+//END KSaveLineEdit::Private
+
+KSaveLineEdit::KSaveLineEdit(QWidget *parent)
+: QLineEdit(parent)
+, d(new Private)
+{
+	setSavedText(QString());
+	setSaveButtonShown(true);
+	connect(this, SIGNAL(returnPressed()),this,SLOT(slotSaveText()));
+}
+
+void KSaveLineEdit::updateSaveButtonIcon(const QString& text)
+{
+	if (!d->saveButton || isReadOnly()) {
+		return;
+	}
+
+	if (text != savedText()) {
+		if (d->saveButtonState == K3Icon::DefaultState) {
+			return;
+		}
+
+		d->saveButtonState = K3Icon::DefaultState;
+	} else {
+		if (d->saveButtonState == K3Icon::DisabledState) {
+			return;
+		}
+
+		d->saveButtonState = K3Icon::DisabledState;
+	}
+
+	d->saveButton->setPixmap(SmallIcon("document-save", 0, d->saveButtonState));
+}
+
+void KSaveLineEdit::updateSaveButton()
+{
+	if (!d->saveButton || isReadOnly()) {
+		return;
+	}
+
+	QSize geom = size();
+	int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
+	int buttonWidth = d->saveButton->sizeHint().width();
+	QSize newButtonSize(buttonWidth, geom.height());
+
+	if (newButtonSize != d->saveButton->size()) {
+		d->saveButton->resize(newButtonSize);
+		// + 2 means "don't be so ugly when I'm selecting a text bigger than the lineedit"
+		setStyleSheet(QString("QLineEdit { padding-right: %1; }").arg(buttonWidth + 2));
+	}
+
+	if (qApp->isLeftToRight()) {
+		d->saveButton->move(geom.width() - frameWidth - buttonWidth - 1, 0);
+	} else {
+		d->saveButton->move(frameWidth + 1, 0);
+	}
+}
+
+void KSaveLineEdit::setSaveButtonShown(bool show)
+{
+	if (show) {
+		if (d->saveButton) {
+			return;
+		}
+
+		d->saveButton = new QLabel(this);
+		d->saveButton->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
+		d->saveButton->setCursor(Qt::ArrowCursor);
+		d->saveButton->setToolTip(i18n( "Save" ));
+
+		updateSaveButton();
+		updateSaveButtonIcon(text());
+		d->saveButton->show();
+		connect(this, SIGNAL(textEdited(QString)), this, \
SLOT(updateSaveButtonIcon(QString))); +	} else {
+		disconnect(this, SIGNAL(textEdited(QString)), this, \
SLOT(updateSaveButtonIcon(QString))); +		delete d->saveButton;
+		d->saveButton = 0;
+		d->clickInSave = false;
+		setStyleSheet(QString());
+	}
+}
+
+bool KSaveLineEdit::isSaveButtonShown()
+{
+	return d->saveButton != 0;
+}
+
+void KSaveLineEdit::resizeEvent(QResizeEvent * ev)
+{
+	updateSaveButton();
+	QLineEdit::resizeEvent(ev);
+}
+
+void KSaveLineEdit::mousePressEvent(QMouseEvent* e)
+{
+	if  ( (e->button() == Qt::LeftButton ||
+	       e->button() == Qt::MidButton ) &&
+	       d->saveButton ) {
+		d->clickInSave = d->saveButton->underMouse();
+	}
+
+	QLineEdit::mousePressEvent(e);
+}
+
+void KSaveLineEdit::mouseReleaseEvent(QMouseEvent* e)
+{
+	if (d->clickInSave) {
+		if ( d->saveButton->underMouse() ) {
+			emit returnPressed();
+		}
+
+		d->clickInSave = false;
+		e->accept();
+		return;
+	}
+
+	QLineEdit::mouseReleaseEvent(e);
+}
+
+void KSaveLineEdit::slotSaveText()
+{
+	if(displayText() != savedText()){
+		setSavedText(displayText());
+		emit textSaved(savedText());
+	}
+}
+
+void KSaveLineEdit::setSavedText(const QString& newText)
+{
+	if(newText != savedText()){
+		d->savedText = newText;
+		QLineEdit::setText(newText);
+		updateSaveButtonIcon(newText);
+	}
+}
+
+QString KSaveLineEdit::savedText() const
+{
+	return d->savedText;
+}
+
+} // end namespace UI
+
+} // end namespace Kopete



_______________________________________________
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