Beim Start mit der größe Minimumsize(noch ok):
https://dl.dropbox.com/u/56040841/gui%20anfang.png
Maximiert (nicht mehr ok warum Expandiert QWebView stärker als QTextEdit?):
https://dl.dropbox.com/u/56040841/gui.png
TextHTML.h
Code: Alles auswählen
#ifndef TEXTHTML_H
#define TEXTHTML_H
#include <QtGui>
#include <QtWebKit>
class TextHTML : public QWidget
{
Q_OBJECT
public:
//(De/Kon)struktor
TextHTML();
~TextHTML(){}
// Gui Stuffz
QLabel* htmlLabel;
QLabel* htmlIcon;
QLabel* codeLabel;
QLabel* codeIcon;
QPixmap* htmlIconPixmap;
QPixmap* codeIconPixmap;
QPushButton* preview;
QGroupBox* mainGroupBox;
QTextEdit* codeTextfeld;
QGridLayout* mainGrid;
QVBoxLayout* vBox;
QWebView* htmlView;
QUrl base;
//Methoden
QString getHtmlCode();
void setHtmlCode(QString);
void setBaseUrl(const QUrl &url);
public slots:
void updateHtml();
void updateText();
void searchText();
void toolbarSearch(QString);
void hideCode(bool);
void hideHtml(bool);
};
#endif // TEXTHTML_H
Code: Alles auswählen
#include "TextHTML.h"
#include "advSearch.h"
TextHTML::TextHTML()
{
/*
QLabel initialisierungen
*/
codeLabel = new QLabel("HTML code: ");
htmlLabel = new QLabel("HTML view: ");
htmlIcon = new QLabel();
codeIcon = new QLabel();
preview = new QPushButton("&Preview");
preview->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
/*
Initialisierungen der Iconpixmaps und adden in ein Label
*/
htmlIconPixmap = new QPixmap(QString("%1%2")
.arg(QCoreApplication::applicationDirPath())
.arg("/icons/html.png") );
codeIconPixmap = new QPixmap(QString("%1%2")
.arg(QCoreApplication::applicationDirPath())
.arg("/icons/code.png") );
htmlIcon->setScaledContents(true);
htmlIcon->setPixmap(*htmlIconPixmap);
htmlIcon->setMask( htmlIconPixmap->mask() );
htmlIcon->setFixedSize(45,45);
codeIcon->setScaledContents(true);
codeIcon->setPixmap(*codeIconPixmap);
codeIcon->setMask( codeIconPixmap->mask() );
codeIcon->setFixedSize(45,45);
codeTextfeld = new QTextEdit;
htmlView = new QWebView(this);
codeLabel->setFixedSize(75,45);
htmlLabel->setFixedSize(75,45);
htmlView->setMinimumSize(300,300);
codeTextfeld->setMinimumSize(300,300);
mainGroupBox = new QGroupBox("Text to HTML");
mainGrid = new QGridLayout;
mainGrid->addWidget(codeIcon ,0,0, Qt::AlignTop | Qt::AlignLeft);
mainGrid->addWidget(codeLabel ,0,1, Qt::AlignTop | Qt::AlignLeft);
mainGrid->addWidget(codeTextfeld,0,2);
mainGrid->addWidget(preview ,1,2);
mainGrid->addWidget(htmlIcon ,0,4, Qt::AlignTop | Qt::AlignLeft);
mainGrid->addWidget(htmlLabel ,0,5, Qt::AlignTop | Qt::AlignLeft);
mainGrid->addWidget(htmlView ,0,6,2,1);
mainGroupBox->setLayout(mainGrid);
vBox = new QVBoxLayout;
vBox->addWidget(mainGroupBox);
setLayout(vBox);
connect( preview, SIGNAL(clicked()), this, SLOT(updateHtml()) );
connect( htmlView, SIGNAL(loadFinished(bool)), this, SLOT(updateText()) );
}
void TextHTML::updateHtml(){
QString htmlCode = codeTextfeld->toPlainText();
htmlView->setHtml(htmlCode,base);
}
void TextHTML::updateText(){
QWebFrame *mainFrame = htmlView->page()->mainFrame();
QString frameText = mainFrame->toHtml();
setHtmlCode(frameText);
}
QString TextHTML::getHtmlCode(){
return codeTextfeld->toPlainText();
}
void TextHTML::setHtmlCode(QString code){
codeTextfeld->setPlainText(code);
}
void TextHTML::searchText(){
AdvSearch* searchDialog = new AdvSearch(this);
searchDialog->exec();
QString tmp = searchDialog->getString();
QTextDocument::FindFlags flags = searchDialog->getSearchFlags();
QTextCursor tc(codeTextfeld->textCursor());
tc.movePosition(QTextCursor::Start);
codeTextfeld->setTextCursor(tc);
codeTextfeld->find(tmp,flags);
}
void TextHTML::toolbarSearch(QString str){
QTextCursor tc(codeTextfeld->textCursor());
tc.movePosition(QTextCursor::Start);
codeTextfeld->setTextCursor(tc);
codeTextfeld->find(str);
}
void TextHTML::hideCode(bool flag){
if(!flag){
codeIcon->hide();
codeLabel->hide();
codeTextfeld->hide();
preview->hide();
}
else {
codeIcon->show();
codeLabel->show();
codeTextfeld->show();
preview->show();
}
}
void TextHTML::hideHtml(bool flag){
if(!flag){
htmlIcon->hide();
htmlLabel->hide();
htmlView->hide();
}
else {
htmlIcon->show();
htmlLabel->show();
htmlView->show();
}
}
void TextHTML::setBaseUrl(const QUrl &url){
base = url;
}