┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/settings/interface/statusandlocationbarssettingspage.cpp
blob: 1ab292ab56d89416576e491209cb0bea290af46a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 * SPDX-FileCopyrightText: 2023 Dimosthenis Krallis <[email protected]>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "statusandlocationbarssettingspage.h"
#include "dolphinmainwindow.h"
#include "dolphinviewcontainer.h"
#include "settings/interface/folderstabssettingspage.h"

#include <KLocalizedString>

#include <QCheckBox>
#include <QFormLayout>

#include <QButtonGroup>
#include <QRadioButton>
#include <QSpacerItem>
#include <QStyle>
#include <QStyleOption>

StatusAndLocationBarsSettingsPage::StatusAndLocationBarsSettingsPage(QWidget *parent, FoldersTabsSettingsPage *foldersPage)
    : SettingsPageBase(parent)
    , m_editableUrl(nullptr)
    , m_showFullPath(nullptr)
    , m_statusBarButtonGroup(nullptr)
    , m_showStatusBarSmall(nullptr)
    , m_showStatusBarFullWidth(nullptr)
    , m_showZoomSlider(nullptr)
    , m_disableStatusBar(nullptr)
{
    // We need to update some urls at the Folders & Tabs tab. We get that from foldersPage and set it on a private attribute
    // foldersTabsPage. That way, we can modify the necessary stuff from here. Specifically, any changes on locationUpdateInitialViewOptions()
    // which is a copy of updateInitialViewOptions() on Folders & Tabs.
    foldersTabsPage = foldersPage;

    QFormLayout *topLayout = new QFormLayout(this);
    topLayout->setFormAlignment(Qt::AlignHCenter);

    // Status bar
    m_statusBarButtonGroup = new QButtonGroup(this);
    m_showStatusBarSmall = new QRadioButton(i18nc("@option:radio", "Small"), this);
    m_showStatusBarFullWidth = new QRadioButton(i18nc("@option:radio", "Full width"), this);
    m_showZoomSlider = new QCheckBox(i18nc("@option:check", "Show zoom slider"), this);
    m_disableStatusBar = new QRadioButton(i18nc("@option:check", "Disabled"), this);

    m_statusBarButtonGroup->addButton(m_showStatusBarSmall, GeneralSettings::EnumShowStatusBar::Small);
    m_statusBarButtonGroup->addButton(m_showStatusBarFullWidth, GeneralSettings::EnumShowStatusBar::FullWidth);
    m_statusBarButtonGroup->addButton(m_disableStatusBar, GeneralSettings::EnumShowStatusBar::Disabled);

    topLayout->addRow(i18nc("@title:group", "Status Bar:"), m_showStatusBarSmall);
    topLayout->addRow(QString(), m_showStatusBarFullWidth);

    // Indent the m_showZoomSlider checkbox under m_showStatusBarFullWidth.
    QHBoxLayout *zoomSliderLayout = new QHBoxLayout;
    QStyleOption opt;
    opt.initFrom(this);
    zoomSliderLayout->addItem(
        new QSpacerItem(style()->pixelMetric(QStyle::PM_IndicatorWidth, &opt, this), Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed));
    zoomSliderLayout->addWidget(m_showZoomSlider);

    topLayout->addRow(QString(), zoomSliderLayout);

    topLayout->addRow(QString(), m_disableStatusBar);
    topLayout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed));

    // Location bar
    m_editableUrl = new QCheckBox(i18nc("@option:check Startup Settings", "Make location bar editable"));
    topLayout->addRow(i18n("Location bar:"), m_editableUrl);

    m_showFullPath = new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar"));
    topLayout->addRow(QString(), m_showFullPath);

    loadSettings();

    locationUpdateInitialViewOptions();

    connect(m_editableUrl, &QCheckBox::toggled, this, &StatusAndLocationBarsSettingsPage::locationSlotSettingsChanged);
    connect(m_showFullPath, &QCheckBox::toggled, this, &StatusAndLocationBarsSettingsPage::locationSlotSettingsChanged);

    connect(m_statusBarButtonGroup, &QButtonGroup::idClicked, this, &StatusAndLocationBarsSettingsPage::changed);
    connect(m_statusBarButtonGroup, &QButtonGroup::idClicked, this, &StatusAndLocationBarsSettingsPage::onShowStatusBarToggled);
    connect(m_showZoomSlider, &QCheckBox::toggled, this, &StatusAndLocationBarsSettingsPage::changed);
}

StatusAndLocationBarsSettingsPage::~StatusAndLocationBarsSettingsPage() = default;

void StatusAndLocationBarsSettingsPage::applySettings()
{
    GeneralSettings *settings = GeneralSettings::self();

    settings->setEditableUrl(m_editableUrl->isChecked());
    settings->setShowFullPath(m_showFullPath->isChecked());

    settings->setShowStatusBar(m_statusBarButtonGroup->checkedId());
    settings->setShowZoomSlider(m_showZoomSlider->isChecked());

    settings->save();
}

void StatusAndLocationBarsSettingsPage::onShowStatusBarToggled()
{
    const bool checked = (m_statusBarButtonGroup->checkedId() == GeneralSettings::EnumShowStatusBar::FullWidth);
    m_showZoomSlider->setEnabled(checked);
}

void StatusAndLocationBarsSettingsPage::restoreDefaults()
{
    GeneralSettings *settings = GeneralSettings::self();
    settings->useDefaults(true);
    loadSettings();
    settings->useDefaults(false);
}

void StatusAndLocationBarsSettingsPage::locationSlotSettingsChanged()
{
    // Provide a hint that the startup settings have been changed. This allows the views
    // to apply the startup settings only if they have been explicitly changed by the user
    // (see bug #254947).
    GeneralSettings::setModifiedStartupSettings(true);

    // Enable and disable home URL controls appropriately
    locationUpdateInitialViewOptions();
    Q_EMIT changed();
}

void StatusAndLocationBarsSettingsPage::locationUpdateInitialViewOptions()
{
    foldersTabsPage->m_homeUrlBoxLayoutContainer->setEnabled(foldersTabsPage->m_homeUrlRadioButton->isChecked());
    foldersTabsPage->m_buttonBoxLayoutContainer->setEnabled(foldersTabsPage->m_homeUrlRadioButton->isChecked());
}

void StatusAndLocationBarsSettingsPage::loadSettings()
{
    m_editableUrl->setChecked(GeneralSettings::editableUrl());
    m_showFullPath->setChecked(GeneralSettings::showFullPath());
    m_statusBarButtonGroup->button(GeneralSettings::showStatusBar())->setChecked(true);
    m_showZoomSlider->setChecked(GeneralSettings::showZoomSlider());

    onShowStatusBarToggled();
}

#include "moc_statusandlocationbarssettingspage.cpp"