⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commandline.cc

📁 c++的guiQt做的开发
💻 CC
字号:
/** @file CommandLine - class representing command window (editation of command and output of previous commands)*/#include "commandline.h"#include "settings.h"#include "util.h"#include <iostream>#include <qglobal.h>#if QT_VERSION >= 0x040200#include <QCompleter>#endif#include <QTextCursor>#include <QLayout>#include <QPushButton>#include <QFile>#include <QTextEdit>#include <QLineEdit>#include <QComboBox>#include <QSizePolicy>using namespace std;using namespace util;namespace gui {/** constructor of CommandLine, creates window and fills it with elements @param parent Parent widget*/CommandLine::CommandLine(QWidget *parent/*=0*/):QWidget(parent) { QBoxLayout * hl = new QVBoxLayout( this ); out=new QTextEdit(this); cmd=new QLineEdit(this); out->setReadOnly(true); // init history history = new QComboBox(this); history->setLineEdit(cmd); history->setEditable(true); // setting sizePolicy for ignoring width hint (some history items are too large) QSizePolicy spol ( QSizePolicy::Ignored, QSizePolicy::Preferred ); history->setSizePolicy( spol ); history->setMinimumHeight( history->sizeHint().height() );// history->setInsertionPolicy( QComboBox::AtTop ); history->setInsertPolicy(QComboBox::NoInsert); history->insertItem(0,""); history->setCurrentIndex(0); history->setAutoCompletion( true ); QObject::connect(cmd, SIGNAL(returnPressed()), this, SLOT(execute())); hl->addWidget(out); hl->addWidget(history); out->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);}/** Turn on autocompletion with provided words @param words command list used for auto completion*/void CommandLine::setAutoCompleter(const QStringList &words) {#if QT_VERSION >= 0x040200 QCompleter *completer = new QCompleter(words,this); completer->setCaseSensitivity(Qt::CaseInsensitive); cmd->setCompleter(completer);#endif}/** Erase all text in the window*/void CommandLine::clearWindow() { out->setHtml("");}/** Execute and clear current command */void CommandLine::execute() { QString command=cmd->text(); history->insertItem(1,command); history->setCurrentIndex(0); history->setItemText(0,""); emit commandExecuted(command);		//execute command via signal}/** move cursor to the end of output window*/void CommandLine::moveCursorToEnd() { QTextCursor c=out->textCursor(); c.movePosition(QTextCursor::End); out->setTextCursor(c);}/** Add command executed from menu or any source to be echoed to command window @param command Command to add*/void CommandLine::addCommand(const QString &command) { moveCursorToEnd(); out->insertHtml("<b>&gt; </b>"+htmlEnt(command)+"<br>"); moveCursorToEnd(); consoleLog("> "+command,globalSettings->readExpand("path/console_log"));}/** Add string to be echoed to command window @param str String to add*/void CommandLine::addString(const QString &str) { moveCursorToEnd(); out->insertHtml(htmlEnt(str)+"<br>"); moveCursorToEnd(); consoleLog(str,globalSettings->readExpand("path/console_log"));}/** Add string in HTML format to be echoed to command window @param str String to add*/void CommandLine::addStringHtml(const QString &str) { moveCursorToEnd(); out->insertHtml(str+"<br>"); moveCursorToEnd(); consoleLog(str,globalSettings->readExpand("path/console_log"));}/** Add error message to be echoed to command window @param message Error message to add*/void CommandLine::addError(const QString &message) { moveCursorToEnd(); out->insertHtml("<font color=red>! </font>"+htmlEnt(message)+"<br>"); moveCursorToEnd(); consoleLog("! "+message,globalSettings->readExpand("path/console_log"));}/** default destructor */CommandLine::~CommandLine() {}} // namespace gui

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -