Skip to content

Commit

Permalink
allow to keep docks when expanding content area
Browse files Browse the repository at this point in the history
  • Loading branch information
tamlok committed May 18, 2021
1 parent b9ac16d commit 9ada45e
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 62 deletions.
30 changes: 30 additions & 0 deletions src/core/iconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <QSharedPointer>
#include <QJsonObject>
#include <QJsonArray>
#include <QBitArray>
#include <QDataStream>

namespace vnotex
{
Expand Down Expand Up @@ -137,6 +139,34 @@ namespace vnotex
p_obj.insert(p_key, QLatin1String(p_bytes.toBase64()));
}

static QBitArray readBitArray(const QJsonObject &p_obj,
const QString &p_key)
{
auto bytes = readByteArray(p_obj, p_key);
if (bytes.isEmpty()) {
return QBitArray();
}

QDataStream ds(bytes);
ds.setVersion(QDataStream::Qt_5_12);

QBitArray bits;
ds >> bits;
return bits;
}

static void writeBitArray(QJsonObject &p_obj,
const QString &p_key,
const QBitArray &p_bits)
{
QByteArray bytes;
QDataStream ds(&bytes, QIODevice::WriteOnly);
ds.setVersion(QDataStream::Qt_5_12);
ds << p_bits;

writeByteArray(p_obj, p_key, bytes);
}

static bool readBool(const QJsonObject &p_default,
const QJsonObject &p_user,
const QString &p_key)
Expand Down
2 changes: 2 additions & 0 deletions src/core/sessionconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ QJsonObject SessionConfig::saveStateAndGeometry() const
QJsonObject obj;
writeByteArray(obj, QStringLiteral("main_window_state"), m_mainWindowStateGeometry.m_mainState);
writeByteArray(obj, QStringLiteral("main_window_geometry"), m_mainWindowStateGeometry.m_mainGeometry);
writeBitArray(obj, QStringLiteral("docks_visibility_before_expand"), m_mainWindowStateGeometry.m_docksVisibilityBeforeExpand);
return obj;
}

Expand Down Expand Up @@ -318,6 +319,7 @@ void SessionConfig::loadStateAndGeometry(const QJsonObject &p_session)
const auto obj = p_session.value(QStringLiteral("state_geometry")).toObject();
m_mainWindowStateGeometry.m_mainState = readByteArray(obj, QStringLiteral("main_window_state"));
m_mainWindowStateGeometry.m_mainGeometry = readByteArray(obj, QStringLiteral("main_window_geometry"));
m_mainWindowStateGeometry.m_docksVisibilityBeforeExpand = readBitArray(obj, QStringLiteral("docks_visibility_before_expand"));
}

QByteArray SessionConfig::getViewAreaSessionAndClear()
Expand Down
6 changes: 5 additions & 1 deletion src/core/sessionconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ namespace vnotex
bool operator==(const MainWindowStateGeometry &p_other) const
{
return m_mainState == p_other.m_mainState
&& m_mainGeometry == p_other.m_mainGeometry;
&& m_mainGeometry == p_other.m_mainGeometry
&& m_docksVisibilityBeforeExpand == p_other.m_docksVisibilityBeforeExpand;
}

QByteArray m_mainState;

QByteArray m_mainGeometry;

QBitArray m_docksVisibilityBeforeExpand;
};

enum OpenGL
Expand Down
15 changes: 15 additions & 0 deletions src/core/widgetconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using namespace vnotex;

#define READINT(key) readInt(appObj, userObj, (key))
#define READBOOL(key) readBool(appObj, userObj, (key))
#define READSTRLIST(key) readStringList(appObj, userObj, (key))

WidgetConfig::WidgetConfig(ConfigMgr *p_mgr, IConfig *p_topConfig)
: IConfig(p_mgr, p_topConfig)
Expand All @@ -29,6 +30,7 @@ void WidgetConfig::init(const QJsonObject &p_app,
m_nodeExplorerExternalFilesVisible = READBOOL(QStringLiteral("node_explorer_external_files_visible"));
m_nodeExplorerAutoImportExternalFilesEnabled = READBOOL(QStringLiteral("node_explorer_auto_import_external_files_enabled"));
m_searchPanelAdvancedSettingsVisible = READBOOL(QStringLiteral("search_panel_advanced_settings_visible"));
m_mainWindowKeepDocksExpandingContentArea = READSTRLIST(QStringLiteral("main_window_keep_docks_expanding_content_area"));
}

