Commit 6d43f0ca authored by Jekyll Wu's avatar Jekyll Wu

Refacotr history size related UI components into HistorySizeWidget

This make EditProfileDialog and HistorySizeDialog reuse the same
widget, instead of duplicating each other in its own code or .ui file.
HistorySizeDialog is now just a simple container of HistorySizeWidget
parent 066fdd5f
......@@ -76,6 +76,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/tests/CTestCustom.cmake)
Filter.cpp
History.cpp
HistorySizeDialog.cpp
HistorySizeWidget.cpp
IncrementalSearchBar.cpp
KeyBindingEditor.cpp
KeyboardTranslator.cpp
......@@ -138,6 +139,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/tests/CTestCustom.cmake)
KeyBindingEditor.ui
ManageProfilesDialog.ui
RenameTabsDialog.ui
HistorySizeWidget.ui
settings/GeneralSettings.ui
settings/TabBarSettings.ui
)
......
......@@ -963,40 +963,26 @@ void EditProfileDialog::setupScrollingPage(const Profile::Ptr profile)
// setup scrollback type radio
int scrollBackType = profile->property<int>(Profile::HistoryMode);
RadioOption types[] = { {_ui->disableScrollbackButton, Enum::NoHistory, SLOT(noScrollBack())},
{_ui->fixedScrollbackButton, Enum::FixedSizeHistory, SLOT(fixedScrollBack())},
{_ui->unlimitedScrollbackButton, Enum::UnlimitedHistory, SLOT(unlimitedScrollBack())},
{0, 0, 0}
};
setupRadio(types , scrollBackType);
_ui->historySizeWidget->setMode(Enum::HistoryModeEnum(scrollBackType));
connect(_ui->historySizeWidget, SIGNAL(historyModeChanged(Enum::HistoryModeEnum)),
this, SLOT(historyModeChanged(Enum::HistoryModeEnum)));
// setup scrollback line count spinner
const int historySize = profile->historySize();
_ui->scrollBackLinesSpinner->setValue(historySize);
_ui->scrollBackLinesSpinner->setSingleStep(historySize / 10);
_ui->scrollBackLinesSpinner->setSuffix(ki18ncp("Unit of scrollback", " line", " lines"));
_ui->historySizeWidget->setLineCount(historySize);
// signals and slots
connect(_ui->scrollBackLinesSpinner, SIGNAL(valueChanged(int)), this,
SLOT(scrollBackLinesChanged(int)));
connect(_ui->historySizeWidget, SIGNAL(historySizeChanged(int)),
this, SLOT(historySizeChanged(int)));
}
void EditProfileDialog::scrollBackLinesChanged(int lineCount)
void EditProfileDialog::historySizeChanged(int lineCount)
{
updateTempProfileProperty(Profile::HistorySize , lineCount);
}
void EditProfileDialog::noScrollBack()
{
updateTempProfileProperty(Profile::HistoryMode , Enum::NoHistory);
}
void EditProfileDialog::fixedScrollBack()
{
updateTempProfileProperty(Profile::HistoryMode , Enum::FixedSizeHistory);
}
void EditProfileDialog::unlimitedScrollBack()
void EditProfileDialog::historyModeChanged(Enum::HistoryModeEnum mode)
{
updateTempProfileProperty(Profile::HistoryMode , Enum::UnlimitedHistory);
updateTempProfileProperty(Profile::HistoryMode, mode);
}
void EditProfileDialog::hideScrollBar()
{
......
......@@ -30,6 +30,7 @@
// Konsole
#include "Profile.h"
#include "Enumeration.h"
class QAbstractButton;
class QItemSelectionModel;
......@@ -137,11 +138,9 @@ private slots:
void colorSchemeAnimationUpdate();
// scrolling page
void noScrollBack();
void fixedScrollBack();
void unlimitedScrollBack();
void historyModeChanged(Enum::HistoryModeEnum mode);
void scrollBackLinesChanged(int);
void historySizeChanged(int);
void hideScrollBar();
void showScrollBarLeft();
......
......@@ -569,81 +569,7 @@
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QRadioButton" name="disableScrollbackButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Do not remember previous output</string>
</property>
<property name="text">
<string>No scrollback</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QRadioButton" name="fixedScrollbackButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Limit the remembered output to a fixed number of lines</string>
</property>
<property name="text">
<string>Fixed size scrollback:</string>
</property>
</widget>
</item>
<item>
<widget class="KIntSpinBox" name="scrollBackLinesSpinner">
<property name="toolTip">
<string>Number of lines of output to remember</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>100000</number>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QRadioButton" name="unlimitedScrollbackButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Remember all output produced by the terminal</string>
</property>
<property name="text">
<string>Unlimited scrollback</string>
</property>
<widget class="Konsole::HistorySizeWidget" name="historySizeWidget">
</widget>
</item>
</layout>
......@@ -1187,6 +1113,11 @@
<extends>QPushButton</extends>
<header>TabTitleFormatButton.h</header>
</customwidget>
<customwidget>
<class>Konsole::HistorySizeWidget</class>
<extends>QWidget</extends>
<header>HistorySizeWidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
......
......@@ -21,27 +21,21 @@
#include "HistorySizeDialog.h"
// Qt
#include <QtGui/QButtonGroup>
#include <QtGui/QVBoxLayout>
#include <QtGui/QLabel>
#include <QtGui/QRadioButton>
#include <QtGui/QWidget>
// KDE
#include <KLocalizedString>
#include <KNumInput>
// Konsole
#include "SessionManager.h"
#include "HistorySizeWidget.h"
using namespace Konsole;
HistorySizeDialog::HistorySizeDialog(QWidget* aParent)
: KDialog(aParent)
, _noHistoryButton(0)
, _fixedHistoryButton(0)
, _unlimitedHistoryButton(0)
, _lineCountBox(0)
, _historySizeWidget(0)
{
// basic dialog properties
setPlainCaption(i18n("Adjust Scrollback"));
......@@ -55,43 +49,14 @@ HistorySizeDialog::HistorySizeDialog(QWidget* aParent)
QVBoxLayout* dialogLayout = new QVBoxLayout(dialogWidget);
_noHistoryButton = new QRadioButton(i18n("No scrollback"));
_fixedHistoryButton = new QRadioButton(i18n("Fixed size scrollback: "));
_unlimitedHistoryButton = new QRadioButton(i18n("Unlimited scrollback"));
QButtonGroup* modeGroup = new QButtonGroup(this);
modeGroup->addButton(_noHistoryButton);
modeGroup->addButton(_fixedHistoryButton);
modeGroup->addButton(_unlimitedHistoryButton);
_lineCountBox = new KIntSpinBox(this);
// minimum lines = 1 ( for 0 lines , "No History" mode should be used instead )
// maximum lines is arbitrarily chosen, I do not think it is sensible to allow this
// to be set to a very large figure because that will use large amounts of memory,
// if a very large log is required, "Unlimited History" mode should be used
_lineCountBox->setRange(1 , 100000);
_lineCountBox->setValue(HistorySizeDialog::defaultLineCount);
_lineCountBox->setSingleStep(HistorySizeDialog::defaultLineCount / 10);
_lineCountBox->setSuffix(ki18ncp("Unit of scrollback", " line", " lines"));
_fixedHistoryButton->setFocusProxy(_lineCountBox);
connect(_fixedHistoryButton , SIGNAL(clicked()) ,
_lineCountBox , SLOT(selectAll()));
QHBoxLayout* lineCountLayout = new QHBoxLayout();
lineCountLayout->addWidget(_fixedHistoryButton);
lineCountLayout->addWidget(_lineCountBox);
QLabel* warningLabel = new QLabel(i18n("<center>The adjustment is only temporary</center>"), this);
warningLabel->setStyleSheet("text-align:center; font-weight:normal; color:palette(dark)");
_historySizeWidget = new HistorySizeWidget(this);
dialogLayout->addWidget(warningLabel);
dialogLayout->insertSpacing(-1, 5);
dialogLayout->addWidget(_noHistoryButton);
dialogLayout->addLayout(lineCountLayout);
dialogLayout->addWidget(_unlimitedHistoryButton);
dialogLayout->addWidget(_historySizeWidget);
dialogLayout->insertSpacing(-1, 10);
connect(this, SIGNAL(accepted()), this, SLOT(emitOptionsChanged()));
......@@ -102,40 +67,24 @@ void HistorySizeDialog::emitOptionsChanged()
emit optionsChanged(mode() , lineCount());
}
void HistorySizeDialog::setMode(Enum::HistoryModeEnum historyMode)
void HistorySizeDialog::setMode(Enum::HistoryModeEnum aMode)
{
if (historyMode == Enum::NoHistory) {
_noHistoryButton->setChecked(true);
} else if (historyMode == Enum::FixedSizeHistory) {
_fixedHistoryButton->setChecked(true);
} else if (historyMode == Enum::UnlimitedHistory) {
_unlimitedHistoryButton->setChecked(true);
}
_historySizeWidget->setMode(aMode);
}
Enum::HistoryModeEnum HistorySizeDialog::mode() const
{
if (_noHistoryButton->isChecked())
return Enum::NoHistory;
else if (_fixedHistoryButton->isChecked())
return Enum::FixedSizeHistory;
else if (_unlimitedHistoryButton->isChecked())
return Enum::UnlimitedHistory;
Q_ASSERT(false);
return Enum::NoHistory;
return _historySizeWidget->mode();
}
int HistorySizeDialog::lineCount() const
{
return _lineCountBox->value();
return _historySizeWidget->lineCount();
}
void HistorySizeDialog::setLineCount(int lines)
{
_lineCountBox->setValue(lines);
_lineCountBox->setSingleStep(lines / 10);
_historySizeWidget->setLineCount(lines);
}
#include "HistorySizeDialog.moc"
......@@ -26,39 +26,34 @@
// Konsole
#include "Enumeration.h"
class QAbstractButton;
class KIntSpinBox;
namespace Konsole
{
class HistorySizeWidget;
/**
* A dialog which allows the user to select the number of lines of output
* which are remembered for a session.
* A dialog for controlling history related options
* It is only a simple container of HistorySizeWidget
*/
class HistorySizeDialog : public KDialog
{
Q_OBJECT
public:
/**
* Construct a new history size dialog.
*/
explicit HistorySizeDialog(QWidget* parent);
/** Specifies the history mode. */
void setMode(Enum::HistoryModeEnum mode);
/** Returns the history mode chosen by the user. */
/** See HistorySizeWidget::setMode. */
void setMode(Enum::HistoryModeEnum aMode);
/** See HistorySizeWidget::mode. */
Enum::HistoryModeEnum mode() const;
/**
* Returns the number of lines of history to remember.
* This is only valid when mode() == FixedSizeHistory,
* and returns 0 otherwise.
*/
int lineCount() const;
/** Sets the number of lines for the fixed size history mode. */
/** See HistorySizeWidget::setLineCount. */
void setLineCount(int lines);
/** See HistorySizeWidget::lineCount. */
int lineCount() const;
signals:
/**
* Emitted when the user changes the scroll-back mode or line count and
......@@ -77,13 +72,8 @@ private slots:
void emitOptionsChanged();
private:
QAbstractButton* _noHistoryButton;
QAbstractButton* _fixedHistoryButton;
QAbstractButton* _unlimitedHistoryButton;
KIntSpinBox* _lineCountBox;
HistorySizeWidget* _historySizeWidget;
// 1000 lines was the default in the KDE 3 series
static const int defaultLineCount = 1000;
};
}
......
/*
Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
Copyright 2012 by Jekyll Wu <adaptee@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
// Own
#include "HistorySizeWidget.h"
// Qt
#include <QtGui/QButtonGroup>
#include <QtGui/QAbstractButton>
// Konsole
#include "ui_HistorySizeWidget.h"
using namespace Konsole;
HistorySizeWidget::HistorySizeWidget(QWidget* parent)
: QWidget(parent)
{
_ui = new Ui::HistorySizeWidget();
_ui->setupUi(this);
// focus and select the spinner automatically when appropriate
_ui->fixedSizeHistoryButton->setFocusProxy(_ui->historyLineSpinner);
connect(_ui->fixedSizeHistoryButton , SIGNAL(clicked()) ,
_ui->historyLineSpinner , SLOT(selectAll()));
QButtonGroup* modeGroup = new QButtonGroup(this);
modeGroup->addButton(_ui->noHistoryButton);
modeGroup->addButton(_ui->fixedSizeHistoryButton);
modeGroup->addButton(_ui->unlimitedHistoryButton);
connect(modeGroup, SIGNAL(buttonClicked(QAbstractButton*)),
this, SLOT(buttonClicked(QAbstractButton*)) );
_ui->historyLineSpinner->setSuffix(ki18ncp("Unit of scrollback", " line", " lines"));
this->setLineCount(HistorySizeWidget::DefaultLineCount);
connect(_ui->historyLineSpinner, SIGNAL(valueChanged(int)),
this, SIGNAL(historySizeChanged(int)) );
}
HistorySizeWidget::~HistorySizeWidget()
{
delete _ui;
}
void HistorySizeWidget::buttonClicked(QAbstractButton*) const
{
emit historyModeChanged(mode());
}
void HistorySizeWidget::setMode(Enum::HistoryModeEnum aMode)
{
if (aMode == Enum::NoHistory) {
_ui->noHistoryButton->setChecked(true);
} else if (aMode == Enum::FixedSizeHistory) {
_ui->fixedSizeHistoryButton->setChecked(true);
} else if (aMode == Enum::UnlimitedHistory) {
_ui->unlimitedHistoryButton->setChecked(true);
}
}
Enum::HistoryModeEnum HistorySizeWidget::mode() const
{
if (_ui->noHistoryButton->isChecked())
return Enum::NoHistory;
else if (_ui->fixedSizeHistoryButton->isChecked())
return Enum::FixedSizeHistory;
else if (_ui->unlimitedHistoryButton->isChecked())
return Enum::UnlimitedHistory;
Q_ASSERT(false);
return Enum::NoHistory;
}
void HistorySizeWidget::setLineCount(int lines)
{
_ui->historyLineSpinner->setValue(lines);
_ui->historyLineSpinner->setSingleStep(lines / 10);
}
int HistorySizeWidget::lineCount() const
{
return _ui->historyLineSpinner->value();
}
#include "HistorySizeWidget.moc"
/*
Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
Copyright 2012 by Jekyll Wu <adaptee@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
#ifndef HISTORYSIZEWIDGET_H
#define HISTORYSIZEWIDGET_H
// Qt
#include <QtGui/QWidget>
// Konsole
#include "Enumeration.h"
class QAbstractButton;
namespace Ui
{
class HistorySizeWidget;
}
namespace Konsole
{
/**
* A widget for controlling hisotry related options
*/
class HistorySizeWidget : public QWidget
{
Q_OBJECT
public:
explicit HistorySizeWidget(QWidget* parent);
virtual ~HistorySizeWidget();
/** Specifies the history mode. */
void setMode(Enum::HistoryModeEnum aMode);
/** Returns the history mode chosen by the user. */
Enum::HistoryModeEnum mode() const;
/** Sets the number of lines for the fixed size history mode. */
void setLineCount(int lines);
/**
* Returns the number of lines of history to remember.
* This is only valid when mode() == FixedSizeHistory,
* and returns 0 otherwise.
*/
int lineCount() const;
signals:
/** Emitted when the history mode is changed. */
void historyModeChanged(Enum::HistoryModeEnum) const;
/** Emitted when the history size is changed. */
void historySizeChanged(int) const;
private slots:
void buttonClicked(QAbstractButton*) const;
private:
Ui::HistorySizeWidget* _ui;
// 1000 lines was the default in the KDE3 series
static const int DefaultLineCount = 1000;
};
}
#endif // HISTORYSIZEWIDGET_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>HistorySizeWidget</class>
<widget class="QWidget" name="HistorySizeWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>86</height>
</rect>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QRadioButton" name="noHistoryButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Do not remember previous output</string>
</property>
<property name="text">
<string>No scrollback</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QRadioButton" name="fixedSizeHistoryButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Limit the remembered output to a fixed number of lines</string>
</property>
<property name="text">
<string>Fixed size scrollback:</string>
</property>
</widget>
</item>
<item>
<widget class="KIntSpinBox" name="historyLineSpinner">
<property name="toolTip">
<string>Number of lines of output to remember</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>100000</number>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QRadioButton" name="unlimitedHistoryButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Remember all output produced by the terminal</string>
</property>
<property name="text">
<string>Unlimited scrollback</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KIntSpinBox</class>
<extends>QSpinBox</extends>
<header>knuminput.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
......@@ -63,7 +63,6 @@ class IncrementalSearchBar;
class ProfileList;
class UrlFilter;
class RegExpFilter;
class HistorySizeDialog;
// SaveHistoryTask
class TerminalCharacterDecoder;
......
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