Subversion Repositories svn1

Rev

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