Mercurial > hg > octave-lyh
changeset 15633:36110925f67b
Simplified code.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Mon, 23 Jan 2012 14:15:27 +0100 |
parents | a026315511a2 |
children | 3524352c7382 |
files | libqterminal/ColorTables.h libqterminal/QTerminal.cpp libqterminal/QTerminal.h libqterminal/TerminalDisplay.cpp libqterminal/TerminalDisplay.h qterminal/main.cpp |
diffstat | 6 files changed, 76 insertions(+), 291 deletions(-) [+] |
line wrap: on
line diff
deleted file mode 100644 --- a/libqterminal/ColorTables.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef _COLOR_TABLE_H -#define _COLOR_TABLE_H - -#include "CharacterColor.h" - -using namespace Konsole; - -static const ColorEntry whiteonblack_color_table[TABLE_COLORS] = -{ - // normal - ColorEntry(QColor(0xFF,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0x00,0x00,0x00), 1, 0 ), // Dfore, Dback - ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red - ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow - ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta - ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White - // intensiv - ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ), - ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ), - ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ), - ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0xFF), 0, 0 ), - ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 ) -}; - -static const ColorEntry greenonblack_color_table[TABLE_COLORS] = -{ - ColorEntry(QColor( 24, 240, 24), 0, 0), ColorEntry(QColor( 0, 0, 0), 1, 0), - ColorEntry(QColor( 0, 0, 0), 0, 0), ColorEntry(QColor( 178, 24, 24), 0, 0), - ColorEntry(QColor( 24, 178, 24), 0, 0), ColorEntry(QColor( 178, 104, 24), 0, 0), - ColorEntry(QColor( 24, 24, 178), 0, 0), ColorEntry(QColor( 178, 24, 178), 0, 0), - ColorEntry(QColor( 24, 178, 178), 0, 0), ColorEntry(QColor( 178, 178, 178), 0, 0), - // intensive colors - ColorEntry(QColor( 24, 240, 24), 0, 1 ), ColorEntry(QColor( 0, 0, 0), 1, 0 ), - ColorEntry(QColor( 104, 104, 104), 0, 0 ), ColorEntry(QColor( 255, 84, 84), 0, 0 ), - ColorEntry(QColor( 84, 255, 84), 0, 0 ), ColorEntry(QColor( 255, 255, 84), 0, 0 ), - ColorEntry(QColor( 84, 84, 255), 0, 0 ), ColorEntry(QColor( 255, 84, 255), 0, 0 ), - ColorEntry(QColor( 84, 255, 255), 0, 0 ), ColorEntry(QColor( 255, 255, 255), 0, 0 ) -}; - -static const ColorEntry blackonlightyellow_color_table[TABLE_COLORS] = -{ - ColorEntry(QColor( 0, 0, 0), 0, 0), ColorEntry(QColor( 255, 255, 221), 1, 0), - ColorEntry(QColor( 0, 0, 0), 0, 0), ColorEntry(QColor( 178, 24, 24), 0, 0), - ColorEntry(QColor( 24, 178, 24), 0, 0), ColorEntry(QColor( 178, 104, 24), 0, 0), - ColorEntry(QColor( 24, 24, 178), 0, 0), ColorEntry(QColor( 178, 24, 178), 0, 0), - ColorEntry(QColor( 24, 178, 178), 0, 0), ColorEntry(QColor( 178, 178, 178), 0, 0), - ColorEntry(QColor( 0, 0, 0), 0, 1), ColorEntry(QColor( 255, 255, 221), 1, 0), - ColorEntry(QColor(104, 104, 104), 0, 0), ColorEntry(QColor( 255, 84, 84), 0, 0), - ColorEntry(QColor( 84, 255, 84), 0, 0), ColorEntry(QColor( 255, 255, 84), 0, 0), - ColorEntry(QColor( 84, 84, 255), 0, 0), ColorEntry(QColor( 255, 84, 255), 0, 0), - ColorEntry(QColor( 84, 255, 255), 0, 0), ColorEntry(QColor( 255, 255, 255), 0, 0) -}; - - - - - -#endif -
--- a/libqterminal/QTerminal.cpp +++ b/libqterminal/QTerminal.cpp @@ -19,113 +19,54 @@ #include "QTerminal.h" -#include "Session.h" -#include "TerminalDisplay.h" - using namespace Konsole; -void *createTermWidget(int startnow, void *parent) -{ - return (void*) new QTerminal(startnow, (QWidget*)parent); -} - -struct TermWidgetImpl -{ - TermWidgetImpl(QWidget* parent = 0); - - TerminalDisplay *m_terminalDisplay; - Session *m_session; - - Session* createSession(); - TerminalDisplay* createTerminalDisplay(Session *session, QWidget* parent); -}; - -TermWidgetImpl::TermWidgetImpl(QWidget* parent) -{ - this->m_session = createSession(); - this->m_terminalDisplay = createTerminalDisplay(this->m_session, parent); -} - - -Session *TermWidgetImpl::createSession() -{ - Session *session = new Session(); - - session->setTitle(Session::NameRole, "QTermWidget"); - session->setProgram("/bin/bash"); - QStringList args(""); - session->setArguments(args); - session->setAutoClose(true); - - session->setCodec(QTextCodec::codecForName("UTF-8")); - - session->setFlowControlEnabled(true); - session->setHistoryType(HistoryTypeBuffer(1000)); +QTerminal::QTerminal(QWidget *parent) + : QWidget(parent) { + init(); - session->setDarkBackground(true); - - session->setKeyBindings(""); - return session; -} - -TerminalDisplay *TermWidgetImpl::createTerminalDisplay(Session *session, QWidget* parent) -{ -// TerminalDisplay* display = new TerminalDisplay(this); - TerminalDisplay* display = new TerminalDisplay(parent); - - display->setBellMode(TerminalDisplay::NotifyBell); - display->setTerminalSizeHint(true); - display->setTripleClickMode(TerminalDisplay::SelectWholeLine); - display->setTerminalSizeStartup(true); - - display->setRandomSeed(session->sessionId() * 31); + setFocus(Qt::OtherFocusReason); + m_terminalDisplay->resize(this->size()); - return display; -} - - -QTerminal::QTerminal(int startnow, QWidget *parent) -:QWidget(parent) -{ - m_impl = new TermWidgetImpl(this); - - init(); - - if (startnow && m_impl->m_session) { - m_impl->m_session->run(); - } - - this->setFocus( Qt::OtherFocusReason ); - m_impl->m_terminalDisplay->resize(this->size()); - - this->setFocusProxy(m_impl->m_terminalDisplay); -} - -void QTerminal::startShellProgram() -{ - if ( m_impl->m_session->isRunning() ) - return; - - m_impl->m_session->run(); + this->setFocusProxy(m_terminalDisplay); } void QTerminal::init() -{ - m_impl->m_terminalDisplay->setSize(80, 40); +{ + m_session = new Session(); + + m_session->setTitle(Session::NameRole, "QTermWidget"); + m_session->setProgram("/bin/bash"); + QStringList args(""); + m_session->setArguments(args); + m_session->setAutoClose(true); + m_session->setCodec(QTextCodec::codecForName("UTF-8")); + m_session->setFlowControlEnabled(true); + m_session->setHistoryType(HistoryTypeBuffer(1000)); + m_session->setDarkBackground(true); + m_session->setKeyBindings(""); + + m_terminalDisplay = new TerminalDisplay(this); + m_terminalDisplay->setBellMode(TerminalDisplay::NotifyBell); + m_terminalDisplay->setTerminalSizeHint(true); + m_terminalDisplay->setTripleClickMode(TerminalDisplay::SelectWholeLine); + m_terminalDisplay->setTerminalSizeStartup(true); + m_terminalDisplay->setRandomSeed(m_session->sessionId() * 31); + m_terminalDisplay->setSize(80, 40); QFont font = QApplication::font(); font.setFamily("Monospace"); font.setPointSize(10); font.setStyleHint(QFont::TypeWriter); - setTerminalFont(font); - setScrollBarPosition(NoScrollBar); - - m_impl->m_session->addView(m_impl->m_terminalDisplay); - - connect(m_impl->m_session, SIGNAL(finished()), this, SLOT(sessionFinished())); + setTerminalFont(font); + + m_session->run(); + m_session->addView(m_terminalDisplay); + m_terminalDisplay->setScrollBarPosition(TerminalDisplay::ScrollBarRight); + + connect(m_session, SIGNAL(finished()), this, SLOT(sessionFinished())); } - QTerminal::~QTerminal() { emit destroyed(); @@ -134,136 +75,103 @@ void QTerminal::setTerminalFont(QFont &font) { - if (!m_impl->m_terminalDisplay) + if(!m_terminalDisplay) return; - m_impl->m_terminalDisplay->setVTFont(font); + m_terminalDisplay->setVTFont(font); } void QTerminal::setShellProgram(const QString &progname) { - if (!m_impl->m_session) + if(!m_session) return; - m_impl->m_session->setProgram(progname); + m_session->setProgram(progname); } void QTerminal::setWorkingDirectory(const QString& dir) { - if (!m_impl->m_session) + if(!m_session) return; - m_impl->m_session->setInitialWorkingDirectory(dir); + m_session->setInitialWorkingDirectory(dir); } void QTerminal::setArgs(QStringList &args) { - if (!m_impl->m_session) + if (!m_session) return; - m_impl->m_session->setArguments(args); + m_session->setArguments(args); } void QTerminal::setTextCodec(QTextCodec *codec) { - if (!m_impl->m_session) + if(!m_session) return; - m_impl->m_session->setCodec(codec); -} - -void QTerminal::setColorScheme(int scheme) -{ - switch(scheme) { - case COLOR_SCHEME_WHITE_ON_BLACK: - m_impl->m_terminalDisplay->setColorTable(whiteonblack_color_table); - break; - case COLOR_SCHEME_GREEN_ON_BLACK: - m_impl->m_terminalDisplay->setColorTable(greenonblack_color_table); - break; - case COLOR_SCHEME_BLACK_ON_LIGHT_YELLOW: - m_impl->m_terminalDisplay->setColorTable(blackonlightyellow_color_table); - break; - default: //do nothing - break; - }; + m_session->setCodec(codec); } void QTerminal::setSize(int h, int v) { - if (!m_impl->m_terminalDisplay) + if(!m_terminalDisplay) return; - m_impl->m_terminalDisplay->setSize(h, v); + m_terminalDisplay->setSize(h, v); } void QTerminal::setHistorySize(int lines) { - if (lines < 0) - m_impl->m_session->setHistoryType(HistoryTypeFile()); + if(lines < 0) + m_session->setHistoryType(HistoryTypeFile()); else - m_impl->m_session->setHistoryType(HistoryTypeBuffer(lines)); -} - -void QTerminal::setScrollBarPosition(ScrollBarPosition pos) -{ - if (!m_impl->m_terminalDisplay) - return; - m_impl->m_terminalDisplay->setScrollBarPosition((TerminalDisplay::ScrollBarPosition)pos); -} - -void QTerminal::sendText(QString &text) -{ - m_impl->m_session->sendText(text); + m_session->setHistoryType(HistoryTypeBuffer(lines)); } void QTerminal::setReadOnly(bool readonly) { - m_impl->m_terminalDisplay->setReadOnly(readonly); + m_terminalDisplay->setReadOnly(readonly); } void QTerminal::resizeEvent(QResizeEvent*) { -//qDebug("global window resizing...with %d %d", this->size().width(), this->size().height()); - m_impl->m_terminalDisplay->resize(this->size()); + m_terminalDisplay->resize(this->size()); } - void QTerminal::sessionFinished() { emit finished(); } - void QTerminal::copyClipboard() { - m_impl->m_terminalDisplay->copyClipboard(); + m_terminalDisplay->copyClipboard(); } void QTerminal::pasteClipboard() { - m_impl->m_terminalDisplay->pasteClipboard(); + m_terminalDisplay->pasteClipboard(); } void QTerminal::setFlowControlEnabled(bool enabled) { - m_impl->m_session->setFlowControlEnabled(enabled); + m_session->setFlowControlEnabled(enabled); } bool QTerminal::flowControlEnabled(void) { - return m_impl->m_session->flowControlEnabled(); + return m_session->flowControlEnabled(); } void QTerminal::setFlowControlWarningEnabled(bool enabled) { if(flowControlEnabled()) { - // Do not show warning label if flow control is disabled - m_impl->m_terminalDisplay->setFlowControlWarningEnabled(enabled); + m_terminalDisplay->setFlowControlWarningEnabled(enabled); } } void QTerminal::setEnvironment(const QStringList& environment) { - m_impl->m_session->setEnvironment(environment); + m_session->setEnvironment(environment); } void* QTerminal::getTerminalDisplay() { - return static_cast<void*>(m_impl->m_terminalDisplay); + return static_cast<void*>(m_terminalDisplay); }
--- a/libqterminal/QTerminal.h +++ b/libqterminal/QTerminal.h @@ -17,83 +17,42 @@ */ -#ifndef _Q_TERM_WIDGET -#define _Q_TERM_WIDGET +#ifndef Q_TERMINAL +#define Q_TERMINAL #include <QtGui> - -struct TermWidgetImpl; +#include "Session.h" +#include "TerminalDisplay.h" -enum COLOR_SCHEME { COLOR_SCHEME_WHITE_ON_BLACK = 1, - COLOR_SCHEME_GREEN_ON_BLACK, - COLOR_SCHEME_BLACK_ON_LIGHT_YELLOW }; +using namespace Konsole; class QTerminal : public QWidget { Q_OBJECT public: - - enum ScrollBarPosition - { - /** Do not show the scroll bar. */ - NoScrollBar=0, - /** Show the scroll bar on the left side of the display. */ - ScrollBarLeft=1, - /** Show the scroll bar on the right side of the display. */ - ScrollBarRight=2 - }; - - - //Creation of widget - QTerminal(int startnow = 1, //start shell programm immediatelly - QWidget *parent = 0); + QTerminal(QWidget *parent = 0); ~QTerminal(); - //start shell program if it was not started in constructor void startShellProgram(); - //look-n-feel, if you don`t like defaults + void setTerminalFont(QFont &font); - // Terminal font - // Default is application font with family Monospace, size 10 - // USE ONLY FIXED-PITCH FONT! - // otherwise symbols' position could be incorrect - void setTerminalFont(QFont &font); - - //environment void setEnvironment(const QStringList& environment); - // Shell program, default is /bin/bash void setShellProgram(const QString &progname); - - //working directory + void setWorkingDirectory(const QString& dir); - // Shell program args, default is none void setArgs(QStringList &args); - - //Text codec, default is UTF-8 + void setTextCodec(QTextCodec *codec); - //Color scheme, default is white on black - void setColorScheme(int scheme); - - //set size void setSize(int h, int v); - - // History size for scrolling - void setHistorySize(int lines); //infinite if lines < 0 - // Presence of scrollbar - void setScrollBarPosition(ScrollBarPosition); - - // Send some text to terminal - void sendText(QString &text); + void setHistorySize(int lines); - // Sets whether flow control is enabled void setFlowControlEnabled(bool enabled); - // Returns whether flow control is enabled bool flowControlEnabled(void); /** @@ -102,17 +61,14 @@ */ void setFlowControlWarningEnabled(bool enabled); - // Sets read-only mode to terminal + void setReadOnly(bool); signals: void finished(); public slots: - // Paste clipboard content to terminal void copyClipboard(); - - // Copies selection to clipboard void pasteClipboard(); protected: @@ -123,17 +79,9 @@ void sessionFinished(); private: - void init(); - TermWidgetImpl *m_impl; + void init(); + TerminalDisplay *m_terminalDisplay; + Session *m_session; }; - -//Maybe useful, maybe not - -#ifdef __cplusplus -extern "C" -#endif -void *createTermWidget(int startnow, void *parent); - -#endif - +#endif // Q_TERMINAL
--- a/libqterminal/TerminalDisplay.cpp +++ b/libqterminal/TerminalDisplay.cpp @@ -47,7 +47,6 @@ #include "konsole_wcwidth.h" #include "ScreenWindow.h" #include "TerminalCharacterDecoder.h" -#include "ColorTables.h" using namespace Konsole; @@ -300,7 +299,7 @@ // QCursor::setAutoHideCursor( this, true ); setUsesMouse(true); - setColorTable(whiteonblack_color_table); + setColorTable(base_color_table); // setColorTable(blackonlightyellow_color_table); setMouseTracking(true);
--- a/libqterminal/TerminalDisplay.h +++ b/libqterminal/TerminalDisplay.h @@ -31,7 +31,6 @@ // Konsole #include "Filter.h" #include "Character.h" -#include "ColorTables.h" class QDrag; class QDragEnterEvent;
--- a/qterminal/main.cpp +++ b/qterminal/main.cpp @@ -29,20 +29,9 @@ QMainWindow *mainWindow = new QMainWindow(); QTerminal *terminal = new QTerminal(); - - QFont font = QApplication::font(); - font.setFamily("Monospace"); - font.setPointSize(12); - - terminal->setTerminalFont(font); - - //console->setColorScheme(COLOR_SCHEME_BLACK_ON_LIGHT_YELLOW); - terminal->setScrollBarPosition(QTerminal::ScrollBarRight); - //console->setReadOnly(true); - + mainWindow->setCentralWidget(terminal); - mainWindow->resize(902, 810); - + mainWindow->resize(600, 400); QObject::connect(terminal, SIGNAL(finished()), mainWindow, SLOT(close())); mainWindow->show();