Esempio n. 1
0
void OutputWidget::addLine( const QColor& color, const QString& string )
{
	moveCursor( QTextCursor::End );
	insertHtml( QString( "<span style=\"color:%1;\">[%2] %3</span>" ).arg( color.name() ).arg( QTime::currentTime().toString() ).arg( string ) );
	insertPlainText( "\n" );
	verticalScrollBar()->setValue( verticalScrollBar()->maximum() );
}
Esempio n. 2
0
        void ConsoleText::writeError(std::string const& message)
        {
            std::stringstream sstream;
            sstream << "<font color=\"#DD0000\"> " << message << "</font><br>";

            insertHtml(tr(sstream.str().c_str()));
        }
Esempio n. 3
0
void TabTerminal::_insertPrompt()
{
	QTextCursor cursor = textCursor();
	cursor.insertBlock();
	insertHtml(_userPrompt);
	ensureCursorVisible();
}
Esempio n. 4
0
void MimeTextEdit::pasteOwnCertificateLink()
{
	RetroShareLink link;
	std::string ownId = rsPeers->getOwnId();

	if (link.createCertificate(ownId)) {
		insertHtml(link.toHtml() + " ");
	}
}
Esempio n. 5
0
void KTextCursor::insertHtml( const QString &text, const QMap<QString, QString>& imgs )
{
	if(!imgs.isEmpty())
	{
		for(QMap<QString,QString>::const_iterator iter = imgs.begin(); iter != imgs.end(); iter++)
		{
			QString key = iter.key();
			QString file = iter.value();
			if(moviePool()->insertMovie(file, file))
			{
				//修改属性为动画。
				document()->addResource(QTextDocument::ImageResource, QUrl(file), moviePool()->currentImage(file));
			}
			else
			{
				QImage image(file);
				if(!image.isNull())
				{
					document()->addResource(QTextDocument::ImageResource, QUrl(file), image);
				}
			}
		}
	}

	int istart = position();
	insertHtml(text);
	int inow = position();

	if(!imgs.isEmpty() && inow > istart)
	{
		setPosition(istart);
		movePosition(NextCharacter, KeepAnchor, inow-istart);
		QString txt = selectedText();
		int index = txt.indexOf(QChar::ObjectReplacementCharacter, 0);
		while(index >= 0)
		{
			/*修改字体类型。*/
			setPosition(istart+index);
			movePosition(NextCharacter, KeepAnchor, 1);
			QTextCharFormat fmt = charFormat();			
			QTextImageFormat imgFmt = fmt.toImageFormat();
			QString key = imgFmt.name();
			if(imgs.contains(key))
			{
				imgFmt.setProperty(KImageKey, key);
				imgFmt.setName(imgs.value(key));
				imgFmt.setProperty(KAnimationImage, true);
				setCharFormat(imgFmt);
			}
			int idx = index+1;
			index = txt.indexOf(QChar::ObjectReplacementCharacter, idx);
		}
	}

	setPosition(inow);
}
Esempio n. 6
0
void DictionaryTextEdit::insertFromMimeData(const QMimeData * source)
{
    if (source->hasHtml())
    {
        QString str = source->html();
        insertHtml(htmlModifier.normalizeHtml(str));
    }
    else
        QTextEdit::insertFromMimeData(source);    
}
Esempio n. 7
0
void TabTerminal::_handleHistoryUp()
{
	if(0 < _historyUp.count()) {
		QString cmd = _historyUp.pop();
		_historyDown.push(cmd);
		_clearLine();
		insertHtml(cmd);
	}

	_historySkip = true;
}
void TextWindow::addMessage(const QString &login, const QString &msg)
{
	QString newText = Qt::escape(msg);
	
	newText = newText.replace(":)", QString("<img src=\"")+THEME_DIR+"/chat/smile.png" +"\" />");
	newText = newText.replace(":(", QString("<img src=\"")+THEME_DIR+"/chat/sad.png" +"\" />");
	newText = newText.replace("xD", QString("<img src=\"")+THEME_DIR+"/chat/laugh.png" +"\" />");
	newText.remove('\n');
	
	append("<"+login+"> ");
	insertHtml(newText+'\n');
}
Esempio n. 9
0
TabTerminal::TabTerminal(QWidget * parent) :
	QTextEdit(parent),
	_userPrompt(QString("<span style=\"color: #00FF00;\">sand6$</span> ")),
	_locked(false),
	_historySkip(false)
{
	document()->setMaximumBlockCount(1000);
	setStyleSheet("color: #ddd; background: black;");
	QFont font("Monospace");
	font.setFamily("Terminus");
	font.setStyleHint(QFont::TypeWriter);
	//font.setPointSize(12);
	setFont(font);
	QFontMetrics fm(font);
	setCursorWidth(fm.averageCharWidth());
	_historyUp.clear();
	_historyDown.clear();
	setLineWrapMode(WidgetWidth);
	insertHtml("<span style=\"color: #996600;\">*** Welcome to puzzleSEQ Terminal ***</span><br>");
	insertHtml(_userPrompt);
}
Esempio n. 10
0
MainWindow::MainWindow(QStringList args)
{
    _simProject = new SimProject(this);

    _logWidget = new QTextEdit();
    _logWidget->setReadOnly(true);
    setCentralWidget(_logWidget);
    createMenus();

    connect(SimServer::instance(), SIGNAL(clientAdded(SimClient *)), this, SLOT(setClient(SimClient *)));
    connect(_simProject, SIGNAL(logAppended(QString)), _logWidget, SLOT(insertHtml(QString)));

    if (args.size()>1)
        openProject(args[1]);
}
Esempio n. 11
0
DiagnosticsDialog::DiagnosticsDialog( QWidget *parent )
:	QDialog( parent )
{
	QApplication::setOverrideCursor( Qt::WaitCursor );
	setupUi( this );
	setAttribute( Qt::WA_DeleteOnClose, true );

	worker = new Diagnostics();
	connect( worker, SIGNAL(update(QString)), diagnosticsText, SLOT(insertHtml(QString)), Qt::QueuedConnection );
#ifdef Q_OS_LINUX
	worker->run();
#else
	worker->start();
#endif
}
Esempio n. 12
0
void TabTerminal::_handleHistoryDown()
{
	if(0 < _historyDown.count() && _historySkip) {
		_historyUp.push(_historyDown.pop());
		_historySkip = false;
	}

	if(0 < _historyDown.count()) {
		QString cmd = _historyDown.pop();
		_historyUp.push(cmd);

		_clearLine();
		insertHtml(cmd);
	} else {
		_clearLine();
	}
}
Esempio n. 13
0
void TabTerminal::_handleEnter()
{
	QString cmd = _getCommand();

	if(0 < cmd.length()) {
		while(_historyDown.count() > 0) {
			_historyUp.push(_historyDown.pop());
		}

		_historyUp.push(cmd);
	}

	_moveToEndOfLine();

	if(!cmd.isEmpty()) { // instead of: cmp.length() > 0
		_locked = true;
		setFocus();
		insertHtml("<br>");
		emit command(cmd);
	} else {
		_insertPrompt();
	}
}
Esempio n. 14
0
HtmlEditor::HtmlEditor(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui_MainWindow)
        , sourceDirty(true)
        , highlighter(0)
        , ui_dialog(0)
        , insertHtmlDialog(0)
{
    ui->setupUi(this);
    ui->tabWidget->setTabText(0, "Normal View");
    ui->tabWidget->setTabText(1, "HTML Source");
    connect(ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(changeTab(int)));
    resize(600, 600);

    highlighter = new Highlighter(ui->plainTextEdit->document());

    QWidget *spacer = new QWidget(this);
    spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
    ui->standardToolBar->insertWidget(ui->actionZoomOut, spacer);

    zoomLabel = new QLabel;
    ui->standardToolBar->insertWidget(ui->actionZoomOut, zoomLabel);

    zoomSlider = new QSlider(this);
    zoomSlider->setOrientation(Qt::Horizontal);
    zoomSlider->setMaximumWidth(150);
    zoomSlider->setRange(25, 400);
    zoomSlider->setSingleStep(25);
    zoomSlider->setPageStep(100);
    connect(zoomSlider, SIGNAL(valueChanged(int)), SLOT(changeZoom(int)));
    ui->standardToolBar->insertWidget(ui->actionZoomIn, zoomSlider);

    connect(ui->actionFileNew, SIGNAL(triggered()), SLOT(fileNew()));
    connect(ui->actionFileOpen, SIGNAL(triggered()), SLOT(fileOpen()));
    connect(ui->actionFileSave, SIGNAL(triggered()), SLOT(fileSave()));
    connect(ui->actionFileSaveAs, SIGNAL(triggered()), SLOT(fileSaveAs()));
    connect(ui->actionExit, SIGNAL(triggered()), SLOT(close()));
    connect(ui->actionInsertImage, SIGNAL(triggered()), SLOT(insertImage()));
    connect(ui->actionCreateLink, SIGNAL(triggered()), SLOT(createLink()));
    connect(ui->actionInsertHtml, SIGNAL(triggered()), SLOT(insertHtml()));
    connect(ui->actionZoomOut, SIGNAL(triggered()), SLOT(zoomOut()));
    connect(ui->actionZoomIn, SIGNAL(triggered()), SLOT(zoomIn()));

    // these are forward to internal QWebView
    FORWARD_ACTION(ui->actionEditUndo, QWebPage::Undo);
    FORWARD_ACTION(ui->actionEditRedo, QWebPage::Redo);
    FORWARD_ACTION(ui->actionEditCut, QWebPage::Cut);
    FORWARD_ACTION(ui->actionEditCopy, QWebPage::Copy);
    FORWARD_ACTION(ui->actionEditPaste, QWebPage::Paste);
    FORWARD_ACTION(ui->actionFormatBold, QWebPage::ToggleBold);
    FORWARD_ACTION(ui->actionFormatItalic, QWebPage::ToggleItalic);
    FORWARD_ACTION(ui->actionFormatUnderline, QWebPage::ToggleUnderline);

    // Qt 4.5.0 has a bug: always returns 0 for QWebPage::SelectAll
    connect(ui->actionEditSelectAll, SIGNAL(triggered()), SLOT(editSelectAll()));

    connect(ui->actionStyleParagraph, SIGNAL(triggered()), SLOT(styleParagraph()));
    connect(ui->actionStyleHeading1, SIGNAL(triggered()), SLOT(styleHeading1()));
    connect(ui->actionStyleHeading2, SIGNAL(triggered()), SLOT(styleHeading2()));
    connect(ui->actionStyleHeading3, SIGNAL(triggered()), SLOT(styleHeading3()));
    connect(ui->actionStyleHeading4, SIGNAL(triggered()), SLOT(styleHeading4()));
    connect(ui->actionStyleHeading5, SIGNAL(triggered()), SLOT(styleHeading5()));
    connect(ui->actionStyleHeading6, SIGNAL(triggered()), SLOT(styleHeading6()));
    connect(ui->actionStylePreformatted, SIGNAL(triggered()), SLOT(stylePreformatted()));
    connect(ui->actionStyleAddress, SIGNAL(triggered()), SLOT(styleAddress()));
    connect(ui->actionFormatFontName, SIGNAL(triggered()), SLOT(formatFontName()));
    connect(ui->actionFormatFontSize, SIGNAL(triggered()), SLOT(formatFontSize()));
     connect(ui->actionFormatTextColor, SIGNAL(triggered()), SLOT(formatTextColor()));
    connect(ui->actionFormatBackgroundColor, SIGNAL(triggered()), SLOT(formatBackgroundColor()));

    // no page action exists yet for these, so use execCommand trick
    connect(ui->actionFormatStrikethrough, SIGNAL(triggered()), SLOT(formatStrikeThrough()));
    connect(ui->actionFormatAlignLeft, SIGNAL(triggered()), SLOT(formatAlignLeft()));
    connect(ui->actionFormatAlignCenter, SIGNAL(triggered()), SLOT(formatAlignCenter()));
    connect(ui->actionFormatAlignRight, SIGNAL(triggered()), SLOT(formatAlignRight()));
    connect(ui->actionFormatAlignJustify, SIGNAL(triggered()), SLOT(formatAlignJustify()));
    connect(ui->actionFormatDecreaseIndent, SIGNAL(triggered()), SLOT(formatDecreaseIndent()));
    connect(ui->actionFormatIncreaseIndent, SIGNAL(triggered()), SLOT(formatIncreaseIndent()));
    connect(ui->actionFormatNumberedList, SIGNAL(triggered()), SLOT(formatNumberedList()));
    connect(ui->actionFormatBulletedList, SIGNAL(triggered()), SLOT(formatBulletedList()));


    // necessary to sync our actions
    connect(ui->webView->page(), SIGNAL(selectionChanged()), SLOT(adjustActions()));

    connect(ui->webView->page(), SIGNAL(contentsChanged()), SLOT(adjustSource()));
    ui->webView->setFocus();

    setCurrentFileName(QString());

    QString initialFile = ":/example.html";
    const QStringList args = QCoreApplication::arguments();
    if (args.count() == 2)
        initialFile = args.at(1);

    if (!load(initialFile))
        fileNew();

    adjustActions();
    adjustSource();
    setWindowModified(false);
    changeZoom(100);
}
Esempio n. 15
0
void MimeTextEdit::pasteLink()
{
	insertHtml(RSLinkClipboard::toHtml()) ;
}
void MAutocompleteWidget::addText(const QString &text) {
    insertHtml(text);
    QFontMetrics fontMetric(currentFont());
    int height = fontMetric.height()*(toPlainText().count("\n")+3);
    setMaximumHeight(height);
}
Esempio n. 17
0
void TabTerminal::append(const QString & text)
{
	insertHtml(text);
	ensureCursorVisible();
}
Esempio n. 18
0
void RichTextHtmlEdit::insertFromMimeData(const QMimeData *source) {
	QString uri;
	QString title;
	QRegExp newline(QLatin1String("[\\r\\n]"));

#ifndef QT_NO_DEBUG
	qWarning() << "RichTextHtmlEdit::insertFromMimeData" << source->formats();
	foreach(const QString &format, source->formats())
		qWarning() << format << decodeMimeString(source->data(format));
#endif

	if (source->hasImage()) {
		QImage img = qvariant_cast<QImage>(source->imageData());
		QString html = Log::imageToImg(img);
		if (! html.isEmpty())
			insertHtml(html);
		return;
	}

	QString mozurl = decodeMimeString(source->data(QLatin1String("text/x-moz-url")));
	if (! mozurl.isEmpty()) {
		QStringList lines = mozurl.split(newline);
		qWarning() << mozurl << lines;
		if (lines.count() >= 2) {
			uri = lines.at(0);
			title = lines.at(1);
		}
	}

	if (uri.isEmpty())
		uri = decodeMimeString(source->data(QLatin1String("text/x-moz-url-data")));
	if (title.isEmpty())
		title = decodeMimeString(source->data(QLatin1String("text/x-moz-url-desc")));

	if (uri.isEmpty()) {
		QStringList urls;
#ifdef Q_OS_WIN
		urls = decodeMimeString(source->data(QLatin1String("application/x-qt-windows-mime;value=\"UniformResourceLocatorW\""))).split(newline);
		if (urls.isEmpty())
#endif
			urls = decodeMimeString(source->data(QLatin1String("text/uri-list"))).split(newline);
		if (! urls.isEmpty())
			uri = urls.at(0);
		uri = urls.at(0).trimmed();
	}

	if (uri.isEmpty()) {
		QUrl url(source->text(), QUrl::StrictMode);
		if (url.isValid() && ! url.isRelative()) {
			uri = url.toString();
		}
	}

#ifdef Q_OS_WIN
	if (title.isEmpty() && source->hasFormat(QLatin1String("application/x-qt-windows-mime;value=\"FileGroupDescriptorW\""))) {
		QByteArray qba = source->data(QLatin1String("application/x-qt-windows-mime;value=\"FileGroupDescriptorW\""));
		if (qba.length() == sizeof(FILEGROUPDESCRIPTORW)) {
			const FILEGROUPDESCRIPTORW *ptr = reinterpret_cast<const FILEGROUPDESCRIPTORW *>(qba.constData());
			title = QString::fromUtf16(ptr->fgd[0].cFileName);
			if (title.endsWith(QLatin1String(".url"), Qt::CaseInsensitive))
				title = title.left(title.length() - 4);
		}
	}
#endif

	if (! uri.isEmpty()) {
		if (title.isEmpty())
			title = uri;
		uri = Qt::escape(uri);
		title = Qt::escape(title);

		insertHtml(QString::fromLatin1("<a href=\"%1\">%2</a>").arg(uri, title));
		return;
	}

	QString html = decodeMimeString(source->data(QLatin1String("text/html")));
	if (! html.isEmpty()) {
		insertHtml(html);
		return;
	}

	QTextEdit::insertFromMimeData(source);
}
Esempio n. 19
0
void MessageWidget::print(
    const QtMsgType type
    ,   const QMessageLogContext & context
    ,   const QDateTime & timestamp
    ,   const QString & message)
{
#ifdef _NDEBUG
    const QString t(timestamp.toString("hh:mm:ss"));
#else
    const QString t(timestamp.toString("hh:mm:ss:zzz"));
#endif
    //const QString timestamp(entry.timestamp().toString("hh:mm:ss"));

    QString html;
    switch (type)
    {
    case QtMsgType::QtDebugMsg:
#ifdef _DEBUG
        html = QString("%1 %2(%3): %4\n").arg(t).arg(context.file).arg(context.line).arg(message);
#else
        html = QString("%1: %2").arg(t).arg(message);
#endif
        break;

    case QtMsgType::QtCriticalMsg:
    case QtMsgType::QtFatalMsg:
    case QtMsgType::QtWarningMsg:
        html = QString("%1: %2").arg(t).arg(message);
        break;

    default:
        break;
    };

    if (m_detectLinks)
    {
        QRegExp reHttp("\\b(?:(?:https?|ftp):\\/\\/(\\/)?|www\\.|ftp\\.)[-\\w\\+&@#\\/%=~|\\$?!:,\\.]*[\\w\\+&@#/%=~_\\$]", Qt::CaseInsensitive);
        QRegExp reFile("\\b(?:(?:file):\\/\\/(\\/)?){1,1}[-\\w\\+&@#\\/%=~|\\$?!:,\\.]*[\\w\\+&@#\\/%=~_\\$]", Qt::CaseInsensitive);
        QRegExp reMail("\\b(?:((?:mailto:)?[\\w\\._%+-]+@[\\w\\._%-]+\\.[A-Z]{2,})\\b)", Qt::CaseInsensitive);

        assert(reHttp.isValid());
        assert(reFile.isValid());
        assert(reMail.isValid());

        int pos = 0;
        while ((pos = reHttp.indexIn(message, pos)) != -1)
        {
            pos += reHttp.matchedLength();
            const QString uri = reHttp.capturedTexts()[0];
            html.replace(uri, QString("<a href =\"%1\">%1</a>").arg(uri));
        }

        pos = 0;
        while ((pos = reFile.indexIn(message, pos)) != -1)
        {
            pos += reFile.matchedLength();
            const QString uri = reFile.capturedTexts()[0];

            QString replace(uri);
            replace.remove("file:///", Qt::CaseInsensitive);
            replace.remove("file://", Qt::CaseInsensitive);

            QFileInfo fi(replace);
            if (fi.exists())
            {
#ifdef WIN32
                html.replace(uri, QString("<a href =\"file:///%1\">%1</a>").arg(fi.absoluteFilePath()));
#else
                html.replace(uri, QString("<a href =\"file://%1\">%1</a>").arg(fi.absoluteFilePath()));
#endif
            }
        }

        pos = 0;
        while ((pos = reMail.indexIn(message, pos)) != -1)
        {
            pos += reMail.matchedLength();
            const QString uri = reMail.capturedTexts()[0];

            QString replace(uri);
            replace.remove("mailto:", Qt::CaseInsensitive);

            html.replace(uri, QString("<a href =\"mailto:%1\">%1</a>").arg(replace));
        }
    }

    if (m_detectControlCharacters)
    {
        html.replace("\n", "<br>");
        html.replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
    }

    moveCursor(QTextCursor::End);
    insertHtml("<span style=\"color:" + m_colors[type] + "\">" + html + "</span><br>");

    ensureCursorVisible();
}
Esempio n. 20
0
void TabTerminal::result(const QString & result)
{
	insertHtml(result);
	_insertPrompt();
	_locked = false;
}