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