Added markup implementation.
This commit is contained in:
+5
-1
@@ -638,6 +638,7 @@ namespace glabels
|
|||||||
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();
|
bool showGrid = settings.value( "showGrid", true ).toBool();
|
||||||
|
bool showMarkup = settings.value( "showMarkup", true ).toBool();
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
viewFileToolBarAction ->setChecked( showFileToolBar );
|
viewFileToolBarAction ->setChecked( showFileToolBar );
|
||||||
@@ -645,12 +646,14 @@ namespace glabels
|
|||||||
viewEditToolBarAction ->setChecked( showEditToolBar );
|
viewEditToolBarAction ->setChecked( showEditToolBar );
|
||||||
viewViewToolBarAction ->setChecked( showViewToolBar );
|
viewViewToolBarAction ->setChecked( showViewToolBar );
|
||||||
viewGridAction ->setChecked( showGrid );
|
viewGridAction ->setChecked( showGrid );
|
||||||
|
viewMarkupAction ->setChecked( showMarkup );
|
||||||
|
|
||||||
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 );
|
view ->setGridVisible( showGrid );
|
||||||
|
view ->setMarkupVisible( showMarkup );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -664,6 +667,7 @@ namespace glabels
|
|||||||
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.setValue( "showGrid", viewGridAction->isChecked() );
|
||||||
|
settings.setValue( "showMarkup", viewMarkupAction->isChecked() );
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -808,7 +812,7 @@ namespace glabels
|
|||||||
|
|
||||||
void MainWindow::viewMarkup( bool state )
|
void MainWindow::viewMarkup( bool state )
|
||||||
{
|
{
|
||||||
std::cout << "ACTION: edit->Markup" << std::endl;
|
view->setMarkupVisible( state );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,11 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "libglabels/Markup.h"
|
||||||
#include "libglabels/FrameRect.h"
|
#include "libglabels/FrameRect.h"
|
||||||
|
#include "libglabels/FrameRound.h"
|
||||||
|
#include "libglabels/FrameEllipse.h"
|
||||||
|
#include "libglabels/FrameCd.h"
|
||||||
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@@ -47,6 +51,9 @@ namespace
|
|||||||
const QColor gridLineColor( 192, 192, 192 );
|
const QColor gridLineColor( 192, 192, 192 );
|
||||||
const double gridLineWidthPixels = 1;
|
const double gridLineWidthPixels = 1;
|
||||||
const double gridSpacing = 9; // TODO: determine from locale.
|
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( mLabelLayer = new QGraphicsItemGroup() );
|
||||||
mScene->addItem( mGridLayer = new QGraphicsItemGroup() );
|
mScene->addItem( mGridLayer = new QGraphicsItemGroup() );
|
||||||
|
mScene->addItem( mMarkupLayer = new QGraphicsItemGroup() );
|
||||||
mScene->addItem( mObjectLayer = new QGraphicsItemGroup() );
|
mScene->addItem( mObjectLayer = new QGraphicsItemGroup() );
|
||||||
mScene->addItem( mForegroundLayer = new QGraphicsItemGroup() );
|
mScene->addItem( mForegroundLayer = new QGraphicsItemGroup() );
|
||||||
}
|
}
|
||||||
@@ -79,6 +87,7 @@ namespace glabels
|
|||||||
|
|
||||||
createLabelLayer();
|
createLabelLayer();
|
||||||
createGridLayer();
|
createGridLayer();
|
||||||
|
createMarkupLayer();
|
||||||
|
|
||||||
foreach (LabelModelObject* object, model->objectList() )
|
foreach (LabelModelObject* object, model->objectList() )
|
||||||
{
|
{
|
||||||
@@ -95,6 +104,12 @@ namespace glabels
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void View::setMarkupVisible( bool visibleFlag )
|
||||||
|
{
|
||||||
|
mMarkupLayer->setVisible( visibleFlag );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void View::zoomIn()
|
void View::zoomIn()
|
||||||
{
|
{
|
||||||
// Find closest standard zoom level to our current zoom
|
// 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 )
|
void View::addObjectToObjectLayer( LabelModelObject* object )
|
||||||
{
|
{
|
||||||
QGraphicsItem* item = object->createGraphicsItem();
|
QGraphicsItem* item = object->createGraphicsItem();
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ namespace glabels
|
|||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
public:
|
public:
|
||||||
void setGridVisible( bool visibleFlag );
|
void setGridVisible( bool visibleFlag );
|
||||||
|
void setMarkupVisible( bool visibleFlag );
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
@@ -102,6 +103,7 @@ namespace glabels
|
|||||||
void clearLayer( QGraphicsItemGroup* layer );
|
void clearLayer( QGraphicsItemGroup* layer );
|
||||||
void createLabelLayer();
|
void createLabelLayer();
|
||||||
void createGridLayer();
|
void createGridLayer();
|
||||||
|
void createMarkupLayer();
|
||||||
void addObjectToObjectLayer( LabelModelObject* object );
|
void addObjectToObjectLayer( LabelModelObject* object );
|
||||||
void createForegroundLayer();
|
void createForegroundLayer();
|
||||||
|
|
||||||
@@ -114,6 +116,7 @@ namespace glabels
|
|||||||
|
|
||||||
QGraphicsItemGroup* mLabelLayer;
|
QGraphicsItemGroup* mLabelLayer;
|
||||||
QGraphicsItemGroup* mGridLayer;
|
QGraphicsItemGroup* mGridLayer;
|
||||||
|
QGraphicsItemGroup* mMarkupLayer;
|
||||||
QGraphicsItemGroup* mObjectLayer;
|
QGraphicsItemGroup* mObjectLayer;
|
||||||
QGraphicsItemGroup* mForegroundLayer;
|
QGraphicsItemGroup* mForegroundLayer;
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
#include "Frame.h"
|
#include "Frame.h"
|
||||||
|
|
||||||
|
#include "Markup.h"
|
||||||
|
|
||||||
|
|
||||||
namespace libglabels
|
namespace libglabels
|
||||||
{
|
{
|
||||||
|
|||||||
+4
-1
@@ -25,16 +25,18 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QPainterPath>
|
#include <QPainterPath>
|
||||||
|
#include <QGraphicsItem>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
#include "Units.h"
|
#include "Units.h"
|
||||||
#include "Point.h"
|
#include "Point.h"
|
||||||
#include "Layout.h"
|
#include "Layout.h"
|
||||||
#include "Markup.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace libglabels
|
namespace libglabels
|
||||||
{
|
{
|
||||||
|
class Markup; // Forward reference
|
||||||
|
|
||||||
|
|
||||||
class Frame
|
class Frame
|
||||||
{
|
{
|
||||||
@@ -68,6 +70,7 @@ namespace libglabels
|
|||||||
virtual bool isSimilarTo( Frame *other ) const = 0;
|
virtual bool isSimilarTo( Frame *other ) const = 0;
|
||||||
|
|
||||||
virtual const QPainterPath &path() const = 0;
|
virtual const QPainterPath &path() const = 0;
|
||||||
|
virtual QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const = 0;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -86,5 +86,36 @@ namespace libglabels
|
|||||||
mPath.translate( w()/2 - mR1, h()/2 - mR1 );
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ namespace libglabels
|
|||||||
bool isSimilarTo( Frame *other ) const;
|
bool isSimilarTo( Frame *other ) const;
|
||||||
|
|
||||||
const QPainterPath &path() const { return mPath; }
|
const QPainterPath &path() const { return mPath; }
|
||||||
|
QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -64,5 +64,17 @@ namespace libglabels
|
|||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ namespace libglabels
|
|||||||
bool isSimilarTo( Frame *other ) const;
|
bool isSimilarTo( Frame *other ) const;
|
||||||
|
|
||||||
const QPainterPath &path() const { return mPath; }
|
const QPainterPath &path() const { return mPath; }
|
||||||
|
QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -64,5 +64,21 @@ namespace libglabels
|
|||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ namespace libglabels
|
|||||||
bool isSimilarTo( Frame *other ) const;
|
bool isSimilarTo( Frame *other ) const;
|
||||||
|
|
||||||
const QPainterPath &path() const { return mPath; }
|
const QPainterPath &path() const { return mPath; }
|
||||||
|
QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -62,5 +62,16 @@ namespace libglabels
|
|||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ namespace libglabels
|
|||||||
bool isSimilarTo( Frame *other ) const;
|
bool isSimilarTo( Frame *other ) const;
|
||||||
|
|
||||||
const QPainterPath &path() const { return mPath; }
|
const QPainterPath &path() const { return mPath; }
|
||||||
|
QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
+46
-2
@@ -21,6 +21,11 @@
|
|||||||
#ifndef libglabels_Markup_h
|
#ifndef libglabels_Markup_h
|
||||||
#define libglabels_Markup_h
|
#define libglabels_Markup_h
|
||||||
|
|
||||||
|
#include <QGraphicsItem>
|
||||||
|
#include <QPainterPath>
|
||||||
|
|
||||||
|
#include "Frame.h"
|
||||||
|
|
||||||
|
|
||||||
namespace libglabels
|
namespace libglabels
|
||||||
{
|
{
|
||||||
@@ -29,6 +34,7 @@ namespace libglabels
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual Markup *dup() const = 0;
|
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 ); }
|
Markup *dup() const { return new MarkupMargin( mSize ); }
|
||||||
|
|
||||||
|
QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const
|
||||||
|
{
|
||||||
|
return frame->createMarginGraphicsItem( mSize, pen );
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double mSize;
|
double mSize;
|
||||||
};
|
};
|
||||||
@@ -62,6 +73,14 @@ namespace libglabels
|
|||||||
|
|
||||||
Markup *dup() const { return new MarkupLine( mX1, mY1, mX2, mY2 ); }
|
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:
|
private:
|
||||||
double mX1;
|
double mX1;
|
||||||
double mY1;
|
double mY1;
|
||||||
@@ -86,6 +105,17 @@ namespace libglabels
|
|||||||
|
|
||||||
Markup *dup() const { return new MarkupRect( mX1, mY1, mW, mH, mR ); }
|
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:
|
private:
|
||||||
double mX1;
|
double mX1;
|
||||||
double mY1;
|
double mY1;
|
||||||
@@ -110,6 +140,14 @@ namespace libglabels
|
|||||||
|
|
||||||
Markup *dup() const { return new MarkupEllipse( mX1, mY1, mW, mH ); }
|
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:
|
private:
|
||||||
double mX1;
|
double mX1;
|
||||||
double mY1;
|
double mY1;
|
||||||
@@ -132,6 +170,14 @@ namespace libglabels
|
|||||||
|
|
||||||
Markup *dup() const { return new MarkupCircle( mX0, mY0, mR ); }
|
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:
|
private:
|
||||||
double mX0;
|
double mX0;
|
||||||
double mY0;
|
double mY0;
|
||||||
@@ -139,8 +185,6 @@ namespace libglabels
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // libglabels_Markup_h
|
#endif // libglabels_Markup_h
|
||||||
|
|||||||
Reference in New Issue
Block a user