Commit b3df7c60 authored by Hadi Charara's avatar Hadi Charara
Browse files

Better show/hide logic

parent 8a5f426c
Pipeline #66655 passed with stage
in 5 minutes and 53 seconds
...@@ -11,7 +11,8 @@ ReadmePanel::ReadmePanel ( QWidget* parent ) : ...@@ -11,7 +11,8 @@ ReadmePanel::ReadmePanel ( QWidget* parent ) :
m_layout(nullptr), m_layout(nullptr),
m_readmeWidget(nullptr), m_readmeWidget(nullptr),
m_markdownPart(nullptr), m_markdownPart(nullptr),
m_readmeUrl() m_readmeUrl(),
m_textBrowser(nullptr)
{ {
m_layout = new QVBoxLayout(this); m_layout = new QVBoxLayout(this);
m_layout->setContentsMargins(0, 0, 0, 0); m_layout->setContentsMargins(0, 0, 0, 0);
...@@ -27,7 +28,7 @@ void ReadmePanel::showEvent ( QShowEvent* event ) ...@@ -27,7 +28,7 @@ void ReadmePanel::showEvent ( QShowEvent* event )
} }
m_markdownPart = factory ? (factory->create<KParts::ReadOnlyPart>(this)) : nullptr; m_markdownPart = factory ? (factory->create<KParts::ReadOnlyPart>(this)) : nullptr;
m_readmeWidget = m_markdownPart->widget(); m_readmeWidget = m_markdownPart->widget();
configureTextBrowser(m_readmeWidget->findChild<QTextBrowser *>()); configureTextBrowser();
setFocusProxy(m_readmeWidget); setFocusProxy(m_readmeWidget);
m_layout->addWidget(m_readmeWidget); m_layout->addWidget(m_readmeWidget);
} }
...@@ -35,11 +36,13 @@ void ReadmePanel::showEvent ( QShowEvent* event ) ...@@ -35,11 +36,13 @@ void ReadmePanel::showEvent ( QShowEvent* event )
Panel::showEvent(event); Panel::showEvent(event);
} }
inline void ReadmePanel::configureTextBrowser(QTextBrowser* browser) inline void ReadmePanel::configureTextBrowser()
{ {
browser->setFrameStyle(0); if(!m_textBrowser)
browser->setStyleSheet("QTextEdit { background-color: transparent; }"); m_textBrowser = m_readmeWidget->findChild<QTextBrowser *>();
browser->scroll(0, 0); if(!m_textBrowser) return;
m_textBrowser->setFrameStyle(0);
m_textBrowser->setStyleSheet("QTextEdit { background-color: transparent; }");
} }
...@@ -53,10 +56,10 @@ bool ReadmePanel::urlChanged() ...@@ -53,10 +56,10 @@ bool ReadmePanel::urlChanged()
m_readmeUrl = QUrl(url().toString().append("/README.md")); m_readmeUrl = QUrl(url().toString().append("/README.md"));
QFileInfo check_file(m_readmeUrl.path()); QFileInfo check_file(m_readmeUrl.path());
if (!m_readmeUrl.isValid() || !check_file.exists()) { if (!m_readmeUrl.isValid() || !check_file.exists()) {
this->hide(); this->parentWidget()->hide();
return false; return false;
} }
this->show(); this->parentWidget()->show();
m_markdownPart->openUrl(m_readmeUrl); m_markdownPart->openUrl(m_readmeUrl);
return true; return true;
} }
...@@ -28,13 +28,14 @@ protected: ...@@ -28,13 +28,14 @@ protected:
void hideEvent(QHideEvent* event) override; void hideEvent(QHideEvent* event) override;
private: private:
inline void configureTextBrowser(QTextBrowser* browser); inline void configureTextBrowser();
private: private:
QVBoxLayout* m_layout; QVBoxLayout* m_layout;
QWidget* m_readmeWidget; QWidget* m_readmeWidget;
KParts::ReadOnlyPart* m_markdownPart; KParts::ReadOnlyPart* m_markdownPart;
QUrl m_readmeUrl; QUrl m_readmeUrl;
QTextBrowser* m_textBrowser;
}; };
#endif // READMEPANEL_H #endif // READMEPANEL_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment