~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: 2004-06-15 00:10:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040615001041-enywb6pcpe4sjsw6
Tags: 0.9.2-1
* New upstream release
* Set KDEDIR for ./configure so kde specific files get installed
* Don't install libpsiwidgets.so. It got installed in /usr/share
  where it doesn't belong. May be included (at a better location)
  later.

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
 
****************************************************************************/
 
1
/*
 
2
 * msgmle.cpp - subclass of PsiTextView to handle various hotkeys
 
3
 * Copyright (C) 2001-2003  Justin Karneges, Michail Pishchagin
 
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 library; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 *
 
19
 */
20
20
 
 
21
#include"common.h"
21
22
#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)
 
23
 
 
24
//----------------------------------------------------------------------------
 
25
// ChatView
 
26
//----------------------------------------------------------------------------
 
27
ChatView::ChatView(QWidget *parent, const char *name)
 
28
: PsiTextView(parent, name)
 
29
{
 
30
        setWordWrap(WidgetWidth);
 
31
        setWrapPolicy(AtWordOrDocumentBoundary);
 
32
 
 
33
        setTextFormat(RichText);
 
34
        setReadOnly(true);
 
35
        setUndoRedoEnabled(false);
 
36
        setHScrollBarMode(QScrollView::AlwaysOff);
 
37
}
 
38
 
 
39
ChatView::~ChatView()
 
40
{
 
41
}
 
42
 
 
43
bool ChatView::focusNextPrevChild(bool next)
36
44
{
37
45
        return QWidget::focusNextPrevChild(next);
38
46
}
39
47
 
40
 
void MsgMle::keyPressEvent(QKeyEvent *e)
 
48
void ChatView::keyPressEvent(QKeyEvent *e)
41
49
{
42
50
        if(e->key() == Key_Escape)
43
51
                e->ignore();
 
52
#ifdef Q_WS_MAC
 
53
        else if(e->key() == Key_W && e->state() & ControlButton)
 
54
                e->ignore();
 
55
#endif
44
56
        else if(e->key() == Key_Return && ((e->state() & ControlButton) || (e->state() & AltButton)) )
45
57
                e->ignore();
46
58
        else if(e->key() == Key_H && (e->state() & ControlButton))
47
59
                e->ignore();
 
60
        else if(e->key() == Key_M && (e->state() & ControlButton)) // newline
 
61
                insert("\n");
 
62
        else if(e->key() == Key_U && (e->state() & ControlButton))
 
63
                setText("");
48
64
        else
49
65
                QTextEdit::keyPressEvent(e);
50
66
}
51
67
 
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)
 
68
void ChatView::resizeEvent(QResizeEvent *e)
 
69
{
 
70
        // This fixes flyspray #45
 
71
        if(contentsY() == contentsHeight() - visibleHeight())
 
72
                scrollToBottom();
 
73
 
 
74
        QTextEdit::resizeEvent(e);
 
75
}
 
76
 
 
77
//----------------------------------------------------------------------------
 
78
// ChatEdit
 
79
//----------------------------------------------------------------------------
 
80
ChatEdit::ChatEdit(QWidget *parent, const char *name)
 
81
: PsiTextView(parent, name)
90
82
{
91
83
        setWordWrap(QTextEdit::WidgetWidth);
92
 
}
93
 
 
94
 
bool ChatMle::focusNextPrevChild(bool next)
 
84
 
 
85
        setReadOnly(false);
 
86
        setUndoRedoEnabled(true);
 
87
 
 
88
        setTextFormat(PlainText);
 
89
        setMinimumHeight(48);
 
90
}
 
91
 
 
92
ChatEdit::~ChatEdit()
 
93
{
 
94
}
 
95
 
 
96
bool ChatEdit::focusNextPrevChild(bool next)
95
97
{
96
98
        return QWidget::focusNextPrevChild(next);
97
99
}
98
100
 
99
 
void ChatMle::keyPressEvent(QKeyEvent *e)
 
101
void ChatEdit::keyPressEvent(QKeyEvent *e)
100
102
{
101
 
        if(e->key() == Key_Escape)
 
103
        if(e->key() == Key_Escape || (e->key() == Key_W && e->state() & ControlButton))
102
104
                e->ignore();
103
105
        else if(e->key() == Key_Return && ((e->state() & ControlButton) || (e->state() & AltButton)) )
104
106
                e->ignore();
105
 
        else if(e->key() == Key_M && (e->state() & ControlButton))
 
107
        else if(e->key() == Key_M && (e->state() & ControlButton)) // newline
106
108
                insert("\n");
107
 
        else if(e->key() == Key_H && (e->state() & ControlButton))
 
109
        else if(e->key() == Key_H && (e->state() & ControlButton)) // history
108
110
                e->ignore();
109
111
        else if(e->key() == Key_S && (e->state() & AltButton))
110
112
                e->ignore();
111
 
        else if((e->key() == Key_Return) && !(e->state() & ShiftButton) /*&& !option.chatSoftReturn */)
 
113
        else if(e->key() == Key_U && (e->state() & ControlButton))
 
114
                setText("");
 
115
        else if((e->key() == Key_Return || e->key() == Key_Enter) && !(e->state() & ShiftButton) && option.chatSoftReturn)
112
116
                e->ignore();
113
117
        else if((e->key() == Key_PageUp || e->key() == Key_PageDown) && (e->state() & ShiftButton))
114
118
                e->ignore();
 
119
        else if(e->key() == Key_U && (e->state() & ControlButton))
 
120
                setText("");
115
121
        else
116
122
                QTextEdit::keyPressEvent(e);
117
123
}
 
124
 
 
125