Subversion Repositories tpanel

Rev

Rev 309 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 309 Rev 310
Line 26... Line 26...
26
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
26
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
27
#include <QAnyStringView>
27
#include <QAnyStringView>
28
#endif
28
#endif
29
 
29
 
30
#include "tqeditline.h"
30
#include "tqeditline.h"
-
 
31
#include "tqsingleline.h"
-
 
32
#include "tqmultiline.h"
31
#include "terror.h"
33
#include "terror.h"
32
 
34
 
33
using std::string;
35
using std::string;
34
 
36
 
35
TQEditLine::TQEditLine(QWidget *widget, bool multiline)
37
TQEditLine::TQEditLine(QWidget *widget, bool multiline)
Line 55... Line 57...
55
TQEditLine::~TQEditLine()
57
TQEditLine::~TQEditLine()
56
{
58
{
57
    DECL_TRACER("TQEditLine::~TQEditLine()");
59
    DECL_TRACER("TQEditLine::~TQEditLine()");
58
 
60
 
59
    if (mMultiline && mTextArea)
61
    if (mMultiline && mTextArea)
-
 
62
    {
60
        disconnect(mTextArea, &QTextEdit::textChanged, this, &TQEditLine::onTextAreaChanged);
63
        disconnect(mTextArea, &TQMultiLine::textChanged, this, &TQEditLine::onTextAreaChanged);
-
 
64
        disconnect(mTextArea, &TQMultiLine::focusChanged, this, &TQEditLine::onFocusChanged);
-
 
65
        disconnect(mTextArea, &TQMultiLine::keyPressed, this, &TQEditLine::onKeyPressed);
-
 
66
    }
61
    else if (!mMultiline && mEdit)
67
    else if (!mMultiline && mEdit)
62
    {
68
    {
63
        disconnect(mEdit, &QLineEdit::textChanged, this, &TQEditLine::onTextChanged);
69
        disconnect(mEdit, &TQSingleLine::textChanged, this, &TQEditLine::onTextChanged);
64
        disconnect(mEdit, &QLineEdit::cursorPositionChanged, this, &TQEditLine::onCursorPositionChangedS);
70
        disconnect(mEdit, &TQSingleLine::cursorPositionChanged, this, &TQEditLine::onCursorPositionChangedS);
-
 
71
        disconnect(mEdit, &TQSingleLine::editingFinished, this, &TQEditLine::onEditingFinished);
-
 
72
        disconnect(mEdit, &TQSingleLine::focusChanged, this, &TQEditLine::onFocusChanged);
-
 
73
        disconnect(mEdit, &TQSingleLine::keyPressed, this, &TQEditLine::onKeyPressed);
65
    }
74
    }
66
}
75
}
67
 
76
 
