Added grid layer to view.
This commit is contained in:
+9
-5
@@ -222,12 +222,12 @@ namespace glabels
|
|||||||
viewGridAction = new QAction( tr("Grid"), this );
|
viewGridAction = new QAction( tr("Grid"), this );
|
||||||
viewGridAction->setCheckable( true );
|
viewGridAction->setCheckable( true );
|
||||||
viewGridAction->setStatusTip( tr("Change visibility of the grid in current window") );
|
viewGridAction->setStatusTip( tr("Change visibility of the grid in current window") );
|
||||||
connect( viewGridAction, SIGNAL(triggered()), this, SLOT(viewGrid()) );
|
connect( viewGridAction, SIGNAL(toggled(bool)), this, SLOT(viewGrid(bool)) );
|
||||||
|
|
||||||
viewMarkupAction = new QAction( tr("Markup"), this );
|
viewMarkupAction = new QAction( tr("Markup"), this );
|
||||||
viewMarkupAction->setCheckable( true );
|
viewMarkupAction->setCheckable( true );
|
||||||
viewMarkupAction->setStatusTip( tr("Change visibility of markup lines in current window") );
|
viewMarkupAction->setStatusTip( tr("Change visibility of markup lines in current window") );
|
||||||
connect( viewMarkupAction, SIGNAL(triggered()), this, SLOT(viewMarkup()) );
|
connect( viewMarkupAction, SIGNAL(toggled(bool)), this, SLOT(viewMarkup(bool)) );
|
||||||
|
|
||||||
viewZoomInAction = new QAction( tr("Zoom &In"), this );
|
viewZoomInAction = new QAction( tr("Zoom &In"), this );
|
||||||
viewZoomInAction->setIcon( QIcon::fromTheme( "zoom-in", Icons::Fallback::ZoomIn() ) );
|
viewZoomInAction->setIcon( QIcon::fromTheme( "zoom-in", Icons::Fallback::ZoomIn() ) );
|
||||||
@@ -637,17 +637,20 @@ namespace glabels
|
|||||||
bool showObjectsToolBar = settings.value( "showObjectsToolBar", true ).toBool();
|
bool showObjectsToolBar = settings.value( "showObjectsToolBar", true ).toBool();
|
||||||
bool showEditToolBar = settings.value( "showEditToolBar", true ).toBool();
|
bool showEditToolBar = settings.value( "showEditToolBar", true ).toBool();
|
||||||
bool showViewToolBar = settings.value( "showViewToolBar", true ).toBool();
|
bool showViewToolBar = settings.value( "showViewToolBar", true ).toBool();
|
||||||
|
bool showGrid = settings.value( "showGrid", true ).toBool();
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
viewFileToolBarAction->setChecked( showFileToolBar );
|
viewFileToolBarAction->setChecked( showFileToolBar );
|
||||||
viewObjectsToolBarAction->setChecked( showObjectsToolBar );
|
viewObjectsToolBarAction->setChecked( showObjectsToolBar );
|
||||||
viewEditToolBarAction->setChecked( showEditToolBar );
|
viewEditToolBarAction->setChecked( showEditToolBar );
|
||||||
viewViewToolBarAction->setChecked( showViewToolBar );
|
viewViewToolBarAction->setChecked( showViewToolBar );
|
||||||
|
viewGridAction->setChecked( showGrid );
|
||||||
|
|
||||||
fileToolBar->setVisible( showFileToolBar );
|
fileToolBar->setVisible( showFileToolBar );
|
||||||
objectsToolBar->setVisible( showObjectsToolBar );
|
objectsToolBar->setVisible( showObjectsToolBar );
|
||||||
editToolBar->setVisible( showEditToolBar );
|
editToolBar->setVisible( showEditToolBar );
|
||||||
viewToolBar->setVisible( showViewToolBar );
|
viewToolBar->setVisible( showViewToolBar );
|
||||||
|
view->setGridVisible( showGrid );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -660,6 +663,7 @@ namespace glabels
|
|||||||
settings.setValue( "showObjectsToolBar", viewObjectsToolBarAction->isChecked() );
|
settings.setValue( "showObjectsToolBar", viewObjectsToolBarAction->isChecked() );
|
||||||
settings.setValue( "showEditToolBar", viewEditToolBarAction->isChecked() );
|
settings.setValue( "showEditToolBar", viewEditToolBarAction->isChecked() );
|
||||||
settings.setValue( "showViewToolBar", viewViewToolBarAction->isChecked() );
|
settings.setValue( "showViewToolBar", viewViewToolBarAction->isChecked() );
|
||||||
|
settings.setValue( "showGrid", viewGridAction->isChecked() );
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -796,13 +800,13 @@ namespace glabels
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::viewGrid()
|
void MainWindow::viewGrid( bool state )
|
||||||
{
|
{
|
||||||
std::cout << "ACTION: edit->Grid" << std::endl;
|
view->setGridVisible( state );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::viewMarkup()
|
void MainWindow::viewMarkup( bool state )
|
||||||
{
|
{
|
||||||
std::cout << "ACTION: edit->Markup" << std::endl;
|
std::cout << "ACTION: edit->Markup" << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -72,8 +72,8 @@ namespace glabels
|
|||||||
void viewObjectsToolBar( bool );
|
void viewObjectsToolBar( bool );
|
||||||
void viewEditToolBar( bool );
|
void viewEditToolBar( bool );
|
||||||
void viewViewToolBar( bool );
|
void viewViewToolBar( bool );
|
||||||
void viewGrid();
|
void viewGrid( bool );
|
||||||
void viewMarkup();
|
void viewMarkup( bool );
|
||||||
void viewZoomIn();
|
void viewZoomIn();
|
||||||
void viewZoomOut();
|
void viewZoomOut();
|
||||||
void viewZoom1To1();
|
void viewZoom1To1();
|
||||||
|
|||||||
+100
-9
@@ -21,10 +21,13 @@
|
|||||||
#include "View.h"
|
#include "View.h"
|
||||||
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QGraphicsLineItem>
|
||||||
#include <QGraphicsDropShadowEffect>
|
#include <QGraphicsDropShadowEffect>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "libglabels/FrameRect.h"
|
||||||
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@@ -40,6 +43,10 @@ namespace
|
|||||||
const QColor labelColor( 255, 255, 255 );
|
const QColor labelColor( 255, 255, 255 );
|
||||||
const QColor labelOutlineColor( 0, 0, 0 );
|
const QColor labelOutlineColor( 0, 0, 0 );
|
||||||
const double labelOutlineWidthPixels = 1;
|
const double labelOutlineWidthPixels = 1;
|
||||||
|
|
||||||
|
const QColor gridLineColor( 192, 192, 192 );
|
||||||
|
const double gridLineWidthPixels = 1;
|
||||||
|
const double gridSpacing = 9; // TODO: determine from locale.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -58,6 +65,11 @@ namespace glabels
|
|||||||
|
|
||||||
mScene = new QGraphicsScene();
|
mScene = new QGraphicsScene();
|
||||||
setScene( mScene );
|
setScene( mScene );
|
||||||
|
|
||||||
|
mScene->addItem( mLabelLayer = new QGraphicsItemGroup() );
|
||||||
|
mScene->addItem( mGridLayer = new QGraphicsItemGroup() );
|
||||||
|
mScene->addItem( mObjectLayer = new QGraphicsItemGroup() );
|
||||||
|
mScene->addItem( mForegroundLayer = new QGraphicsItemGroup() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -66,12 +78,20 @@ namespace glabels
|
|||||||
mModel = model;
|
mModel = model;
|
||||||
|
|
||||||
createLabelLayer();
|
createLabelLayer();
|
||||||
|
createGridLayer();
|
||||||
|
|
||||||
foreach (LabelModelObject* object, model->objectList() )
|
foreach (LabelModelObject* object, model->objectList() )
|
||||||
{
|
{
|
||||||
QGraphicsItem* item = object->createGraphicsItem();
|
addObjectToObjectLayer( object );
|
||||||
mScene->addItem( item );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createForegroundLayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void View::setGridVisible( bool visibleFlag )
|
||||||
|
{
|
||||||
|
mGridLayer->setVisible( visibleFlag );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -191,26 +211,97 @@ namespace glabels
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void View::clearLayer( QGraphicsItemGroup* layer )
|
||||||
|
{
|
||||||
|
foreach( QGraphicsItem* item, layer->childItems() )
|
||||||
|
{
|
||||||
|
layer->removeFromGroup( item );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void View::createLabelLayer()
|
void View::createLabelLayer()
|
||||||
{
|
{
|
||||||
|
clearLayer( mLabelLayer );
|
||||||
|
|
||||||
QGraphicsPathItem *labelItem = new QGraphicsPathItem( mModel->frame()->path() );
|
QGraphicsPathItem *labelItem = new QGraphicsPathItem( mModel->frame()->path() );
|
||||||
|
|
||||||
QBrush brush( labelColor );
|
QBrush brush( labelColor );
|
||||||
labelItem->setBrush( brush );
|
labelItem->setBrush( brush );
|
||||||
|
|
||||||
QPen pen( labelOutlineColor );
|
|
||||||
pen.setJoinStyle( Qt::MiterJoin );
|
|
||||||
pen.setCosmetic( true );
|
|
||||||
pen.setWidthF( labelOutlineWidthPixels );
|
|
||||||
labelItem->setPen( pen );
|
|
||||||
|
|
||||||
QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect();
|
QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect();
|
||||||
shadowEffect->setColor( shadowColor );
|
shadowEffect->setColor( shadowColor );
|
||||||
shadowEffect->setOffset( shadowOffsetPixels );
|
shadowEffect->setOffset( shadowOffsetPixels );
|
||||||
shadowEffect->setBlurRadius( shadowRadiusPixels );
|
shadowEffect->setBlurRadius( shadowRadiusPixels );
|
||||||
labelItem->setGraphicsEffect( shadowEffect );
|
labelItem->setGraphicsEffect( shadowEffect );
|
||||||
|
|
||||||
mScene->addItem( labelItem );
|
mLabelLayer->addToGroup( labelItem );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void View::createGridLayer()
|
||||||
|
{
|
||||||
|
clearLayer( mGridLayer );
|
||||||
|
|
||||||
|
QGraphicsPathItem *clipItem = new QGraphicsPathItem( mModel->frame()->path() );
|
||||||
|
clipItem->setFlag( QGraphicsItem::ItemClipsChildrenToShape );
|
||||||
|
|
||||||
|
QPen pen( gridLineColor );
|
||||||
|
pen.setCosmetic( true );
|
||||||
|
pen.setWidthF( gridLineWidthPixels );
|
||||||
|
|
||||||
|
double w = mModel->w();
|
||||||
|
double h = mModel->h();
|
||||||
|
double x0;
|
||||||
|
double y0;
|
||||||
|
if ( dynamic_cast<const libglabels::FrameRect*>( mModel->frame() ) )
|
||||||
|
{
|
||||||
|
x0 = gridSpacing;
|
||||||
|
y0 = gridSpacing;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* round labels, align grid with center of label. */
|
||||||
|
x0 = fmod( w/2, gridSpacing );
|
||||||
|
y0 = fmod( h/2, gridSpacing );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( double x = x0; x < w; x += gridSpacing )
|
||||||
|
{
|
||||||
|
QGraphicsLineItem* lineItem = new QGraphicsLineItem( x, 0, x, h, clipItem );
|
||||||
|
lineItem->setPen( pen );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( double y = y0; y < h; y += gridSpacing )
|
||||||
|
{
|
||||||
|
QGraphicsLineItem* lineItem = new QGraphicsLineItem( 0, y, w, y, clipItem );
|
||||||
|
lineItem->setPen( pen );
|
||||||
|
}
|
||||||
|
|
||||||
|
mGridLayer->addToGroup( clipItem );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void View::addObjectToObjectLayer( LabelModelObject* object )
|
||||||
|
{
|
||||||
|
QGraphicsItem* item = object->createGraphicsItem();
|
||||||
|
mObjectLayer->addToGroup( item );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void View::createForegroundLayer()
|
||||||
|
{
|
||||||
|
clearLayer( mForegroundLayer );
|
||||||
|
|
||||||
|
QGraphicsPathItem *outlineItem = new QGraphicsPathItem( mModel->frame()->path() );
|
||||||
|
|
||||||
|
QPen pen( labelOutlineColor );
|
||||||
|
pen.setJoinStyle( Qt::MiterJoin );
|
||||||
|
pen.setCosmetic( true );
|
||||||
|
pen.setWidthF( labelOutlineWidthPixels );
|
||||||
|
outlineItem->setPen( pen );
|
||||||
|
|
||||||
|
mForegroundLayer->addToGroup( outlineItem );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-4
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
|
#include <QGraphicsItemGroup>
|
||||||
|
|
||||||
#include "LabelModel.h"
|
#include "LabelModel.h"
|
||||||
|
|
||||||
@@ -64,6 +65,13 @@ namespace glabels
|
|||||||
void setModel( LabelModel* model );
|
void setModel( LabelModel* model );
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////
|
||||||
|
// Visibility operations
|
||||||
|
/////////////////////////////////////
|
||||||
|
public:
|
||||||
|
void setGridVisible( bool visibleFlag );
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
// Zoom operations
|
// Zoom operations
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
@@ -91,19 +99,28 @@ namespace glabels
|
|||||||
// Private methods
|
// Private methods
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
private:
|
private:
|
||||||
|
void clearLayer( QGraphicsItemGroup* layer );
|
||||||
void createLabelLayer();
|
void createLabelLayer();
|
||||||
|
void createGridLayer();
|
||||||
|
void addObjectToObjectLayer( LabelModelObject* object );
|
||||||
|
void createForegroundLayer();
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
// Private data
|
// Private data
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
private:
|
private:
|
||||||
QGraphicsScene* mScene;
|
QGraphicsScene* mScene;
|
||||||
|
|
||||||
double mZoom;
|
QGraphicsItemGroup* mLabelLayer;
|
||||||
bool mZoomToFitFlag;
|
QGraphicsItemGroup* mGridLayer;
|
||||||
|
QGraphicsItemGroup* mObjectLayer;
|
||||||
|
QGraphicsItemGroup* mForegroundLayer;
|
||||||
|
|
||||||
LabelModel* mModel;
|
double mZoom;
|
||||||
|
bool mZoomToFitFlag;
|
||||||
|
|
||||||
|
LabelModel* mModel;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user