You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
195 lines
4.3 KiB
195 lines
4.3 KiB
15 years ago
|
//
|
||
|
// TODO: insert copyright header
|
||
|
//
|
||
|
|
||
14 years ago
|
#include <tqpainter.h>
|
||
15 years ago
|
|
||
|
#include "kspread_view.h"
|
||
|
|
||
|
#include "kspread_handler.h"
|
||
|
|
||
|
#define KS_MIN_RECTSIZE 3
|
||
|
|
||
|
using namespace KSpread;
|
||
|
|
||
14 years ago
|
InsertHandler::InsertHandler( View* view, TQWidget* widget )
|
||
|
: KoEventHandler( TQT_TQOBJECT(widget) )
|
||
15 years ago
|
{
|
||
|
m_view = view;
|
||
|
m_started = false;
|
||
|
m_clicked = false;
|
||
|
|
||
|
widget->setCursor( crossCursor );
|
||
|
}
|
||
|
|
||
|
InsertHandler::~InsertHandler()
|
||
|
{
|
||
14 years ago
|
((TQWidget*)target())->setCursor( arrowCursor );
|
||
15 years ago
|
m_view->resetInsertHandle();
|
||
|
}
|
||
|
|
||
14 years ago
|
bool InsertHandler::eventFilter( TQObject*, TQEvent* ev )
|
||
15 years ago
|
{
|
||
14 years ago
|
if ( ev->type() == TQEvent::MouseButtonPress )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQMouseEvent* e = (TQMouseEvent*)ev;
|
||
15 years ago
|
|
||
14 years ago
|
m_geometryStart = e->pos();
|
||
|
m_geometryEnd = e->pos();
|
||
15 years ago
|
m_started = false;
|
||
|
m_clicked = true;
|
||
|
|
||
|
return true;
|
||
|
}
|
||
14 years ago
|
else if ( ev->type() == TQEvent::MouseMove )
|
||
15 years ago
|
{
|
||
|
if ( !m_clicked )
|
||
|
return true;
|
||
|
|
||
14 years ago
|
TQMouseEvent* e = (TQMouseEvent*)ev;
|
||
15 years ago
|
|
||
14 years ago
|
TQPainter painter;
|
||
|
painter.begin( (TQWidget*)target() );
|
||
15 years ago
|
painter.setRasterOp( NotROP );
|
||
|
|
||
14 years ago
|
TQPen pen;
|
||
|
pen.setStyle( Qt::DashLine );
|
||
15 years ago
|
painter.setPen( pen );
|
||
|
|
||
|
if ( m_started )
|
||
|
{
|
||
14 years ago
|
int x = m_geometryStart.x();
|
||
|
int y = m_geometryStart.y();
|
||
|
if ( x > m_geometryEnd.x() )
|
||
|
x = m_geometryEnd.x();
|
||
|
if ( y > m_geometryEnd.y() )
|
||
|
y = m_geometryEnd.y();
|
||
|
int w = m_geometryEnd.x() - m_geometryStart.x();
|
||
15 years ago
|
if ( w < 0 ) w *= -1;
|
||
14 years ago
|
int h = m_geometryEnd.y() - m_geometryStart.y();
|
||
15 years ago
|
if ( h < 0 ) h *= -1;
|
||
|
|
||
|
if ( w < KS_MIN_RECTSIZE ) w = KS_MIN_RECTSIZE;
|
||
|
if ( h < KS_MIN_RECTSIZE ) h = KS_MIN_RECTSIZE;
|
||
|
|
||
|
painter.drawRect( x, y, w, h );
|
||
|
}
|
||
|
else
|
||
|
m_started = true;
|
||
|
|
||
14 years ago
|
m_geometryEnd = e->pos();
|
||
15 years ago
|
|
||
14 years ago
|
int x = m_geometryStart.x();
|
||
|
int y = m_geometryStart.y();
|
||
|
if ( x > m_geometryEnd.x() )
|
||
|
x = m_geometryEnd.x();
|
||
|
if ( y > m_geometryEnd.y() )
|
||
|
y = m_geometryEnd.y();
|
||
|
int w = m_geometryEnd.x() - m_geometryStart.x();
|
||
15 years ago
|
if ( w < 0 ) w *= -1;
|
||
14 years ago
|
int h = m_geometryEnd.y() - m_geometryStart.y();
|
||
15 years ago
|
if ( h < 0 ) h *= -1;
|
||
|
|
||
|
if ( w < KS_MIN_RECTSIZE ) w = KS_MIN_RECTSIZE;
|
||
|
if ( h < KS_MIN_RECTSIZE ) h = KS_MIN_RECTSIZE;
|
||
|
|
||
|
painter.drawRect( x, y, w, h );
|
||
|
painter.end();
|
||
|
|
||
|
return true;
|
||
|
}
|
||
14 years ago
|
else if ( ev->type() == TQEvent::MouseButtonRelease )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQMouseEvent* e = (TQMouseEvent*)ev;
|
||
15 years ago
|
|
||
|
if ( !m_started )
|
||
|
{
|
||
|
delete this;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
14 years ago
|
m_geometryEnd = e->pos();
|
||
|
|
||
|
int x = m_geometryStart.x();
|
||
|
int y = m_geometryStart.y();
|
||
|
if ( x > m_geometryEnd.x() )
|
||
|
x = m_geometryEnd.x();
|
||
|
if ( y > m_geometryEnd.y() )
|
||
|
y = m_geometryEnd.y();
|
||
|
int w = m_geometryEnd.x() - m_geometryStart.x();
|
||
15 years ago
|
if ( w < 0 ) w *= -1;
|
||
14 years ago
|
int h = m_geometryEnd.y() - m_geometryStart.y();
|
||
15 years ago
|
if ( h < 0 ) h *= -1;
|
||
|
|
||
|
if ( w < KS_MIN_RECTSIZE ) w = KS_MIN_RECTSIZE;
|
||
|
if ( h < KS_MIN_RECTSIZE ) h = KS_MIN_RECTSIZE;
|
||
|
|
||
14 years ago
|
TQPainter painter;
|
||
|
painter.begin( (TQWidget*)target() );
|
||
15 years ago
|
|
||
14 years ago
|
TQPen pen;
|
||
|
pen.setStyle( Qt::DashLine );
|
||
15 years ago
|
painter.setPen( pen );
|
||
|
|
||
|
painter.setRasterOp( NotROP );
|
||
|
painter.drawRect( x, y, w, h );
|
||
|
painter.end();
|
||
|
|
||
14 years ago
|
insertObject( TQRect( x, y, w, h) );
|
||
15 years ago
|
|
||
|
delete this;
|
||
|
return true;
|
||
|
}
|
||
14 years ago
|
else if ( ev->type() == TQEvent::KeyPress )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQKeyEvent* e = (TQKeyEvent*)ev;
|
||
15 years ago
|
if ( e->key() != Key_Escape )
|
||
|
return false;
|
||
|
|
||
|
delete this;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
14 years ago
|
InsertPartHandler::InsertPartHandler( View* view, TQWidget* widget, const KoDocumentEntry& entry )
|
||
15 years ago
|
: InsertHandler( view, widget ), m_entry( entry )
|
||
|
{
|
||
|
}
|
||
|
InsertPartHandler::~InsertPartHandler()
|
||
|
{
|
||
|
}
|
||
14 years ago
|
void InsertPartHandler::insertObject( TQRect r)
|
||
15 years ago
|
{
|
||
|
m_view->insertChild( r, m_entry );
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
InsertChartHandler::InsertChartHandler( View* view, TQWidget* widget, const KoDocumentEntry& entry )
|
||
15 years ago
|
: InsertHandler( view, widget ), m_entry( entry )
|
||
|
{
|
||
|
}
|
||
|
InsertChartHandler::~InsertChartHandler()
|
||
|
{
|
||
|
}
|
||
14 years ago
|
void InsertChartHandler::insertObject( TQRect r)
|
||
15 years ago
|
{
|
||
|
m_view->insertChart( r, m_entry );
|
||
|
}
|
||
|
|
||
14 years ago
|
InsertPictureHandler::InsertPictureHandler( View* view, TQWidget* widget, const KURL &file )
|
||
15 years ago
|
: InsertHandler( view, widget )
|
||
|
{
|
||
|
m_file = file;
|
||
|
}
|
||
|
InsertPictureHandler::~InsertPictureHandler()
|
||
|
{
|
||
|
}
|
||
14 years ago
|
void InsertPictureHandler::insertObject( TQRect r)
|
||
15 years ago
|
{
|
||
|
//m_view->insertPicture(/* r,*/ m_file );
|
||
|
}
|
||
|
|
||
|
#include "kspread_handler.moc"
|