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
11 
12 // mythbrowser
13 #include "mythbrowser.h"
14 #include "webpage.h"
15 
16 WebPage::WebPage(MythBrowser *parent, QRect area, const char* name)
17 {
18  m_parent = parent;
19 
20  m_listItem = new MythUIButtonListItem(parent->m_pageList, "", "", false,
22 
23  m_browser = new MythUIWebBrowser(parent, name);
24  m_browser->SetArea(MythRect(area));
25  m_browser->Init();
26 
37 }
38 
40 {
41  m_parent = parent;
42 
43  m_listItem = new MythUIButtonListItem(parent->m_pageList, "");
44 
45  m_browser = browser;
46 
57 }
58 
60 {
61  if (m_browser)
62  {
63  m_browser->disconnect();
65  m_browser = nullptr;
66  }
67 
68  if (m_listItem)
69  {
70  delete m_listItem;
71  m_listItem = nullptr;
72  }
73 }
74 
75 void WebPage::SetActive(bool active)
76 {
77  if (active)
78  {
79  m_browser->SetActive(true);
80  m_browser->Show();
81  }
82  else
83  {
84  m_browser->SetActive(false);
85  m_browser->Hide();
86  }
87 
88  m_active = active;
89 }
90 
92 {
93  if (!m_listItem)
94  return;
95 
96  QIcon icon = m_browser->GetIcon();
97 
98  if (icon.isNull())
99  {
100  MythImage *mimage = m_parent->GetDefaultFavIcon();
101  m_listItem->SetImage(mimage, "favicon");
102  mimage->DecrRef();
103  }
104  else
105  {
106  QPixmap pixmap = icon.pixmap(32, 32);
107  QImage image = pixmap.toImage();
108  image = image.scaled(
109  QSize(32,32), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
110  MythImage *mimage = GetMythPainter()->GetFormatImage();
111  mimage->Assign(image);
112 
113  m_listItem->SetImage(mimage, "favicon");
114  mimage->DecrRef();
115  }
116 
118 }
119 
121 {
122  m_listItem->SetText(tr("Loading..."));
123  m_listItem->DisplayState("loading", "loadingstate");
124  m_listItem->SetImage(nullptr, "favicon");
125  m_listItem->SetImage("", "favicon");
126 
128 }
129 
131 {
132  m_listItem->DisplayState("off", "loadingstate");
133 
134  slotIconChanged();
135 
137 
138  emit loadFinished(OK);
139 }
140 
142 {
143  if (m_active)
144  emit loadProgress(progress);
145 }
146 
147 void WebPage::slotStatusBarMessage(const QString &text)
148 {
149  if (m_active)
150  emit statusBarMessage(text);
151 }
152 
153 void WebPage::slotTitleChanged(const QString &title)
154 {
155  m_listItem->SetText(title);
157 }
MythUIWebBrowser::SetActive
void SetActive(bool active)
Toggles the active state of the widget.
Definition: mythuiwebbrowser.cpp:1117
MythUIType::DeleteChild
void DeleteChild(const QString &name)
Delete a named child of this UIType.
Definition: mythuitype.cpp:148
WebPage::m_listItem
MythUIButtonListItem * m_listItem
Definition: webpage.h:51
MythUIButtonListItem::DisplayState
void DisplayState(const QString &state, const QString &name)
Definition: mythuibuttonlist.cpp:3563
MythUIWebBrowser::statusBarMessage
void statusBarMessage(const QString &text)
a pages title has changed
progress
bool progress
Definition: mythcommflag.cpp:69
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:534
MythUIWebBrowser::loadProgress
void loadProgress(int progress)
a page has finished loading
MythUIType::SetArea
virtual void SetArea(const MythRect &rect)
Definition: mythuitype.cpp:609
MythUIWebBrowser::titleChanged
void titleChanged(const QString &title)
% of page loaded
WebPage::slotStatusBarMessage
void slotStatusBarMessage(const QString &text)
Definition: webpage.cpp:147
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:3268
WebPage::slotLoadStarted
void slotLoadStarted(void)
Definition: webpage.cpp:120
MythUIButtonListItem
Definition: mythuibuttonlist.h:41
MythUIButtonListItem::CantCheck
@ CantCheck
Definition: mythuibuttonlist.h:45
MythUIType::Show
void Show(void)
Definition: mythuitype.cpp:1147
mythlogging.h
MythUIType::Refresh
void Refresh(void)
Definition: mythuitype.cpp:1054
MythUIWebBrowser::GetIcon
QIcon GetIcon(void)
Gets the current page's fav icon.
Definition: mythuiwebbrowser.cpp:1271
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:860
MythUIWebBrowser::loadStarted
void loadStarted(void)
MythUIWebBrowser::GetTitle
QString GetTitle(void)
Gets the current page's title.
Definition: mythuiwebbrowser.cpp:1297
WebPage::slotLoadProgress
void slotLoadProgress(int progress)
Definition: webpage.cpp:141
MythUIType::Hide
void Hide(void)
Definition: mythuitype.cpp:1142
webpage.h
WebPage::WebPage
WebPage(MythBrowser *parent, QRect area, const char *name)
Definition: webpage.cpp:16
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:3429
MythImage
Definition: mythimage.h:36
WebPage::SetActive
void SetActive(bool active)
Definition: webpage.cpp:75
WebPage::~WebPage
~WebPage() override
Definition: webpage.cpp:59
WebPage::slotTitleChanged
void slotTitleChanged(const QString &title)
Definition: webpage.cpp:153
OK
static constexpr int OK
Definition: dvbci.cpp:69
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:91
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:130