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
****************************************************************************/
2
* msgmle.cpp - subclass of PsiTextView to handle various hotkeys
3
* Copyright (C) 2001-2003 Justin Karneges, Michail Pishchagin
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 library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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)
24
//----------------------------------------------------------------------------
26
//----------------------------------------------------------------------------
27
ChatView::ChatView(QWidget *parent, const char *name)
28
: PsiTextView(parent, name)
30
setWordWrap(WidgetWidth);
31
setWrapPolicy(AtWordOrDocumentBoundary);
33
setTextFormat(RichText);
35
setUndoRedoEnabled(false);
36
setHScrollBarMode(QScrollView::AlwaysOff);
43
bool ChatView::focusNextPrevChild(bool next)
37
45
return QWidget::focusNextPrevChild(next);
40
void MsgMle::keyPressEvent(QKeyEvent *e)
48
void ChatView::keyPressEvent(QKeyEvent *e)
42
50
if(e->key() == Key_Escape)
53
else if(e->key() == Key_W && e->state() & ControlButton)
44
56
else if(e->key() == Key_Return && ((e->state() & ControlButton) || (e->state() & AltButton)) )
46
58
else if(e->key() == Key_H && (e->state() & ControlButton))
60
else if(e->key() == Key_M && (e->state() & ControlButton)) // newline
62
else if(e->key() == Key_U && (e->state() & ControlButton))
49
65
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)
68
void ChatView::resizeEvent(QResizeEvent *e)
70
// This fixes flyspray #45
71
if(contentsY() == contentsHeight() - visibleHeight())
74
QTextEdit::resizeEvent(e);
77
//----------------------------------------------------------------------------
79
//----------------------------------------------------------------------------
80
ChatEdit::ChatEdit(QWidget *parent, const char *name)
81
: PsiTextView(parent, name)
91
83
setWordWrap(QTextEdit::WidgetWidth);
94
bool ChatMle::focusNextPrevChild(bool next)
86
setUndoRedoEnabled(true);
88
setTextFormat(PlainText);
96
bool ChatEdit::focusNextPrevChild(bool next)
96
98
return QWidget::focusNextPrevChild(next);
99
void ChatMle::keyPressEvent(QKeyEvent *e)
101
void ChatEdit::keyPressEvent(QKeyEvent *e)
101
if(e->key() == Key_Escape)
103
if(e->key() == Key_Escape || (e->key() == Key_W && e->state() & ControlButton))
103
105
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_M && (e->state() & ControlButton)) // newline
107
else if(e->key() == Key_H && (e->state() & ControlButton))
109
else if(e->key() == Key_H && (e->state() & ControlButton)) // history
109
111
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_U && (e->state() & ControlButton))
115
else if((e->key() == Key_Return || e->key() == Key_Enter) && !(e->state() & ShiftButton) && option.chatSoftReturn)
113
117
else if((e->key() == Key_PageUp || e->key() == Key_PageDown) && (e->state() & ShiftButton))
119
else if(e->key() == Key_U && (e->state() & ControlButton))
116
122
QTextEdit::keyPressEvent(e);