~ubuntu-branches/ubuntu/edgy/psi/edgy

« back to all changes in this revision

Viewing changes to src/msgmle.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2002-04-19 02:28:44 UTC
  • Revision ID: james.westby@ubuntu.com-20020419022844-za7xgai5qyfd9xv6
Tags: upstream-0.8.5
ImportĀ upstreamĀ versionĀ 0.8.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
** msgmle.cpp - subclass of QTextEdit to handle various hotkeys
 
3
** Copyright (C) 2001, 2002  Justin Karneges
 
4
**
 
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.
 
9
**
 
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.
 
14
**
 
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.
 
18
**
 
19
****************************************************************************/
 
20
 
 
21
#include"msgmle.h"
 
22
#include"common.h"
 
23
#include<qiconset.h>
 
24
#include<qpopupmenu.h>
 
25
#include<qapplication.h>
 
26
#include<qclipboard.h>
 
27
 
 
28
 
 
29
MsgMle::MsgMle(QWidget *parent, const char *name)
 
30
:QTextEdit(parent, name)
 
31
{
 
32
        setWordWrap(QTextEdit::WidgetWidth);
 
33
}
 
34
 
 
35
bool MsgMle::focusNextPrevChild(bool next)
 
36
{
 
37
        return QWidget::focusNextPrevChild(next);
 
38
}
 
39
 
 
40
void MsgMle::keyPressEvent(QKeyEvent *e)
 
41
{
 
42
        if(e->key() == Key_Escape)
 
43
                e->ignore();
 
44
        else if(e->key() == Key_Return && ((e->state() & ControlButton) || (e->state() & AltButton)) )
 
45
                e->ignore();
 
46
        else if(e->key() == Key_H && (e->state() & ControlButton))
 
47
                e->ignore();
 
48
        else
 
49
                QTextEdit::keyPressEvent(e);
 
50
}
 
51
 
 
52
QPopupMenu *MsgMle::createPopupMenu(const QPoint& pos)
 
53
{
 
54
        lastLink = anchorAt(pos);
 
55
        if(lastLink.isEmpty())
 
56
                return QTextEdit::createPopupMenu(pos);
 
57
 
 
58
        QString txt = lastLink.left(7) == "mailto:" ? tr("Open mail composer") : tr("Open web browser");
 
59
 
 
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()));
 
63
        return m;
 
64
}
 
65
 
 
66
#include<stdio.h>
 
67
void MsgMle::emitLinkClicked(const QString &s)
 
68
{
 
69
        linkClicked(s);
 
70
}
 
71
 
 
72
void MsgMle::menuURL()
 
73
{
 
74
        linkClicked(lastLink);
 
75
}
 
76
 
 
77
void MsgMle::menuCopy()
 
78
{
 
79
        QString str = lastLink;
 
80
 
 
81
        if(str.left(7) == "mailto:")
 
82
                str.remove(0, 7);
 
83
 
 
84
        QApplication::clipboard()->setText(str);
 
85
}
 
86
 
 
87
 
 
88
ChatMle::ChatMle(QWidget *parent, const char *name)
 
89
:QTextEdit(parent, name)
 
90
{
 
91
        setWordWrap(QTextEdit::WidgetWidth);
 
92
}
 
93
 
 
94
bool ChatMle::focusNextPrevChild(bool next)
 
95
{
 
96
        return QWidget::focusNextPrevChild(next);
 
97
}
 
98
 
 
99
void ChatMle::keyPressEvent(QKeyEvent *e)
 
100
{
 
101
        if(e->key() == Key_Escape)
 
102
                e->ignore();
 
103
        else if(e->key() == Key_Return && ((e->state() & ControlButton) || (e->state() & AltButton)) )
 
104
                e->ignore();
 
105
        else if(e->key() == Key_M && (e->state() & ControlButton))
 
106
                insert("\n");
 
107
        else if(e->key() == Key_H && (e->state() & ControlButton))
 
108
                e->ignore();
 
109
        else if(e->key() == Key_S && (e->state() & AltButton))
 
110
                e->ignore();
 
111
        else if((e->key() == Key_Return) && !(e->state() & ShiftButton) /*&& !option.chatSoftReturn */)
 
112
                e->ignore();
 
113
        else if((e->key() == Key_PageUp || e->key() == Key_PageDown) && (e->state() & ShiftButton))
 
114
                e->ignore();
 
115
        else
 
116
                QTextEdit::keyPressEvent(e);
 
117
}