Subversion Repositories svn1-original

Rev

Go to most recent revision | Details | 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>
262 - 13
#include <QPrinter>
211 - 14
#include <QPrintPreviewDialog>
284 david 15
#include <QDesktopServices>
160 - 16
 
211 - 17
#include <QDirIterator>
18
#include <QtDebug>
19
 
172 david 20
#include    "consts.h"
21
#include    "structs.h"
22
#include    "proto.h"
23
 
287 david 24
QmReportWindow *reportWindow = NULL;
25
 
208 - 26
QmReportWindow::QmReportWindow(QWidget *parent) : QWidget(parent)
160 - 27
{
209 - 28
    currentWebView = NULL;
262 - 29
    currentWebViewPrinter = NULL;
30
    printPreviewDialog = NULL;
287 david 31
    reportWindow = this;
215 - 32
 
262 - 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();
37
    printer->setPageMargins(10,10,10,10,QPrinter::Millimeter);
215 - 38
 
262 - 39
//    printPreviewDialog = new QPrintPreviewDialog(this);
40
//    printPreviewDialog->setModal ( true );
41
//    connect(printPreviewDialog,SIGNAL(paintRequested(QPrinter *)), this , SLOT(printPreview(QPrinter *)) );
42
 
208 - 43
    QVBoxLayout *verticalLayout;
44
    QLabel *label;
211 - 45
    QToolBar *tb;
208 - 46
 
47
    verticalLayout = new QVBoxLayout(this);
48
    verticalLayout->setContentsMargins(0, 0, 0, 0);
211 - 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()));
284 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();
211 - 61
    pb_print = tb->addAction ( QIcon(":/trolltech/dialogs/qprintpreviewdialog/images/print-32.png" ),"Print", this, SLOT(print()));
262 - 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);
211 - 67
    label = new QLabel("Path");
68
    tb->addWidget(label);
69
    tabPath = new QLineEdit();
70
    tabPath->setReadOnly(true);
71
    tb->addWidget(tabPath);
72
 
208 - 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
 
274 david 81
    addReport(QString(filepath)+ "web/" + filebase + "_index.html", "Index");
262 - 82
    //addReport(QString(filepath) + "brmr2011_l2_2.txt", "Starters Report 2");
208 - 83
    tabWidget->setCurrentIndex(0);
84
 
211 - 85
//    {
86
//        QDirIterator it(":", QDirIterator::Subdirectories);
87
//        while (it.hasNext())
88
//                qDebug() << it.next();
89
//    }
90
 
215 - 91
    //QWebSettings *gs =  QWebSettings::globalSettings ();
92
    //gs->setFontSize(QWebSettings::DefaultFixedFontSize,16);
93
 
160 - 94
}
95
 
207 - 96
void QmReportWindow::addReport(const QString &report, const QString &name)
97
{
209 - 98
    QmWebView *webView = NULL;
208 - 99
    bool adding = false;
100
    for( int index = 0; index < tabWidget->count(); index++)
207 - 101
    {
208 - 102
        if (tabWidget->tabText(index) == name)
207 - 103
        {
209 - 104
            webView = dynamic_cast<QmWebView *>(tabWidget->widget(index));
207 - 105
            if (webView)
106
            {
214 - 107
                //qDebug("Reuse Tab:%s", qPrintable(report));
207 - 108
                break;
109
            }
110
        }
111
    }
112
 
113
    if (webView == NULL)
114
    {
209 - 115
        webView = new QmWebView();
208 - 116
        adding = true;
207 - 117
    }
208 - 118
 
209 - 119
    webView->setUrl(report);
208 - 120
    if ( adding )
121
    {
122
        int tab = tabWidget->addTab(webView, name);
123
        tabChanged(tab);
214 - 124
        //qDebug("Adding(%d):%s", tab, qPrintable(report));
208 - 125
    }
207 - 126
}
127
 
287 david 128
QmWebView *QmReportWindow::newTab(void)
129
{
130
    QmWebView *webView = NULL;
131
    if (reportWindow)
132
    {
133
        webView = new QmWebView();
134
        int tab = reportWindow->tabWidget->addTab(webView, "New");
135
        webView->setTab(tab);
136
        reportWindow->tabChanged(tab);
137
 
138
    }
139
    return(webView);
140
}
141
 
