From 6d2b05ccc41435768f5c6e658703070b0e3e3e34 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Tue, 10 Nov 2020 20:55:39 +0100 Subject: [PATCH 01/34] Add uuid to current piece infos --- src/app/puzzle/vpmainwindow.cpp | 1 + src/app/puzzle/vpmainwindow.ui | 39 ++++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 863da9047..f41ee55ec 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -356,6 +356,7 @@ void VPMainWindow::SetPropertyTabCurrentPieceData() // set the value to the current piece ui->lineEditCurrentPieceName->setText(selectedPiece->GetName()); + ui->plainTextEditCurrentPieceUUID->setPlainText(selectedPiece->GetUUID().toString()); ui->checkBoxCurrentPieceShowSeamline->setChecked(selectedPiece->GetShowSeamLine()); ui->checkBoxCurrentPieceMirrorPiece->setChecked(selectedPiece->GetPieceMirrored()); diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 4684fbd66..ab98f6eb8 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -36,7 +36,7 @@ 0 0 1427 - 21 + 22 @@ -234,7 +234,7 @@ 0 0 342 - 1252 + 1318 @@ -275,6 +275,13 @@ Infos + + + + Name: + + + @@ -285,10 +292,26 @@ - - + + - Name: + UUID: + + + + + + + + 16777215 + 48 + + + + true + + + {7b2ce4ae-96f5-4905-bb34-405cb40ca208} @@ -542,7 +565,7 @@ 0 0 356 - 761 + 760 @@ -958,7 +981,7 @@ 0 0 356 - 761 + 760 @@ -1031,7 +1054,7 @@ 0 0 356 - 761 + 760 From f448514c71716489d490011bf92bac7680b75bce Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Tue, 10 Nov 2020 21:29:23 +0100 Subject: [PATCH 02/34] take into account Show Seamline --- src/app/puzzle/vpgraphicspiece.cpp | 12 +++++++++++- src/app/puzzle/vpgraphicspiece.h | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/app/puzzle/vpgraphicspiece.cpp b/src/app/puzzle/vpgraphicspiece.cpp index d369e98ea..3ee802c11 100644 --- a/src/app/puzzle/vpgraphicspiece.cpp +++ b/src/app/puzzle/vpgraphicspiece.cpp @@ -109,6 +109,7 @@ void VPGraphicsPiece::Init() connect(m_piece, &VPPiece::SelectionChanged, this, &VPGraphicsPiece::on_PieceSelectionChanged); connect(m_piece, &VPPiece::PositionChanged, this, &VPGraphicsPiece::on_PiecePositionChanged); connect(m_piece, &VPPiece::RotationChanged, this, &VPGraphicsPiece::on_PieceRotationChanged); + connect(m_piece, &VPPiece::PropertiesChanged, this, &VPGraphicsPiece::on_PiecePropertiesChanged); } //--------------------------------------------------------------------------------------------------------------------- @@ -168,7 +169,7 @@ void VPGraphicsPiece::paint(QPainter *painter, const QStyleOptionGraphicsItem *o } // paint the seam line - if(!m_seamLine.isEmpty()) + if(!m_seamLine.isEmpty() && m_piece->GetShowSeamLine()) { painter->drawPath(m_seamLine); } @@ -370,6 +371,15 @@ void VPGraphicsPiece::on_PieceRotationChanged() setRotation(-m_piece->GetRotation()); } +//--------------------------------------------------------------------------------------------------------------------- +void VPGraphicsPiece::on_PiecePropertiesChanged() +{ + if(scene()) + { + scene()->update(); + } +} + //--------------------------------------------------------------------------------------------------------------------- QVariant VPGraphicsPiece::itemChange(GraphicsItemChange change, const QVariant &value) { diff --git a/src/app/puzzle/vpgraphicspiece.h b/src/app/puzzle/vpgraphicspiece.h index 858c4a177..03c543cf8 100644 --- a/src/app/puzzle/vpgraphicspiece.h +++ b/src/app/puzzle/vpgraphicspiece.h @@ -63,6 +63,11 @@ public slots: */ void on_PieceRotationChanged(); + /** + * @brief on_PiecePropertiesChanged Slot called when the showSeamline / mirrored was changed + */ + void on_PiecePropertiesChanged(); + protected: QRectF boundingRect() const override; QPainterPath shape() const override; From 23c4f8190415c89817fcaf1ac91e9fffaf6cfde1 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Tue, 10 Nov 2020 21:46:23 +0100 Subject: [PATCH 03/34] Hide some ui elements for MVP --- src/app/puzzle/vpmainwindow.cpp | 12 +++++++++++- src/app/puzzle/vpmainwindow.ui | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index f41ee55ec..34ed3bd96 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -369,6 +369,9 @@ void VPMainWindow::SetPropertyTabCurrentPieceData() qreal angle = selectedPiece->GetRotation(); SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceAngle, angle); + + // FIXME ---- For MVP we hide a few things. To be displayed when functions there + ui->groupBoxLayoutControl->hide(); } else { @@ -415,6 +418,10 @@ void VPMainWindow::SetPropertyTabSheetData() // set the checkboxes SetCheckBoxValue(ui->checkBoxSheetStickyEdges, m_layout->GetFocusedSheet()->GetStickyEdges()); + + // FIXME ---- For MVP we hide a few things. To be displayed when functions there + ui->pushButtonSheetRemoveUnusedLength->hide(); + ui->groupBoxSheetControl->hide(); } //--------------------------------------------------------------------------------------------------------------------- @@ -434,12 +441,15 @@ void VPMainWindow::SetPropertyTabLayoutData() // set controls SetCheckBoxValue(ui->checkBoxLayoutWarningPiecesOutOfBound, m_layout->GetWarningPiecesOutOfBound()); SetCheckBoxValue(ui->checkBoxLayoutWarningPiecesSuperposition, m_layout->GetWarningSuperpositionOfPieces()); + + // FIXME ---- For MVP we hide a few things. To be displayed when functions there + ui->groupBoxLayoutControl->hide(); } //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::SetPropertyTabTilesData() { - +// TODO } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index ab98f6eb8..0ad8dd2c2 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -176,7 +176,7 @@ QTabWidget::Rounded - 0 + 1 From c0c85bb2d5b0406162bda8e7aac22ed65041bca3 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Wed, 11 Nov 2020 19:14:06 +0100 Subject: [PATCH 04/34] Layout name und description persistence --- src/app/puzzle/vplayout.cpp | 25 +++++++++++++++++++++++++ src/app/puzzle/vplayout.h | 27 +++++++++++++++++++++++++++ src/app/puzzle/vpmainwindow.cpp | 6 ++++++ src/app/puzzle/vpmainwindow.ui | 4 ++-- 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/app/puzzle/vplayout.cpp b/src/app/puzzle/vplayout.cpp index fe77d2959..6f14c4cae 100644 --- a/src/app/puzzle/vplayout.cpp +++ b/src/app/puzzle/vplayout.cpp @@ -141,6 +141,31 @@ bool VPLayout::GetWarningPiecesOutOfBound() const return m_warningPiecesOutOfBound; } +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetTitle(QString title) +{ + m_title = title; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VPLayout::GetTitle() const +{ + return m_title; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetDescription(QString description) +{ + m_description = description; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VPLayout::GetDescription() const +{ + return m_description; +} + + //--------------------------------------------------------------------------------------------------------------------- void VPLayout::ClearSelection() { diff --git a/src/app/puzzle/vplayout.h b/src/app/puzzle/vplayout.h index a81017bb8..17a529a9b 100644 --- a/src/app/puzzle/vplayout.h +++ b/src/app/puzzle/vplayout.h @@ -78,6 +78,30 @@ public: void SetWarningPiecesOutOfBound(bool state); bool GetWarningPiecesOutOfBound() const; + /** + * @brief SetTitle Sets the title of the layout to the given value + * @param title the title of the layout + */ + void SetTitle(QString title); + + /** + * @brief GetTitle Returns the title of the layout + * @return + */ + QString GetTitle() const; + + /** + * @brief SetDescription Sets the description of the layout to the given value + * @param description the description of the layout + */ + void SetDescription(QString description); + + /** + * @brief GetDescription Returns the description of the layout. + * @return + */ + QString GetDescription() const; + /** * @brief ClearSelection goes through the unplaced pieces and through the sheets and calls * SetIsSelected(false) for the pieces that were selected. @@ -141,6 +165,9 @@ private: bool m_warningSuperpositionOfPieces{false}; bool m_warningPiecesOutOfBound{false}; + QString m_title{}; + QString m_description{}; + }; diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 34ed3bd96..26e19bbb0 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -73,6 +73,8 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : m_layout->SetUnit(Unit::Cm); m_layout->SetWarningSuperpositionOfPieces(true); + m_layout->SetTitle(QString("My Test Layout")); + m_layout->SetDescription(QString("Description of my Layout")); // -------------------------------------------------------- ui->setupUi(this); @@ -250,6 +252,10 @@ void VPMainWindow::InitPropertyTabCurrentPiece() //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::InitPropertyTabLayout() { + // --------------- init the title and derscription ----------------- + ui->lineEditLayoutName->setText(m_layout->GetTitle()); + ui->plainTextEditLayoutDescription->setPlainText(m_layout->GetDescription()); + // -------------------- init the unit combobox --------------------- ui->comboBoxLayoutUnit->addItem(tr("Centimeters"), QVariant(UnitsToStr(Unit::Cm))); ui->comboBoxLayoutUnit->addItem(tr("Millimiters"), QVariant(UnitsToStr(Unit::Mm))); diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 0ad8dd2c2..fbbf5e704 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -176,7 +176,7 @@ QTabWidget::Rounded - 1 + 3 @@ -1089,7 +1089,7 @@ - My layout + From 9fb4a2cc39298d43361d1b207897b444ed2298da Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Wed, 11 Nov 2020 19:31:39 +0100 Subject: [PATCH 05/34] init tab refactoring --- src/app/puzzle/vpmainwindow.cpp | 33 +++++++++++++++++++-------------- src/app/puzzle/vpmainwindow.h | 5 +++++ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 26e19bbb0..ca83c6b61 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -233,6 +233,7 @@ void VPMainWindow::InitMenuBar() void VPMainWindow::InitProperties() { InitPropertyTabCurrentPiece(); + InitPropertyTabCurrentSheet(); InitPropertyTabLayout(); InitPropertyTabTiles(); } @@ -240,6 +241,10 @@ void VPMainWindow::InitProperties() //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::InitPropertyTabCurrentPiece() { + // FIXME ---- For MVP we hide a few things. To be displayed when functions there + ui->groupBoxLayoutControl->hide(); + ui->groupBoxCurrentPieceGeometry->hide(); + // ------------------------------ placement ----------------------------------- connect(ui->doubleSpinBoxCurrentPieceBoxPositionX, QOverload::of(&QDoubleSpinBox::valueChanged), this, @@ -248,13 +253,21 @@ void VPMainWindow::InitPropertyTabCurrentPiece() &VPMainWindow::on_CurrentPiecePositionEdited); } +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::InitPropertyTabCurrentSheet() +{ + // FIXME ---- For MVP we hide a few things. To be displayed when functions there + ui->pushButtonSheetRemoveUnusedLength->hide(); + ui->groupBoxSheetControl->hide(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::InitPropertyTabLayout() { - // --------------- init the title and derscription ----------------- - ui->lineEditLayoutName->setText(m_layout->GetTitle()); - ui->plainTextEditLayoutDescription->setPlainText(m_layout->GetDescription()); + + // FIXME ---- For MVP we hide a few things. To be displayed when functions there + ui->groupBoxLayoutControl->hide(); // -------------------- init the unit combobox --------------------- ui->comboBoxLayoutUnit->addItem(tr("Centimeters"), QVariant(UnitsToStr(Unit::Cm))); @@ -375,9 +388,6 @@ void VPMainWindow::SetPropertyTabCurrentPieceData() qreal angle = selectedPiece->GetRotation(); SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceAngle, angle); - - // FIXME ---- For MVP we hide a few things. To be displayed when functions there - ui->groupBoxLayoutControl->hide(); } else { @@ -424,16 +434,14 @@ void VPMainWindow::SetPropertyTabSheetData() // set the checkboxes SetCheckBoxValue(ui->checkBoxSheetStickyEdges, m_layout->GetFocusedSheet()->GetStickyEdges()); - - // FIXME ---- For MVP we hide a few things. To be displayed when functions there - ui->pushButtonSheetRemoveUnusedLength->hide(); - ui->groupBoxSheetControl->hide(); } //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::SetPropertyTabLayoutData() { - // TODO FIXME : Set name and description + // set the title and description + ui->lineEditLayoutName->setText(m_layout->GetTitle()); + ui->plainTextEditLayoutDescription->setPlainText(m_layout->GetDescription()); // set Unit int index = ui->comboBoxLayoutUnit->findData(QVariant(UnitsToStr(m_layout->GetUnit()))); @@ -447,9 +455,6 @@ void VPMainWindow::SetPropertyTabLayoutData() // set controls SetCheckBoxValue(ui->checkBoxLayoutWarningPiecesOutOfBound, m_layout->GetWarningPiecesOutOfBound()); SetCheckBoxValue(ui->checkBoxLayoutWarningPiecesSuperposition, m_layout->GetWarningSuperpositionOfPieces()); - - // FIXME ---- For MVP we hide a few things. To be displayed when functions there - ui->groupBoxLayoutControl->hide(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index 65380c4dc..c7229b089 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -119,6 +119,11 @@ private: */ void InitPropertyTabCurrentPiece(); + /** + * @brief InitPropertyTabCurrentSheet Inits the current sheet tab in the properties; + */ + void InitPropertyTabCurrentSheet(); + /** * @brief InitPropertyTabLayout Inits the layout tab in the properties */ From e1c79b0db5fb8063def9412d8bfa6f3ac60b735a Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Wed, 11 Nov 2020 21:09:01 +0100 Subject: [PATCH 06/34] Icon for the layout tab --- src/app/puzzle/share/resources/puzzleicon.qrc | 1 + .../puzzleicon/64x64/iconProperties.png | Bin 0 -> 1576 bytes .../puzzleicon/64x64/iconProperties@2x.png | Bin 0 -> 3250 bytes .../puzzleicon/svg/iconProperties.svg | 136 ++++++++++++++++++ src/app/puzzle/vpmainwindow.ui | 8 +- 5 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 src/app/puzzle/share/resources/puzzleicon/64x64/iconProperties.png create mode 100644 src/app/puzzle/share/resources/puzzleicon/64x64/iconProperties@2x.png create mode 100644 src/app/puzzle/share/resources/puzzleicon/svg/iconProperties.svg diff --git a/src/app/puzzle/share/resources/puzzleicon.qrc b/src/app/puzzle/share/resources/puzzleicon.qrc index 809e972be..50e94a444 100644 --- a/src/app/puzzle/share/resources/puzzleicon.qrc +++ b/src/app/puzzle/share/resources/puzzleicon.qrc @@ -10,5 +10,6 @@ puzzleicon/64x64/iconGrainlineVertical.png puzzleicon/64x64/iconGrainlineHorizontal.png puzzleicon/64x64/cursorRotate.png + puzzleicon/64x64/iconProperties.png diff --git a/src/app/puzzle/share/resources/puzzleicon/64x64/iconProperties.png b/src/app/puzzle/share/resources/puzzleicon/64x64/iconProperties.png new file mode 100644 index 0000000000000000000000000000000000000000..0dc054e3f309a84fa47e8104dcbd273cc7d2f19e GIT binary patch literal 1576 zcmV+@2G{wCP)%lUE$Ze=RMgP$pNIH}EzThchz}=NO9@bW$Ql;~2s&Ucw~V42F;qXN3Z* zAWmXrW*7(?a~}+J5CW4sl10GX#N8azD8if(T_h;rR-x}cAViH6Ex5kaKFRy#oagj8 z=ht)kf8V4pj4Ul6Sjm+-(jsLh001DBN|8t;quE3$K@cz+jb@M60zz6^nlMqN)9FUt z0aCN^Scz-^EIk2B%Lc&G6R@;w0L&e@eED)D5{W3ThK7d!AAq%J)H}hEbmYhpZr!>y zo^vr>SVG05r~U}o09bkgmX@synmy7=WGjP~2o;l_`XgWiVCe~1TDCH1 z_DCy{tqfWsR7`s6kAMw;r6*u%S#=p47#MhR0K_b#(a5e{yGTh%8ERU?2tW8%R|W+^ zAT~CZ+}vDzT&B>~*Ue2sUm)-$5Dnb7Ev%{x3WC6n9XrU)&1I?g3sk*!0DC(biwn1O zoxO4C4M4&mg#Mv1R&xXdL15?3og6-Vn7M8Z-QhR>bnD4sCV{Ru90pxMd zx~&F4LP7$E4jlsEV%J~jFPs?eQ_2)HuFvrbnC#aByaVhT>az*}iHV71Wo7ZApBK&h zz{|stn1+3Pajs(6<0MydVqLasf$OY0Ks?|MA}E7nd6EOrXf$MIX0mABWNJR_tU}-uEfvHr~mG{UB(1J3`$8!L8sH<|C}c^yRYHyJlO6x9cq($ zQ90SOwLYD^vt_pdGEN`u`szZ168Ijt2qGwh=2jD(PKQ>j#c#F;wY#t5`ON+O{@w%B zrP{GHLEznn3`I#>L)-E8Q!{}}!0QbDd1_*o!OYA|G#U-QGu^1$^EX~D5BCMkHc-9? zLR0BK-hOHp@F%bWXdm)SxFc}z;6V}-6PfGnO8uT2OmQ{sZ@&fz$bqZCYM|}j{s{#j zJ3E{B_;|dhOrl29#WZ)*{?F>A#C{3_^fCC&w?62ZFaYxM@`#IzW4f0!4ccyIPB!f? zY?2Z4i7SM&f1 z3JQpciNVuVNsZ>In@9b8Q3EI}EM(iZZFsmkQm^f0{&ds+ ziWV7B2P8N-Ia51CmhX@Bj{Qr4y0VJEYvtgMVBOO`xVp4oSTPeM&iO?MYBqc-U_i|3g3*Z(3V ze6I{UnVgD>3W9@!A3IZ2J0K?~2ZOgPIy*agbKNUseDD@+ zSMTuZZadl^fN<)Z6!k|640nta6%`Q@5;CS-(EzBdtOOt=Xd&-Ktso=uZQ8F5uqs)? zl^cVemNqGBosxeH1L*a7!otGFoGTgtRaI3e?BxUp%m?88s1<1AA~}CWU}X|ioR+Xs ztE8vTKv7WOxw)B_7yII*R1CK#Y+b{ajVo!r4C+*Yo<0M|jvXUB zJbc`;MNtOp>gwq4?`KueLjE=M)A-{bRGs{Z>XW~6{?Ziy92^`dC@5gVh7IGIEeZfb z=U-p>9eZ<1>FK=3iP)zUO1rF(5c5YE zLA0?$-LZ!TOmJOG1OUL+@ki+Jun&)EO1^-576B$O*8rrWzY73~L`r%1dLf)0;Vx1z zf48hHRR{pUs-dTS$22&5GdtAu(IX+e#-ZK3QvnDI4|toDn3@V6axZkqjBG|@8nXj3 zoLy60p1WR7eV(AlZ!R~)RU%na7q7HB!g=9BQF0ZXYwRBq}Ou)8OA(Ea1;#q(oaS2Kv9i#}~7);Vln& zbpko9tg4!}V%9_fM*rDd*!4#GK}U#ZTm}zl{tZy^^#0p8a9$l zNiGYKZZUMG@w}SL{|&vMW5NSh;Ip7Rtoi;pz%?CL;3<6um`nA(E07_N1NcEe2GjlD zkOAIL%IgI&Z$|#ZO5BUavOvNyoEy`)%0JzO)ZTz{~)I@q4*KN8S%1j z`7a<@>3(72N0Z`8k71}+DZ)tSU*CR7OBdV(*yo-_sLXxI>jASlN2*!q!wI(GeDudM zwB;VdMM^Pq;vd91oyRRY&#xlF*xBYN3XaG9q?bStkU=x12@ykg!d3XaYkzGxWV_|C z6dND$6`kIgd57aP`}f?$M}F>$<3X&W$WL`F_;W|~A<7qkWKn3+3qCp5oqm<=+qf#H zBAM!GSf=-Q)8FjWTh!5f=`goK+hBgYB>H1J1^v<0hsP!Ag&OPdrn$*M4 znc6S6_Q%oLxg|}a^;MHn*?=WSOW9u--nInktiIk{wXB2nacgI*S3cQxFi!`qg-byK zXLZx6b{o!-A>-UYGLvgnh7#geMbM^|m%i{ju_rGwqB(sIJYOBW z<8j6A;m_*(ka)17iE0q|Pv{Hy2snji=|Q?8OsJuuVa(qsKlL-qtIKSdndpUxVCz}P zT|wu)yv00?O=K2AGg$bCLGYORJG?BkqTqP4jgD_mb0|9Y~E>S8S~e~r1m|?Du;StNqN9U2L3GY7no*aDF`Y@|@rPTaZ{N|bDQYm^5wwtzo3Q&{ z115|@!oucSp$S>~P$`@G`DK?7LvL?MKR-X8AazX2b@NL1@0YwRi${09*~pnh*Qx3} z<=6_je>dd4!A}uehd#VVLxjEE?J~+;0&{Qr=0O-FxXe!|gVod7tlZAP)wQUmbkyDA zFg;^UOm*N94AYbw1)Q65qO+RiE+mY6jhk#mKKaYy*R^Qgd@zAP5ET>auo`n0ITQ`P zO`v2Sfa=4f(18VnYb6oAMQq)?`LBZ4-lx%SHMgcTiVV0z2Zw{BkU=5jkeL{ECyavQ zY-3<=jtWoJt{I;wVxlYf-zi3`GE|?luJv}@T_W(Z)`o|yJ+{~l zb=gfb*IG0Nn|tO2i~$d%GUZ?F1DKQ2(pD~0BjuNIa|o_CsSRAhZ9hM2IRO~1N=P_# zCtqb-91uQVQhYt>%c8_(SFd`T;YFcVOB{gtp@oGm3Z)zvSZlt?=RE(6l0x`$#;97|vf}Tad9G5t6tVm6x$ou;N`>2+IhE9OGv9WP` zz28p(P`lhkhgVvQ!pHrVCre9@6?|tt=!VN+*f)N(WK~zopC`J-MVSj@n>Y7TZiYua zoV4nxx4HCCMijX`iuremjj?i%$aEFHs2y1!6RtVE5Q(Yi@2~ z96-qA;ln$|#++$VlO!8MfpgpaRi$IZl=2b>vYgeY{wZ9-%a>vr8hP=8YE20r_hMk%@8eDEEx)!FyC1e=%s0oliFEH$~9fDnE{_al*3|Zq-A~^O-&du?y)tI*R5f2kxHI8_*Juj^?00r^Z!~ zf*M@}bIjRKK3-B>>h_b`(-k}pS3%1xvp=r)?RN6mzfMo@%8+v_#XbZ&tZNOb_|)uY zo2=XzIGW3?ejzLe0 z;%(IJNz+h@{eoCAY;SL$sWxSk!SHW2ZL1sRD7)N9SY@C7>#7*_<6f#xOS$0$ZhP*F zMrUWI4^%ydE^}!D>ugBj*=pufmJp$?y_9x(5nre=h1(u47Zw*6kBW|N^7yFggn>#( zN(RJ!{=qz%Wn)Uh?3s(mSmRglK82_1VaGyb~TGx~Zh8-Q7^Sj8u_%r21ki5+B< zUtC_3-p}!NPiM~IRc{@-~D~bjm?~m+;n^3ypqV89Oj>c7&8d z1g;G|Yj4*oC@i#I_vgOD>JWWOIg3DQ`-QpnK$<@duS{asMea4RVXGG9%1oQ)Sf^V; zk-NLQytm=`(qRQM??xxLGRrUMcD+^wss!R$98q;(u$3q zo}TE{t9r!IrZPq*CO?bR_+_v8=g?10+9*s37Y~nh=lQPdQ|q;@hQ(sa%9-B_b>v)o zd1+w?*j=!_9z$1VY-&2F2ZvG SK>K(A0DAWfwac^|BL5A1FFFnY literal 0 HcmV?d00001 diff --git a/src/app/puzzle/share/resources/puzzleicon/svg/iconProperties.svg b/src/app/puzzle/share/resources/puzzleicon/svg/iconProperties.svg new file mode 100644 index 000000000..eb0cdd094 --- /dev/null +++ b/src/app/puzzle/share/resources/puzzleicon/svg/iconProperties.svg @@ -0,0 +1,136 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index fbbf5e704..6130698c7 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -176,7 +176,7 @@ QTabWidget::Rounded - 3 + 1 @@ -1018,8 +1018,12 @@ + + + :/puzzleicon/64x64/iconProperties.png:/puzzleicon/64x64/iconProperties.png + - Prop. + From 4ec3e29bb13e6eb5cf145bde7d67f023e77bd9e4 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Wed, 11 Nov 2020 22:04:07 +0100 Subject: [PATCH 07/34] add zoom icons to toolbar --- src/app/puzzle/vpmainwindow.ui | 65 +++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 6130698c7..8a9cae6aa 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -564,8 +564,8 @@ 0 0 - 356 - 760 + 342 + 731 @@ -981,7 +981,7 @@ 0 0 356 - 760 + 717 @@ -1058,7 +1058,7 @@ 0 0 356 - 760 + 717 @@ -1182,6 +1182,24 @@ + + + toolBar + + + Qt::ToolButtonTextUnderIcon + + + TopToolBarArea + + + false + + + + + + &Open @@ -1260,6 +1278,45 @@ Properties + + + + .. + + + Zoom in + + + + + + .. + + + Zoom out + + + + + + .. + + + Zoom 1:1 + + + + + + .. + + + Zoom sheet + + + Zoom sheet + + From c497e325d88846e378c9d558a85e82f3b6df0ef2 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Fri, 13 Nov 2020 23:31:22 +0100 Subject: [PATCH 08/34] Zoom functions --- src/app/puzzle/vpapplication.cpp | 1 + src/app/puzzle/vpmainwindow.cpp | 33 ++++++++++++++++++++++++++++++++ src/app/puzzle/vpmainwindow.h | 10 ++++++++++ src/app/puzzle/vpmainwindow.ui | 8 ++++---- 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/app/puzzle/vpapplication.cpp b/src/app/puzzle/vpapplication.cpp index 9d6233713..e3233a2c0 100644 --- a/src/app/puzzle/vpapplication.cpp +++ b/src/app/puzzle/vpapplication.cpp @@ -363,6 +363,7 @@ VPMainWindow *VPApplication::NewMainWindow(const VPCommandLinePtr &cmd) { puzzle->show(); } + puzzle->InitZoom(); return puzzle; } diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index ca83c6b61..e4a000619 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -84,6 +84,7 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : InitCarrousel(); InitMainGraphics(); + InitToolBar(); SetPropertiesData(); @@ -185,6 +186,12 @@ void VPMainWindow::ImportRawLayouts(const QStringList &rawLayouts) } } +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::InitZoom() +{ + m_graphicsView->ZoomFitBest(); +} + //--------------------------------------------------------------------------------------------------------------------- VPPiece* VPMainWindow::CreatePiece(const VLayoutPiece &rawPiece) { @@ -472,6 +479,32 @@ void VPMainWindow::InitMainGraphics() m_graphicsView->RefreshLayout(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::InitToolBar() +{ + QList zoomInShortcuts; + zoomInShortcuts.append(QKeySequence(QKeySequence::ZoomIn)); + zoomInShortcuts.append(QKeySequence(Qt::ControlModifier + Qt::Key_Plus + Qt::KeypadModifier)); + ui->actionZoomIn->setShortcuts(zoomInShortcuts); + connect(ui->actionZoomIn, &QAction::triggered, m_graphicsView, &VPMainGraphicsView::ZoomIn); + + QList zoomOutShortcuts; + zoomOutShortcuts.append(QKeySequence(QKeySequence::ZoomOut)); + zoomOutShortcuts.append(QKeySequence(Qt::ControlModifier + Qt::Key_Minus + Qt::KeypadModifier)); + ui->actionZoomOut->setShortcuts(zoomOutShortcuts); + connect(ui->actionZoomOut, &QAction::triggered, m_graphicsView, &VPMainGraphicsView::ZoomOut); + + QList zoomOriginalShortcuts; + zoomOriginalShortcuts.append(QKeySequence(Qt::ControlModifier + Qt::Key_0)); + zoomOriginalShortcuts.append(QKeySequence(Qt::ControlModifier + Qt::Key_0 + Qt::KeypadModifier)); + ui->actionZoomOriginal->setShortcuts(zoomOriginalShortcuts); + connect(ui->actionZoomOriginal, &QAction::triggered, m_graphicsView, &VPMainGraphicsView::ZoomOriginal); + + QList zoomFitBestShortcuts; + zoomFitBestShortcuts.append(QKeySequence(Qt::ControlModifier + Qt::Key_Equal)); + ui->actionZoomFitBest->setShortcuts(zoomFitBestShortcuts); + connect(ui->actionZoomFitBest, &QAction::triggered, m_graphicsView, &VPMainGraphicsView::ZoomFitBest); +} //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::SetDoubleSpinBoxValue(QDoubleSpinBox *spinBox, qreal value) diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index c7229b089..fd004d680 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -74,6 +74,11 @@ public: */ void ImportRawLayouts(const QStringList &rawLayouts); + /** + * @brief InitZoom Initialises the zoom to fit best + */ + void InitZoom(); + public slots: /** * @brief on_actionNew_triggered When the menu action File > New @@ -144,6 +149,11 @@ private: */ void InitMainGraphics(); + /** + * @brief InitToolBar Initialises the tool bar + */ + void InitToolBar(); + /** * @brief SetPropertiesData Sets the values of UI elements * in all the property tabs to the values saved in m_layout diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 8a9cae6aa..84b9fa0ea 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -1197,8 +1197,8 @@ - - + + @@ -1296,7 +1296,7 @@ Zoom out - + .. @@ -1305,7 +1305,7 @@ Zoom 1:1 - + .. From d55dbbb61e47dde15007987895b4ebd9dbc42699 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 14 Nov 2020 10:20:02 +0100 Subject: [PATCH 09/34] Add scale spinbox functionality --- src/app/puzzle/vpmainwindow.cpp | 46 +++++++++++++++++++++++++++++++-- src/app/puzzle/vpmainwindow.h | 10 ++++++- src/app/puzzle/vpmainwindow.ui | 4 +-- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index e4a000619..97740e8de 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -29,6 +29,7 @@ #include #include +#include #include "ui_vpmainwindow.h" #include "dialogs/vpdialogabout.h" @@ -84,7 +85,7 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : InitCarrousel(); InitMainGraphics(); - InitToolBar(); + InitZoomToolBar(); SetPropertiesData(); @@ -477,11 +478,15 @@ void VPMainWindow::InitMainGraphics() ui->centralWidget->layout()->addWidget(m_graphicsView); m_graphicsView->RefreshLayout(); + + connect(m_graphicsView, &VPMainGraphicsView::ScaleChanged, this, &VPMainWindow::on_ScaleChanged); } //--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::InitToolBar() +void VPMainWindow::InitZoomToolBar() { + + // connect the zoom buttons and shortcuts to the slots QList zoomInShortcuts; zoomInShortcuts.append(QKeySequence(QKeySequence::ZoomIn)); zoomInShortcuts.append(QKeySequence(Qt::ControlModifier + Qt::Key_Plus + Qt::KeypadModifier)); @@ -504,6 +509,28 @@ void VPMainWindow::InitToolBar() zoomFitBestShortcuts.append(QKeySequence(Qt::ControlModifier + Qt::Key_Equal)); ui->actionZoomFitBest->setShortcuts(zoomFitBestShortcuts); connect(ui->actionZoomFitBest, &QAction::triggered, m_graphicsView, &VPMainGraphicsView::ZoomFitBest); + + // defined the scale + ui->toolBarZoom->addSeparator(); + QLabel* zoomScale = new QLabel(tr("Scale:"), this); + ui->toolBarZoom->addWidget(zoomScale); + + m_doubleSpinBoxScale = new QDoubleSpinBox(this); + m_doubleSpinBoxScale->setDecimals(1); + m_doubleSpinBoxScale->setSuffix("%"); + on_ScaleChanged(m_graphicsView->transform().m11()); + connect(m_doubleSpinBoxScale.data(), QOverload::of(&QDoubleSpinBox::valueChanged), + this, [this](double d){m_graphicsView->Zoom(d/100.0);}); + ui->toolBarZoom->addWidget(m_doubleSpinBoxScale); + + + // define the mouse position + ui->toolBarZoom->addSeparator(); + + m_mouseCoordinate = new QLabel(QString("0, 0 (%1)").arg(UnitsToStr(m_layout->GetUnit(), true))); + ui->toolBarZoom->addWidget(m_mouseCoordinate); + ui->toolBarZoom->addSeparator(); + } //--------------------------------------------------------------------------------------------------------------------- @@ -1057,3 +1084,18 @@ void VPMainWindow::on_PieceRotationChanged() SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceAngle, angle); } } + + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::on_ScaleChanged(qreal scale) +{ + if (not m_doubleSpinBoxScale.isNull()) + { + m_doubleSpinBoxScale->blockSignals(true); + m_doubleSpinBoxScale->setMaximum(qFloor(VPMainGraphicsView::MaxScale()*1000)/10.0); + m_doubleSpinBoxScale->setMinimum(qFloor(VPMainGraphicsView::MinScale()*1000)/10.0); + m_doubleSpinBoxScale->setValue(qFloor(scale*1000)/10.0); + m_doubleSpinBoxScale->setSingleStep(1); + m_doubleSpinBoxScale->blockSignals(false); + } +} diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index fd004d680..5e74f3f1d 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -103,6 +103,9 @@ private: VPLayout *m_layout{nullptr}; QListm_selectedPieces{QList()}; + QLabel* m_mouseCoordinate{nullptr}; + QPointer m_doubleSpinBoxScale{nullptr}; + /** * @brief CreatePiece creates a piece from the given VLayoutPiece data * @param rawPiece the raw piece data @@ -152,7 +155,7 @@ private: /** * @brief InitToolBar Initialises the tool bar */ - void InitToolBar(); + void InitZoomToolBar(); /** * @brief SetPropertiesData Sets the values of UI elements @@ -395,6 +398,11 @@ private slots: */ void on_PieceRotationChanged(); + /** + * @brief on_ScaleChanged + */ + void on_ScaleChanged(qreal scale); + }; #endif // VPMAINWINDOW_H diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 84b9fa0ea..412528d40 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -1182,7 +1182,7 @@ - + toolBar @@ -1311,7 +1311,7 @@ .. - Zoom sheet + Zoom fit best Zoom sheet From 491d5848b4bd9a74f28a01bad8ba9b9d6fe8b0f7 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 14 Nov 2020 10:55:57 +0100 Subject: [PATCH 10/34] Add mouse position functionality --- src/app/puzzle/vpmaingraphicsview.cpp | 6 ++++++ src/app/puzzle/vpmaingraphicsview.h | 8 ++++++++ src/app/puzzle/vpmainwindow.cpp | 24 +++++++++++++++++++++++- src/app/puzzle/vpmainwindow.h | 17 +++++++++++++++-- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/app/puzzle/vpmaingraphicsview.cpp b/src/app/puzzle/vpmaingraphicsview.cpp index a114a8ff0..1db306030 100644 --- a/src/app/puzzle/vpmaingraphicsview.cpp +++ b/src/app/puzzle/vpmaingraphicsview.cpp @@ -74,6 +74,12 @@ void VPMainGraphicsView::RefreshLayout() m_scene->update(); } +//--------------------------------------------------------------------------------------------------------------------- +VMainGraphicsScene* VPMainGraphicsView::GetScene() +{ + return m_scene; +} + //--------------------------------------------------------------------------------------------------------------------- void VPMainGraphicsView::dragEnterEvent(QDragEnterEvent *event) { diff --git a/src/app/puzzle/vpmaingraphicsview.h b/src/app/puzzle/vpmaingraphicsview.h index 15709c520..fdea4efb6 100644 --- a/src/app/puzzle/vpmaingraphicsview.h +++ b/src/app/puzzle/vpmaingraphicsview.h @@ -48,6 +48,14 @@ public: */ void RefreshLayout(); + + /** + * @brief GetScene Returns the scene of the view + * @return + */ + VMainGraphicsScene* GetScene(); + + protected: void dragEnterEvent(QDragEnterEvent *event) override; void dragMoveEvent(QDragMoveEvent *event) override; diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 97740e8de..5633b3602 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -41,6 +41,7 @@ #include "../vmisc/projectversion.h" #include "../ifc/xml/vlayoutconverter.h" #include "../ifc/exception/vexception.h" +#include "../vwidgets/vmaingraphicsscene.h" #include "vpsheet.h" #include @@ -480,11 +481,21 @@ void VPMainWindow::InitMainGraphics() m_graphicsView->RefreshLayout(); connect(m_graphicsView, &VPMainGraphicsView::ScaleChanged, this, &VPMainWindow::on_ScaleChanged); + connect(m_graphicsView->GetScene(), &VMainGraphicsScene::mouseMove, this, &VPMainWindow::on_MouseMoved); } //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::InitZoomToolBar() { + if (not m_doubleSpinBoxScale.isNull()) + { + delete m_doubleSpinBoxScale; + } + + if (m_mouseCoordinate != nullptr) + { + delete m_mouseCoordinate; + } // connect the zoom buttons and shortcuts to the slots QList zoomInShortcuts; @@ -530,7 +541,6 @@ void VPMainWindow::InitZoomToolBar() m_mouseCoordinate = new QLabel(QString("0, 0 (%1)").arg(UnitsToStr(m_layout->GetUnit(), true))); ui->toolBarZoom->addWidget(m_mouseCoordinate); ui->toolBarZoom->addSeparator(); - } //--------------------------------------------------------------------------------------------------------------------- @@ -1099,3 +1109,15 @@ void VPMainWindow::on_ScaleChanged(qreal scale) m_doubleSpinBoxScale->blockSignals(false); } } + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::on_MouseMoved(const QPointF &scenePos) +{ + if (m_mouseCoordinate != nullptr) + { + m_mouseCoordinate->setText(QStringLiteral("%1, %2 (%3)") + .arg(static_cast(FromPixel(scenePos.x(), m_layout->GetUnit()))) + .arg(static_cast(FromPixel(scenePos.y(), m_layout->GetUnit()))) + .arg(UnitsToStr(m_layout->GetUnit(), true))); + } +} diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index 5e74f3f1d..ce6d166bb 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -31,6 +31,7 @@ #include #include #include +#include #include "../vmisc/def.h" #include "vpcarrousel.h" @@ -103,9 +104,16 @@ private: VPLayout *m_layout{nullptr}; QListm_selectedPieces{QList()}; - QLabel* m_mouseCoordinate{nullptr}; + /** + * @brief spin box with the scale factor of the graphic view + */ QPointer m_doubleSpinBoxScale{nullptr}; + /** + * @brief mouseCoordinate pointer to label who show mouse coordinate. + */ + QLabel* m_mouseCoordinate{nullptr}; + /** * @brief CreatePiece creates a piece from the given VLayoutPiece data * @param rawPiece the raw piece data @@ -399,10 +407,15 @@ private slots: void on_PieceRotationChanged(); /** - * @brief on_ScaleChanged + * @brief on_ScaleChanged When the scale of the graphic view is changed */ void on_ScaleChanged(qreal scale); + /** + * @brief mouseMove save mouse position and show user. + * @param scenePos position mouse. + */ + void on_MouseMoved(const QPointF &scenePos); }; #endif // VPMAINWINDOW_H From f6e5f67159cdaa048facc92909c7bdac0c72589c Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 14 Nov 2020 12:37:43 +0100 Subject: [PATCH 11/34] Button export with test svg export --- src/app/puzzle/puzzle.pro | 2 +- src/app/puzzle/vpgraphicssheet.cpp | 26 ++++++++++++++--- src/app/puzzle/vpgraphicssheet.h | 16 +++++++++++ src/app/puzzle/vpmaingraphicsview.cpp | 18 ++++++++++++ src/app/puzzle/vpmaingraphicsview.h | 10 +++++++ src/app/puzzle/vpmainwindow.cpp | 41 +++++++++++++++++++++++---- src/app/puzzle/vpmainwindow.h | 2 ++ 7 files changed, 104 insertions(+), 11 deletions(-) diff --git a/src/app/puzzle/puzzle.pro b/src/app/puzzle/puzzle.pro index 462579124..4d1e2fbd8 100644 --- a/src/app/puzzle/puzzle.pro +++ b/src/app/puzzle/puzzle.pro @@ -7,7 +7,7 @@ # File with common stuff for whole project include(../../../common.pri) -QT += core gui widgets network xml xmlpatterns printsupport concurrent +QT += core gui widgets network xml svg xmlpatterns printsupport concurrent # Name of binary file TARGET = puzzle diff --git a/src/app/puzzle/vpgraphicssheet.cpp b/src/app/puzzle/vpgraphicssheet.cpp index 42ed505d1..cfee78a09 100644 --- a/src/app/puzzle/vpgraphicssheet.cpp +++ b/src/app/puzzle/vpgraphicssheet.cpp @@ -55,12 +55,18 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o painter->setPen(pen); painter->setBrush(noBrush); - painter->drawRect(GetMarginsRect()); + if(m_showMargin) + { + painter->drawRect(GetMarginsRect()); + } - pen.setColor(Qt::black); + if(m_showBorder) + { + pen.setColor(Qt::black); - painter->setPen(pen); - painter->drawRect(GetSheetRect()); + painter->setPen(pen); + painter->drawRect(GetSheetRect()); + } m_boundingRect = GetSheetRect(); } @@ -96,6 +102,18 @@ QRectF VPGraphicsSheet::GetMarginsRect() const return rect; } +//--------------------------------------------------------------------------------------------------------------------- +void VPGraphicsSheet::SetShowMargin(bool value) +{ + m_showMargin = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPGraphicsSheet::SetShowBorder(bool value) +{ + m_showBorder = value; +} + //--------------------------------------------------------------------------------------------------------------------- QRectF VPGraphicsSheet::boundingRect() const diff --git a/src/app/puzzle/vpgraphicssheet.h b/src/app/puzzle/vpgraphicssheet.h index 4ee8b4329..0cbef3a41 100644 --- a/src/app/puzzle/vpgraphicssheet.h +++ b/src/app/puzzle/vpgraphicssheet.h @@ -47,12 +47,28 @@ public: QRectF GetSheetRect() const; QRectF GetMarginsRect() const; + /** + * @brief ShowMargin Sets Wether we see the margin + * @param value true to show the margin + */ + void SetShowMargin(bool value); + + /** + * @brief ShowBorder Sets whether we see the border of the sheet + * @param value true to show the border + */ + void SetShowBorder(bool value); + + private: Q_DISABLE_COPY(VPGraphicsSheet) VPSheet *m_sheet{nullptr}; QRectF m_boundingRect; + + bool m_showMargin{true}; + bool m_showBorder{true}; }; #endif // VPGRAPHICSSHEET_H diff --git a/src/app/puzzle/vpmaingraphicsview.cpp b/src/app/puzzle/vpmaingraphicsview.cpp index 1db306030..4c838f9fd 100644 --- a/src/app/puzzle/vpmaingraphicsview.cpp +++ b/src/app/puzzle/vpmaingraphicsview.cpp @@ -80,6 +80,24 @@ VMainGraphicsScene* VPMainGraphicsView::GetScene() return m_scene; } + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainGraphicsView::PrepareForExport() +{ + m_graphicsSheet->SetShowBorder(false); + m_graphicsSheet->SetShowMargin(false); + RefreshLayout(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainGraphicsView::CleanAfterExport() +{ + m_graphicsSheet->SetShowBorder(true); + m_graphicsSheet->SetShowMargin(true); + RefreshLayout(); +} + + //--------------------------------------------------------------------------------------------------------------------- void VPMainGraphicsView::dragEnterEvent(QDragEnterEvent *event) { diff --git a/src/app/puzzle/vpmaingraphicsview.h b/src/app/puzzle/vpmaingraphicsview.h index fdea4efb6..94d52e1b5 100644 --- a/src/app/puzzle/vpmaingraphicsview.h +++ b/src/app/puzzle/vpmaingraphicsview.h @@ -55,6 +55,16 @@ public: */ VMainGraphicsScene* GetScene(); + /** + * @brief PrepareForExport prepares the graphic for an export (i.e hide margin etc) + */ + void PrepareForExport(); + + /** + * @brief CleanAfterExport cleans the graphic for an export (i.e show margin etc) + */ + void CleanAfterExport(); + protected: void dragEnterEvent(QDragEnterEvent *event) override; diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 5633b3602..65a110319 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -45,6 +45,7 @@ #include "vpsheet.h" #include +#include QT_WARNING_PUSH QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes") @@ -993,14 +994,42 @@ void VPMainWindow::on_checkBoxSheetStickyEdges_toggled(bool checked) //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_pushButtonSheetExport_clicked() { - // just for test purpuses, to be removed: - QMessageBox msgBox; - msgBox.setText("TODO VPMainWindow::on_pushButtonSheetExport_clicked"); - int ret = msgBox.exec(); + m_graphicsView->PrepareForExport(); - Q_UNUSED(ret); + // svg export to do some test for the first test - // TODO + QString dir = QDir::homePath(); + QString filters(tr("SVG Files") + QLatin1String("(*.svg)")); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), + dir + QLatin1String("/") + tr("Layout") + QLatin1String(".svg"), + filters, nullptr +#ifdef Q_OS_LINUX + , QFileDialog::DontUseNativeDialog +#endif + ); + + + + const QSizeF s = m_layout->GetFocusedSheet()->GetSheetSize(); + const QRectF r = QRectF(0, 0, s.width(), s.height()); + + QSvgGenerator generator; + generator.setFileName(fileName); + generator.setSize(QSize(qFloor(s.width()),qFloor(s.height()))); + generator.setViewBox(r); + generator.setTitle(tr("Pattern")); + generator.setDescription(m_layout->GetDescription().toHtmlEscaped()); + generator.setResolution(static_cast(PrintDPI)); + + QPainter painter; + painter.begin(&generator); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(QPen(Qt::black, qApp->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.setBrush ( QBrush ( Qt::NoBrush ) ); + m_graphicsView->GetScene()->render(&painter, r, r, Qt::IgnoreAspectRatio); + painter.end(); + + m_graphicsView->CleanAfterExport(); } diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index ce6d166bb..43a40f07a 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -40,6 +40,7 @@ #include "vppiece.h" #include "../vlayout/vlayoutpiece.h" #include "vpcommandline.h" +#include "../vlayout/vlayoutdef.h" namespace Ui { @@ -216,6 +217,7 @@ private: bool MaybeSave(); + private slots: /** * @brief on_actionOpen_triggered When the menu action File > Open is From ffaca85f497805208b6dfcaa0d1b8df32f1a19ad Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 14 Nov 2020 12:46:18 +0100 Subject: [PATCH 12/34] Test SVG export improved --- src/app/puzzle/vpmainwindow.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 65a110319..8ed52ad0e 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -994,8 +994,6 @@ void VPMainWindow::on_checkBoxSheetStickyEdges_toggled(bool checked) //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_pushButtonSheetExport_clicked() { - m_graphicsView->PrepareForExport(); - // svg export to do some test for the first test QString dir = QDir::homePath(); @@ -1008,7 +1006,9 @@ void VPMainWindow::on_pushButtonSheetExport_clicked() #endif ); - + if(not fileName.isEmpty()) + { + m_graphicsView->PrepareForExport(); const QSizeF s = m_layout->GetFocusedSheet()->GetSheetSize(); const QRectF r = QRectF(0, 0, s.width(), s.height()); @@ -1030,6 +1030,7 @@ void VPMainWindow::on_pushButtonSheetExport_clicked() painter.end(); m_graphicsView->CleanAfterExport(); + } } From 40c9e8161bed073cc1270c8a44f6d81ff2ad344d Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 14 Nov 2020 13:23:32 +0100 Subject: [PATCH 13/34] Tiles Tab content --- src/app/puzzle/vpmainwindow.ui | 176 ++++++++++++++++++++++++++++++++- 1 file changed, 175 insertions(+), 1 deletion(-) diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 412528d40..68adf8583 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -991,13 +991,187 @@ font-weight: bold; - Tiles of current sheet + Tiled Pdf Export Qt::AlignCenter + + + + Format + + + + + + + + Width + + + + + + + + + + Length + + + + + + + + + + Orientation + + + + + + + + + + + + + :/puzzleicon/64x64/iconPortrait.png:/puzzleicon/64x64/iconPortrait.png + + + + 32 + 32 + + + + true + + + + + + + + + + + :/puzzleicon/64x64/iconLandscape.png:/puzzleicon/64x64/iconLandscape.png + + + + 32 + 32 + + + + + + + + + + + + + + + Margins + + + + + + Right: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Left: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + Top: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Bottom: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + Control + + + + + + Show Tiles on sheet + + + + + + + + + + Export + + + + + + Export Tiled Pdf + + + + + + From dddf1fe6549c306b4bbacb50eb4e4cc84a0f2829 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 14 Nov 2020 15:58:42 +0100 Subject: [PATCH 14/34] Tiles functions and persistence --- src/app/puzzle/vplayout.cpp | 117 ++++++++++++++++++++++ src/app/puzzle/vplayout.h | 122 +++++++++++++++++++++++ src/app/puzzle/vpmainwindow.cpp | 165 ++++++++++++++++++++++++++------ src/app/puzzle/vpmainwindow.h | 41 ++++++-- src/app/puzzle/vpmainwindow.ui | 7 +- 5 files changed, 413 insertions(+), 39 deletions(-) diff --git a/src/app/puzzle/vplayout.cpp b/src/app/puzzle/vplayout.cpp index 6f14c4cae..6744850d1 100644 --- a/src/app/puzzle/vplayout.cpp +++ b/src/app/puzzle/vplayout.cpp @@ -230,3 +230,120 @@ VPSheet* VPLayout::GetFocusedSheet() { return m_focusedSheet; } + + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetTilesSize(qreal width, qreal height) +{ + m_tilesSize.setWidth(width); + m_tilesSize.setHeight(height); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetTilesSizeConverted(qreal width, qreal height) +{ + m_tilesSize.setWidth(UnitConvertor(width, GetUnit(), Unit::Px)); + m_tilesSize.setHeight(UnitConvertor(height, GetUnit(), Unit::Px)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetTilesSize(const QSizeF &size) +{ + m_tilesSize = size; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetTilesSizeConverted(const QSizeF &size) +{ + m_tilesSize = QSizeF( + UnitConvertor(size.width(), GetUnit(), Unit::Px), + UnitConvertor(size.height(), GetUnit(), Unit::Px) + ); +} + +//--------------------------------------------------------------------------------------------------------------------- +QSizeF VPLayout::GetTilesSize() const +{ + return m_tilesSize; +} + +//--------------------------------------------------------------------------------------------------------------------- +QSizeF VPLayout::GetTilesSizeConverted() const +{ + QSizeF convertedSize = QSizeF( + UnitConvertor(m_tilesSize.width(), Unit::Px, GetUnit()), + UnitConvertor(m_tilesSize.height(), Unit::Px, GetUnit()) + ); + + return convertedSize; +} + +//--------------------------------------------------------------------------------------------------------------------- +PageOrientation VPLayout::GetTilesOrientation() +{ + return m_tilesOrientation; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetTilesOrientation(PageOrientation orientation) +{ + if(orientation != m_tilesOrientation) + { + m_tilesOrientation = orientation; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetTilesMargins(qreal left, qreal top, qreal right, qreal bottom) +{ + m_tilesMargins.setLeft(left); + m_tilesMargins.setTop(top); + m_tilesMargins.setRight(right); + m_tilesMargins.setBottom(bottom); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetTilesMarginsConverted(qreal left, qreal top, qreal right, qreal bottom) +{ + m_tilesMargins.setLeft(UnitConvertor(left, GetUnit(), Unit::Px)); + m_tilesMargins.setTop(UnitConvertor(top, GetUnit(), Unit::Px)); + m_tilesMargins.setRight(UnitConvertor(right, GetUnit(), Unit::Px)); + m_tilesMargins.setBottom(UnitConvertor(bottom, GetUnit(), Unit::Px)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetTilesMargins(const QMarginsF &margins) +{ + m_tilesMargins = margins; +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetTilesMarginsConverted(const QMarginsF &margins) +{ + m_tilesMargins = UnitConvertor(margins, GetUnit(), Unit::Px); +} + +//--------------------------------------------------------------------------------------------------------------------- +QMarginsF VPLayout::GetTilesMargins() const +{ + return m_tilesMargins; +} + +//--------------------------------------------------------------------------------------------------------------------- +QMarginsF VPLayout::GetTilesMarginsConverted() const +{ + return UnitConvertor(m_tilesMargins, Unit::Px, GetUnit()); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VPLayout::GetShowTiles() +{ + return m_showTiles; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetShowTiles(bool value) +{ + m_showTiles = value; +} diff --git a/src/app/puzzle/vplayout.h b/src/app/puzzle/vplayout.h index 17a529a9b..144578b46 100644 --- a/src/app/puzzle/vplayout.h +++ b/src/app/puzzle/vplayout.h @@ -138,6 +138,111 @@ public: VPSheet* GetFocusedSheet(); + /** + * @brief SetTilesSize sets the size of the tiles, the values have to be in Unit::Px + * @param width tiles width + * @param height tiles height + */ + void SetTilesSize(qreal width, qreal height); + + /** + * @brief SetTilesSizeConverted sets the size of the sheet, the values have to be in the layout's unit + * @param width tiles width + * @param height tiles height + */ + void SetTilesSizeConverted(qreal width, qreal height); + + /** + * @brief SetTilesSize sets the size of the tiles, the values have to be in Unit::Px + * @param size sheet size + */ + void SetTilesSize(const QSizeF &size); + /** + * @brief SetTilesSizeConverted sets the size of the tiles, the values have to be in the layout's unit + * @param size sheet size + */ + void SetTilesSizeConverted(const QSizeF &size); + + /** + * @brief GetTilesSize Returns the size of the tiles in Unit::Px + * @return sheet size in Unit::Px + */ + QSizeF GetTilesSize() const; + + /** + * @brief GetTilesSizeConverted Returns the size of the tiles in the layout's unit + * @return the size in the layout's unit + */ + QSizeF GetTilesSizeConverted() const; + + /** + * @brief GetOrientation Returns the orientation of the tiles + * @return orientation of the tiles + */ + PageOrientation GetTilesOrientation(); + + /** + * @brief SetOrientation Sets the orientation of the tiles to the given value + * @param orientation the new tiles orientation + */ + void SetTilesOrientation(PageOrientation orientation); + + /** + * @brief SetTilesMargins, set the margins of the tiles, the values have to be in Unit::Px + * @param left in Unit::Px + * @param top in Unit::Px + * @param right in Unit::Px + * @param bottom in Unit::Px + */ + void SetTilesMargins(qreal left, qreal top, qreal right, qreal bottom); + + /** + * @brief SetSheetMargins, set the margins of the tiles, the values have to be in the unit of the layout + * @param left in Unit::Px + * @param top in Unit::Px + * @param right in Unit::Px + * @param bottom in Unit::Px + */ + void SetTilesMarginsConverted(qreal left, qreal top, qreal right, qreal bottom); + + /** + * @brief SetTilesMargins set the margins of the tiles, the values have to be in Unit::Px + * @param margins tiles margins + */ + void SetTilesMargins(const QMarginsF &margins); + + /** + * @brief SetTilesMarginsConverted set the margins of the tiles, the values have to be in the unit of the layout + * @param margins tiles margins + */ + void SetTilesMarginsConverted(const QMarginsF &margins); + + /** + * @brief GetTilesMargins Returns margins of the tiles in Unit::Px + * @return the size in Unit::Px + */ + QMarginsF GetTilesMargins() const; + + /** + * @brief GetTilesMarginsConverted Returns the margins of the tiles in the layout's unit + * @return the margins in the tiles's unit + */ + QMarginsF GetTilesMarginsConverted() const; + + /** + * @brief GetShowTiles Returns true if the tiles has to be shown on the current sheet + * @return + */ + bool GetShowTiles(); + + /** + * @brief SetShowTiles Sets wether to show the tiles on the current sheet or not + * @param value true to show the tiles + */ + void SetShowTiles(bool value); + + + signals: void PieceMovedToPieceList(VPPiece *piece, VPPieceList *pieceListBefore, VPPieceList *pieceListAfter); @@ -169,6 +274,23 @@ private: QString m_description{}; + /** + * @brief m_size the Size of the tiles in Unit::Px + */ + QSizeF m_tilesSize{}; + + /** + * @brief holds the orientation of the tiles + */ + PageOrientation m_tilesOrientation {PageOrientation::Portrait}; + + // margins + /** + * @brief m_margins the margins of the tiles in Unit::Px + */ + QMarginsF m_tilesMargins{}; + + bool m_showTiles{false}; }; #endif // VPLAYOUT_H diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 8ed52ad0e..b6de14936 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -78,6 +78,12 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : m_layout->SetWarningSuperpositionOfPieces(true); m_layout->SetTitle(QString("My Test Layout")); m_layout->SetDescription(QString("Description of my Layout")); + + m_layout->SetTilesSizeConverted(21,29.7); + m_layout->SetTilesOrientation(PageOrientation::Portrait); + m_layout->SetTilesMarginsConverted(1,1,1,1); + m_layout->SetShowTiles(true); + // -------------------------------------------------------- ui->setupUi(this); @@ -269,27 +275,6 @@ void VPMainWindow::InitPropertyTabCurrentSheet() // FIXME ---- For MVP we hide a few things. To be displayed when functions there ui->pushButtonSheetRemoveUnusedLength->hide(); ui->groupBoxSheetControl->hide(); -} - - -//--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::InitPropertyTabLayout() -{ - - // FIXME ---- For MVP we hide a few things. To be displayed when functions there - ui->groupBoxLayoutControl->hide(); - - // -------------------- init the unit combobox --------------------- - ui->comboBoxLayoutUnit->addItem(tr("Centimeters"), QVariant(UnitsToStr(Unit::Cm))); - ui->comboBoxLayoutUnit->addItem(tr("Millimiters"), QVariant(UnitsToStr(Unit::Mm))); - ui->comboBoxLayoutUnit->addItem(tr("Inches"), QVariant(UnitsToStr(Unit::Inch))); - - // set default unit - TODO when we have the setting for the unit -// const qint32 indexUnit = -1;//ui->comboBoxLayoutUnit->findData(qApp->ValentinaSettings()->GetUnit()); -// if (indexUnit != -1) -// { -// ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit); -// } // some of the UI Elements are connected to the slots via auto-connect // see https://doc.qt.io/qt-5/designer-using-a-ui-file.html#widgets-and-dialogs-with-auto-connect @@ -326,14 +311,52 @@ void VPMainWindow::InitPropertyTabLayout() // TODO init the file format export combobox + } //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::InitPropertyTabTiles() { - // for the MVP we don't want the tiles tab. - // we remove it. As soon as we need it, update this code - ui->tabWidgetProperties->removeTab(2); // remove tiles + // -------------------- layout width, length, orientation ------------------------ + connect(ui->doubleSpinBoxSheetWidth, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_TilesSizeChanged); + connect(ui->doubleSpinBoxSheetLength, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_TilesSizeChanged); + connect(ui->radioButtonSheetPortrait, QOverload::of(&QRadioButton::clicked), this, + &VPMainWindow::on_TilesOrientationChanged); + connect(ui->radioButtonSheetLandscape, QOverload::of(&QRadioButton::clicked), this, + &VPMainWindow::on_TilesOrientationChanged); + + // -------------------- margins ------------------------ + connect(ui->doubleSpinBoxSheetMarginTop, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_TilesMarginChanged); + connect(ui->doubleSpinBoxSheetMarginRight, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_TilesMarginChanged); + connect(ui->doubleSpinBoxSheetMarginBottom, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_TilesMarginChanged); + connect(ui->doubleSpinBoxSheetMarginLeft, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_TilesMarginChanged); +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::InitPropertyTabLayout() +{ + + // FIXME ---- For MVP we hide a few things. To be displayed when functions there + ui->groupBoxLayoutControl->hide(); + + // -------------------- init the unit combobox --------------------- + ui->comboBoxLayoutUnit->addItem(tr("Centimeters"), QVariant(UnitsToStr(Unit::Cm))); + ui->comboBoxLayoutUnit->addItem(tr("Millimiters"), QVariant(UnitsToStr(Unit::Mm))); + ui->comboBoxLayoutUnit->addItem(tr("Inches"), QVariant(UnitsToStr(Unit::Inch))); + + // set default unit - TODO when we have the setting for the unit +// const qint32 indexUnit = -1;//ui->comboBoxLayoutUnit->findData(qApp->ValentinaSettings()->GetUnit()); +// if (indexUnit != -1) +// { +// ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit); +// } } //--------------------------------------------------------------------------------------------------------------------- @@ -423,7 +446,7 @@ void VPMainWindow::SetPropertyTabSheetData() SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetLength, size.height()); // Set Orientation - if(size.width() <= size.height()) + if(m_layout->GetFocusedSheet()->GetOrientation() == PageOrientation::Portrait) { ui->radioButtonSheetPortrait->setChecked(true); } @@ -446,6 +469,36 @@ void VPMainWindow::SetPropertyTabSheetData() SetCheckBoxValue(ui->checkBoxSheetStickyEdges, m_layout->GetFocusedSheet()->GetStickyEdges()); } + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::SetPropertyTabTilesData() +{ + // set Width / Length + QSizeF size = m_layout->GetTilesSizeConverted(); + SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesWidth, size.width()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesLength, size.height()); + + // Set Orientation + if(m_layout->GetTilesOrientation() == PageOrientation::Portrait) + { + ui->radioButtonSheetPortrait->setChecked(true); + } + else + { + ui->radioButtonSheetLandscape->setChecked(true); + } + + // set margins + QMarginsF margins = m_layout->GetTilesMarginsConverted(); + SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesMarginLeft, margins.left()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesMarginTop, margins.top()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesMarginRight, margins.right()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesMarginBottom, margins.bottom()); + + // set "show tiles" checkbox + ui->checkBoxTilesShowTiles->setChecked(m_layout->GetShowTiles()); +} + //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::SetPropertyTabLayoutData() { @@ -467,11 +520,7 @@ void VPMainWindow::SetPropertyTabLayoutData() SetCheckBoxValue(ui->checkBoxLayoutWarningPiecesSuperposition, m_layout->GetWarningSuperpositionOfPieces()); } -//--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::SetPropertyTabTilesData() -{ -// TODO -} + //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::InitMainGraphics() @@ -941,6 +990,62 @@ void VPMainWindow::on_SheetMarginChanged() } +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::on_TilesSizeChanged() +{ + m_layout->SetTilesSizeConverted(ui->doubleSpinBoxTilesWidth->value(), ui->doubleSpinBoxTilesLength->value()); + + // TODO Undo / Redo + + m_graphicsView->RefreshLayout(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::on_TilesOrientationChanged() +{ + // Updates the orientation + if(ui->radioButtonTilesPortrait->isChecked()) + { + m_layout->SetTilesOrientation(PageOrientation::Portrait); + } + else + { + m_layout->SetTilesOrientation(PageOrientation::Landscape); + } + + // TODO Undo / Redo + + m_graphicsView->RefreshLayout(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::on_TilesMarginChanged() +{ + m_layout->GetFocusedSheet()->SetSheetMarginsConverted( + ui->doubleSpinBoxTilesMarginLeft->value(), + ui->doubleSpinBoxTilesMarginTop->value(), + ui->doubleSpinBoxTilesMarginRight->value(), + ui->doubleSpinBoxTilesMarginBottom->value() + ); + + // TODO Undo / Redo + + m_graphicsView->RefreshLayout(); +} + + + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::on_checkBoxTilesShowTiles_toggled(bool checked) +{ + m_layout->SetShowTiles(checked); + + // TODO Undo / Redo + + m_graphicsView->RefreshLayout(); +} + + //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_SheetFollowGrainlineChanged() { diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index 43a40f07a..d01c7b447 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -285,33 +285,33 @@ private slots: void on_comboBoxSheetTemplate_currentIndexChanged(int index); /** - * @brief LayoutSizeChanged When the width or the length has been changed in - * the layout property tab + * @brief on_SheetSizeChanged When the width or the length has been changed in + * the sheet property tab */ void on_SheetSizeChanged(); /** - * @brief LayoutOrientationChanged When one of the radio boxes for the layout + * @brief on_SheetOrientationChanged When one of the radio boxes for the sheet * orientation has been clicked */ void on_SheetOrientationChanged(); /** * @brief on_pushButtonLayoutRemoveUnusedLength_clicked When the button - * "Remove unused length" in the layout property tab is clicked. + * "Remove unused length" in the sheet property tab is clicked. * The slot is automatically connected through name convention. */ void on_pushButtonSheetRemoveUnusedLength_clicked(); /** - * @brief on_LayoutMarginChanged When one of the margin values has been changed - * in the layout property tab. + * @brief on_SheetMarginChanged When one of the margin values has been changed + * in the sheet property tab. */ void on_SheetMarginChanged(); /** * @brief LayoutFollowGrainlineChanged When one of the radio boxes for the - * "Follow grainline" has been clicked in the layout property tab. + * "Follow grainline" has been clicked in the sheet property tab. */ void on_SheetFollowGrainlineChanged(); @@ -323,6 +323,33 @@ private slots: */ void on_doubleSpinBoxSheetPiecesGap_valueChanged(double value); + + /** + * @brief on_TilesSizeChanged When the width or the length has been changed in + * the tiles property tab + */ + void on_TilesSizeChanged(); + + /** + * @brief on_TilesOrientationChanged When one of the radio boxes for the tiles + * orientation has been clicked + */ + void on_TilesOrientationChanged(); + + /** + * @brief on_TilesMarginChanged When one of the margin values has been changed + * in the tiles property tab. + */ + void on_TilesMarginChanged(); + + /** + * @brief on_checkBoxTilesShowTiles_toggled When the checkbox "show tiles" is + * clicked + * @param checked´ + */ + void on_checkBoxTilesShowTiles_toggled(bool checked); + + /** * @brief on_checkBoxLayoutWarningPiecesSuperposition_toggled When the * "Warning when pieces superposition" checkbox value in the layout diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 68adf8583..3941db274 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -176,7 +176,7 @@ QTabWidget::Rounded - 1 + 2 @@ -530,7 +530,7 @@ - Layout properties + Sheet properties @@ -1199,6 +1199,9 @@ + + Layout properties + 0 From e7cd13b7034a5754dcfd9feb4246d60a65604112 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 14 Nov 2020 17:31:34 +0100 Subject: [PATCH 15/34] Preview grid of the tiles on the sheet --- src/app/puzzle/vpgraphicssheet.cpp | 62 +++++++++++++++++++++++++++ src/app/puzzle/vpmaingraphicsview.cpp | 9 ++++ src/app/puzzle/vpmaingraphicsview.h | 5 +++ src/app/puzzle/vpmainwindow.cpp | 49 ++++++++++++++++----- src/app/puzzle/vpmainwindow.h | 4 ++ src/app/puzzle/vpmainwindow.ui | 24 +++++++++-- src/app/puzzle/vpsheet.cpp | 6 +++ src/app/puzzle/vpsheet.h | 7 +++ 8 files changed, 152 insertions(+), 14 deletions(-) diff --git a/src/app/puzzle/vpgraphicssheet.cpp b/src/app/puzzle/vpgraphicssheet.cpp index cfee78a09..e07037c56 100644 --- a/src/app/puzzle/vpgraphicssheet.cpp +++ b/src/app/puzzle/vpgraphicssheet.cpp @@ -27,6 +27,8 @@ *************************************************************************/ #include "vpgraphicssheet.h" +#include "vplayout.h" +#include //--------------------------------------------------------------------------------------------------------------------- VPGraphicsSheet::VPGraphicsSheet(VPSheet *sheet, QGraphicsItem *parent): @@ -68,6 +70,66 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o painter->drawRect(GetSheetRect()); } + // show the tiles grid. Maybe it shouldn't be in the graphics sheet, maybe better in maingraphicsview + VPLayout* layout = m_sheet->GetLayout(); + if(layout->GetShowTiles()) + { + pen.setColor(QColor(255,0,0,127)); + pen.setStyle(Qt::DashLine); + painter->setPen(pen); + + QSizeF tilesSize = layout->GetTilesSize(); + QSizeF sheetSize = m_sheet->GetSheetSize(); + + QMarginsF tilesMargins = layout->GetTilesMargins(); + + PageOrientation tilesOrientation = layout->GetTilesOrientation(); + PageOrientation sheetOrientation = m_sheet->GetOrientation(); + + qreal colWidth = 0; + qreal rowHeight = 0; + if(tilesOrientation == PageOrientation::Portrait) + { + colWidth = tilesSize.width() - (tilesMargins.left()+ tilesMargins.right() + UnitConvertor(1, Unit::Cm, Unit::Px)); + rowHeight = tilesSize.height() - (tilesMargins.top()+ tilesMargins.bottom() + UnitConvertor(1, Unit::Cm, Unit::Px)); + } + else + { + colWidth = tilesSize.height() - (tilesMargins.left()+ tilesMargins.right() + UnitConvertor(1, Unit::Cm, Unit::Px)); + rowHeight = tilesSize.width() - (tilesMargins.top()+ tilesMargins.bottom() + UnitConvertor(1, Unit::Cm, Unit::Px)); + } + // the "+ UnitConvertor(1, Unit::Cm, Unit::Px)" is because of the part for gluing and where we + // have infos of the single tile. Maybe it's not the right value, to be corrected. + + + qreal drawingWidth = 0; + qreal drawingHeight = 0; + + if(sheetOrientation == PageOrientation::Portrait) + { + drawingWidth = sheetSize.width(); + drawingHeight = sheetSize.height(); + } + else + { + drawingWidth = sheetSize.height(); + drawingHeight = sheetSize.width(); + } + + int nbCol = qCeil(drawingWidth/colWidth); + int nbRow = qCeil(drawingHeight/rowHeight); + + for(int i=0;i<=nbCol;i++) + { + painter->drawLine(QPointF(i*colWidth, 0), QPointF(i*colWidth,nbRow*rowHeight)); + } + + for(int j=0;j<=nbRow;j++) + { + painter->drawLine(QPointF(0, j*rowHeight), QPointF(nbCol*colWidth, j*rowHeight)); + } + } + m_boundingRect = GetSheetRect(); } diff --git a/src/app/puzzle/vpmaingraphicsview.cpp b/src/app/puzzle/vpmaingraphicsview.cpp index 4c838f9fd..6e63b4643 100644 --- a/src/app/puzzle/vpmaingraphicsview.cpp +++ b/src/app/puzzle/vpmaingraphicsview.cpp @@ -84,8 +84,14 @@ VMainGraphicsScene* VPMainGraphicsView::GetScene() //--------------------------------------------------------------------------------------------------------------------- void VPMainGraphicsView::PrepareForExport() { + m_layout->ClearSelection(); + m_graphicsSheet->SetShowBorder(false); m_graphicsSheet->SetShowMargin(false); + + m_showTilesTmp = m_layout->GetShowTiles(); + m_layout->SetShowTiles(false); + RefreshLayout(); } @@ -94,6 +100,9 @@ void VPMainGraphicsView::CleanAfterExport() { m_graphicsSheet->SetShowBorder(true); m_graphicsSheet->SetShowMargin(true); + + m_layout->SetShowTiles(m_showTilesTmp); + RefreshLayout(); } diff --git a/src/app/puzzle/vpmaingraphicsview.h b/src/app/puzzle/vpmaingraphicsview.h index 94d52e1b5..5641bf2d2 100644 --- a/src/app/puzzle/vpmaingraphicsview.h +++ b/src/app/puzzle/vpmaingraphicsview.h @@ -99,6 +99,11 @@ private: QList m_graphicsPieces{}; + /** + * variable to hold temporarly hte value of the show tiles + */ + bool m_showTilesTmp{false}; + }; #endif // VPMAINGRAPHICSVIEW_H diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index b6de14936..9b4a182d2 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -318,23 +318,23 @@ void VPMainWindow::InitPropertyTabCurrentSheet() void VPMainWindow::InitPropertyTabTiles() { // -------------------- layout width, length, orientation ------------------------ - connect(ui->doubleSpinBoxSheetWidth, QOverload::of(&QDoubleSpinBox::valueChanged), this, + connect(ui->doubleSpinBoxTilesWidth, QOverload::of(&QDoubleSpinBox::valueChanged), this, &VPMainWindow::on_TilesSizeChanged); - connect(ui->doubleSpinBoxSheetLength, QOverload::of(&QDoubleSpinBox::valueChanged), this, + connect(ui->doubleSpinBoxTilesLength, QOverload::of(&QDoubleSpinBox::valueChanged), this, &VPMainWindow::on_TilesSizeChanged); - connect(ui->radioButtonSheetPortrait, QOverload::of(&QRadioButton::clicked), this, + connect(ui->radioButtonTilesPortrait, QOverload::of(&QRadioButton::clicked), this, &VPMainWindow::on_TilesOrientationChanged); - connect(ui->radioButtonSheetLandscape, QOverload::of(&QRadioButton::clicked), this, + connect(ui->radioButtonTilesLandscape, QOverload::of(&QRadioButton::clicked), this, &VPMainWindow::on_TilesOrientationChanged); // -------------------- margins ------------------------ - connect(ui->doubleSpinBoxSheetMarginTop, QOverload::of(&QDoubleSpinBox::valueChanged), this, + connect(ui->doubleSpinBoxTilesMarginTop, QOverload::of(&QDoubleSpinBox::valueChanged), this, &VPMainWindow::on_TilesMarginChanged); - connect(ui->doubleSpinBoxSheetMarginRight, QOverload::of(&QDoubleSpinBox::valueChanged), this, + connect(ui->doubleSpinBoxTilesMarginRight, QOverload::of(&QDoubleSpinBox::valueChanged), this, &VPMainWindow::on_TilesMarginChanged); - connect(ui->doubleSpinBoxSheetMarginBottom, QOverload::of(&QDoubleSpinBox::valueChanged), this, + connect(ui->doubleSpinBoxTilesMarginBottom, QOverload::of(&QDoubleSpinBox::valueChanged), this, &VPMainWindow::on_TilesMarginChanged); - connect(ui->doubleSpinBoxSheetMarginLeft, QOverload::of(&QDoubleSpinBox::valueChanged), this, + connect(ui->doubleSpinBoxTilesMarginLeft, QOverload::of(&QDoubleSpinBox::valueChanged), this, &VPMainWindow::on_TilesMarginChanged); } @@ -1021,7 +1021,7 @@ void VPMainWindow::on_TilesOrientationChanged() //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_TilesMarginChanged() { - m_layout->GetFocusedSheet()->SetSheetMarginsConverted( + m_layout->SetTilesMarginsConverted( ui->doubleSpinBoxTilesMarginLeft->value(), ui->doubleSpinBoxTilesMarginTop->value(), ui->doubleSpinBoxTilesMarginRight->value(), @@ -1034,7 +1034,6 @@ void VPMainWindow::on_TilesMarginChanged() } - //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_checkBoxTilesShowTiles_toggled(bool checked) { @@ -1045,6 +1044,36 @@ void VPMainWindow::on_checkBoxTilesShowTiles_toggled(bool checked) m_graphicsView->RefreshLayout(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::on_pushButtonTilesExport_clicked() +{ + // svg export to do some test for the first test + + QString dir = QDir::homePath(); + QString filters(tr("PDF Files") + QLatin1String("(*.pdf)")); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), + dir + QLatin1String("/") + tr("Layout") + QLatin1String(".pdf"), + filters, nullptr +#ifdef Q_OS_LINUX + , QFileDialog::DontUseNativeDialog +#endif + ); + + if(not fileName.isEmpty()) + { + m_graphicsView->PrepareForExport(); + + + + // TODO : Tiles export + + + + m_graphicsView->CleanAfterExport(); + } +} + + //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_SheetFollowGrainlineChanged() diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index d01c7b447..dc1145e26 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -349,6 +349,10 @@ private slots: */ void on_checkBoxTilesShowTiles_toggled(bool checked); + /** + * @brief on_pushButtonTilesExport_clicked When the export tiles button is clicked + */ + void on_pushButtonTilesExport_clicked(); /** * @brief on_checkBoxLayoutWarningPiecesSuperposition_toggled When the diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 3941db274..6e7a241c5 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -1106,10 +1106,18 @@ - + + + 0.100000000000000 + + - + + + 0.100000000000000 + + @@ -1122,7 +1130,11 @@ - + + + 0.100000000000000 + + @@ -1135,7 +1147,11 @@ - + + + 0.100000000000000 + + diff --git a/src/app/puzzle/vpsheet.cpp b/src/app/puzzle/vpsheet.cpp index 591194813..e1f6cb501 100644 --- a/src/app/puzzle/vpsheet.cpp +++ b/src/app/puzzle/vpsheet.cpp @@ -43,6 +43,12 @@ VPSheet::~VPSheet() delete m_pieceList; } +//--------------------------------------------------------------------------------------------------------------------- +VPLayout* VPSheet::GetLayout() +{ + return m_layout; +} + //--------------------------------------------------------------------------------------------------------------------- VPPieceList* VPSheet::GetPieceList() { diff --git a/src/app/puzzle/vpsheet.h b/src/app/puzzle/vpsheet.h index 47c62d819..2e49acaf3 100644 --- a/src/app/puzzle/vpsheet.h +++ b/src/app/puzzle/vpsheet.h @@ -49,6 +49,12 @@ public: ~VPSheet(); + /** + * @brief GetLayout Returns the Layout of the sheet + * @return + */ + VPLayout* GetLayout(); + /** * @brief GetPieceList returns the piece list of the sheet * @return piece list @@ -203,6 +209,7 @@ public: void SetStickyEdges(bool state); bool GetStickyEdges() const; + private: Q_DISABLE_COPY(VPSheet) From f90f8ca01b5ded2977228ee9a0b75399a8548adf Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sun, 15 Nov 2020 12:30:29 +0100 Subject: [PATCH 16/34] First tiles export --- src/app/puzzle/vplayout.cpp | 18 +++++-- src/app/puzzle/vplayout.h | 21 ++++++-- src/app/puzzle/vpmainwindow.cpp | 90 +++++++++++++++++++++++++++++++-- src/app/puzzle/vpmainwindow.ui | 12 ++++- 4 files changed, 129 insertions(+), 12 deletions(-) diff --git a/src/app/puzzle/vplayout.cpp b/src/app/puzzle/vplayout.cpp index 6744850d1..ef81a0694 100644 --- a/src/app/puzzle/vplayout.cpp +++ b/src/app/puzzle/vplayout.cpp @@ -268,16 +268,22 @@ QSizeF VPLayout::GetTilesSize() const } //--------------------------------------------------------------------------------------------------------------------- -QSizeF VPLayout::GetTilesSizeConverted() const +QSizeF VPLayout::GetTilesSize(Unit unit) const { QSizeF convertedSize = QSizeF( - UnitConvertor(m_tilesSize.width(), Unit::Px, GetUnit()), - UnitConvertor(m_tilesSize.height(), Unit::Px, GetUnit()) + UnitConvertor(m_tilesSize.width(), Unit::Px, unit), + UnitConvertor(m_tilesSize.height(), Unit::Px, unit) ); return convertedSize; } +//--------------------------------------------------------------------------------------------------------------------- +QSizeF VPLayout::GetTilesSizeConverted() const +{ + return GetTilesSize(GetUnit()); +} + //--------------------------------------------------------------------------------------------------------------------- PageOrientation VPLayout::GetTilesOrientation() { @@ -330,6 +336,12 @@ QMarginsF VPLayout::GetTilesMargins() const return m_tilesMargins; } +//--------------------------------------------------------------------------------------------------------------------- +QMarginsF VPLayout::GetTilesMargins(Unit unit) const +{ + return UnitConvertor(m_tilesMargins, Unit::Px, unit); +} + //--------------------------------------------------------------------------------------------------------------------- QMarginsF VPLayout::GetTilesMarginsConverted() const { diff --git a/src/app/puzzle/vplayout.h b/src/app/puzzle/vplayout.h index 144578b46..e8ca4d933 100644 --- a/src/app/puzzle/vplayout.h +++ b/src/app/puzzle/vplayout.h @@ -154,21 +154,27 @@ public: /** * @brief SetTilesSize sets the size of the tiles, the values have to be in Unit::Px - * @param size sheet size + * @param size tiles size */ void SetTilesSize(const QSizeF &size); /** * @brief SetTilesSizeConverted sets the size of the tiles, the values have to be in the layout's unit - * @param size sheet size + * @param size tiles size */ void SetTilesSizeConverted(const QSizeF &size); /** * @brief GetTilesSize Returns the size of the tiles in Unit::Px - * @return sheet size in Unit::Px + * @return tiles size in Unit::Px */ QSizeF GetTilesSize() const; + /** + * @brief GetTilesSize Returns the size of the tiles in given Unit + * @return tiles size + */ + QSizeF GetTilesSize(Unit unit) const; + /** * @brief GetTilesSizeConverted Returns the size of the tiles in the layout's unit * @return the size in the layout's unit @@ -219,10 +225,17 @@ public: /** * @brief GetTilesMargins Returns margins of the tiles in Unit::Px - * @return the size in Unit::Px + * @return the margins in Unit::Px */ QMarginsF GetTilesMargins() const; + /** + * @brief GetTilesMargins Returns margins of the tiles in the given unit + * @param unit the unit in which we want the margins + * @return the margins in the given unit + */ + QMarginsF GetTilesMargins(Unit unit) const; + /** * @brief GetTilesMarginsConverted Returns the margins of the tiles in the layout's unit * @return the margins in the tiles's unit diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 9b4a182d2..fa49e302f 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -496,7 +496,7 @@ void VPMainWindow::SetPropertyTabTilesData() SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesMarginBottom, margins.bottom()); // set "show tiles" checkbox - ui->checkBoxTilesShowTiles->setChecked(m_layout->GetShowTiles()); + SetCheckBoxValue(ui->checkBoxTilesShowTiles, m_layout->GetShowTiles()); } //--------------------------------------------------------------------------------------------------------------------- @@ -913,8 +913,9 @@ void VPMainWindow::on_comboBoxLayoutUnit_currentIndexChanged(int index) m_layout->SetUnit(Unit::Inch); } - SetPropertyTabSheetData(); SetPropertyTabCurrentPieceData(); + SetPropertyTabSheetData(); + SetPropertyTabTilesData(); } //--------------------------------------------------------------------------------------------------------------------- @@ -1061,13 +1062,96 @@ void VPMainWindow::on_pushButtonTilesExport_clicked() if(not fileName.isEmpty()) { + // tests for now, later we want this in a separated function + m_graphicsView->PrepareForExport(); + PageOrientation tilesOrientation = m_layout->GetTilesOrientation(); + QSizeF tilesSize = m_layout->GetTilesSize(); + QMarginsF tilesMargins = m_layout->GetTilesMargins(); - // TODO : Tiles export + // ------------- Set up the printer + QPrinter* printer = new QPrinter(); + + printer->setCreator(QGuiApplication::applicationDisplayName()+QChar(QChar::Space)+ + QCoreApplication::applicationVersion()); + printer->setOrientation(QPrinter::Portrait); // in the pdf file the pages should always be in portrait + + // here we might need to so some rounding for the size. + printer->setPageSize(QPageSize(m_layout->GetTilesSize(Unit::Mm), + QPageSize::Millimeter)); + printer->setFullPage(true); + const bool success = printer->setPageMargins(m_layout->GetTilesMargins(Unit::Mm), QPageLayout::Millimeter); + if (not success) + { + qWarning() << tr("Cannot set printer margins"); + } + + #ifdef Q_OS_MAC + printer->setOutputFormat(QPrinter::NativeFormat); + #else + printer->setOutputFormat(QPrinter::PdfFormat); + #endif + + printer->setOutputFileName(fileName); + printer->setResolution(static_cast(PrintDPI)); + + printer->setDocName("Test"); + // ------------- Set up the painter + QPainter painter; + if (not painter.begin(printer)) + { // failed to open file + qCritical() << tr("Failed to open file, is it writable?"); + return; + } + painter.setFont( QFont( QStringLiteral("Arial"), 8, QFont::Normal ) ); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.setBrush ( QBrush ( Qt::NoBrush ) ); + + if(tilesOrientation == PageOrientation::Landscape) + { + // The landscape tiles have to be rotated, because the pages + // stay portrait in the pdf + painter.rotate(90); + painter.translate(0, -ToPixel(printer->pageRect(QPrinter::Millimeter).width(), Unit::Mm)); + } + + + // ------------- Perform the Tiling + qreal tilesDrawingAreaHeight = (tilesOrientation == PageOrientation::Portrait)? + tilesSize.height() : tilesSize.width(); + tilesDrawingAreaHeight -= + tilesMargins.top() + tilesMargins.bottom() + UnitConvertor(1, Unit::Cm, Unit::Px); + + // the -1cm is for test purpuses, it correspondings to the overlaping for gluing the parts, + // later we'll have a proper abstract value + + qreal tilesDrawingAreaWidth = (tilesOrientation == PageOrientation::Portrait)? + tilesSize.width() : tilesSize.height(); + tilesDrawingAreaWidth -= + tilesMargins.left() + tilesMargins.right() + UnitConvertor(1, Unit::Cm, Unit::Px); + + + QRectF source = QRectF(0,0,tilesDrawingAreaWidth, tilesDrawingAreaHeight); + + QRectF target = QRectF(m_layout->GetTilesMargins().left(), m_layout->GetTilesMargins().top(), + source.width(), source.height()); + m_graphicsView->GetScene()->render(&painter, target, source, Qt::IgnoreAspectRatio); + + if (not printer->newPage()) + { + qWarning("failed in flushing page to disk, disk full?"); + return; + } + + source = QRectF(tilesDrawingAreaWidth,0,tilesDrawingAreaWidth, tilesDrawingAreaHeight); + m_graphicsView->GetScene()->render(&painter, target, source, Qt::IgnoreAspectRatio); + + painter.end(); m_graphicsView->CleanAfterExport(); } diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 6e7a241c5..72f44bece 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -1014,7 +1014,11 @@ - + + + 100000.000000000000000 + + @@ -1024,7 +1028,11 @@ - + + + 100000.000000000000000 + + From cbf0651486fb4ef97f6e21b32e4aa382908f8e49 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sun, 15 Nov 2020 13:06:57 +0100 Subject: [PATCH 17/34] All tiles exported --- src/app/puzzle/vpmainwindow.cpp | 225 ++++++++++++++++++-------------- src/app/puzzle/vpmainwindow.h | 6 + 2 files changed, 135 insertions(+), 96 deletions(-) diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index fa49e302f..14f621bc3 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -702,6 +702,132 @@ bool VPMainWindow::MaybeSave() return true; } +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::generateTiledPdf(QString fileName) +{ + if(not fileName.isEmpty()) + { + m_graphicsView->PrepareForExport(); + + PageOrientation tilesOrientation = m_layout->GetTilesOrientation(); + QSizeF tilesSize = m_layout->GetTilesSize(); + QMarginsF tilesMargins = m_layout->GetTilesMargins(); + + + // ------------- Set up the printer + QPrinter* printer = new QPrinter(); + + printer->setCreator(QGuiApplication::applicationDisplayName()+QChar(QChar::Space)+ + QCoreApplication::applicationVersion()); + printer->setOrientation(QPrinter::Portrait); // in the pdf file the pages should always be in portrait + + // here we might need to so some rounding for the size. + printer->setPageSize(QPageSize(m_layout->GetTilesSize(Unit::Mm), + QPageSize::Millimeter)); + printer->setFullPage(true); + const bool success = printer->setPageMargins(m_layout->GetTilesMargins(Unit::Mm), QPageLayout::Millimeter); + if (not success) + { + qWarning() << tr("Cannot set printer margins"); + } + + #ifdef Q_OS_MAC + printer->setOutputFormat(QPrinter::NativeFormat); + #else + printer->setOutputFormat(QPrinter::PdfFormat); + #endif + + printer->setOutputFileName(fileName); + printer->setResolution(static_cast(PrintDPI)); + + printer->setDocName("Test"); + + + // ------------- Set up the painter + QPainter painter; + if (not painter.begin(printer)) + { // failed to open file + qCritical() << tr("Failed to open file, is it writable?"); + return; + } + painter.setFont( QFont( QStringLiteral("Arial"), 8, QFont::Normal ) ); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.setBrush ( QBrush ( Qt::NoBrush ) ); + + if(tilesOrientation == PageOrientation::Landscape) + { + // The landscape tiles have to be rotated, because the pages + // stay portrait in the pdf + painter.rotate(90); + painter.translate(0, -ToPixel(printer->pageRect(QPrinter::Millimeter).width(), Unit::Mm)); + } + + + // ------------- Prepare infos for the tiling + qreal tilesDrawingAreaHeight = (tilesOrientation == PageOrientation::Portrait)? + tilesSize.height() : tilesSize.width(); + tilesDrawingAreaHeight -= + tilesMargins.top() + tilesMargins.bottom() + UnitConvertor(1, Unit::Cm, Unit::Px); + + // the -1cm is for test purpuses, it correspondings to the overlaping for gluing the parts, + // later we'll have a proper abstract value + + qreal tilesDrawingAreaWidth = (tilesOrientation == PageOrientation::Portrait)? + tilesSize.width() : tilesSize.height(); + tilesDrawingAreaWidth -= + tilesMargins.left() + tilesMargins.right() + UnitConvertor(1, Unit::Cm, Unit::Px); + + + QSizeF sheetSize = m_layout->GetFocusedSheet()->GetSheetSize(); + qreal drawingWidth = 0; + qreal drawingHeight = 0; + + if(m_layout->GetFocusedSheet()->GetOrientation() == PageOrientation::Portrait) + { + drawingWidth = sheetSize.width(); + drawingHeight = sheetSize.height(); + } + else + { + drawingWidth = sheetSize.height(); + drawingHeight = sheetSize.width(); + } + + int nbCol = qCeil(drawingWidth/tilesDrawingAreaWidth); + int nbRow = qCeil(drawingHeight/tilesDrawingAreaHeight); + + // ------------- Perform the tiling + for(int i=0;inewPage()) + { + qWarning("failed in flushing page to disk, disk full?"); + return; + } + } + + QRectF source = QRectF(j*tilesDrawingAreaWidth, i*tilesDrawingAreaHeight, tilesDrawingAreaWidth, tilesDrawingAreaHeight); + QRectF target = QRectF(m_layout->GetTilesMargins().left(), m_layout->GetTilesMargins().top(), + source.width(), source.height()); + + // TODO: add the lines etc + + m_graphicsView->GetScene()->render(&painter, target, source, Qt::IgnoreAspectRatio); + } + } + + painter.end(); + + m_graphicsView->CleanAfterExport(); + } +} + + //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_actionNew_triggered() { @@ -811,7 +937,8 @@ void VPMainWindow::on_actionSave_triggered() //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_actionSaveAs_triggered() { - // TODO / FIXME : See valentina how the save is done over there. we need to add the extension .vlt, check for empty file names etc. + // TODO / FIXME : See valentina how the save is done over there. we need to add the + // extension .vlt, check for empty file names etc. //Get list last open files QStringList recentFiles = qApp->PuzzleSettings()->GetRecentFileList(); @@ -1060,101 +1187,7 @@ void VPMainWindow::on_pushButtonTilesExport_clicked() #endif ); - if(not fileName.isEmpty()) - { - // tests for now, later we want this in a separated function - - m_graphicsView->PrepareForExport(); - - PageOrientation tilesOrientation = m_layout->GetTilesOrientation(); - QSizeF tilesSize = m_layout->GetTilesSize(); - QMarginsF tilesMargins = m_layout->GetTilesMargins(); - - - // ------------- Set up the printer - QPrinter* printer = new QPrinter(); - - printer->setCreator(QGuiApplication::applicationDisplayName()+QChar(QChar::Space)+ - QCoreApplication::applicationVersion()); - printer->setOrientation(QPrinter::Portrait); // in the pdf file the pages should always be in portrait - - // here we might need to so some rounding for the size. - printer->setPageSize(QPageSize(m_layout->GetTilesSize(Unit::Mm), - QPageSize::Millimeter)); - printer->setFullPage(true); - const bool success = printer->setPageMargins(m_layout->GetTilesMargins(Unit::Mm), QPageLayout::Millimeter); - if (not success) - { - qWarning() << tr("Cannot set printer margins"); - } - - #ifdef Q_OS_MAC - printer->setOutputFormat(QPrinter::NativeFormat); - #else - printer->setOutputFormat(QPrinter::PdfFormat); - #endif - - printer->setOutputFileName(fileName); - printer->setResolution(static_cast(PrintDPI)); - - printer->setDocName("Test"); - - - // ------------- Set up the painter - QPainter painter; - if (not painter.begin(printer)) - { // failed to open file - qCritical() << tr("Failed to open file, is it writable?"); - return; - } - painter.setFont( QFont( QStringLiteral("Arial"), 8, QFont::Normal ) ); - painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - painter.setBrush ( QBrush ( Qt::NoBrush ) ); - - if(tilesOrientation == PageOrientation::Landscape) - { - // The landscape tiles have to be rotated, because the pages - // stay portrait in the pdf - painter.rotate(90); - painter.translate(0, -ToPixel(printer->pageRect(QPrinter::Millimeter).width(), Unit::Mm)); - } - - - // ------------- Perform the Tiling - qreal tilesDrawingAreaHeight = (tilesOrientation == PageOrientation::Portrait)? - tilesSize.height() : tilesSize.width(); - tilesDrawingAreaHeight -= - tilesMargins.top() + tilesMargins.bottom() + UnitConvertor(1, Unit::Cm, Unit::Px); - - // the -1cm is for test purpuses, it correspondings to the overlaping for gluing the parts, - // later we'll have a proper abstract value - - qreal tilesDrawingAreaWidth = (tilesOrientation == PageOrientation::Portrait)? - tilesSize.width() : tilesSize.height(); - tilesDrawingAreaWidth -= - tilesMargins.left() + tilesMargins.right() + UnitConvertor(1, Unit::Cm, Unit::Px); - - - QRectF source = QRectF(0,0,tilesDrawingAreaWidth, tilesDrawingAreaHeight); - - QRectF target = QRectF(m_layout->GetTilesMargins().left(), m_layout->GetTilesMargins().top(), - source.width(), source.height()); - m_graphicsView->GetScene()->render(&painter, target, source, Qt::IgnoreAspectRatio); - - if (not printer->newPage()) - { - qWarning("failed in flushing page to disk, disk full?"); - return; - } - - source = QRectF(tilesDrawingAreaWidth,0,tilesDrawingAreaWidth, tilesDrawingAreaHeight); - m_graphicsView->GetScene()->render(&painter, target, source, Qt::IgnoreAspectRatio); - - painter.end(); - - m_graphicsView->CleanAfterExport(); - } + generateTiledPdf(fileName); } diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index dc1145e26..e11a28956 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -217,6 +217,12 @@ private: bool MaybeSave(); + /** + * @brief generateTiledPdf Generates the tiled Pdf in the given filename + * @param filename + */ + void generateTiledPdf(QString fileName); + private slots: /** From db4bd0d616a6bd4d252a944796fcb294f2167699 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sun, 15 Nov 2020 22:34:24 +0100 Subject: [PATCH 18/34] Improve tiles decoration --- src/app/puzzle/share/resources/puzzleicon.qrc | 3 + .../puzzleicon/svg/icon_scissors.svg | 75 +++++++++ .../svg/icon_scissors_horizontal.svg | 77 +++++++++ .../puzzleicon/svg/icon_scissors_vertical.svg | 77 +++++++++ src/app/puzzle/vpmainwindow.cpp | 158 ++++++++++++++++-- 5 files changed, 379 insertions(+), 11 deletions(-) create mode 100644 src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors.svg create mode 100644 src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors_horizontal.svg create mode 100644 src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors_vertical.svg diff --git a/src/app/puzzle/share/resources/puzzleicon.qrc b/src/app/puzzle/share/resources/puzzleicon.qrc index 50e94a444..12c2a72ee 100644 --- a/src/app/puzzle/share/resources/puzzleicon.qrc +++ b/src/app/puzzle/share/resources/puzzleicon.qrc @@ -11,5 +11,8 @@ puzzleicon/64x64/iconGrainlineHorizontal.png puzzleicon/64x64/cursorRotate.png puzzleicon/64x64/iconProperties.png + puzzleicon/svg/icon_scissors.svg + puzzleicon/svg/icon_scissors_vertical.svg + puzzleicon/svg/icon_scissors_horizontal.svg diff --git a/src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors.svg b/src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors.svg new file mode 100644 index 000000000..fd1bd78c7 --- /dev/null +++ b/src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors.svg @@ -0,0 +1,75 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors_horizontal.svg b/src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors_horizontal.svg new file mode 100644 index 000000000..03d29b139 --- /dev/null +++ b/src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors_horizontal.svg @@ -0,0 +1,77 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors_vertical.svg b/src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors_vertical.svg new file mode 100644 index 000000000..c88794863 --- /dev/null +++ b/src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors_vertical.svg @@ -0,0 +1,77 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 14f621bc3..6efa30b7e 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -713,7 +713,6 @@ void VPMainWindow::generateTiledPdf(QString fileName) QSizeF tilesSize = m_layout->GetTilesSize(); QMarginsF tilesMargins = m_layout->GetTilesMargins(); - // ------------- Set up the printer QPrinter* printer = new QPrinter(); @@ -739,8 +738,7 @@ void VPMainWindow::generateTiledPdf(QString fileName) printer->setOutputFileName(fileName); printer->setResolution(static_cast(PrintDPI)); - - printer->setDocName("Test"); + printer->setDocName("Test"); // FIXME // ------------- Set up the painter @@ -752,8 +750,10 @@ void VPMainWindow::generateTiledPdf(QString fileName) } painter.setFont( QFont( QStringLiteral("Arial"), 8, QFont::Normal ) ); painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); + QPen penTileInfos = QPen(QColor(180,180,180), qApp->Settings()->WidthHairLine(), Qt::DashLine, Qt::RoundCap, Qt::RoundJoin); + QPen penTileDrawing = QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + if(tilesOrientation == PageOrientation::Landscape) { @@ -797,12 +797,67 @@ void VPMainWindow::generateTiledPdf(QString fileName) int nbCol = qCeil(drawingWidth/tilesDrawingAreaWidth); int nbRow = qCeil(drawingHeight/tilesDrawingAreaHeight); + + // ------------- prepare triangles for positioning + // top triangle + QRectF rectTop = QRectF(tilesMargins.left()+ tilesDrawingAreaWidth/2 - UnitConvertor(0.5, Unit::Cm, Unit::Px), + tilesMargins.top(), + UnitConvertor(1, Unit::Cm, Unit::Px), + UnitConvertor(0.5, Unit::Cm, Unit::Px) + ); + QPainterPath triangleTop; + triangleTop.moveTo(rectTop.topLeft()); + triangleTop.lineTo(rectTop.topRight()); + triangleTop.lineTo(rectTop.left() + (rectTop.width() / 2), rectTop.bottom()); + triangleTop.lineTo(rectTop.topLeft()); + + // left triangle + QRectF rectLeft = QRectF(tilesMargins.left(), + tilesMargins.top() + tilesDrawingAreaHeight/2 - UnitConvertor(0.5, Unit::Cm, Unit::Px), + UnitConvertor(0.5, Unit::Cm, Unit::Px), + UnitConvertor(1, Unit::Cm, Unit::Px) + ); + QPainterPath triangleLeft; + triangleLeft.moveTo(rectLeft.topLeft()); + triangleLeft.lineTo(rectLeft.right(), rectLeft.top() + (rectLeft.height() / 2)); + triangleLeft.lineTo(rectLeft.bottomLeft()); + triangleLeft.lineTo(rectLeft.topLeft()); + + // bottom triangle + QRectF rectBottom = QRectF(tilesMargins.left()+ tilesDrawingAreaWidth/2 - UnitConvertor(0.5, Unit::Cm, Unit::Px), + tilesMargins.top()+tilesDrawingAreaHeight - UnitConvertor(0.5, Unit::Cm, Unit::Px), + UnitConvertor(1, Unit::Cm, Unit::Px), + UnitConvertor(0.5, Unit::Cm, Unit::Px) + ); + QPainterPath triangleBottom; + triangleBottom.moveTo(rectBottom.bottomLeft()); + triangleBottom.lineTo(rectBottom.left() + (rectBottom.width() / 2), rectBottom.top()); + triangleBottom.lineTo(rectBottom.bottomRight()); + triangleBottom.lineTo(rectBottom.bottomLeft()); + + // right triangle + QRectF rectRight = QRectF(tilesMargins.left() + tilesDrawingAreaWidth - UnitConvertor(0.5, Unit::Cm, Unit::Px), + tilesMargins.top() + tilesDrawingAreaHeight/2 - UnitConvertor(0.5, Unit::Cm, Unit::Px), + UnitConvertor(0.5, Unit::Cm, Unit::Px), + UnitConvertor(1, Unit::Cm, Unit::Px) + ); + QPainterPath triangleRight; + triangleRight.moveTo(rectRight.topRight()); + triangleRight.lineTo(rectRight.bottomRight()); + triangleRight.lineTo(rectRight.left(), rectRight.top() + (rectRight.height() / 2)); + triangleRight.lineTo(rectRight.topRight()); + + QBrush triangleBush = QBrush(QColor(200,200,200)); + + // ------------- Perform the tiling - for(int i=0;inewPage()) { @@ -811,12 +866,93 @@ void VPMainWindow::generateTiledPdf(QString fileName) } } - QRectF source = QRectF(j*tilesDrawingAreaWidth, i*tilesDrawingAreaHeight, tilesDrawingAreaWidth, tilesDrawingAreaHeight); - QRectF target = QRectF(m_layout->GetTilesMargins().left(), m_layout->GetTilesMargins().top(), - source.width(), source.height()); + // add the tiles decorations (cutting and gluing lines, scissors, infos etc.) + penTileInfos.setStyle(Qt::DashLine); + painter.setPen(penTileInfos); - // TODO: add the lines etc + if(row > 0) + { + // add top triangle + painter.fillPath(triangleTop, triangleBush); + // scissors along the top line + svgRenderer->load(QStringLiteral("://puzzleicon/svg/icon_scissors_horizontal.svg")); + svgRenderer->render(&painter, QRectF(tilesMargins.left()+tilesDrawingAreaWidth, + tilesMargins.top(), + UnitConvertor(1, Unit::Cm, Unit::Px), + UnitConvertor(0.56, Unit::Cm, Unit::Px) + )); + + // top line + painter.drawLine(QPointF(tilesMargins.left(), + tilesMargins.top()), + QPointF(tilesMargins.left() + tilesDrawingAreaWidth + UnitConvertor(1, Unit::Cm, Unit::Px), + tilesMargins.top()) + ); + } + if(col > 0) + { + // add left triangle + painter.fillPath(triangleLeft, triangleBush); + + // scissors along the left line + svgRenderer->load(QStringLiteral("://puzzleicon/svg/icon_scissors_vertical.svg")); + svgRenderer->render(&painter, QRectF(tilesMargins.left(), + tilesMargins.top()+tilesDrawingAreaHeight, + UnitConvertor(0.56, Unit::Cm, Unit::Px), + UnitConvertor(1, Unit::Cm, Unit::Px) + )); + + // left line + painter.drawLine(QPointF(tilesMargins.left(), + tilesMargins.top()), + QPointF(tilesMargins.left(), + tilesMargins.top() + tilesDrawingAreaHeight + UnitConvertor(1, Unit::Cm, Unit::Px)) + ); + } + + penTileInfos.setStyle(Qt::DotLine); + painter.setPen(penTileInfos); + + if(row < nbRow-1) + { + // add bottom triangle + painter.fillPath(triangleBottom, triangleBush); + + // bottom line + painter.drawLine(QPointF(tilesMargins.left(), + tilesMargins.top() + tilesDrawingAreaHeight), + QPointF(tilesMargins.left() + tilesDrawingAreaWidth + UnitConvertor(1, Unit::Cm, Unit::Px), + tilesMargins.top() + tilesDrawingAreaHeight) + ); + } + + if(col < nbCol-1) + { + // add right triangle + painter.fillPath(triangleRight, triangleBush); + + // right line + painter.drawLine(QPointF(tilesMargins.left() + tilesDrawingAreaWidth, + tilesMargins.top()), + QPointF(tilesMargins.left() + tilesDrawingAreaWidth, + tilesMargins.top()+ tilesDrawingAreaHeight + UnitConvertor(1, Unit::Cm, Unit::Px)) + ); + } + + // paint the page + QRectF source = QRectF(col*tilesDrawingAreaWidth, + row*tilesDrawingAreaHeight, + tilesDrawingAreaWidth + UnitConvertor(1, Unit::Cm, Unit::Px), + tilesDrawingAreaHeight + UnitConvertor(1, Unit::Cm, Unit::Px) + ); + QRectF target = QRectF(tilesMargins.left(), + tilesMargins.top(), + source.width(), + source.height() + ); + + painter.setPen(penTileDrawing); m_graphicsView->GetScene()->render(&painter, target, source, Qt::IgnoreAspectRatio); } } From 97351b58ddb52f1b951cc0bcbd1575842f511168 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Mon, 16 Nov 2020 20:22:38 +0100 Subject: [PATCH 19/34] Add text infos to the tiles --- .../svg/icon_scissors_horizontal.svg | 12 +++--- .../puzzleicon/svg/icon_scissors_vertical.svg | 2 +- src/app/puzzle/vpmainwindow.cpp | 38 +++++++++++++++++++ 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors_horizontal.svg b/src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors_horizontal.svg index 03d29b139..c6ed9f159 100644 --- a/src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors_horizontal.svg +++ b/src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors_horizontal.svg @@ -34,16 +34,16 @@ guidetolerance="10" inkscape:pageopacity="0" inkscape:pageshadow="2" - inkscape:window-width="1845" - inkscape:window-height="1016" + inkscape:window-width="1510" + inkscape:window-height="773" id="namedview9" showgrid="false" inkscape:zoom="4" inkscape:cx="-13.069473" inkscape:cy="57.804097" - inkscape:window-x="75" - inkscape:window-y="27" - inkscape:window-maximized="1" + inkscape:window-x="285" + inkscape:window-y="105" + inkscape:window-maximized="0" inkscape:current-layer="g4593" inkscape:document-rotation="0" units="mm" /> @@ -70,7 +70,7 @@ diff --git a/src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors_vertical.svg b/src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors_vertical.svg index c88794863..8bc4994e4 100644 --- a/src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors_vertical.svg +++ b/src/app/puzzle/share/resources/puzzleicon/svg/icon_scissors_vertical.svg @@ -70,7 +70,7 @@ diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 6efa30b7e..07cef248a 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -954,6 +954,44 @@ void VPMainWindow::generateTiledPdf(QString fileName) painter.setPen(penTileDrawing); m_graphicsView->GetScene()->render(&painter, target, source, Qt::IgnoreAspectRatio); + + QTextDocument td; + + td.documentLayout()->setPaintDevice(printer); + td.setPageSize(QSizeF(tilesDrawingAreaWidth - UnitConvertor(2, Unit::Cm, Unit::Px), tilesDrawingAreaHeight)); + + + const QString grid = tr("Grid ( %1 , %2 )").arg(row+1).arg(col+1); + const QString page = tr("Page %1 of %2").arg(row*nbCol+col+1).arg(nbCol*nbRow); + + td.setHtml(QString("" + "" + "" + "" + "
%1
") + .arg(grid)); + painter.setPen(penTileInfos); + painter.save(); + painter.translate(QPointF(tilesMargins.left()+ UnitConvertor(1, Unit::Cm, Unit::Px), + tilesDrawingAreaHeight + tilesMargins.top() + )); + td.drawContents(&painter); + painter.restore(); + + td.setPageSize(QSizeF(tilesDrawingAreaHeight - UnitConvertor(2, Unit::Cm, Unit::Px), tilesDrawingAreaWidth)); + td.setHtml(QString("" + "" + "" + "" + "
%1 - %2
") + .arg(page).arg(m_layout->GetFocusedSheet()->GetName())); + painter.save(); + painter.rotate(-90); + painter.translate(QPointF(-(tilesDrawingAreaHeight+tilesMargins.top()) + UnitConvertor(1, Unit::Cm, Unit::Px), + tilesDrawingAreaWidth + tilesMargins.left() + )); + td.drawContents(&painter); + painter.restore(); } } From 9f8f0e83410919296654adbea916d3308d6a77eb Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Thu, 19 Nov 2020 14:33:27 +0100 Subject: [PATCH 20/34] refactoring vpgraphicstilegrid and vptilefactory --- src/app/puzzle/puzzle.pri | 4 + src/app/puzzle/vpgraphicssheet.cpp | 60 ----- src/app/puzzle/vpgraphicstilegrid.cpp | 78 ++++++ src/app/puzzle/vpgraphicstilegrid.h | 57 +++++ src/app/puzzle/vpmaingraphicsview.cpp | 8 +- src/app/puzzle/vpmaingraphicsview.h | 10 +- src/app/puzzle/vpmainwindow.cpp | 255 ++------------------ src/app/puzzle/vpmainwindow.h | 3 + src/app/puzzle/vptilefactory.cpp | 330 ++++++++++++++++++++++++++ src/app/puzzle/vptilefactory.h | 121 ++++++++++ 10 files changed, 632 insertions(+), 294 deletions(-) create mode 100644 src/app/puzzle/vpgraphicstilegrid.cpp create mode 100644 src/app/puzzle/vpgraphicstilegrid.h create mode 100644 src/app/puzzle/vptilefactory.cpp create mode 100644 src/app/puzzle/vptilefactory.h diff --git a/src/app/puzzle/puzzle.pri b/src/app/puzzle/puzzle.pri index 5c90f52f5..c0915d854 100644 --- a/src/app/puzzle/puzzle.pri +++ b/src/app/puzzle/puzzle.pri @@ -12,6 +12,7 @@ SOURCES += \ $$PWD/vpcommands.cpp \ $$PWD/vpgraphicspiece.cpp \ $$PWD/vpgraphicssheet.cpp \ + $$PWD/vpgraphicstilegrid.cpp \ $$PWD/vplayout.cpp \ $$PWD/vpmaingraphicsview.cpp \ $$PWD/vpmainwindow.cpp \ @@ -20,6 +21,7 @@ SOURCES += \ $$PWD/vppiecelist.cpp \ $$PWD/vpsettings.cpp \ $$PWD/vpsheet.cpp \ + $$PWD/vptilefactory.cpp \ $$PWD/xml/vplayoutfilereader.cpp \ $$PWD/xml/vplayoutfilewriter.cpp \ $$PWD/xml/vplayoutliterals.cpp @@ -36,6 +38,7 @@ HEADERS += \ $$PWD/vpcommands.h \ $$PWD/vpgraphicspiece.h \ $$PWD/vpgraphicssheet.h \ + $$PWD/vpgraphicstilegrid.h \ $$PWD/vplayout.h \ $$PWD/vpmaingraphicsview.h \ $$PWD/vpmainwindow.h \ @@ -45,6 +48,7 @@ HEADERS += \ $$PWD/vpsettings.h \ $$PWD/vpsheet.h \ $$PWD/vpstable.h \ + $$PWD/vptilefactory.h \ $$PWD/xml/vplayoutfilereader.h \ $$PWD/xml/vplayoutfilewriter.h \ $$PWD/xml/vplayoutliterals.h diff --git a/src/app/puzzle/vpgraphicssheet.cpp b/src/app/puzzle/vpgraphicssheet.cpp index e07037c56..5c9638faf 100644 --- a/src/app/puzzle/vpgraphicssheet.cpp +++ b/src/app/puzzle/vpgraphicssheet.cpp @@ -70,66 +70,6 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o painter->drawRect(GetSheetRect()); } - // show the tiles grid. Maybe it shouldn't be in the graphics sheet, maybe better in maingraphicsview - VPLayout* layout = m_sheet->GetLayout(); - if(layout->GetShowTiles()) - { - pen.setColor(QColor(255,0,0,127)); - pen.setStyle(Qt::DashLine); - painter->setPen(pen); - - QSizeF tilesSize = layout->GetTilesSize(); - QSizeF sheetSize = m_sheet->GetSheetSize(); - - QMarginsF tilesMargins = layout->GetTilesMargins(); - - PageOrientation tilesOrientation = layout->GetTilesOrientation(); - PageOrientation sheetOrientation = m_sheet->GetOrientation(); - - qreal colWidth = 0; - qreal rowHeight = 0; - if(tilesOrientation == PageOrientation::Portrait) - { - colWidth = tilesSize.width() - (tilesMargins.left()+ tilesMargins.right() + UnitConvertor(1, Unit::Cm, Unit::Px)); - rowHeight = tilesSize.height() - (tilesMargins.top()+ tilesMargins.bottom() + UnitConvertor(1, Unit::Cm, Unit::Px)); - } - else - { - colWidth = tilesSize.height() - (tilesMargins.left()+ tilesMargins.right() + UnitConvertor(1, Unit::Cm, Unit::Px)); - rowHeight = tilesSize.width() - (tilesMargins.top()+ tilesMargins.bottom() + UnitConvertor(1, Unit::Cm, Unit::Px)); - } - // the "+ UnitConvertor(1, Unit::Cm, Unit::Px)" is because of the part for gluing and where we - // have infos of the single tile. Maybe it's not the right value, to be corrected. - - - qreal drawingWidth = 0; - qreal drawingHeight = 0; - - if(sheetOrientation == PageOrientation::Portrait) - { - drawingWidth = sheetSize.width(); - drawingHeight = sheetSize.height(); - } - else - { - drawingWidth = sheetSize.height(); - drawingHeight = sheetSize.width(); - } - - int nbCol = qCeil(drawingWidth/colWidth); - int nbRow = qCeil(drawingHeight/rowHeight); - - for(int i=0;i<=nbCol;i++) - { - painter->drawLine(QPointF(i*colWidth, 0), QPointF(i*colWidth,nbRow*rowHeight)); - } - - for(int j=0;j<=nbRow;j++) - { - painter->drawLine(QPointF(0, j*rowHeight), QPointF(nbCol*colWidth, j*rowHeight)); - } - } - m_boundingRect = GetSheetRect(); } diff --git a/src/app/puzzle/vpgraphicstilegrid.cpp b/src/app/puzzle/vpgraphicstilegrid.cpp new file mode 100644 index 000000000..45e905bd9 --- /dev/null +++ b/src/app/puzzle/vpgraphicstilegrid.cpp @@ -0,0 +1,78 @@ +#include "vpgraphicstilegrid.h" + +#include "vptilefactory.h" +#include "vplayout.h" + +//--------------------------------------------------------------------------------------------------------------------- +VPGraphicsTileGrid::VPGraphicsTileGrid(VPLayout *layout, VPTileFactory *tileFactory,QGraphicsItem *parent): + QGraphicsItem(parent), + m_tileFactory(tileFactory), + m_layout(layout) +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +VPGraphicsTileGrid::~VPGraphicsTileGrid() +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VPGraphicsTileGrid::boundingRect() const +{ + if(m_layout->GetShowTiles()) + { + return QRectF(0, + 0, + m_tileFactory->getColNb()* m_tileFactory->getDrawingAreaWidth(), + m_tileFactory->getRowNb()* m_tileFactory->getDrawingAreaHeight() + ); + } + else + { + return QRectF(0,0,0,0); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPGraphicsTileGrid::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(widget); + Q_UNUSED(option); + + if(m_layout->GetShowTiles()) + { + QPen pen(QColor(255,0,0,127), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + pen.setCosmetic(true); + pen.setStyle(Qt::DashLine); + QBrush noBrush(Qt::NoBrush); + painter->setPen(pen); + painter->setBrush(noBrush); + + for(int i=0;i<=m_tileFactory->getColNb();i++) + { + painter->drawLine(QPointF( + i*m_tileFactory->getDrawingAreaWidth(), + 0), + QPointF( + i*m_tileFactory->getDrawingAreaWidth(), + m_tileFactory->getRowNb()*m_tileFactory->getDrawingAreaHeight() + ) + ); + } + + for(int j=0;j<=m_tileFactory->getRowNb();j++) + { + painter->drawLine(QPointF( + 0, + j*m_tileFactory->getDrawingAreaHeight() + ), + QPointF( + m_tileFactory->getColNb()*m_tileFactory->getDrawingAreaWidth(), + j*m_tileFactory->getDrawingAreaHeight() + ) + ); + } + } +} diff --git a/src/app/puzzle/vpgraphicstilegrid.h b/src/app/puzzle/vpgraphicstilegrid.h new file mode 100644 index 000000000..9559f3e55 --- /dev/null +++ b/src/app/puzzle/vpgraphicstilegrid.h @@ -0,0 +1,57 @@ +/************************************************************************ + ** + ** @file vpgraphicstilegrid.h + ** @author Ronan Le Tiec + ** @date 19 11, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VPGRAPHICSTILEGRID_H +#define VPGRAPHICSTILEGRID_H + +#include +#include + +#include "../vmisc/def.h" + +class VPTileFactory; +class VPLayout; + +class VPGraphicsTileGrid : public QGraphicsItem +{ +public: + explicit VPGraphicsTileGrid(VPLayout* layout, VPTileFactory *tileFactory, QGraphicsItem *parent = nullptr); + ~VPGraphicsTileGrid(); + + QRectF boundingRect() const override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; + + +private: + Q_DISABLE_COPY(VPGraphicsTileGrid) + + VPTileFactory *m_tileFactory{nullptr}; + VPLayout *m_layout{nullptr}; +}; + +#endif // VPGRAPHICSTILEGRID_H diff --git a/src/app/puzzle/vpmaingraphicsview.cpp b/src/app/puzzle/vpmaingraphicsview.cpp index 6e63b4643..d7241a72c 100644 --- a/src/app/puzzle/vpmaingraphicsview.cpp +++ b/src/app/puzzle/vpmaingraphicsview.cpp @@ -37,6 +37,7 @@ #include "vplayout.h" #include "vpsheet.h" #include "../vwidgets/vmaingraphicsscene.h" +#include "vptilefactory.h" #include @@ -44,7 +45,7 @@ Q_LOGGING_CATEGORY(pMainGraphicsView, "p.mainGraphicsView") //--------------------------------------------------------------------------------------------------------------------- -VPMainGraphicsView::VPMainGraphicsView(VPLayout *layout, QWidget *parent) : +VPMainGraphicsView::VPMainGraphicsView(VPLayout *layout, VPTileFactory *tileFactory, QWidget *parent) : VMainGraphicsView(parent), m_layout(layout) { @@ -58,6 +59,9 @@ VPMainGraphicsView::VPMainGraphicsView(VPLayout *layout, QWidget *parent) : setAcceptDrops(true); + m_graphicsTileGrid = new VPGraphicsTileGrid(layout, tileFactory); + m_scene->addItem(m_graphicsTileGrid); + // add the connections connect(m_layout, &VPLayout::PieceMovedToPieceList, this, &VPMainGraphicsView::on_PieceMovedToPieceList); connect(m_scene, &VMainGraphicsScene::selectionChanged, this, @@ -71,6 +75,8 @@ void VPMainGraphicsView::RefreshLayout() m_graphicsSheet->update(); + m_graphicsTileGrid->update(); + m_scene->update(); } diff --git a/src/app/puzzle/vpmaingraphicsview.h b/src/app/puzzle/vpmaingraphicsview.h index 5641bf2d2..b1c84bc90 100644 --- a/src/app/puzzle/vpmaingraphicsview.h +++ b/src/app/puzzle/vpmaingraphicsview.h @@ -31,16 +31,19 @@ #include "vpgraphicssheet.h" #include "vpgraphicspiece.h" +#include "vptilefactory.h" +#include "vpgraphicstilegrid.h" #include "../vwidgets/vmaingraphicsview.h" class VMainGraphicsScene; +class VPTileFactory; class VPMainGraphicsView : public VMainGraphicsView { Q_OBJECT public: - VPMainGraphicsView(VPLayout *layout, QWidget *parent); + VPMainGraphicsView(VPLayout *layout, VPTileFactory *tileFactory, QWidget *parent); ~VPMainGraphicsView() = default; /** @@ -74,6 +77,8 @@ protected: void keyPressEvent(QKeyEvent *event) override; + void drawTilesLine(); + private slots: /** * @brief on_PieceMovedToPieceList The slot is called when the given piece was moved from the given piece list to the other @@ -95,6 +100,9 @@ private: VMainGraphicsScene *m_scene{nullptr}; VPGraphicsSheet *m_graphicsSheet{nullptr}; + + VPGraphicsTileGrid *m_graphicsTileGrid{nullptr}; + VPLayout *m_layout{nullptr}; QList m_graphicsPieces{}; diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 07cef248a..a1983ed7d 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "ui_vpmainwindow.h" #include "dialogs/vpdialogabout.h" @@ -45,7 +46,6 @@ #include "vpsheet.h" #include -#include QT_WARNING_PUSH QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes") @@ -91,6 +91,11 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : InitMenuBar(); InitProperties(); InitCarrousel(); + + // init the tile factory + m_tileFactory = new VPTileFactory(m_layout, qApp->Settings()); + m_tileFactory->refreshTileInfos(); + InitMainGraphics(); InitZoomToolBar(); @@ -98,6 +103,8 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : SetPropertiesData(); ReadSettings(); + + } //--------------------------------------------------------------------------------------------------------------------- @@ -525,7 +532,7 @@ void VPMainWindow::SetPropertyTabLayoutData() //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::InitMainGraphics() { - m_graphicsView = new VPMainGraphicsView(m_layout, this); + m_graphicsView = new VPMainGraphicsView(m_layout, m_tileFactory, this); ui->centralWidget->layout()->addWidget(m_graphicsView); m_graphicsView->RefreshLayout(); @@ -708,10 +715,9 @@ void VPMainWindow::generateTiledPdf(QString fileName) if(not fileName.isEmpty()) { m_graphicsView->PrepareForExport(); + m_tileFactory->refreshTileInfos(); PageOrientation tilesOrientation = m_layout->GetTilesOrientation(); - QSizeF tilesSize = m_layout->GetTilesSize(); - QMarginsF tilesMargins = m_layout->GetTilesMargins(); // ------------- Set up the printer QPrinter* printer = new QPrinter(); @@ -724,11 +730,6 @@ void VPMainWindow::generateTiledPdf(QString fileName) printer->setPageSize(QPageSize(m_layout->GetTilesSize(Unit::Mm), QPageSize::Millimeter)); printer->setFullPage(true); - const bool success = printer->setPageMargins(m_layout->GetTilesMargins(Unit::Mm), QPageLayout::Millimeter); - if (not success) - { - qWarning() << tr("Cannot set printer margins"); - } #ifdef Q_OS_MAC printer->setOutputFormat(QPrinter::NativeFormat); @@ -740,7 +741,6 @@ void VPMainWindow::generateTiledPdf(QString fileName) printer->setResolution(static_cast(PrintDPI)); printer->setDocName("Test"); // FIXME - // ------------- Set up the painter QPainter painter; if (not painter.begin(printer)) @@ -751,9 +751,6 @@ void VPMainWindow::generateTiledPdf(QString fileName) painter.setFont( QFont( QStringLiteral("Arial"), 8, QFont::Normal ) ); painter.setRenderHint(QPainter::Antialiasing, true); painter.setBrush ( QBrush ( Qt::NoBrush ) ); - QPen penTileInfos = QPen(QColor(180,180,180), qApp->Settings()->WidthHairLine(), Qt::DashLine, Qt::RoundCap, Qt::RoundJoin); - QPen penTileDrawing = QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); - if(tilesOrientation == PageOrientation::Landscape) { @@ -763,99 +760,9 @@ void VPMainWindow::generateTiledPdf(QString fileName) painter.translate(0, -ToPixel(printer->pageRect(QPrinter::Millimeter).width(), Unit::Mm)); } - - // ------------- Prepare infos for the tiling - qreal tilesDrawingAreaHeight = (tilesOrientation == PageOrientation::Portrait)? - tilesSize.height() : tilesSize.width(); - tilesDrawingAreaHeight -= - tilesMargins.top() + tilesMargins.bottom() + UnitConvertor(1, Unit::Cm, Unit::Px); - - // the -1cm is for test purpuses, it correspondings to the overlaping for gluing the parts, - // later we'll have a proper abstract value - - qreal tilesDrawingAreaWidth = (tilesOrientation == PageOrientation::Portrait)? - tilesSize.width() : tilesSize.height(); - tilesDrawingAreaWidth -= - tilesMargins.left() + tilesMargins.right() + UnitConvertor(1, Unit::Cm, Unit::Px); - - - QSizeF sheetSize = m_layout->GetFocusedSheet()->GetSheetSize(); - qreal drawingWidth = 0; - qreal drawingHeight = 0; - - if(m_layout->GetFocusedSheet()->GetOrientation() == PageOrientation::Portrait) + for(int row=0;rowgetRowNb();row++) // for each row of the tiling grid { - drawingWidth = sheetSize.width(); - drawingHeight = sheetSize.height(); - } - else - { - drawingWidth = sheetSize.height(); - drawingHeight = sheetSize.width(); - } - - int nbCol = qCeil(drawingWidth/tilesDrawingAreaWidth); - int nbRow = qCeil(drawingHeight/tilesDrawingAreaHeight); - - - // ------------- prepare triangles for positioning - // top triangle - QRectF rectTop = QRectF(tilesMargins.left()+ tilesDrawingAreaWidth/2 - UnitConvertor(0.5, Unit::Cm, Unit::Px), - tilesMargins.top(), - UnitConvertor(1, Unit::Cm, Unit::Px), - UnitConvertor(0.5, Unit::Cm, Unit::Px) - ); - QPainterPath triangleTop; - triangleTop.moveTo(rectTop.topLeft()); - triangleTop.lineTo(rectTop.topRight()); - triangleTop.lineTo(rectTop.left() + (rectTop.width() / 2), rectTop.bottom()); - triangleTop.lineTo(rectTop.topLeft()); - - // left triangle - QRectF rectLeft = QRectF(tilesMargins.left(), - tilesMargins.top() + tilesDrawingAreaHeight/2 - UnitConvertor(0.5, Unit::Cm, Unit::Px), - UnitConvertor(0.5, Unit::Cm, Unit::Px), - UnitConvertor(1, Unit::Cm, Unit::Px) - ); - QPainterPath triangleLeft; - triangleLeft.moveTo(rectLeft.topLeft()); - triangleLeft.lineTo(rectLeft.right(), rectLeft.top() + (rectLeft.height() / 2)); - triangleLeft.lineTo(rectLeft.bottomLeft()); - triangleLeft.lineTo(rectLeft.topLeft()); - - // bottom triangle - QRectF rectBottom = QRectF(tilesMargins.left()+ tilesDrawingAreaWidth/2 - UnitConvertor(0.5, Unit::Cm, Unit::Px), - tilesMargins.top()+tilesDrawingAreaHeight - UnitConvertor(0.5, Unit::Cm, Unit::Px), - UnitConvertor(1, Unit::Cm, Unit::Px), - UnitConvertor(0.5, Unit::Cm, Unit::Px) - ); - QPainterPath triangleBottom; - triangleBottom.moveTo(rectBottom.bottomLeft()); - triangleBottom.lineTo(rectBottom.left() + (rectBottom.width() / 2), rectBottom.top()); - triangleBottom.lineTo(rectBottom.bottomRight()); - triangleBottom.lineTo(rectBottom.bottomLeft()); - - // right triangle - QRectF rectRight = QRectF(tilesMargins.left() + tilesDrawingAreaWidth - UnitConvertor(0.5, Unit::Cm, Unit::Px), - tilesMargins.top() + tilesDrawingAreaHeight/2 - UnitConvertor(0.5, Unit::Cm, Unit::Px), - UnitConvertor(0.5, Unit::Cm, Unit::Px), - UnitConvertor(1, Unit::Cm, Unit::Px) - ); - QPainterPath triangleRight; - triangleRight.moveTo(rectRight.topRight()); - triangleRight.lineTo(rectRight.bottomRight()); - triangleRight.lineTo(rectRight.left(), rectRight.top() + (rectRight.height() / 2)); - triangleRight.lineTo(rectRight.topRight()); - - QBrush triangleBush = QBrush(QColor(200,200,200)); - - - // ------------- Perform the tiling - QSvgRenderer* svgRenderer = new QSvgRenderer(); - - for(int row=0;rowgetColNb();col++) // for each column of tiling grid { if(not (row == 0 && col == 0)) { @@ -866,132 +773,7 @@ void VPMainWindow::generateTiledPdf(QString fileName) } } - // add the tiles decorations (cutting and gluing lines, scissors, infos etc.) - penTileInfos.setStyle(Qt::DashLine); - painter.setPen(penTileInfos); - - if(row > 0) - { - // add top triangle - painter.fillPath(triangleTop, triangleBush); - - // scissors along the top line - svgRenderer->load(QStringLiteral("://puzzleicon/svg/icon_scissors_horizontal.svg")); - svgRenderer->render(&painter, QRectF(tilesMargins.left()+tilesDrawingAreaWidth, - tilesMargins.top(), - UnitConvertor(1, Unit::Cm, Unit::Px), - UnitConvertor(0.56, Unit::Cm, Unit::Px) - )); - - // top line - painter.drawLine(QPointF(tilesMargins.left(), - tilesMargins.top()), - QPointF(tilesMargins.left() + tilesDrawingAreaWidth + UnitConvertor(1, Unit::Cm, Unit::Px), - tilesMargins.top()) - ); - } - if(col > 0) - { - // add left triangle - painter.fillPath(triangleLeft, triangleBush); - - // scissors along the left line - svgRenderer->load(QStringLiteral("://puzzleicon/svg/icon_scissors_vertical.svg")); - svgRenderer->render(&painter, QRectF(tilesMargins.left(), - tilesMargins.top()+tilesDrawingAreaHeight, - UnitConvertor(0.56, Unit::Cm, Unit::Px), - UnitConvertor(1, Unit::Cm, Unit::Px) - )); - - // left line - painter.drawLine(QPointF(tilesMargins.left(), - tilesMargins.top()), - QPointF(tilesMargins.left(), - tilesMargins.top() + tilesDrawingAreaHeight + UnitConvertor(1, Unit::Cm, Unit::Px)) - ); - } - - penTileInfos.setStyle(Qt::DotLine); - painter.setPen(penTileInfos); - - if(row < nbRow-1) - { - // add bottom triangle - painter.fillPath(triangleBottom, triangleBush); - - // bottom line - painter.drawLine(QPointF(tilesMargins.left(), - tilesMargins.top() + tilesDrawingAreaHeight), - QPointF(tilesMargins.left() + tilesDrawingAreaWidth + UnitConvertor(1, Unit::Cm, Unit::Px), - tilesMargins.top() + tilesDrawingAreaHeight) - ); - } - - if(col < nbCol-1) - { - // add right triangle - painter.fillPath(triangleRight, triangleBush); - - // right line - painter.drawLine(QPointF(tilesMargins.left() + tilesDrawingAreaWidth, - tilesMargins.top()), - QPointF(tilesMargins.left() + tilesDrawingAreaWidth, - tilesMargins.top()+ tilesDrawingAreaHeight + UnitConvertor(1, Unit::Cm, Unit::Px)) - ); - } - - // paint the page - QRectF source = QRectF(col*tilesDrawingAreaWidth, - row*tilesDrawingAreaHeight, - tilesDrawingAreaWidth + UnitConvertor(1, Unit::Cm, Unit::Px), - tilesDrawingAreaHeight + UnitConvertor(1, Unit::Cm, Unit::Px) - ); - QRectF target = QRectF(tilesMargins.left(), - tilesMargins.top(), - source.width(), - source.height() - ); - - painter.setPen(penTileDrawing); - m_graphicsView->GetScene()->render(&painter, target, source, Qt::IgnoreAspectRatio); - - QTextDocument td; - - td.documentLayout()->setPaintDevice(printer); - td.setPageSize(QSizeF(tilesDrawingAreaWidth - UnitConvertor(2, Unit::Cm, Unit::Px), tilesDrawingAreaHeight)); - - - const QString grid = tr("Grid ( %1 , %2 )").arg(row+1).arg(col+1); - const QString page = tr("Page %1 of %2").arg(row*nbCol+col+1).arg(nbCol*nbRow); - - td.setHtml(QString("" - "" - "" - "" - "
%1
") - .arg(grid)); - painter.setPen(penTileInfos); - painter.save(); - painter.translate(QPointF(tilesMargins.left()+ UnitConvertor(1, Unit::Cm, Unit::Px), - tilesDrawingAreaHeight + tilesMargins.top() - )); - td.drawContents(&painter); - painter.restore(); - - td.setPageSize(QSizeF(tilesDrawingAreaHeight - UnitConvertor(2, Unit::Cm, Unit::Px), tilesDrawingAreaWidth)); - td.setHtml(QString("" - "" - "" - "" - "
%1 - %2
") - .arg(page).arg(m_layout->GetFocusedSheet()->GetName())); - painter.save(); - painter.rotate(-90); - painter.translate(QPointF(-(tilesDrawingAreaHeight+tilesMargins.top()) + UnitConvertor(1, Unit::Cm, Unit::Px), - tilesDrawingAreaWidth + tilesMargins.left() - )); - td.drawContents(&painter); - painter.restore(); + m_tileFactory->drawTile(&painter, m_graphicsView, row, col); } } @@ -1237,7 +1019,12 @@ void VPMainWindow::on_comboBoxSheetTemplate_currentIndexChanged(int index) //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_SheetSizeChanged() { - m_layout->GetFocusedSheet()->SetSheetSizeConverted(ui->doubleSpinBoxSheetWidth->value(), ui->doubleSpinBoxSheetLength->value()); + m_layout->GetFocusedSheet()->SetSheetSizeConverted( + ui->doubleSpinBoxSheetWidth->value(), + ui->doubleSpinBoxSheetLength->value() + ); + + m_tileFactory->refreshTileInfos(); // TODO Undo / Redo @@ -1256,6 +1043,7 @@ void VPMainWindow::on_SheetOrientationChanged() { m_layout->GetFocusedSheet()->SetOrientation(PageOrientation::Landscape); } + m_tileFactory->refreshTileInfos(); // TODO Undo / Redo @@ -1296,6 +1084,7 @@ void VPMainWindow::on_SheetMarginChanged() void VPMainWindow::on_TilesSizeChanged() { m_layout->SetTilesSizeConverted(ui->doubleSpinBoxTilesWidth->value(), ui->doubleSpinBoxTilesLength->value()); + m_tileFactory->refreshTileInfos(); // TODO Undo / Redo @@ -1314,6 +1103,7 @@ void VPMainWindow::on_TilesOrientationChanged() { m_layout->SetTilesOrientation(PageOrientation::Landscape); } + m_tileFactory->refreshTileInfos(); // TODO Undo / Redo @@ -1329,6 +1119,7 @@ void VPMainWindow::on_TilesMarginChanged() ui->doubleSpinBoxTilesMarginRight->value(), ui->doubleSpinBoxTilesMarginBottom->value() ); + m_tileFactory->refreshTileInfos(); // TODO Undo / Redo diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index e11a28956..462e8a8bf 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -39,6 +39,7 @@ #include "vplayout.h" #include "vppiece.h" #include "../vlayout/vlayoutpiece.h" +#include "vptilefactory.h" #include "vpcommandline.h" #include "../vlayout/vlayoutdef.h" @@ -105,6 +106,8 @@ private: VPLayout *m_layout{nullptr}; QListm_selectedPieces{QList()}; + VPTileFactory *m_tileFactory{nullptr}; + /** * @brief spin box with the scale factor of the graphic view */ diff --git a/src/app/puzzle/vptilefactory.cpp b/src/app/puzzle/vptilefactory.cpp new file mode 100644 index 000000000..a7606b1b4 --- /dev/null +++ b/src/app/puzzle/vptilefactory.cpp @@ -0,0 +1,330 @@ +#include "vptilefactory.h" + +#include + +#include "../vwidgets/vmaingraphicsscene.h" +#include "vpsheet.h" +#include "vpmaingraphicsview.h" + + +//--------------------------------------------------------------------------------------------------------------------- +VPTileFactory::VPTileFactory(VPLayout *layout, VCommonSettings *commonSettings): + m_layout(layout), + m_commonSettings(commonSettings) +{ + m_infoStripeWidth = UnitConvertor(1, Unit::Cm, Unit::Px); +} + +//--------------------------------------------------------------------------------------------------------------------- +VPTileFactory::~VPTileFactory() +{ + +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPTileFactory::refreshTileInfos() +{ + PageOrientation tilesOrientation = m_layout->GetTilesOrientation(); + QSizeF tilesSize = m_layout->GetTilesSize(); + QMarginsF tilesMargins = m_layout->GetTilesMargins(); + + // sets the drawing height + m_drawingAreaHeight = (tilesOrientation == PageOrientation::Portrait)? + tilesSize.height() : tilesSize.width(); + m_drawingAreaHeight -= + tilesMargins.top() + tilesMargins.bottom() + m_infoStripeWidth; + + // sets the drawing width + m_drawingAreaWidth = (tilesOrientation == PageOrientation::Portrait)? + tilesSize.width() : tilesSize.height(); + m_drawingAreaWidth -= + tilesMargins.left() + tilesMargins.right() + m_infoStripeWidth; + + + QSizeF sheetSize = m_layout->GetFocusedSheet()->GetSheetSize(); + qreal totalDrawingWidth = 0; + qreal totaldrawingHeight = 0; + + if(m_layout->GetFocusedSheet()->GetOrientation() == PageOrientation::Portrait) + { + totalDrawingWidth = sheetSize.width(); + totaldrawingHeight = sheetSize.height(); + } + else + { + totalDrawingWidth = sheetSize.height(); + totaldrawingHeight = sheetSize.width(); + } + + m_nbCol = qCeil(totalDrawingWidth/m_drawingAreaWidth); + m_nbRow = qCeil(totaldrawingHeight/m_drawingAreaHeight); +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPTileFactory::drawTile(QPainter *painter, VPMainGraphicsView *graphicsView, int row, int col) +{ + QMarginsF tilesMargins = m_layout->GetTilesMargins(); + QPen penTileInfos = QPen(QColor(180,180,180), m_commonSettings->WidthHairLine(), Qt::DashLine, Qt::RoundCap, Qt::RoundJoin); + QPen penTileDrawing = QPen(Qt::black, m_commonSettings->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + + QSvgRenderer* svgRenderer = new QSvgRenderer(); + + + // ------------- prepare triangles for positioning + + // top triangle + QRectF rectTop = QRectF(tilesMargins.left()+ m_drawingAreaWidth/2 - UnitConvertor(0.5, Unit::Cm, Unit::Px), + tilesMargins.top(), + UnitConvertor(1, Unit::Cm, Unit::Px), + UnitConvertor(0.5, Unit::Cm, Unit::Px) + ); + QPainterPath triangleTop; + triangleTop.moveTo(rectTop.topLeft()); + triangleTop.lineTo(rectTop.topRight()); + triangleTop.lineTo(rectTop.left() + (rectTop.width() / 2), rectTop.bottom()); + triangleTop.lineTo(rectTop.topLeft()); + + // left triangle + QRectF rectLeft = QRectF(tilesMargins.left(), + tilesMargins.top() + m_drawingAreaHeight/2 - UnitConvertor(0.5, Unit::Cm, Unit::Px), + UnitConvertor(0.5, Unit::Cm, Unit::Px), + UnitConvertor(1, Unit::Cm, Unit::Px) + ); + QPainterPath triangleLeft; + triangleLeft.moveTo(rectLeft.topLeft()); + triangleLeft.lineTo(rectLeft.right(), rectLeft.top() + (rectLeft.height() / 2)); + triangleLeft.lineTo(rectLeft.bottomLeft()); + triangleLeft.lineTo(rectLeft.topLeft()); + + // bottom triangle + QRectF rectBottom = QRectF(tilesMargins.left()+ m_drawingAreaWidth/2 - UnitConvertor(0.5, Unit::Cm, Unit::Px), + tilesMargins.top()+m_drawingAreaHeight - UnitConvertor(0.5, Unit::Cm, Unit::Px), + UnitConvertor(1, Unit::Cm, Unit::Px), + UnitConvertor(0.5, Unit::Cm, Unit::Px) + ); + QPainterPath triangleBottom; + triangleBottom.moveTo(rectBottom.bottomLeft()); + triangleBottom.lineTo(rectBottom.left() + (rectBottom.width() / 2), rectBottom.top()); + triangleBottom.lineTo(rectBottom.bottomRight()); + triangleBottom.lineTo(rectBottom.bottomLeft()); + + // right triangle + QRectF rectRight = QRectF(tilesMargins.left() + m_drawingAreaWidth - UnitConvertor(0.5, Unit::Cm, Unit::Px), + tilesMargins.top() + m_drawingAreaHeight/2 - UnitConvertor(0.5, Unit::Cm, Unit::Px), + UnitConvertor(0.5, Unit::Cm, Unit::Px), + UnitConvertor(1, Unit::Cm, Unit::Px) + ); + QPainterPath triangleRight; + triangleRight.moveTo(rectRight.topRight()); + triangleRight.lineTo(rectRight.bottomRight()); + triangleRight.lineTo(rectRight.left(), rectRight.top() + (rectRight.height() / 2)); + triangleRight.lineTo(rectRight.topRight()); + + QBrush triangleBush = QBrush(QColor(200,200,200)); + + // add the tiles decorations (cutting and gluing lines, scissors, infos etc.) + painter->setPen(penTileInfos); + + if(row > 0) + { + // add top triangle + painter->fillPath(triangleTop, triangleBush); + + // scissors along the top line + svgRenderer->load(QStringLiteral("://puzzleicon/svg/icon_scissors_horizontal.svg")); + svgRenderer->render(painter, QRectF(tilesMargins.left() + m_drawingAreaWidth, + tilesMargins.top(), + UnitConvertor(1, Unit::Cm, Unit::Px), + UnitConvertor(0.56, Unit::Cm, Unit::Px) + )); + + // dashed top line (for cutting) + penTileInfos.setStyle(Qt::DashLine); + painter->setPen(penTileInfos); + painter->drawLine(QPointF(tilesMargins.left(), + tilesMargins.top()), + QPointF(tilesMargins.left() + m_drawingAreaWidth + m_infoStripeWidth, + tilesMargins.top()) + ); + } + else + { + // solid top line stopping at the edge + penTileInfos.setStyle(Qt::SolidLine); + painter->setPen(penTileInfos); + painter->drawLine(QPointF(tilesMargins.left(), + tilesMargins.top()), + QPointF(tilesMargins.left() + m_drawingAreaWidth + ((col < m_nbCol-1)? m_infoStripeWidth : 0), + tilesMargins.top()) + ); + } + + if(col > 0) + { + // add left triangle + painter->fillPath(triangleLeft, triangleBush); + + // scissors along the left line + svgRenderer->load(QStringLiteral("://puzzleicon/svg/icon_scissors_vertical.svg")); + svgRenderer->render(painter, QRectF(tilesMargins.left(), + tilesMargins.top()+m_drawingAreaHeight, + UnitConvertor(0.56, Unit::Cm, Unit::Px), + UnitConvertor(1, Unit::Cm, Unit::Px) + )); + + // dashed left line (for cutting) + penTileInfos.setStyle(Qt::DashLine); + painter->setPen(penTileInfos); + painter->drawLine(QPointF(tilesMargins.left(), + tilesMargins.top()), + QPointF(tilesMargins.left(), + tilesMargins.top() + m_drawingAreaHeight + m_infoStripeWidth) + ); + } + else + { + // solid left line at the edge + penTileInfos.setStyle(Qt::SolidLine); + painter->setPen(penTileInfos); + painter->drawLine(QPointF(tilesMargins.left(), + tilesMargins.top()), + QPointF(tilesMargins.left(), + tilesMargins.top() + m_drawingAreaHeight + ((row < m_nbRow-1)? m_infoStripeWidth : 0)) + ); + } + + if(row < m_nbRow-1) + { + // add bottom triangle + painter->fillPath(triangleBottom, triangleBush); + + // dotted bottom line (for glueing) + penTileInfos.setStyle(Qt::DotLine); + painter->setPen(penTileInfos); + painter->drawLine(QPointF(tilesMargins.left(), + tilesMargins.top() + m_drawingAreaHeight), + QPointF(tilesMargins.left() + m_drawingAreaWidth + m_infoStripeWidth, + tilesMargins.top() + m_drawingAreaHeight) + ); + } else + { + // solid bottom line at the edge + penTileInfos.setStyle(Qt::SolidLine); + painter->setPen(penTileInfos); + painter->drawLine(QPointF(tilesMargins.left(), + tilesMargins.top() + m_drawingAreaHeight), + QPointF(tilesMargins.left() + m_drawingAreaWidth + ((col < m_nbCol-1)? m_infoStripeWidth : 0), + tilesMargins.top() + m_drawingAreaHeight) + ); + } + + if(col < m_nbCol-1) + { + // add right triangle + painter->fillPath(triangleRight, triangleBush); + + // dotted right line (for glueing) + penTileInfos.setStyle(Qt::DotLine); + painter->setPen(penTileInfos); + painter->drawLine(QPointF(tilesMargins.left() + m_drawingAreaWidth, + tilesMargins.top()), + QPointF(tilesMargins.left() + m_drawingAreaWidth, + tilesMargins.top()+ m_drawingAreaHeight + m_infoStripeWidth) + ); + } + else + { + // solid right line at the edge + penTileInfos.setStyle(Qt::SolidLine); + painter->setPen(penTileInfos); + painter->drawLine(QPointF(tilesMargins.left() + m_drawingAreaWidth, + tilesMargins.top()), + QPointF(tilesMargins.left() + m_drawingAreaWidth, + tilesMargins.top()+ m_drawingAreaHeight + ((row < m_nbRow-1) ? m_infoStripeWidth : 0)) + ); + } + + // paint the content of the page + QRectF source = QRectF(col*m_drawingAreaWidth, + row*m_drawingAreaHeight, + m_drawingAreaWidth + m_infoStripeWidth, + m_drawingAreaHeight + m_infoStripeWidth + ); + QRectF target = QRectF(tilesMargins.left(), + tilesMargins.top(), + source.width(), + source.height() + ); + + painter->setPen(penTileDrawing); + graphicsView->GetScene()->render(painter, target, source, Qt::IgnoreAspectRatio); + + // prepare the painting for the text information + QTextDocument td; + +// td.documentLayout()->setPaintDevice(printer); ?? + + td.setPageSize(QSizeF(m_drawingAreaWidth - UnitConvertor(2, Unit::Cm, Unit::Px), m_drawingAreaHeight)); + + // paint the grid information + const QString grid = tr("Grid ( %1 , %2 )").arg(row+1).arg(col+1); + + td.setHtml(QString("" + "" + "" + "" + "
%1
") + .arg(grid)); + painter->setPen(penTileInfos); + painter->save(); + painter->translate(QPointF(tilesMargins.left()+ UnitConvertor(1, Unit::Cm, Unit::Px), + m_drawingAreaHeight + tilesMargins.top() + )); + td.drawContents(painter); + painter->restore(); + + // paint the page information + const QString page = tr("Page %1 of %2").arg(row*m_nbCol+col+1).arg(m_nbCol*m_nbRow); + + td.setPageSize(QSizeF(m_drawingAreaHeight - UnitConvertor(2, Unit::Cm, Unit::Px), m_drawingAreaWidth)); + td.setHtml(QString("" + "" + "" + "" + "
%1 - %2
") + .arg(page).arg(m_layout->GetFocusedSheet()->GetName())); + painter->save(); + painter->rotate(-90); + painter->translate(QPointF(-(m_drawingAreaHeight+tilesMargins.top()) + UnitConvertor(1, Unit::Cm, Unit::Px), + m_drawingAreaWidth + tilesMargins.left() + )); + td.drawContents(painter); + painter->restore(); + +} + +//--------------------------------------------------------------------------------------------------------------------- +int VPTileFactory::getRowNb() +{ + return m_nbRow; +} + +//--------------------------------------------------------------------------------------------------------------------- +int VPTileFactory::getColNb() +{ + return m_nbCol; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPTileFactory::getDrawingAreaHeight() +{ + return m_drawingAreaHeight; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPTileFactory::getDrawingAreaWidth() +{ + return m_drawingAreaWidth; +} diff --git a/src/app/puzzle/vptilefactory.h b/src/app/puzzle/vptilefactory.h new file mode 100644 index 000000000..7b78a36f7 --- /dev/null +++ b/src/app/puzzle/vptilefactory.h @@ -0,0 +1,121 @@ +/************************************************************************ + ** + ** @file vptilefactory.h + ** @author Ronan Le Tiec + ** @date 19 11, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VPTILEFACTORY_H +#define VPTILEFACTORY_H + +#include +#include + +#include "vplayout.h" +#include "../vmisc/def.h" +#include "vcommonsettings.h" + +class VPMainGraphicsView; + +class VPTileFactory : QObject +{ + Q_OBJECT + +public: + VPTileFactory(VPLayout *layout, VCommonSettings *settings); + + ~VPTileFactory(); + + /** + * @brief drawTile draws the tile of given coordinate (row, col) from the + * current sheet of the layout with the given painter + * @param painter + * @param row + * @param col + */ + void drawTile(QPainter *painter, VPMainGraphicsView *graphicsView, int row, int col); + + /** + * @brief refreshTileInfos Resfreshes the tile infos (m_nbCol, m_nbRow, m_drawingAreaHeight, m_drawingAreaWidth) + */ + void refreshTileInfos(); + + /** + * @brief getRowNb Returns the number of row pages + * @return + */ + int getRowNb(); + + /** + * @brief getColNb Returns the number of col pages + * @return + */ + int getColNb(); + + /** + * @brief getDrawingAreaHeight Returns the usable height of the tile in Px + * @return + */ + qreal getDrawingAreaHeight(); + + /** + * @brief getDrawingAreaWidth Returns the usable width of the tile in Px + * @return + */ + qreal getDrawingAreaWidth(); + +private: + Q_DISABLE_COPY(VPTileFactory) + + VPLayout *m_layout{nullptr}; + VCommonSettings *m_commonSettings{nullptr}; + + /** + * @brief m_nbCol the number of column-pages for the current sheet of the layout + */ + int m_nbCol{0}; + + /** + * @brief m_nbRow the number of row-pages for the current sheet of the layout + */ + int m_nbRow{0}; + + /** + * @brief m_drawingAreaHeight the height of the drawing area + */ + qreal m_drawingAreaHeight{0}; + + /** + * @brief m_drawingAreaWidth the width of the drawing area + */ + qreal m_drawingAreaWidth{0}; + + /** + * @brief m_infoStripeWidth the width of the info / glueing stripe in Px + */ + qreal m_infoStripeWidth{0}; + +}; + +#endif // VPTILEFACTORY_H From a0cd4e9a311e45d07857dd7eed7819f8752f5915 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Thu, 19 Nov 2020 15:08:45 +0100 Subject: [PATCH 21/34] Selected piece on top --- src/app/puzzle/vpmaingraphicsview.cpp | 17 +++++++++++++++-- src/app/puzzle/vptilefactory.cpp | 9 +++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/app/puzzle/vpmaingraphicsview.cpp b/src/app/puzzle/vpmaingraphicsview.cpp index d7241a72c..4c4c3d1a0 100644 --- a/src/app/puzzle/vpmaingraphicsview.cpp +++ b/src/app/puzzle/vpmaingraphicsview.cpp @@ -232,9 +232,22 @@ void VPMainGraphicsView::on_PieceMovedToPieceList(VPPiece *piece, VPPieceList *p //--------------------------------------------------------------------------------------------------------------------- void VPMainGraphicsView::on_SceneSelectionChanged() { - // most of the selection behaviour taks place automatically + // most of the selection behaviour takes place automatically // but we need to make sure that the unplaced pieces are unselected when the scene selection has changed // because as they are not part of the scene, they are not updated - m_layout->GetUnplacedPieceList()->ClearSelection(); + + + // make sure, that the selected items are on top + // FIXME: maybe there is a more proper way to do it + for(auto graphicPiece : m_graphicsPieces) + { + if(!graphicPiece->GetPiece()->GetIsSelected()) + { + if(!m_scene->selectedItems().isEmpty()) + { + graphicPiece->stackBefore(m_scene->selectedItems().first()); + } + } + } } diff --git a/src/app/puzzle/vptilefactory.cpp b/src/app/puzzle/vptilefactory.cpp index a7606b1b4..1f3cd73c6 100644 --- a/src/app/puzzle/vptilefactory.cpp +++ b/src/app/puzzle/vptilefactory.cpp @@ -71,6 +71,7 @@ void VPTileFactory::drawTile(QPainter *painter, VPMainGraphicsView *graphicsView QSvgRenderer* svgRenderer = new QSvgRenderer(); + // FIXME here instead of creating 4 triangle, maybe create one and rotate it // ------------- prepare triangles for positioning @@ -263,10 +264,10 @@ void VPTileFactory::drawTile(QPainter *painter, VPMainGraphicsView *graphicsView // prepare the painting for the text information QTextDocument td; - -// td.documentLayout()->setPaintDevice(printer); ?? - - td.setPageSize(QSizeF(m_drawingAreaWidth - UnitConvertor(2, Unit::Cm, Unit::Px), m_drawingAreaHeight)); + td.setPageSize(QSizeF( + m_drawingAreaWidth - UnitConvertor(2, Unit::Cm, Unit::Px), + m_drawingAreaHeight + )); // paint the grid information const QString grid = tr("Grid ( %1 , %2 )").arg(row+1).arg(col+1); From b90a99a0aa7ddebb4443883debe7a81d0d621935 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Thu, 19 Nov 2020 16:32:47 +0100 Subject: [PATCH 22/34] Showing internal paths --- src/app/puzzle/vpgraphicspiece.cpp | 41 +++++++++++++++++++++++++++--- src/app/puzzle/vpgraphicspiece.h | 4 ++- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/app/puzzle/vpgraphicspiece.cpp b/src/app/puzzle/vpgraphicspiece.cpp index 3ee802c11..a2b4f16c4 100644 --- a/src/app/puzzle/vpgraphicspiece.cpp +++ b/src/app/puzzle/vpgraphicspiece.cpp @@ -44,6 +44,8 @@ #include "vplayout.h" #include "vpsheet.h" +#include "vlayoutpiecepath.h" + #include Q_LOGGING_CATEGORY(pGraphicsPiece, "p.graphicsPiece") @@ -54,6 +56,8 @@ VPGraphicsPiece::VPGraphicsPiece(VPPiece *piece, QGraphicsItem *parent) : m_cuttingLine(QPainterPath()), m_seamLine(QPainterPath()), m_grainline(QPainterPath()), + m_internalPaths(QVector()), + m_internalPathsPenStyle(QVector()), m_rotationStartPoint(QPointF()) { Init(); @@ -78,7 +82,7 @@ void VPGraphicsPiece::Init() if(!seamLinePoints.isEmpty()) { m_seamLine.moveTo(seamLinePoints.first()); - for (int i = 1; i < seamLinePoints.size(); ++i) + for (int i = 0; i < seamLinePoints.size(); i++) m_seamLine.lineTo(seamLinePoints.at(i)); } @@ -87,7 +91,7 @@ void VPGraphicsPiece::Init() if(!cuttingLinepoints.isEmpty()) { m_cuttingLine.moveTo(cuttingLinepoints.first()); - for (int i = 1; i < cuttingLinepoints.size(); ++i) + for (int i = 0; i < cuttingLinepoints.size(); i++) m_cuttingLine.lineTo(cuttingLinepoints.at(i)); } @@ -98,11 +102,21 @@ void VPGraphicsPiece::Init() if(!grainLinepoints.isEmpty()) { m_grainline.moveTo(grainLinepoints.first()); - for (int i = 1; i < grainLinepoints.size(); ++i) + for (int i = 0; i < grainLinepoints.size(); i++) m_grainline.lineTo(grainLinepoints.at(i)); } } + // initialises the internal paths + QVector internalPaths = m_piece->GetInternalPaths(); + for (int i = 0; i < internalPaths.size(); i++) + { + VLayoutPiecePath piecePath = internalPaths.at(i); + QPainterPath path = m_piece->GetMatrix().map(piecePath.GetPainterPath()); + m_internalPaths.append(path); + m_internalPathsPenStyle.append(piecePath.PenStyle()); + } + // TODO : initialises the other elements labels, passmarks etc. // Initialises the connectors @@ -149,9 +163,11 @@ void VPGraphicsPiece::paint(QPainter *painter, const QStyleOptionGraphicsItem *o QPen pen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); QBrush noBrush(Qt::NoBrush); QBrush selectionBrush(QColor(255,160,160,60)); + QBrush blackBrush(Qt::black); painter->setPen(pen); + // selection if(isSelected()) { painter->setBrush(selectionBrush); @@ -179,8 +195,27 @@ void VPGraphicsPiece::paint(QPainter *painter, const QStyleOptionGraphicsItem *o // paint the grainline if(!m_grainline.isEmpty()) { + painter->setBrush(blackBrush); painter->drawPath(m_grainline); } + + // paint the internal paths + painter->setBrush(noBrush); + if(!m_internalPaths.isEmpty()) + { + Qt::PenStyle penStyleTmp = pen.style(); + + for (int i = 0; i < m_internalPaths.size(); i++) + { + painter->setPen(m_internalPathsPenStyle.at(i)); + painter->drawPath(m_internalPaths.at(i)); + } + pen.setStyle(penStyleTmp); + } + + + // when using m_piece->GetItem(), the results were quite bad + } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/vpgraphicspiece.h b/src/app/puzzle/vpgraphicspiece.h index 03c543cf8..bd0e1fd9d 100644 --- a/src/app/puzzle/vpgraphicspiece.h +++ b/src/app/puzzle/vpgraphicspiece.h @@ -98,8 +98,10 @@ private: QPainterPath m_seamLine; QPainterPath m_grainline; - QPointF m_rotationStartPoint; + QVector m_internalPaths; + QVector m_internalPathsPenStyle; + QPointF m_rotationStartPoint; }; #endif // VPGRAPHICSPIECE_H From 7e16c126231bff689c24a6e8087f466df2c6773b Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Thu, 19 Nov 2020 16:45:02 +0100 Subject: [PATCH 23/34] Change the selection sequence with tabs --- src/app/puzzle/vpmainwindow.ui | 43 ++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 72f44bece..7e875e3d6 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -176,7 +176,7 @@ QTabWidget::Rounded - 2 + 3 @@ -1521,12 +1521,51 @@
+ tabWidgetProperties + scrollAreaCurrentPiece scrollAreaSheet + scrollAreaTiles + scrollAreaLayout + lineEditCurrentPieceName + plainTextEditCurrentPieceUUID + checkBoxCurrentPieceShowSeamline + checkBoxCurrentPieceMirrorPiece + doubleSpinBoxCurrentPieceAngle + doubleSpinBoxCurrentPieceBoxPositionX + doubleSpinBoxCurrentPieceBoxPositionY + lineEditSheetName + comboBoxSheetTemplate + doubleSpinBoxSheetWidth + doubleSpinBoxSheetLength + radioButtonSheetPortrait + radioButtonSheetLandscape + pushButtonSheetRemoveUnusedLength doubleSpinBoxSheetMarginTop doubleSpinBoxSheetMarginLeft doubleSpinBoxSheetMarginRight doubleSpinBoxSheetMarginBottom - scrollAreaTiles + radioButtonSheetFollowGrainlineNo + radioButtonSheetFollowGrainlineVertical + radioButtonSheetFollowGrainlineHorizontal + doubleSpinBoxSheetPiecesGap + checkBoxSheetStickyEdges + comboBoxSheetExportFormat + pushButtonSheetExport + doubleSpinBoxTilesWidth + doubleSpinBoxTilesLength + radioButtonTilesPortrait + radioButtonTilesLandscape + doubleSpinBoxTilesMarginTop + doubleSpinBoxTilesMarginLeft + doubleSpinBoxTilesMarginRight + doubleSpinBoxTilesMarginBottom + checkBoxTilesShowTiles + pushButtonTilesExport + lineEditLayoutName + plainTextEditLayoutDescription + comboBoxLayoutUnit + checkBoxLayoutWarningPiecesSuperposition + checkBoxLayoutWarningPiecesOutOfBound From 073bd93df7647f71c349fb7b1484a6ff3b2535f1 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Thu, 19 Nov 2020 17:24:48 +0100 Subject: [PATCH 24/34] remove the grainline filling --- src/app/puzzle/vpgraphicspiece.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/puzzle/vpgraphicspiece.cpp b/src/app/puzzle/vpgraphicspiece.cpp index a2b4f16c4..7babfa5a3 100644 --- a/src/app/puzzle/vpgraphicspiece.cpp +++ b/src/app/puzzle/vpgraphicspiece.cpp @@ -195,7 +195,10 @@ void VPGraphicsPiece::paint(QPainter *painter, const QStyleOptionGraphicsItem *o // paint the grainline if(!m_grainline.isEmpty()) { - painter->setBrush(blackBrush); + // here to fill the grainlines arrow. Not wanted for mvp + // later maybe if it's configurable +// painter->setBrush(blackBrush); + painter->drawPath(m_grainline); } From 9140fdcb78cf5611122bb9d78bd2018f79c81920 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Fri, 20 Nov 2020 15:51:24 +0100 Subject: [PATCH 25/34] Templates for sheet and tiles --- src/app/puzzle/vpmainwindow.cpp | 129 ++++++++++++++++--- src/app/puzzle/vpmainwindow.h | 15 ++- src/app/puzzle/vpmainwindow.ui | 30 ++++- src/app/puzzle/vpsheet.cpp | 211 +++++++++++++++++++++++++++++++ src/app/puzzle/vpsheet.h | 64 +++++++++- src/app/puzzle/vptilefactory.cpp | 67 +++++----- 6 files changed, 457 insertions(+), 59 deletions(-) diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index a1983ed7d..4f02469f2 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -88,14 +88,14 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : ui->setupUi(this); - InitMenuBar(); - InitProperties(); - InitCarrousel(); - // init the tile factory m_tileFactory = new VPTileFactory(m_layout, qApp->Settings()); m_tileFactory->refreshTileInfos(); + InitMenuBar(); + InitProperties(); + InitCarrousel(); + InitMainGraphics(); InitZoomToolBar(); @@ -314,11 +314,33 @@ void VPMainWindow::InitPropertyTabCurrentSheet() connect(ui->radioButtonSheetFollowGrainlineHorizontal, QOverload::of(&QRadioButton::clicked), this, &VPMainWindow::on_SheetFollowGrainlineChanged); - // -------------------- export --------------------------- + // -------------------- sheet template --------------------------- - // TODO init the file format export combobox + // FIXME: find a nicer way to initiliase it + QVector sheetTemplates = QVector(); + sheetTemplates.append(PaperSizeTemplate::A0); + sheetTemplates.append(PaperSizeTemplate::A1); + sheetTemplates.append(PaperSizeTemplate::A2); + sheetTemplates.append(PaperSizeTemplate::A3); + sheetTemplates.append(PaperSizeTemplate::A4); + sheetTemplates.append(PaperSizeTemplate::Letter); + sheetTemplates.append(PaperSizeTemplate::Legal); + sheetTemplates.append(PaperSizeTemplate::Tabloid); + sheetTemplates.append(PaperSizeTemplate::Roll24in); + sheetTemplates.append(PaperSizeTemplate::Roll30in); + sheetTemplates.append(PaperSizeTemplate::Roll36in); + sheetTemplates.append(PaperSizeTemplate::Roll42in); + sheetTemplates.append(PaperSizeTemplate::Roll44in); + sheetTemplates.append(PaperSizeTemplate::Roll48in); + sheetTemplates.append(PaperSizeTemplate::Roll62in); + sheetTemplates.append(PaperSizeTemplate::Roll72in); + sheetTemplates.append(PaperSizeTemplate::Custom); + ui->comboBoxSheetTemplate->blockSignals(true); + VPSheet::PopulateComboBox(&sheetTemplates, ui->comboBoxSheetTemplate); + ui->comboBoxSheetTemplate->blockSignals(false); + ui->comboBoxSheetTemplate->setCurrentIndex(0); } //--------------------------------------------------------------------------------------------------------------------- @@ -334,6 +356,24 @@ void VPMainWindow::InitPropertyTabTiles() connect(ui->radioButtonTilesLandscape, QOverload::of(&QRadioButton::clicked), this, &VPMainWindow::on_TilesOrientationChanged); + // -------------------- tiles template + QVector tilesTemplates = QVector(); + tilesTemplates.append(PaperSizeTemplate::A0); + tilesTemplates.append(PaperSizeTemplate::A1); + tilesTemplates.append(PaperSizeTemplate::A2); + tilesTemplates.append(PaperSizeTemplate::A3); + tilesTemplates.append(PaperSizeTemplate::A4); + tilesTemplates.append(PaperSizeTemplate::Letter); + tilesTemplates.append(PaperSizeTemplate::Legal); + tilesTemplates.append(PaperSizeTemplate::Custom); + + ui->comboBoxTilesTemplate->blockSignals(true); + VPSheet::PopulateComboBox(&tilesTemplates, ui->comboBoxTilesTemplate); + ui->comboBoxTilesTemplate->blockSignals(false); + + ui->comboBoxTilesTemplate->setCurrentIndex(4); //A4 + + // -------------------- margins ------------------------ connect(ui->doubleSpinBoxTilesMarginTop, QOverload::of(&QDoubleSpinBox::valueChanged), this, &VPMainWindow::on_TilesMarginChanged); @@ -1004,26 +1044,46 @@ void VPMainWindow::on_comboBoxLayoutUnit_currentIndexChanged(int index) //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_comboBoxSheetTemplate_currentIndexChanged(int index) { - // just for test purpuses, to be removed: - QMessageBox msgBox; - msgBox.setText("TODO VPMainWindow::SheetTemplateChanged"); - int ret = msgBox.exec(); + PaperSizeTemplate tmpl = static_cast( + ui->comboBoxSheetTemplate->itemData(index).toInt() + ); - Q_UNUSED(index); - Q_UNUSED(ret); + QSizeF tmplSize = VPSheet::GetTemplateSize(tmpl); + if(!tmplSize.isEmpty()) + { + ui->doubleSpinBoxSheetWidth->blockSignals(true); + ui->doubleSpinBoxSheetLength->blockSignals(true); + ui->doubleSpinBoxSheetWidth->setValue(UnitConvertor(tmplSize.width(), Unit::Px, m_layout->GetUnit())); + ui->doubleSpinBoxSheetLength->setValue(UnitConvertor(tmplSize.height(), Unit::Px, m_layout->GetUnit())); - // TODO + on_SheetSizeChanged(false); + + ui->doubleSpinBoxSheetWidth->blockSignals(false); + ui->doubleSpinBoxSheetLength->blockSignals(false); + } } //--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::on_SheetSizeChanged() +void VPMainWindow::on_SheetSizeChanged(bool changedViaSizeCombobox) { m_layout->GetFocusedSheet()->SetSheetSizeConverted( ui->doubleSpinBoxSheetWidth->value(), ui->doubleSpinBoxSheetLength->value() ); + if(changedViaSizeCombobox) + { + ui->comboBoxSheetTemplate->blockSignals(true); + + // we don't try to get the right size, because it doesn't work well because of mm / inch conversion + int index = ui->comboBoxSheetTemplate->findData( + QVariant(static_cast(PaperSizeTemplate::Custom))); + + ui->comboBoxSheetTemplate->setCurrentIndex(index); + ui->comboBoxSheetTemplate->blockSignals(false); + } + m_tileFactory->refreshTileInfos(); // TODO Undo / Redo @@ -1079,16 +1139,53 @@ void VPMainWindow::on_SheetMarginChanged() m_graphicsView->RefreshLayout(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::on_comboBoxTilesTemplate_currentIndexChanged(int index) +{ + PaperSizeTemplate tmpl = static_cast( + ui->comboBoxTilesTemplate->itemData(index).toInt() + ); + + QSizeF tmplSize = VPSheet::GetTemplateSize(tmpl); + if(!tmplSize.isEmpty()) + { + ui->doubleSpinBoxTilesWidth->blockSignals(true); + ui->doubleSpinBoxTilesLength->blockSignals(true); + + ui->doubleSpinBoxTilesWidth->setValue(UnitConvertor(tmplSize.width(), Unit::Px, m_layout->GetUnit())); + ui->doubleSpinBoxTilesLength->setValue(UnitConvertor(tmplSize.height(), Unit::Px, m_layout->GetUnit())); + + on_TilesSizeChanged(false); + + ui->doubleSpinBoxTilesWidth->blockSignals(false); + ui->doubleSpinBoxTilesLength->blockSignals(false); + } +} //--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::on_TilesSizeChanged() +void VPMainWindow::on_TilesSizeChanged(bool changedViaSizeCombobox) { m_layout->SetTilesSizeConverted(ui->doubleSpinBoxTilesWidth->value(), ui->doubleSpinBoxTilesLength->value()); m_tileFactory->refreshTileInfos(); + if(changedViaSizeCombobox) + { + ui->comboBoxTilesTemplate->blockSignals(true); + + // we don't try to get the right size, because it doesn't work well because of mm / inch conversion + int index = ui->comboBoxTilesTemplate->findData( + QVariant(static_cast(PaperSizeTemplate::Custom))); + + ui->comboBoxTilesTemplate->setCurrentIndex(index); + ui->comboBoxTilesTemplate->blockSignals(false); + } + // TODO Undo / Redo - m_graphicsView->RefreshLayout(); + if(m_graphicsView != nullptr) + { + m_graphicsView->RefreshLayout(); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index 462e8a8bf..72287ecfa 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -287,7 +287,7 @@ private slots: /** * @brief on_comboBoxLayoutTemplate_currentIndexChanged When the template is - * changed in the layout property tab. + * changed in the sheet property tab. * The slot is automatically connected through name convention. * @param index the index of the selected templated */ @@ -296,8 +296,9 @@ private slots: /** * @brief on_SheetSizeChanged When the width or the length has been changed in * the sheet property tab + * @param changedViaSizeCombobox true if the change happened through the combobox */ - void on_SheetSizeChanged(); + void on_SheetSizeChanged(bool changedViaSizeCombobox = true); /** * @brief on_SheetOrientationChanged When one of the radio boxes for the sheet @@ -332,12 +333,20 @@ private slots: */ void on_doubleSpinBoxSheetPiecesGap_valueChanged(double value); + /** + * @brief on_comboBoxTilesTemplate_currentIndexChanged When the template is + * changed in the tiles property tab. + * The slot is automatically connected through name convention. + * @param index the index of the selected templated + */ + void on_comboBoxTilesTemplate_currentIndexChanged(int index); /** * @brief on_TilesSizeChanged When the width or the length has been changed in * the tiles property tab + * @param changedViaSizeCombobox true if the change happened through the combobox */ - void on_TilesSizeChanged(); + void on_TilesSizeChanged(bool changedViaSizeCombobox = true); /** * @brief on_TilesOrientationChanged When one of the radio boxes for the tiles diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 7e875e3d6..0951bd143 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -176,7 +176,7 @@ QTabWidget::Rounded - 3 + 2 @@ -632,6 +632,9 @@
+ + 2 + 100000.000000000000000 @@ -646,6 +649,9 @@ + + 2 + 100000.000000000000000 @@ -1006,42 +1012,42 @@ - + Width - + 100000.000000000000000 - + Length - + 100000.000000000000000 - + Orientation - + @@ -1082,6 +1088,16 @@ + + + + Template + + + + + + diff --git a/src/app/puzzle/vpsheet.cpp b/src/app/puzzle/vpsheet.cpp index e1f6cb501..475584860 100644 --- a/src/app/puzzle/vpsheet.cpp +++ b/src/app/puzzle/vpsheet.cpp @@ -43,6 +43,217 @@ VPSheet::~VPSheet() delete m_pieceList; } +//--------------------------------------------------------------------------------------------------------------------- +QSizeF VPSheet::GetTemplateSize(PaperSizeTemplate tmpl) +{ + qreal height = 0; + qreal width = 0; + + switch (tmpl) + { + case PaperSizeTemplate::A0: + width = UnitConvertor(841, Unit::Mm, Unit::Px); + height = UnitConvertor(1189, Unit::Mm, Unit::Px); + break; + + case PaperSizeTemplate::A1: + width = UnitConvertor(594, Unit::Mm, Unit::Px); + height = UnitConvertor(841, Unit::Mm, Unit::Px); + break; + + case PaperSizeTemplate::A2: + width = UnitConvertor(420, Unit::Mm, Unit::Px); + height = UnitConvertor(594, Unit::Mm, Unit::Px); + break; + + case PaperSizeTemplate::A3: + width = UnitConvertor(297, Unit::Mm, Unit::Px); + height = UnitConvertor(420, Unit::Mm, Unit::Px); + break; + + case PaperSizeTemplate::A4: + width = UnitConvertor(210, Unit::Mm, Unit::Px); + height = UnitConvertor(297, Unit::Mm, Unit::Px); + break; + + case PaperSizeTemplate::Letter: + width = UnitConvertor(8.5, Unit::Inch, Unit::Px); + height = UnitConvertor(11, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Legal: + width = UnitConvertor(8.5, Unit::Inch, Unit::Px); + height = UnitConvertor(14, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Tabloid: + width = UnitConvertor(11, Unit::Inch, Unit::Px); + height = UnitConvertor(17, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Roll24in: + width = UnitConvertor(24, Unit::Inch, Unit::Px); + height = UnitConvertor(48, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Roll30in: + width = UnitConvertor(30, Unit::Inch, Unit::Px); + height = UnitConvertor(60, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Roll36in: + width = UnitConvertor(36, Unit::Inch, Unit::Px); + height = UnitConvertor(72, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Roll42in: + width = UnitConvertor(42, Unit::Inch, Unit::Px); + height = UnitConvertor(84, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Roll44in: + width = UnitConvertor(44, Unit::Inch, Unit::Px); + height = UnitConvertor(88, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Roll48in: + width = UnitConvertor(48, Unit::Inch, Unit::Px); + height = UnitConvertor(96, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Roll62in: + width = UnitConvertor(62, Unit::Inch, Unit::Px); + height = UnitConvertor(124, Unit::Inch, Unit::Px); + break; + + case PaperSizeTemplate::Roll72in: + width = UnitConvertor(72, Unit::Inch, Unit::Px); + height = UnitConvertor(144, Unit::Inch, Unit::Px); + break; + + default: + break; + } + + return QSizeF(width, height); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VPSheet::GetTemplateName(PaperSizeTemplate tmpl) +{ + switch (tmpl) + { + case PaperSizeTemplate::A0: + return QString("A0"); + + case PaperSizeTemplate::A1: + return QString("A1"); + + case PaperSizeTemplate::A2: + return QString("A2"); + + case PaperSizeTemplate::A3: + return QString("A3"); + + case PaperSizeTemplate::A4: + return QString("A4"); + + case PaperSizeTemplate::Letter: + return tr("Letter"); + + case PaperSizeTemplate::Legal: + return tr("Legal"); + + case PaperSizeTemplate::Tabloid: + return tr("Tabloid"); + + case PaperSizeTemplate::Roll24in: + return tr("Roll 24in"); + + case PaperSizeTemplate::Roll30in: + return tr("Roll 30in"); + + case PaperSizeTemplate::Roll36in: + return tr("Roll 36in"); + + case PaperSizeTemplate::Roll42in: + return tr("Roll 42in"); + + case PaperSizeTemplate::Roll44in: + return tr("Roll 44in"); + + case PaperSizeTemplate::Roll48in: + return tr("Roll 48in"); + + case PaperSizeTemplate::Roll62in: + return tr("Roll 62in"); + + case PaperSizeTemplate::Roll72in: + return tr("Roll 72in"); + + case PaperSizeTemplate::Custom: + return tr("Custom"); + + default: + break; + } + + return QString(""); +} + +//--------------------------------------------------------------------------------------------------------------------- +PaperSizeTemplate VPSheet::GetTemplate(QSizeF size) +{ + const int max = static_cast(PaperSizeTemplate::Custom); + + for (int i=0; i < max; i++) + { + PaperSizeTemplate tmpl = static_cast(i); + const QSizeF tmplSize = GetTemplateSize(tmpl); + + if(size.width() == tmplSize.width()) + { + if(isRollTemplate(tmpl)) + { + return tmpl; + } + else if(size.height() == tmplSize.height()) + { + return tmpl; + } + } + } + + return PaperSizeTemplate::Custom; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VPSheet::isRollTemplate(PaperSizeTemplate tmpl) +{ + switch (tmpl) { + case PaperSizeTemplate::Roll24in: + case PaperSizeTemplate::Roll30in: + case PaperSizeTemplate::Roll36in: + case PaperSizeTemplate::Roll42in: + case PaperSizeTemplate::Roll44in: + case PaperSizeTemplate::Roll48in: + case PaperSizeTemplate::Roll62in: + case PaperSizeTemplate::Roll72in: + return true; + default: + return false; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::PopulateComboBox(QVector *tmpls, QComboBox* comboBox) +{ + for (auto tmpl : *tmpls) + { + comboBox->addItem(GetTemplateName(tmpl), QVariant(static_cast(tmpl))); + } +} + //--------------------------------------------------------------------------------------------------------------------- VPLayout* VPSheet::GetLayout() { diff --git a/src/app/puzzle/vpsheet.h b/src/app/puzzle/vpsheet.h index 2e49acaf3..39fa05268 100644 --- a/src/app/puzzle/vpsheet.h +++ b/src/app/puzzle/vpsheet.h @@ -32,11 +32,36 @@ #include #include #include +#include #include "def.h" // is this the right place for the definition? -enum class FollowGrainline : qint8 { No = 0, Follow90 = 1, Follow180 = 2}; +enum class FollowGrainline : qint8 { + No = 0, + Follow90 = 1, + Follow180 = 2 +}; + +enum class PaperSizeTemplate : qint8 { + A0 = 0, + A1, + A2, + A3, + A4, + Letter, + Legal, + Tabloid, + Roll24in, + Roll30in, + Roll36in, + Roll42in, + Roll44in, + Roll48in, + Roll62in, + Roll72in, + Custom +}; class VPLayout; class VPPieceList; @@ -45,10 +70,47 @@ class VPSheet : public QObject { Q_OBJECT public: + + explicit VPSheet(VPLayout* layout); ~VPSheet(); + /** + * @brief GetTemplateSize Returns the size in Px of the given template + * @param tmpl + * @return the size in Px + */ + static QSizeF GetTemplateSize(PaperSizeTemplate tmpl); + + /** + * @brief GetTemplateName Returns the name of the given template + * @param tmpl + * @return + */ + static QString GetTemplateName(PaperSizeTemplate tmpl); + + /** + * @brief GetTemplate GetTemplate Returns the template that corresponds to the given size + * @param size the Size in Px + * @return + */ + static PaperSizeTemplate GetTemplate(QSizeF size); + + /** + * @brief PopulateComboBox Populates the given combo with the given templates + * @param tmpls + * @param comboBox + */ + static void PopulateComboBox(QVector *tmpls, QComboBox* comboBox); + + /** + * @brief isRollTemplate Returns wether the given template is a roll or not. + * @param tmpl + * @return + */ + static bool isRollTemplate(PaperSizeTemplate tmpl); + /** * @brief GetLayout Returns the Layout of the sheet * @return diff --git a/src/app/puzzle/vptilefactory.cpp b/src/app/puzzle/vptilefactory.cpp index 1f3cd73c6..a243fa857 100644 --- a/src/app/puzzle/vptilefactory.cpp +++ b/src/app/puzzle/vptilefactory.cpp @@ -25,40 +25,43 @@ VPTileFactory::~VPTileFactory() //--------------------------------------------------------------------------------------------------------------------- void VPTileFactory::refreshTileInfos() { - PageOrientation tilesOrientation = m_layout->GetTilesOrientation(); - QSizeF tilesSize = m_layout->GetTilesSize(); - QMarginsF tilesMargins = m_layout->GetTilesMargins(); - - // sets the drawing height - m_drawingAreaHeight = (tilesOrientation == PageOrientation::Portrait)? - tilesSize.height() : tilesSize.width(); - m_drawingAreaHeight -= - tilesMargins.top() + tilesMargins.bottom() + m_infoStripeWidth; - - // sets the drawing width - m_drawingAreaWidth = (tilesOrientation == PageOrientation::Portrait)? - tilesSize.width() : tilesSize.height(); - m_drawingAreaWidth -= - tilesMargins.left() + tilesMargins.right() + m_infoStripeWidth; - - - QSizeF sheetSize = m_layout->GetFocusedSheet()->GetSheetSize(); - qreal totalDrawingWidth = 0; - qreal totaldrawingHeight = 0; - - if(m_layout->GetFocusedSheet()->GetOrientation() == PageOrientation::Portrait) + if(m_layout != nullptr) { - totalDrawingWidth = sheetSize.width(); - totaldrawingHeight = sheetSize.height(); - } - else - { - totalDrawingWidth = sheetSize.height(); - totaldrawingHeight = sheetSize.width(); - } + PageOrientation tilesOrientation = m_layout->GetTilesOrientation(); + QSizeF tilesSize = m_layout->GetTilesSize(); + QMarginsF tilesMargins = m_layout->GetTilesMargins(); - m_nbCol = qCeil(totalDrawingWidth/m_drawingAreaWidth); - m_nbRow = qCeil(totaldrawingHeight/m_drawingAreaHeight); + // sets the drawing height + m_drawingAreaHeight = (tilesOrientation == PageOrientation::Portrait)? + tilesSize.height() : tilesSize.width(); + m_drawingAreaHeight -= + tilesMargins.top() + tilesMargins.bottom() + m_infoStripeWidth; + + // sets the drawing width + m_drawingAreaWidth = (tilesOrientation == PageOrientation::Portrait)? + tilesSize.width() : tilesSize.height(); + m_drawingAreaWidth -= + tilesMargins.left() + tilesMargins.right() + m_infoStripeWidth; + + + QSizeF sheetSize = m_layout->GetFocusedSheet()->GetSheetSize(); + qreal totalDrawingWidth = 0; + qreal totaldrawingHeight = 0; + + if(m_layout->GetFocusedSheet()->GetOrientation() == PageOrientation::Portrait) + { + totalDrawingWidth = sheetSize.width(); + totaldrawingHeight = sheetSize.height(); + } + else + { + totalDrawingWidth = sheetSize.height(); + totaldrawingHeight = sheetSize.width(); + } + + m_nbCol = qCeil(totalDrawingWidth/m_drawingAreaWidth); + m_nbRow = qCeil(totaldrawingHeight/m_drawingAreaHeight); + } } From efac90c9bb6b2e2efdd1626ee67b695095db3ae8 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Fri, 20 Nov 2020 16:24:53 +0100 Subject: [PATCH 26/34] Icons for templates --- src/app/puzzle/share/resources/puzzleicon.qrc | 2 + .../share/resources/puzzleicon/16x16/roll.png | Bin 0 -> 241 bytes .../resources/puzzleicon/16x16/template.png | Bin 0 -> 372 bytes src/app/puzzle/vpsheet.cpp | 44 +++++++++++------- 4 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 src/app/puzzle/share/resources/puzzleicon/16x16/roll.png create mode 100644 src/app/puzzle/share/resources/puzzleicon/16x16/template.png diff --git a/src/app/puzzle/share/resources/puzzleicon.qrc b/src/app/puzzle/share/resources/puzzleicon.qrc index 12c2a72ee..83dde8c8e 100644 --- a/src/app/puzzle/share/resources/puzzleicon.qrc +++ b/src/app/puzzle/share/resources/puzzleicon.qrc @@ -14,5 +14,7 @@ puzzleicon/svg/icon_scissors.svg puzzleicon/svg/icon_scissors_vertical.svg puzzleicon/svg/icon_scissors_horizontal.svg + puzzleicon/16x16/roll.png + puzzleicon/16x16/template.png diff --git a/src/app/puzzle/share/resources/puzzleicon/16x16/roll.png b/src/app/puzzle/share/resources/puzzleicon/16x16/roll.png new file mode 100644 index 0000000000000000000000000000000000000000..49c30dff11916a06b3aa06d2404b94c0f255ceae GIT binary patch literal 241 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^zg78t&m77ygF@N{tu z(FlHeW}}xABZJ#R{aBe+w&3Z~EQ-3i5AQvZvXcJ7WVV}=*RN04vDx`^>=hk$LDtl2Rt3;DTffo^8-boFyt=akR{03vf*A^-pY literal 0 HcmV?d00001 diff --git a/src/app/puzzle/share/resources/puzzleicon/16x16/template.png b/src/app/puzzle/share/resources/puzzleicon/16x16/template.png new file mode 100644 index 0000000000000000000000000000000000000000..c29755d29dd988896cbc17477f6adabc2d10b693 GIT binary patch literal 372 zcmV-)0gL{LP)%hRk?(XjP_V)Pr_~_{9 z(b3WB>gw0%|D6o9@Zf%2b0#xkEa1M7 z4RIKYU=cc4#!0eD*WiRhoMju>?)nuUA=`@_FghGh4$ea4d5V|o&4DPSB2A{eJE$sz z2h>pd8^sfqYMR%30;yAKTl#qD5Uhpoyy(zcYmAvdVy&qc@-R2R{4M7J`|k&(PaperSizeTemplate::Custom); + // TODO, float comparision not safe and problems with + // inch / cm - for (int i=0; i < max; i++) - { - PaperSizeTemplate tmpl = static_cast(i); - const QSizeF tmplSize = GetTemplateSize(tmpl); +// const int max = static_cast(PaperSizeTemplate::Custom); - if(size.width() == tmplSize.width()) - { - if(isRollTemplate(tmpl)) - { - return tmpl; - } - else if(size.height() == tmplSize.height()) - { - return tmpl; - } - } - } +// for (int i=0; i < max; i++) +// { +// PaperSizeTemplate tmpl = static_cast(i); +// const QSizeF tmplSize = GetTemplateSize(tmpl); + +// if(size.width() == tmplSize.width()) +// { +// if(isRollTemplate(tmpl)) +// { +// return tmpl; +// } +// else if(size.height() == tmplSize.height()) +// { +// return tmpl; +// } +// } +// } return PaperSizeTemplate::Custom; } @@ -248,9 +251,14 @@ bool VPSheet::isRollTemplate(PaperSizeTemplate tmpl) //--------------------------------------------------------------------------------------------------------------------- void VPSheet::PopulateComboBox(QVector *tmpls, QComboBox* comboBox) { + const QIcon icoPaper("://puzzleicon/16x16/template.png"); + const QIcon icoRoll("://puzzleicon/16x16/roll.png"); + + QIcon icon; for (auto tmpl : *tmpls) { - comboBox->addItem(GetTemplateName(tmpl), QVariant(static_cast(tmpl))); + icon = (isRollTemplate(tmpl))? icoRoll : icoPaper; + comboBox->addItem(icon, GetTemplateName(tmpl), QVariant(static_cast(tmpl))); } } From 4366cbdec9fb4b907c15f447cccdcd5ec5a74659 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Fri, 20 Nov 2020 17:05:56 +0100 Subject: [PATCH 27/34] Display passmarks and place labels --- src/app/puzzle/vpgraphicspiece.cpp | 46 ++++++++++++++++++++++++++++-- src/app/puzzle/vpgraphicspiece.h | 3 ++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/app/puzzle/vpgraphicspiece.cpp b/src/app/puzzle/vpgraphicspiece.cpp index 7babfa5a3..eb0e4df4b 100644 --- a/src/app/puzzle/vpgraphicspiece.cpp +++ b/src/app/puzzle/vpgraphicspiece.cpp @@ -45,6 +45,7 @@ #include "vpsheet.h" #include "vlayoutpiecepath.h" +#include "vplacelabelitem.h" #include Q_LOGGING_CATEGORY(pGraphicsPiece, "p.graphicsPiece") @@ -56,8 +57,10 @@ VPGraphicsPiece::VPGraphicsPiece(VPPiece *piece, QGraphicsItem *parent) : m_cuttingLine(QPainterPath()), m_seamLine(QPainterPath()), m_grainline(QPainterPath()), + m_passmarks(QPainterPath()), m_internalPaths(QVector()), m_internalPathsPenStyle(QVector()), + m_placeLabels(QVector()), m_rotationStartPoint(QPointF()) { Init(); @@ -117,7 +120,28 @@ void VPGraphicsPiece::Init() m_internalPathsPenStyle.append(piecePath.PenStyle()); } - // TODO : initialises the other elements labels, passmarks etc. + // initialises the passmarks + QVector passmarks = m_piece->GetPassmarks(); + for(auto &passmark : passmarks) + { + for (auto &line : passmark.lines) + { + m_passmarks.moveTo(line.p1()); + m_passmarks.lineTo(line.p2()); + } + } + + // initialises the place labels (buttons etc) + QVector placeLabels = m_piece->GetPlaceLabels(); + for(auto &placeLabel : placeLabels) + { + QPainterPath path = VPlaceLabelItem::LabelShapePath(placeLabel.shape); + m_placeLabels.append(path); + } + + // TODO : initialises the text labels + + // Initialises the connectors connect(m_piece, &VPPiece::SelectionChanged, this, &VPGraphicsPiece::on_PieceSelectionChanged); @@ -213,9 +237,27 @@ void VPGraphicsPiece::paint(QPainter *painter, const QStyleOptionGraphicsItem *o painter->setPen(m_internalPathsPenStyle.at(i)); painter->drawPath(m_internalPaths.at(i)); } - pen.setStyle(penStyleTmp); + painter->setPen(penStyleTmp); } + // paint the passmarks + if(!m_passmarks.isEmpty()) + { + painter->drawPath(m_passmarks); + } + + // paint the place labels (buttons etc) + if(!m_placeLabels.isEmpty()) + { + for(auto &placeLabel : m_placeLabels) + { + painter->drawPath(placeLabel); + } + } + + + // TODO Detail & Piece Label + // when using m_piece->GetItem(), the results were quite bad diff --git a/src/app/puzzle/vpgraphicspiece.h b/src/app/puzzle/vpgraphicspiece.h index bd0e1fd9d..aefcca155 100644 --- a/src/app/puzzle/vpgraphicspiece.h +++ b/src/app/puzzle/vpgraphicspiece.h @@ -97,10 +97,13 @@ private: QPainterPath m_cuttingLine; QPainterPath m_seamLine; QPainterPath m_grainline; + QPainterPath m_passmarks; QVector m_internalPaths; QVector m_internalPathsPenStyle; + QVector m_placeLabels; + QPointF m_rotationStartPoint; }; From 898a5a92c31472e9e29966a4f8f4d9d0d19a61a1 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 21 Nov 2020 13:26:38 +0100 Subject: [PATCH 28/34] Ppi after format name added --- src/app/puzzle/vpsheet.cpp | 60 ++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/src/app/puzzle/vpsheet.cpp b/src/app/puzzle/vpsheet.cpp index 59018f0bb..96796a0c1 100644 --- a/src/app/puzzle/vpsheet.cpp +++ b/src/app/puzzle/vpsheet.cpp @@ -141,69 +141,93 @@ QSizeF VPSheet::GetTemplateSize(PaperSizeTemplate tmpl) //--------------------------------------------------------------------------------------------------------------------- QString VPSheet::GetTemplateName(PaperSizeTemplate tmpl) { + QString tmplName; switch (tmpl) { case PaperSizeTemplate::A0: - return QString("A0"); + tmplName = QString("A0"); + break; case PaperSizeTemplate::A1: - return QString("A1"); + tmplName = QString("A1"); + break; case PaperSizeTemplate::A2: - return QString("A2"); + tmplName = QString("A2"); + break; case PaperSizeTemplate::A3: - return QString("A3"); + tmplName = QString("A3"); + break; case PaperSizeTemplate::A4: - return QString("A4"); + tmplName = QString("A4"); + break; case PaperSizeTemplate::Letter: - return tr("Letter"); + tmplName = tr("Letter"); + break; case PaperSizeTemplate::Legal: - return tr("Legal"); + tmplName = tr("Legal"); + break; case PaperSizeTemplate::Tabloid: - return tr("Tabloid"); + tmplName = tr("Tabloid"); + break; case PaperSizeTemplate::Roll24in: - return tr("Roll 24in"); + tmplName = tr("Roll 24in"); + break; case PaperSizeTemplate::Roll30in: - return tr("Roll 30in"); + tmplName = tr("Roll 30in"); + break; case PaperSizeTemplate::Roll36in: - return tr("Roll 36in"); + tmplName = tr("Roll 36in"); + break; case PaperSizeTemplate::Roll42in: - return tr("Roll 42in"); + tmplName = tr("Roll 42in"); + break; case PaperSizeTemplate::Roll44in: - return tr("Roll 44in"); + tmplName = tr("Roll 44in"); + break; case PaperSizeTemplate::Roll48in: - return tr("Roll 48in"); + tmplName = tr("Roll 48in"); + break; case PaperSizeTemplate::Roll62in: - return tr("Roll 62in"); + tmplName = tr("Roll 62in"); + break; case PaperSizeTemplate::Roll72in: - return tr("Roll 72in"); + tmplName = tr("Roll 72in"); + break; case PaperSizeTemplate::Custom: - return tr("Custom"); + tmplName = tr("Custom"); + break; default: break; } - return QString(""); + if(not tmplName.isEmpty()) + { + tmplName += " " + QStringLiteral("(%1ppi)").arg(PrintDPI); + } + + return tmplName; } //--------------------------------------------------------------------------------------------------------------------- PaperSizeTemplate VPSheet::GetTemplate(QSizeF size) { + Q_UNUSED(size); // TODO, float comparision not safe and problems with // inch / cm From b606497c4865d205319f26f6815d28b05bcf9bf8 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 21 Nov 2020 13:45:26 +0100 Subject: [PATCH 29/34] Persistence of sheet name --- src/app/puzzle/vpcarrousel.cpp | 9 +++++++++ src/app/puzzle/vpcarrousel.h | 5 +++++ src/app/puzzle/vpgraphicspiece.cpp | 6 ++++++ src/app/puzzle/vpmainwindow.cpp | 11 +++++++++++ src/app/puzzle/vpmainwindow.h | 7 +++++++ src/app/puzzle/vpmainwindow.ui | 2 +- 6 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/app/puzzle/vpcarrousel.cpp b/src/app/puzzle/vpcarrousel.cpp index 072b3a528..87287c739 100644 --- a/src/app/puzzle/vpcarrousel.cpp +++ b/src/app/puzzle/vpcarrousel.cpp @@ -83,6 +83,15 @@ void VPCarrousel::Refresh() RefreshOrientation(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPCarrousel::RefreshFocusedSheetName() +{ + // FIXME : This implementation will need a refactoring when we have multiple sheets, now it's not very nice!! + + ui->comboBoxPieceList->setItemText(1, tr("Pieces of ") + m_layout->GetFocusedSheet()->GetName()); +} + + //--------------------------------------------------------------------------------------------------------------------- void VPCarrousel::Clear() { diff --git a/src/app/puzzle/vpcarrousel.h b/src/app/puzzle/vpcarrousel.h index 4a3119a0e..2fb31a61b 100644 --- a/src/app/puzzle/vpcarrousel.h +++ b/src/app/puzzle/vpcarrousel.h @@ -65,6 +65,11 @@ public: */ void Refresh(); + /** + * @brief RefreshFocusedSheetName refreshes the name of the focused sheet + */ + void RefreshFocusedSheetName(); + /** * @brief Clear Clears the carrousel (removes everything) */ diff --git a/src/app/puzzle/vpgraphicspiece.cpp b/src/app/puzzle/vpgraphicspiece.cpp index eb0e4df4b..fda68e039 100644 --- a/src/app/puzzle/vpgraphicspiece.cpp +++ b/src/app/puzzle/vpgraphicspiece.cpp @@ -258,6 +258,12 @@ void VPGraphicsPiece::paint(QPainter *painter, const QStyleOptionGraphicsItem *o // TODO Detail & Piece Label +// QPointF position = m_piece->GetPatternTextPosition(); +// QStringList texts = m_piece->GetPatternText(); + +// painter->drawText(); + + // when using m_piece->GetItem(), the results were quite bad diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 4f02469f2..6a6efa726 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -1041,6 +1041,17 @@ void VPMainWindow::on_comboBoxLayoutUnit_currentIndexChanged(int index) SetPropertyTabTilesData(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::on_lineEditSheetName_textChanged(const QString &text) +{ + m_layout->GetFocusedSheet()->SetName(text); + + if(m_carrousel != nullptr) + { + m_carrousel->RefreshFocusedSheetName(); + } +} + //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_comboBoxSheetTemplate_currentIndexChanged(int index) { diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index 72287ecfa..aaf5bd0c0 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -285,6 +285,13 @@ private slots: */ void on_comboBoxLayoutUnit_currentIndexChanged(int index); + /** + * @brief on_lineEditSheetName_textChanged When the name of the sheet is changed + * in the sheet layout tab + * @param text + */ + void on_lineEditSheetName_textChanged(const QString &text); + /** * @brief on_comboBoxLayoutTemplate_currentIndexChanged When the template is * changed in the sheet property tab. diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 0951bd143..7d73aa8d2 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -176,7 +176,7 @@ QTabWidget::Rounded - 2 + 1 From b9e26f0b3fc127c43bea1a022bdc6b7d8ec0f15f Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 21 Nov 2020 14:24:07 +0100 Subject: [PATCH 30/34] Add a trash list and delete context menu function --- src/app/puzzle/vpcarrouselpiecelist.cpp | 12 ++++++++---- src/app/puzzle/vpcarrouselpiecelist.h | 1 - src/app/puzzle/vplayout.cpp | 10 +++++++++- src/app/puzzle/vplayout.h | 16 +++++++++------- src/app/puzzle/vpmaingraphicsview.cpp | 2 +- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/app/puzzle/vpcarrouselpiecelist.cpp b/src/app/puzzle/vpcarrouselpiecelist.cpp index c782bfeb7..a6bea85ba 100644 --- a/src/app/puzzle/vpcarrouselpiecelist.cpp +++ b/src/app/puzzle/vpcarrouselpiecelist.cpp @@ -197,10 +197,16 @@ void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event) { VPPieceList* sheetPieces = pieceItem->GetPiece()->GetPieceList()->GetLayout()->GetFocusedSheet()->GetPieceList(); QAction *moveAction = contextMenu.addAction(tr("Move to Sheet")); - QVariant data = QVariant::fromValue(sheetPieces); - moveAction->setData(data); + QVariant moveData = QVariant::fromValue(sheetPieces); + moveAction->setData(moveData); + + VPPieceList* trashPieceList = pieceItem->GetPiece()->GetPieceList()->GetLayout()->GetTrashPieceList(); + QAction *deleteAction = contextMenu.addAction(tr("Delete")); + QVariant deleteData = QVariant::fromValue(trashPieceList); + deleteAction->setData(deleteData); connect(moveAction, &QAction::triggered, this, &VPCarrouselPieceList::on_ActionPieceMovedToPieceList); + connect(deleteAction, &QAction::triggered, this, &VPCarrouselPieceList::on_ActionPieceMovedToPieceList); } // remove from piece list action @@ -235,8 +241,6 @@ void VPCarrouselPieceList::on_ActionPieceMovedToPieceList() } } - - //--------------------------------------------------------------------------------------------------------------------- void VPCarrouselPieceList::on_PieceAdded(VPPiece* piece) { diff --git a/src/app/puzzle/vpcarrouselpiecelist.h b/src/app/puzzle/vpcarrouselpiecelist.h index 48d8cf5ce..26f65d957 100644 --- a/src/app/puzzle/vpcarrouselpiecelist.h +++ b/src/app/puzzle/vpcarrouselpiecelist.h @@ -108,7 +108,6 @@ private slots: * @brief on_ActionPieceMovedToPieceList when a piece is moved to another piece list via a context menu */ void on_ActionPieceMovedToPieceList(); - }; #endif // VPCARROUSELPIECELIST_H diff --git a/src/app/puzzle/vplayout.cpp b/src/app/puzzle/vplayout.cpp index ef81a0694..539bc9e0c 100644 --- a/src/app/puzzle/vplayout.cpp +++ b/src/app/puzzle/vplayout.cpp @@ -38,6 +38,7 @@ Q_LOGGING_CATEGORY(pLayout, "p.layout") //--------------------------------------------------------------------------------------------------------------------- VPLayout::VPLayout() : m_unplacedPieceList(new VPPieceList(this)), + m_trashPieceList(new VPPieceList(this)), m_sheets(QList()) { m_unplacedPieceList->SetName(QObject::tr("Unplaced pieces")); @@ -48,6 +49,7 @@ VPLayout::~VPLayout() { qDeleteAll(m_sheets); delete m_unplacedPieceList; + delete m_trashPieceList; } //--------------------------------------------------------------------------------------------------------------------- @@ -56,6 +58,12 @@ VPPieceList* VPLayout::GetUnplacedPieceList() return m_unplacedPieceList; } +//--------------------------------------------------------------------------------------------------------------------- +VPPieceList* VPLayout::GetTrashPieceList() +{ + return m_trashPieceList; +} + //--------------------------------------------------------------------------------------------------------------------- VPSheet* VPLayout::AddSheet() { @@ -208,7 +216,7 @@ void VPLayout::MovePieceToPieceList(VPPiece* piece, VPPieceList* pieceList) pieceList->AddPiece(piece); // signal, that a piece was moved - emit PieceMovedToPieceList(piece, pieceListBefore,pieceList); + emit PieceMovedToPieceList(piece, pieceListBefore, pieceList); } diff --git a/src/app/puzzle/vplayout.h b/src/app/puzzle/vplayout.h index e8ca4d933..f8ff3a7ee 100644 --- a/src/app/puzzle/vplayout.h +++ b/src/app/puzzle/vplayout.h @@ -50,6 +50,12 @@ public: */ VPPieceList* GetUnplacedPieceList(); + /** + * @brief GetTrashPieceList Returns the piece list of the trash + * @return the pieces list of trashed pieces. + */ + VPPieceList* GetTrashPieceList(); + VPSheet* AddSheet(); VPSheet* AddSheet(VPSheet *sheet); QList GetSheets(); @@ -265,16 +271,12 @@ private: VPPieceList *m_unplacedPieceList; - QList m_sheets; - /** - TODO : To be replaced by m_focusedSheet - * @brief m_focusedPieceList pointer the the focused piece list, to which pieces will be - * added via drag and drop, or if no piece list is defined. + * @brief m_trashPieceList Holds the pieces that were deleted */ - VPPieceList *m_focusedPieceList{nullptr}; - + VPPieceList *m_trashPieceList; + QList m_sheets; VPSheet *m_focusedSheet{nullptr}; // format diff --git a/src/app/puzzle/vpmaingraphicsview.cpp b/src/app/puzzle/vpmaingraphicsview.cpp index 4c4c3d1a0..17a246d96 100644 --- a/src/app/puzzle/vpmaingraphicsview.cpp +++ b/src/app/puzzle/vpmaingraphicsview.cpp @@ -213,7 +213,7 @@ void VPMainGraphicsView::on_PieceMovedToPieceList(VPPiece *piece, VPPieceList *p scene()->removeItem(_graphicsPiece); m_graphicsPieces.removeAll(_graphicsPiece); } - else if(pieceListAfter != m_layout->GetUnplacedPieceList()) + else if(pieceListAfter != m_layout->GetUnplacedPieceList() && pieceListAfter != m_layout->GetTrashPieceList()) { if(_graphicsPiece == nullptr) { From 728b2c83c35dd729adaf5d02c6058e9821b8bfad Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 21 Nov 2020 14:28:28 +0100 Subject: [PATCH 31/34] Fix piece carrousel context menu crash --- src/app/puzzle/vpcarrouselpiecelist.cpp | 59 +++++++++++++------------ 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/src/app/puzzle/vpcarrouselpiecelist.cpp b/src/app/puzzle/vpcarrouselpiecelist.cpp index a6bea85ba..6ee1d6528 100644 --- a/src/app/puzzle/vpcarrouselpiecelist.cpp +++ b/src/app/puzzle/vpcarrouselpiecelist.cpp @@ -187,39 +187,42 @@ void VPCarrouselPieceList::dragMoveEvent(QDragMoveEvent* e) void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event) { QListWidgetItem* _item = currentItem(); - if(_item->type() == 1001) + if(_item != nullptr) { - VPCarrouselPiece *pieceItem = static_cast (_item); - - QMenu contextMenu; - - if(m_pieceList->GetSheet() == nullptr) + if(_item->type() == 1001) { - VPPieceList* sheetPieces = pieceItem->GetPiece()->GetPieceList()->GetLayout()->GetFocusedSheet()->GetPieceList(); - QAction *moveAction = contextMenu.addAction(tr("Move to Sheet")); - QVariant moveData = QVariant::fromValue(sheetPieces); - moveAction->setData(moveData); + VPCarrouselPiece *pieceItem = static_cast (_item); - VPPieceList* trashPieceList = pieceItem->GetPiece()->GetPieceList()->GetLayout()->GetTrashPieceList(); - QAction *deleteAction = contextMenu.addAction(tr("Delete")); - QVariant deleteData = QVariant::fromValue(trashPieceList); - deleteAction->setData(deleteData); + QMenu contextMenu; - connect(moveAction, &QAction::triggered, this, &VPCarrouselPieceList::on_ActionPieceMovedToPieceList); - connect(deleteAction, &QAction::triggered, this, &VPCarrouselPieceList::on_ActionPieceMovedToPieceList); + if(m_pieceList->GetSheet() == nullptr) + { + VPPieceList* sheetPieces = pieceItem->GetPiece()->GetPieceList()->GetLayout()->GetFocusedSheet()->GetPieceList(); + QAction *moveAction = contextMenu.addAction(tr("Move to Sheet")); + QVariant moveData = QVariant::fromValue(sheetPieces); + moveAction->setData(moveData); + + VPPieceList* trashPieceList = pieceItem->GetPiece()->GetPieceList()->GetLayout()->GetTrashPieceList(); + QAction *deleteAction = contextMenu.addAction(tr("Delete")); + QVariant deleteData = QVariant::fromValue(trashPieceList); + deleteAction->setData(deleteData); + + connect(moveAction, &QAction::triggered, this, &VPCarrouselPieceList::on_ActionPieceMovedToPieceList); + connect(deleteAction, &QAction::triggered, this, &VPCarrouselPieceList::on_ActionPieceMovedToPieceList); + } + + // remove from piece list action + if(m_pieceList->GetSheet() != nullptr) + { + VPPieceList* unplacedPieces = pieceItem->GetPiece()->GetPieceList()->GetLayout()->GetUnplacedPieceList(); + QAction *removeAction = contextMenu.addAction(tr("Remove from Sheet")); + QVariant data = QVariant::fromValue(unplacedPieces); + removeAction->setData(data); + connect(removeAction, &QAction::triggered, this, &VPCarrouselPieceList::on_ActionPieceMovedToPieceList); + } + + contextMenu.exec(event->globalPos()); } - - // remove from piece list action - if(m_pieceList->GetSheet() != nullptr) - { - VPPieceList* unplacedPieces = pieceItem->GetPiece()->GetPieceList()->GetLayout()->GetUnplacedPieceList(); - QAction *removeAction = contextMenu.addAction(tr("Remove from Sheet")); - QVariant data = QVariant::fromValue(unplacedPieces); - removeAction->setData(data); - connect(removeAction, &QAction::triggered, this, &VPCarrouselPieceList::on_ActionPieceMovedToPieceList); - } - - contextMenu.exec(event->globalPos()); } } From dd5970f8ba75a8c93addffa80edf88c92b019d61 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 21 Nov 2020 15:38:33 +0100 Subject: [PATCH 32/34] Improve Piece carrousel icon and drag icon --- src/app/puzzle/vpcarrouselpiece.cpp | 79 ++++++++++++++++++------- src/app/puzzle/vpcarrouselpiece.h | 2 +- src/app/puzzle/vpcarrouselpiecelist.cpp | 4 +- 3 files changed, 60 insertions(+), 25 deletions(-) diff --git a/src/app/puzzle/vpcarrouselpiece.cpp b/src/app/puzzle/vpcarrouselpiece.cpp index c5e651546..7fc443003 100644 --- a/src/app/puzzle/vpcarrouselpiece.cpp +++ b/src/app/puzzle/vpcarrouselpiece.cpp @@ -74,7 +74,7 @@ void VPCarrouselPiece::RefreshSelection() } //--------------------------------------------------------------------------------------------------------------------- -QIcon VPCarrouselPiece::CreatePieceIcon(const QSize &size) const +QIcon VPCarrouselPiece::CreatePieceIcon(const QSize &size, bool isDragIcon) const { QVector points = m_piece->GetMappedContourPoints(); // seamline if(points.isEmpty()) @@ -92,31 +92,66 @@ QIcon VPCarrouselPiece::CreatePieceIcon(const QSize &size) const qreal dx = canvas.center().x() - boundingRect.center().x(); qreal dy = canvas.center().y() - boundingRect.center().y(); - QPixmap pixmap(size); - pixmap.fill(QColor("white")); + QVector iconModes; + iconModes.append(QIcon::Normal); - QPainter painter; - painter.begin(&pixmap); - painter.setRenderHint(QPainter::Antialiasing); - painter.setRenderHint(QPainter::SmoothPixmapTransform); - - int spacing = 2; - painter.translate(spacing, spacing); - - qreal scaleFactorX = canvasSize * 100 / (size.width() - spacing*2) / 100; - qreal scaleFactorY = canvasSize * 100 / (size.height() - spacing*2) / 100; - painter.scale(1./scaleFactorX, 1./scaleFactorY); - painter.setPen(QPen(Qt::black, 0.8*qMax(scaleFactorX, scaleFactorY))); - - painter.translate(dx, dy); - - painter.drawPolygon(shape); - painter.end(); + if(not isDragIcon) + { + iconModes.append(QIcon::Selected); + } QIcon icon; - icon.addPixmap(pixmap,QIcon::Normal); - icon.addPixmap(pixmap,QIcon::Selected); + for(auto iconMode : iconModes) + { + QPixmap pixmap(size); + + if(not isDragIcon) + { + pixmap.fill(QColor(Qt::white)); + } + else + { + pixmap.fill(QColor(Qt::transparent)); + } + + QPainter painter; + painter.begin(&pixmap); + painter.setRenderHint(QPainter::Antialiasing); + painter.setRenderHint(QPainter::SmoothPixmapTransform); + + int spacing = 2; + + painter.translate(spacing, spacing); + + qreal scaleFactorX = canvasSize * 100 / (size.width() - spacing*2) / 100; + qreal scaleFactorY = canvasSize * 100 / (size.height() - spacing*2) / 100; + painter.scale(1./scaleFactorX, 1./scaleFactorY); + painter.setPen(QPen(Qt::black, 0.8*qMax(scaleFactorX, scaleFactorY))); + + if(not isDragIcon) + { + painter.translate(dx, dy); + } + else + { + painter.translate(-boundingRect.topLeft().x()+spacing, -boundingRect.topLeft().y()+spacing); + } + + if(iconMode == QIcon::Selected) + { + painter.setBrush(QBrush(QColor(255,160,160,60))); + } + else + { + painter.setBrush(QBrush(Qt::white)); + } + + painter.drawPolygon(shape); + painter.end(); + + icon.addPixmap(pixmap,iconMode); + } return icon; } diff --git a/src/app/puzzle/vpcarrouselpiece.h b/src/app/puzzle/vpcarrouselpiece.h index 9be77a355..d9d0a83f4 100644 --- a/src/app/puzzle/vpcarrouselpiece.h +++ b/src/app/puzzle/vpcarrouselpiece.h @@ -56,7 +56,7 @@ public: * @param size of the icon * @return the created icon */ - QIcon CreatePieceIcon(const QSize &size) const; + QIcon CreatePieceIcon(const QSize &size, bool isDragIcon = false) const; private: diff --git a/src/app/puzzle/vpcarrouselpiecelist.cpp b/src/app/puzzle/vpcarrouselpiecelist.cpp index 6ee1d6528..00ca57d9d 100644 --- a/src/app/puzzle/vpcarrouselpiecelist.cpp +++ b/src/app/puzzle/vpcarrouselpiecelist.cpp @@ -47,7 +47,7 @@ VPCarrouselPieceList::VPCarrouselPieceList(QWidget* parent) : QListWidget(parent), m_dragStart(QPoint()) { - setStyleSheet("QListWidget::item{border: 2px solid transparent; color: black;} QListWidget::item:selected {border: 2px solid red;}"); + setStyleSheet("QListWidget::item{border: 2px solid transparent; color: black;} QListWidget::item:selected {border: 2px solid rgb(255,160,160);}"); setContextMenuPolicy(Qt::DefaultContextMenu); setSelectionMode(QAbstractItemView::MultiSelection); setViewMode(QListView::IconMode); @@ -163,7 +163,7 @@ void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions) mimeData->SetPiecePtr(piece); mimeData->setObjectName("piecePointer"); - QPixmap pixmap = pieceItem->CreatePieceIcon(QSize(120,120)).pixmap(QSize(120,120)); + QPixmap pixmap = pieceItem->CreatePieceIcon(QSize(120,120), true).pixmap(QSize(120,120)); drag->setPixmap(pixmap); drag->setMimeData(mimeData); From cdff123231b6efc81dd4095439f509a3683f692d Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 21 Nov 2020 16:47:05 +0100 Subject: [PATCH 33/34] Refactor triangle position marks for tiled pdf --- src/app/puzzle/vptilefactory.cpp | 77 ++++++++++++-------------------- 1 file changed, 29 insertions(+), 48 deletions(-) diff --git a/src/app/puzzle/vptilefactory.cpp b/src/app/puzzle/vptilefactory.cpp index a243fa857..a929de02f 100644 --- a/src/app/puzzle/vptilefactory.cpp +++ b/src/app/puzzle/vptilefactory.cpp @@ -74,66 +74,31 @@ void VPTileFactory::drawTile(QPainter *painter, VPMainGraphicsView *graphicsView QSvgRenderer* svgRenderer = new QSvgRenderer(); - // FIXME here instead of creating 4 triangle, maybe create one and rotate it - - // ------------- prepare triangles for positioning - - // top triangle - QRectF rectTop = QRectF(tilesMargins.left()+ m_drawingAreaWidth/2 - UnitConvertor(0.5, Unit::Cm, Unit::Px), - tilesMargins.top(), + // ------------- prepare triangles for position marks + QRectF rectBasic = QRectF(-UnitConvertor(0.5, Unit::Cm, Unit::Px), + 0, UnitConvertor(1, Unit::Cm, Unit::Px), UnitConvertor(0.5, Unit::Cm, Unit::Px) ); - QPainterPath triangleTop; - triangleTop.moveTo(rectTop.topLeft()); - triangleTop.lineTo(rectTop.topRight()); - triangleTop.lineTo(rectTop.left() + (rectTop.width() / 2), rectTop.bottom()); - triangleTop.lineTo(rectTop.topLeft()); - - // left triangle - QRectF rectLeft = QRectF(tilesMargins.left(), - tilesMargins.top() + m_drawingAreaHeight/2 - UnitConvertor(0.5, Unit::Cm, Unit::Px), - UnitConvertor(0.5, Unit::Cm, Unit::Px), - UnitConvertor(1, Unit::Cm, Unit::Px) - ); - QPainterPath triangleLeft; - triangleLeft.moveTo(rectLeft.topLeft()); - triangleLeft.lineTo(rectLeft.right(), rectLeft.top() + (rectLeft.height() / 2)); - triangleLeft.lineTo(rectLeft.bottomLeft()); - triangleLeft.lineTo(rectLeft.topLeft()); - - // bottom triangle - QRectF rectBottom = QRectF(tilesMargins.left()+ m_drawingAreaWidth/2 - UnitConvertor(0.5, Unit::Cm, Unit::Px), - tilesMargins.top()+m_drawingAreaHeight - UnitConvertor(0.5, Unit::Cm, Unit::Px), - UnitConvertor(1, Unit::Cm, Unit::Px), - UnitConvertor(0.5, Unit::Cm, Unit::Px) - ); - QPainterPath triangleBottom; - triangleBottom.moveTo(rectBottom.bottomLeft()); - triangleBottom.lineTo(rectBottom.left() + (rectBottom.width() / 2), rectBottom.top()); - triangleBottom.lineTo(rectBottom.bottomRight()); - triangleBottom.lineTo(rectBottom.bottomLeft()); - - // right triangle - QRectF rectRight = QRectF(tilesMargins.left() + m_drawingAreaWidth - UnitConvertor(0.5, Unit::Cm, Unit::Px), - tilesMargins.top() + m_drawingAreaHeight/2 - UnitConvertor(0.5, Unit::Cm, Unit::Px), - UnitConvertor(0.5, Unit::Cm, Unit::Px), - UnitConvertor(1, Unit::Cm, Unit::Px) - ); - QPainterPath triangleRight; - triangleRight.moveTo(rectRight.topRight()); - triangleRight.lineTo(rectRight.bottomRight()); - triangleRight.lineTo(rectRight.left(), rectRight.top() + (rectRight.height() / 2)); - triangleRight.lineTo(rectRight.topRight()); + QPainterPath triangleBasic; + triangleBasic.moveTo(rectBasic.topLeft()); + triangleBasic.lineTo(rectBasic.topRight()); + triangleBasic.lineTo(rectBasic.left() + (rectBasic.width() / 2), rectBasic.bottom()); + triangleBasic.lineTo(rectBasic.topLeft()); QBrush triangleBush = QBrush(QColor(200,200,200)); + // add the tiles decorations (cutting and gluing lines, scissors, infos etc.) painter->setPen(penTileInfos); if(row > 0) { // add top triangle + QPainterPath triangleTop = + QTransform() + .translate(tilesMargins.left()+m_drawingAreaWidth/2, tilesMargins.top()) + .map(triangleBasic); painter->fillPath(triangleTop, triangleBush); // scissors along the top line @@ -168,6 +133,11 @@ void VPTileFactory::drawTile(QPainter *painter, VPMainGraphicsView *graphicsView if(col > 0) { // add left triangle + QPainterPath triangleLeft = + QTransform() + .translate(tilesMargins.left(), tilesMargins.top()+ m_drawingAreaHeight/2) + .rotate(-90) + .map(triangleBasic); painter->fillPath(triangleLeft, triangleBush); // scissors along the left line @@ -202,6 +172,12 @@ void VPTileFactory::drawTile(QPainter *painter, VPMainGraphicsView *graphicsView if(row < m_nbRow-1) { // add bottom triangle + QPainterPath triangleBottom = + QTransform() + .translate(tilesMargins.left()+ m_drawingAreaWidth/2, tilesMargins.top()+ m_drawingAreaHeight) + .rotate(180) + .map(triangleBasic); + painter->fillPath(triangleBottom, triangleBush); // dotted bottom line (for glueing) @@ -227,6 +203,11 @@ void VPTileFactory::drawTile(QPainter *painter, VPMainGraphicsView *graphicsView if(col < m_nbCol-1) { // add right triangle + QPainterPath triangleRight = + QTransform() + .translate(tilesMargins.left()+ m_drawingAreaWidth, tilesMargins.top()+ m_drawingAreaHeight/2) + .rotate(90) + .map(triangleBasic); painter->fillPath(triangleRight, triangleBush); // dotted right line (for glueing) From bbe27ec671d83a98ead5058215388bef33389e72 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sun, 22 Nov 2020 12:45:38 +0100 Subject: [PATCH 34/34] Nicer rotate cursor --- src/app/puzzle/share/resources/puzzleicon.qrc | 2 +- .../puzzleicon/64x64/cursorRotate.png | Bin 1635 -> 1452 bytes .../puzzleicon/64x64/cursorRotate@2x.png | Bin 2938 -> 2838 bytes .../puzzleicon/svg/cursor_rotate.svg | 79 +++++++++--------- src/app/puzzle/vpgraphicspiece.cpp | 46 +++++----- src/app/puzzle/vpgraphicspiece.h | 3 + 6 files changed, 70 insertions(+), 60 deletions(-) diff --git a/src/app/puzzle/share/resources/puzzleicon.qrc b/src/app/puzzle/share/resources/puzzleicon.qrc index 83dde8c8e..cf7527f52 100644 --- a/src/app/puzzle/share/resources/puzzleicon.qrc +++ b/src/app/puzzle/share/resources/puzzleicon.qrc @@ -9,12 +9,12 @@ puzzleicon/64x64/iconPortrait.png puzzleicon/64x64/iconGrainlineVertical.png puzzleicon/64x64/iconGrainlineHorizontal.png - puzzleicon/64x64/cursorRotate.png puzzleicon/64x64/iconProperties.png puzzleicon/svg/icon_scissors.svg puzzleicon/svg/icon_scissors_vertical.svg puzzleicon/svg/icon_scissors_horizontal.svg puzzleicon/16x16/roll.png puzzleicon/16x16/template.png + puzzleicon/svg/cursor_rotate.svg diff --git a/src/app/puzzle/share/resources/puzzleicon/64x64/cursorRotate.png b/src/app/puzzle/share/resources/puzzleicon/64x64/cursorRotate.png index a9ade2aee24b7949c0e842cd8722883b286671cd..831f77ed0f64e814e97bf13e33879215764ab62a 100644 GIT binary patch delta 1397 zcmV-*1&aFP46F-~BoYa5NLh0L00&_J00&_KmBYBUkwz$gIY~r8RCt`_n_X-bMHGO) zmKH?BOR=F9siK4cBGMpH6Qc>*Xs8jRiP6L#g3;hh#h9SR7augBJ{TkVpu|7?i4hY` z>Vrg!KZ#ai5F|pY5v@XqNU23ikrsM=IJbJ;?wvWacW1VgFF9$_yXVX~v$Hd2cFw{n zPDKW7Rs$D*0rfylLCz@r)(i9jdw>q$fNy6)biipqGq40$3^W%0r=bUE2igj z1$c$9fk$N@aEtFi<7h%=>@0&XmY2{^uw}Cn81x)}P!ib&oU08Y$ud|0tN|WLpgYVU z@I9~>S^Il|2}nLr56q>!nSKv&EzqgC_+m%nFOuxeYzH1ia)I%RcBTQhBJ)d zP!rH*WNp=qhQ}P87yw=c=4l);a5}I8xudR=<4l|JrwbQv0_qIc-Q(E!M&NvhAT?A1 z%YprW4t{h3Q%y#1D!TZ0>w3af^qEId+TYyRF$K=dy=x$bjbDZ*Gg<_oaqF81E@+`U=HiBw&&rwwF z@)k-mCZOAqUK6MMxk522{lJ$<&)<&h&$D>VR?L;yAB7L&6rZ#xX{8656rTW=0cWQk zqMdgwJ`N(O_W!uiqLf6sfmOgbA5j`uh5-h)1qXO9h8_|Ga`pQO%Z%)AT0b(n)60&0^OZUP$8@zE%A%)B|-$mS^gJfVCP! zIp9Iymxyvd=9A>CiQCUa#kiZzA$QrdHGamA?`6|~RGXTD-)1vX4g6*?avZoUb@$6> zBlf$0ug1`7g`r&ptjbbw2X>$LqTJR`LW&)121mSB%7}TuU)cR!u+-OmmjkMYL=Un>mfkvGGCS#SFP-6mJko3A8`Ksg(q=ujy$v!6|v-+HZ{YIoZ)Rp5%@NXpa(aL1tBiu(q2d`oT8@^WGdvV0vb{Ov*xEjp3J>sVkvPaXaNhQ8i3KwVJC00000NkvXXu0mjf Dr(~8| delta 1582 zcmV+}2GRMf3*!usBq9WJLP=Bz2nYy#2xN!=000SaNLh0L00&|K00&|LIC`1ekv1rQ z;7LS5RCt`#+i8p?RTaST-}E$eGn$rV7#tMB<_t#JL=c@$j0=#kg(W5gFzP46e1Nb= z68)etCIl1xKoE(78WW8stcj99SQ8f6A|Vh+7$-9#1_o%RyWi{So`w(SJ*R2vR#&~M zdhhv9ZaPy_b?!N*?mczyx#z9Ye>UKM3>=4zI27x!fcHCpr|}A&z;k%M^Y8y#PQcCh z59Tlrf2!2uY{xvz!QcpZ<6=)P4rU^n)`;T?Hjz)79!t5=ZQWfm{tTx{>bj-EIY zZ^{pHGo5>WfTK#t9>tgOv(EF=!XYaK%D3^wYGxH8Ad(NuZXD*|7O3b}1CA!0Z@z4hPp6v8Jo9KIKjJcqJ{t*Eu6|iP;rSUa6v@%{p#whAfvcNdP*$f zEwSgQ%tg}Po)e$1L2 z3JTdMK7m=R!9OZ0*(A4riNLpN0-2W${onJoI2d8t6^OyQ`a4md1veYeQ<4?8a>uCFQTfQiKQIkC$c zcDBlnVdJCt1wOOvKX!^J+2zv-!3+32z9m+J-7IhSM5iSjG~cU#<_$AWEMa>+yqFix znp)C!ij~#^-VvGNLGvRq0~qQ%u3LWd8vI+e zsW6N64H{IIi$!36&WcedXFc#Wy-$T{k(eAN?w0*RTXItOw@GJL^8(+ic|r%kI_a1B zVBUihVux480WEyB0VAq#gY1~L6Bn-Z@EMAag0@IM4HNszPvR8H3I0hjCk$KQBVI_B z?sH<{SBU+^S$m%GGq}1&#p~ca`6on2lo57rj<7|Ma2Te4YORf8h^I#CFMAPshioUb z@%73obBv5dNe>(%D#udi7gP8|FM<#BQLoP7u8IneiSn1-xVNIL!|d7jr>5%nt8{Ro z4@cFObe^CHlVStbJ!!7ufK$Z_N*UkA-_=kQ_BVSlFzIYHA8u8 zin|NQIS^OiHN^@l+c>kNuC?=Bdvc6<%HEmr?5L=16 z`$b4rn-@mEj%%=Q^CspqF1EruH8TQsi6!p5NNwMQP1400rK#&PI3Y^nuk6U|r8Is) z7~2+qE4;0ERs_{2#9JSF4#3Za5qTBdS?%`&(6=!T!R^ZZT<-P(=-D_&i%m|E&*N_g zq+?$=2@lBssmpH$rd=P|gr{Y%6mK1%UVZ1A;uLAABZjHix-YC2xrH}Ge7I$>>I{y( gahV=V*sJmZ)e=K|IZy?J00000NkvXXu0mh|g5jPV8~^|S diff --git a/src/app/puzzle/share/resources/puzzleicon/64x64/cursorRotate@2x.png b/src/app/puzzle/share/resources/puzzleicon/64x64/cursorRotate@2x.png index 0bde89ddb33bdafa5bc1c313903123bea9199419..4cb07973bd0b4ac100d9d6dc3456abf7dac3e6b1 100644 GIT binary patch delta 2794 zcmV7t3{D?X zF-;VvGv#3E`bEgM3L+-3EFi=#yX?FDao(M!b$6fpJont^^ZsVe>-%OLo1#klJF<>Sz184?DI?(f9WFb5aJXMxm4)k~er~u9YZUbIKzLh-*NC|iz zxE(ml>4-f5oCe$t>>!y550Xv50$`#m2NaPJ!1cg?8j_!2Q|Sg)1J{=A_e7u`m=EkE z`3bd=UBFF1t*(3W%V^+E;2_CQo{NQ0r{}7CQ3HGjdHqUyvRq0l@Lix<$8GuG65th* zpPV>lE%NGGXx7g!umxBRyAW5KkWG-+7eV;9eVoU>O z@%cY7aKgeT3_l-6c4GF+lVzr(|EACdoD;>E&4voz1kO9=bH|~-t-BFl}YFxepwktc@+`>N@DU`k*!vboMzUHrOXba{BMeiO{Eh! zH;j=5;5;OMLBqcr2@xB(T}f#e`F04$6p4lC`Pew8aJHgS6Inq%i&SV(#o!_Ou<|^H zejZDF37fm|4}C#2BDoG4{=US2ROu!qg+Vemq%(@jb?Er}AEpYIC@D0Nt-x~RIp7@p zx%q*pKqgPa-!n`UepN|X6gdjKj6@~pBa1>U`7y&ZqZ4p@$VAx(6clO7VWa}reZV!? zXDekDjTE~!48Bm6r2p8~0c26!4}6|tY#cSBvwi#-6J@Iv6vZV6fghlMm&}@GevZAr zR+uQdO+k@sDFMGmPU;keldz8v9>HM4?NUo6u4N7IQDe8|i{D`Hzb^(U8ACEho`Pg2 z5jgY{TGK*&~)pv}7ePIi!>F&QGxS z>*+yCzM`PSMp}rN+*kmA&c@!q-waaHte_-{>_MV{DkooaN+ps+W8>%LCQ9~ODhVT< zNMNTvl1qxm3hey7*+j`-EtQzcO5`2aW6pf+eBO;gBaK@vl?2HK;Ns{$C^Q;-HfIJY zxmZETK(Yrp*YEH1(Wyk**4WI$=Yo`sMmHeTiEK$0HTPee7qOdvj~@m_)b=A8LK-{{ zd>F|$XjQsq(J^|E8-ga2km}QxN;V>U3l|{C9v(exznqOO7r;K?2IOJo&k?WT8Jew@ zpEs(sGL7)B7t8P&zi|*$*C9w=HBnNDc`g6Pkt*Pxc$kIV0x*6S3##{5sQGr((qegR~cbFn`nx6Uts>@v&p z^M~-afJ`&X^7H=&di(;&CZjPp+ZVt;q1eZ)v&`k#r_?{CVTdOgY)@>JuxKz975{6a z!+7k=#JtpdG1rq)fg~>e9cf76vFEec|NO7gFk~o(BMqEirf=14z~>U!QiXYMr=et~ zD+BA0Q>#0F22p&GE5!xjD(ol!4IG@woCMrWaDmAuwG|hL3Z$Wy?E<({)2NRlT`}hfu1^@KXh2dN8biUGHHjI{v;-%b=6dsTxuOKB;9? zPPr1D$?rtDsJ3m1vR>H@OwcqeM@&JlOy6Q{qt& zK^CFwyB^>daSi|^L_AmyfQ>vze%ry-A`_+UvrQz_T4y>Eanc@83lbE`6Q>|~dD_0} zz&>5viUk80r6GGU?0A_0u0dYUT=;2TjN=%8kV@b$xEWjzl6(?-Io4n&(?Y3X3Ob1+L&;VoW{}qN2Gzjz=*CF~k{!Ur zn8p-}=}5yzmxJ#?%F)jyJ=IEUkTVe5a6k5a$i`f1nS)Nta}(JG+yi_tmXW=avw#PG zkO$T{#@mj={C-V7MSP2(SJoo+ji=+TFHtp8q~TWNS18W$bpoH(7(`szxtAlY-m7EM zcPwql(XuVvI#%`yC{IKS?g+ zAaEDZpyjZ<(uABOj$>yr4mkk)2&JRiMWO+?1^0Odu4EUoar7>2#}thb$O)oV=p9gX zB}ahYA;;j8*a*u#3$P&_Aa~_86**!X(h@2=|ifo+3Iq5rr<-ixnSUcT3 zSLDefPtt+_V*_u3#50?zZQu< wjG`}R{|J)a)e7uEatF4R|J~#9cyhr100sCRohJsulK=n!07*qoM6N<$g87{|{{R30 delta 2895 zcmV-V3$XN-7Wx*DBq9WJLP=Bz2nYy#2xN!=000SaNLh0L01nsy01nsz2S|~okv1rQ z_en%SRCt{2oqMp=RTalS=W@CC%0=T%C?;w=0tz2x11Un*Sc7OU$)>Whhh&W~rD!%; zq65;X1@xRC8+weXAwej{R60;f_<)Hp(|8398HmEYz~ymHf2?!hTsZgMv)6Awevk8+ zS;Nfb{C>ahUVEQ?etYk=*UphG1_C30f#Jn}&jR`ttuJsY&`|dIS5L4lz)QeCi}o^* z_aog6xzGX}GZdHrTvD_lmhb;M@Kn+MT(pChpHah*w*ub+{st60TMMulxDFWLxSTc0 z=m}g8JdgiM@5qh_x;houTU@ma38#iQ+{=nV9e!^FOu4%8Z z47kX?OR_-|a68GX_)4|{xX`Y9(#=F*BjGE~rsaVLfwL|8DRuM&?k9X@xwHeoY@mlF zpQVNifENj0LB8x|;4&+oO94}nNtMu*;@k4T0-$$v7bcT#zT@tsc z;AY@gz?BZ4@fz?P@ONMv;^GhzE$*djmK9r0>KYREZaE5=$$LWhcgnM-Wy>Vq6`niHf0_Z))j1ELqV-o}DjWeG_ z@5>Ja&`UR9vqEeE3FfGAGT%k#&lm6)#&(P=m0}CP)xO0hghpUJI-h>lx7df3LU#b& zeTz*HqtQhhZNuY#>S<5(FMl(AiA*rF(E0XyUjjd-6j%V>;!9+LX$H1p?%NG`njBiJ z5LZBA^=njzHloV;*0TomGk z8G=LtnfUq;@CLBo1B^mHiSrkmLNde_V6EXb-I2tZ)*FC!^I`!>>{vs`Zxq*D3h`+G z+mT#M%z8WP~~+St*Xc#1wytA8$bi_ zM&-3zE$YaBD$gjc8D+BpoR0pTVuwW?S!ILb8mkT9O%bl$ZcRmY(KLV|HXFd;2-nsc zKy-E>*+WbiV6y@Aig4}!tf|N@d1NGD!a$o1K%0&0ATlJW5gpS8V6_L(Hh>n38nRBS z;pdy`k-c~47ynRNmMv!=?SESi(Eebg!$>7wYWVPf5^c!oU3<&^wnurdtYdm$RecUP z5BMwbjl_MO<7raM8)GZ7ss&Q;R^W5MzrCu97t1i)PIs)q%tRl>6BnCjQ1G+ zR=Ti(FvqOfvQ0>&Y}Q$gncsGmUIGsRpTT?_83zhT*Khg)ltxZ9{QOBPu(JvOZ8o(Z z8WuW#&Fsd^ch8=9gC=AnVdzS&*0uttMQ~V}=z+QaR-QNya1e0`i~yS@#vwu_>OD`(bgW)$laLx@uQvHa6Hkn zdb+g98V{wMKVa_1E_;pnikrH&MdrRqJx!Q@Z^v(?imV|$ki!f^S9-}_L6T0^XwPMs z`*JmO9m2IANh(lqp<2OIYOw>An54MID2DLIg#Y$GpeSS($e~LXah1tKPD66c)Vluo z@h;5$c?k1qW8SBDkS)8$RBVR$8Rq_cLi@0vDjpWqf@ZpmIRnsT5LF*6(F^0Q1c(AEycD!Z@Z4{T46!Lv> zdr)%lH0Lqr40I>3v|=$q)Q1%Usx|L{x3hB%qCniUo#FReanVPj#`FoK)0yQerANUXYFP0O3u2BlAWU)BoCZ^Wf%+=_FbMhSD`sb8ul>!UEjXnfc$$OCS__#0*{n-lz zJO|J$R|s51JdQpe$#MP518XTU7TLU^t^7T}K%asKBa=AQ3fvD2^C_?b1CjB6art?@ zacBVJh*tRp;7i_BBipp96?jt!fkjRMzE0&Cwb0YhA0b+|UjWt+DEoSj>UOC<9Y|mu z^1jkpfXlJ~x<$MA-ho4BQ4(*q_5oa zNTZ51!+{GN-Fq1J-kwWl<3*|)a)8!CqL1l2vuPHzCX#+gW-#p`Rh`*lrKV=!a^MHJ z4Vf$1HNMPsaFdEl#6YU~tW!!aA=kc0-ai5S;j z1@%DhqBSGK$-&43*O|zF()IZ`K7q3Xjv^a&7Y2BCFfK->j(vQ);%qIz2P672QM?&= znDCB|gKfgk97-(c1AGUWI126fIM_;LFGlKV0KP)B@Uk>n8xjkci9@v~6R&hMp=~2@ zVI+?xgt5rE!J!=<7dr^dLIPG&O%BOIW@{xZ4fZJd!#5L2A0+92MAjR@Ix?R7a02im z;VZ(otp`3tZ9@zoYxpxs|Ijaw#7tgAt>P;(3iFdMl3=@ld&$^uyp}p-qo~UTA77Qe z0Licx*F(8t%^>v25JFfRvMP8NlD;+ei)~5y4VsJucb*wqNEru^$(jvCdk$H!+8D}QNJR5dp4 zQ`RBV$J23l?r^^AkJN|*X9JI6zX$l9&q9PGi9J9$n~`|=KZt(2XAj%`ToB`_rnMbgii_5k;V z5F3It_5kI)giOhP3OReAS~BwvkoE=uQkjc@(ZJ6QuE_*hXaFU4BDsOCK(>!}My&y) znB_=*qB(RtmtT7c%n0uQp6BG3z&RmB`6P=yKsjrXMlgf+%ea~O38- - - - - + viewBox="0 0 128 128" + sodipodi:docname="cursor_rotate.svg" + inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)" + inkscape:export-filename="/home/ronan/Workspace_cpp/valentina/src/app/puzzle/share/resources/puzzleicon/64x64/cursorRotate@2x.png" + inkscape:export-xdpi="96" + inkscape:export-ydpi="96"> + id="metadata899"> @@ -52,16 +29,38 @@ + + + inkscape:label="Image" + id="g901"> + id="path1502" + style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-feature-settings:normal;font-variation-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;shape-margin:0;inline-size:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:16.112;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate;stop-color:#000000;stop-opacity:1" + d="M 67.494019,3 C 45.635979,3 26.4721,14.832798 15.842825,32.458789 L 0,20.886257 10.290418,67.03627 50.234036,44.059307 30.104959,39.845618 c 7.88695,-12.507886 21.673605,-20.733626 37.38906,-20.733626 24.548563,0 44.393991,20.068893 44.393991,45.180711 0,25.111817 -19.845428,45.178617 -44.393991,45.178617 -18.793455,0 -34.829896,-11.76047 -41.31635,-28.542147 -12.799702,5.691961 -3.295568,1.770075 -14.669238,6.556583 C 20.55829,109.77568 42.229103,125.58331 67.494019,125.58331 100.88055,125.58331 128,97.98361 128,64.292703 128,30.601797 100.88055,3 67.494019,3 Z" + sodipodi:nodetypes="scccccsssccsss" /> diff --git a/src/app/puzzle/vpgraphicspiece.cpp b/src/app/puzzle/vpgraphicspiece.cpp index fda68e039..c0973ce34 100644 --- a/src/app/puzzle/vpgraphicspiece.cpp +++ b/src/app/puzzle/vpgraphicspiece.cpp @@ -31,13 +31,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include "vppiece.h" #include "vppiecelist.h" @@ -61,8 +61,13 @@ VPGraphicsPiece::VPGraphicsPiece(VPPiece *piece, QGraphicsItem *parent) : m_internalPaths(QVector()), m_internalPathsPenStyle(QVector()), m_placeLabels(QVector()), - m_rotationStartPoint(QPointF()) + m_rotationStartPoint(QPointF()), + m_rotateCursor(QCursor()) { + + QPixmap cursor_pixmap = QIcon("://puzzleicon/svg/cursor_rotate.svg").pixmap(QSize(32,32)); + m_rotateCursor= QCursor(cursor_pixmap, 16, 16); + Init(); } @@ -276,11 +281,24 @@ void VPGraphicsPiece::mousePressEvent(QGraphicsSceneMouseEvent *event) //perform the default behaviour QGraphicsItem::mousePressEvent(event); - // change the cursor when clicking left button + // change the cursor when clicking the left button + if((event->button() == Qt::LeftButton)) + { + if(event->modifiers() & Qt::AltModifier) + { + setCursor(m_rotateCursor); + } + else + { + setCursor(Qt::ClosedHandCursor); + } + } + + + // change the selected state when clicking left button if (event->button() == Qt::LeftButton) { setSelected(true); - setCursor(Qt::ClosedHandCursor); if (event->modifiers() & Qt::ControlModifier) { @@ -295,12 +313,6 @@ void VPGraphicsPiece::mousePressEvent(QGraphicsSceneMouseEvent *event) if((event->button() == Qt::LeftButton) && (event->modifiers() & Qt::AltModifier)) { m_rotationStartPoint = event->scenePos(); - - QPixmap cursor_pixmap = QPixmap(":/cursor_rotate"); - cursor_pixmap = cursor_pixmap.scaledToWidth(32); - QCursor cursor_rotate = QCursor(cursor_pixmap, 16, 16); - - setCursor(cursor_rotate); } } @@ -309,6 +321,8 @@ void VPGraphicsPiece::mouseMoveEvent(QGraphicsSceneMouseEvent * event) { if((event->buttons() == Qt::LeftButton) && (event->modifiers() & Qt::AltModifier)) { + //FIXME: it flickers between the arrow cursor and the rotate cursor + setCursor(m_rotateCursor); QPointF rotationNewPoint = event->scenePos(); QPointF rotationCenter = sceneBoundingRect().center(); @@ -365,20 +379,14 @@ void VPGraphicsPiece::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VPGraphicsPiece::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { - if(event->modifiers() & Qt::AltModifier) { - // TODO FIXME: find a more efficient way - - QPixmap cursor_pixmap = QPixmap(":/cursor_rotate"); - cursor_pixmap = cursor_pixmap.scaledToWidth(32); - QCursor cursor_rotate = QCursor(cursor_pixmap, 16, 16); - - setCursor(cursor_rotate); + //FIXME: it flickers between the arrow cursor and the rotate cursor + setCursor(m_rotateCursor); } else { - setCursor(QCursor(Qt::OpenHandCursor)); + setCursor(Qt::OpenHandCursor); } } diff --git a/src/app/puzzle/vpgraphicspiece.h b/src/app/puzzle/vpgraphicspiece.h index aefcca155..f7238a759 100644 --- a/src/app/puzzle/vpgraphicspiece.h +++ b/src/app/puzzle/vpgraphicspiece.h @@ -30,6 +30,7 @@ #define VPGRAPHICSPIECE_H #include +#include class VPPiece; @@ -105,6 +106,8 @@ private: QVector m_placeLabels; QPointF m_rotationStartPoint; + + QCursor m_rotateCursor; }; #endif // VPGRAPHICSPIECE_H