#include "qmreportwindow.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "consts.h" #include "structs.h" #include "proto.h" QmReportWindow::QmReportWindow(QWidget *parent) : QWidget(parent) { currentWebView = NULL; printPreviewDialog = new QPrintPreviewDialog(this); printPreviewDialog->setModal ( true ); connect(printPreviewDialog,SIGNAL(paintRequested(QPrinter *)), this , SLOT(printPreview(QPrinter *)) ); QVBoxLayout *verticalLayout; QLabel *label; QToolBar *tb; verticalLayout = new QVBoxLayout(this); verticalLayout->setContentsMargins(0, 0, 0, 0); tb = new QToolBar ( "Actions" ); verticalLayout->addWidget(tb); pb_original = tb->addAction ( QIcon(":/webkit/inspector/Images/reloadButtonGlyph.png"),"Home", this, SLOT(home())); pb_back = tb->addAction ( QIcon(":/trolltech/styles/commonstyle/images/left-32.png"),"Back", this, SLOT(back())); pb_forward = tb->addAction ( QIcon(":/trolltech/styles/commonstyle/images/right-32.png"),"Forward", this, SLOT(forward())); pb_print = tb->addAction ( QIcon(":/trolltech/dialogs/qprintpreviewdialog/images/print-32.png" ),"Print", this, SLOT(print())); tb->addSeparator(); label = new QLabel("Path"); tb->addWidget(label); tabPath = new QLineEdit(); tabPath->setReadOnly(true); tb->addWidget(tabPath); tabWidget = new QTabWidget(); tabWidget->setTabsClosable(true); tabWidget->setUsesScrollButtons(true); verticalLayout->addWidget(tabWidget); connect(tabWidget,SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int))); connect(tabWidget,SIGNAL(tabCloseRequested(int)), this, SLOT(deleteTab(int))); addReport(QString(filepath)+ filebase + "_index.html", "Index"); tabWidget->setCurrentIndex(0); // { // QDirIterator it(":", QDirIterator::Subdirectories); // while (it.hasNext()) // qDebug() << it.next(); // } //QWebSettings *gs = QWebSettings::globalSettings (); //gs->setFontSize(QWebSettings::DefaultFixedFontSize,16); } void QmReportWindow::addReport(const QString &report, const QString &name) { QmWebView *webView = NULL; bool adding = false; for( int index = 0; index < tabWidget->count(); index++) { if (tabWidget->tabText(index) == name) { webView = dynamic_cast(tabWidget->widget(index)); if (webView) { //qDebug("Reuse Tab:%s", qPrintable(report)); break; } } } if (webView == NULL) { webView = new QmWebView(); adding = true; } webView->setUrl(report); if ( adding ) { int tab = tabWidget->addTab(webView, name); tabChanged(tab); //qDebug("Adding(%d):%s", tab, qPrintable(report)); } } void QmReportWindow::deleteTab(int tab) { // qDebug("Delete TAB:%d", tab); tabWidget->removeTab(tab); } void QmReportWindow::tabChanged(int tab) { //qDebug("Update TAB:%d", tab); currentWebView = dynamic_cast(tabWidget->currentWidget()); bool enable = (currentWebView != NULL); pb_original->setEnabled(enable); pb_back->setEnabled(enable); pb_forward->setEnabled(enable); pb_print->setEnabled(enable); if ( enable ) { tabPath->setText(currentWebView->homeUrl); } else { tabPath->setText(""); } } void QmReportWindow::back(void) { if ( currentWebView ) { currentWebView->back(); } } void QmReportWindow::forward(void) { if ( currentWebView ) { currentWebView->forward(); } } void QmReportWindow::home(void) { if ( currentWebView ) { currentWebView->home(); } } void QmReportWindow::print(void) { if ( currentWebView ) { // printPreviewDialog->open(this,SLOT(fred())); //currentWebView->setStyleSheet("*{font 50px;}"); //currentWebView->setZoomFactor(2.0); printPreviewDialog->exec(); // QPrintDialog printDialog(this); // if (printDialog.exec() == QDialog::Accepted) { // QPrinter * printer = printDialog.printer(); // currentWebView->print(printer); // // print ... // } } } void QmReportWindow::printPreview(QPrinter * printer) { qDebug("QmReportWindow::printPreview"); currentWebView->print(printer); } QmReportWindow::~QmReportWindow() { }