142
void QmReportWindow::setTabName(const int tab, const QString &name)
143
{
144
    if (reportWindow)
145
    {
146
        reportWindow->tabWidget->setTabText(tab, name);
147
    }
148
}
149
 
208 - 150
void QmReportWindow::deleteTab(int tab)
151
{
209 - 152
//    qDebug("Delete TAB:%d", tab);
208 - 153
    tabWidget->removeTab(tab);
154
}
155
 
156
void QmReportWindow::tabChanged(int tab)
157
{
214 - 158
    //qDebug("Update TAB:%d", tab);
209 - 159
    currentWebView = dynamic_cast<QmWebView *>(tabWidget->currentWidget());
160
    bool enable = (currentWebView != NULL);
210 - 161
 
209 - 162
    pb_original->setEnabled(enable);
163
    pb_back->setEnabled(enable);
164
    pb_forward->setEnabled(enable);
165
    pb_print->setEnabled(enable);
284 david 166
    pb_explore->setEnabled(enable);
167
    pb_openExternal->setEnabled(enable);
210 - 168
 
209 - 169
    if ( enable )
208 - 170
    {
209 - 171
        tabPath->setText(currentWebView->homeUrl);
208 - 172
    }
173
    else
174
    {
175
        tabPath->setText("");
176
    }
177
}
178
 
179
void QmReportWindow::back(void)
180
{
209 - 181
     if ( currentWebView )
208 - 182
     {
209 - 183
         currentWebView->back();
208 - 184
     }
185
}
186
 
209 - 187
void QmReportWindow::forward(void)
188
{
189
     if ( currentWebView )
190
     {
191
         currentWebView->forward();
192
     }
193
}
194
 
195
void QmReportWindow::home(void)
196
{
197
     if ( currentWebView )
198
     {
199
         currentWebView->home();
200
     }
201
}
202
 
284 david 203
void QmReportWindow::openLocation(void)
204
{
205
    if ( currentWebView )
206
    {
207
        QString target = currentWebView->homeUrl;
208
        target.remove(QRegExp("/[^/]*$"));
209
        QDesktopServices::openUrl(target);
210
    }
211
}
212
 
213
void QmReportWindow::openExternal(void)
214
{
215
    if ( currentWebView )
216
    {
217
        QDesktopServices::openUrl(currentWebView->homeUrl);
218
    }
219
}
220
 
211 - 221
void QmReportWindow::print(void)
222
{
223
     if ( currentWebView )
224
     {
262 - 225
         // Delete printer preview if we are previewing a different page
226
         //
227
         if ( printPreviewDialog /* && currentWebViewPrinter !=  currentWebView */)
228
         {
229
             delete printPreviewDialog;
230
             printPreviewDialog = NULL;
231
             currentWebViewPrinter = NULL;
232
         }
233
 
234
         // Allocate Printer Preview if we don't have one
235
         if (printPreviewDialog == NULL)
236
         {
237
             currentWebViewPrinter = currentWebView;
238
             printPreviewDialog = new QPrintPreviewDialog(printer, this);
239
             printPreviewDialog->setModal ( true );
240
             printPreviewDialog->setSizeGripEnabled(true);
241
             printer->setDocName(currentWebView->url().toString());
242
         }
243
 
215 - 244
//        printPreviewDialog->open(this,SLOT(fred()));
262 - 245
         //currentWebView->setStyleSheet("*{font-size:250%;}");
215 - 246
         //currentWebView->setZoomFactor(2.0);
262 - 247
         currentWebView->setTextSizeMultiplier ( pb_size->value() );
248
         qDebug("setTextSizeMultiplier:%f", pb_size->value());
211 - 249
 
262 - 250
         connect(printPreviewDialog,SIGNAL(paintRequested(QPrinter *)), this , SLOT(printPreview(QPrinter *)) );
251
         printPreviewDialog->exec();
252
 
253
         currentWebView->setTextSizeMultiplier ( 1.0 );
254
 
211 - 255
//         QPrintDialog printDialog(this);
256
//         if (printDialog.exec() == QDialog::Accepted) {
257
//             QPrinter * printer = printDialog.printer();
258
//             currentWebView->print(printer);
259
//              // print ...
260
//          }
261
     }
262
}
263
 
264
void QmReportWindow::printPreview(QPrinter * printer)
265
{
266
    qDebug("QmReportWindow::printPreview");
267
    currentWebView->print(printer);
268
}
269
 
160 - 270
QmReportWindow::~QmReportWindow()
271
{
272
}