QJsonObject WidgetConfig::toJson() const
Expand All @@ -41,6 +43,9 @@ QJsonObject WidgetConfig::toJson() const
obj[QStringLiteral("node_explorer_external_files_visible")] = m_nodeExplorerExternalFilesVisible;
obj[QStringLiteral("node_explorer_auto_import_external_files_enabled")] = m_nodeExplorerAutoImportExternalFilesEnabled;
obj[QStringLiteral("search_panel_advanced_settings_visible")] = m_searchPanelAdvancedSettingsVisible;
writeStringList(obj,
QStringLiteral("main_window_keep_docks_expanding_content_area"),
m_mainWindowKeepDocksExpandingContentArea);
return obj;
}

Expand Down Expand Up @@ -113,3 +118,13 @@ void WidgetConfig::setSearchPanelAdvancedSettingsVisible(bool p_visible)
{
updateConfig(m_searchPanelAdvancedSettingsVisible, p_visible, this);
}

const QStringList &WidgetConfig::getMainWindowKeepDocksExpandingContentArea() const
{
return m_mainWindowKeepDocksExpandingContentArea;
}

void WidgetConfig::setMainWindowKeepDocksExpandingContentArea(const QStringList &p_docks)
{
updateConfig(m_mainWindowKeepDocksExpandingContentArea, p_docks, this);
}
6 changes: 6 additions & 0 deletions src/core/widgetconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ namespace vnotex
bool isSearchPanelAdvancedSettingsVisible() const;
void setSearchPanelAdvancedSettingsVisible(bool p_visible);

const QStringList &getMainWindowKeepDocksExpandingContentArea() const;
void setMainWindowKeepDocksExpandingContentArea(const QStringList &p_docks);

private:
int m_outlineAutoExpandedLevel = 6;

Expand All @@ -53,6 +56,9 @@ namespace vnotex
bool m_nodeExplorerAutoImportExternalFilesEnabled = true;

bool m_searchPanelAdvancedSettingsVisible = true;

// Object name of those docks that should be kept when expanding content area.
QStringList m_mainWindowKeepDocksExpandingContentArea;
};
}

Expand Down
1 change: 0 additions & 1 deletion src/data/core/core.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<file>icons/expand.svg</file>
<file>icons/fullscreen.svg</file>
<file>icons/history_explorer.svg</file>
<file>icons/notebook_explorer.svg</file>
<file>icons/tag_explorer.svg</file>
<file>icons/help.svg</file>
<file>icons/menu.svg</file>
Expand Down
8 changes: 0 additions & 8 deletions src/data/core/icons/notebook_explorer.svg

This file was deleted.

4 changes: 3 additions & 1 deletion src/data/core/vnotex.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@
"node_explorer_recycle_bin_node_visible" : false,
"node_explorer_external_files_visible" : true,
"node_explorer_auto_import_external_files_enabled" : true,
"search_panel_advanced_settings_visible" : true
"search_panel_advanced_settings_visible" : true,
"//comment" : "Docks to ignore when expanding content area of main window",
"main_window_keep_docks_expanding_content_area": []
}
}
46 changes: 46 additions & 0 deletions src/widgets/dialogs/settings/appearancepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
#include <QCheckBox>
#include <QFormLayout>
#include <QSpinBox>
#include <QVBoxLayout>
#include <QDockWidget>

#include <widgets/widgetsfactory.h>
#include <core/sessionconfig.h>
#include <core/coreconfig.h>
#include <core/widgetconfig.h>
#include <core/configmgr.h>
#include <utils/widgetutils.h>
#include <widgets/mainwindow.h>
#include <core/vnotex.h>

using namespace vnotex;

Expand Down Expand Up @@ -45,30 +50,71 @@ void AppearancePage::setupUI()
connect(m_toolBarIconSizeSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
this, &AppearancePage::pageIsChanged);
}

{
const auto &docks = VNoteX::getInst().getMainWindow()->getDocks();
Q_ASSERT(!docks.isEmpty());
m_keepDocksExpandingContentArea.resize(docks.size());

auto layout = new QVBoxLayout();

for (int i = 0; i < docks.size(); ++i) {
m_keepDocksExpandingContentArea[i].first = WidgetsFactory::createCheckBox(docks[i]->windowTitle(), this);
m_keepDocksExpandingContentArea[i].second = docks[i]->objectName();
layout->addWidget(m_keepDocksExpandingContentArea[i].first);
connect(m_keepDocksExpandingContentArea[i].first, &QCheckBox::stateChanged,
this, &AppearancePage::pageIsChanged);
}

const QString label(tr("Keep dock widgets when expanding content area:"));
mainLayout->addRow(label, layout);
addSearchItem(label, label, m_keepDocksExpandingContentArea.first().first);
}
}

