Commit 1e6f2743 authored by Stéphane Albert's avatar Stéphane Albert

ENH: Cleaned duplicate code in Manipulator classes tree; Moved...

ENH: Cleaned duplicate code in Manipulator classes tree; Moved ModelImageRegionChanged() connection.
parent 05496088
......@@ -108,10 +108,12 @@ MainWindow
qApp, SLOT( quit() )
);
/*
// Connect the setLargestPossibleregion
QObject::connect(
centralWidget(), SIGNAL( ModelImageRegionChanged(const ImageRegionType&) ),
imageViewManipulator, SLOT( OnModelImageRegionChanged(const ImageRegionType&)) );
*/
// Connect Appllication and MainWindow when selected model is about
// to change.
......@@ -159,10 +161,12 @@ MainWindow
Qt::LeftDockWidgetArea
);
/*
// Connect the setLargestPossibleregion
QObject::connect(
qlWidget, SIGNAL( ModelImageRegionChanged(const ImageRegionType&) ),
qlViewManipulator, SLOT( OnModelImageRegionChanged(const ImageRegionType&)) );
*/
//
// COLOR SETUP.
......@@ -428,7 +432,7 @@ MainWindow
// QUICKLOOK VIEW.
// Assign newly selected model to view.
#if 0
#if 1
qobject_cast< GLImageWidget * >( GetQuicklookDock()->widget() )->SetImageModel(
vectorImageModel->GetQuicklookModel()
);
......
......@@ -67,7 +67,8 @@ namespace mvd
/* CLASS DEFINITION SECTION */
/** \class AbstractViewManipulator
* Base class for QWidget manipulation
*
* \brief Base class for QWidget manipulation
*/
class Monteverdi2_EXPORT AbstractViewManipulator :
public QObject
......@@ -97,6 +98,7 @@ public:
virtual void resizeEvent ( QResizeEvent * event ) = 0;
virtual void keyPressEvent( QKeyEvent * event ) = 0;
// TODO: See if HasZoomChanged() pure virtual method can be transformed into Qt signal.
virtual bool HasZoomChanged() const = 0;
/** */
......@@ -122,25 +124,44 @@ signals:
// Protected types.
protected:
/** Navigation context */
struct NavigationContextType
struct NavigationContext
{
// TODO: Implement default construtor (to safely initialize POD).
// TODO: Rename NavigationContextType struct into NagivationContext (this is not a typedef).
/**
* \brief Constructor.
*
* Default constructor (safely) initializes POD (Plain Old Data)
* structure.
*/
NavigationContext() :
m_ViewportImageRegion(),
m_ModelImageRegion(),
m_SizeXBeforeConstrain(),
m_SizeYBeforeConstrain()
{
// TODO: Initialize default viewport region to (0, 0) i.e. no
// viewed image.
ImageRegionType::SizeType region;
region[ 0 ] = 1;
region[ 1 ] = 1;
m_ViewportImageRegion.SetSize( region );
}
ImageRegionType m_ViewportImageRegion;
ImageRegionType m_ModelImageRegion;
// Stored as double to keep precision when dividing
// by scale
double m_SizeXBeforeConstrain;
double m_SizeYBeforeConstrain;
double m_SizeXBeforeConstrain;
double m_SizeYBeforeConstrain;
};
/** Mouse context */
struct MouseContextType
struct MouseContext
{
// TODO: Rename MouseContextType struct into NagivationContext (this is not a typedef).
/** Default constructor */
MouseContextType() :
/** \brief Default constructor. */
MouseContext() :
x( 0 ),
y( 0 ),
xMove( 0 ),
......@@ -167,10 +188,10 @@ protected:
protected:
/** */
NavigationContextType m_NavigationContext;
NavigationContext m_NavigationContext;
/** */
MouseContextType m_MouseContext;
MouseContext m_MouseContext;
/** */
double m_IsotropicZoom;
......
......@@ -128,6 +128,15 @@ GLImageWidget
this, SIGNAL( releasingMouse() ),
m_ImageModelRenderer, SLOT(onReleasedMouse())
);
// Connect this model region changed.
QObject::connect(
this,
SIGNAL( ModelImageRegionChanged( const ImageRegionType& ) ),
// to:
m_ImageViewManipulator,
SLOT( OnModelImageRegionChanged( const ImageRegionType& ) )
);
}
/*******************************************************************************/
......
......@@ -51,8 +51,6 @@ ImageViewManipulator
AbstractViewManipulator( parent ),
m_PreviousIsotropicZoom(1.)
{
// TODO: Remove later because initialized in struct's default constructor and resizeEvent().
this->InitializeContext(1,1);
}
/*****************************************************************************/
......@@ -61,17 +59,19 @@ ImageViewManipulator
{
}
/*******************************************************************************/
void
/*****************************************************************************/
bool
ImageViewManipulator
::InitializeContext(int width, int height)
::HasZoomChanged() const
{
ImageRegionType::SizeType initialSize;
initialSize[0] = width;
initialSize[1] = height;
bool res = false;
if (vcl_abs(m_IsotropicZoom - m_PreviousIsotropicZoom) > 0.00000001 )
{
res = true;
}
// initialize with the given size
m_NavigationContext.m_ViewportImageRegion.SetSize(initialSize);
return res;
}
/******************************************************************************/
......
......@@ -25,6 +25,10 @@
//// Included at first position before any other ones.
#include "ConfigureMonteverdi2.h"
/*****************************************************************************/
/* INCLUDE SECTION */
//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
......@@ -43,6 +47,10 @@
#include "mvdTypes.h"
#include "mvdAbstractViewManipulator.h"
/*****************************************************************************/
/* PRE-DECLARATION SECTION */
//
// External classes pre-declaration.
namespace
......@@ -54,8 +62,14 @@ namespace mvd
//
// Internal classes pre-declaration.
/** \class ImageViewManipulator
* Brief this class handles the event related to a QGLWidget. It also
/*****************************************************************************/
/* CLASS DEFINITION SECTION */
/**
* \class ImageViewManipulator
*
* \brief This class handles the event related to a QGLWidget. It also
* handles :
* - NavigationContext : to store the region of the image to be
* rendered.
......@@ -67,60 +81,72 @@ namespace mvd
class Monteverdi2_EXPORT ImageViewManipulator :
public AbstractViewManipulator
{
/*-[ QOBJECT SECTION ]-----------------------------------------------------*/
Q_OBJECT;
/*-[ PUBLIC SECTION ]------------------------------------------------------*/
//
// Public methods.
public:
/** Constructor */
/** \brief Constructor. */
ImageViewManipulator( QObject* parent =NULL );
/** Destructor */
/** \brief Destructor. */
virtual ~ImageViewManipulator();
/** */
void mouseMoveEvent ( QMouseEvent * event );
/** */
void mousePressEvent ( QMouseEvent * event );
/** */
void mouseReleaseEvent ( QMouseEvent * event );
/** */
void wheelEvent ( QWheelEvent* event);
/** */
void resizeEvent ( QResizeEvent * event );
/** */
void keyPressEvent( QKeyEvent * event );
inline
bool HasZoomChanged() const
{
bool res = false;
if (vcl_abs(m_IsotropicZoom - m_PreviousIsotropicZoom) > 0.00000001 )
{
res = true;
}
/** */
bool HasZoomChanged() const;
return res;
}
//
// SIGNALS.
signals:
/*-[ PUBLIC SLOTS SECTION ]-----------------------------------------------**/
//
// Public SLOTS.
public slots:
void InitializeContext(int width, int height);
void OnModelImageRegionChanged(const ImageRegionType & largestRegion);
/*-[ SIGNALS SECTION ]-----------------------------------------------------*/
//
// Signals.
signals:
/*-[ PROTECTED SECTION ]---------------------------------------------------*/
//
// Protected methods.
protected:
/** */
void ConstrainRegion( ImageRegionType& region, const ImageRegionType& largest);
/** */
void CenterRegion(double scale);
/** */
void ResizeRegion(unsigned int w, unsigned int h);
//
// Protected attributes.
protected:
/*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/
//
// Private types.
private:
......@@ -128,20 +154,32 @@ private:
//
// Private methods.
private:
/** */
void Zoom(const double scale);
/** */
void moveRegion(double dx, double dy);
//
// Private attributes.
private:
double m_PreviousIsotropicZoom;
/** */
double m_PreviousIsotropicZoom;
/*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/
//
// SLOTS.
// Slots.
private slots:
};
} // end namespace 'mvd'
/*****************************************************************************/
/* INLINE SECTION */
namespace mvd
{
} // end namespace 'mvd'
#endif // __mvdImageViewManipulator_h
......@@ -66,6 +66,8 @@ namespace mvd
/**
* \class MyClass
*
* \brief WIP.
*/
class Monteverdi2_EXPORT MyClass :
public QObject
......@@ -81,12 +83,18 @@ class Monteverdi2_EXPORT MyClass :
// Public methods.
public:
/** Constructor */
/** \brief Constructor. */
MyClass( QObject* parent =NULL );
/** Destructor */
/** \brief Destructor. */
virtual ~MyClass();
/*-[ PUBLIC SLOTS SECTION ]-----------------------------------------------**/
//
// Public SLOTS.
public slots:
/*-[ SIGNALS SECTION ]-----------------------------------------------------*/
//
......
......@@ -51,8 +51,6 @@ QuicklookViewManipulator
AbstractViewManipulator( parent ),
m_PreviousIsotropicZoom(1.)
{
// TODO: Remove later because initialized in struct's default constructor and resizeEvent().
this->InitializeContext(1,1);
}
/*****************************************************************************/
......@@ -61,17 +59,12 @@ QuicklookViewManipulator
{
}
/*******************************************************************************/
void
/*****************************************************************************/
bool
QuicklookViewManipulator
::InitializeContext(int width, int height)
::HasZoomChanged() const
{
ImageRegionType::SizeType initialSize;
initialSize[0] = width;
initialSize[1] = height;
// initialize with the given size
m_NavigationContext.m_ViewportImageRegion.SetSize(initialSize);
return false;
}
/******************************************************************************/
......@@ -329,14 +322,14 @@ QuicklookViewManipulator
void
QuicklookViewManipulator
::keyPressEvent( QKeyEvent * event )
{
{
}
/*****************************************************************************/
/* SLOTS */
/*****************************************************************************/
void QuicklookViewManipulator
void
QuicklookViewManipulator
::OnModelImageRegionChanged(const ImageRegionType & largestRegion)
{
// set back the zoom to 1
......
......@@ -25,6 +25,10 @@
//// Included at first position before any other ones.
#include "ConfigureMonteverdi2.h"
/*****************************************************************************/
/* INCLUDE SECTION */
//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
......@@ -44,6 +48,10 @@
#include "mvdTypes.h"
#include "mvdAbstractViewManipulator.h"
/*****************************************************************************/
/* PRE-DECLARATION SECTION */
//
// External classes pre-declaration.
namespace
......@@ -55,8 +63,14 @@ namespace mvd
//
// Internal classes pre-declaration.
/** \class QuicklookViewManipulator
* Brief this class handles the event related to a QGLWidget. It also
/*****************************************************************************/
/* CLASS DEFINITION SECTION */
/**
* \class QuicklookViewManipulator
*
* \brief This class handles the event related to a QGLWidget. It also
* handles :
* - NavigationContext : to store the region of the image to be
* rendered.
......@@ -68,105 +82,106 @@ namespace mvd
class Monteverdi2_EXPORT QuicklookViewManipulator :
public AbstractViewManipulator
{
/*-[ QOBJECT SECTION ]-----------------------------------------------------*/
Q_OBJECT;
/*-[ PUBLIC SECTION ]------------------------------------------------------*/
//
// Public methods.
public:
/** Constructor */
/** \brief Constructor. */
QuicklookViewManipulator( QObject* parent =NULL );
/** Destructor */
/** \brief Destructor. */
virtual ~QuicklookViewManipulator();
/** */
void mouseMoveEvent ( QMouseEvent * event );
/** */
void mousePressEvent ( QMouseEvent * event );
/** */
void mouseReleaseEvent ( QMouseEvent * event );
/** */
void wheelEvent ( QWheelEvent* event);
/** */
void resizeEvent ( QResizeEvent * event );
/** */
void keyPressEvent( QKeyEvent * event );
inline
bool HasZoomChanged() const
{
return false;
}
//
// SIGNALS.
signals:
/** */
bool HasZoomChanged() const;
/*-[ PUBLIC SLOTS SECTION ]-----------------------------------------------**/
//
// Public SLOTS.
public slots:
void InitializeContext(int width, int height);
void OnModelImageRegionChanged(const ImageRegionType & largestRegion);
/*-[ SIGNALS SECTION ]-----------------------------------------------------*/
//
// Signals.
signals:
/*-[ PROTECTED SECTION ]---------------------------------------------------*/
//
// Protected methods.
protected:
/** */
void ConstrainRegion( ImageRegionType& region, const ImageRegionType& largest);
/** */
void CenterRegion(double scale);
/** */
void ResizeRegion(unsigned int w, unsigned int h);
//
// Protected attributes.
protected:
/*-[ PRIVATE SECTION ]-----------------------------------------------------*/
//
// Private types.
private:
/** Navigation context */
struct NavigationContextType
{
ImageRegionType m_ViewportImageRegion;
ImageRegionType m_ModelImageRegion;
// Stored as double to keep precision when dividing
// by scale
double m_SizeXBeforeConstrain;
double m_SizeYBeforeConstrain;
};
/** Mouse context */
struct MouseContextType
{
/** Default constructor */
MouseContextType() :
x( 0 ),
y( 0 ),
xMove( 0 ),
yMove( 0 ),
dx( 0 ),
dy( 0 )
{
}
int x; // mousePress x
int y; // mousePress y
int xMove; // for mouseMove x
int yMove; // for mouseMove y
int dx; // mouseMove in x (Drag)
int dy; // mouseMove in y (Drag)
};
//
// Private methods.
private:
/** */
void Zoom(const double scale);
/** */
void moveRegion(double dx, double dy);
//
// Private attributes.
private:
double m_PreviousIsotropicZoom;
// TODO: No zoom for quicklook. Remove when implementation is cleaned.
double m_PreviousIsotropicZoom;
/*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/
//
// SLOTS.
// Slots.
private slots:
};
} // end namespace 'mvd'
/*****************************************************************************/
/* INLINE SECTION */
namespace mvd
{
} // end namespace 'mvd'
#endif // __mvdQuicklookViewManipulator_h
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