Subversion Repositories svn1

Rev

Rev 204 | Rev 206 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
156 - 1
#include "qmreportwindow.h"
204 - 2
#include <QVariant>
3
#include <QApplication>
4
#include <QTabWidget>
5
#include <QWidget>
168 david 6
#include <QVBoxLayout>
204 - 7
#include <QButtonGroup>
8
#include <QHBoxLayout>
9
#include <QLabel>
10
#include <QSpacerItem>
156 - 11
 
168 david 12
#include    "consts.h"
13
#include    "structs.h"
14
#include    "proto.h"
15
 
204 - 16
QmReportWindow::QmReportWindow(QWidget *parent) : QWidget(parent)
156 - 17
{
205 - 18
    currentWebView = NULL;
204 - 19
    QVBoxLayout *verticalLayout;
20
 
21
    QWidget *widget;
22
    QHBoxLayout *horizontalLayout_2;
23
    QHBoxLayout *horizontalLayout;
24
    //QSpacerItem *horizontalSpacer;
25
    QLabel *label;
26
 
27
    verticalLayout = new QVBoxLayout(this);
28
    verticalLayout->setContentsMargins(0, 0, 0, 0);
29
    tabWidget = new QTabWidget();
30
    tabWidget->setTabsClosable(true);
31
    tabWidget->setUsesScrollButtons(true);
32
    verticalLayout->addWidget(tabWidget);
33
 
34
    widget = new QWidget();
35
    horizontalLayout_2 = new QHBoxLayout(widget);
36
    horizontalLayout = new QHBoxLayout();
37
    //horizontalLayout->setSpacing(6);
38
    //horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
39
    //horizontalLayout->addItem(horizontalSpacer);
40
    label = new QLabel("Path", widget);
41
    horizontalLayout->addWidget(label);
42
    tabPath = new QLineEdit(widget);
43
    tabPath->setReadOnly(true);
44
    horizontalLayout->addWidget(tabPath);
45
    pb_original = new QPushButton("Original",widget);
46
    horizontalLayout->addWidget(pb_original);
47
    pb_back = new QPushButton("Back",widget);
48
    horizontalLayout->addWidget(pb_back);
205 - 49
    pb_forward = new QPushButton("Forward",widget);
50
    horizontalLayout->addWidget(pb_forward);
204 - 51
    pb_print = new QPushButton("Print",widget);
52
    horizontalLayout->addWidget(pb_print);
53
    horizontalLayout_2->addLayout(horizontalLayout);
54
    verticalLayout->addWidget(widget);
55
 
56
 
57
    connect(tabWidget,SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
58
    connect(tabWidget,SIGNAL(tabCloseRequested(int)), this, SLOT(deleteTab(int)));
59
    connect(pb_back,SIGNAL(clicked()), this, SLOT(back()));
205 - 60
    connect(pb_forward,SIGNAL(clicked()), this, SLOT(forward()));
61
    connect(pb_original, SIGNAL(clicked()), this, SLOT(home()));
204 - 62
 
205 - 63
    addReport(QString(filepath)+ filebase + "_index.html", "Index");
204 - 64
    tabWidget->setCurrentIndex(0);
205 - 65
    //tabChanged(-2);
204 - 66
 
156 - 67
}
68
 
203 - 69
void QmReportWindow::addReport(const QString &report, const QString &name)
70
{
205 - 71
    QmWebView *webView = NULL;
204 - 72
    bool adding = false;
73
    for( int index = 0; index < tabWidget->count(); index++)
203 - 74
    {
204 - 75
        if (tabWidget->tabText(index) == name)
203 - 76
        {
205 - 77
            webView = dynamic_cast<QmWebView *>(tabWidget->widget(index));
203 - 78
            if (webView)
79
            {
80
                qDebug("Reuse Tab:%s", qPrintable(report));
81
                break;
82
            }
83
        }
84
    }
85
 
86
    if (webView == NULL)
87
    {
205 - 88
        webView = new QmWebView();
204 - 89
        adding = true;
203 - 90
    }
204 - 91
 
205 - 92
    webView->setUrl(report);
204 - 93
    if ( adding )
94
    {
95
        int tab = tabWidget->addTab(webView, name);
96
        tabChanged(tab);
97
        qDebug("Adding(%d):%s", tab, qPrintable(report));
98
    }
203 - 99
 
100
}
101
 
204 - 102
void QmReportWindow::deleteTab(int tab)
103
{
205 - 104
//    qDebug("Delete TAB:%d", tab);
204 - 105
    tabWidget->removeTab(tab);
106
}
107
 
108
void QmReportWindow::tabChanged(int tab)
109
{
110
    qDebug("Update TAB:%d", tab);
205 - 111
    currentWebView = dynamic_cast<QmWebView *>(tabWidget->currentWidget());
112
    bool enable = (currentWebView != NULL);
113
    pb_original->setEnabled(enable);
114
    pb_back->setEnabled(enable);
115
    pb_forward->setEnabled(enable);
116
    pb_print->setEnabled(enable);
117
    if ( enable )
204 - 118
    {
205 - 119
        tabPath->setText(currentWebView->homeUrl);
204 - 120
    }
121
    else
122
    {
123
        tabPath->setText("");
124
    }
125
}
126
 
127
void QmReportWindow::back(void)
128
{
205 - 129
     if ( currentWebView )
204 - 130
     {
205 - 131
         currentWebView->back();
204 - 132
     }
133
}
134
 
205 - 135
void QmReportWindow::forward(void)
136
{
137
     if ( currentWebView )
138
     {
139
         currentWebView->forward();
140
     }
141
}
142
 
143
void QmReportWindow::home(void)
144
{
145
     if ( currentWebView )
146
     {
147
         currentWebView->home();
148
     }
149
}
150
 
156 - 151
QmReportWindow::~QmReportWindow()
152
{
153
}