Subversion Repositories svn1-original

Rev

Rev 208 | Rev 210 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include "qmreportwindow.h"
#include <QVariant>
#include <QApplication>
#include <QTabWidget>
#include <QWidget>
#include <QVBoxLayout>
#include <QButtonGroup>
#include <QHBoxLayout>
#include <QLabel>
#include <QSpacerItem>

#include    "consts.h"
#include    "structs.h"
#include    "proto.h"

QmReportWindow::QmReportWindow(QWidget *parent) : QWidget(parent)
{
    currentWebView = NULL;
    QVBoxLayout *verticalLayout;

    QWidget *widget;
    QHBoxLayout *horizontalLayout_2;
    QHBoxLayout *horizontalLayout;
    //QSpacerItem *horizontalSpacer;
    QLabel *label;

    verticalLayout = new QVBoxLayout(this);
    verticalLayout->setContentsMargins(0, 0, 0, 0);
    tabWidget = new QTabWidget();
    tabWidget->setTabsClosable(true);
    tabWidget->setUsesScrollButtons(true);
    verticalLayout->addWidget(tabWidget);

    widget = new QWidget();
    horizontalLayout_2 = new QHBoxLayout(widget);
    horizontalLayout = new QHBoxLayout();
    //horizontalLayout->setSpacing(6);
    //horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
    //horizontalLayout->addItem(horizontalSpacer);
    label = new QLabel("Path", widget);
    horizontalLayout->addWidget(label);
    tabPath = new QLineEdit(widget);
    tabPath->setReadOnly(true);
    horizontalLayout->addWidget(tabPath);
    pb_original = new QPushButton("Original",widget);
    horizontalLayout->addWidget(pb_original);
    pb_back = new QPushButton("Back",widget);
    horizontalLayout->addWidget(pb_back);
    pb_forward = new QPushButton("Forward",widget);
    horizontalLayout->addWidget(pb_forward);
    pb_print = new QPushButton("Print",widget);
    horizontalLayout->addWidget(pb_print);
    horizontalLayout_2->addLayout(horizontalLayout);
    verticalLayout->addWidget(widget);


    connect(tabWidget,SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
    connect(tabWidget,SIGNAL(tabCloseRequested(int)), this, SLOT(deleteTab(int)));
    connect(pb_back,SIGNAL(clicked()), this, SLOT(back()));
    connect(pb_forward,SIGNAL(clicked()), this, SLOT(forward()));
    connect(pb_original, SIGNAL(clicked()), this, SLOT(home()));

    addReport(QString(filepath)+ filebase + "_index.html", "Index");
    tabWidget->setCurrentIndex(0);
    //tabChanged(-2);

}

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<QmWebView *>(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<QmWebView *>(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();
     }
}

QmReportWindow::~QmReportWindow()
{
}