diff --git a/kmuddy/dialogs/dlgconnect.cpp b/kmuddy/dialogs/dlgconnect.cpp index 372e9be..99ee225 100644 --- a/kmuddy/dialogs/dlgconnect.cpp +++ b/kmuddy/dialogs/dlgconnect.cpp @@ -1,266 +1,266 @@ /*************************************************************************** dlgconnect.cpp - Connect dialog This file is a part of KMuddy distribution. ------------------- begin : Ut Jul 23 2002 copyright : (C) 2002-2008 by Tomas Mecir email : kmuddy@kmuddy.com ***************************************************************************/ /*************************************************************************** * * * 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 "dlgconnect.h" #include "dlgeditprofile.h" #include "cprofilemanager.h" #include "cprofilesettings.h" #include #include #include #include #include #include #include #include #include dlgConnect::dlgConnect(QWidget *parent) : QDialog (parent) { setWindowTitle (i18n ("Connect")); //create main dialog's widget QGridLayout *layout = new QGridLayout (this); //put some widgets there lw = new QTreeView (this); lw->setModel (cProfileManager::self()->model()); lw->setUniformRowHeights (true); lw->setRootIsDecorated (false); lw->setItemsExpandable (false); lw->setWhatsThis( i18n ("This list shows currently defined profiles.

Profiles " "allow you to speed up connecting to your MUD, as well as to use " "more advanced features like aliases or triggers.")); QWidget *vb = new QWidget (this); QVBoxLayout *vblayout = new QVBoxLayout (vb); vblayout->setSpacing (5); KPushButton *addButton = new KPushButton (i18n ("&New profile"), vb); KPushButton *modifyButton = new KPushButton (i18n ("&Modify profile"), vb); KPushButton *deleteButton = new KPushButton (i18n ("&Delete profile"), vb); KPushButton *duplicateButton = new KPushButton (i18n ("&Duplicate profile"), vb); vblayout->addWidget (addButton); vblayout->addWidget (modifyButton); vblayout->addWidget (deleteButton); vblayout->addWidget (duplicateButton); chkSendNothing = new QCheckBox (i18n ("Do not &send login sequence"), this); chkSendNothing->setWhatsThis( i18n ("Login sequence won't be sent for " "this connect. Useful when you're creating a new character and you " "want to use QuickConnect for some reason.")); chkSendNothing->setChecked (false); chkOffline = new QCheckBox (i18n ("&Offline editing"), this); chkOffline->setWhatsThis( i18n ("This allows offline editing of " "profiles.")); chkOffline->setChecked(false); buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); QPushButton *button = buttons->button (QDialogButtonBox::Ok); button->setText (i18n ("&Connect")); button->setToolTip (i18n ("Establishes connection with specified parameters.")); button = buttons->button (QDialogButtonBox::Cancel); button->setText (i18n ("C&lose")); button->setToolTip (i18n ("Closes this dialog box without connecting.")); connect (buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); connect (buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); layout->setRowStretch (0, 0); layout->setRowStretch (1, 5); layout->setSpacing (5); layout->addWidget (lw, 0, 0, 2, 1); layout->addWidget (vb, 0, 1); layout->addWidget (chkSendNothing, 2, 0); layout->addWidget (chkOffline, 3, 0); - layout->addWidget (buttons, 4, 0, 2, 1); + layout->addWidget (buttons, 4, 0, 1, 2); //connect signals connect (addButton, SIGNAL(clicked()), this, SLOT(addPressed())); connect (modifyButton, SIGNAL(clicked()), this, SLOT(modifyPressed())); connect (deleteButton, SIGNAL(clicked()), this, SLOT(deletePressed())); connect (duplicateButton, SIGNAL(clicked()), this, SLOT(duplicatePressed())); connect (lw->selectionModel(), SIGNAL (selectionChanged (const QItemSelection &, const QItemSelection &)), this, SLOT (selectionChanged (const QItemSelection &))); connect (lw, SIGNAL (doubleClicked (const QModelIndex &)), this, SLOT (doubleClicked (const QModelIndex &))); lw->setFocus (); } dlgConnect::~dlgConnect() { } QSize dlgConnect::sizeHint() const { return QSize (500, 400); } QString dlgConnect::selectedProfile () { QItemSelection sel = lw->selectionModel()->selection(); if (sel.empty()) return QString(); int idx = sel.indexes().first().row(); return cProfileManager::self()->profileList()[idx]; } bool dlgConnect::sendNothing () { return chkSendNothing->isChecked (); } bool dlgConnect::isOffLine() { return chkOffline->isChecked (); } void dlgConnect::selectionChanged (const QItemSelection &index) { //enable/disable Connect button QPushButton *button = buttons->button (QDialogButtonBox::Ok); button->setEnabled (index.indexes().empty() ? false : true); } void dlgConnect::doubleClicked (const QModelIndex &index) { if (index.isValid ()) accept(); } void dlgConnect::addPressed () { //so first we have to create the dialog... mdlg = new dlgEditProfile (this); //then we connect() all its signals - this handles everything that the dialog offers... connect (mdlg, SIGNAL (accepted()), this, SLOT (doAdd ())); //fill in default login sequence QStringList ls; ls.append ("$name"); ls.append ("$password"); mdlg->setConnectionString (ls); //dialog is ready - show it! mdlg->exec (); delete mdlg; } void dlgConnect::modifyPressed () { cProfileManager *mgr = cProfileManager::self(); QString profile = selectedProfile(); cProfileSettings *sett = mgr->settings (profile); if (!sett) return; // no profile selected //so first we have to create the dialog... mdlg = new dlgEditProfile (this); //then we connect() all its signals - this handles everything that the dialog offers... connect (mdlg, SIGNAL (accepted()), this, SLOT (doModify ())); mdlg->setName (mgr->visibleProfileName (profile)); mdlg->setServer (sett->getString ("server")); mdlg->setPort (sett->getInt ("port")); mdlg->setLogin (sett->getString ("login")); mdlg->setPassword (sett->getString ("password")); QStringList conn; int cnt = sett->getInt ("on-connect-count"); for (int i = 0; i < cnt; ++i) conn << sett->getString ("on-connect-"+QString::number(i)); mdlg->setConnectionString (conn); //dialog is ready - show it! mdlg->exec (); delete mdlg; } void dlgConnect::updateProfileFromDialog (const QString &profile) { cProfileManager *mgr = cProfileManager::self(); cProfileSettings *sett = mgr->settings (profile); if (!sett) return; sett->setString ("server", mdlg->server()); sett->setInt ("port", mdlg->port()); sett->setString ("login", mdlg->login()); sett->setString ("password", mdlg->password()); QStringList con = mdlg->connectionString(); sett->setInt ("on-connect-count", con.size()); for (int i = 0; i < con.size(); ++i) sett->setString ("on-connect-"+QString::number(i), con[i]); sett->save(); mgr->profileInfoChanged (profile); } void dlgConnect::deletePressed () { cProfileManager *mgr = cProfileManager::self(); QString profile = selectedProfile(); cProfileSettings *sett = mgr->settings (profile); if (!sett) return; // can we do that ? if (mgr->hasSessionAssigned (profile)) { KMessageBox::sorry (this, i18n ("This profile cannot be deleted, because you have a connection open using this profile."), i18n ("Unable to delete")); return; } if (KMessageBox::questionYesNoCancel (this, i18n ("Do you really want to delete profile %1?", mgr->visibleProfileName (profile)), i18n ("Delete profile")) != KMessageBox::Yes) return; // wants to delete // TODO: offer the option to also delete the files mgr->deleteProfile (profile, false); } void dlgConnect::duplicatePressed () { cProfileManager *mgr = cProfileManager::self(); QString profile = selectedProfile(); cProfileSettings *sett = mgr->settings (profile); if (!sett) return; bool ok; QString newName = KInputDialog::getText (i18n ("Duplicate Profile"), i18n ("Please enter name for the duplicated profile"), mgr->visibleProfileName (profile), &ok, this); if (!mgr->duplicateProfile (profile, newName)) KMessageBox::sorry (this, i18n ("There was an error trying to duplicate the profile. Please ensure that you have write access to the profile directory."), i18n ("Unable to duplicate")); } void dlgConnect::doAdd () { cProfileManager *mgr = cProfileManager::self(); QString profile = mgr->newProfile (mdlg->name()); updateProfileFromDialog (profile); } void dlgConnect::doModify () { cProfileManager *mgr = cProfileManager::self(); QString profile = selectedProfile(); mgr->renameProfile (profile, mdlg->name()); updateProfileFromDialog (profile); } diff --git a/kmuddy/kmuddy-version.h b/kmuddy/kmuddy-version.h index 2ac5575..1d04d8c 100644 --- a/kmuddy/kmuddy-version.h +++ b/kmuddy/kmuddy-version.h @@ -1,9 +1,9 @@ #ifndef KMUDDY_VERSION_H #define KMUDDY_VERSION_H #define PACKAGE "KMuddy" -#define VERSION "1.1pre" +#define VERSION "1.2pre" #endif // KMUDDY_VERSION_H diff --git a/libs/cconsole.cpp b/libs/cconsole.cpp index 4a65c6a..d1e7f19 100644 --- a/libs/cconsole.cpp +++ b/libs/cconsole.cpp @@ -1,310 +1,315 @@ /*************************************************************************** cconsole.cpp - main displaying widget v2 This file is a part of KMuddy distribution. ------------------- begin : So Dec 21 2017 copyright : (C) 2002-2017 by Tomas Mecir email : mecirt@gmail.com ***************************************************************************/ /*************************************************************************** * * * 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 "cconsole.h" #include "cactionmanager.h" #include "ctextchunk.h" #include #include #include #include #include #include /** Class cHistoryBuffer - holds the whole buffer, rotates it when needed and provides access to it. Inspired by a similar class from Alex Bache. */ class KMUDDY_EXPORT cHistoryBuffer { public: /** create the cyclic buffer of a given size */ cHistoryBuffer (int size); /** destructor */ ~cHistoryBuffer (); /** current number of items in the buffer */ int items () { return _items; }; /** current size of the buffer */ int size () { return _size; }; /** add a new line to the buffer */ void add (cTextChunk *chunk); /** Returns one line in the buffer. Returns cTextChunk*, not cTextChunk*& - so that we can modify the chunk contents, but we cannot assign another chunk to any given position,*/ cTextChunk * operator[] (int idx); /** flush the buffer */ void flush (); protected: int _size, _items; /** position in the cyclic buffer, where the NEXT added item will go */ int curidx; /** the actual buffer */ cTextChunk **buffer; }; class cConsole::Private { QGraphicsScene scene; QGraphicsTextItem *mainText, *scrollText; QTextDocument *text; QColor bgcolor; QFont font; int sess; int charWidth, charHeight; bool wantNewLine; friend class cConsole; }; cConsole::cConsole(QWidget *parent) : QGraphicsView(parent) { d = new Private; d->sess = -1; d->charWidth = 12; d->charHeight = 12; d->wantNewLine = false; d->text = new QTextDocument; QString stylesheet = "body { color: " + QColor (Qt::lightGray).name() + "; } "; d->text->setDefaultStyleSheet (stylesheet); QTextOption opt; opt.setWrapMode (QTextOption::WrapAtWordBoundaryOrAnywhere); d->text->setDefaultTextOption (opt); d->mainText = new QGraphicsTextItem; d->mainText->setDocument (d->text); d->mainText->setFiltersChildEvents (true); d->scrollText = new QGraphicsTextItem; d->scrollText->setDocument (d->text); d->scrollText->setParentItem (d->mainText); d->scrollText->setFocusProxy (d->mainText); d->scrollText->setVisible (false); setScene (&d->scene); d->scene.addItem (d->mainText); d->scene.addItem (d->scrollText); d->scene.setFocusItem (d->mainText); //background color d->bgcolor = Qt::black; QPalette pal = palette(); pal.setColor (backgroundRole(), d->bgcolor); pal.setColor (QPalette::Base, d->bgcolor); setPalette (pal); setBackgroundRole (QPalette::Base); //size policy QSizePolicy qsp (QSizePolicy::Expanding, QSizePolicy::Expanding); setSizePolicy (qsp); //context menu setContextMenuPolicy (Qt::ActionsContextMenu); KActionCollection *acol = cActionManager::self()->getACol(); QAction *showmenubar = acol->action ("ShowMenuBar"); QAction *fullscreenmode = acol->action ("SetFullScreen"); QAction *clipcopy = acol->action ("ClipboardCopy"); QAction *pastemenu = acol->action ("PasteMenu"); QAction *sep1 = new QAction (this); QAction *sep2 = new QAction (this); sep1->setSeparator (true); sep2->setSeparator (true); if (clipcopy) addAction (clipcopy); if (pastemenu) addAction (pastemenu); addAction (sep1); if (showmenubar) addAction (showmenubar); addAction (sep2); if (fullscreenmode) addAction (fullscreenmode); setFont (QFontDatabase::systemFont (QFontDatabase::FixedFont)); //default system fixed font setCursor (Qt::IBeamCursor); fixupOutput(); } cConsole::~cConsole() { delete d->scrollText; delete d->mainText; delete d->text; // TODO delete d; } void cConsole::setSession (int s) { d->sess = s; } void cConsole::setFont (QFont f) { d->font = f; d->text->setDefaultFont (d->font); QFontMetrics fm (f); d->charWidth = fm.width ("m"); d->charHeight = fm.lineSpacing(); fixupOutput(); } QFont cConsole::font () { return d->font; } void cConsole::setDefaultBkColor (QColor color) { d->bgcolor = color; QPalette pal = palette(); pal.setColor (backgroundRole(), d->bgcolor); pal.setColor (QPalette::Base, d->bgcolor); setPalette (pal); update(); } QColor cConsole::defaultBkColor () { return d->bgcolor; } +void cConsole::setScrollTextVisible (bool vis) +{ + d->scrollText->setVisible (vis); +} + void cConsole::setScrollTextSize (int aconsize) { // TODO } void cConsole::setIndentation (int val) { // TODO } void cConsole::setEnableBlinking (bool value) { // TODO } int cConsole::curRows() { return height() / d->charHeight; } int cConsole::curCols() { if (d->charWidth <= 0) return 0; return width() / d->charWidth; } void cConsole::setRepaintCount (int val) { // TODO } void cConsole::forceEmitSize () { emit dimensionsChanged (curCols(), curRows()); } void cConsole::dumpBuffer (bool fromcurrent, QFile &file, char dumpType) { // TODO } void cConsole::tryUpdateHistorySize () { // TODO } void cConsole::setInitialHistorySize (int size) { // TODO } QStringList cConsole::words (QString prefix, int minLength) { QStringList res; // TODO return res; } void cConsole::clear () { d->text->clear(); update(); } void cConsole::addLine (cTextChunk *chunk) { addNewText (chunk, true); } void cConsole::addText (cTextChunk *chunk) { addNewText (chunk, false); } void cConsole::addNewText (cTextChunk *chunk, bool endTheLine) { QTextCursor cursor (d->text); cursor.movePosition (QTextCursor::End); if (chunk) { if (d->wantNewLine) { cursor.insertBlock (); d->wantNewLine = false; } cursor.insertHtml (chunk->toHTML()); } if (endTheLine) d->wantNewLine = true; } void cConsole::forceBeginOfLine () { addNewText (nullptr, true); } void cConsole::expireNamedLinks (const QString &name) { // TODO } void cConsole::addSelectionToClipboard (QClipboard::Mode clipboardMode) { // TODO } void cConsole::lineUp () { // TODO } void cConsole::lineDown () { // TODO } void cConsole::pageUp () { // TODO } void cConsole::pageDown () { // TODO } void cConsole::resizeEvent (QResizeEvent *) { fixupOutput(); } void cConsole::fixupOutput () { d->text->setTextWidth (d->scene.width()); forceEmitSize (); } /* TODO SIGNALS - these must be emitted void sendCommand (const QString &command); -- in activateLink void promptCommand (const QString &command); -- in activateLink */ diff --git a/libs/cconsole.h b/libs/cconsole.h index 66c6210..096cfce 100644 --- a/libs/cconsole.h +++ b/libs/cconsole.h @@ -1,119 +1,121 @@ /*************************************************************************** cconsole.h - main displaying widget This file is a part of KMuddy distribution. ------------------- begin : So Jun 22 2017 copyright : (C) 2002-2017 by Tomas Mecir email : mecirt@gmail.com ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #ifndef CCONSOLE_H #define CCONSOLE_H #define TRANSCRIPT_PLAIN 2 #define TRANSCRIPT_ANSI 3 #define TRANSCRIPT_HTML 1 #include #include #include #include #include class cTextChunk; //maximum cache size #define MAXCACHE 50 /** Main console - displays output of the MUD server... This is a new version of the displaying widget, replacing the old QTableView-based widget. */ class KMUDDY_EXPORT cConsole : public QGraphicsView { Q_OBJECT public: cConsole(QWidget *parent = Q_NULLPTR); ~cConsole(); void setSession (int s); /** set font */ void setFont (QFont f); /** get currently used font */ QFont font (); void setDefaultBkColor (QColor color); QColor defaultBkColor (); void setIndentation (int val); void setEnableBlinking (bool value); /** return current number of rows */ int curRows(); /** return current number of columns */ int curCols(); + /** Is the scroll text visible? */ + void setScrollTextVisible (bool vis); /** Size of the secondary console shown while scrolling */ void setScrollTextSize (int aconsize); /** number of lines until a forced repaint */ void setRepaintCount (int val); /** forces amission of dimensionsChanged signal; used by toolbar hiding functions, where this fails for unknown reasons */ void forceEmitSize (); /** dump all history buffer to that file */ void dumpBuffer (bool fromcurrent, QFile &file, char dumpType); void tryUpdateHistorySize (); void setInitialHistorySize (int size); QStringList words (QString prefix, int minLength = 3); /** clear the widget */ void clear (); /** adds line to the widget */ void addLine (cTextChunk *chunk); /** as addLine, but does not end line */ void addText (cTextChunk *chunk); /** ensure that our current position is at beginning of a line */ void forceBeginOfLine (); /** expire all links with a given name, or all named links if no name given */ void expireNamedLinks (const QString &name = QString()); public slots: /** adds selection to clipboard (adding to mouse selection buffer is done automatically) */ void addSelectionToClipboard (QClipboard::Mode clipboardMode); /** shifting it around (SHIFT+keys) */ void lineUp (); void lineDown (); void pageUp (); void pageDown (); signals: void dimensionsChanged (int cols, int rows); void sendCommand (const QString &command); void promptCommand (const QString &command); protected: void resizeEvent (QResizeEvent *e) override; /** called when resizing and when changing font */ void fixupOutput (); void addNewText (cTextChunk *chunk, bool endTheLine); class Private; Private *d; }; #endif diff --git a/libs/coutput.cpp b/libs/coutput.cpp index 05a20c1..9fde6c3 100644 --- a/libs/coutput.cpp +++ b/libs/coutput.cpp @@ -1,270 +1,276 @@ // // C++ Implementation: cOutput // // Description: the cOutput class // /* Copyright 2005-2011 Tomas Mecir 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "coutput.h" #include "cglobalsettings.h" #include "cconsole.h" #include "cprofilesettings.h" #include "ctextchunk.h" #include #include #include #include cOutput::cOutput (int sess, QWidget *parent) : cActionBase ("output", sess) { con = new cConsole (parent); setWidget (con); con->setSession (sess); echocolor = Qt::yellow; systemcolor = Qt::cyan; bgcolor = Qt::black; // enable vertical scrollbar, disable the other one setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOn); // connect cConsole to us ... connect (con, SIGNAL (dimensionsChanged (int, int)), this, SLOT (dimensionsChanged (int, int))); connect (con, SIGNAL (sendCommand (const QString &)), this, SLOT (sendCommand (const QString &))); connect (con, SIGNAL (promptCommand (const QString &)), this, SLOT (promptCommand (const QString &))); //and connect() slider so that aconsole is shown/hidden as needed - connect (verticalScrollBar (), SIGNAL (sliderMoved (int)), con, SLOT (sliderChanged (int))); - connect (verticalScrollBar (), SIGNAL (valueChanged (int)), con, SLOT (sliderChanged (int))); + connect (verticalScrollBar (), SIGNAL (sliderMoved (int)), this, SLOT (sliderChanged (int))); + connect (verticalScrollBar (), SIGNAL (valueChanged (int)), this, SLOT (sliderChanged (int))); // react on events addEventHandler ("display-line", 20, PT_TEXTCHUNK); addEventHandler ("display-prompt", 20, PT_TEXTCHUNK); addEventHandler ("command-sent", 50, PT_STRING); addEventHandler ("message", 50, PT_STRING); addEventHandler ("user-message", 50, PT_STRING); addGlobalEventHandler ("global-settings-changed", 50, PT_NOTHING); aconsize = 25; con->setScrollTextSize (aconsize); } cOutput::~cOutput () { removeEventHandler ("display-line"); removeEventHandler ("display-prompt"); removeEventHandler ("display-sent"); removeEventHandler ("message"); removeEventHandler ("user-message"); removeGlobalEventHandler ("global-settings-changed"); } void cOutput::eventNothingHandler (QString event, int /*session*/) { if (event == "global-settings-changed") { cGlobalSettings *gs = cGlobalSettings::self(); con->setInitialHistorySize (gs->getInt ("history-size")); con->setFont (gs->getFont ("console-font")); setEchoColor (gs->getColor ("color-" + QString::number (gs->getInt ("echo-color")))); setSystemColor (gs->getColor ("color-" + QString::number (gs->getInt ("system-color")))); setEnableEcho (gs->getBool ("command-echo")); setEnableMessages (gs->getBool ("show-messages")); con->setEnableBlinking (gs->getBool ("allow-blink")); con->setIndentation (gs->getInt ("indent")); con->setRepaintCount (gs->getInt ("force-redraw")); //changing font often causes view to move - move to the very bottom verticalScrollBar()->setValue (verticalScrollBar()->maximum()); con->tryUpdateHistorySize (); } } void cOutput::eventStringHandler (QString event, int, QString &par1, const QString &) { if (event == "command-sent") { if (cmdecho) addCommand (par1); } else if (event == "message") { if (messages) //only if messages are enabled systemMessage (par1); } else if (event == "user-message") { systemMessage (par1); } } void cOutput::eventChunkHandler (QString event, int, cTextChunk *chunk) { if (event == "display-line") addLine (chunk); if (event == "display-prompt") addText (chunk); } void cOutput::dimensionsChanged (int x, int y) { invokeEvent ("dimensions-changed", sess(), x, y); } +void cOutput::sliderChanged (int val) +{ + int maxval = verticalScrollBar()->maximum (); + bool vis = (val < maxval); + con->setScrollTextVisible (vis); +} + void cOutput::sendCommand (const QString &command) { // we send the command directly, with no parsing, because these commands // are coming from the server, and we want to keep some security ... invokeEvent ("send-command", sess(), command); } void cOutput::promptCommand (const QString &command) { callAction ("inputline", "set-text", sess(), command); } void cOutput::setDefaultBkColor (QColor color) { bgcolor = color; con->setDefaultBkColor (color); - aconsole->setDefaultBkColor (color); } void cOutput::setEchoColor (QColor color) { echocolor = color; } void cOutput::setSystemColor (QColor color) { systemcolor = color; } void cOutput::getAllColors (QColor &_echo, QColor &_system) //this is used by cTranscript class to determine correct colors for command output { _echo = echocolor; _system = systemcolor; } void cOutput::setEnableEcho (bool value) { cmdecho = value; } void cOutput::setEnableMessages (bool value) { messages = value; } void cOutput::addText (cTextChunk *chunk) { cProfileSettings *sett = settings (); //prompt displayed if enabled in profile prefs, or if it's a quick-connection if ((!sett) || sett->getBool ("prompt-console")) { con->addText (chunk); invokeEvent ("displayed-prompt", sess(), chunk); } } void cOutput::addLine (cTextChunk *chunk) { con->addLine (chunk); invokeEvent ("displayed-line", sess(), chunk); } void cOutput::addCommand (const QString &text) //addText plus some colouring... { //IMPORTANT: the signal emitted here is also captured by session transcript //so, if you disable cmd echo here, it won't work with session //transcript!!! cTextChunk *chunk = cTextChunk::makeLine (text, echocolor, bgcolor, con); addLine (chunk); delete chunk; } void cOutput::systemMessage (const QString &text) //addText plus some colouring... { con->forceBeginOfLine (); cTextChunk *chunk = cTextChunk::makeLine (text, systemcolor, bgcolor, con); addLine (chunk); delete chunk; } void cOutput::decisionMessage (const QString &text) //addText plus some colouring... { con->forceBeginOfLine (); cTextChunk *chunk = cTextChunk::makeLine (text, systemcolor, bgcolor, con); addLine (chunk); delete chunk; } void cOutput::makeDecision () { QString ss; //generate a random number in 0..9 range int which = KRandom::random() % 10; switch (which) { case 0: ss = i18n ("No, no, no!"); break; case 1: ss = i18n ("I don't agree with it."); break; case 2: ss = i18n ("Better not."); break; case 3: ss = i18n ("I'd probably suggest to reject."); break; case 4: ss = i18n ("Saying no seems a bit better."); break; case 5: ss = i18n ("Saying yes seems a bit better."); break; case 6: ss = i18n ("I'd probably suggest to accept."); break; case 7: ss = i18n ("Sounds good."); break; case 8: ss = i18n ("I agree with it."); break; case 9: ss = i18n ("Definitely yes!"); break; }; QString s = i18n ("My decision: %1", ss); //now display that decision decisionMessage (s); } void cOutput::aconUp () { //85% is max size if (aconsize > 80) return; aconsize += 5; con->setScrollTextSize (aconsize); } void cOutput::aconDown () { //5% is min size if (aconsize < 10) return; aconsize -= 5; con->setScrollTextSize (aconsize); } diff --git a/libs/coutput.h b/libs/coutput.h index 728880d..bab9531 100644 --- a/libs/coutput.h +++ b/libs/coutput.h @@ -1,107 +1,104 @@ // // C++ Interface: cOutput // // Description: wrapper for cConsole // /* Copyright 2005-2011 Tomas Mecir 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef COUTPUT_H #define COUTPUT_H #include #include #include #include class cConsole; /** This class serves as a wrapper for the main cConsole widget. It translates its signal-slot mechanism to the cAction-based approach. This is necessary, because cConsole is used in other places as well. It also handles scrollbars. @author Tomas Mecir */ class KMUDDY_EXPORT cOutput : public QScrollArea, public cActionBase { Q_OBJECT public: /** constructor */ cOutput (int sess, QWidget *parent); /** destructor */ ~cOutput(); cConsole *console () { return con; }; void addText (cTextChunk *chunk); void addLine (cTextChunk *chunk); /** add command to console, if allowed */ void addCommand (const QString &command); /** adds a new system message to the widget - calls addText and also does some extra things*/ void systemMessage (const QString &text); /** decision message (Tools/Decide). The same as systemMessage, but it is shown even if system messages are off*/ void decisionMessage (const QString &text); /** this is my decision helper similar to one found in zmud */ void makeDecision (); void setDefaultBkColor (QColor color); QColor defaultBkColor () { return bgcolor; }; /** change color of local echo (typed commands etc.) */ void setEchoColor (QColor color); /** change color of system messages */ void setSystemColor (QColor color); /** this function returns all the colors - well, actually, only echo and system color... */ void getAllColors (QColor &_echo, QColor &_system); void setEnableEcho (bool value); void setEnableMessages (bool value); /** resizing aconsole (CTRL+keys) */ void aconUp (); void aconDown (); protected slots: void dimensionsChanged (int x, int y); void sendCommand (const QString &command); void promptCommand (const QString &command); + void sliderChanged (int); protected: virtual void eventStringHandler (QString event, int, QString &par1, const QString &) override; virtual void eventChunkHandler (QString event, int, cTextChunk *chunk) override; virtual void eventNothingHandler (QString event, int session) override; /** show commands / messages ? */ bool cmdecho, messages; QColor echocolor; QColor systemcolor; //default bg color QColor bgcolor; /** stored cConsole widget */ cConsole *con; - /** our auxiliary console */ - cConsole *aconsole; - /** is the auxiliary console visible? */ - bool aconvisible; /** size of auxiliary console (in percents) */ int aconsize; }; #endif