Subversion Repositories svn1

Rev

Go to most recent revision | Details | 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>
258 - 13
#include <QPrinter>
207 - 14
#include <QPrintPreviewDialog>
156 - 15
 
207 - 16
#include <QDirIterator>
17
#include <QtDebug>
18
 
168 david 19
#include    "consts.h"
20
#include    "structs.h"
21
#include    "proto.h"
22
 
204 - 23
QmReportWindow::QmReportWindow(QWidget *parent) : QWidget(parent)
156 - 24
{
205 - 25
    currentWebView = NULL;
258 - 26
    currentWebViewPrinter = NULL;
27
    printPreviewDialog = NULL;
211 - 28
 
258 - 29
    // Allocate one printer for the entire widget
30
    // Setting made to the printer will then be used in all reports
31
    //
32
    printer = new QPrinter();
33
    printer->setPageMargins(10,10,10,10,QPrinter::Millimeter);
211 - 34
 
258 - 35
//    printPreviewDialog = new QPrintPreviewDialog(this);
36
//    printPreviewDialog->setModal ( true );
37
//    connect(printPreviewDialog,SIGNAL(paintRequested(QPrinter *)), this , SLOT(printPreview(QPrinter *)) );
38
 
204 - 39
    QVBoxLayout *verticalLayout;
40
    QLabel *label;
207 - 41
    QToolBar *tb;
204 - 42
 
43
    verticalLayout = new QVBoxLayout(this);
44
    verticalLayout->setContentsMargins(0, 0, 0, 0);
207 - 45
 
46
    tb = new QToolBar ( "Actions" );
47
    verticalLayout->addWidget(tb);
48
    pb_original = tb->addAction ( QIcon(":/webkit/inspector/Images/reloadButtonGlyph.png"),"Home", this, SLOT(home()));
49
    pb_back = tb->addAction ( QIcon(":/trolltech/styles/commonstyle/images/left-32.png"),"Back", this, SLOT(back()));
50
    pb_forward = tb->addAction ( QIcon(":/trolltech/styles/commonstyle/images/right-32.png"),"Forward", this, SLOT(forward()));
51
    pb_print = tb->addAction ( QIcon(":/trolltech/dialogs/qprintpreviewdialog/images/print-32.png" ),"Print", this, SLOT(print()));
52
    tb->addSeparator();
258 - 53
    pb_size = new QDoubleSpinBox();
54
    pb_size->setSingleStep (0.05);
55
    pb_size->setValue(1.4);
56
    pb_size->setToolTip("Printer Scaling Size");
57
    tb->addWidget(pb_size);
207 - 58
    label = new QLabel("Path");
59
    tb->addWidget(label);
60
    tabPath = new QLineEdit();
61
    tabPath->setReadOnly(true);
62
    tb->addWidget(tabPath);
63
 
204 - 64
    tabWidget = new QTabWidget();
65
    tabWidget->setTabsClosable(true);
66
    tabWidget->setUsesScrollButtons(true);
67
    verticalLayout->addWidget(tabWidget);
68
 
69
    connect(tabWidget,SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
70
    connect(tabWidget,SIGNAL(tabCloseRequested(int)), this, SLOT(deleteTab(int)));
71
 
270 david 72
    addReport(QString(filepath)+ "web/" + filebase + "_index.html", "Index");
258 - 73
    //addReport(QString(filepath) + "brmr2011_l2_2.txt", "Starters Report 2");
204 - 74
    tabWidget->setCurrentIndex(0);
75
 
207 - 76
//    {
77
//        QDirIterator it(":", QDirIterator::Subdirectories);
78
//        while (it.hasNext())
79
//                qDebug() << it.next();
80
//    }
81
 
211 - 82
    //QWebSettings *gs =  QWebSettings::globalSettings ();
83
    //gs->setFontSize(QWebSettings::DefaultFixedFontSize,16);
84
 
156 - 85
}
86
 
203 - 87
void QmReportWindow::addReport(const QString &report, const QString &name)
88
{
205 - 89
    QmWebView *webView = NULL;
204 - 90
    bool adding = false;
91
    for( int index = 0; index < tabWidget->count(); index++)
203 - 92
    {
204 - 93
        if (tabWidget->tabText(index) == name)
203 - 94
        {
205 - 95
            webView = dynamic_cast<QmWebView *>(tabWidget->widget(index));
203 - 96
            if (webView)
97
            {
210 - 98
                //qDebug("Reuse Tab:%s", qPrintable(report));
203 - 99
                break;
100
            }
101
        }
102
    }
103
 
104
    if (webView == NULL)
105
    {
205 - 106
        webView = new QmWebView();
204 - 107
        adding = true;
203 - 108
    }
204 - 109
 
205 - 110
    webView->setUrl(report);
204 - 111
    if ( adding )
112
    {
113
        int tab = tabWidget->addTab(webView, name);
114
        tabChanged(tab);
210 - 115
        //qDebug("Adding(%d):%s", tab, qPrintable(report));
204 - 116
    }
203 - 117
}
118
 
204 - 119
void QmReportWindow::deleteTab(int tab)
120
{
205 - 121
//    qDebug("Delete TAB:%d", tab);
204 - 122
    tabWidget->removeTab(tab);
123
}
124
 
125
void QmReportWindow::tabChanged(int tab)
126
{
210 - 127
    //qDebug("Update TAB:%d", tab);
205 - 128
    currentWebView = dynamic_cast<QmWebView *>(tabWidget->currentWidget());
129
    bool enable = (currentWebView != NULL);
206 - 130
 
205 - 131
    pb_original->setEnabled(enable);
132
    pb_back->setEnabled(enable);
133
    pb_forward->setEnabled(enable);
134
    pb_print->setEnabled(enable);
206 - 135
 
205 - 136
    if ( enable )
204 - 137
    {
205 - 138
        tabPath->setText(currentWebView->homeUrl);
204 - 139
    }
140
    else
141
    {
142
        tabPath->setText("");
143
    }
144
}
145
 
146
void QmReportWindow::back(void)
147
{
205 - 148
     if ( currentWebView )
204 - 149
     {
205 - 150
         currentWebView->back();
204 - 151
     }
152
}
153
 
205 - 154
void QmReportWindow::forward(void)
155
{
156
     if ( currentWebView )
157
     {
158
         currentWebView->forward();
159
     }
160
}
161
 
162
void QmReportWindow::home(void)
163
{
164
     if ( currentWebView )
165
     {
166
         currentWebView->home();
167
     }
168
}
169
 
207 - 170
void QmReportWindow::print(void)
171
{
172
     if ( currentWebView )
173
     {
258 - 174
         // Delete printer preview if we are previewing a different page
175
         //
176
         if ( printPreviewDialog /* && currentWebViewPrinter !=  currentWebView */)
177
         {
178
             delete printPreviewDialog;
179
             printPreviewDialog = NULL;
180
             currentWebViewPrinter = NULL;
181
         }
182
 
183
         // Allocate Printer Preview if we don't have one
184
         if (printPreviewDialog == NULL)
185
         {
186
             currentWebViewPrinter = currentWebView;
187
             printPreviewDialog = new QPrintPreviewDialog(printer, this);
188
             printPreviewDialog->setModal ( true );
189
             printPreviewDialog->setSizeGripEnabled(true);
190
             printer->setDocName(currentWebView->url().toString());
191
         }
192
 
211 - 193
//        printPreviewDialog->open(this,SLOT(fred()));
258 - 194
         //currentWebView->setStyleSheet("*{font-size:250%;}");
211 - 195
         //currentWebView->setZoomFactor(2.0);
258 - 196
         currentWebView->setTextSizeMultiplier ( pb_size->value() );
197
         qDebug("setTextSizeMultiplier:%f", pb_size->value());
207 - 198
 
258 - 199
         connect(printPreviewDialog,SIGNAL(paintRequested(QPrinter *)), this , SLOT(printPreview(QPrinter *)) );
200
         printPreviewDialog->exec();
201
 
202
         currentWebView->setTextSizeMultiplier ( 1.0 );
203
 
207 - 204
//         QPrintDialog printDialog(this);
205
//         if (printDialog.exec() == QDialog::Accepted) {
206
//             QPrinter * printer = printDialog.printer();
207
//             currentWebView->print(printer);
208
//              // print ...
209
//          }
210
     }
211
}
212
 
213
void QmReportWindow::printPreview(QPrinter * printer)
214
{
215
    qDebug("QmReportWindow::printPreview");
216
    currentWebView->print(printer);
217
}
218
 
156 - 219
QmReportWindow::~QmReportWindow()
220
{
221
}