#ifndef MAINWINDOWIMPL_H
#define MAINWINDOWIMPL_H
//
#include "ui_mainwindow.h"
//
class MainWindowImpl
: public QMainWindow,
public Ui
::MainWindow{
Q_OBJECT
public:
MainWindowImpl
( QWidget * parent
= 0, Qt
::WFlags f
= 0 );
public slots:
void playVMi
(const QUrl &url
);
private slots:
void returnPressed();
private:
};
#endif
#ifndef MAINWINDOWIMPL_H
#define MAINWINDOWIMPL_H
//
#include "ui_mainwindow.h"
//
class MainWindowImpl : public QMainWindow, public Ui::MainWindow
{
Q_OBJECT
public:
MainWindowImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
public slots:
void playVMi(const QUrl &url);
private slots:
void returnPressed();
private:
QString detectLinks(QString dataIn, QString urlType);
void display(QString dataIn);
};
#endif
To copy to clipboard, switch view to plain text mode
#include <QtGui>
#include <QDesktopServices>
#include "mainwindowimpl.h"
//
MainWindowImpl
::MainWindowImpl( QWidget * parent, Qt
::WFlags f
) {
setupUi(this);
connect(leInput, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
}
void MainWindowImpl::returnPressed()
{
if(leInput->text() != "")
display(leInput->text());
leInput->setText("");
}
// we registerd vm:// with the URL catcher and it sends us here when a url of this type is clicked
void MainWindowImpl
::playVMi(const QUrl &url
) {
leInput->setFocus();
// Normally there would be code here to act upon the URL in some way
}
void MainWindowImpl
::display(QString dataIn
) {
dataIn = detectLinks(dataIn, "http://");
dataIn = detectLinks(dataIn, "mailto:");
dataIn = detectLinks(dataIn, "ftp://");
dataIn = detectLinks(dataIn, "vmi://");
tbDisplay->append(dataIn);
tbDisplay->verticalScrollBar()->setValue(tbDisplay->verticalScrollBar()->maximum());
}
// Detect URL's
{
int sp[100], ep[100], y, count1, count2;
count1 = -1;
count2 = -1;
y = 0;
do // First find the link start points
{
count1++;
sp[count1] = dataIn.indexOf(urlType, y, Qt::CaseSensitive);
y = sp[count1] + 1;
}
while(sp[count1] > -1);
count1--;
if(sp[0] > -1) // if there are any start points.....
{
do // find the link end points
{
count2++;
ep[count2] = dataIn.indexOf(" ", sp[count2], Qt::CaseSensitive);
if(ep[count2] == -1) // if the link is the end of the text then the space will not be found....
ep[count2] = dataIn.size(); // ....so set the end point to the end of the text
}
while(count2 <= count1);
}
for(int x = count1; x >= 0; x--)
{
url = "\">" + dataIn.mid(sp[x], ep[x] - sp[x]) + "</a>";
dataIn.insert(ep[x], url);
dataIn.
insert(sp
[x
],
QString("<a href=\""));
}
return(dataIn);
}
#include <QtGui>
#include <QDesktopServices>
#include "mainwindowimpl.h"
//
MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f)
: QMainWindow(parent, f)
{
setupUi(this);
connect(leInput, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
QDesktopServices::setUrlHandler("vmi", this, "playVMi");
}
void MainWindowImpl::returnPressed()
{
if(leInput->text() != "")
display(leInput->text());
leInput->setText("");
}
// we registerd vm:// with the URL catcher and it sends us here when a url of this type is clicked
void MainWindowImpl::playVMi(const QUrl &url)
{
leInput->setFocus();
// Normally there would be code here to act upon the URL in some way
}
void MainWindowImpl::display(QString dataIn)
{
dataIn = detectLinks(dataIn, "http://");
dataIn = detectLinks(dataIn, "mailto:");
dataIn = detectLinks(dataIn, "ftp://");
dataIn = detectLinks(dataIn, "vmi://");
tbDisplay->append(dataIn);
tbDisplay->verticalScrollBar()->setValue(tbDisplay->verticalScrollBar()->maximum());
}
// Detect URL's
QString MainWindowImpl::detectLinks(QString dataIn, QString urlType)
{
QString url;
QString user;
QDateTime dt;
dt = QDateTime::currentDateTime();
int sp[100], ep[100], y, count1, count2;
count1 = -1;
count2 = -1;
y = 0;
do // First find the link start points
{
count1++;
sp[count1] = dataIn.indexOf(urlType, y, Qt::CaseSensitive);
y = sp[count1] + 1;
}
while(sp[count1] > -1);
count1--;
if(sp[0] > -1) // if there are any start points.....
{
do // find the link end points
{
count2++;
ep[count2] = dataIn.indexOf(" ", sp[count2], Qt::CaseSensitive);
if(ep[count2] == -1) // if the link is the end of the text then the space will not be found....
ep[count2] = dataIn.size(); // ....so set the end point to the end of the text
}
while(count2 <= count1);
}
for(int x = count1; x >= 0; x--)
{
url = "\">" + dataIn.mid(sp[x], ep[x] - sp[x]) + "</a>";
dataIn.insert(ep[x], url);
dataIn.insert(sp[x], QString("<a href=\""));
}
return(dataIn);
}
To copy to clipboard, switch view to plain text mode
Bookmarks