Commit 5b04dfec authored by Eckhart Wörner's avatar Eckhart Wörner

Move EquationEditWidget into its own files

svn path=/trunk/KDE/kdeedu/kmplot/; revision=902515
parent 74458aa2
......@@ -12,6 +12,7 @@ set(kmplotpart_PART_SRCS
parser.cpp
xparser.cpp
equationedit.cpp
equationeditwidget.cpp
function.cpp
view.cpp
maindlg.cpp
......
......@@ -35,41 +35,12 @@
#include <QHBoxLayout>
#include <QLocale>
#include <QPushButton>
#include <QStyleOptionFrame>
#include <assert.h>
CharMap EquationEdit::m_replaceMap;
#include "equationeditwidget.h"
/**
* The actual line edit.
*/
class EquationEditWidget : public QTextEdit
{
public:
EquationEditWidget( EquationEdit * parent );
/**
* Call this after changing font size.
*/
void recalculateGeometry();
/**
* Whether to clear the selection when focus is lost.
*/
void setClearSelectionOnFocusOut( bool doIt ) { m_clearSelectionOnFocusOut = doIt; }
protected:
void clearSelection();
void wheelEvent( QWheelEvent * e );
void keyPressEvent( QKeyEvent * e );
void focusOutEvent( QFocusEvent * e );
void focusInEvent( QFocusEvent * e );
EquationEdit * m_parent;
bool m_clearSelectionOnFocusOut;
};
CharMap EquationEdit::m_replaceMap;
class EquationEditorWidget : public QWidget, public Ui::EquationEditor
......@@ -435,103 +406,6 @@ void EquationEdit::insertText( const QString & text )
//BEGIN class EquationEditWidget
EquationEditWidget::EquationEditWidget( EquationEdit * parent )
: QTextEdit( parent )
{
m_clearSelectionOnFocusOut = true;
m_parent = parent;
recalculateGeometry();
}
void EquationEditWidget::recalculateGeometry()
{
// Set fixed height
ensurePolished();
QFontMetrics fm( document()->defaultFont() );
int h = qMax(fm.lineSpacing(), 14) + 6;
int m = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
QStyleOptionFrame opt;
opt.rect = rect();
opt.palette = palette();
opt.state = QStyle::State_None;
setFixedHeight( h + (2 * m) );
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setContentsMargins( 0, 0, 0, 0 );
setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
setWordWrapMode( QTextOption::NoWrap );
setLineWrapMode( QTextEdit::NoWrap );
setTabChangesFocus( true );
}
void EquationEditWidget::wheelEvent( QWheelEvent * e )
{
e->accept();
}
void EquationEditWidget::keyPressEvent( QKeyEvent * e )
{
if ( (e->key() == Qt::Key_Return) ||
(e->key() == Qt::Key_Enter) )
{
e->accept();
emit m_parent->editingFinished();
emit m_parent->returnPressed();
}
else
{
// Still pass these keys to QTextEdit, in case the user has to scroll
// up/down the text
if ( e->key() == Qt::Key_Up )
emit m_parent->upPressed();
else if ( e->key() == Qt::Key_Down )
emit m_parent->downPressed();
QTextEdit::keyPressEvent( e );
}
}
void EquationEditWidget::focusOutEvent( QFocusEvent * e )
{
QTextEdit::focusOutEvent( e );
if ( m_clearSelectionOnFocusOut )
clearSelection();
m_parent->reHighlight();
emit m_parent->editingFinished();
}
void EquationEditWidget::focusInEvent( QFocusEvent * e )
{
QTextEdit::focusOutEvent( e );
m_parent->reHighlight();
if ( e->reason() == Qt::TabFocusReason )
selectAll();
}
void EquationEditWidget::clearSelection( )
{
QTextCursor cursor = textCursor();
if ( !cursor.hasSelection() )
return;
cursor.clearSelection();
setTextCursor( cursor );
}
//END class EquationEditWidget
//BEGIN class EquationEditor
EquationEditor::EquationEditor( QWidget * parent )
: KDialog( parent )
......
#include "equationeditwidget.h"
#include <QtGui/QFocusEvent>
#include <QtGui/QKeyEvent>
#include <QtGui/QStyle>
#include <QtGui/QStyleOptionFrame>
#include <QtGui/QWheelEvent>
#include "equationedit.h"
void EquationEditWidget::setClearSelectionOnFocusOut(bool doIt) {
m_clearSelectionOnFocusOut = doIt;
}
EquationEditWidget::EquationEditWidget(EquationEdit* parent)
: QTextEdit(parent)
{
m_clearSelectionOnFocusOut = true;
m_parent = parent;
recalculateGeometry();
}
void EquationEditWidget::recalculateGeometry() {
// Set fixed height
ensurePolished();
QFontMetrics fm(document()->defaultFont());
int h = qMax(fm.lineSpacing(), 14) + 6;
int m = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
QStyleOptionFrame opt;
opt.rect = rect();
opt.palette = palette();
opt.state = QStyle::State_None;
setFixedHeight(h + (2 * m));
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setContentsMargins(0, 0, 0, 0);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setWordWrapMode(QTextOption::NoWrap);
setLineWrapMode(QTextEdit::NoWrap);
setTabChangesFocus(true);
}
void EquationEditWidget::wheelEvent(QWheelEvent* e) {
e->accept();
}
void EquationEditWidget::keyPressEvent(QKeyEvent* e) {
if ((e->key() == Qt::Key_Return) || (e->key() == Qt::Key_Enter)) {
e->accept();
emit m_parent->editingFinished();
emit m_parent->returnPressed();
} else {
// Still pass these keys to QTextEdit, in case the user has to scroll
// up/down the text
if (e->key() == Qt::Key_Up)
emit m_parent->upPressed();
else if (e->key() == Qt::Key_Down)
emit m_parent->downPressed();
QTextEdit::keyPressEvent(e);
}
}
void EquationEditWidget::focusOutEvent(QFocusEvent* e) {
QTextEdit::focusOutEvent(e);
if (m_clearSelectionOnFocusOut)
clearSelection();
m_parent->reHighlight();
emit m_parent->editingFinished();
}
void EquationEditWidget::focusInEvent(QFocusEvent* e) {
QTextEdit::focusOutEvent(e);
m_parent->reHighlight();
if (e->reason() == Qt::TabFocusReason)
selectAll();
}
void EquationEditWidget::clearSelection() {
QTextCursor cursor = textCursor();
if (!cursor.hasSelection())
return;
cursor.clearSelection();
setTextCursor(cursor);
}
/*
* KmPlot - a math. function plotter for the KDE-Desktop
*
* Copyright (C) 2006 David Saxton <david@bluehaze.org>
*
* This file is part of the KDE Project.
* KmPlot is part of the KDE-EDU Project.
*
* 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 EQUATIONEDITWIDGET_H
#define EQUATIONEDITWIDGET_H
#include <QtGui/QTextEdit>
class EquationEdit;
/**
* The actual line edit.
*/
class EquationEditWidget : public QTextEdit
{
public:
EquationEditWidget(EquationEdit* parent);
/**
* Call this after changing font size.
*/
void recalculateGeometry();
/**
* Whether to clear the selection when focus is lost.
*/
void setClearSelectionOnFocusOut(bool doIt);
protected:
void clearSelection();
void wheelEvent(QWheelEvent* e);
void keyPressEvent(QKeyEvent* e);
void focusOutEvent(QFocusEvent* e);
void focusInEvent(QFocusEvent* e);
EquationEdit* m_parent;
bool m_clearSelectionOnFocusOut;
};
#endif
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