Commit 56f5e1fd authored by Hadi Charara's avatar Hadi Charara
Browse files

Panel Activation logic fixed.

I can now be enabled while hidden from view.
parent 391ca9d5
Pipeline #66670 passed with stage
in 5 minutes and 30 seconds
......@@ -290,6 +290,7 @@ kconfig_add_kcfg_files(dolphinstatic
panels/folders/dolphin_folderspanelsettings.kcfgc
panels/information/dolphin_informationpanelsettings.kcfgc
panels/places/dolphin_placespanelsettings.kcfgc
panels/readme/dolphin_readmepanelsettings.kcfgc
settings/dolphin_compactmodesettings.kcfgc
settings/dolphin_detailsmodesettings.kcfgc
settings/dolphin_contextmenusettings.kcfgc
......
......@@ -1984,7 +1984,7 @@ void DolphinMainWindow::setupDockWidgets()
// Setup "README.md Preview"
if ( KService::serviceByDesktopName ( "markdownpart" ) ) {
DolphinDockWidget* readmeDock = new DolphinDockWidget ( i18nc ( "@title:window", "README.md Previewer" ) );
DolphinDockWidget* readmeDock = new DolphinDockWidget ( i18nc ( "@title:window", "README.md Preview" ) );
readmeDock->setLocked ( lock );
readmeDock->setObjectName ( QStringLiteral ( "readmeDock" ) );
m_readmePanel = new ReadmePanel ( readmeDock );
......@@ -1993,10 +1993,9 @@ void DolphinMainWindow::setupDockWidgets()
m_readmePanel, &ReadmePanel::setUrl );
readmeDock->setAllowedAreas(Qt::BottomDockWidgetArea | Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
QAction* readmeAction = readmeDock->toggleViewAction();
createPanelAction ( QIcon::fromTheme ( QStringLiteral ( "text-x-readme" ) ), QKeySequence(), readmeAction, QStringLiteral ( "show_readme_panel" ) );
createPanelAction ( QIcon::fromTheme ( QStringLiteral ( "text-x-readme" ) ), QKeySequence(), m_readmePanel->toggleViewAction.get(), QStringLiteral ( "show_readme_panel" ) );
addDockWidget ( Qt::BottomDockWidgetArea, readmeDock );
addDockWidget ( Qt::RightDockWidgetArea, readmeDock );
if ( GeneralSettings::version() < 200 )
readmeDock->hide();
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE kcfg SYSTEM "http://www.kde.org/standards/kcfg/1.0/kcfg.dtd">
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
<kcfgfile name="dolphinrc"/>
<group name="ReadmePanel">
<entry name="enabled" type="Bool">
<label>Whether the README.md Preview Panel is enabled.</label>
<default>false</default>
</entry>
</group>
</kcfg>
File=dolphin_readmepanelsettings.kcfg
ClassName=ReadmePanelSettings
Singleton=true
Mutators=true
......@@ -6,8 +6,11 @@
#include <QFileInfo>
#include <QtWidgets>
#include "dolphin_readmepanelsettings.h"
ReadmePanel::ReadmePanel ( QWidget* parent ) :
Panel(parent),
toggleViewAction(QSharedPointer<QAction>(new QAction(this))),
m_layout(nullptr),
m_readmeWidget(nullptr),
m_markdownPart(nullptr),
......@@ -16,9 +19,25 @@ ReadmePanel::ReadmePanel ( QWidget* parent ) :
{
m_layout = new QVBoxLayout(this);
m_layout->setContentsMargins(0, 0, 0, 0);
toggleViewAction->setCheckable(true);
toggleViewAction->setMenuRole(QAction::NoRole);
toggleViewAction->setText("README.md Preview");
toggleViewAction->setChecked(ReadmePanelSettings::enabled());
connect(toggleViewAction.get(), SIGNAL(triggered(bool)),
this, SLOT(toggleView(bool)));
}
void ReadmePanel::toggleView(bool b)
{
ReadmePanelSettings::setEnabled(b);
if (b)
urlChanged();
else
hide();
}
void ReadmePanel::showEvent ( QShowEvent* event )
void ReadmePanel::show()
{
if (!m_markdownPart) {
KPluginFactory* factory = nullptr;
......@@ -32,8 +51,6 @@ void ReadmePanel::showEvent ( QShowEvent* event )
setFocusProxy(m_readmeWidget);
m_layout->addWidget(m_readmeWidget);
}
Panel::showEvent(event);
}
inline void ReadmePanel::configureTextBrowser()
......@@ -46,19 +63,21 @@ inline void ReadmePanel::configureTextBrowser()
}
void ReadmePanel::hideEvent(QHideEvent* event) {
void ReadmePanel::hide() {
if(m_markdownPart)
m_markdownPart->closeUrl();
this->parentWidget()->hide();
}
bool ReadmePanel::urlChanged()
{
m_readmeUrl.setUrl((url().toString().append("/README.md")));
QFileInfo check_file(m_readmeUrl.path());
if (!m_readmeUrl.isValid() || !check_file.exists()) {
this->parentWidget()->hide();
if (!m_readmeUrl.isValid() || !check_file.exists() || !toggleViewAction->isChecked()) {
hide();
return true;
}
show();
this->parentWidget()->show();
m_markdownPart->openUrl(m_readmeUrl);
return true;
......
......@@ -8,7 +8,7 @@ class QVBoxLayout;
class QWidget;
namespace KParts {
class ReadOnlyPart;
class ReadOnlyPart;
}
/**
* @brief Shows a preview of README.md if it is located in the current folder.
......@@ -20,17 +20,22 @@ class ReadmePanel : public Panel
public:
explicit ReadmePanel(QWidget* parent = nullptr);
~ReadmePanel() override = default;
QSharedPointer<QAction> toggleViewAction;
public Q_SLOTS:
void toggleView(bool);
Q_SIGNALS:
void triggered(bool checked = false);
protected:
bool urlChanged() override;
void showEvent(QShowEvent* event) override;
void hideEvent(QHideEvent* event) override;
void show();
void hide();
private:
inline void configureTextBrowser();
private:
QVBoxLayout* m_layout;
QWidget* m_readmeWidget;
KParts::ReadOnlyPart* m_markdownPart;
......
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