68
void TQEditLine::init()
77
void TQEditLine::init()
69
{
78
{
Line 74... Line 83...
74
        mLayout = new QHBoxLayout(this);
83
        mLayout = new QHBoxLayout(this);
75
        mLayout->setSpacing(0);
84
        mLayout->setSpacing(0);
76
        mLayout->setContentsMargins(0, 0, 0, 0);
85
        mLayout->setContentsMargins(0, 0, 0, 0);
77
 
86
 
78
        if (mMultiline)
87
        if (mMultiline)
79
        {
-
 
80
            mTextArea = new QTextEdit;
88
            mTextArea = new TQMultiLine;
81
        }
-
 
82
        else
89
        else
83
        {
-
 
84
            mEdit = new QLineEdit;
90
            mEdit = new TQSingleLine;
85
        }
-
 
86
 
91
 
87
        QPalette pal(palette());
92
        QPalette pal(palette());
88
 
93
 
89
        pal.setColor(QPalette::Window, QColorConstants::Transparent);
94
        pal.setColor(QPalette::Window, Qt::transparent);
90
        pal.setColor(QPalette::WindowText, QColorConstants::Black);
95
        pal.setColor(QPalette::WindowText, Qt::black);
-
 
96
        pal.setColor(QPalette::Text, Qt::black);
91
 
97
 
92
        if (!mText.empty())
98
        if (!mText.empty())
93
        {
99
        {
94
            if (mMultiline)
100
            if (mMultiline)
95
                mTextArea->setText(mText.c_str());
101
                mTextArea->setText(mText.c_str());
Line 97... Line 103...
97
                mEdit->setText(mText.c_str());
103
                mEdit->setText(mText.c_str());
98
        }
104
        }
99
 
105
 
100
        if (mMultiline)
106
        if (mMultiline)
101
        {
107
        {
102
            QWidget::setPalette(pal);
108
            mTextArea->setPalette(pal);
103
 
109
 
104
            QWidget::connect(mTextArea, &QTextEdit::textChanged, this, &TQEditLine::onTextAreaChanged);
110
            QWidget::connect(mTextArea, &TQMultiLine::textChanged, this, &TQEditLine::onTextAreaChanged);
-
 
111
            QWidget::connect(mTextArea, &TQMultiLine::focusChanged, this, &TQEditLine::onFocusChanged);
-
 
112
            QWidget::connect(mTextArea, &TQMultiLine::keyPressed, this, &TQEditLine::onKeyPressed);
105
            mLayout->addWidget(mTextArea);
113
            mLayout->addWidget(mTextArea);
106
        }
114
        }
107
        else
115
        else
108
        {
116
        {
109
            QWidget::setPalette(pal);
117
            mEdit->setPalette(pal);
110
 
118
 
111
            QWidget::connect(mEdit, &QLineEdit::textChanged, this, &TQEditLine::onTextChanged);
119
            QWidget::connect(mEdit, &TQSingleLine::textChanged, this, &TQEditLine::onTextChanged);
112
            QWidget::connect(mEdit, &QLineEdit::cursorPositionChanged, this, &TQEditLine::onCursorPositionChangedS);
120
            QWidget::connect(mEdit, &TQSingleLine::cursorPositionChanged, this, &TQEditLine::onCursorPositionChangedS);
113
            QWidget::connect(mEdit, &QLineEdit::editingFinished, this, &TQEditLine::onEditingFinished);
121
            QWidget::connect(mEdit, &TQSingleLine::editingFinished, this, &TQEditLine::onEditingFinished);
-
 
122
            QWidget::connect(mEdit, &TQSingleLine::focusChanged, this, &TQEditLine::onFocusChanged);
-
 
123
            QWidget::connect(mEdit, &TQSingleLine::keyPressed, this, &TQEditLine::onKeyPressed);
114
            mLayout->addWidget(mEdit);
124
            mLayout->addWidget(mEdit);
115
        }
125
        }
116
 
126
 
117
        QWidget::setLayout(mLayout);
127
        QWidget::setLayout(mLayout);
118
    }
128
    }
Line 196... Line 206...
196
void TQEditLine::setPalette(QPalette &pal)
206
void TQEditLine::setPalette(QPalette &pal)
197
{
207
{
198
    DECL_TRACER("TQEditLine::setPalette(QPalette &pal)");
208
    DECL_TRACER("TQEditLine::setPalette(QPalette &pal)");
199
 
209
 
200
    QWidget::setPalette(pal);
210
    QWidget::setPalette(pal);
201
 
211
/*
202
    if (mMultiline && mTextArea)
212
    if (mMultiline && mTextArea)
203
        mTextArea->setPalette(pal);
213
        mTextArea->setPalette(pal);
204
    else if (!mMultiline && mEdit)
214
    else if (!mMultiline && mEdit)
-
 
215
        mEdit->setPalette(pal); */
-
 
216
}
-
 
217
 
-
 
218
void TQEditLine::setTextColor(QColor col)
-
 
219
{
-
 
220
    DECL_TRACER("TQEditLine::setTextColor(QColor col)");
-
 
221
 
-
 
222
    QPalette pal;
-
 
223
 
-
 
224
    if (!mMultiline && mEdit)
-
 
225
        pal = mEdit->palette();
-
 
226
    else if (mMultiline && mTextArea)
-
 
227
        pal = mTextArea->palette();
-
 
228
    else
-
 
229
        return;
-
 
230
 
-
 
231
    pal.setColor(QPalette::WindowText, col);
-
 
232
    pal.setColor(QPalette::Text, col);
-
 
233
 
-
 
234
    if (!mMultiline)
205
        mEdit->setPalette(pal);
235
        mEdit->setPalette(pal);
-
 
236
    else
-
 
237
        mTextArea->setPalette(pal);
206
}
238
}
207
 
