MythTV  master
webpage.cpp
Go to the documentation of this file.
1 #include <cstdlib>
2 #include <iostream>
3 
4 // qt
5 #include <QEvent>
6 #include <QIcon>
7 
8 // MythTV
10 
11 // mythbrowser
12 #include "mythbrowser.h"
13 #include "webpage.h"
14 
15 WebPage::WebPage(MythBrowser *parent, QRect area, const char* name)
16  : m_parent(parent)
17 {
18  m_listItem = new MythUIButtonListItem(parent->m_pageList, "", "", false,
20 
21  m_browser = new MythUIWebBrowser(parent, name);
22  m_browser->SetArea(MythRect(area));
23  m_browser->Init();
24 
35 }
36 
38  : m_parent(parent),
39  m_browser(browser)
40 {
41  m_listItem = new MythUIButtonListItem(parent->m_pageList, "");
42 
53 }
54 
56 {
57  if (m_browser)
58  {
59  m_browser->disconnect();
61  m_browser = nullptr;
62  }
63 
64  if (m_listItem)
65  {
66  delete m_listItem;
67  m_listItem = nullptr;
68  }
69 }
70 
71 void WebPage::SetActive(bool active)
72 {
73  if (active)
74  {
75  m_browser->SetActive(true);
76  m_browser->Show();
77  }
78  else
79  {
80  m_browser->SetActive(false);
81  m_browser->Hide();
82  }
83 
84  m_active = active;
85 }
86 
88 {
89  if (!m_listItem)
90  return;
91 
92  QIcon icon = m_browser->GetIcon();
93 
94  if (icon.isNull())
95  {
97  m_listItem->SetImage(mimage, "favicon");
98  mimage->DecrRef();
99  }
100  else
101  {
102  QPixmap pixmap = icon.pixmap(32, 32);
103  QImage image = pixmap.toImage();
104  image = image.scaled(
105  QSize(32,32), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
106  MythImage *mimage = GetMythPainter()->GetFormatImage();
107  mimage->Assign(image);
108 
109  m_listItem->SetImage(mimage, "favicon");
110  mimage->DecrRef();
111  }
112 
114 }
115 
117 {
118  m_listItem->SetText(tr("Loading..."));
119  m_listItem->DisplayState("loading", "loadingstate");
120  m_listItem->SetImage(nullptr, "favicon");
121  m_listItem->SetImage("", "favicon");
122 
124 }
125 
127 {
128  m_listItem->DisplayState("off", "loadingstate");
129 
130  slotIconChanged();
131 
133 
134  emit loadFinished(OK);
135 }
136 
138 {
139  if (m_active)
140  emit loadProgress(progress);
141 }
142 
143 void WebPage::slotStatusBarMessage(const QString &text)
144 {
145  if (m_active)
146  emit statusBarMessage(text);
147 }
148 
149 void WebPage::slotTitleChanged(const QString &title)
150 {
151  m_listItem->SetText(title);
153 }
MythUIWebBrowser::SetActive
void SetActive(bool active)
Toggles the active state of the widget.
Definition: mythuiwebbrowser.cpp:1115
MythUIType::DeleteChild
void DeleteChild(const QString &name)
Delete a named child of this UIType.
Definition: mythuitype.cpp:153
WebPage::m_listItem
MythUIButtonListItem * m_listItem
Definition: webpage.h:51
MythUIButtonListItem::DisplayState
void DisplayState(const QString &state, const QString &name)
Definition: mythuibuttonlist.cpp:3613
MythUIWebBrowser::statusBarMessage
void statusBarMessage(const QString &text)
a pages title has changed
progress
bool progress
Definition: mythcommflag.cpp:60
WebPage::m_active
bool m_active
Definition: webpage.h:47
MythPainter::GetFormatImage
MythImage * GetFormatImage()
Returns a blank reference counted image in the format required for the Draw functions for this painte...
Definition: mythpainter.cpp:524
MythUIWebBrowser::loadProgress
void loadProgress(int progress)
a page has finished loading
MythUIType::SetArea
virtual void SetArea(const MythRect &rect)
Definition: mythuitype.cpp:610
MythUIWebBrowser::titleChanged
void titleChanged(const QString &title)
% of page loaded
WebPage::slotStatusBarMessage
void slotStatusBarMessage(const QString &text)
Definition: webpage.cpp:143
MythBrowser::GetDefaultFavIcon
MythImage * GetDefaultFavIcon(void)
Definition: mythbrowser.h:32
MythRect
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:17
WebPage::loadProgress
void loadProgress(int progress)
MythUIButtonListItem::SetText
void SetText(const QString &text, const QString &name="", const QString &state="")
Definition: mythuibuttonlist.cpp:3319
WebPage::slotLoadStarted
void slotLoadStarted(void)
Definition: webpage.cpp:116
MythUIButtonListItem
Definition: mythuibuttonlist.h:41
MythUIType::Show
void Show(void)
Definition: mythuitype.cpp:1144
MythUIType::Refresh
void Refresh(void)
Definition: mythuitype.cpp:1051
MythUIWebBrowser::GetIcon
QIcon GetIcon(void)
Gets the current page's fav icon.
Definition: mythuiwebbrowser.cpp:1263
MythUIButtonList::Update
void Update()
Definition: mythuibuttonlist.cpp:141
MythImage::DecrRef
int DecrRef(void) override
Decrements reference count and deletes on 0.
Definition: mythimage.cpp:52
MythUIWebBrowser::Init
void Init(void)
Initializes the widget ready for use.
Definition: mythuiwebbrowser.cpp:858
MythUIWebBrowser::loadStarted
void loadStarted(void)
MythUIWebBrowser::GetTitle
QString GetTitle(void)
Gets the current page's title.
Definition: mythuiwebbrowser.cpp:1289
WebPage::slotLoadProgress
void slotLoadProgress(int progress)
Definition: webpage.cpp:137
MythUIType::Hide
void Hide(void)
Definition: mythuitype.cpp:1139
webpage.h
WebPage::WebPage
WebPage(MythBrowser *parent, QRect area, const char *name)
Definition: webpage.cpp:15
MythUIWebBrowser::loadFinished
void loadFinished(bool ok)
a page is starting to load
MythBrowser
Definition: mythbrowser.h:18
WebPage::m_parent
MythBrowser * m_parent
Definition: webpage.h:49
MythUIButtonListItem::SetImage
void SetImage(MythImage *image, const QString &name="")
Sets an image directly, should only be used in special circumstances since it bypasses the cache.
Definition: mythuibuttonlist.cpp:3479
MythImage
Definition: mythimage.h:36
WebPage::SetActive
void SetActive(bool active)
Definition: webpage.cpp:71
WebPage::~WebPage
~WebPage() override
Definition: webpage.cpp:55
WebPage::slotTitleChanged
void slotTitleChanged(const QString &title)
Definition: webpage.cpp:149
OK
static constexpr int OK
Definition: dvbci.cpp:69
MythUIButtonListItem::CantCheck
@ CantCheck
Definition: mythuibuttonlist.h:45
MythBrowser::m_pageList
MythUIButtonList * m_pageList
Definition: mythbrowser.h:72
MythUIWebBrowser
Web browsing widget.
Definition: mythuiwebbrowser.h:132
WebPage::statusBarMessage
void statusBarMessage(const QString &text)
MythImage::Assign
void Assign(const QImage &img)
Definition: mythimage.cpp:77
GetMythPainter
MythPainter * GetMythPainter(void)
Definition: mythmainwindow.cpp:119
mythmainwindow.h
WebPage::slotIconChanged
void slotIconChanged(void)
Definition: webpage.cpp:87
WebPage::m_browser
MythUIWebBrowser * m_browser
Definition: webpage.h:50
WebPage::loadFinished
void loadFinished(bool OK)
mythbrowser.h
WebPage::slotLoadFinished
void slotLoadFinished(bool OK)
Definition: webpage.cpp:126