Mercurial > hg > octave-lyh
annotate gui/src/terminal/QTerminalWidget.cpp @ 13568:d3bede98d798
Removed a bunch of sourcecode again.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Mon, 01 Aug 2011 11:11:55 +0200 |
parents | 7eb8cd35454c |
children | e744593197ef |
rev | line source |
---|---|
13501 | 1 /* Copyright (C) 2008 e_k (e_k@users.sourceforge.net) |
2 | |
3 This library is free software; you can redistribute it and/or | |
4 modify it under the terms of the GNU Library General Public | |
5 License as published by the Free Software Foundation; either | |
6 version 2 of the License, or (at your option) any later version. | |
7 | |
8 This library is distributed in the hope that it will be useful, | |
9 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
11 Library General Public License for more details. | |
12 | |
13 You should have received a copy of the GNU Library General Public License | |
14 along with this library; see the file COPYING.LIB. If not, write to | |
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
16 Boston, MA 02110-1301, USA. | |
17 */ | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
18 |
13501 | 19 #include "QTerminalWidget.h" |
20 #include "Session.h" | |
21 #include "TerminalDisplay.h" | |
22 | |
23 struct TermWidgetImpl | |
24 { | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
25 TermWidgetImpl (QWidget * parent = 0); |
13501 | 26 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
27 TerminalDisplay *m_terminalDisplay; |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
28 Session *m_session; |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
29 Session *createSession (); |
13568
d3bede98d798
Removed a bunch of sourcecode again.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13515
diff
changeset
|
30 TerminalDisplay *createTerminalDisplay (QWidget * parent); |
13501 | 31 }; |
32 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
33 TermWidgetImpl::TermWidgetImpl (QWidget * parent) |
13501 | 34 { |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
35 QPalette palette = QApplication::palette (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
36 m_session = createSession (); |
13568
d3bede98d798
Removed a bunch of sourcecode again.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13515
diff
changeset
|
37 m_terminalDisplay = createTerminalDisplay (parent); |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
38 m_terminalDisplay->setBackgroundColor (palette.color (QPalette::Base)); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
39 m_terminalDisplay->setForegroundColor (palette.color (QPalette::Text)); |
13501 | 40 } |
41 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
42 Session * |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
43 TermWidgetImpl::createSession () |
13501 | 44 { |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
45 Session *session = new Session (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
46 session->setTitle (Session::NameRole, "QTerminalWidget"); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
47 session->setProgram ("/bin/bash"); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
48 session->setArguments (QStringList ()); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
49 session->setAutoClose (true); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
50 session->setCodec (QTextCodec::codecForName ("UTF-8")); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
51 session->setFlowControlEnabled (true); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
52 session->setHistoryType (HistoryTypeBuffer (1000)); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
53 session->setDarkBackground (true); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
54 session->setKeyBindings (""); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
55 return session; |
13501 | 56 } |
57 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
58 TerminalDisplay * |
13568
d3bede98d798
Removed a bunch of sourcecode again.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13515
diff
changeset
|
59 TermWidgetImpl::createTerminalDisplay (QWidget * parent) |
13501 | 60 { |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
61 TerminalDisplay *display = new TerminalDisplay (parent); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
62 display->setBellMode (TerminalDisplay::NotifyBell); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
63 display->setTerminalSizeHint (true); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
64 display->setTripleClickMode (TerminalDisplay::SelectWholeLine); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
65 display->setTerminalSizeStartup (true); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
66 return display; |
13501 | 67 } |
68 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
69 QTerminalWidget::QTerminalWidget (int startnow, QWidget * parent):QWidget |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
70 (parent) |
13501 | 71 { |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
72 m_impl = new TermWidgetImpl (this); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
73 |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
74 initialize (); |
13501 | 75 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
76 if (startnow && m_impl->m_session) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
77 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
78 m_impl->m_session->run (); |
13501 | 79 } |
80 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
81 setFocus (Qt::OtherFocusReason); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
82 m_impl->m_terminalDisplay->resize (this->size ()); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
83 setFocusProxy (m_impl->m_terminalDisplay); |
13501 | 84 } |
85 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
86 void |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
87 QTerminalWidget::initialize () |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
88 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
89 m_impl->m_terminalDisplay->setSize (80, 40); |
13501 | 90 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
91 QFont font = QApplication::font (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
92 font.setFamily ("Monospace"); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
93 font.setPointSize (10); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
94 font.setStyleHint (QFont::TypeWriter); |
13515
7eb8cd35454c
Removed unused code in order shrink down the terminal code and hopefully nearing the goal to replace it.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13506
diff
changeset
|
95 m_impl->m_terminalDisplay->setVTFont (font); |
7eb8cd35454c
Removed unused code in order shrink down the terminal code and hopefully nearing the goal to replace it.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13506
diff
changeset
|
96 m_impl->m_terminalDisplay->setScrollBarPosition (TerminalDisplay::ScrollBarRight); |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
97 |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
98 m_impl->m_session->addView (m_impl->m_terminalDisplay); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
99 |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
100 connect (m_impl->m_session, SIGNAL (finished ()), this, |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
101 SLOT (sessionFinished ())); |
13501 | 102 } |
103 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
104 QTerminalWidget::~QTerminalWidget () |
13501 | 105 { |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
106 emit destroyed (); |
13501 | 107 } |
108 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
109 void |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
110 QTerminalWidget::openTeletype (int fd) |
13501 | 111 { |
13568
d3bede98d798
Removed a bunch of sourcecode again.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13515
diff
changeset
|
112 //if (m_impl->m_session->isRunning ()) |
d3bede98d798
Removed a bunch of sourcecode again.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13515
diff
changeset
|
113 // return; |
13501 | 114 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
115 m_impl->m_session->openTeletype (fd); |
13501 | 116 } |
117 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
118 void |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
119 QTerminalWidget::setTextCodec (QTextCodec * codec) |
13501 | 120 { |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
121 if (!m_impl->m_session) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
122 return; |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
123 m_impl->m_session->setCodec (codec); |
13501 | 124 } |
125 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
126 void |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
127 QTerminalWidget::setSize (int h, int v) |
13501 | 128 { |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
129 if (!m_impl->m_terminalDisplay) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
130 return; |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
131 m_impl->m_terminalDisplay->setSize (h, v); |
13501 | 132 } |
133 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
134 void |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
135 QTerminalWidget::setHistorySize (int lines) |
13501 | 136 { |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
137 if (lines < 0) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
138 m_impl->m_session->setHistoryType (HistoryTypeFile ()); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
139 else |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
140 m_impl->m_session->setHistoryType (HistoryTypeBuffer (lines)); |
13501 | 141 } |
142 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
143 void |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
144 QTerminalWidget::sendText (const QString & text) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
145 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
146 m_impl->m_session->sendText (text); |
13501 | 147 } |
148 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
149 void |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
150 QTerminalWidget::resizeEvent (QResizeEvent *) |
13501 | 151 { |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
152 m_impl->m_terminalDisplay->resize (this->size ()); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
153 m_impl->m_terminalDisplay->update (); |
13501 | 154 } |
155 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
156 void |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
157 QTerminalWidget::sessionFinished () |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
158 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
159 emit finished (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
160 } |