/***************************************************************************
                          dcqtextedit.cpp  -  description
                             -------------------
    begin                : Don Aug 21 2003
    copyright            : (C) 2003 by Mathias Küster
    email                : mathen@users.berlios.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "dcqtextedit.h"

/** */
DCQTextEdit::DCQTextEdit( QWidget * parent ) : QTextEdit( parent )
{
}

/** */
DCQTextEdit::~DCQTextEdit()
{
}

/** */
void DCQTextEdit::mouseReleaseEvent( QMouseEvent * event )
{
	QTextEdit::mouseReleaseEvent( event );

	_mbnick = "";
	
	if ( event->button() == Qt::LeftButton )
	{
		emit clicked();
	}
        else if ( event->button() == Qt::MidButton )
	{
		QPoint p = mapFromGlobal(QCursor::pos());
		QString pressedPara;
		int nickStart, nickLen;

		QTextCursor cursor = cursorForPosition(p);

		pressedPara = cursor.block().text();

		nickStart = 1 + pressedPara.indexOf("<");
		nickLen = pressedPara.indexOf(">") - nickStart;
	
		if ((nickStart == 0) || (nickLen < 0))
	  		return;
	
		_mbnick = pressedPara.mid(nickStart, nickLen);

		emit clicked();
	}
}

/** */
void DCQTextEdit::mouseDoubleClickEvent( QMouseEvent * event )
{
	QTextEdit::mouseDoubleClickEvent( event );
	
	if ( event->button() == Qt::LeftButton )
	{
		emit doubleClicked();
	}
}

QString DCQTextEdit::getMBNick()
{
    	return _mbnick;
}

