diff --git a/app/MainWindow.cpp b/app/MainWindow.cpp index 510cbd2..1c0ccbb 100644 --- a/app/MainWindow.cpp +++ b/app/MainWindow.cpp @@ -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 ); } diff --git a/app/View.cpp b/app/View.cpp index a1855d8..c289de3 100644 --- a/app/View.cpp +++ b/app/View.cpp @@ -26,7 +26,11 @@ #include #include +#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(); diff --git a/app/View.h b/app/View.h index 9b458d2..1f61d95 100644 --- a/app/View.h +++ b/app/View.h @@ -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; diff --git a/libglabels/Frame.cpp b/libglabels/Frame.cpp index 2cfaa4d..d06a72c 100644 --- a/libglabels/Frame.cpp +++ b/libglabels/Frame.cpp @@ -20,6 +20,8 @@ #include "Frame.h" +#include "Markup.h" + namespace libglabels { diff --git a/libglabels/Frame.h b/libglabels/Frame.h index c018081..1e5590e 100644 --- a/libglabels/Frame.h +++ b/libglabels/Frame.h @@ -25,16 +25,18 @@ #include #include #include +#include #include #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: diff --git a/libglabels/FrameCd.cpp b/libglabels/FrameCd.cpp index f1a437f..652ec49 100644 --- a/libglabels/FrameCd.cpp +++ b/libglabels/FrameCd.cpp @@ -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; + } + } diff --git a/libglabels/FrameCd.h b/libglabels/FrameCd.h index f79fa66..42b4c5d 100644 --- a/libglabels/FrameCd.h +++ b/libglabels/FrameCd.h @@ -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: diff --git a/libglabels/FrameEllipse.cpp b/libglabels/FrameEllipse.cpp index 09cce89..c9a898c 100644 --- a/libglabels/FrameEllipse.cpp +++ b/libglabels/FrameEllipse.cpp @@ -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; + } + } diff --git a/libglabels/FrameEllipse.h b/libglabels/FrameEllipse.h index 3f58266..d25a7bc 100644 --- a/libglabels/FrameEllipse.h +++ b/libglabels/FrameEllipse.h @@ -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: diff --git a/libglabels/FrameRect.cpp b/libglabels/FrameRect.cpp index 8f7de1f..79a781c 100644 --- a/libglabels/FrameRect.cpp +++ b/libglabels/FrameRect.cpp @@ -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; + } + } diff --git a/libglabels/FrameRect.h b/libglabels/FrameRect.h index 3548c37..d927108 100644 --- a/libglabels/FrameRect.h +++ b/libglabels/FrameRect.h @@ -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: diff --git a/libglabels/FrameRound.cpp b/libglabels/FrameRound.cpp index 86804d2..8560b34 100644 --- a/libglabels/FrameRound.cpp +++ b/libglabels/FrameRound.cpp @@ -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; + } + } diff --git a/libglabels/FrameRound.h b/libglabels/FrameRound.h index ae501aa..5599aa2 100644 --- a/libglabels/FrameRound.h +++ b/libglabels/FrameRound.h @@ -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: diff --git a/libglabels/Markup.h b/libglabels/Markup.h index fc7278b..6c2b9b3 100644 --- a/libglabels/Markup.h +++ b/libglabels/Markup.h @@ -21,6 +21,11 @@ #ifndef libglabels_Markup_h #define libglabels_Markup_h +#include +#include + +#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; }; - - }