3 Copyright (c) 2012 Jakob Leben & Tim Blechmann
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef SCIDE_WIDGETS_GOTO_LINE_TOOL_HPP_INCLUDED
22 #define SCIDE_WIDGETS_GOTO_LINE_TOOL_HPP_INCLUDED
24 #include "code_editor/editor.hpp"
25 #include "../core/doc_manager.hpp"
29 #include <QToolButton>
30 #include <QHBoxLayout>
37 class GoToLineTool
: public QWidget
42 GoToLineTool( QWidget
* parent
= 0 ):
46 mSpinBox
= new QSpinBox
;
47 mSpinBox
->setMinimum(0);
48 mSpinBox
->setMaximum(0);
50 QToolButton
*goBtn
= new QToolButton
;
51 goBtn
->setText(tr("Go"));
52 goBtn
->setAutoRaise(true);
54 QLabel
*label
= new QLabel("Line:");
56 QHBoxLayout
*layout
= new QHBoxLayout
;
57 layout
->setContentsMargins(0,0,0,0);
58 layout
->addWidget(label
);
59 layout
->addWidget(mSpinBox
);
60 layout
->addWidget(goBtn
);
65 setFocusProxy(mSpinBox
);
67 connect(goBtn
, SIGNAL(clicked()), this, SLOT(go()));
68 connect(mSpinBox
, SIGNAL(editingFinished()), this, SLOT(onEditingFinished()));
71 void setEditor( CodeEditor
*editor
)
74 mEditor
->disconnect( this, SLOT(setMaximum(int)) );
79 connect(mEditor
, SIGNAL(blockCountChanged(int)), this, SLOT(setMaximum(int)));
80 setMaximum(mEditor
->blockCount());
86 void setValue( int value
) { mSpinBox
->setValue(value
); }
90 void setMaximum( int max
) {
92 mSpinBox
->setRange(1, max
);
94 mSpinBox
->setRange(0,0);
99 mSpinBox
->setFocus(Qt::OtherFocusReason
);
100 mSpinBox
->selectAll();
105 void activated( int lineNumber
);
111 int lineNumber
= mSpinBox
->value();
114 QTextDocument
*doc
= mEditor
->textDocument();
115 QTextBlock
block( doc
->findBlockByNumber(lineNumber
- 1) );
116 if (!block
.isValid())
119 QTextCursor
cursor( doc
);
120 cursor
.setPosition( block
.position() );
121 mEditor
->setTextCursor(cursor
);
124 emit
activated( lineNumber
);
127 void onEditingFinished()
129 if (mSpinBox
->hasFocus())
136 QPointer
<CodeEditor
> mEditor
;