Added markup implementation.

This commit is contained in:
Jim Evins
2013-12-13 22:56:58 -05:00
parent f017af3cac
commit 5c74625a97
14 changed files with 177 additions and 13 deletions
+14 -10
View File
@@ -638,19 +638,22 @@ namespace glabels
bool showEditToolBar = settings.value( "showEditToolBar", true ).toBool();
bool showViewToolBar = settings.value( "showViewToolBar", true ).toBool();
bool showGrid = settings.value( "showGrid", true ).toBool();
bool showMarkup = settings.value( "showMarkup", true ).toBool();
settings.endGroup();
viewFileToolBarAction->setChecked( showFileToolBar );
viewFileToolBarAction ->setChecked( showFileToolBar );
viewObjectsToolBarAction->setChecked( showObjectsToolBar );
viewEditToolBarAction->setChecked( showEditToolBar );
viewViewToolBarAction->setChecked( showViewToolBar );
viewGridAction->setChecked( showGrid );
viewEditToolBarAction ->setChecked( showEditToolBar );
viewViewToolBarAction ->setChecked( showViewToolBar );
viewGridAction ->setChecked( showGrid );
viewMarkupAction ->setChecked( showMarkup );
fileToolBar->setVisible( showFileToolBar );
objectsToolBar->setVisible( showObjectsToolBar );
editToolBar->setVisible( showEditToolBar );
viewToolBar->setVisible( showViewToolBar );
view->setGridVisible( showGrid );
fileToolBar ->setVisible( showFileToolBar );
objectsToolBar->setVisible( showObjectsToolBar );
editToolBar ->setVisible( showEditToolBar );
viewToolBar ->setVisible( showViewToolBar );
view ->setGridVisible( showGrid );
view ->setMarkupVisible( showMarkup );
}
@@ -664,6 +667,7 @@ namespace glabels
settings.setValue( "showEditToolBar", viewEditToolBarAction->isChecked() );
settings.setValue( "showViewToolBar", viewViewToolBarAction->isChecked() );
settings.setValue( "showGrid", viewGridAction->isChecked() );
settings.setValue( "showMarkup", viewMarkupAction->isChecked() );
settings.endGroup();
}
@@ -808,7 +812,7 @@ namespace glabels
void MainWindow::viewMarkup( bool state )
{
std::cout << "ACTION: edit->Markup" << std::endl;
view->setMarkupVisible( state );
}
+34
View File
@@ -26,7 +26,11 @@
#include <cmath>
#include <iostream>
#include "libglabels/Markup.h"
#include "libglabels/FrameRect.h"
#include "libglabels/FrameRound.h"
#include "libglabels/FrameEllipse.h"
#include "libglabels/FrameCd.h"
namespace
@@ -47,6 +51,9 @@ namespace
const QColor gridLineColor( 192, 192, 192 );
const double gridLineWidthPixels = 1;
const double gridSpacing = 9; // TODO: determine from locale.
const QColor markupLineColor( 240, 99, 99 );
const double markupLineWidthPixels = 1;
}
@@ -68,6 +75,7 @@ namespace glabels
mScene->addItem( mLabelLayer = new QGraphicsItemGroup() );
mScene->addItem( mGridLayer = new QGraphicsItemGroup() );
mScene->addItem( mMarkupLayer = new QGraphicsItemGroup() );
mScene->addItem( mObjectLayer = new QGraphicsItemGroup() );
mScene->addItem( mForegroundLayer = new QGraphicsItemGroup() );
}
@@ -79,6 +87,7 @@ namespace glabels
createLabelLayer();
createGridLayer();
createMarkupLayer();
foreach (LabelModelObject* object, model->objectList() )
{
@@ -95,6 +104,12 @@ namespace glabels
}
void View::setMarkupVisible( bool visibleFlag )
{
mMarkupLayer->setVisible( visibleFlag );
}
void View::zoomIn()
{
// Find closest standard zoom level to our current zoom
@@ -282,6 +297,25 @@ namespace glabels
}
void View::createMarkupLayer()
{
clearLayer( mMarkupLayer );
QPen pen( markupLineColor );
pen.setCosmetic( true );
pen.setWidthF( markupLineWidthPixels );
const libglabels::Frame* frame = mModel->frame();
foreach (libglabels::Markup* markup, frame->markups() )
{
QGraphicsItem* markupItem = markup->createGraphicsItem( frame, pen );
mMarkupLayer->addToGroup( markupItem );
}
}
void View::addObjectToObjectLayer( LabelModelObject* object )
{
QGraphicsItem* item = object->createGraphicsItem();
+3
View File
@@ -70,6 +70,7 @@ namespace glabels
/////////////////////////////////////
public:
void setGridVisible( bool visibleFlag );
void setMarkupVisible( bool visibleFlag );
/////////////////////////////////////
@@ -102,6 +103,7 @@ namespace glabels
void clearLayer( QGraphicsItemGroup* layer );
void createLabelLayer();
void createGridLayer();
void createMarkupLayer();
void addObjectToObjectLayer( LabelModelObject* object );
void createForegroundLayer();
@@ -114,6 +116,7 @@ namespace glabels
QGraphicsItemGroup* mLabelLayer;
QGraphicsItemGroup* mGridLayer;
QGraphicsItemGroup* mMarkupLayer;
QGraphicsItemGroup* mObjectLayer;
QGraphicsItemGroup* mForegroundLayer;
+2
View File
@@ -20,6 +20,8 @@
#include "Frame.h"
#include "Markup.h"
namespace libglabels
{
+4 -1
View File
@@ -25,16 +25,18 @@
#include <QString>
#include <QList>
#include <QPainterPath>
#include <QGraphicsItem>
#include <QVector>
#include "Units.h"
#include "Point.h"
#include "Layout.h"
#include "Markup.h"
namespace libglabels
{
class Markup; // Forward reference
class Frame
{
@@ -68,6 +70,7 @@ namespace libglabels
virtual bool isSimilarTo( Frame *other ) const = 0;
virtual const QPainterPath &path() const = 0;
virtual QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const = 0;
private:
+31
View File
@@ -86,5 +86,36 @@ namespace libglabels
mPath.translate( w()/2 - mR1, h()/2 - mR1 );
}
QGraphicsItem* FrameCd::createMarginGraphicsItem( double size, const QPen& pen ) const
{
double r1 = mR1 - size;
double r2 = mR2 + size;
QPainterPath path;
// Outer path (may be clipped in the case business card type CD)
double theta1 = acos( (mW-2*size) / (2*r1) ) * 180/M_PI;
double theta2 = asin( (mH-2*size) / (2*r1) ) * 180/M_PI;
path.arcMoveTo( 0, 0, 2*r1, 2*r1, theta1 );
path.arcTo( 0, 0, 2*r1, 2*r1, theta1, theta2-theta1 );
path.arcTo( 0, 0, 2*r1, 2*r1, 180-theta2, theta2-theta1 );
path.arcTo( 0, 0, 2*r1, 2*r1, 180+theta1, theta2-theta1 );
path.arcTo( 0, 0, 2*r1, 2*r1, 360-theta2, theta2-theta1 );
path.closeSubpath();
// Inner path (hole)
path.addEllipse( r1-r2, r1-r2, 2*r2, 2*r2 );
// Translate to account for offset with clipped business card CDs (applies to element already drawn)
path.translate( mW/2 - r1, mH/2 - r1 );
QGraphicsPathItem* item = new QGraphicsPathItem( path );
item->setPen( pen );
return item;
}
}
+1
View File
@@ -60,6 +60,7 @@ namespace libglabels
bool isSimilarTo( Frame *other ) const;
const QPainterPath &path() const { return mPath; }
QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const;
private:
+12
View File
@@ -64,5 +64,17 @@ namespace libglabels
return false;
}
QGraphicsItem* FrameEllipse::createMarginGraphicsItem( double size, const QPen& pen ) const
{
double w = mW - 2*size;
double h = mH - 2*size;
QGraphicsEllipseItem* item = new QGraphicsEllipseItem( size, size, w, h );
item->setPen( pen );
return item;
}
}
+1
View File
@@ -55,6 +55,7 @@ namespace libglabels
bool isSimilarTo( Frame *other ) const;
const QPainterPath &path() const { return mPath; }
QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const;
private:
+16
View File
@@ -64,5 +64,21 @@ namespace libglabels
return false;
}
QGraphicsItem* FrameRect::createMarginGraphicsItem( double size, const QPen& pen ) const
{
double w = mW - 2*size;
double h = mH - 2*size;
double r = std::max( mR - size, 0.0 );
QPainterPath path;
path.addRoundedRect( size, size, w, h, r, r );
QGraphicsPathItem* item = new QGraphicsPathItem( path );
item->setPen( pen );
return item;
}
}
+1
View File
@@ -60,6 +60,7 @@ namespace libglabels
bool isSimilarTo( Frame *other ) const;
const QPainterPath &path() const { return mPath; }
QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const;
private:
+11
View File
@@ -62,5 +62,16 @@ namespace libglabels
return false;
}
QGraphicsItem* FrameRound::createMarginGraphicsItem( double size, const QPen& pen ) const
{
double r = mR - size;
QGraphicsEllipseItem* item = new QGraphicsEllipseItem( mR-r, mR-r, 2*r, 2*r );
item->setPen( pen );
return item;
}
}
+1
View File
@@ -55,6 +55,7 @@ namespace libglabels
bool isSimilarTo( Frame *other ) const;
const QPainterPath &path() const { return mPath; }
QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const;
private:
+46 -2
View File
@@ -21,6 +21,11 @@
#ifndef libglabels_Markup_h
#define libglabels_Markup_h
#include <QGraphicsItem>
#include <QPainterPath>
#include "Frame.h"
namespace libglabels
{
@@ -29,6 +34,7 @@ namespace libglabels
{
public:
virtual Markup *dup() const = 0;
virtual QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const = 0;
};
@@ -43,6 +49,11 @@ namespace libglabels
Markup *dup() const { return new MarkupMargin( mSize ); }
QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const
{
return frame->createMarginGraphicsItem( mSize, pen );
}
private:
double mSize;
};
@@ -62,6 +73,14 @@ namespace libglabels
Markup *dup() const { return new MarkupLine( mX1, mY1, mX2, mY2 ); }
QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const
{
QGraphicsLineItem* item = new QGraphicsLineItem( mX1, mY1, mX2, mY2 );
item->setPen( pen );
return item;
}
private:
double mX1;
double mY1;
@@ -86,6 +105,17 @@ namespace libglabels
Markup *dup() const { return new MarkupRect( mX1, mY1, mW, mH, mR ); }
QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const
{
QPainterPath path;
path.addRoundedRect( mX1, mY1, mW, mH, mR, mR );
QGraphicsPathItem* item = new QGraphicsPathItem( path );
item->setPen( pen );
return item;
}
private:
double mX1;
double mY1;
@@ -110,6 +140,14 @@ namespace libglabels
Markup *dup() const { return new MarkupEllipse( mX1, mY1, mW, mH ); }
QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const
{
QGraphicsEllipseItem* item = new QGraphicsEllipseItem( mX1, mY1, mW, mH );
item->setPen( pen );
return item;
}
private:
double mX1;
double mY1;
@@ -132,13 +170,19 @@ namespace libglabels
Markup *dup() const { return new MarkupCircle( mX0, mY0, mR ); }
QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const
{
QGraphicsEllipseItem* item = new QGraphicsEllipseItem( mX0-mR, mY0-mR, 2*mR, 2*mR );
item->setPen( pen );
return item;
}
private:
double mX0;
double mY0;
double mR;
};
}