Changeset View
Changeset View
Standalone View
Standalone View
src/HistorySizeWidget.cpp
Show All 14 Lines | 1 | /* | |||
---|---|---|---|---|---|
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
18 | 02110-1301 USA. | 18 | 02110-1301 USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | // Own | 21 | // Own | ||
22 | #include "HistorySizeWidget.h" | 22 | #include "HistorySizeWidget.h" | ||
23 | #include "KonsoleSettings.h" | ||||
23 | 24 | | |||
24 | // Qt | 25 | // Qt | ||
25 | #include <QButtonGroup> | 26 | #include <QButtonGroup> | ||
26 | #include <QAbstractButton> | 27 | #include <QAbstractButton> | ||
27 | #include <QToolTip> | 28 | #include <QToolTip> | ||
28 | #include <QWhatsThis> | 29 | #include <QWhatsThis> | ||
29 | 30 | | |||
30 | #include <KLocalizedString> | 31 | #include <KLocalizedString> | ||
32 | #include <KConfigDialogManager> | ||||
31 | 33 | | |||
32 | // Konsole | 34 | // Konsole | ||
33 | #include "ui_HistorySizeWidget.h" | 35 | #include "ui_HistorySizeWidget.h" | ||
34 | 36 | | |||
35 | using namespace Konsole; | 37 | using namespace Konsole; | ||
36 | 38 | | |||
37 | HistorySizeWidget::HistorySizeWidget(QWidget *parent) : | 39 | HistorySizeWidget::HistorySizeWidget(QWidget *parent) : | ||
38 | QWidget(parent), | 40 | QWidget(parent), | ||
39 | _ui(nullptr) | 41 | _ui(new Ui::HistorySizeWidget()) | ||
40 | { | 42 | { | ||
41 | _ui = new Ui::HistorySizeWidget(); | | |||
42 | _ui->setupUi(this); | 43 | _ui->setupUi(this); | ||
43 | 44 | | |||
44 | // focus and select the spinner automatically when appropriate | 45 | // focus and select the spinner automatically when appropriate | ||
45 | _ui->fixedSizeHistoryButton->setFocusProxy(_ui->historyLineSpinner); | 46 | _ui->fixedSizeHistoryButton->setFocusProxy(_ui->historyLineSpinner); | ||
46 | connect(_ui->fixedSizeHistoryButton, &QRadioButton::clicked, | 47 | connect(_ui->fixedSizeHistoryButton, &QRadioButton::clicked, | ||
47 | _ui->historyLineSpinner, | 48 | _ui->historyLineSpinner, &KPluralHandlingSpinBox::selectAll); | ||
48 | &KPluralHandlingSpinBox::selectAll); | | |||
49 | 49 | | |||
50 | auto modeGroup = new QButtonGroup(this); | 50 | for(auto *widget : {_ui->noHistoryButton, _ui->fixedSizeHistoryButton, _ui->unlimitedHistoryButton}) { | ||
51 | modeGroup->addButton(_ui->noHistoryButton); | 51 | connect(widget, &QRadioButton::clicked, this, [this]{ emit historyModeChanged(mode()); }); | ||
52 | modeGroup->addButton(_ui->fixedSizeHistoryButton); | 52 | } | ||
53 | modeGroup->addButton(_ui->unlimitedHistoryButton); | | |||
54 | connect(modeGroup, | | |||
55 | static_cast<void (QButtonGroup::*)(QAbstractButton *)>(&QButtonGroup::buttonClicked), | | |||
56 | this, &Konsole::HistorySizeWidget::buttonClicked); | | |||
57 | 53 | | |||
58 | _ui->historyLineSpinner->setSuffix(ki18ncp("@label:textbox Unit of scrollback", " line", " lines")); | 54 | _ui->historyLineSpinner->setSuffix(ki18ncp("@label:textbox Unit of scrollback", " line", " lines")); | ||
59 | setLineCount(HistorySizeWidget::DefaultLineCount); | 55 | setLineCount(HistorySizeWidget::DefaultLineCount); | ||
60 | 56 | | |||
61 | connect(_ui->historyLineSpinner, | 57 | connect(_ui->historyLineSpinner, | ||
62 | static_cast<void (KPluralHandlingSpinBox::*)(int)>(&KPluralHandlingSpinBox::valueChanged), | 58 | static_cast<void (KPluralHandlingSpinBox::*)(int)>(&KPluralHandlingSpinBox::valueChanged), | ||
63 | this, &Konsole::HistorySizeWidget::historySizeChanged); | 59 | this, &Konsole::HistorySizeWidget::historySizeChanged); | ||
64 | 60 | | |||
65 | auto warningButtonSizePolicy = _ui->fixedSizeHistoryWarningButton->sizePolicy(); | 61 | auto warningButtonSizePolicy = _ui->fixedSizeHistoryWarningButton->sizePolicy(); | ||
66 | warningButtonSizePolicy.setRetainSizeWhenHidden(true); | 62 | warningButtonSizePolicy.setRetainSizeWhenHidden(true); | ||
67 | 63 | | |||
68 | _ui->fixedSizeHistoryWarningButton->setSizePolicy(warningButtonSizePolicy); | 64 | _ui->fixedSizeHistoryWarningButton->setSizePolicy(warningButtonSizePolicy); | ||
69 | _ui->fixedSizeHistoryWarningButton->hide(); | 65 | _ui->fixedSizeHistoryWarningButton->hide(); | ||
70 | connect(_ui->fixedSizeHistoryButton, &QAbstractButton::toggled, _ui->historyLineSpinner, &QWidget::setEnabled); | 66 | connect(_ui->fixedSizeHistoryButton, &QAbstractButton::toggled, [this] (bool toggled) { | ||
71 | connect(_ui->fixedSizeHistoryButton, &QAbstractButton::toggled, _ui->fixedSizeHistoryWarningButton, &QWidget::setVisible); | 67 | _ui->historyLineSpinner->setEnabled(toggled); | ||
68 | _ui->fixedSizeHistoryWarningButton->setVisible(toggled); | ||||
69 | }); | ||||
70 | | ||||
72 | connect(_ui->fixedSizeHistoryWarningButton, &QToolButton::clicked, this, [this](bool) { | 71 | connect(_ui->fixedSizeHistoryWarningButton, &QToolButton::clicked, this, [this](bool) { | ||
73 | const QString message = i18nc("@info:whatsthis", "When using this option, the scrollback data will be saved to RAM. If you choose a huge value, your system may run out of free RAM and cause serious issues with your system."); | 72 | const QString message = i18nc("@info:whatsthis", | ||
74 | const QPoint pos = QPoint(_ui->fixedSizeHistoryWrapper->width() / 2, _ui->fixedSizeHistoryWrapper->height()); | 73 | "When using this option, the scrollback data will be saved to RAM." | ||
75 | QWhatsThis::showText(_ui->fixedSizeHistoryWrapper->mapToGlobal(pos), message, _ui->fixedSizeHistoryWrapper); | 74 | " If you choose a huge value, your system may run out of free RAM " | ||
75 | "and cause serious issues with your system."); | ||||
76 | | ||||
77 | const QPoint pos = QPoint(_ui->fixedSizeHistoryWarningButton->width() / 2, _ui->fixedSizeHistoryWarningButton->height()); | ||||
78 | QWhatsThis::showText(_ui->fixedSizeHistoryWarningButton->mapToGlobal(pos), message, _ui->fixedSizeHistoryWarningButton); | ||||
76 | }); | 79 | }); | ||
77 | 80 | | |||
78 | _ui->unlimitedHistoryWarningButton->setSizePolicy(warningButtonSizePolicy); | 81 | _ui->unlimitedHistoryWarningButton->setSizePolicy(warningButtonSizePolicy); | ||
79 | _ui->unlimitedHistoryWarningButton->hide(); | 82 | _ui->unlimitedHistoryWarningButton->hide(); | ||
80 | connect(_ui->unlimitedHistoryButton, &QAbstractButton::toggled, _ui->unlimitedHistoryWarningButton, &QWidget::setVisible); | 83 | connect(_ui->unlimitedHistoryButton, &QAbstractButton::toggled, [this](bool toggled) { | ||
81 | connect(_ui->unlimitedHistoryWarningButton, &QToolButton::clicked, this, [this](bool) { | 84 | _ui->unlimitedHistoryWarningButton->setVisible(toggled); | ||
82 | const auto message = xi18nc("@info:tooltip", "When using this option, the scrollback data will be written unencrypted to temporary files. Those temporary files will be deleted automatically when Konsole is closed in a normal manner.<nl/>Use <emphasis>Settings → Configure Konsole → File Location</emphasis> to select the location of the temporary files."); | 85 | _ui->unlimitedHistoryGroupBox->setVisible(!_temporary && toggled); | ||
83 | const QPoint pos = QPoint(_ui->unlimitedHistoryWrapper->width() / 2, _ui->unlimitedHistoryWrapper->height()); | | |||
84 | QWhatsThis::showText(_ui->unlimitedHistoryWrapper->mapToGlobal(pos), message, _ui->unlimitedHistoryWrapper); | | |||
85 | }); | 86 | }); | ||
86 | 87 | | |||
87 | // Make radio buttons height equal | 88 | connect(_ui->unlimitedHistoryWarningButton, &QToolButton::clicked, this, [this](bool) { | ||
88 | // fixedSizeHistoryWrapper contains radio + spinbox + toolbutton, so it | 89 | const auto message = xi18nc("@info:tooltip", | ||
89 | // has height always equal to or larger than single radio button, and | 90 | "When using this option, the scrollback data will be written unencrypted to " | ||
90 | // radio + toolbutton | 91 | "temporary files. Those temporary files will be deleted automatically when " | ||
91 | const int radioButtonHeight = _ui->fixedSizeHistoryWrapper->sizeHint().height(); | 92 | "Konsole is closed in a normal manner."); | ||
92 | _ui->noHistoryButton->setMinimumHeight(radioButtonHeight); | 93 | const QPoint pos = QPoint(_ui->unlimitedHistoryWarningButton->width() / 2, _ui->unlimitedHistoryWarningButton->height()); | ||
93 | _ui->unlimitedHistoryButton->setMinimumHeight(radioButtonHeight); | 94 | QWhatsThis::showText(_ui->unlimitedHistoryWarningButton->mapToGlobal(pos), message, _ui->unlimitedHistoryWarningButton); | ||
95 | }); | ||||
94 | } | 96 | } | ||
95 | 97 | | |||
96 | HistorySizeWidget::~HistorySizeWidget() | 98 | HistorySizeWidget::~HistorySizeWidget() | ||
97 | { | 99 | { | ||
98 | delete _ui; | 100 | delete _ui; | ||
99 | } | 101 | } | ||
100 | 102 | | |||
101 | void HistorySizeWidget::buttonClicked(QAbstractButton *) | 103 | void HistorySizeWidget::setTemporary(bool temporary) | ||
102 | { | 104 | { | ||
103 | Enum::HistoryModeEnum selectedMode = mode(); | 105 | _temporary = temporary; | ||
104 | emit historyModeChanged(selectedMode); | | |||
105 | } | 106 | } | ||
106 | 107 | | |||
107 | void HistorySizeWidget::setMode(Enum::HistoryModeEnum aMode) | 108 | void HistorySizeWidget::setMode(Enum::HistoryModeEnum aMode) | ||
108 | { | 109 | { | ||
109 | if (aMode == Enum::NoHistory) { | 110 | auto widget = [aMode, this]() { | ||
110 | _ui->noHistoryButton->setChecked(true); | 111 | return aMode == Enum::NoHistory ? _ui->noHistoryButton | ||
111 | } else if (aMode == Enum::FixedSizeHistory) { | 112 | : aMode == Enum::FixedSizeHistory ? _ui->fixedSizeHistoryButton | ||
112 | _ui->fixedSizeHistoryButton->setChecked(true); | 113 | : /* aMode == Enum::UnlimitedHistory */ _ui->unlimitedHistoryButton; | ||
113 | } else if (aMode == Enum::UnlimitedHistory) { | 114 | }(); | ||
114 | _ui->unlimitedHistoryButton->setChecked(true); | 115 | widget->setChecked(true); | ||
115 | } | | |||
116 | } | 116 | } | ||
117 | 117 | | |||
118 | Enum::HistoryModeEnum HistorySizeWidget::mode() const | 118 | Enum::HistoryModeEnum HistorySizeWidget::mode() const | ||
119 | { | 119 | { | ||
120 | if (_ui->noHistoryButton->isChecked()) { | 120 | return _ui->unlimitedHistoryButton->isChecked() ? Enum::UnlimitedHistory | ||
121 | return Enum::NoHistory; | 121 | : _ui->fixedSizeHistoryButton->isChecked() ? Enum::FixedSizeHistory | ||
122 | } else if (_ui->fixedSizeHistoryButton->isChecked()) { | 122 | : /* _ui->noHistoryButton->isChecked() */ Enum::NoHistory; | ||
123 | return Enum::FixedSizeHistory; | | |||
124 | } else if (_ui->unlimitedHistoryButton->isChecked()) { | | |||
125 | return Enum::UnlimitedHistory; | | |||
126 | } | | |||
127 | | ||||
128 | Q_ASSERT(false); | | |||
129 | return Enum::NoHistory; | | |||
130 | } | 123 | } | ||
131 | 124 | | |||
132 | void HistorySizeWidget::setLineCount(int lines) | 125 | void HistorySizeWidget::setLineCount(int lines) | ||
133 | { | 126 | { | ||
134 | _ui->historyLineSpinner->setValue(lines); | 127 | _ui->historyLineSpinner->setValue(lines); | ||
135 | _ui->historyLineSpinner->setSingleStep(lines / 10); | 128 | _ui->historyLineSpinner->setSingleStep(lines / 10); | ||
136 | } | 129 | } | ||
137 | 130 | | |||
138 | int HistorySizeWidget::lineCount() const | 131 | int HistorySizeWidget::lineCount() const | ||
139 | { | 132 | { | ||
140 | return _ui->historyLineSpinner->value(); | 133 | return _ui->historyLineSpinner->value(); | ||
141 | } | 134 | } | ||
142 | | ||||
143 | int HistorySizeWidget::preferredLabelHeight() | | |||
144 | { | | |||
145 | Q_ASSERT(_ui); | | |||
146 | Q_ASSERT(_ui->noHistoryButton); | | |||
147 | | ||||
148 | return _ui->fixedSizeHistoryWrapper->sizeHint().height(); | | |||
149 | } | |