| 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);
|
| 205 |
- |
171 |
currentWebView = dynamic_cast<QmWebView *>(tabWidget->currentWidget());
|
|
|
172 |
bool enable = (currentWebView != NULL);
|
| 206 |
- |
173 |
|
| 205 |
- |
174 |
pb_original->setEnabled(enable);
|
|
|
175 |
pb_back->setEnabled(enable);
|
|
|
176 |
pb_forward->setEnabled(enable);
|
|
|
177 |
pb_print->setEnabled(enable);
|
| 380 |
david |
178 |
pb_explore->setEnabled(enable);
|
|
|
179 |
pb_openExternal->setEnabled(enable);
|
| 206 |
- |
180 |
|
| 205 |
- |
181 |
if ( enable )
|
| 204 |
- |
182 |
{
|
| 380 |
david |
183 |
//tabPath->setText(currentWebView->homeUrl);
|
|
|
184 |
//tabPath->setText(currentWebView->url().toString());
|
|
|
185 |
QmReportWindow::updateTabPath();
|
| 204 |
- |
186 |
}
|
|
|
187 |
else
|
|
|
188 |
{
|
|
|
189 |
tabPath->setText("");
|
|
|
190 |
}
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
void QmReportWindow::back(void)
|
|
|
194 |
{
|
| 205 |
- |
195 |
if ( currentWebView )
|
| 204 |
- |
196 |
{
|
| 205 |
- |
197 |
currentWebView->back();
|
| 204 |
- |
198 |
}
|
|
|
199 |
}
|
|
|
200 |
|
| 205 |
- |
201 |
void QmReportWindow::forward(void)
|
|
|
202 |
{
|
|
|
203 |
if ( currentWebView )
|
|
|
204 |
{
|
|
|
205 |
currentWebView->forward();
|
|
|
206 |
}
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
void QmReportWindow::home(void)
|
|
|
210 |
{
|
|
|
211 |
if ( currentWebView )
|
|
|
212 |
{
|
|
|
213 |
currentWebView->home();
|
|
|
214 |
}
|
|
|
215 |
}
|
|
|
216 |
|
| 380 |
david |
217 |
void QmReportWindow::openLocation(void)
|
|
|
218 |
{
|
|
|
219 |
if ( currentWebView )
|
|
|
220 |
{
|
|
|
221 |
QString target = tabPath->text();
|
| 387 |
david |
222 |
target.remove(QRegularExpression("/[^/]*$"));
|
| 380 |
david |
223 |
QDesktopServices::openUrl(target);
|
|
|
224 |
}
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
void QmReportWindow::openExternal(void)
|
|
|
228 |
{
|
|
|
229 |
if ( currentWebView )
|
|
|
230 |
{
|
|
|
231 |
QString target = tabPath->text();
|
|
|
232 |
QDesktopServices::openUrl(target);
|
|
|
233 |
}
|
|
|
234 |
}
|
|
|
235 |
|
| 207 |
- |
236 |
void QmReportWindow::print(void)
|
|
|
237 |
{
|
|
|
238 |
if ( currentWebView )
|
|
|
239 |
{
|
| 380 |
david |
240 |
// Delete printer preview if we are previewing a different page
|
|
|
241 |
//
|
|
|
242 |
if ( printPreviewDialog /* && currentWebViewPrinter != currentWebView */)
|
|
|
243 |
{
|
|
|
244 |
delete printPreviewDialog;
|
|
|
245 |
printPreviewDialog = NULL;
|
|
|
246 |
currentWebViewPrinter = NULL;
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
// Allocate Printer Preview if we don't have one
|
|
|
250 |
if (printPreviewDialog == NULL)
|
|
|
251 |
{
|
|
|
252 |
currentWebViewPrinter = currentWebView;
|
|
|
253 |
printPreviewDialog = new QPrintPreviewDialog(printer, this);
|
|
|
254 |
printPreviewDialog->setModal ( true );
|
|
|
255 |
printPreviewDialog->setSizeGripEnabled(true);
|
|
|
256 |
printer->setDocName(currentWebView->url().toString());
|
|
|
257 |
}
|
|
|
258 |
|
| 211 |
- |
259 |
// printPreviewDialog->open(this,SLOT(fred()));
|
| 380 |
david |
260 |
//currentWebView->setStyleSheet("*{font-size:250%;}");
|
| 211 |
- |
261 |
//currentWebView->setZoomFactor(2.0);
|
| 384 |
david |
262 |
//TODO currentWebView->setTextSizeMultiplier ( pb_size->value() );
|
| 380 |
david |
263 |
qDebug("setTextSizeMultiplier:%f", pb_size->value());
|
| 207 |
- |
264 |
|
| 380 |
david |
265 |
connect(printPreviewDialog,SIGNAL(paintRequested(QPrinter *)), this , SLOT(printPreview(QPrinter *)) );
|
|
|
266 |
printPreviewDialog->exec();
|
|
|
267 |
|
| 384 |
david |
268 |
//TODO currentWebView->setTextSizeMultiplier ( 1.0 );
|
| 380 |
david |
269 |
|
| 207 |
- |
270 |
// QPrintDialog printDialog(this);
|
|
|
271 |
// if (printDialog.exec() == QDialog::Accepted) {
|
|
|
272 |
// QPrinter * printer = printDialog.printer();
|
|
|
273 |
// currentWebView->print(printer);
|
|
|
274 |
// // print ...
|
|
|
275 |
// }
|
|
|
276 |
}
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
void QmReportWindow::printPreview(QPrinter * printer)
|
|
|
280 |
{
|
|
|
281 |
qDebug("QmReportWindow::printPreview");
|
| 384 |
david |
282 |
//TODO currentWebView->print(printer);
|
| 207 |
- |
283 |
}
|
|
|
284 |
|
| 156 |
- |
285 |
QmReportWindow::~QmReportWindow()
|
|
|
286 |
{
|
|
|
287 |
}
|