summaryrefslogtreecommitdiffstats
path: root/languages/ruby/debugger/rdboutputwidget.cpp
blob: 5e08e1164531f14799ada0224d89b5d916d315bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// *************************************************************************
//                          rdboutputwidget.cpp  -  description
//                             -------------------
//    begin                : 10th April 2003
//    copyright            : (C) 2003 by John Birch
//    email                : [email protected]
//	
//                          Adapted for ruby debugging
//                          --------------------------
//    begin                : Mon Nov 1 2004
//   copyright            : (C) 2004 by Richard Dale
//    email                : [email protected]
// **************************************************************************
//
// **************************************************************************
// *                                                                        *
// *   This program is free software; you can redistribute it and/or modify *
// *   it under the terms of the GNU General Public License as published by *
// *   the Free Software Foundation; either version 2 of the License, or    *
// *   (at your option) any later version.                                  *
// *                                                                        *
// **************************************************************************

#include "rdboutputwidget.h"
#include "dbgcontroller.h"

#include <kcombobox.h>
#include <kdebug.h>
#include <kiconloader.h>
#include <klocale.h>

#include <qlabel.h>
#include <qlayout.h>
#include <qtextedit.h>
#include <qtoolbutton.h>
#include <qtooltip.h>

/***************************************************************************/
/***************************************************************************/
/***************************************************************************/

namespace RDBDebugger
{

/***************************************************************************/

RDBOutputWidget::RDBOutputWidget( QWidget *parent, const char *name) :
    QWidget(parent, name),
    m_userRDBCmdEditor(0),
    m_Interrupt(0),
    m_rdbView(0)
{

    m_rdbView = new QTextEdit (this, name);
    m_rdbView->setReadOnly(true);

    QBoxLayout *userRDBCmdEntry = new QHBoxLayout();
    m_userRDBCmdEditor = new KHistoryCombo (this, "rdb-user-cmd-editor");

    QLabel *label = new QLabel(i18n("&RDB cmd:"), this);
    label->setBuddy(m_userRDBCmdEditor);
    userRDBCmdEntry->addWidget(label);

    userRDBCmdEntry->addWidget(m_userRDBCmdEditor);
    userRDBCmdEntry->setStretchFactor(m_userRDBCmdEditor, 1);

    m_Interrupt = new QToolButton( this, "add breakpoint" );
    m_Interrupt->setSizePolicy ( QSizePolicy ( (QSizePolicy::SizeType)0,
                                         ( QSizePolicy::SizeType)0,
                                         0,
                                         0,
                                         m_Interrupt->sizePolicy().hasHeightForWidth())
                                         );
    m_Interrupt->setPixmap ( SmallIcon ( "player_pause" ) );
    userRDBCmdEntry->addWidget(m_Interrupt);
    QToolTip::add ( m_Interrupt, i18n ( "Pause execution of the app to enter rdb commands" ) );

    QVBoxLayout *topLayout = new QVBoxLayout(this, 2);
    topLayout->addWidget(m_rdbView, 10);
    topLayout->addLayout(userRDBCmdEntry);

    slotDbgStatus( "", s_dbgNotStarted);

    connect( m_userRDBCmdEditor, SIGNAL(returnPressed()), SLOT(slotRDBCmd()) );
    connect( m_Interrupt,        SIGNAL(clicked()),       SIGNAL(breakInto()));
}

/***************************************************************************/

RDBOutputWidget::~RDBOutputWidget()
{
    delete m_rdbView;
    delete m_userRDBCmdEditor;
}

/***************************************************************************/

void RDBOutputWidget::clear()
{
    if (m_rdbView)
        m_rdbView->clear();
}

/***************************************************************************/

void RDBOutputWidget::slotReceivedStdout(const char* line)
{
    if (strncmp(line, "(rdb:", 5) == 0)
        m_rdbView->append(QString("<font color=\"blue\">").append( line ).append("</font>") );
    else
        m_rdbView->append(line);
}

/***************************************************************************/

void RDBOutputWidget::slotReceivedStderr(const char* line)
{
    m_rdbView->append(QString("<font color=\"red\">").append( line ).append("</font>") );
}

/***************************************************************************/

void RDBOutputWidget::slotRDBCmd()
{
    QString RDBCmd(m_userRDBCmdEditor->currentText());
    if (!RDBCmd.isEmpty())
    {
        m_userRDBCmdEditor->addToHistory(RDBCmd);
        m_userRDBCmdEditor->clearEdit();
        emit userRDBCmd(RDBCmd);
    }
}

/***************************************************************************/

void RDBOutputWidget::slotDbgStatus(const QString &, int statusFlag)
{
    if (statusFlag & s_dbgNotStarted)
    {
        m_Interrupt->setEnabled(false);
        m_userRDBCmdEditor->setEnabled(false);
        return;
    }

    if (statusFlag & s_appBusy)
    {
        m_Interrupt->setEnabled(true);
        m_userRDBCmdEditor->setEnabled(false);
    }
    else
    {
        m_Interrupt->setEnabled(false);
        m_userRDBCmdEditor->setEnabled(true);
    }
}

/***************************************************************************/

void RDBOutputWidget::focusInEvent(QFocusEvent */*e*/)
{
    m_userRDBCmdEditor->setFocus();
}

/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
}


#include "rdboutputwidget.moc"