PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/mainwindow/mainnotebook/context/abstractcontainer.cpp

https://github.com/raphaelamorim/audactile
C++ | 55 lines | 41 code | 11 blank | 3 comment | 0 complexity | bb3cb58ec994e789bc4153abaa352a0f MD5 | raw file
  1. #include "abstractcontainer.h"
  2. AbstractContainer::AbstractContainer(QWidget *parent) :
  3. QFrame(parent)
  4. {
  5. setFrameShape(QFrame::Box);
  6. setFrameShadow(QFrame::Sunken);
  7. contentView = new QWebView(this);
  8. connect(contentView, SIGNAL(linkClicked(QUrl)), this, SLOT(openLinksInExternalWindow(QUrl)));
  9. contentView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
  10. contentView->setContextMenuPolicy(Qt::NoContextMenu);
  11. // Stole font from a QLabel
  12. QLabel *label = new QLabel("I will die soon!");
  13. QFont font = label->font();
  14. delete label;
  15. // TODO: set margins, color, etc.
  16. QStringList headerList;
  17. headerList += "<style type=\"text/css\">body { \n";
  18. headerList += " font-family: " + font.family() + ";\n";
  19. headerList += " font-size: " + QString::number(font.pointSize() + 2) + "pt; \n";
  20. headerList += "} \n";
  21. headerList += ".title {";
  22. headerList += " font-size: " + QString::number(font.pointSize() + 4) + "pt; \n";
  23. headerList += " font-weight: bold; \n";
  24. headerList += "}\n";
  25. headerList += ".reference {";
  26. headerList += " text-align: right;";
  27. headerList += " font-style: italic; \n";
  28. headerList += "}\n";
  29. headerList += "</style>";
  30. header = headerList.join("");
  31. footer = ""; // no footer yet.
  32. // TODO: open links in another window
  33. QVBoxLayout *layout = new QVBoxLayout(this);
  34. layout->addWidget(contentView);
  35. layout->setContentsMargins(0, 0, 0, 0);
  36. setLayout(layout);
  37. }
  38. void AbstractContainer::setHtml(QString html) {
  39. html = header + html + footer;
  40. contentView->setHtml(html);
  41. }
  42. void AbstractContainer::openLinksInExternalWindow(QUrl url) {
  43. QDesktopServices::openUrl(url);
  44. }