3 Copyright (c) 2010-2012 Jakob Leben
4 Copyright (c) 2012 Tim Blechmann
5 http://www.audiosynth.com
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "cmd_line.hpp"
24 #include <QHBoxLayout>
30 CmdLine::CmdLine( const QString
&text
, int maxHist
) :
32 maxHistory( qMax(1,maxHist
) )
34 QLabel
*lbl
= new QLabel(text
);
37 QFont
f( expr
->font() );
38 f
.setFamily("monospace");
39 f
.setStyleHint(QFont::TypeWriter
);
42 QHBoxLayout
*l
= new QHBoxLayout
;
43 l
->setContentsMargins(0,0,0,0);
48 expr
->installEventFilter( this );
52 bool CmdLine::eventFilter( QObject
*, QEvent
*e
)
55 if( type
!= QEvent::KeyPress
) return false;
57 QKeyEvent
*ke
= static_cast<QKeyEvent
*>(e
);
64 if( expr
->text().isEmpty() ) return true;
66 emit
invoked( expr
->text(), false );
67 if( history
.count() == 0 || history
[0] != expr
->text() )
69 if( history
.count() >= maxHistory
) history
.removeAt( history
.count() - 1 );
70 history
.prepend( expr
->text() );
77 if( curHistory
< history
.count() - 1 ) {
78 expr
->blockSignals(true);
79 expr
->setText( history
[++curHistory
] );
80 expr
->blockSignals(false);
85 if( curHistory
> -1 ) {
87 expr
->blockSignals(true);
88 if( curHistory
== -1 ) expr
->clear();
89 else expr
->setText( history
[curHistory
] );
90 expr
->blockSignals(false);
94 default: return false;