View Single Post
sakya's Avatar
Posts: 533 | Thanked: 1,341 times | Joined on Dec 2010 @ Italy
#437
Originally Posted by Scorpius View Post
I think I found a nice way and it renders fast, but there's still a lot to be done.
Maybe you solved it but what's the problem with replace the smiley's text with html code (for the input box)?
For the history you can do the same thing with a QLabel (which has the linkActivated slot)

Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    m_IgnoreChange = false;
    connect(ui->textEdit, SIGNAL(textChanged()), this, SLOT(textChangedSlot()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::textChangedSlot()
{
    if (m_IgnoreChange)
        return;

    QTextCursor cursor = ui->textEdit->textCursor();
    m_IgnoreChange = true;
    QString text = ui->textEdit->toHtml();

    //Here using regexp probably is better ;)
    text = text.replace(":)", "<img src=\"c:/Users/paolo/smiley/images/smile_1.png\"/>");
    text = text.replace(":-)", "<img src=\"c:/Users/paolo/smiley/images/smile_1.png\"/>");

    text = text.replace(";)", "<img src=\"c:/Users/paolo/smiley/images/ok.png\"/>");
    text = text.replace(";-)", "<img src=\"c:/Users/paolo/smiley/images/ok.png\"/>");

    text = text.replace(":D", "<img src=\"c:/Users/paolo/smiley/images/smile_7.png\"/>");
    text = text.replace(":-D", "<img src=\"c:/Users/paolo/smiley/images/smile_7.png\"/>");

    ui->textEdit->setHtml(text);
    ui->textEdit->setTextCursor(cursor);
    ui->textEdit->ensureCursorVisible();
    m_IgnoreChange = false;
}
 

The Following User Says Thank You to sakya For This Useful Post: