1
/****************************************************************************
2
** msgmle.cpp - subclass of QTextEdit to handle various hotkeys
3
** Copyright (C) 2001, 2002 Justin Karneges
5
** This program is free software; you can redistribute it and/or
6
** modify it under the terms of the GNU General Public License
7
** as published by the Free Software Foundation; either version 2
8
** of the License, or (at your option) any later version.
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
** GNU General Public License for more details.
15
** You should have received a copy of the GNU General Public License
16
** along with this program; if not, write to the Free Software
17
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
19
****************************************************************************/
24
#include<qpopupmenu.h>
25
#include<qapplication.h>
26
#include<qclipboard.h>
29
MsgMle::MsgMle(QWidget *parent, const char *name)
30
:QTextEdit(parent, name)
32
setWordWrap(QTextEdit::WidgetWidth);
35
bool MsgMle::focusNextPrevChild(bool next)
37
return QWidget::focusNextPrevChild(next);
40
void MsgMle::keyPressEvent(QKeyEvent *e)
42
if(e->key() == Key_Escape)
44
else if(e->key() == Key_Return && ((e->state() & ControlButton) || (e->state() & AltButton)) )
46
else if(e->key() == Key_H && (e->state() & ControlButton))
49
QTextEdit::keyPressEvent(e);
52
QPopupMenu *MsgMle::createPopupMenu(const QPoint& pos)
54
lastLink = anchorAt(pos);
55
if(lastLink.isEmpty())
56
return QTextEdit::createPopupMenu(pos);
58
QString txt = lastLink.left(7) == "mailto:" ? tr("Open mail composer") : tr("Open web browser");
60
QPopupMenu *m = new QPopupMenu(this);
61
m->insertItem(QIconSet(*pix_url), txt, this, SLOT(menuURL()));
62
m->insertItem(tr("Copy location"), this, SLOT(menuCopy()));
67
void MsgMle::emitLinkClicked(const QString &s)
72
void MsgMle::menuURL()
74
linkClicked(lastLink);
77
void MsgMle::menuCopy()
79
QString str = lastLink;
81
if(str.left(7) == "mailto:")
84
QApplication::clipboard()->setText(str);
88
ChatMle::ChatMle(QWidget *parent, const char *name)
89
:QTextEdit(parent, name)
91
setWordWrap(QTextEdit::WidgetWidth);
94
bool ChatMle::focusNextPrevChild(bool next)
96
return QWidget::focusNextPrevChild(next);
99
void ChatMle::keyPressEvent(QKeyEvent *e)
101
if(e->key() == Key_Escape)
103
else if(e->key() == Key_Return && ((e->state() & ControlButton) || (e->state() & AltButton)) )
105
else if(e->key() == Key_M && (e->state() & ControlButton))
107
else if(e->key() == Key_H && (e->state() & ControlButton))
109
else if(e->key() == Key_S && (e->state() & AltButton))
111
else if((e->key() == Key_Return) && !(e->state() & ShiftButton) /*&& !option.chatSoftReturn */)
113
else if((e->key() == Key_PageUp || e->key() == Key_PageDown) && (e->state() & ShiftButton))
116
QTextEdit::keyPressEvent(e);