~ubuntu-branches/ubuntu/quantal/linpsk/quantal

« back to all changes in this revision

Viewing changes to linpsk/ctxwindow.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bruce Walker
  • Date: 2002-02-06 11:43:38 UTC
  • Revision ID: james.westby@ubuntu.com-20020206114338-xqmjmhh01lpjm0g4
Tags: upstream-0.6.2
ImportĀ upstreamĀ versionĀ 0.6.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          ctxwindow.cpp  -  description
 
3
                             -------------------
 
4
    begin                : Sun Mar 5 2000
 
5
    copyright            : (C) 2000 by Volker Schroer
 
6
    email                : DL1KSV@gmx.de
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *    based on the work of  Moe Wheatly, AE4JY                             *  
 
16
 ***************************************************************************/
 
17
 
 
18
#include "ctxwindow.h"
 
19
 
 
20
 
 
21
CTxwindow::CTxwindow (QWidget *parent, const char *name ) : QMultiLineEdit(parent,name)
 
22
{
 
23
 
 
24
inpos=0;
 
25
outpos=0;
 
26
filled=0;
 
27
 
 
28
}
 
29
CTxwindow::~CTxwindow(){
 
30
}
 
31
 
 
32
void CTxwindow::keyPressEvent(QKeyEvent *e)     // Bearbeiten der Eingaben im
 
33
                                                                                                                                                                                // TX Window
 
34
{
 
35
unsigned char c;
 
36
static bool CapsLock = false;
 
37
if (filled < TXBUFFER_LENGTH)
 
38
        {
 
39
                switch(e->key())
 
40
                {
 
41
                        case Key_Enter:
 
42
                        case Key_Return:
 
43
                        
 
44
                                cursorPosition(&akt_line,&akt_col);
 
45
                                akt_line++;
 
46
                                if(akt_line >= maxline)
 
47
                                        removeLine(0);  //Erste Zeile entfernen
 
48
                                        
 
49
                                        newLine();
 
50
                                        c='\n';
 
51
                                e->accept();
 
52
                                filled++;
 
53
                                txbuffer[inpos++]=c;
 
54
                                inpos = inpos % TXBUFFER_LENGTH;
 
55
      break;
 
56
                        
 
57
                        case Key_CapsLock:      
 
58
                                CapsLock = !CapsLock;
 
59
                                e->accept();
 
60
                                break;
 
61
                                
 
62
 
 
63
                                case Key_Backspace:
 
64
                                c='\b';
 
65
                                backspace();
 
66
                                e->accept();
 
67
                                if (filled > 0)
 
68
                                        {                               // We can delete the last char direct in the buffer
 
69
                                                filled--;
 
70
                                                inpos = inpos + TXBUFFER_LENGTH - 1;
 
71
                                        }
 
72
                                else
 
73
                                        {
 
74
                                                filled++;
 
75
                                                txbuffer[inpos++]=c;
 
76
                                        }
 
77
                                inpos = inpos % TXBUFFER_LENGTH;
 
78
 
 
79
                                break;
 
80
 
 
81
                                default:        
 
82
                                if ( (e->state() == ShiftButton) || CapsLock)
 
83
                                c=toupper(e->ascii());
 
84
                                else
 
85
                                c=tolower(e->ascii());
 
86
                                if ( c !=0 )
 
87
                                        {
 
88
                                        cursorPosition(&akt_line,&akt_col);
 
89
                                        akt_col++;
 
90
                                        if (akt_col >80)
 
91
                                                {
 
92
                                                insertCntrlChar('\n'); //This newline Char will  be Transmitted
 
93
                                                newLine();
 
94
                                                }
 
95
                                        insertChar(c);
 
96
                                        e->accept();
 
97
                                        filled++;
 
98
                                        txbuffer[inpos++]=c;
 
99
                                        inpos = inpos % TXBUFFER_LENGTH;
 
100
                                }
 
101
                                } // End Case
 
102
 
 
103
                }
 
104
        else
 
105
        {
 
106
                QApplication::beep();
 
107
                e->ignore();
 
108
        }
 
109
 
 
110
} // keyPressEvent
 
111
 
 
112
int CTxwindow::getTxChar(void)
 
113
{
 
114
int ch;
 
115
if (filled > 0)
 
116
        {
 
117
                ch=txbuffer[outpos++];
 
118
                filled--;
 
119
                if (filled == 0)
 
120
                        {
 
121
                                inpos=0;
 
122
                                outpos=0;
 
123
                        }
 
124
                 else
 
125
                        outpos=outpos % TXBUFFER_LENGTH;
 
126
                if (ch == TXOFF_CODE)
 
127
                        settings.status=TX_POSTAMBLE_STATE;
 
128
                return ch;
 
129
        }
 
130
else
 
131
         return TXTOG_CODE;
 
132
 
 
133
}
 
134
 
 
135
int CTxwindow::insertTxChar(const char *txtstring, int anzahl)
 
136
 
 
137
{
 
138
int len;
 
139
int i;
 
140
len = TXBUFFER_LENGTH-filled;
 
141
if(len == 0)
 
142
         return len; //TXBuffer full; try later
 
143
 
 
144
if (len > anzahl)
 
145
        len =anzahl;
 
146
 
 
147
for (i=0;i < len;i++)
 
148
 {
 
149
        txbuffer[inpos++]= *(txtstring+i);
 
150
        inpos=inpos % TXBUFFER_LENGTH;
 
151
        }
 
152
filled +=len;
 
153
return len;
 
154
}       
 
155
 
 
156
void CTxwindow::insertCntrlChar(int CntrlChar)
 
157
 
 
158
{
 
159
while (filled >= TXBUFFER_LENGTH)
 
160
        qApp->processEvents(100);
 
161
filled++;
 
162
txbuffer[inpos++]= CntrlChar;
 
163
inpos %= TXBUFFER_LENGTH;
 
164
return;
 
165
}
 
166
 
 
167
bool CTxwindow::TxBufferisEmpty(void)
 
168
{
 
169
if (filled == 0 )
 
170
return true; //Buffer is empty
 
171
else
 
172
return false; // Some Char's to xmit
 
173
}
 
174
 
 
175
void CTxwindow::setMaxLine(int count)
 
176
 
 
177
{
 
178
maxline=count;
 
179
}