Typica is a free program for professional coffee roasters. https://typica.us
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

webview.cpp 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*573:*/
  2. #line 52 "./webview.w"
  3. #include "webview.h"
  4. /*574:*/
  5. #line 66 "./webview.w"
  6. TypicaWebView::TypicaWebView():QWebView()
  7. {
  8. page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks);
  9. connect(page(),SIGNAL(linkClicked(QUrl)),this,SLOT(linkDelegate(QUrl)));
  10. QDesktopWidget*desktop= QApplication::desktop();
  11. const int dpi= desktop->logicalDpiX();
  12. setZoomFactor((qreal)(dpi)/96.0);
  13. settings()->setUserStyleSheetUrl(QUrl("qrc:/resources/css/default.css"));
  14. }
  15. /*:574*//*575:*/
  16. #line 88 "./webview.w"
  17. void TypicaWebView::linkDelegate(const QUrl&url)
  18. {
  19. if(url.scheme()=="typica")
  20. {
  21. QString address(url.toEncoded());
  22. /*576:*/
  23. #line 106 "./webview.w"
  24. if(address=="typica://aboutqt")
  25. {
  26. QMessageBox::aboutQt(this);
  27. return;
  28. }
  29. /*:576*/
  30. #line 94 "./webview.w"
  31. /*577:*/
  32. #line 115 "./webview.w"
  33. if(address.startsWith("typica://script/"))
  34. {
  35. emit scriptLinkClicked(address.remove(0,16));
  36. return;
  37. }
  38. /*:577*/
  39. #line 95 "./webview.w"
  40. }
  41. else
  42. {
  43. QDesktopServices::openUrl(url);
  44. }
  45. }
  46. /*:575*//*578:*/
  47. #line 127 "./webview.w"
  48. void TypicaWebView::load(const QString&url)
  49. {
  50. QWebView::load(QUrl(url));
  51. }
  52. void TypicaWebView::setHtml(const QString&html,const QUrl&baseUrl)
  53. {
  54. QWebView::setHtml(html,baseUrl);
  55. }
  56. void TypicaWebView::setContent(QIODevice*device)
  57. {
  58. QSettings settings;
  59. device->reset();
  60. QByteArray content= device->readAll();
  61. QUrl baseDir= QUrl("file://"+settings.value("config").toString()+"/");
  62. QWebView::setContent(content,"application/xhtml+xml",baseDir);
  63. }
  64. QString TypicaWebView::saveXml()
  65. {
  66. return page()->currentFrame()->documentElement().toOuterXml();
  67. }
  68. /*:578*//*579:*/
  69. #line 159 "./webview.w"
  70. void TypicaWebView::print(const QString&printerName)
  71. {
  72. QPrinter*printer= new QPrinter(QPrinter::HighResolution);
  73. if(!printerName.isEmpty())
  74. {
  75. printer->setPrinterName(printerName);
  76. printer->setFullPage(true);
  77. QWebView::print(printer);
  78. return;
  79. }
  80. QPrintDialog printDialog(printer,NULL);
  81. if(printDialog.exec()==QDialog::Accepted)
  82. {
  83. QWebView::print(printer);
  84. }
  85. }
  86. /*:579*//*585:*/
  87. #line 240 "./webview.w"
  88. QWebElement TypicaWebView::documentElement()
  89. {
  90. return page()->mainFrame()->documentElement();
  91. }
  92. QWebElement TypicaWebView::findFirstElement(const QString&selector)
  93. {
  94. return page()->mainFrame()->findFirstElement(selector);
  95. }
  96. /*:585*/
  97. #line 55 "./webview.w"
  98. /*:573*/