Subversion Repositories svn1-original

Rev

Rev 214 | Details | Compare with Previous | Last modification | View Log | RSS feed

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