PageRenderTime 22ms CodeModel.GetById 22ms RepoModel.GetById 6ms app.codeStats 0ms

/Istc/src/gui/browser.cpp

https://gitlab.com/dexots/surgery-training-curriculum-system
C++ | 183 lines | 120 code | 34 blank | 29 comment | 1 complexity | 7b6987a1d7e97e28428a27ad0f35d0c6 MD5 | raw file
  1. #include "gui/browser.h"
  2. const int Browser::FONT_SIZE = 17;
  3. const QString Browser::LABEL_ERROR = "ERROR! Check your Internet Connection";
  4. const QString Browser::LABEL_LOADING = "LOADING PAGE.....";
  5. const QString Browser::LABEL_BACK = QString::fromUtf8(":/icon/ButtonIcon/back.png");
  6. const QString Browser::LABEL_HOME = QString::fromUtf8(":/icon/ButtonIcon/home.png");
  7. const QString Browser::LABEL_FORWARD = QString::fromUtf8(":/icon/ButtonIcon/forward.png");
  8. Browser::Browser() {
  9. _font.setBold(true);
  10. _font.setPointSize(FONT_SIZE);
  11. Browser::initializeBrowser();
  12. }
  13. Browser::~Browser() {
  14. Browser::clearGarbage();
  15. }
  16. //public:
  17. void Browser::load(QUrl url) {
  18. //_browserView->load(url);
  19. QDesktopServices::openUrl(url);
  20. timeToShowWidget();
  21. }
  22. void Browser::clearCookie() {
  23. /*
  24. _browserView->page()->
  25. networkAccessManager()->
  26. setCookieJar(new QNetworkCookieJar());
  27. */
  28. }
  29. void Browser::hideHomeButton() {
  30. _homeClick->hide();
  31. }
  32. //private methods:
  33. void Browser::closeWebView() {
  34. clearCookie();
  35. //_browserView->deleteLater();
  36. }
  37. void Browser::clearGarbage() {
  38. closeWebView();
  39. delete _backLabel;
  40. delete _backClick;
  41. delete _forwardLabel;
  42. delete _loadingLabel;
  43. delete _loadErrorLabel;
  44. delete _forwardClick;
  45. delete _homeLabel;
  46. delete _homeClick;
  47. delete _buttonLayout;
  48. delete _browserLayout;
  49. }
  50. void Browser::initializeBrowser() {
  51. /*
  52. _browserView = new QWebView;
  53. connect (_browserView, SIGNAL(urlChanged(QUrl)),
  54. this, SLOT(timeToChangeUrl(QUrl)));
  55. connect (_browserView, SIGNAL(loadFinished(bool)),
  56. this, SLOT(loadStatus(bool)));
  57. connect (_browserView, SIGNAL(loadStarted()),
  58. this, SLOT(loadStart()));
  59. */
  60. Browser::initiateBack();
  61. Browser::initiateForward();
  62. Browser::initiateHome();
  63. Browser::initiateLoadingLabel();
  64. Browser::initiateLoadErrorLabel();
  65. Browser::initiateButtonsLayout();
  66. Browser::initiateBrowserLayout();
  67. this->setLayout(_browserLayout);
  68. }
  69. void Browser::initiateBack(){
  70. _backLabel = new QLabel;
  71. _backLabel->setPixmap(QPixmap(LABEL_BACK));
  72. _backClick = new ClickableWidget(_backLabel);
  73. /*
  74. connect (_backClick, SIGNAL(isClicked()),
  75. _browserView, SLOT(back()));
  76. */
  77. }
  78. void Browser::initiateForward() {
  79. _forwardLabel = new QLabel;
  80. _forwardLabel->setPixmap(QPixmap(LABEL_FORWARD));
  81. _forwardClick = new ClickableWidget(_forwardLabel);
  82. /*
  83. connect (_forwardClick, SIGNAL(isClicked()),
  84. _browserView, SLOT(forward()));
  85. */
  86. }
  87. void Browser::initiateHome() {
  88. _homeLabel = new QLabel;
  89. _homeLabel->setPixmap(QPixmap(LABEL_HOME));
  90. _homeClick = new ClickableWidget(_homeLabel);
  91. connect (_homeClick, SIGNAL(isClicked()),
  92. this, SLOT(timeToShowWidget()));
  93. }
  94. void Browser::initiateLoadingLabel() {
  95. _loadingLabel = new QLabel;
  96. _loadingLabel->setText(LABEL_LOADING);
  97. _loadingLabel->setFont(_font);
  98. QPalette palette = _loadingLabel->palette();
  99. palette.setColor(_loadingLabel->foregroundRole(), Qt::blue);
  100. _loadingLabel->setPalette(palette);
  101. _loadingLabel->hide();
  102. }
  103. void Browser::initiateLoadErrorLabel() {
  104. _loadErrorLabel = new QLabel;
  105. _loadErrorLabel->setText(LABEL_ERROR);
  106. _loadErrorLabel->setFont(_font);
  107. QPalette palette = _loadErrorLabel->palette();
  108. palette.setColor(_loadErrorLabel->foregroundRole(), Qt::red);
  109. _loadErrorLabel->setPalette(palette);
  110. _loadErrorLabel->hide();
  111. }
  112. void Browser::initiateButtonsLayout() {
  113. _buttonLayout = new QHBoxLayout;
  114. _buttonLayout->addWidget(_backClick);
  115. _buttonLayout->addWidget(_forwardClick);
  116. _buttonLayout->addWidget(_homeClick);
  117. _buttonLayout->addWidget(_loadingLabel);
  118. _buttonLayout->addWidget(_loadErrorLabel);
  119. _buttonLayout->setSpacing(0);
  120. }
  121. void Browser::initiateBrowserLayout() {
  122. _browserLayout = new QVBoxLayout;
  123. _browserLayout->addLayout(_buttonLayout, 1);
  124. //_browserLayout->addWidget(_browserView, 10);
  125. }
  126. //private slots
  127. void Browser::timeToShowWidget() {
  128. //_browserView->stop();
  129. _backClick->hide();
  130. _forwardClick->hide();
  131. _homeClick->hide();
  132. clearCookie();
  133. _loadingLabel->hide();
  134. _loadErrorLabel->hide();
  135. emit this->showWidget();
  136. }
  137. void Browser::timeToChangeUrl(QUrl url) {
  138. emit this->urlChanged(url);
  139. }
  140. void Browser::loadStatus(bool success) {
  141. if (!success) {
  142. _loadErrorLabel->show();
  143. }
  144. _loadingLabel->hide();
  145. }
  146. void Browser::loadStart() {
  147. _loadErrorLabel->hide();
  148. _loadingLabel->show();
  149. }