Commit 1e0bc163 authored by Hadi Charara's avatar Hadi Charara
Browse files

Initial Commit

parent 5e79f27a
Pipeline #66622 passed with stage
in 4 minutes and 55 seconds
......@@ -235,6 +235,7 @@ target_sources(dolphinstatic PRIVATE
panels/folders/treeviewcontextmenu.cpp
panels/folders/folderspanel.cpp
panels/terminal/terminalpanel.cpp
panels/readme/readmepanel.cpp
search/dolphinfacetswidget.cpp
search/dolphinquery.cpp
search/dolphinsearchbox.cpp
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -43,6 +43,7 @@ class KToolBarPopupAction;
class QToolButton;
class PlacesPanel;
class TerminalPanel;
class ReadmePanel;
namespace KIO {
class OpenUrlJob;
......@@ -113,6 +114,7 @@ public:
bool isFoldersPanelEnabled() const;
bool isInformationPanelEnabled() const;
bool isReadmePanelEnabled() const;
public Q_SLOTS:
/**
......@@ -666,6 +668,7 @@ private:
TerminalPanel* m_terminalPanel;
PlacesPanel* m_placesPanel;
ReadmePanel* m_readmePanel;
bool m_tearDownFromPlacesRequested;
KToolBarPopupAction* m_backAction;
......
#include "readmepanel.h"
#include <qevent.h>
#include <kservice.h>
#include <KParts/ReadOnlyPart>
#include <QVBoxLayout>
#include <QFileInfo>
#include <QtWidgets>
ReadmePanel::ReadmePanel ( QWidget* parent ) :
Panel(parent),
m_layout(nullptr),
m_readmeWidget(nullptr),
m_markdownPart(nullptr),
m_readmeUrl()
{
m_layout = new QVBoxLayout(this);
m_layout->setContentsMargins(0, 0, 0, 0);
}
void ReadmePanel::showEvent ( QShowEvent* event )
{
if (!m_markdownPart) {
KPluginFactory* factory = nullptr;
KService::Ptr service = KService::serviceByDesktopName(QStringLiteral("markdownpart"));
if (service) {
factory = KPluginLoader(service->library()).factory();
}
m_markdownPart = factory ? (factory->create<KParts::ReadOnlyPart>(this)) : nullptr;
m_readmeWidget = m_markdownPart->widget();
configureTextBrowser(m_readmeWidget->findChild<QTextBrowser *>());
setFocusProxy(m_readmeWidget);
m_layout->addWidget(m_readmeWidget);
}
Panel::showEvent(event);
}
inline void ReadmePanel::configureTextBrowser(QTextBrowser* browser)
{
browser->setFrameStyle(0);
browser->setStyleSheet("QTextEdit { background-color: transparent; }");
browser->scroll(0, 0);
}
void ReadmePanel::hideEvent(QHideEvent* event) {
if(m_markdownPart)
m_markdownPart->closeUrl();
}
bool ReadmePanel::urlChanged()
{
m_readmeUrl = QUrl(url().toString().append("/README.md"));
QFileInfo check_file(m_readmeUrl.path());
if (!m_readmeUrl.isValid() || !check_file.exists()) {
this->hide();
return false;
}
this->show();
m_markdownPart->openUrl(m_readmeUrl);
return true;
}
#ifndef READMEPANEL_H
#define READMEPANEL_H
#include "panels/panel.h"
#include <QTextBrowser>
class QVBoxLayout;
class QWidget;
namespace KParts {
class ReadOnlyPart;
}
/**
* @brief Shows a preview of README.md if it is located in the current folder.
*/
class ReadmePanel : public Panel
{
Q_OBJECT
public:
explicit ReadmePanel(QWidget* parent = nullptr);
~ReadmePanel() override = default;
protected:
bool urlChanged() override;
void showEvent(QShowEvent* event) override;
void hideEvent(QHideEvent* event) override;
private:
inline void configureTextBrowser(QTextBrowser* browser);
private:
QVBoxLayout* m_layout;
QWidget* m_readmeWidget;
KParts::ReadOnlyPart* m_markdownPart;
QUrl m_readmeUrl;
};
#endif // READMEPANEL_H
......@@ -46,6 +46,7 @@ QVariant SettingsDataSource::data()
if (m_mainWindow) {
map.insert(QStringLiteral("informationPanelEnabled"), m_mainWindow->isInformationPanelEnabled());
map.insert(QStringLiteral("foldersPanelEnabled"), m_mainWindow->isFoldersPanelEnabled());
map.insert(QStringLiteral("readmePanelEnabled"), m_mainWindow->isReadmePanelEnabled());
}
map.insert(QStringLiteral("tooltipsEnabled"), GeneralSettings::showToolTips());
......
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