add more spacing
[personal-kdebase.git] / apps / konsole / src / HistorySizeDialog.cpp
blob3f7a38f01ccd246dd1e0633fa214fcfa785e77fe
1 /*
2 Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301 USA.
20 // Own
21 #include "HistorySizeDialog.h"
23 // Qt
24 #include <QtGui/QButtonGroup>
25 #include <QtGui/QBoxLayout>
26 #include <QtGui/QLabel>
27 #include <QtGui/QRadioButton>
28 #include <QtGui/QSpinBox>
29 #include <QtGui/QWidget>
31 // KDE
32 #include <KLocalizedString>
34 // Konsole
35 #include "SessionManager.h"
37 using namespace Konsole;
39 HistorySizeDialog::HistorySizeDialog( QWidget* parent )
40 : KDialog(parent)
41 , _noHistoryButton(0)
42 , _fixedHistoryButton(0)
43 , _unlimitedHistoryButton(0)
44 , _lineCountBox(0)
45 , _defaultMode(FixedSizeHistory)
46 , _defaultLineCount(1000)
48 // basic dialog properties
49 setPlainCaption( i18n("Scrollback Options") );
50 setButtons( Default | Ok | Cancel );
51 setDefaultButton(Ok);
52 setModal( false );
54 // dialog widgets
55 QWidget* dialogWidget = new QWidget(this);
56 setMainWidget(dialogWidget);
58 QVBoxLayout* dialogLayout = new QVBoxLayout(dialogWidget);
60 QButtonGroup* modeGroup = new QButtonGroup(this);
62 _noHistoryButton = new QRadioButton( i18n("No scrollback") );
63 _fixedHistoryButton = new QRadioButton( i18n("Fixed size scrollback: ") );
64 _unlimitedHistoryButton = new QRadioButton( i18n("Unlimited scrollback") );
66 modeGroup->addButton(_noHistoryButton);
67 modeGroup->addButton(_fixedHistoryButton);
68 modeGroup->addButton(_unlimitedHistoryButton);
70 _lineCountBox = new QSpinBox(this);
72 // minimum lines = 1 ( for 0 lines , "No History" mode should be used instead )
73 // maximum lines is abritrarily chosen, I do not think it is sensible to allow this
74 // to be set to a very large figure because that will use large amounts of memory,
75 // if a very large log is required, "Unlimited History" mode should be used
76 _lineCountBox->setRange( 1 , 100000 );
78 // 1000 lines was the default in the KDE 3 series
79 // using that for now
80 _lineCountBox->setValue( _defaultLineCount );
82 _lineCountBox->setSingleStep( _defaultLineCount / 10 );
84 QLabel* lineCountLabel = new QLabel(i18n("lines"),this);
85 QHBoxLayout* lineCountLayout = new QHBoxLayout();
87 _fixedHistoryButton->setFocusProxy(_lineCountBox);
89 connect( _fixedHistoryButton , SIGNAL(clicked()) , _lineCountBox , SLOT(selectAll()) );
90 lineCountLayout->addWidget(_fixedHistoryButton);
91 lineCountLayout->addWidget(_lineCountBox);
92 lineCountLayout->addWidget(lineCountLabel);
94 dialogLayout->addWidget(_noHistoryButton);
95 dialogLayout->addLayout(lineCountLayout);
96 dialogLayout->addWidget(_unlimitedHistoryButton);
98 // select the fixed size mode by default
99 _fixedHistoryButton->click();
100 _fixedHistoryButton->setFocus( Qt::OtherFocusReason );
102 connect(this,SIGNAL(defaultClicked()),this,SLOT(useDefaults()));
104 connect(this,SIGNAL(accepted()),this,SLOT(emitOptionsChanged()));
107 void HistorySizeDialog::emitOptionsChanged()
109 emit optionsChanged( mode() , lineCount() );
112 void HistorySizeDialog::setDefaultMode( HistoryMode mode ) { _defaultMode = mode; }
113 HistorySizeDialog::HistoryMode HistorySizeDialog::defaultMode() const { return _defaultMode; }
114 void HistorySizeDialog::setDefaultLineCount( int count ) { _defaultLineCount = count; }
115 int HistorySizeDialog::defaultLineCount() const { return _defaultLineCount; }
117 void HistorySizeDialog::useDefaults()
119 setMode( _defaultMode );
120 setLineCount( _defaultLineCount );
123 void HistorySizeDialog::setMode( HistoryMode mode )
125 if ( mode == NoHistory )
127 _noHistoryButton->setChecked(true);
128 } else if ( mode == FixedSizeHistory )
130 _fixedHistoryButton->setChecked(true);
131 } else if ( mode == UnlimitedHistory )
133 _unlimitedHistoryButton->setChecked(true);
137 HistorySizeDialog::HistoryMode HistorySizeDialog::mode() const
139 if ( _noHistoryButton->isChecked() )
140 return NoHistory;
141 else if ( _fixedHistoryButton->isChecked() )
142 return FixedSizeHistory;
143 else if ( _unlimitedHistoryButton->isChecked() )
144 return UnlimitedHistory;
146 Q_ASSERT(false);
147 return NoHistory;
150 int HistorySizeDialog::lineCount() const
152 return _lineCountBox->value();
155 void HistorySizeDialog::setLineCount(int lines)
157 _lineCountBox->setValue(lines);
161 #include "HistorySizeDialog.moc"