Subversion Repositories svn1

Rev

Rev 207 | 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>
207 - 11
#include <QToolBar>
12
#include <QPrintDialog>
13
#include <QPrintPreviewDialog>
156 - 14
 
207 - 15
#include <QDirIterator>
16
#include <QtDebug>
17
 
168 david 18
#include    "consts.h"
19
#include    "structs.h"
20
#include    "proto.h"
21
 
204 - 22
QmReportWindow::QmReportWindow(QWidget *parent) : QWidget(parent)
156 - 23
{
205 - 24
    currentWebView = NULL;
204 - 25
    QVBoxLayout *verticalLayout;
26
    QLabel *label;
207 - 27
    QToolBar *tb;
204 - 28
 
29
    verticalLayout = new QVBoxLayout(this);
30
    verticalLayout->setContentsMargins(0, 0, 0, 0);
207 - 31
 
32
    tb = new QToolBar ( "Actions" );
33
    verticalLayout->addWidget(tb);
34
    pb_original = tb->addAction ( QIcon(":/webkit/inspector/Images/reloadButtonGlyph.png"),"Home", this, SLOT(home()));
35
    pb_back = tb->addAction ( QIcon(":/trolltech/styles/commonstyle/images/left-32.png"),"Back", this, SLOT(back()));
36
    pb_forward = tb->addAction ( QIcon(":/trolltech/styles/commonstyle/images/right-32.png"),"Forward", this, SLOT(forward()));
37
    pb_print = tb->addAction ( QIcon(":/trolltech/dialogs/qprintpreviewdialog/images/print-32.png" ),"Print", this, SLOT(print()));
38
    tb->addSeparator();
39
    label = new QLabel("Path");
40
    tb->addWidget(label);
41
    tabPath = new QLineEdit();
42
    tabPath->setReadOnly(true);
43
    tb->addWidget(tabPath);
44
 
204 - 45
    tabWidget = new QTabWidget();
46
    tabWidget->setTabsClosable(true);
47
    tabWidget->setUsesScrollButtons(true);
48
    verticalLayout->addWidget(tabWidget);
49
 
50
    connect(tabWidget,SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
51
    connect(tabWidget,SIGNAL(tabCloseRequested(int)), this, SLOT(deleteTab(int)));
52
 
205 - 53
    addReport(QString(filepath)+ filebase + "_index.html", "Index");
204 - 54
    tabWidget->setCurrentIndex(0);
55
 
207 - 56
//    {
57
//        QDirIterator it(":", QDirIterator::Subdirectories);
58
//        while (it.hasNext())
59
//                qDebug() << it.next();
60
//    }
61
 
156 - 62
}
63
 
203 - 64
void QmReportWindow::addReport(const QString &report, const QString &name)
65
{
205 - 66
    QmWebView *webView = NULL;
204 - 67
    bool adding = false;
68
    for( int index = 0; index < tabWidget->count(); index++)
203 - 69
    {
204 - 70
        if (tabWidget->tabText(index) == name)
203 - 71
        {
205 - 72
            webView = dynamic_cast<QmWebView *>(tabWidget->widget(index));
203 - 73
            if (webView)
74
            {
210 - 75
                //qDebug("Reuse Tab:%s", qPrintable(report));
203 - 76
                break;
77
            }
78
        }
79
    }
80
 
81
    if (webView == NULL)
82
    {
205 - 83
        webView = new QmWebView();
204 - 84
        adding = true;
203 - 85
    }
204 - 86
 
205 - 87
    webView->setUrl(report);
204 - 88
    if ( adding )
89
    {
90
        int tab = tabWidget->addTab(webView, name);
91
        tabChanged(tab);
210 - 92
        //qDebug("Adding(%d):%s", tab, qPrintable(report));
204 - 93
    }
203 - 94
}
95
 
204 - 96
void QmReportWindow::deleteTab(int tab)
97
{
205 - 98
//    qDebug("Delete TAB:%d", tab);
204 - 99
    tabWidget->removeTab(tab);
100
}
101
 
102
void QmReportWindow::tabChanged(int tab)
103
{
210 - 104
    //qDebug("Update TAB:%d", tab);
205 - 105
    currentWebView = dynamic_cast<QmWebView *>(tabWidget->currentWidget());
106
    bool enable = (currentWebView != NULL);
206 - 107
 
205 - 108
    pb_original->setEnabled(enable);
109
    pb_back->setEnabled(enable);
110
    pb_forward->setEnabled(enable);
111
    pb_print->setEnabled(enable);
206 - 112
 
205 - 113
    if ( enable )
204 - 114
    {
205 - 115
        tabPath->setText(currentWebView->homeUrl);
204 - 116
    }
117
    else
118
    {
119
        tabPath->setText("");
120
    }
121
}
122
 
123
void QmReportWindow::back(void)
124
{
205 - 125
     if ( currentWebView )
204 - 126
     {
205 - 127
         currentWebView->back();
204 - 128
     }
129
}
130
 
205 - 131
void QmReportWindow::forward(void)
132
{
133
     if ( currentWebView )
134
     {
135
         currentWebView->forward();
136
     }
137
}
138
 
139
void QmReportWindow::home(void)
140
{
141
     if ( currentWebView )
142
     {
143
         currentWebView->home();
144
     }
145
}
146
 
207 - 147
void QmReportWindow::print(void)
148
{
149
     if ( currentWebView )
150
     {
151
        QPrintPreviewDialog printPreviewDialog ( this );
152
        connect(&printPreviewDialog,SIGNAL(paintRequested(QPrinter *)), this , SLOT(printPreview(QPrinter *)) );
153
        printPreviewDialog.open(this,SLOT(fred()));
154
        printPreviewDialog.exec();
155
 
156
//         QPrintDialog printDialog(this);
157
//         if (printDialog.exec() == QDialog::Accepted) {
158
//             QPrinter * printer = printDialog.printer();
159
//             currentWebView->print(printer);
160
//              // print ...
161
//          }
162
         //currentWebView->print(zzzz);
163
     }
164
}
165
 
166
void QmReportWindow::printPreview(QPrinter * printer)
167
{
168
    qDebug("QmReportWindow::printPreview");
169
    currentWebView->print(printer);
170
}
171
 
156 - 172
QmReportWindow::~QmReportWindow()
173
{
174
}