239
 
208
void TQEditLine::grabGesture(Qt::GestureType type, Qt::GestureFlags flags)
240
void TQEditLine::grabGesture(Qt::GestureType type, Qt::GestureFlags flags)
209
{
241
{
210
    DECL_TRACER("TQEditLine::grabGesture(Qt::GestureType type, Qt::GestureFlags flags)");
242
    DECL_TRACER("TQEditLine::grabGesture(Qt::GestureType type, Qt::GestureFlags flags)");
Line 298... Line 330...
298
#endif
330
#endif
299
 
331
 
300
/*
332
/*
301
 * Here the signal and callback functions follow.
333
 * Here the signal and callback functions follow.
302
 */
334
 */
303
void TQEditLine::keyPressEvent(QKeyEvent *event)
335
void TQEditLine::onKeyPressed(int key)
304
{
336
{
-
 
337
    DECL_TRACER("TQEditLine::onKeyPressed(int key)");
-
 
338
 
305
    if (event && (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return))
339
    if (key == Qt::Key_Enter || key == Qt::Key_Return)
306
    {
340
    {
307
        string txt;
341
        string txt;
308
 
342
 
309
        if (mMultiline && mTextArea)
343
        if (mMultiline && mTextArea)
310
            txt = mTextArea->toPlainText().toStdString();
344
            txt = mTextArea->toPlainText().toStdString();
Line 321... Line 355...
321
    }
355
    }
322
}
356
}
323
 
357
 
324
void TQEditLine::hideEvent(QHideEvent *event)
358
void TQEditLine::hideEvent(QHideEvent *event)
325
{
359
{
-
 
360
    DECL_TRACER("TQEditLine::hideEvent(QHideEvent *event)");
-
 
361
 
326
    Q_UNUSED(event);
362
    Q_UNUSED(event);
327
    _end();
363
    _end();
328
}
364
}
329
 
365
 
330
void TQEditLine::leaveEvent(QEvent *event)
366
void TQEditLine::leaveEvent(QEvent *event)
331
{
367
{
-
 
368
    DECL_TRACER("TQEditLine::leaveEvent(QEvent *event)");
-
 
369
 
332
    Q_UNUSED(event);
370
    Q_UNUSED(event);
333
    _end();
371
    _end();
334
}
372
}
335
 
373
 
336
void TQEditLine::closeEvent(QCloseEvent *event)
374
void TQEditLine::closeEvent(QCloseEvent *event)
337
{
375
{
-
 
376
    DECL_TRACER("TQEditLine::closeEvent(QCloseEvent *event)");
-
 
377
 
338
    Q_UNUSED(event);
378
    Q_UNUSED(event);
339
    _end();
379
    _end();
340
}
380
}
341
 
381
 
342
void TQEditLine::focusInEvent(QFocusEvent *e)
382
void TQEditLine::onFocusChanged(bool in)
343
{
383
{
344
    DECL_TRACER("TQEditLine::focusInEvent(QFocusEvent *e)");
384
    DECL_TRACER("TQEditLine::onFocusChanged(bool in)");
345
 
385
 
346
    emit focusChanged(mHandle, e->gotFocus());
386
    emit focusChanged(mHandle, in);
347
}
-
 
348
 
-
 
349
void TQEditLine::focusOutEvent(QFocusEvent *e)
-
 
350
{
-
 
351
    DECL_TRACER("TQEditLine::focusOutEvent(QFocusEvent *e)");
-
 
352
 
-
 
353
    emit focusChanged(mHandle, e->gotFocus());
-
 
354
}
387
}
355
 
388
 
356
void TQEditLine::_end()
389
void TQEditLine::_end()
357
{
390
{
-
 
391
    DECL_TRACER("TQEditLine::_end()");
-
 
392
 
358
    string text;
393
    string text;
359
 
394
 
360
    if (mMultiline && mTextArea)
395
    if (mMultiline && mTextArea)
361
        text = mTextArea->toPlainText().toStdString();
396
        text = mTextArea->toPlainText().toStdString();
362
    else if (!mMultiline && mEdit)
397
    else if (!mMultiline && mEdit)