Mercurial > hg > octave-terminal
changeset 15658:eaa7da75d202 draft
Added QTerminalInteface class.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Tue, 31 Jan 2012 11:14:38 +0100 |
parents | 17ef804ef614 |
children | 739f0f73e772 |
files | libqterminal/QTerminal.h libqterminal/libqterminal.pro libqterminal/unix/QUnixTerminalImpl.cpp libqterminal/unix/QUnixTerminalImpl.h libqterminal/win32/QWinTerminalImpl.cpp libqterminal/win32/QWinTerminalImpl.h qterminal/main.cpp |
diffstat | 7 files changed, 64 insertions(+), 83 deletions(-) [+] |
line wrap: on
line diff
--- a/libqterminal/QTerminal.h +++ b/libqterminal/QTerminal.h @@ -25,8 +25,24 @@ #ifdef __WIN32 #include "win32/QWinTerminalImpl.h" + class QTerminal : public QWinTerminalImpl + { + Q_OBJECT + public: + QTerminal(QWidget *parent = 0) + : QWinTerminalImpl(parent) { } + ~QTerminal() { } + }; #else #include "unix/QUnixTerminalImpl.h" + class QTerminal : public QUnixTerminalImpl + { + Q_OBJECT + public: + QTerminal(QWidget *parent = 0) + : QUnixTerminalImpl(parent) { } + ~QTerminal() { } + }; #endif #endif // QTERMINAL_H
--- a/libqterminal/libqterminal.pro +++ b/libqterminal/libqterminal.pro @@ -59,4 +59,5 @@ } HEADERS += QTerminal.h \ - QTerminal + QTerminal \ + QTerminalInterface.h
--- a/libqterminal/unix/QUnixTerminalImpl.cpp +++ b/libqterminal/unix/QUnixTerminalImpl.cpp @@ -24,13 +24,13 @@ #include <termios.h> -QTerminal::QTerminal(QWidget *parent) - : QWidget(parent) { +QUnixTerminalImpl::QUnixTerminalImpl(QWidget *parent) + : QTerminalInterface(parent) { setMinimumSize(600, 400); initialize(); } -void QTerminal::initialize() +void QUnixTerminalImpl::initialize() { m_kpty = new KPty(); m_kpty->open(); @@ -60,7 +60,6 @@ m_sessionModel->addView(m_sessionView); m_sessionView->setScrollBarPosition(TerminalView::ScrollBarRight); - connect(m_sessionModel, SIGNAL(finished()), this, SLOT(sessionFinished())); setFocusProxy(m_sessionView); setFocus(Qt::OtherFocusReason); @@ -69,7 +68,7 @@ connectToPty(); } -void QTerminal::connectToPty() +void QUnixTerminalImpl::connectToPty() { int fds = m_kpty->slaveFd(); @@ -90,51 +89,31 @@ } } -QTerminal::~QTerminal() +QUnixTerminalImpl::~QUnixTerminalImpl() { emit destroyed(); } -void QTerminal::setTerminalFont(QFont &font) +void QUnixTerminalImpl::setTerminalFont(QFont &font) { if(!m_sessionView) return; m_sessionView->setVTFont(font); } -void QTerminal::setTextCodec(QTextCodec *codec) -{ - if(!m_sessionModel) - return; - m_sessionModel->setCodec(codec); -} - -void QTerminal::setSize(int h, int v) +void QUnixTerminalImpl::setSize(int h, int v) { if(!m_sessionView) return; m_sessionView->setSize(h, v); } -void QTerminal::setHistorySize(int lines) -{ - if(lines < 0) - m_sessionModel->setHistoryType(HistoryTypeFile()); - else - m_sessionModel->setHistoryType(HistoryTypeBuffer(lines)); -} - -void QTerminal::setReadOnly(bool readonly) -{ - m_sessionView->setReadOnly(readonly); -} - -void QTerminal::sendText(QString text) +void QUnixTerminalImpl::sendText(QString text) { m_sessionModel->sendText(text); } -void QTerminal::focusInEvent(QFocusEvent *focusEvent) +void QUnixTerminalImpl::focusInEvent(QFocusEvent *focusEvent) { Q_UNUSED(focusEvent); m_sessionView->updateImage(); @@ -142,14 +121,14 @@ m_sessionView->update(); } -void QTerminal::showEvent(QShowEvent *) +void QUnixTerminalImpl::showEvent(QShowEvent *) { m_sessionView->updateImage(); m_sessionView->repaint(); m_sessionView->update(); } -void QTerminal::resizeEvent(QResizeEvent*) +void QUnixTerminalImpl::resizeEvent(QResizeEvent*) { m_sessionView->resize(this->size()); m_sessionView->updateImage(); @@ -157,17 +136,12 @@ m_sessionView->update(); } -void QTerminal::sessionFinished() -{ - emit finished(); -} - -void QTerminal::copyClipboard() +void QUnixTerminalImpl::copyClipboard() { m_sessionView->copyClipboard(); } -void QTerminal::pasteClipboard() +void QUnixTerminalImpl::pasteClipboard() { m_sessionView->pasteClipboard(); }
--- a/libqterminal/unix/QUnixTerminalImpl.h +++ b/libqterminal/unix/QUnixTerminalImpl.h @@ -18,31 +18,25 @@ */ -#ifndef Q_TERMINAL -#define Q_TERMINAL +#ifndef Q_UNIXTERMINALIMPL +#define Q_UNIXTERMINALIMPL #include <QtGui> #include "unix/kpty.h" #include "unix/TerminalModel.h" #include "unix/TerminalView.h" +#include "QTerminalInterface.h" -class QTerminal : public QWidget +class QUnixTerminalImpl : public QTerminalInterface { Q_OBJECT public: - QTerminal(QWidget *parent = 0); - ~QTerminal(); + QUnixTerminalImpl(QWidget *parent = 0); + virtual ~QUnixTerminalImpl(); void setTerminalFont(QFont &font); - void setArgs(QStringList &args); - void setTextCodec(QTextCodec *codec); void setSize(int h, int v); - void setHistorySize(int lines); - void setReadOnly(bool); void sendText(QString text); - -signals: - void finished(); public slots: void copyClipboard(); @@ -51,10 +45,7 @@ protected: void focusInEvent(QFocusEvent *focusEvent); void showEvent(QShowEvent *); - virtual void resizeEvent(QResizeEvent *); - -protected slots: - void sessionFinished(); + virtual void resizeEvent(QResizeEvent *); private: void initialize(); @@ -65,4 +56,4 @@ KPty *m_kpty; }; -#endif // Q_TERMINAL +#endif // Q_UNIXTERMINALIMPL
--- a/libqterminal/win32/QWinTerminalImpl.cpp +++ b/libqterminal/win32/QWinTerminalImpl.cpp @@ -53,7 +53,7 @@ class QConsoleView : public QWidget { public: - QConsoleView (QTerminal* parent = 0) : QWidget (parent), q (parent) { } + QConsoleView (QWinTerminalImpl* parent = 0) : QWidget (parent), q (parent) { } ~QConsoleView (void) { } protected: @@ -61,7 +61,7 @@ void resizeEvent (QResizeEvent* event) { q->viewResizeEvent (this, event); } private: - QTerminal* q; + QWinTerminalImpl* q; }; ////////////////////////////////////////////////////////////////////////////// @@ -69,24 +69,24 @@ class QConsoleThread : public QThread { public: - QConsoleThread (QTerminal* console) : QThread (console), q (console) { } + QConsoleThread (QWinTerminalImpl* console) : QThread (console), q (console) { } protected: void run (void) { q->start (); } private: - QTerminal* q; + QWinTerminalImpl* q; }; ////////////////////////////////////////////////////////////////////////////// class QConsolePrivate { - friend class QTerminal; + friend class QWinTerminalImpl; public: - QConsolePrivate (QTerminal* parent, const QString& cmd = QString ()); + QConsolePrivate (QUnixTerminalImpl* parent, const QString& cmd = QString ()); ~QConsolePrivate (void); void updateConsoleSize (bool sync = false); @@ -106,7 +106,7 @@ const char* devName); private: - QTerminal* q; + QWinTerminalImpl* q; private: QFont m_font; @@ -135,7 +135,7 @@ ////////////////////////////////////////////////////////////////////////////// -QConsolePrivate::QConsolePrivate (QTerminal* parent, const QString& cmd) +QConsolePrivate::QConsolePrivate (QUnixTerminalImpl* parent, const QString& cmd) : q (parent), m_command (cmd), m_process (NULL), m_inWheelEvent (false) { log (NULL); @@ -686,28 +686,28 @@ ////////////////////////////////////////////////////////////////////////////// -QTerminal::QTerminal (QWidget* parent) +QUnixTerminalImpl::QUnixTerminalImpl (QWidget* parent) : d (new QConsolePrivate (this)) { } ////////////////////////////////////////////////////////////////////////////// -QTerminal::QTerminal (const QString& cmd, QWidget* parent) +QUnixTerminalImpl::QUnixTerminalImpl (const QString& cmd, QWidget* parent) : d (new QConsolePrivate (this, cmd)) { } ////////////////////////////////////////////////////////////////////////////// -QTerminal::~QTerminal (void) +QUnixTerminalImpl::~QUnixTerminalImpl (void) { delete d; } ////////////////////////////////////////////////////////////////////////////// -void QTerminal::viewResizeEvent (QConsoleView*, QResizeEvent*) +void QUnixTerminalImpl::viewResizeEvent (QConsoleView*, QResizeEvent*) { d->updateConsoleSize (true); d->grabConsoleBuffer (); @@ -715,7 +715,7 @@ ////////////////////////////////////////////////////////////////////////////// -void QTerminal::viewPaintEvent (QConsoleView* w, QPaintEvent* event) +void QUnixTerminalImpl::viewPaintEvent (QConsoleView* w, QPaintEvent* event) { QPainter p (w); int cw = d->m_charSize.width (), ch = d->m_charSize.height (); @@ -805,7 +805,7 @@ ////////////////////////////////////////////////////////////////////////////// -void QTerminal::wheelEvent (QWheelEvent* event) +void QUnixTerminalImpl::wheelEvent (QWheelEvent* event) { if (! d->m_inWheelEvent) { @@ -818,7 +818,7 @@ ////////////////////////////////////////////////////////////////////////////// -bool QTerminal::winEvent (MSG* msg, long* result) +bool QUnixTerminalImpl::winEvent (MSG* msg, long* result) { switch (msg->message) { @@ -839,35 +839,35 @@ ////////////////////////////////////////////////////////////////////////////// -void QTerminal::scrollValueChanged (int value) +void QUnixTerminalImpl::scrollValueChanged (int value) { d->setScrollValue (value); } ////////////////////////////////////////////////////////////////////////////// -void QTerminal::monitorConsole (void) +void QUnixTerminalImpl::monitorConsole (void) { d->monitorConsole (); } ////////////////////////////////////////////////////////////////////////////// -void QTerminal::focusInEvent (QFocusEvent* event) +void QUnixTerminalImpl::focusInEvent (QFocusEvent* event) { QWidget::focusInEvent (event); } ////////////////////////////////////////////////////////////////////////////// -void QTerminal::start (void) +void QUnixTerminalImpl::start (void) { d->startCommand (); } ////////////////////////////////////////////////////////////////////////////// -void QTerminal::sendText (const QString& s) +void QUnixTerminalImpl::sendText (const QString& s) { d->sendConsoleText (s); }
--- a/libqterminal/win32/QWinTerminalImpl.h +++ b/libqterminal/win32/QWinTerminalImpl.h @@ -23,7 +23,7 @@ #define __QConsole_h__ 1 #include <QWidget> - +#include "QTerminalInterface.h" class QFocusEvent; class QKeyEvent; class QPaintEvent; @@ -36,7 +36,7 @@ ////////////////////////////////////////////////////////////////////////////// -class QTerminal : public QWidget +class QWinTerminalImpl : public QTerminalInterface { Q_OBJECT friend class QConsolePrivate; @@ -44,9 +44,9 @@ friend class QConsoleView; public: - QTerminal (QWidget* parent = 0); - QTerminal (const QString& cmd, QWidget* parent = 0); - ~QTerminal (void); + QWinTerminalImpl (QWidget* parent = 0); + QWinTerminalImpl (const QString& cmd, QWidget* parent = 0); + ~QWinTerminalImpl (void); void sendText (const QString& s);