void AppearancePage::loadInternal()
{
const auto &sessionConfig = ConfigMgr::getInst().getSessionConfig();
const auto &coreConfig = ConfigMgr::getInst().getCoreConfig();
const auto &widgetConfig = ConfigMgr::getInst().getWidgetConfig();

if (m_systemTitleBarCheckBox) {
m_systemTitleBarCheckBox->setChecked(sessionConfig.getSystemTitleBarEnabled());
}

m_toolBarIconSizeSpinBox->setValue(coreConfig.getToolBarIconSize());

{
const auto &docks = widgetConfig.getMainWindowKeepDocksExpandingContentArea();
for (const auto &cb : m_keepDocksExpandingContentArea) {
if (docks.contains(cb.second)) {
cb.first->setChecked(true);
}
}
}
}

void AppearancePage::saveInternal()
{
auto &sessionConfig = ConfigMgr::getInst().getSessionConfig();
auto &coreConfig = ConfigMgr::getInst().getCoreConfig();
auto &widgetConfig = ConfigMgr::getInst().getWidgetConfig();

if (m_systemTitleBarCheckBox) {
sessionConfig.setSystemTitleBarEnabled(m_systemTitleBarCheckBox->isChecked());
}

coreConfig.setToolBarIconSize(m_toolBarIconSizeSpinBox->value());

{
QStringList docks;
for (const auto &cb : m_keepDocksExpandingContentArea) {
if (cb.first->isChecked()) {
docks << cb.second;
}
}
widgetConfig.setMainWindowKeepDocksExpandingContentArea(docks);
}
}

QString AppearancePage::title() const
Expand Down
6 changes: 6 additions & 0 deletions src/widgets/dialogs/settings/appearancepage.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include "settingspage.h"

#include <QVector>
#include <QPair>

class QCheckBox;
class QSpinBox;

Expand All @@ -27,6 +30,9 @@ namespace vnotex
QCheckBox *m_systemTitleBarCheckBox = nullptr;

QSpinBox *m_toolBarIconSizeSpinBox = nullptr;

// <CheckBox, ObjectName>.
QVector<QPair<QCheckBox *, QString>> m_keepDocksExpandingContentArea;
};
}

Expand Down
16 changes: 13 additions & 3 deletions src/widgets/dialogs/settings/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QStackedLayout>
#include <QScrollArea>

#include <widgets/treewidget.h>
#include <widgets/lineedit.h>
Expand All @@ -19,7 +20,7 @@
using namespace vnotex;

SettingsDialog::SettingsDialog(QWidget *p_parent)
: ScrollDialog(p_parent)
: Dialog(p_parent)
{
setupUI();

Expand All @@ -35,8 +36,16 @@ void SettingsDialog::setupUI()

setupPageExplorer(mainLayout, widget);

m_pageLayout = new QStackedLayout();
mainLayout->addLayout(m_pageLayout, 5);
{
auto scrollArea = new QScrollArea(widget);
scrollArea->setWidgetResizable(true);
mainLayout->addWidget(scrollArea, 5);

auto scrollWidget = new QWidget(scrollArea);
scrollArea->setWidget(scrollWidget);

m_pageLayout = new QStackedLayout(scrollWidget);
}

setDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Apply
Expand Down Expand Up @@ -116,6 +125,7 @@ void SettingsDialog::setupPages()

setChangesUnsaved(false);
m_pageExplorer->setCurrentItem(m_pageExplorer->topLevelItem(0), 0, QItemSelectionModel::ClearAndSelect);
m_pageExplorer->expandAll();
m_pageLayout->setCurrentIndex(0);

m_ready = true;
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/dialogs/settings/settingsdialog.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SETTINGSDIALOG_H
#define SETTINGSDIALOG_H

#include "../scrolldialog.h"
#include "../dialog.h"

#include <functional>

Expand All @@ -14,7 +14,7 @@ namespace vnotex
{
class SettingsPage;

class SettingsDialog : public ScrollDialog
class SettingsDialog : public Dialog
{
Q_OBJECT
public:
Expand Down
Loading

0 comments on commit 9ada45e

Please sign in to comment.