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.0KB

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