Subversion Repositories svn1

Rev

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