mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-22 09:40:52 +01:00
replace tabs by 4 spaces
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef CUSTOM_ELEMENT_GRAPHIC_PART_H
|
||||
#define CUSTOM_ELEMENT_GRAPHIC_PART_H
|
||||
@@ -26,308 +26,308 @@ class QPainter;
|
||||
|
||||
|
||||
/**
|
||||
@brief The CustomElementGraphicPart class
|
||||
This class is the base for all home-made primitive like line,
|
||||
rectangle, ellipse etc....
|
||||
It provides methods and enums to manage style attributes available
|
||||
for primitive (color, pen style, etc...)
|
||||
@brief The CustomElementGraphicPart class
|
||||
This class is the base for all home-made primitive like line,
|
||||
rectangle, ellipse etc....
|
||||
It provides methods and enums to manage style attributes available
|
||||
for primitive (color, pen style, etc...)
|
||||
*/
|
||||
class CustomElementGraphicPart : public QGraphicsObject, public CustomElementPart
|
||||
{
|
||||
#define SHADOWS_HEIGHT 4.0
|
||||
#define SHADOWS_HEIGHT 4.0
|
||||
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(LineStyle line_style READ lineStyle WRITE setLineStyle)
|
||||
Q_PROPERTY(LineWeight line_weight READ lineWeight WRITE setLineWeight)
|
||||
Q_PROPERTY(Filling filling READ filling WRITE setFilling)
|
||||
Q_PROPERTY(Color color READ color WRITE setColor)
|
||||
Q_PROPERTY(bool antialias READ antialiased WRITE setAntialiased)
|
||||
Q_PROPERTY(LineStyle line_style READ lineStyle WRITE setLineStyle)
|
||||
Q_PROPERTY(LineWeight line_weight READ lineWeight WRITE setLineWeight)
|
||||
Q_PROPERTY(Filling filling READ filling WRITE setFilling)
|
||||
Q_PROPERTY(Color color READ color WRITE setColor)
|
||||
Q_PROPERTY(bool antialias READ antialiased WRITE setAntialiased)
|
||||
|
||||
public:
|
||||
//Line style
|
||||
enum LineStyle {NormalStyle,
|
||||
DashedStyle,
|
||||
DottedStyle,
|
||||
DashdottedStyle};
|
||||
Q_ENUM (LineStyle)
|
||||
public:
|
||||
//Line style
|
||||
enum LineStyle {NormalStyle,
|
||||
DashedStyle,
|
||||
DottedStyle,
|
||||
DashdottedStyle};
|
||||
Q_ENUM (LineStyle)
|
||||
|
||||
//Line weight : invisible, 0px, 1px, 2px, 5px
|
||||
enum LineWeight {NoneWeight,
|
||||
ThinWeight,
|
||||
NormalWeight,
|
||||
UltraWeight,
|
||||
BigWeight};
|
||||
Q_ENUM (LineWeight)
|
||||
//Line weight : invisible, 0px, 1px, 2px, 5px
|
||||
enum LineWeight {NoneWeight,
|
||||
ThinWeight,
|
||||
NormalWeight,
|
||||
UltraWeight,
|
||||
BigWeight};
|
||||
Q_ENUM (LineWeight)
|
||||
|
||||
//Filling color of the part : NoneFilling -> No filling (i.e. transparent)
|
||||
enum Filling { NoneFilling, BlackFilling, WhiteFilling,
|
||||
GreenFilling, RedFilling, BlueFilling,
|
||||
GrayFilling, BrunFilling, YellowFilling,
|
||||
CyanFilling, MagentaFilling, LightgrayFilling,
|
||||
OrangeFilling, PurpleFilling,
|
||||
HTMLPinkPinkFilling, HTMLPinkLightPinkFilling,
|
||||
HTMLPinkHotPinkFilling, HTMLPinkDeepPinkFilling,
|
||||
HTMLPinkPaleVioletRedFilling,
|
||||
HTMLPinkMediumVioletRedFilling,
|
||||
HTMLRedLightSalmonFilling, HTMLRedSalmonFilling,
|
||||
HTMLRedDarkSalmonFilling,
|
||||
HTMLRedLightCoralFilling,
|
||||
HTMLRedIndianRedFilling, HTMLRedCrimsonFilling,
|
||||
HTMLRedFirebrickFilling, HTMLRedDarkRedFilling,
|
||||
HTMLRedRedFilling, HTMLOrangeOrangeRedFilling,
|
||||
HTMLOrangeTomatoFilling, HTMLOrangeCoralFilling,
|
||||
HTMLOrangeDarkOrangeFilling,
|
||||
HTMLOrangeOrangeFilling, HTMLYellowYellowFilling,
|
||||
HTMLYellowLightYellowFilling,
|
||||
HTMLYellowLemonChiffonFilling,
|
||||
HTMLYellowLightGoldenrodYellowFilling,
|
||||
HTMLYellowPapayaWhipFilling,
|
||||
HTMLYellowMoccasinFilling,
|
||||
HTMLYellowPeachPuffFilling,
|
||||
HTMLYellowPaleGoldenrodFilling,
|
||||
HTMLYellowKhakiFilling,
|
||||
HTMLYellowDarkKhakiFilling,
|
||||
HTMLYellowGoldFilling, HTMLBrownCornsilkFilling,
|
||||
HTMLBrownBlanchedAlmondFilling,
|
||||
HTMLBrownBisqueFilling,
|
||||
HTMLBrownNavajoWhiteFilling,
|
||||
HTMLBrownWheatFilling, HTMLBrownBurlywoodFilling,
|
||||
HTMLBrownTanFilling, HTMLBrownRosyBrownFilling,
|
||||
HTMLBrownSandyBrownFilling,
|
||||
HTMLBrownGoldenrodFilling,
|
||||
HTMLBrownDarkGoldenrodFilling,
|
||||
HTMLBrownPeruFilling, HTMLBrownChocolateFilling,
|
||||
HTMLBrownSaddleBrownFilling,
|
||||
HTMLBrownSiennaFilling, HTMLBrownBrownFilling,
|
||||
HTMLBrownMaroonFilling,
|
||||
HTMLGreenDarkOliveGreenFilling,
|
||||
HTMLGreenOliveFilling, HTMLGreenOliveDrabFilling,
|
||||
HTMLGreenYellowGreenFilling,
|
||||
HTMLGreenLimeGreenFilling, HTMLGreenLimeFilling,
|
||||
HTMLGreenLawnGreenFilling,
|
||||
HTMLGreenChartreuseFilling,
|
||||
HTMLGreenGreenYellowFilling,
|
||||
HTMLGreenSpringGreenFilling,
|
||||
HTMLGreenMediumSpringGreenFilling,
|
||||
HTMLGreenLightGreenFilling,
|
||||
HTMLGreenPaleGreenFilling,
|
||||
HTMLGreenDarkSeaGreenFilling,
|
||||
HTMLGreenMediumAquamarineFilling,
|
||||
HTMLGreenMediumSeaGreenFilling,
|
||||
HTMLGreenSeaGreenFilling,
|
||||
HTMLGreenForestGreenFilling,
|
||||
HTMLGreenGreenFilling, HTMLGreenDarkGreenFilling,
|
||||
HTMLCyanAquaFilling, HTMLCyanCyanFilling,
|
||||
HTMLCyanLightCyanFilling,
|
||||
HTMLCyanPaleTurquoiseFilling,
|
||||
HTMLCyanAquamarineFilling,
|
||||
HTMLCyanTurquoiseFilling,
|
||||
HTMLCyanMediumTurquoiseFilling,
|
||||
HTMLCyanDarkTurquoiseFilling,
|
||||
HTMLCyanLightSeaGreenFilling,
|
||||
HTMLCyanCadetBlueFilling,
|
||||
HTMLCyanDarkCyanFilling, HTMLCyanTealFilling,
|
||||
HTMLBlueLightSteelBlueFilling,
|
||||
HTMLBluePowderBlueFilling,
|
||||
HTMLBlueLightBlueFilling, HTMLBlueSkyBlueFilling,
|
||||
HTMLBlueLightSkyBlueFilling,
|
||||
HTMLBlueDeepSkyBlueFilling,
|
||||
HTMLBlueDodgerBlueFilling,
|
||||
HTMLBlueCornflowerBlueFilling,
|
||||
HTMLBlueSteelBlueFilling,
|
||||
HTMLBlueRoyalBlueFilling, HTMLBlueBlueFilling,
|
||||
HTMLBlueMediumBlueFilling,
|
||||
HTMLBlueDarkBlueFilling, HTMLBlueNavyFilling,
|
||||
HTMLBlueMidnightBlueFilling,
|
||||
HTMLPurpleLavenderFilling,
|
||||
HTMLPurpleThistleFilling, HTMLPurplePlumFilling,
|
||||
HTMLPurpleVioletFilling, HTMLPurpleOrchidFilling,
|
||||
HTMLPurpleFuchsiaFilling,
|
||||
HTMLPurpleMagentaFilling,
|
||||
HTMLPurpleMediumOrchidFilling,
|
||||
HTMLPurpleMediumPurpleFilling,
|
||||
HTMLPurpleBlueVioletFilling,
|
||||
HTMLPurpleDarkVioletFilling,
|
||||
HTMLPurpleDarkOrchidFilling,
|
||||
HTMLPurpleDarkMagentaFilling,
|
||||
HTMLPurplePurpleFilling, HTMLPurpleIndigoFilling,
|
||||
HTMLPurpleDarkSlateBlueFilling,
|
||||
HTMLPurpleSlateBlueFilling,
|
||||
HTMLPurpleMediumSlateBlueFilling,
|
||||
HTMLWhiteWhiteFilling, HTMLWhiteSnowFilling,
|
||||
HTMLWhiteHoneydewFilling,
|
||||
HTMLWhiteMintCreamFilling, HTMLWhiteAzureFilling,
|
||||
HTMLWhiteAliceBlueFilling,
|
||||
HTMLWhiteGhostWhiteFilling,
|
||||
HTMLWhiteWhiteSmokeFilling,
|
||||
HTMLWhiteSeashellFilling, HTMLWhiteBeigeFilling,
|
||||
HTMLWhiteOldLaceFilling,
|
||||
HTMLWhiteFloralWhiteFilling,
|
||||
HTMLWhiteIvoryFilling,
|
||||
HTMLWhiteAntiqueWhiteFilling,
|
||||
HTMLWhiteLinenFilling,
|
||||
HTMLWhiteLavenderBlushFilling,
|
||||
HTMLWhiteMistyRoseFilling,
|
||||
HTMLGrayGainsboroFilling,
|
||||
HTMLGrayLightGrayFilling, HTMLGraySilverFilling,
|
||||
HTMLGrayDarkGrayFilling, HTMLGrayGrayFilling,
|
||||
HTMLGrayDimGrayFilling,
|
||||
HTMLGrayLightSlateGrayFilling,
|
||||
HTMLGraySlateGrayFilling,
|
||||
HTMLGrayDarkSlateGrayFilling,
|
||||
HTMLGrayBlackFilling, HorFilling, VerFilling,
|
||||
BdiagFilling, FdiagFilling};
|
||||
Q_ENUM (Filling)
|
||||
//Filling color of the part : NoneFilling -> No filling (i.e. transparent)
|
||||
enum Filling { NoneFilling, BlackFilling, WhiteFilling,
|
||||
GreenFilling, RedFilling, BlueFilling,
|
||||
GrayFilling, BrunFilling, YellowFilling,
|
||||
CyanFilling, MagentaFilling, LightgrayFilling,
|
||||
OrangeFilling, PurpleFilling,
|
||||
HTMLPinkPinkFilling, HTMLPinkLightPinkFilling,
|
||||
HTMLPinkHotPinkFilling, HTMLPinkDeepPinkFilling,
|
||||
HTMLPinkPaleVioletRedFilling,
|
||||
HTMLPinkMediumVioletRedFilling,
|
||||
HTMLRedLightSalmonFilling, HTMLRedSalmonFilling,
|
||||
HTMLRedDarkSalmonFilling,
|
||||
HTMLRedLightCoralFilling,
|
||||
HTMLRedIndianRedFilling, HTMLRedCrimsonFilling,
|
||||
HTMLRedFirebrickFilling, HTMLRedDarkRedFilling,
|
||||
HTMLRedRedFilling, HTMLOrangeOrangeRedFilling,
|
||||
HTMLOrangeTomatoFilling, HTMLOrangeCoralFilling,
|
||||
HTMLOrangeDarkOrangeFilling,
|
||||
HTMLOrangeOrangeFilling, HTMLYellowYellowFilling,
|
||||
HTMLYellowLightYellowFilling,
|
||||
HTMLYellowLemonChiffonFilling,
|
||||
HTMLYellowLightGoldenrodYellowFilling,
|
||||
HTMLYellowPapayaWhipFilling,
|
||||
HTMLYellowMoccasinFilling,
|
||||
HTMLYellowPeachPuffFilling,
|
||||
HTMLYellowPaleGoldenrodFilling,
|
||||
HTMLYellowKhakiFilling,
|
||||
HTMLYellowDarkKhakiFilling,
|
||||
HTMLYellowGoldFilling, HTMLBrownCornsilkFilling,
|
||||
HTMLBrownBlanchedAlmondFilling,
|
||||
HTMLBrownBisqueFilling,
|
||||
HTMLBrownNavajoWhiteFilling,
|
||||
HTMLBrownWheatFilling, HTMLBrownBurlywoodFilling,
|
||||
HTMLBrownTanFilling, HTMLBrownRosyBrownFilling,
|
||||
HTMLBrownSandyBrownFilling,
|
||||
HTMLBrownGoldenrodFilling,
|
||||
HTMLBrownDarkGoldenrodFilling,
|
||||
HTMLBrownPeruFilling, HTMLBrownChocolateFilling,
|
||||
HTMLBrownSaddleBrownFilling,
|
||||
HTMLBrownSiennaFilling, HTMLBrownBrownFilling,
|
||||
HTMLBrownMaroonFilling,
|
||||
HTMLGreenDarkOliveGreenFilling,
|
||||
HTMLGreenOliveFilling, HTMLGreenOliveDrabFilling,
|
||||
HTMLGreenYellowGreenFilling,
|
||||
HTMLGreenLimeGreenFilling, HTMLGreenLimeFilling,
|
||||
HTMLGreenLawnGreenFilling,
|
||||
HTMLGreenChartreuseFilling,
|
||||
HTMLGreenGreenYellowFilling,
|
||||
HTMLGreenSpringGreenFilling,
|
||||
HTMLGreenMediumSpringGreenFilling,
|
||||
HTMLGreenLightGreenFilling,
|
||||
HTMLGreenPaleGreenFilling,
|
||||
HTMLGreenDarkSeaGreenFilling,
|
||||
HTMLGreenMediumAquamarineFilling,
|
||||
HTMLGreenMediumSeaGreenFilling,
|
||||
HTMLGreenSeaGreenFilling,
|
||||
HTMLGreenForestGreenFilling,
|
||||
HTMLGreenGreenFilling, HTMLGreenDarkGreenFilling,
|
||||
HTMLCyanAquaFilling, HTMLCyanCyanFilling,
|
||||
HTMLCyanLightCyanFilling,
|
||||
HTMLCyanPaleTurquoiseFilling,
|
||||
HTMLCyanAquamarineFilling,
|
||||
HTMLCyanTurquoiseFilling,
|
||||
HTMLCyanMediumTurquoiseFilling,
|
||||
HTMLCyanDarkTurquoiseFilling,
|
||||
HTMLCyanLightSeaGreenFilling,
|
||||
HTMLCyanCadetBlueFilling,
|
||||
HTMLCyanDarkCyanFilling, HTMLCyanTealFilling,
|
||||
HTMLBlueLightSteelBlueFilling,
|
||||
HTMLBluePowderBlueFilling,
|
||||
HTMLBlueLightBlueFilling, HTMLBlueSkyBlueFilling,
|
||||
HTMLBlueLightSkyBlueFilling,
|
||||
HTMLBlueDeepSkyBlueFilling,
|
||||
HTMLBlueDodgerBlueFilling,
|
||||
HTMLBlueCornflowerBlueFilling,
|
||||
HTMLBlueSteelBlueFilling,
|
||||
HTMLBlueRoyalBlueFilling, HTMLBlueBlueFilling,
|
||||
HTMLBlueMediumBlueFilling,
|
||||
HTMLBlueDarkBlueFilling, HTMLBlueNavyFilling,
|
||||
HTMLBlueMidnightBlueFilling,
|
||||
HTMLPurpleLavenderFilling,
|
||||
HTMLPurpleThistleFilling, HTMLPurplePlumFilling,
|
||||
HTMLPurpleVioletFilling, HTMLPurpleOrchidFilling,
|
||||
HTMLPurpleFuchsiaFilling,
|
||||
HTMLPurpleMagentaFilling,
|
||||
HTMLPurpleMediumOrchidFilling,
|
||||
HTMLPurpleMediumPurpleFilling,
|
||||
HTMLPurpleBlueVioletFilling,
|
||||
HTMLPurpleDarkVioletFilling,
|
||||
HTMLPurpleDarkOrchidFilling,
|
||||
HTMLPurpleDarkMagentaFilling,
|
||||
HTMLPurplePurpleFilling, HTMLPurpleIndigoFilling,
|
||||
HTMLPurpleDarkSlateBlueFilling,
|
||||
HTMLPurpleSlateBlueFilling,
|
||||
HTMLPurpleMediumSlateBlueFilling,
|
||||
HTMLWhiteWhiteFilling, HTMLWhiteSnowFilling,
|
||||
HTMLWhiteHoneydewFilling,
|
||||
HTMLWhiteMintCreamFilling, HTMLWhiteAzureFilling,
|
||||
HTMLWhiteAliceBlueFilling,
|
||||
HTMLWhiteGhostWhiteFilling,
|
||||
HTMLWhiteWhiteSmokeFilling,
|
||||
HTMLWhiteSeashellFilling, HTMLWhiteBeigeFilling,
|
||||
HTMLWhiteOldLaceFilling,
|
||||
HTMLWhiteFloralWhiteFilling,
|
||||
HTMLWhiteIvoryFilling,
|
||||
HTMLWhiteAntiqueWhiteFilling,
|
||||
HTMLWhiteLinenFilling,
|
||||
HTMLWhiteLavenderBlushFilling,
|
||||
HTMLWhiteMistyRoseFilling,
|
||||
HTMLGrayGainsboroFilling,
|
||||
HTMLGrayLightGrayFilling, HTMLGraySilverFilling,
|
||||
HTMLGrayDarkGrayFilling, HTMLGrayGrayFilling,
|
||||
HTMLGrayDimGrayFilling,
|
||||
HTMLGrayLightSlateGrayFilling,
|
||||
HTMLGraySlateGrayFilling,
|
||||
HTMLGrayDarkSlateGrayFilling,
|
||||
HTMLGrayBlackFilling, HorFilling, VerFilling,
|
||||
BdiagFilling, FdiagFilling};
|
||||
Q_ENUM (Filling)
|
||||
|
||||
//Line color
|
||||
enum Color {
|
||||
BlackColor, WhiteColor, GreenColor, RedColor, BlueColor,
|
||||
GrayColor, BrunColor, YellowColor, CyanColor,
|
||||
MagentaColor, LightgrayColor, OrangeColor, PurpleColor,
|
||||
HTMLPinkPinkColor, HTMLPinkLightPinkColor,
|
||||
HTMLPinkHotPinkColor, HTMLPinkDeepPinkColor,
|
||||
HTMLPinkPaleVioletRedColor,
|
||||
HTMLPinkMediumVioletRedColor, HTMLRedLightSalmonColor,
|
||||
HTMLRedSalmonColor, HTMLRedDarkSalmonColor,
|
||||
HTMLRedLightCoralColor, HTMLRedIndianRedColor,
|
||||
HTMLRedCrimsonColor, HTMLRedFirebrickColor,
|
||||
HTMLRedDarkRedColor, HTMLRedRedColor,
|
||||
HTMLOrangeOrangeRedColor, HTMLOrangeTomatoColor,
|
||||
HTMLOrangeCoralColor, HTMLOrangeDarkOrangeColor,
|
||||
HTMLOrangeOrangeColor, HTMLYellowYellowColor,
|
||||
HTMLYellowLightYellowColor, HTMLYellowLemonChiffonColor,
|
||||
HTMLYellowLightGoldenrodYellowColor,
|
||||
HTMLYellowPapayaWhipColor, HTMLYellowMoccasinColor,
|
||||
HTMLYellowPeachPuffColor, HTMLYellowPaleGoldenrodColor,
|
||||
HTMLYellowKhakiColor, HTMLYellowDarkKhakiColor,
|
||||
HTMLYellowGoldColor, HTMLBrownCornsilkColor,
|
||||
HTMLBrownBlanchedAlmondColor, HTMLBrownBisqueColor,
|
||||
HTMLBrownNavajoWhiteColor, HTMLBrownWheatColor,
|
||||
HTMLBrownBurlywoodColor, HTMLBrownTanColor,
|
||||
HTMLBrownRosyBrownColor, HTMLBrownSandyBrownColor,
|
||||
HTMLBrownGoldenrodColor, HTMLBrownDarkGoldenrodColor,
|
||||
HTMLBrownPeruColor, HTMLBrownChocolateColor,
|
||||
HTMLBrownSaddleBrownColor, HTMLBrownSiennaColor,
|
||||
HTMLBrownBrownColor, HTMLBrownMaroonColor,
|
||||
HTMLGreenDarkOliveGreenColor, HTMLGreenOliveColor,
|
||||
HTMLGreenOliveDrabColor, HTMLGreenYellowGreenColor,
|
||||
HTMLGreenLimeGreenColor, HTMLGreenLimeColor,
|
||||
HTMLGreenLawnGreenColor, HTMLGreenChartreuseColor,
|
||||
HTMLGreenGreenYellowColor, HTMLGreenSpringGreenColor,
|
||||
HTMLGreenMediumSpringGreenColor,
|
||||
HTMLGreenLightGreenColor, HTMLGreenPaleGreenColor,
|
||||
HTMLGreenDarkSeaGreenColor,
|
||||
HTMLGreenMediumAquamarineColor,
|
||||
HTMLGreenMediumSeaGreenColor, HTMLGreenSeaGreenColor,
|
||||
HTMLGreenForestGreenColor, HTMLGreenGreenColor,
|
||||
HTMLGreenDarkGreenColor, HTMLCyanAquaColor,
|
||||
HTMLCyanCyanColor, HTMLCyanLightCyanColor,
|
||||
HTMLCyanPaleTurquoiseColor, HTMLCyanAquamarineColor,
|
||||
HTMLCyanTurquoiseColor, HTMLCyanMediumTurquoiseColor,
|
||||
HTMLCyanDarkTurquoiseColor, HTMLCyanLightSeaGreenColor,
|
||||
HTMLCyanCadetBlueColor, HTMLCyanDarkCyanColor,
|
||||
HTMLCyanTealColor, HTMLBlueLightSteelBlueColor,
|
||||
HTMLBluePowderBlueColor, HTMLBlueLightBlueColor,
|
||||
HTMLBlueSkyBlueColor, HTMLBlueLightSkyBlueColor,
|
||||
HTMLBlueDeepSkyBlueColor, HTMLBlueDodgerBlueColor,
|
||||
HTMLBlueCornflowerBlueColor, HTMLBlueSteelBlueColor,
|
||||
HTMLBlueRoyalBlueColor, HTMLBlueBlueColor,
|
||||
HTMLBlueMediumBlueColor, HTMLBlueDarkBlueColor,
|
||||
HTMLBlueNavyColor, HTMLBlueMidnightBlueColor,
|
||||
HTMLPurpleLavenderColor, HTMLPurpleThistleColor,
|
||||
HTMLPurplePlumColor, HTMLPurpleVioletColor,
|
||||
HTMLPurpleOrchidColor, HTMLPurpleFuchsiaColor,
|
||||
HTMLPurpleMagentaColor, HTMLPurpleMediumOrchidColor,
|
||||
HTMLPurpleMediumPurpleColor, HTMLPurpleBlueVioletColor,
|
||||
HTMLPurpleDarkVioletColor, HTMLPurpleDarkOrchidColor,
|
||||
HTMLPurpleDarkMagentaColor, HTMLPurplePurpleColor,
|
||||
HTMLPurpleIndigoColor, HTMLPurpleDarkSlateBlueColor,
|
||||
HTMLPurpleSlateBlueColor,
|
||||
HTMLPurpleMediumSlateBlueColor,
|
||||
HTMLWhiteWhiteColor, HTMLWhiteSnowColor,
|
||||
HTMLWhiteHoneydewColor, HTMLWhiteMintCreamColor,
|
||||
HTMLWhiteAzureColor, HTMLWhiteAliceBlueColor,
|
||||
HTMLWhiteGhostWhiteColor, HTMLWhiteWhiteSmokeColor,
|
||||
HTMLWhiteSeashellColor, HTMLWhiteBeigeColor,
|
||||
HTMLWhiteOldLaceColor, HTMLWhiteFloralWhiteColor,
|
||||
HTMLWhiteIvoryColor, HTMLWhiteAntiqueWhiteColor,
|
||||
HTMLWhiteLinenColor, HTMLWhiteLavenderBlushColor,
|
||||
HTMLWhiteMistyRoseColor, HTMLGrayGainsboroColor,
|
||||
HTMLGrayLightGrayColor, HTMLGraySilverColor,
|
||||
HTMLGrayDarkGrayColor, HTMLGrayGrayColor,
|
||||
HTMLGrayDimGrayColor, HTMLGrayLightSlateGrayColor,
|
||||
HTMLGraySlateGrayColor, HTMLGrayDarkSlateGrayColor,
|
||||
HTMLGrayBlackColor, NoneColor};
|
||||
Q_ENUM (Color)
|
||||
//Line color
|
||||
enum Color {
|
||||
BlackColor, WhiteColor, GreenColor, RedColor, BlueColor,
|
||||
GrayColor, BrunColor, YellowColor, CyanColor,
|
||||
MagentaColor, LightgrayColor, OrangeColor, PurpleColor,
|
||||
HTMLPinkPinkColor, HTMLPinkLightPinkColor,
|
||||
HTMLPinkHotPinkColor, HTMLPinkDeepPinkColor,
|
||||
HTMLPinkPaleVioletRedColor,
|
||||
HTMLPinkMediumVioletRedColor, HTMLRedLightSalmonColor,
|
||||
HTMLRedSalmonColor, HTMLRedDarkSalmonColor,
|
||||
HTMLRedLightCoralColor, HTMLRedIndianRedColor,
|
||||
HTMLRedCrimsonColor, HTMLRedFirebrickColor,
|
||||
HTMLRedDarkRedColor, HTMLRedRedColor,
|
||||
HTMLOrangeOrangeRedColor, HTMLOrangeTomatoColor,
|
||||
HTMLOrangeCoralColor, HTMLOrangeDarkOrangeColor,
|
||||
HTMLOrangeOrangeColor, HTMLYellowYellowColor,
|
||||
HTMLYellowLightYellowColor, HTMLYellowLemonChiffonColor,
|
||||
HTMLYellowLightGoldenrodYellowColor,
|
||||
HTMLYellowPapayaWhipColor, HTMLYellowMoccasinColor,
|
||||
HTMLYellowPeachPuffColor, HTMLYellowPaleGoldenrodColor,
|
||||
HTMLYellowKhakiColor, HTMLYellowDarkKhakiColor,
|
||||
HTMLYellowGoldColor, HTMLBrownCornsilkColor,
|
||||
HTMLBrownBlanchedAlmondColor, HTMLBrownBisqueColor,
|
||||
HTMLBrownNavajoWhiteColor, HTMLBrownWheatColor,
|
||||
HTMLBrownBurlywoodColor, HTMLBrownTanColor,
|
||||
HTMLBrownRosyBrownColor, HTMLBrownSandyBrownColor,
|
||||
HTMLBrownGoldenrodColor, HTMLBrownDarkGoldenrodColor,
|
||||
HTMLBrownPeruColor, HTMLBrownChocolateColor,
|
||||
HTMLBrownSaddleBrownColor, HTMLBrownSiennaColor,
|
||||
HTMLBrownBrownColor, HTMLBrownMaroonColor,
|
||||
HTMLGreenDarkOliveGreenColor, HTMLGreenOliveColor,
|
||||
HTMLGreenOliveDrabColor, HTMLGreenYellowGreenColor,
|
||||
HTMLGreenLimeGreenColor, HTMLGreenLimeColor,
|
||||
HTMLGreenLawnGreenColor, HTMLGreenChartreuseColor,
|
||||
HTMLGreenGreenYellowColor, HTMLGreenSpringGreenColor,
|
||||
HTMLGreenMediumSpringGreenColor,
|
||||
HTMLGreenLightGreenColor, HTMLGreenPaleGreenColor,
|
||||
HTMLGreenDarkSeaGreenColor,
|
||||
HTMLGreenMediumAquamarineColor,
|
||||
HTMLGreenMediumSeaGreenColor, HTMLGreenSeaGreenColor,
|
||||
HTMLGreenForestGreenColor, HTMLGreenGreenColor,
|
||||
HTMLGreenDarkGreenColor, HTMLCyanAquaColor,
|
||||
HTMLCyanCyanColor, HTMLCyanLightCyanColor,
|
||||
HTMLCyanPaleTurquoiseColor, HTMLCyanAquamarineColor,
|
||||
HTMLCyanTurquoiseColor, HTMLCyanMediumTurquoiseColor,
|
||||
HTMLCyanDarkTurquoiseColor, HTMLCyanLightSeaGreenColor,
|
||||
HTMLCyanCadetBlueColor, HTMLCyanDarkCyanColor,
|
||||
HTMLCyanTealColor, HTMLBlueLightSteelBlueColor,
|
||||
HTMLBluePowderBlueColor, HTMLBlueLightBlueColor,
|
||||
HTMLBlueSkyBlueColor, HTMLBlueLightSkyBlueColor,
|
||||
HTMLBlueDeepSkyBlueColor, HTMLBlueDodgerBlueColor,
|
||||
HTMLBlueCornflowerBlueColor, HTMLBlueSteelBlueColor,
|
||||
HTMLBlueRoyalBlueColor, HTMLBlueBlueColor,
|
||||
HTMLBlueMediumBlueColor, HTMLBlueDarkBlueColor,
|
||||
HTMLBlueNavyColor, HTMLBlueMidnightBlueColor,
|
||||
HTMLPurpleLavenderColor, HTMLPurpleThistleColor,
|
||||
HTMLPurplePlumColor, HTMLPurpleVioletColor,
|
||||
HTMLPurpleOrchidColor, HTMLPurpleFuchsiaColor,
|
||||
HTMLPurpleMagentaColor, HTMLPurpleMediumOrchidColor,
|
||||
HTMLPurpleMediumPurpleColor, HTMLPurpleBlueVioletColor,
|
||||
HTMLPurpleDarkVioletColor, HTMLPurpleDarkOrchidColor,
|
||||
HTMLPurpleDarkMagentaColor, HTMLPurplePurpleColor,
|
||||
HTMLPurpleIndigoColor, HTMLPurpleDarkSlateBlueColor,
|
||||
HTMLPurpleSlateBlueColor,
|
||||
HTMLPurpleMediumSlateBlueColor,
|
||||
HTMLWhiteWhiteColor, HTMLWhiteSnowColor,
|
||||
HTMLWhiteHoneydewColor, HTMLWhiteMintCreamColor,
|
||||
HTMLWhiteAzureColor, HTMLWhiteAliceBlueColor,
|
||||
HTMLWhiteGhostWhiteColor, HTMLWhiteWhiteSmokeColor,
|
||||
HTMLWhiteSeashellColor, HTMLWhiteBeigeColor,
|
||||
HTMLWhiteOldLaceColor, HTMLWhiteFloralWhiteColor,
|
||||
HTMLWhiteIvoryColor, HTMLWhiteAntiqueWhiteColor,
|
||||
HTMLWhiteLinenColor, HTMLWhiteLavenderBlushColor,
|
||||
HTMLWhiteMistyRoseColor, HTMLGrayGainsboroColor,
|
||||
HTMLGrayLightGrayColor, HTMLGraySilverColor,
|
||||
HTMLGrayDarkGrayColor, HTMLGrayGrayColor,
|
||||
HTMLGrayDimGrayColor, HTMLGrayLightSlateGrayColor,
|
||||
HTMLGraySlateGrayColor, HTMLGrayDarkSlateGrayColor,
|
||||
HTMLGrayBlackColor, NoneColor};
|
||||
Q_ENUM (Color)
|
||||
|
||||
// constructors, destructor
|
||||
public:
|
||||
// constructors, destructor
|
||||
public:
|
||||
|
||||
CustomElementGraphicPart(QETElementEditor *editor,
|
||||
QGraphicsItem *parent = nullptr);
|
||||
~CustomElementGraphicPart() override;
|
||||
CustomElementGraphicPart(QETElementEditor *editor,
|
||||
QGraphicsItem *parent = nullptr);
|
||||
~CustomElementGraphicPart() override;
|
||||
|
||||
static void drawCross (const QPointF ¢er,
|
||||
QPainter *painter);
|
||||
static void drawCross (const QPointF ¢er,
|
||||
QPainter *painter);
|
||||
|
||||
//Getter and setter
|
||||
LineStyle lineStyle () const {return _linestyle;}
|
||||
void setLineStyle (const LineStyle ls);
|
||||
//Getter and setter
|
||||
LineStyle lineStyle () const {return _linestyle;}
|
||||
void setLineStyle (const LineStyle ls);
|
||||
|
||||
LineWeight lineWeight () const {return _lineweight;}
|
||||
void setLineWeight (const LineWeight lw);
|
||||
qreal penWeight () const;
|
||||
LineWeight lineWeight () const {return _lineweight;}
|
||||
void setLineWeight (const LineWeight lw);
|
||||
qreal penWeight () const;
|
||||
|
||||
Filling filling () const {return _filling;}
|
||||
void setFilling(const Filling f);
|
||||
Filling filling () const {return _filling;}
|
||||
void setFilling(const Filling f);
|
||||
|
||||
Color color () const {return _color;}
|
||||
void setColor(const Color c);
|
||||
Color color () const {return _color;}
|
||||
void setColor(const Color c);
|
||||
|
||||
bool antialiased () const {return _antialiased;}
|
||||
void setAntialiased(const bool b);
|
||||
//End of getter and setter
|
||||
bool antialiased () const {return _antialiased;}
|
||||
void setAntialiased(const bool b);
|
||||
//End of getter and setter
|
||||
|
||||
|
||||
//Rediriged to QObject Q_PROPERTY system
|
||||
void setProperty (const char *name,
|
||||
const QVariant &value) override {
|
||||
QObject::setProperty(name, value);}
|
||||
QVariant property (const char *name) const override {
|
||||
return QObject::property(name);}
|
||||
//Rediriged to QObject Q_PROPERTY system
|
||||
void setProperty (const char *name,
|
||||
const QVariant &value) override {
|
||||
QObject::setProperty(name, value);}
|
||||
QVariant property (const char *name) const override {
|
||||
return QObject::property(name);}
|
||||
|
||||
virtual QPainterPath shadowShape ()const = 0;
|
||||
virtual void setHandlerColor(QPointF /*pos*/,
|
||||
const QColor &/*color*/) {}
|
||||
virtual void resetAllHandlerColor() {}
|
||||
virtual QPainterPath shadowShape ()const = 0;
|
||||
virtual void setHandlerColor(QPointF /*pos*/,
|
||||
const QColor &/*color*/) {}
|
||||
virtual void resetAllHandlerColor() {}
|
||||
|
||||
protected:
|
||||
void stylesToXml (QDomElement &) const;
|
||||
void stylesFromXml(const QDomElement &);
|
||||
void resetStyles ();
|
||||
void applyStylesToQPainter(QPainter &) const;
|
||||
void drawShadowShape (QPainter *painter);
|
||||
protected:
|
||||
void stylesToXml (QDomElement &) const;
|
||||
void stylesFromXml(const QDomElement &);
|
||||
void resetStyles ();
|
||||
void applyStylesToQPainter(QPainter &) const;
|
||||
void drawShadowShape (QPainter *painter);
|
||||
|
||||
QVariant itemChange(GraphicsItemChange change,
|
||||
const QVariant &value) override;
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
|
||||
QVariant itemChange(GraphicsItemChange change,
|
||||
const QVariant &value) override;
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
|
||||
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseReleaseEvent(
|
||||
QGraphicsSceneMouseEvent *event) override;
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseReleaseEvent(
|
||||
QGraphicsSceneMouseEvent *event) override;
|
||||
|
||||
// attributes
|
||||
bool m_hovered;
|
||||
private:
|
||||
LineStyle _linestyle;
|
||||
LineWeight _lineweight;
|
||||
Filling _filling ;
|
||||
Color _color;
|
||||
bool _antialiased;
|
||||
QPointF m_origin_pos;
|
||||
// attributes
|
||||
bool m_hovered;
|
||||
private:
|
||||
LineStyle _linestyle;
|
||||
LineWeight _lineweight;
|
||||
Filling _filling ;
|
||||
Color _color;
|
||||
bool _antialiased;
|
||||
QPointF m_origin_pos;
|
||||
};
|
||||
|
||||
typedef CustomElementGraphicPart CEGP;
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef CUSTOM_ELEMENT_PART_H
|
||||
#define CUSTOM_ELEMENT_PART_H
|
||||
@@ -29,94 +29,94 @@ class QGraphicsItem;
|
||||
class QGraphicsSceneMouseEvent;
|
||||
|
||||
/**
|
||||
@brief The CustomElementPart class
|
||||
This abstract class represents a primitive of
|
||||
the visual representation of an electrical element.
|
||||
The Element, FixedElement and CustomElement classes do not embed
|
||||
its attributes and methods in order to remain lightweight; indeed,
|
||||
there is no point for those classes to store their visual representation
|
||||
with anything more complex than a QImage.
|
||||
@brief The CustomElementPart class
|
||||
This abstract class represents a primitive of
|
||||
the visual representation of an electrical element.
|
||||
The Element, FixedElement and CustomElement classes do not embed
|
||||
its attributes and methods in order to remain lightweight; indeed,
|
||||
there is no point for those classes to store their visual representation
|
||||
with anything more complex than a QImage.
|
||||
*/
|
||||
class CustomElementPart {
|
||||
// constructors, destructor
|
||||
public:
|
||||
/**
|
||||
@brief CustomElementPart
|
||||
Constructor
|
||||
@param editor Element editor this primitive is attached to
|
||||
*/
|
||||
CustomElementPart(QETElementEditor *editor) : element_editor(editor) {}
|
||||
/**
|
||||
@brief ~CustomElementPart
|
||||
Destructor
|
||||
*/
|
||||
virtual ~CustomElementPart() {}
|
||||
|
||||
private:
|
||||
CustomElementPart(const CustomElementPart &);
|
||||
|
||||
// attributes
|
||||
private:
|
||||
QETElementEditor *element_editor;
|
||||
|
||||
// methods
|
||||
public:
|
||||
/**
|
||||
Load the primitive from an XML element that describes it
|
||||
*/
|
||||
virtual void fromXml(const QDomElement &) = 0;
|
||||
/**
|
||||
Export the primitive as an XML element
|
||||
*/
|
||||
virtual const QDomElement toXml(QDomDocument &) const = 0;
|
||||
/**
|
||||
Set a specific property of the primitive
|
||||
*/
|
||||
virtual void setProperty(const char *name, const QVariant &value) = 0;
|
||||
/**
|
||||
Get the current value of a specific primitive property
|
||||
*/
|
||||
virtual QVariant property(const char *name) const = 0;
|
||||
/**
|
||||
@return whether the primitive appears to be useless (e.g. 0-length line)
|
||||
Typically, useless primitives are discarded when saving the element.
|
||||
*/
|
||||
virtual bool isUseless() const = 0;
|
||||
virtual QRectF sceneGeometricRect() const = 0;
|
||||
/**
|
||||
Inform this part a user-induced transformation is about to begin.
|
||||
This method can be used to save data required by handleUserTransformation().
|
||||
*/
|
||||
virtual void startUserTransformation(const QRectF &) = 0;
|
||||
/**
|
||||
Make this part fit into the provided rectangle.
|
||||
*/
|
||||
virtual void handleUserTransformation(const QRectF &,
|
||||
const QRectF &) = 0;
|
||||
/// @return a pointer to the parent element editor
|
||||
virtual QETElementEditor *elementEditor() const;
|
||||
/**
|
||||
Call the updateCurrentPartEditor() slot of the editor
|
||||
@see QETElementEditor::updateCurrentPartEditor()
|
||||
*/
|
||||
virtual void updateCurrentPartEditor() const;
|
||||
/// @return a pointer to the parent editing scene
|
||||
virtual ElementScene *elementScene() const;
|
||||
/// @return the element editor undo stack
|
||||
virtual QUndoStack &undoStack() const;
|
||||
/// @return the name of the primitive
|
||||
virtual QString name() const = 0;
|
||||
/// @return the name that will be used as XML tag when exporting the primitive
|
||||
virtual QString xmlName() const = 0;
|
||||
|
||||
virtual QGraphicsItem *toItem();
|
||||
|
||||
virtual QET::ScalingMethod preferredScalingMethod() const;
|
||||
|
||||
protected:
|
||||
QList<QPointF> mapPoints(
|
||||
const QRectF &,
|
||||
const QRectF &,
|
||||
const QList<QPointF> &);
|
||||
// constructors, destructor
|
||||
public:
|
||||
/**
|
||||
@brief CustomElementPart
|
||||
Constructor
|
||||
@param editor Element editor this primitive is attached to
|
||||
*/
|
||||
CustomElementPart(QETElementEditor *editor) : element_editor(editor) {}
|
||||
/**
|
||||
@brief ~CustomElementPart
|
||||
Destructor
|
||||
*/
|
||||
virtual ~CustomElementPart() {}
|
||||
|
||||
private:
|
||||
CustomElementPart(const CustomElementPart &);
|
||||
|
||||
// attributes
|
||||
private:
|
||||
QETElementEditor *element_editor;
|
||||
|
||||
// methods
|
||||
public:
|
||||
/**
|
||||
Load the primitive from an XML element that describes it
|
||||
*/
|
||||
virtual void fromXml(const QDomElement &) = 0;
|
||||
/**
|
||||
Export the primitive as an XML element
|
||||
*/
|
||||
virtual const QDomElement toXml(QDomDocument &) const = 0;
|
||||
/**
|
||||
Set a specific property of the primitive
|
||||
*/
|
||||
virtual void setProperty(const char *name, const QVariant &value) = 0;
|
||||
/**
|
||||
Get the current value of a specific primitive property
|
||||
*/
|
||||
virtual QVariant property(const char *name) const = 0;
|
||||
/**
|
||||
@return whether the primitive appears to be useless (e.g. 0-length line)
|
||||
Typically, useless primitives are discarded when saving the element.
|
||||
*/
|
||||
virtual bool isUseless() const = 0;
|
||||
virtual QRectF sceneGeometricRect() const = 0;
|
||||
/**
|
||||
Inform this part a user-induced transformation is about to begin.
|
||||
This method can be used to save data required by handleUserTransformation().
|
||||
*/
|
||||
virtual void startUserTransformation(const QRectF &) = 0;
|
||||
/**
|
||||
Make this part fit into the provided rectangle.
|
||||
*/
|
||||
virtual void handleUserTransformation(const QRectF &,
|
||||
const QRectF &) = 0;
|
||||
/// @return a pointer to the parent element editor
|
||||
virtual QETElementEditor *elementEditor() const;
|
||||
/**
|
||||
Call the updateCurrentPartEditor() slot of the editor
|
||||
@see QETElementEditor::updateCurrentPartEditor()
|
||||
*/
|
||||
virtual void updateCurrentPartEditor() const;
|
||||
/// @return a pointer to the parent editing scene
|
||||
virtual ElementScene *elementScene() const;
|
||||
/// @return the element editor undo stack
|
||||
virtual QUndoStack &undoStack() const;
|
||||
/// @return the name of the primitive
|
||||
virtual QString name() const = 0;
|
||||
/// @return the name that will be used as XML tag when exporting the primitive
|
||||
virtual QString xmlName() const = 0;
|
||||
|
||||
virtual QGraphicsItem *toItem();
|
||||
|
||||
virtual QET::ScalingMethod preferredScalingMethod() const;
|
||||
|
||||
protected:
|
||||
QList<QPointF> mapPoints(
|
||||
const QRectF &,
|
||||
const QRectF &,
|
||||
const QList<QPointF> &);
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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.
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "partarc.h"
|
||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||
@@ -23,143 +23,143 @@
|
||||
|
||||
|
||||
/**
|
||||
@brief PartArc::PartArc
|
||||
Constructor
|
||||
@param editor : QETElementEditor of this part
|
||||
@param parent : parent item
|
||||
@brief PartArc::PartArc
|
||||
Constructor
|
||||
@param editor : QETElementEditor of this part
|
||||
@param parent : parent item
|
||||
*/
|
||||
PartArc::PartArc(QETElementEditor *editor, QGraphicsItem *parent) :
|
||||
AbstractPartEllipse(editor, parent)
|
||||
AbstractPartEllipse(editor, parent)
|
||||
{
|
||||
m_start_angle = 0;
|
||||
m_span_angle = -1440;
|
||||
m_start_angle = 0;
|
||||
m_span_angle = -1440;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartArc::~PartArc
|
||||
Destructor
|
||||
@brief PartArc::~PartArc
|
||||
Destructor
|
||||
*/
|
||||
PartArc::~PartArc()
|
||||
{
|
||||
if(m_undo_command) delete m_undo_command;
|
||||
removeHandler();
|
||||
if(m_undo_command) delete m_undo_command;
|
||||
removeHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartArc::paint
|
||||
Draw this arc
|
||||
@param painter
|
||||
@param options
|
||||
@param widget
|
||||
@brief PartArc::paint
|
||||
Draw this arc
|
||||
@param painter
|
||||
@param options
|
||||
@param widget
|
||||
*/
|
||||
void PartArc::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(widget)
|
||||
Q_UNUSED(widget)
|
||||
|
||||
applyStylesToQPainter(*painter);
|
||||
applyStylesToQPainter(*painter);
|
||||
|
||||
//Always remove the brush
|
||||
painter -> setBrush(Qt::NoBrush);
|
||||
QPen t = painter -> pen();
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
||||
t.setCosmetic(options && options -> levelOfDetail < 1.0);
|
||||
//Always remove the brush
|
||||
painter -> setBrush(Qt::NoBrush);
|
||||
QPen t = painter -> pen();
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
||||
t.setCosmetic(options && options -> levelOfDetail < 1.0);
|
||||
#else
|
||||
#if TODO_LIST
|
||||
#pragma message("@TODO remove code for QT 6 or later")
|
||||
#endif
|
||||
t.setCosmetic(options && options -> levelOfDetailFromTransform(painter->worldTransform()) < 1.0);
|
||||
t.setCosmetic(options && options -> levelOfDetailFromTransform(painter->worldTransform()) < 1.0);
|
||||
#endif
|
||||
painter -> setPen(t);
|
||||
painter -> setPen(t);
|
||||
|
||||
if (isSelected())
|
||||
{
|
||||
painter->save();
|
||||
QPen pen(Qt::DotLine);
|
||||
pen.setWidth(1);
|
||||
pen.setCosmetic(true);
|
||||
painter->setPen(pen);
|
||||
//Draw the ellipse in black
|
||||
painter -> drawEllipse(rect());
|
||||
painter->restore();
|
||||
if (isSelected())
|
||||
{
|
||||
painter->save();
|
||||
QPen pen(Qt::DotLine);
|
||||
pen.setWidth(1);
|
||||
pen.setCosmetic(true);
|
||||
painter->setPen(pen);
|
||||
//Draw the ellipse in black
|
||||
painter -> drawEllipse(rect());
|
||||
painter->restore();
|
||||
|
||||
//Draw the arc in red
|
||||
t.setColor(Qt::red);
|
||||
painter -> setPen(t);
|
||||
}
|
||||
//Draw the arc in red
|
||||
t.setColor(Qt::red);
|
||||
painter -> setPen(t);
|
||||
}
|
||||
|
||||
painter->drawArc(m_rect, m_start_angle, m_span_angle);
|
||||
painter->drawArc(m_rect, m_start_angle, m_span_angle);
|
||||
|
||||
if (m_hovered)
|
||||
drawShadowShape(painter);
|
||||
if (m_hovered)
|
||||
drawShadowShape(painter);
|
||||
|
||||
if (isSelected())
|
||||
drawCross(m_rect.center(), painter);
|
||||
if (isSelected())
|
||||
drawCross(m_rect.center(), painter);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartArc::toXml
|
||||
Export this arc in xml
|
||||
@param xml_document : Xml document to use for create the xml element.
|
||||
@return : an xml element that describe this arc
|
||||
@brief PartArc::toXml
|
||||
Export this arc in xml
|
||||
@param xml_document : Xml document to use for create the xml element.
|
||||
@return : an xml element that describe this arc
|
||||
*/
|
||||
const QDomElement PartArc::toXml(QDomDocument &xml_document) const
|
||||
{
|
||||
QDomElement xml_element = xml_document.createElement("arc");
|
||||
QPointF top_left(sceneTopLeft());
|
||||
xml_element.setAttribute("x", QString("%1").arg(top_left.x()));
|
||||
xml_element.setAttribute("y", QString("%1").arg(top_left.y()));
|
||||
xml_element.setAttribute("width", QString("%1").arg(rect().width()));
|
||||
xml_element.setAttribute("height", QString("%1").arg(rect().height()));
|
||||
//to maintain compatibility with the previous version, we write the angle in degrees.
|
||||
xml_element.setAttribute("start", QString("%1").arg(m_start_angle / 16));
|
||||
xml_element.setAttribute("angle", QString("%1").arg(m_span_angle / 16));
|
||||
stylesToXml(xml_element);
|
||||
return(xml_element);
|
||||
QDomElement xml_element = xml_document.createElement("arc");
|
||||
QPointF top_left(sceneTopLeft());
|
||||
xml_element.setAttribute("x", QString("%1").arg(top_left.x()));
|
||||
xml_element.setAttribute("y", QString("%1").arg(top_left.y()));
|
||||
xml_element.setAttribute("width", QString("%1").arg(rect().width()));
|
||||
xml_element.setAttribute("height", QString("%1").arg(rect().height()));
|
||||
//to maintain compatibility with the previous version, we write the angle in degrees.
|
||||
xml_element.setAttribute("start", QString("%1").arg(m_start_angle / 16));
|
||||
xml_element.setAttribute("angle", QString("%1").arg(m_span_angle / 16));
|
||||
stylesToXml(xml_element);
|
||||
return(xml_element);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartArc::fromXml
|
||||
Import the properties of this arc from a xml element.
|
||||
@param qde : Xml document to use.
|
||||
@brief PartArc::fromXml
|
||||
Import the properties of this arc from a xml element.
|
||||
@param qde : Xml document to use.
|
||||
*/
|
||||
void PartArc::fromXml(const QDomElement &qde) {
|
||||
stylesFromXml(qde);
|
||||
m_rect = QRectF(mapFromScene(qde.attribute("x", "0").toDouble(),
|
||||
qde.attribute("y", "0").toDouble()),
|
||||
QSizeF(qde.attribute("width", "0").toDouble(),
|
||||
qde.attribute("height", "0").toDouble()) );
|
||||
stylesFromXml(qde);
|
||||
m_rect = QRectF(mapFromScene(qde.attribute("x", "0").toDouble(),
|
||||
qde.attribute("y", "0").toDouble()),
|
||||
QSizeF(qde.attribute("width", "0").toDouble(),
|
||||
qde.attribute("height", "0").toDouble()) );
|
||||
|
||||
m_start_angle = qde.attribute("start", "0").toDouble() * 16;
|
||||
m_span_angle = qde.attribute("angle", "-1440").toDouble() * 16;
|
||||
m_start_angle = qde.attribute("start", "0").toDouble() * 16;
|
||||
m_span_angle = qde.attribute("angle", "-1440").toDouble() * 16;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartArc::shape
|
||||
@return the shape of this item
|
||||
@brief PartArc::shape
|
||||
@return the shape of this item
|
||||
*/
|
||||
QPainterPath PartArc::shape() const
|
||||
{
|
||||
QPainterPath shape;
|
||||
shape.arcMoveTo(m_rect, m_start_angle/16);
|
||||
shape.arcTo(m_rect, m_start_angle /16, m_span_angle /16);
|
||||
QPainterPath shape;
|
||||
shape.arcMoveTo(m_rect, m_start_angle/16);
|
||||
shape.arcTo(m_rect, m_start_angle /16, m_span_angle /16);
|
||||
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
||||
shape = pps.createStroke(shape);
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
||||
shape = pps.createStroke(shape);
|
||||
|
||||
return shape;
|
||||
return shape;
|
||||
}
|
||||
|
||||
QPainterPath PartArc::shadowShape() const
|
||||
{
|
||||
QPainterPath shape;
|
||||
shape.arcMoveTo(m_rect, m_start_angle/16);
|
||||
shape.arcTo(m_rect, m_start_angle /16, m_span_angle /16);
|
||||
QPainterPath shape;
|
||||
shape.arcMoveTo(m_rect, m_start_angle/16);
|
||||
shape.arcTo(m_rect, m_start_angle /16, m_span_angle /16);
|
||||
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(penWeight());
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(penWeight());
|
||||
|
||||
return (pps.createStroke(shape));
|
||||
return (pps.createStroke(shape));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,327 +173,327 @@ QPainterPath PartArc::shadowShape() const
|
||||
*/
|
||||
QRectF PartArc::sceneGeometricRect() const
|
||||
{
|
||||
return mapToScene(QetGraphicsHandlerUtility::rectForArc(m_rect, m_start_angle/16, m_span_angle/16)).boundingRect();
|
||||
return mapToScene(QetGraphicsHandlerUtility::rectForArc(m_rect, m_start_angle/16, m_span_angle/16)).boundingRect();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartArc::mouseReleaseEvent
|
||||
Handle mouse release event
|
||||
@param event
|
||||
@brief PartArc::mouseReleaseEvent
|
||||
Handle mouse release event
|
||||
@param event
|
||||
*/
|
||||
void PartArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton && event->buttonDownPos(Qt::LeftButton) == event->pos())
|
||||
switchResizeMode();
|
||||
if (event->button() == Qt::LeftButton && event->buttonDownPos(Qt::LeftButton) == event->pos())
|
||||
switchResizeMode();
|
||||
|
||||
CustomElementGraphicPart::mouseReleaseEvent(event);
|
||||
CustomElementGraphicPart::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartArc::itemChange
|
||||
@param change
|
||||
@param value
|
||||
@return
|
||||
@brief PartArc::itemChange
|
||||
@param change
|
||||
@param value
|
||||
@return
|
||||
*/
|
||||
QVariant PartArc::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
if (change == ItemSelectedHasChanged && scene())
|
||||
{
|
||||
if (value.toBool() == true)
|
||||
{
|
||||
//When item is selected, he must to be up to date whene the selection in the scene change, for display or not the handler,
|
||||
//according to the number of selected items.
|
||||
connect(scene(), &QGraphicsScene::selectionChanged, this, &PartArc::sceneSelectionChanged);
|
||||
if (change == ItemSelectedHasChanged && scene())
|
||||
{
|
||||
if (value.toBool() == true)
|
||||
{
|
||||
//When item is selected, he must to be up to date whene the selection in the scene change, for display or not the handler,
|
||||
//according to the number of selected items.
|
||||
connect(scene(), &QGraphicsScene::selectionChanged, this, &PartArc::sceneSelectionChanged);
|
||||
|
||||
if (scene()->selectedItems().size() == 1)
|
||||
addHandler();
|
||||
}
|
||||
else
|
||||
{
|
||||
disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartArc::sceneSelectionChanged);
|
||||
removeHandler();
|
||||
}
|
||||
}
|
||||
else if (change == ItemPositionHasChanged)
|
||||
{
|
||||
adjusteHandlerPos();
|
||||
}
|
||||
else if (change == ItemSceneChange)
|
||||
{
|
||||
if(scene())
|
||||
disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartArc::sceneSelectionChanged);
|
||||
if (scene()->selectedItems().size() == 1)
|
||||
addHandler();
|
||||
}
|
||||
else
|
||||
{
|
||||
disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartArc::sceneSelectionChanged);
|
||||
removeHandler();
|
||||
}
|
||||
}
|
||||
else if (change == ItemPositionHasChanged)
|
||||
{
|
||||
adjusteHandlerPos();
|
||||
}
|
||||
else if (change == ItemSceneChange)
|
||||
{
|
||||
if(scene())
|
||||
disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartArc::sceneSelectionChanged);
|
||||
|
||||
setSelected(false); //This is item removed from scene, then we deselect this, and so, the handlers is also removed.
|
||||
}
|
||||
setSelected(false); //This is item removed from scene, then we deselect this, and so, the handlers is also removed.
|
||||
}
|
||||
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartArc::sceneEventFilter
|
||||
@param watched
|
||||
@param event
|
||||
@return
|
||||
@brief PartArc::sceneEventFilter
|
||||
@param watched
|
||||
@param event
|
||||
@return
|
||||
*/
|
||||
bool PartArc::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
||||
{
|
||||
//Watched must be an handler
|
||||
if(watched->type() == QetGraphicsHandlerItem::Type)
|
||||
{
|
||||
QetGraphicsHandlerItem *qghi = qgraphicsitem_cast<QetGraphicsHandlerItem *>(watched);
|
||||
//Watched must be an handler
|
||||
if(watched->type() == QetGraphicsHandlerItem::Type)
|
||||
{
|
||||
QetGraphicsHandlerItem *qghi = qgraphicsitem_cast<QetGraphicsHandlerItem *>(watched);
|
||||
|
||||
if(m_handler_vector.contains(qghi)) //Handler must be in m_vector_index, then we can start resize
|
||||
{
|
||||
m_vector_index = m_handler_vector.indexOf(qghi);
|
||||
if (m_vector_index != -1)
|
||||
{
|
||||
if(event->type() == QEvent::GraphicsSceneMousePress) //Click
|
||||
{
|
||||
handlerMousePressEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
else if(event->type() == QEvent::GraphicsSceneMouseMove) //Move
|
||||
{
|
||||
handlerMouseMoveEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
else if (event->type() == QEvent::GraphicsSceneMouseRelease) //Release
|
||||
{
|
||||
handlerMouseReleaseEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(m_handler_vector.contains(qghi)) //Handler must be in m_vector_index, then we can start resize
|
||||
{
|
||||
m_vector_index = m_handler_vector.indexOf(qghi);
|
||||
if (m_vector_index != -1)
|
||||
{
|
||||
if(event->type() == QEvent::GraphicsSceneMousePress) //Click
|
||||
{
|
||||
handlerMousePressEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
else if(event->type() == QEvent::GraphicsSceneMouseMove) //Move
|
||||
{
|
||||
handlerMouseMoveEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
else if (event->type() == QEvent::GraphicsSceneMouseRelease) //Release
|
||||
{
|
||||
handlerMouseReleaseEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartArc::switchResizeMode
|
||||
@brief PartArc::switchResizeMode
|
||||
*/
|
||||
void PartArc::switchResizeMode()
|
||||
{
|
||||
if (m_resize_mode == 1)
|
||||
{
|
||||
m_resize_mode = 2;
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector)
|
||||
qghi->setColor(Qt::darkGreen);
|
||||
}
|
||||
else if (m_resize_mode == 2)
|
||||
{
|
||||
m_resize_mode = 3;
|
||||
if (m_resize_mode == 1)
|
||||
{
|
||||
m_resize_mode = 2;
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector)
|
||||
qghi->setColor(Qt::darkGreen);
|
||||
}
|
||||
else if (m_resize_mode == 2)
|
||||
{
|
||||
m_resize_mode = 3;
|
||||
|
||||
//From rect mode to angle mode, then numbers of handlers change
|
||||
removeHandler();
|
||||
addHandler();
|
||||
//From rect mode to angle mode, then numbers of handlers change
|
||||
removeHandler();
|
||||
addHandler();
|
||||
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector)
|
||||
qghi->setColor(Qt::magenta);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_resize_mode = 1;
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector)
|
||||
qghi->setColor(Qt::magenta);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_resize_mode = 1;
|
||||
|
||||
//From angle mode to rect mode, then numbers of handlers change
|
||||
removeHandler();
|
||||
addHandler();
|
||||
//From angle mode to rect mode, then numbers of handlers change
|
||||
removeHandler();
|
||||
addHandler();
|
||||
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector)
|
||||
qghi->setColor(Qt::blue);
|
||||
}
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector)
|
||||
qghi->setColor(Qt::blue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartArc::adjusteHandlerPos
|
||||
@brief PartArc::adjusteHandlerPos
|
||||
*/
|
||||
void PartArc::adjusteHandlerPos()
|
||||
{
|
||||
if (m_handler_vector.isEmpty())
|
||||
return;
|
||||
if (m_handler_vector.isEmpty())
|
||||
return;
|
||||
|
||||
QVector <QPointF> points_vector;
|
||||
QVector <QPointF> points_vector;
|
||||
|
||||
if(m_resize_mode == 3)
|
||||
points_vector = QetGraphicsHandlerUtility::pointsForArc(m_rect, m_start_angle/16, m_span_angle/16);
|
||||
else
|
||||
points_vector = QetGraphicsHandlerUtility::pointsForRect(m_rect);
|
||||
if(m_resize_mode == 3)
|
||||
points_vector = QetGraphicsHandlerUtility::pointsForArc(m_rect, m_start_angle/16, m_span_angle/16);
|
||||
else
|
||||
points_vector = QetGraphicsHandlerUtility::pointsForRect(m_rect);
|
||||
|
||||
|
||||
if (m_handler_vector.size() == points_vector.size())
|
||||
{
|
||||
points_vector = mapToScene(points_vector);
|
||||
for (int i = 0 ; i < points_vector.size() ; ++i)
|
||||
m_handler_vector.at(i)->setPos(points_vector.at(i));
|
||||
}
|
||||
if (m_handler_vector.size() == points_vector.size())
|
||||
{
|
||||
points_vector = mapToScene(points_vector);
|
||||
for (int i = 0 ; i < points_vector.size() ; ++i)
|
||||
m_handler_vector.at(i)->setPos(points_vector.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartArc::handlerMousePressEvent
|
||||
@param qghi
|
||||
@param event
|
||||
@brief PartArc::handlerMousePressEvent
|
||||
@param qghi
|
||||
@param event
|
||||
*/
|
||||
void PartArc::handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(qghi)
|
||||
Q_UNUSED(event)
|
||||
Q_UNUSED(qghi)
|
||||
Q_UNUSED(event)
|
||||
|
||||
if (m_resize_mode == 3) //Resize angle
|
||||
{
|
||||
if (m_vector_index == 0)
|
||||
{
|
||||
m_span_point = QetGraphicsHandlerUtility::pointsForArc(m_rect, m_start_angle/16, m_span_angle/16).at(1);
|
||||
if (m_resize_mode == 3) //Resize angle
|
||||
{
|
||||
if (m_vector_index == 0)
|
||||
{
|
||||
m_span_point = QetGraphicsHandlerUtility::pointsForArc(m_rect, m_start_angle/16, m_span_angle/16).at(1);
|
||||
|
||||
m_undo_command = new QPropertyUndoCommand(this, "startAngle", QVariant(m_start_angle));
|
||||
m_undo_command->setText(tr("Modifier un arc"));
|
||||
m_undo_command->enableAnimation();
|
||||
m_undo_command = new QPropertyUndoCommand(this, "startAngle", QVariant(m_start_angle));
|
||||
m_undo_command->setText(tr("Modifier un arc"));
|
||||
m_undo_command->enableAnimation();
|
||||
|
||||
m_undo_command2 = new QPropertyUndoCommand(this, "spanAngle", QVariant(m_span_angle), m_undo_command);
|
||||
m_undo_command2->setText(tr("Modifier un arc"));
|
||||
m_undo_command2->enableAnimation();
|
||||
}
|
||||
else if (m_vector_index == 1)
|
||||
{
|
||||
m_undo_command = new QPropertyUndoCommand(this, "spanAngle", QVariant(m_span_angle));
|
||||
m_undo_command->setText(tr("Modifier un arc"));
|
||||
m_undo_command->enableAnimation();
|
||||
}
|
||||
}
|
||||
else //resize rect
|
||||
{
|
||||
m_undo_command = new QPropertyUndoCommand(this, "rect", QVariant(m_rect));
|
||||
m_undo_command->setText(tr("Modifier un arc"));
|
||||
m_undo_command->enableAnimation();
|
||||
}
|
||||
m_undo_command2 = new QPropertyUndoCommand(this, "spanAngle", QVariant(m_span_angle), m_undo_command);
|
||||
m_undo_command2->setText(tr("Modifier un arc"));
|
||||
m_undo_command2->enableAnimation();
|
||||
}
|
||||
else if (m_vector_index == 1)
|
||||
{
|
||||
m_undo_command = new QPropertyUndoCommand(this, "spanAngle", QVariant(m_span_angle));
|
||||
m_undo_command->setText(tr("Modifier un arc"));
|
||||
m_undo_command->enableAnimation();
|
||||
}
|
||||
}
|
||||
else //resize rect
|
||||
{
|
||||
m_undo_command = new QPropertyUndoCommand(this, "rect", QVariant(m_rect));
|
||||
m_undo_command->setText(tr("Modifier un arc"));
|
||||
m_undo_command->enableAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartArc::handlerMouseMoveEvent
|
||||
@param qghi
|
||||
@param event
|
||||
@brief PartArc::handlerMouseMoveEvent
|
||||
@param qghi
|
||||
@param event
|
||||
*/
|
||||
void PartArc::handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(qghi)
|
||||
Q_UNUSED(qghi)
|
||||
|
||||
QPointF new_pos = event->scenePos();
|
||||
if (event->modifiers() != Qt::ControlModifier)
|
||||
new_pos = elementScene()->snapToGrid(event->scenePos());
|
||||
new_pos = mapFromScene(new_pos);
|
||||
QPointF new_pos = event->scenePos();
|
||||
if (event->modifiers() != Qt::ControlModifier)
|
||||
new_pos = elementScene()->snapToGrid(event->scenePos());
|
||||
new_pos = mapFromScene(new_pos);
|
||||
|
||||
if (m_resize_mode == 1)
|
||||
setRect(QetGraphicsHandlerUtility::rectForPosAtIndex(m_rect, new_pos, m_vector_index));
|
||||
else if (m_resize_mode == 2)
|
||||
setRect(QetGraphicsHandlerUtility::mirrorRectForPosAtIndex(m_rect, new_pos, m_vector_index));
|
||||
else
|
||||
{
|
||||
QLineF line(m_rect.center(), mapFromScene(event->scenePos()));
|
||||
prepareGeometryChange();
|
||||
if (m_resize_mode == 1)
|
||||
setRect(QetGraphicsHandlerUtility::rectForPosAtIndex(m_rect, new_pos, m_vector_index));
|
||||
else if (m_resize_mode == 2)
|
||||
setRect(QetGraphicsHandlerUtility::mirrorRectForPosAtIndex(m_rect, new_pos, m_vector_index));
|
||||
else
|
||||
{
|
||||
QLineF line(m_rect.center(), mapFromScene(event->scenePos()));
|
||||
prepareGeometryChange();
|
||||
|
||||
if (m_vector_index == 0) {
|
||||
setStartAngle(line.angle()*16);
|
||||
setSpanAngle(line.angleTo(QLineF(m_rect.center(), m_span_point))*16);
|
||||
}
|
||||
else if (m_vector_index == 1) {
|
||||
QLineF line2(m_rect.center(), QetGraphicsHandlerUtility::pointsForArc(m_rect, m_start_angle/16, m_span_angle/16).at(0));
|
||||
setSpanAngle (line2.angleTo(line)*16);
|
||||
}
|
||||
}
|
||||
if (m_vector_index == 0) {
|
||||
setStartAngle(line.angle()*16);
|
||||
setSpanAngle(line.angleTo(QLineF(m_rect.center(), m_span_point))*16);
|
||||
}
|
||||
else if (m_vector_index == 1) {
|
||||
QLineF line2(m_rect.center(), QetGraphicsHandlerUtility::pointsForArc(m_rect, m_start_angle/16, m_span_angle/16).at(0));
|
||||
setSpanAngle (line2.angleTo(line)*16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartArc::handlerMouseReleaseEvent
|
||||
@param qghi
|
||||
@param event
|
||||
@brief PartArc::handlerMouseReleaseEvent
|
||||
@param qghi
|
||||
@param event
|
||||
*/
|
||||
void PartArc::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(qghi)
|
||||
Q_UNUSED(event)
|
||||
Q_UNUSED(qghi)
|
||||
Q_UNUSED(event)
|
||||
|
||||
if (m_resize_mode == 3)
|
||||
{
|
||||
if (m_vector_index == 0)
|
||||
{
|
||||
m_undo_command->setNewValue(QVariant(m_start_angle));
|
||||
m_undo_command2->setNewValue(QVariant(m_span_angle));
|
||||
elementScene()->undoStack().push(m_undo_command);
|
||||
m_undo_command = nullptr;
|
||||
m_undo_command2 = nullptr;
|
||||
m_vector_index = -1;
|
||||
}
|
||||
else if (m_vector_index == 1)
|
||||
{
|
||||
m_undo_command->setNewValue(QVariant(m_span_angle));
|
||||
elementScene()->undoStack().push(m_undo_command);
|
||||
m_undo_command = nullptr;
|
||||
m_vector_index = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_rect.isValid())
|
||||
m_rect = m_rect.normalized();
|
||||
if (m_resize_mode == 3)
|
||||
{
|
||||
if (m_vector_index == 0)
|
||||
{
|
||||
m_undo_command->setNewValue(QVariant(m_start_angle));
|
||||
m_undo_command2->setNewValue(QVariant(m_span_angle));
|
||||
elementScene()->undoStack().push(m_undo_command);
|
||||
m_undo_command = nullptr;
|
||||
m_undo_command2 = nullptr;
|
||||
m_vector_index = -1;
|
||||
}
|
||||
else if (m_vector_index == 1)
|
||||
{
|
||||
m_undo_command->setNewValue(QVariant(m_span_angle));
|
||||
elementScene()->undoStack().push(m_undo_command);
|
||||
m_undo_command = nullptr;
|
||||
m_vector_index = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_rect.isValid())
|
||||
m_rect = m_rect.normalized();
|
||||
|
||||
m_undo_command->setNewValue(QVariant(m_rect));
|
||||
elementScene()->undoStack().push(m_undo_command);
|
||||
m_undo_command = nullptr;
|
||||
m_vector_index = -1;
|
||||
}
|
||||
m_undo_command->setNewValue(QVariant(m_rect));
|
||||
elementScene()->undoStack().push(m_undo_command);
|
||||
m_undo_command = nullptr;
|
||||
m_vector_index = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartArc::sceneSelectionChanged
|
||||
When the scene selection change, if there are several primitive selected, we remove the handler of this item
|
||||
@brief PartArc::sceneSelectionChanged
|
||||
When the scene selection change, if there are several primitive selected, we remove the handler of this item
|
||||
*/
|
||||
void PartArc::sceneSelectionChanged()
|
||||
{
|
||||
if (this->isSelected() && scene()->selectedItems().size() == 1)
|
||||
addHandler();
|
||||
else
|
||||
removeHandler();
|
||||
if (this->isSelected() && scene()->selectedItems().size() == 1)
|
||||
addHandler();
|
||||
else
|
||||
removeHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartArc::addHandler
|
||||
Add handlers for this item
|
||||
@brief PartArc::addHandler
|
||||
Add handlers for this item
|
||||
*/
|
||||
void PartArc::addHandler()
|
||||
{
|
||||
if (m_handler_vector.isEmpty() && scene())
|
||||
{
|
||||
if(m_resize_mode == 3)
|
||||
{
|
||||
m_handler_vector = QetGraphicsHandlerItem::handlerForPoint(mapToScene(QetGraphicsHandlerUtility::pointsForArc(m_rect, m_start_angle/16, m_span_angle/16)));
|
||||
}
|
||||
else
|
||||
m_handler_vector = QetGraphicsHandlerItem::handlerForPoint(mapToScene(QetGraphicsHandlerUtility::pointsForRect(m_rect)));
|
||||
if (m_handler_vector.isEmpty() && scene())
|
||||
{
|
||||
if(m_resize_mode == 3)
|
||||
{
|
||||
m_handler_vector = QetGraphicsHandlerItem::handlerForPoint(mapToScene(QetGraphicsHandlerUtility::pointsForArc(m_rect, m_start_angle/16, m_span_angle/16)));
|
||||
}
|
||||
else
|
||||
m_handler_vector = QetGraphicsHandlerItem::handlerForPoint(mapToScene(QetGraphicsHandlerUtility::pointsForRect(m_rect)));
|
||||
|
||||
for(QetGraphicsHandlerItem *handler : m_handler_vector)
|
||||
{
|
||||
QColor color = Qt::blue;
|
||||
if (m_resize_mode == 2)
|
||||
color = Qt::darkGreen;
|
||||
else if (m_resize_mode == 3)
|
||||
color = Qt::magenta;
|
||||
for(QetGraphicsHandlerItem *handler : m_handler_vector)
|
||||
{
|
||||
QColor color = Qt::blue;
|
||||
if (m_resize_mode == 2)
|
||||
color = Qt::darkGreen;
|
||||
else if (m_resize_mode == 3)
|
||||
color = Qt::magenta;
|
||||
|
||||
handler->setColor(color);
|
||||
scene()->addItem(handler);
|
||||
handler->installSceneEventFilter(this);
|
||||
handler->setZValue(this->zValue()+1);
|
||||
}
|
||||
}
|
||||
handler->setColor(color);
|
||||
scene()->addItem(handler);
|
||||
handler->installSceneEventFilter(this);
|
||||
handler->setZValue(this->zValue()+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartArc::removeHandler
|
||||
Remove the handlers of this item
|
||||
@brief PartArc::removeHandler
|
||||
Remove the handlers of this item
|
||||
*/
|
||||
void PartArc::removeHandler()
|
||||
{
|
||||
if (!m_handler_vector.isEmpty())
|
||||
{
|
||||
qDeleteAll(m_handler_vector);
|
||||
m_handler_vector.clear();
|
||||
}
|
||||
if (!m_handler_vector.isEmpty())
|
||||
{
|
||||
qDeleteAll(m_handler_vector);
|
||||
m_handler_vector.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef PART_ARC_H
|
||||
#define PART_ARC_H
|
||||
@@ -24,65 +24,65 @@ class QPropertyUndoCommand;
|
||||
class QetGraphicsHandlerItem;
|
||||
|
||||
/**
|
||||
@brief The PartArc class
|
||||
This class represents an elliptical arc primitive which may be used to
|
||||
compose the drawing of an electrical element within the element editor.
|
||||
@brief The PartArc class
|
||||
This class represents an elliptical arc primitive which may be used to
|
||||
compose the drawing of an electrical element within the element editor.
|
||||
*/
|
||||
class PartArc : public AbstractPartEllipse
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PartArc(QETElementEditor *editor, QGraphicsItem *parent = nullptr);
|
||||
~PartArc() override;
|
||||
|
||||
private:
|
||||
PartArc(const PartArc &);
|
||||
// methods
|
||||
public:
|
||||
enum { Type = UserType + 1101 };
|
||||
/**
|
||||
Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a PartArc.
|
||||
@return the QGraphicsItem type
|
||||
*/
|
||||
int type() const override { return Type; }
|
||||
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override;
|
||||
public:
|
||||
PartArc(QETElementEditor *editor, QGraphicsItem *parent = nullptr);
|
||||
~PartArc() override;
|
||||
|
||||
private:
|
||||
PartArc(const PartArc &);
|
||||
// methods
|
||||
public:
|
||||
enum { Type = UserType + 1101 };
|
||||
/**
|
||||
Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a PartArc.
|
||||
@return the QGraphicsItem type
|
||||
*/
|
||||
int type() const override { return Type; }
|
||||
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override;
|
||||
|
||||
//Name and XML
|
||||
QString name() const override { return(QObject::tr("arc", "element part name")); }
|
||||
QString xmlName() const override { return(QString("arc")); }
|
||||
const QDomElement toXml (QDomDocument &) const override;
|
||||
void fromXml (const QDomElement &) override;
|
||||
//Name and XML
|
||||
QString name() const override { return(QObject::tr("arc", "element part name")); }
|
||||
QString xmlName() const override { return(QString("arc")); }
|
||||
const QDomElement toXml (QDomDocument &) const override;
|
||||
void fromXml (const QDomElement &) override;
|
||||
|
||||
QPainterPath shape() const override;
|
||||
QPainterPath shadowShape() const override;
|
||||
void setRect(const QRectF &rect) override {AbstractPartEllipse::setRect(rect); adjusteHandlerPos();}
|
||||
void setStartAngle(const int &start_angle) override {AbstractPartEllipse::setStartAngle(start_angle); adjusteHandlerPos();}
|
||||
void setSpanAngle(const int &span_angle) override {AbstractPartEllipse::setSpanAngle(span_angle); adjusteHandlerPos();}
|
||||
QRectF sceneGeometricRect() const override;
|
||||
QPainterPath shape() const override;
|
||||
QPainterPath shadowShape() const override;
|
||||
void setRect(const QRectF &rect) override {AbstractPartEllipse::setRect(rect); adjusteHandlerPos();}
|
||||
void setStartAngle(const int &start_angle) override {AbstractPartEllipse::setStartAngle(start_angle); adjusteHandlerPos();}
|
||||
void setSpanAngle(const int &span_angle) override {AbstractPartEllipse::setSpanAngle(span_angle); adjusteHandlerPos();}
|
||||
QRectF sceneGeometricRect() const override;
|
||||
|
||||
protected:
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||
protected:
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||
|
||||
private:
|
||||
void switchResizeMode();
|
||||
void adjusteHandlerPos();
|
||||
void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void sceneSelectionChanged ();
|
||||
|
||||
void addHandler();
|
||||
void removeHandler();
|
||||
private:
|
||||
void switchResizeMode();
|
||||
void adjusteHandlerPos();
|
||||
void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void sceneSelectionChanged ();
|
||||
|
||||
void addHandler();
|
||||
void removeHandler();
|
||||
|
||||
private:
|
||||
QPropertyUndoCommand *m_undo_command = nullptr;
|
||||
QPropertyUndoCommand *m_undo_command2 = nullptr;
|
||||
int m_resize_mode = 1,
|
||||
m_vector_index = -1;
|
||||
QPointF m_span_point;
|
||||
QVector<QetGraphicsHandlerItem *> m_handler_vector;
|
||||
private:
|
||||
QPropertyUndoCommand *m_undo_command = nullptr;
|
||||
QPropertyUndoCommand *m_undo_command2 = nullptr;
|
||||
int m_resize_mode = 1,
|
||||
m_vector_index = -1;
|
||||
QPointF m_span_point;
|
||||
QVector<QetGraphicsHandlerItem *> m_handler_vector;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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.
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "partdynamictextfield.h"
|
||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||
@@ -25,574 +25,574 @@
|
||||
#include <QColor>
|
||||
|
||||
PartDynamicTextField::PartDynamicTextField(QETElementEditor *editor, QGraphicsItem *parent) :
|
||||
QGraphicsTextItem(parent),
|
||||
CustomElementPart(editor),
|
||||
m_uuid(QUuid::createUuid())
|
||||
QGraphicsTextItem(parent),
|
||||
CustomElementPart(editor),
|
||||
m_uuid(QUuid::createUuid())
|
||||
{
|
||||
setDefaultTextColor(Qt::black);
|
||||
setFont(QETApp::dynamicTextsItemFont());
|
||||
QSettings settings;
|
||||
setRotation(settings.value("diagrameditor/dynamic_text_rotation", 0).toInt());
|
||||
setTextWidth(settings.value("diagrameditor/dynamic_text_width", -1).toInt());
|
||||
setText("_");
|
||||
setTextFrom(DynamicElementTextItem::UserText);
|
||||
setFlags(
|
||||
QGraphicsItem::ItemIsSelectable |
|
||||
QGraphicsItem::ItemSendsGeometryChanges |
|
||||
QGraphicsItem::ItemIsMovable
|
||||
);
|
||||
setDefaultTextColor(Qt::black);
|
||||
setFont(QETApp::dynamicTextsItemFont());
|
||||
QSettings settings;
|
||||
setRotation(settings.value("diagrameditor/dynamic_text_rotation", 0).toInt());
|
||||
setTextWidth(settings.value("diagrameditor/dynamic_text_width", -1).toInt());
|
||||
setText("_");
|
||||
setTextFrom(DynamicElementTextItem::UserText);
|
||||
setFlags(
|
||||
QGraphicsItem::ItemIsSelectable |
|
||||
QGraphicsItem::ItemSendsGeometryChanges |
|
||||
QGraphicsItem::ItemIsMovable
|
||||
);
|
||||
|
||||
//Option when text is displayed in multiple line
|
||||
QTextOption option = document() -> defaultTextOption();
|
||||
option.setAlignment(Qt::AlignHCenter);
|
||||
option.setWrapMode(QTextOption::WordWrap);
|
||||
document() -> setDefaultTextOption(option);
|
||||
//Option when text is displayed in multiple line
|
||||
QTextOption option = document() -> defaultTextOption();
|
||||
option.setAlignment(Qt::AlignHCenter);
|
||||
option.setWrapMode(QTextOption::WordWrap);
|
||||
document() -> setDefaultTextOption(option);
|
||||
}
|
||||
|
||||
QString PartDynamicTextField::name() const
|
||||
{
|
||||
return tr("Champ de texte dynamique", "element part name");
|
||||
return tr("Champ de texte dynamique", "element part name");
|
||||
}
|
||||
|
||||
QString PartDynamicTextField::xmlName() const
|
||||
{
|
||||
return QString("dynamic_text");
|
||||
return QString("dynamic_text");
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartDynamicTextField::startUserTransformation
|
||||
@param initial_selection_rect
|
||||
Start the user-induced transformation,
|
||||
provided this primitive is contained
|
||||
within the initial_selection_rect bounding rectangle.
|
||||
@brief PartDynamicTextField::startUserTransformation
|
||||
@param initial_selection_rect
|
||||
Start the user-induced transformation,
|
||||
provided this primitive is contained
|
||||
within the initial_selection_rect bounding rectangle.
|
||||
*/
|
||||
void PartDynamicTextField::startUserTransformation(const QRectF &initial_selection_rect) {
|
||||
Q_UNUSED(initial_selection_rect)
|
||||
m_saved_point = pos(); // scene coordinates, no need to mapFromScene()
|
||||
Q_UNUSED(initial_selection_rect)
|
||||
m_saved_point = pos(); // scene coordinates, no need to mapFromScene()
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartDynamicTextField::handleUserTransformation
|
||||
@param initial_selection_rect
|
||||
@param new_selection_rect
|
||||
Handle the user-induced transformation
|
||||
from initial_selection_rect to new_selection_rect
|
||||
@brief PartDynamicTextField::handleUserTransformation
|
||||
@param initial_selection_rect
|
||||
@param new_selection_rect
|
||||
Handle the user-induced transformation
|
||||
from initial_selection_rect to new_selection_rect
|
||||
*/
|
||||
void PartDynamicTextField::handleUserTransformation(
|
||||
const QRectF &initial_selection_rect,
|
||||
const QRectF &new_selection_rect)
|
||||
const QRectF &initial_selection_rect,
|
||||
const QRectF &new_selection_rect)
|
||||
{
|
||||
QPointF new_pos = mapPoints(
|
||||
initial_selection_rect, new_selection_rect, QList<QPointF>() << m_saved_point).first();
|
||||
setPos(new_pos);
|
||||
QPointF new_pos = mapPoints(
|
||||
initial_selection_rect, new_selection_rect, QList<QPointF>() << m_saved_point).first();
|
||||
setPos(new_pos);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartDynamicTextField::toXml
|
||||
@param dom_doc
|
||||
@return
|
||||
@brief PartDynamicTextField::toXml
|
||||
@param dom_doc
|
||||
@return
|
||||
*/
|
||||
const QDomElement PartDynamicTextField::toXml(QDomDocument &dom_doc) const
|
||||
{
|
||||
QDomElement root_element = dom_doc.createElement(xmlName());
|
||||
QDomElement root_element = dom_doc.createElement(xmlName());
|
||||
|
||||
root_element.setAttribute("x", QString::number(pos().x()));
|
||||
root_element.setAttribute("y", QString::number(pos().y()));
|
||||
root_element.setAttribute("z", QString::number(zValue()));
|
||||
root_element.setAttribute("rotation", QString::number(QET::correctAngle(rotation())));
|
||||
root_element.setAttribute("font", font().toString());
|
||||
root_element.setAttribute("uuid", m_uuid.toString());
|
||||
root_element.setAttribute("frame", m_frame? "true" : "false");
|
||||
root_element.setAttribute("text_width", QString::number(m_text_width));
|
||||
root_element.setAttribute("x", QString::number(pos().x()));
|
||||
root_element.setAttribute("y", QString::number(pos().y()));
|
||||
root_element.setAttribute("z", QString::number(zValue()));
|
||||
root_element.setAttribute("rotation", QString::number(QET::correctAngle(rotation())));
|
||||
root_element.setAttribute("font", font().toString());
|
||||
root_element.setAttribute("uuid", m_uuid.toString());
|
||||
root_element.setAttribute("frame", m_frame? "true" : "false");
|
||||
root_element.setAttribute("text_width", QString::number(m_text_width));
|
||||
|
||||
QMetaEnum me = DynamicElementTextItem::textFromMetaEnum();
|
||||
root_element.setAttribute("text_from", me.valueToKey(m_text_from));
|
||||
QMetaEnum me = DynamicElementTextItem::textFromMetaEnum();
|
||||
root_element.setAttribute("text_from", me.valueToKey(m_text_from));
|
||||
|
||||
me = QMetaEnum::fromType<Qt::Alignment>();
|
||||
if(this -> alignment() &Qt::AlignRight)
|
||||
root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignRight));
|
||||
else if(this -> alignment() &Qt::AlignLeft)
|
||||
root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignLeft));
|
||||
else if(this -> alignment() &Qt::AlignHCenter)
|
||||
root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignHCenter));
|
||||
me = QMetaEnum::fromType<Qt::Alignment>();
|
||||
if(this -> alignment() &Qt::AlignRight)
|
||||
root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignRight));
|
||||
else if(this -> alignment() &Qt::AlignLeft)
|
||||
root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignLeft));
|
||||
else if(this -> alignment() &Qt::AlignHCenter)
|
||||
root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignHCenter));
|
||||
|
||||
if(this -> alignment() &Qt::AlignBottom)
|
||||
root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignBottom));
|
||||
else if(this -> alignment() & Qt::AlignTop)
|
||||
root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignTop));
|
||||
else if(this -> alignment() &Qt::AlignVCenter)
|
||||
root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignVCenter));
|
||||
if(this -> alignment() &Qt::AlignBottom)
|
||||
root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignBottom));
|
||||
else if(this -> alignment() & Qt::AlignTop)
|
||||
root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignTop));
|
||||
else if(this -> alignment() &Qt::AlignVCenter)
|
||||
root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignVCenter));
|
||||
|
||||
QDomElement dom_text = dom_doc.createElement("text");
|
||||
dom_text.appendChild(dom_doc.createTextNode(toPlainText()));
|
||||
root_element.appendChild(dom_text);
|
||||
QDomElement dom_text = dom_doc.createElement("text");
|
||||
dom_text.appendChild(dom_doc.createTextNode(toPlainText()));
|
||||
root_element.appendChild(dom_text);
|
||||
|
||||
//Info name
|
||||
if(!m_info_name.isEmpty()) {
|
||||
QDomElement dom_info_name = dom_doc.createElement("info_name");
|
||||
dom_info_name.appendChild(dom_doc.createTextNode(m_info_name));
|
||||
root_element.appendChild(dom_info_name);
|
||||
}
|
||||
//Info name
|
||||
if(!m_info_name.isEmpty()) {
|
||||
QDomElement dom_info_name = dom_doc.createElement("info_name");
|
||||
dom_info_name.appendChild(dom_doc.createTextNode(m_info_name));
|
||||
root_element.appendChild(dom_info_name);
|
||||
}
|
||||
|
||||
//Composite text
|
||||
if(!m_composite_text.isEmpty()) {
|
||||
QDomElement dom_comp_text = dom_doc.createElement("composite_text");
|
||||
dom_comp_text.appendChild(dom_doc.createTextNode(m_composite_text));
|
||||
root_element.appendChild(dom_comp_text);
|
||||
}
|
||||
//Composite text
|
||||
if(!m_composite_text.isEmpty()) {
|
||||
QDomElement dom_comp_text = dom_doc.createElement("composite_text");
|
||||
dom_comp_text.appendChild(dom_doc.createTextNode(m_composite_text));
|
||||
root_element.appendChild(dom_comp_text);
|
||||
}
|
||||
|
||||
//Color
|
||||
if(color() != QColor(Qt::black)) {
|
||||
QDomElement dom_color = dom_doc.createElement("color");
|
||||
dom_color.appendChild(dom_doc.createTextNode(color().name()));
|
||||
root_element.appendChild(dom_color);
|
||||
}
|
||||
//Color
|
||||
if(color() != QColor(Qt::black)) {
|
||||
QDomElement dom_color = dom_doc.createElement("color");
|
||||
dom_color.appendChild(dom_doc.createTextNode(color().name()));
|
||||
root_element.appendChild(dom_color);
|
||||
}
|
||||
|
||||
return root_element;
|
||||
return root_element;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartDynamicTextField::fromXml
|
||||
@param dom_elmt
|
||||
@brief PartDynamicTextField::fromXml
|
||||
@param dom_elmt
|
||||
*/
|
||||
void PartDynamicTextField::fromXml(const QDomElement &dom_elmt) {
|
||||
if (dom_elmt.tagName() != xmlName()) {
|
||||
qDebug() << "PartDynamicTextField::fromXml : Wrong tagg name";
|
||||
return;
|
||||
}
|
||||
if (dom_elmt.tagName() != xmlName()) {
|
||||
qDebug() << "PartDynamicTextField::fromXml : Wrong tagg name";
|
||||
return;
|
||||
}
|
||||
|
||||
QGraphicsTextItem::setPos(
|
||||
dom_elmt.attribute("x", QString::number(0)).toDouble(),
|
||||
dom_elmt.attribute("y", QString::number(0)).toDouble()
|
||||
);
|
||||
setZValue(dom_elmt.attribute("z", QString::number(zValue())).toDouble());
|
||||
QGraphicsTextItem::setRotation(dom_elmt.attribute("rotation", QString::number(0)).toDouble());
|
||||
QGraphicsTextItem::setPos(
|
||||
dom_elmt.attribute("x", QString::number(0)).toDouble(),
|
||||
dom_elmt.attribute("y", QString::number(0)).toDouble()
|
||||
);
|
||||
setZValue(dom_elmt.attribute("z", QString::number(zValue())).toDouble());
|
||||
QGraphicsTextItem::setRotation(dom_elmt.attribute("rotation", QString::number(0)).toDouble());
|
||||
|
||||
if (dom_elmt.hasAttribute("font")) {
|
||||
QFont font_;
|
||||
font_.fromString(dom_elmt.attribute("font"));
|
||||
setFont(font_);
|
||||
}
|
||||
else {
|
||||
if (dom_elmt.hasAttribute("font")) {
|
||||
QFont font_;
|
||||
font_.fromString(dom_elmt.attribute("font"));
|
||||
setFont(font_);
|
||||
}
|
||||
else {
|
||||
#if TODO_LIST
|
||||
#pragma message("@TODO remove in futur")
|
||||
#endif
|
||||
//Keep compatibility TODO remove in futur
|
||||
setFont(QETApp::dynamicTextsItemFont(9));
|
||||
}
|
||||
//Keep compatibility TODO remove in futur
|
||||
setFont(QETApp::dynamicTextsItemFont(9));
|
||||
}
|
||||
|
||||
m_uuid = QUuid(dom_elmt.attribute("uuid", QUuid::createUuid().toString()));
|
||||
setFrame(dom_elmt.attribute("frame", "false") == "true"? true : false);
|
||||
setTextWidth(dom_elmt.attribute("text_width", QString::number(-1)).toDouble());
|
||||
m_uuid = QUuid(dom_elmt.attribute("uuid", QUuid::createUuid().toString()));
|
||||
setFrame(dom_elmt.attribute("frame", "false") == "true"? true : false);
|
||||
setTextWidth(dom_elmt.attribute("text_width", QString::number(-1)).toDouble());
|
||||
|
||||
QMetaEnum me = DynamicElementTextItem::textFromMetaEnum();
|
||||
m_text_from = DynamicElementTextItem::TextFrom(
|
||||
me.keyToValue(dom_elmt.attribute("text_from").toStdString().data()));
|
||||
QMetaEnum me = DynamicElementTextItem::textFromMetaEnum();
|
||||
m_text_from = DynamicElementTextItem::TextFrom(
|
||||
me.keyToValue(dom_elmt.attribute("text_from").toStdString().data()));
|
||||
|
||||
me = QMetaEnum::fromType<Qt::Alignment>();
|
||||
if(dom_elmt.hasAttribute("Halignment"))
|
||||
setAlignment(Qt::Alignment(
|
||||
me.keyToValue(dom_elmt.attribute("Halignment").toStdString().data())));
|
||||
if(dom_elmt.hasAttribute(("Valignment")))
|
||||
setAlignment(Qt::Alignment(
|
||||
me.keyToValue(dom_elmt.attribute("Valignment").toStdString().data())) | this -> alignment());
|
||||
me = QMetaEnum::fromType<Qt::Alignment>();
|
||||
if(dom_elmt.hasAttribute("Halignment"))
|
||||
setAlignment(Qt::Alignment(
|
||||
me.keyToValue(dom_elmt.attribute("Halignment").toStdString().data())));
|
||||
if(dom_elmt.hasAttribute(("Valignment")))
|
||||
setAlignment(Qt::Alignment(
|
||||
me.keyToValue(dom_elmt.attribute("Valignment").toStdString().data())) | this -> alignment());
|
||||
|
||||
//Text
|
||||
QDomElement dom_text = dom_elmt.firstChildElement("text");
|
||||
if (!dom_text.isNull()) {
|
||||
m_text = dom_text.text();
|
||||
m_block_alignment = true;
|
||||
setPlainText(m_text);
|
||||
m_block_alignment = false;
|
||||
}
|
||||
//Text
|
||||
QDomElement dom_text = dom_elmt.firstChildElement("text");
|
||||
if (!dom_text.isNull()) {
|
||||
m_text = dom_text.text();
|
||||
m_block_alignment = true;
|
||||
setPlainText(m_text);
|
||||
m_block_alignment = false;
|
||||
}
|
||||
|
||||
//Info name
|
||||
QDomElement dom_info_name = dom_elmt.firstChildElement("info_name");
|
||||
if(!dom_info_name.isNull())
|
||||
m_info_name = dom_info_name.text();
|
||||
//Info name
|
||||
QDomElement dom_info_name = dom_elmt.firstChildElement("info_name");
|
||||
if(!dom_info_name.isNull())
|
||||
m_info_name = dom_info_name.text();
|
||||
|
||||
//Composite text
|
||||
QDomElement dom_comp_text = dom_elmt.firstChildElement("composite_text");
|
||||
if(!dom_comp_text.isNull())
|
||||
m_composite_text = dom_comp_text.text();
|
||||
//Composite text
|
||||
QDomElement dom_comp_text = dom_elmt.firstChildElement("composite_text");
|
||||
if(!dom_comp_text.isNull())
|
||||
m_composite_text = dom_comp_text.text();
|
||||
|
||||
//Color
|
||||
QDomElement dom_color = dom_elmt.firstChildElement("color");
|
||||
if(!dom_color.isNull())
|
||||
setColor(QColor(dom_color.text()));
|
||||
//Color
|
||||
QDomElement dom_color = dom_elmt.firstChildElement("color");
|
||||
if(!dom_color.isNull())
|
||||
setColor(QColor(dom_color.text()));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartDynamicTextField::fromTextFieldXml
|
||||
Setup this text from the xml definition
|
||||
of a text field (The xml tagg of a text field is "input");
|
||||
@param dom_element
|
||||
@brief PartDynamicTextField::fromTextFieldXml
|
||||
Setup this text from the xml definition
|
||||
of a text field (The xml tagg of a text field is "input");
|
||||
@param dom_element
|
||||
*/
|
||||
void PartDynamicTextField::fromTextFieldXml(const QDomElement &dom_element)
|
||||
{
|
||||
if(dom_element.tagName() != "input")
|
||||
return;
|
||||
if(dom_element.tagName() != "input")
|
||||
return;
|
||||
|
||||
setFont(QETApp::diagramTextsFont(dom_element.attribute("size", QString::number(9)).toInt()));
|
||||
setFont(QETApp::diagramTextsFont(dom_element.attribute("size", QString::number(9)).toInt()));
|
||||
|
||||
if(dom_element.attribute("tagg", "none") == "none") {
|
||||
setTextFrom(DynamicElementTextItem::UserText);
|
||||
setText(dom_element.attribute("text", "_"));
|
||||
}
|
||||
else {
|
||||
setTextFrom(DynamicElementTextItem::ElementInfo);
|
||||
setInfoName(dom_element.attribute("tagg", "label"));
|
||||
}
|
||||
if(dom_element.attribute("tagg", "none") == "none") {
|
||||
setTextFrom(DynamicElementTextItem::UserText);
|
||||
setText(dom_element.attribute("text", "_"));
|
||||
}
|
||||
else {
|
||||
setTextFrom(DynamicElementTextItem::ElementInfo);
|
||||
setInfoName(dom_element.attribute("tagg", "label"));
|
||||
}
|
||||
|
||||
QGraphicsTextItem::setRotation(dom_element.attribute("rotation", "0").toDouble());
|
||||
QGraphicsTextItem::setRotation(dom_element.attribute("rotation", "0").toDouble());
|
||||
|
||||
//the origin transformation point of PartDynamicTextField is the top left corner, no matter the font size
|
||||
//The origin transformation point of PartTextField is the middle of left edge, and so by definition, change with the size of the font
|
||||
//We need to use a QTransform to find the pos of this text from the saved pos of text item
|
||||
QTransform transform;
|
||||
//First make the rotation
|
||||
transform.rotate(dom_element.attribute("rotation", "0").toDouble());
|
||||
QPointF pos = transform.map(QPointF(0, -boundingRect().height()/2));
|
||||
transform.reset();
|
||||
//Second translate to the pos
|
||||
transform.translate(
|
||||
dom_element.attribute("x", QString::number(0)).toDouble(),
|
||||
dom_element.attribute("y", QString::number(0)).toDouble()
|
||||
);
|
||||
QGraphicsTextItem::setPos(transform.map(pos));
|
||||
//the origin transformation point of PartDynamicTextField is the top left corner, no matter the font size
|
||||
//The origin transformation point of PartTextField is the middle of left edge, and so by definition, change with the size of the font
|
||||
//We need to use a QTransform to find the pos of this text from the saved pos of text item
|
||||
QTransform transform;
|
||||
//First make the rotation
|
||||
transform.rotate(dom_element.attribute("rotation", "0").toDouble());
|
||||
QPointF pos = transform.map(QPointF(0, -boundingRect().height()/2));
|
||||
transform.reset();
|
||||
//Second translate to the pos
|
||||
transform.translate(
|
||||
dom_element.attribute("x", QString::number(0)).toDouble(),
|
||||
dom_element.attribute("y", QString::number(0)).toDouble()
|
||||
);
|
||||
QGraphicsTextItem::setPos(transform.map(pos));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartDynamicTextField::textFrom
|
||||
@return what the final text is created from.
|
||||
@brief PartDynamicTextField::textFrom
|
||||
@return what the final text is created from.
|
||||
*/
|
||||
DynamicElementTextItem::TextFrom PartDynamicTextField::textFrom() const
|
||||
{
|
||||
return m_text_from;
|
||||
return m_text_from;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartDynamicTextField::setTextFrom
|
||||
Set the final text is created from.
|
||||
@param text_from
|
||||
@brief PartDynamicTextField::setTextFrom
|
||||
Set the final text is created from.
|
||||
@param text_from
|
||||
*/
|
||||
void PartDynamicTextField::setTextFrom(DynamicElementTextItem::TextFrom text_from) {
|
||||
m_text_from = text_from;
|
||||
switch (m_text_from) {
|
||||
case DynamicElementTextItem::UserText:
|
||||
setPlainText(m_text);
|
||||
break;
|
||||
case DynamicElementTextItem::ElementInfo:
|
||||
setInfoName(m_info_name);
|
||||
break;
|
||||
case DynamicElementTextItem::CompositeText:
|
||||
setCompositeText(m_composite_text);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
emit textFromChanged(m_text_from);
|
||||
m_text_from = text_from;
|
||||
switch (m_text_from) {
|
||||
case DynamicElementTextItem::UserText:
|
||||
setPlainText(m_text);
|
||||
break;
|
||||
case DynamicElementTextItem::ElementInfo:
|
||||
setInfoName(m_info_name);
|
||||
break;
|
||||
case DynamicElementTextItem::CompositeText:
|
||||
setCompositeText(m_composite_text);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
emit textFromChanged(m_text_from);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartDynamicTextField::text
|
||||
@return the text of this text
|
||||
@brief PartDynamicTextField::text
|
||||
@return the text of this text
|
||||
*/
|
||||
QString PartDynamicTextField::text() const
|
||||
{
|
||||
return m_text;
|
||||
return m_text;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartDynamicTextField::setText
|
||||
Set the text of this text
|
||||
@param text
|
||||
@brief PartDynamicTextField::setText
|
||||
Set the text of this text
|
||||
@param text
|
||||
*/
|
||||
void PartDynamicTextField::setText(const QString &text) {
|
||||
m_text = text;
|
||||
setPlainText(m_text);
|
||||
emit textChanged(m_text);
|
||||
m_text = text;
|
||||
setPlainText(m_text);
|
||||
emit textChanged(m_text);
|
||||
}
|
||||
|
||||
void PartDynamicTextField::setInfoName(const QString &info_name) {
|
||||
m_info_name = info_name;
|
||||
if(m_text_from == DynamicElementTextItem::ElementInfo && elementScene())
|
||||
setPlainText(elementScene() -> elementInformation().value(m_info_name).toString());
|
||||
emit infoNameChanged(m_info_name);
|
||||
m_info_name = info_name;
|
||||
if(m_text_from == DynamicElementTextItem::ElementInfo && elementScene())
|
||||
setPlainText(elementScene() -> elementInformation().value(m_info_name).toString());
|
||||
emit infoNameChanged(m_info_name);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartDynamicTextField::infoName
|
||||
@return the info name of this text
|
||||
@brief PartDynamicTextField::infoName
|
||||
@return the info name of this text
|
||||
*/
|
||||
QString PartDynamicTextField::infoName() const{
|
||||
return m_info_name;
|
||||
return m_info_name;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartDynamicTextField::setCompositeText
|
||||
Set the composite text of this text item to text
|
||||
@param text
|
||||
@brief PartDynamicTextField::setCompositeText
|
||||
Set the composite text of this text item to text
|
||||
@param text
|
||||
*/
|
||||
void PartDynamicTextField::setCompositeText(const QString &text) {
|
||||
m_composite_text = text;
|
||||
if(m_text_from == DynamicElementTextItem::CompositeText && elementScene())
|
||||
setPlainText(autonum::AssignVariables::replaceVariable(m_composite_text, elementScene() -> elementInformation()));
|
||||
emit compositeTextChanged(m_composite_text);
|
||||
m_composite_text = text;
|
||||
if(m_text_from == DynamicElementTextItem::CompositeText && elementScene())
|
||||
setPlainText(autonum::AssignVariables::replaceVariable(m_composite_text, elementScene() -> elementInformation()));
|
||||
emit compositeTextChanged(m_composite_text);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartDynamicTextField::compositeText
|
||||
@return the composite text of this text
|
||||
@brief PartDynamicTextField::compositeText
|
||||
@return the composite text of this text
|
||||
*/
|
||||
QString PartDynamicTextField::compositeText() const
|
||||
{
|
||||
return m_composite_text;
|
||||
return m_composite_text;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartDynamicTextField::setColor
|
||||
@param color set text color to color
|
||||
@brief PartDynamicTextField::setColor
|
||||
@param color set text color to color
|
||||
*/
|
||||
void PartDynamicTextField::setColor(const QColor& color) {
|
||||
setDefaultTextColor(color);
|
||||
emit colorChanged(color);
|
||||
setDefaultTextColor(color);
|
||||
emit colorChanged(color);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartDynamicTextField::color
|
||||
@return The color of this text
|
||||
@brief PartDynamicTextField::color
|
||||
@return The color of this text
|
||||
*/
|
||||
QColor PartDynamicTextField::color() const
|
||||
{
|
||||
return defaultTextColor();
|
||||
return defaultTextColor();
|
||||
}
|
||||
|
||||
void PartDynamicTextField::setFrame(bool frame) {
|
||||
m_frame = frame;
|
||||
update();
|
||||
emit frameChanged(m_frame);
|
||||
m_frame = frame;
|
||||
update();
|
||||
emit frameChanged(m_frame);
|
||||
}
|
||||
|
||||
bool PartDynamicTextField::frame() const
|
||||
{
|
||||
return m_frame;
|
||||
return m_frame;
|
||||
}
|
||||
|
||||
void PartDynamicTextField::setTextWidth(qreal width) {
|
||||
this -> document() -> setTextWidth(width);
|
||||
this -> document() -> setTextWidth(width);
|
||||
|
||||
//Adjust the width, to ideal width if needed
|
||||
if(width > 0 && document() -> size().width() > width)
|
||||
document() -> setTextWidth(document() -> idealWidth());
|
||||
//Adjust the width, to ideal width if needed
|
||||
if(width > 0 && document() -> size().width() > width)
|
||||
document() -> setTextWidth(document() -> idealWidth());
|
||||
|
||||
m_text_width = document() -> textWidth();
|
||||
emit textWidthChanged(m_text_width);
|
||||
m_text_width = document() -> textWidth();
|
||||
emit textWidthChanged(m_text_width);
|
||||
}
|
||||
|
||||
void PartDynamicTextField::setPlainText(const QString &text) {
|
||||
if(toPlainText() == text)
|
||||
return;
|
||||
if(toPlainText() == text)
|
||||
return;
|
||||
|
||||
prepareAlignment();
|
||||
QGraphicsTextItem::setPlainText(text);
|
||||
prepareAlignment();
|
||||
QGraphicsTextItem::setPlainText(text);
|
||||
|
||||
//User define a text width
|
||||
if(m_text_width > 0) {
|
||||
if(document() -> size().width() > m_text_width) {
|
||||
document() -> setTextWidth(m_text_width);
|
||||
if(document() -> size().width() > m_text_width) {
|
||||
document() -> setTextWidth(document() -> idealWidth());
|
||||
}
|
||||
}
|
||||
}
|
||||
finishAlignment();
|
||||
//User define a text width
|
||||
if(m_text_width > 0) {
|
||||
if(document() -> size().width() > m_text_width) {
|
||||
document() -> setTextWidth(m_text_width);
|
||||
if(document() -> size().width() > m_text_width) {
|
||||
document() -> setTextWidth(document() -> idealWidth());
|
||||
}
|
||||
}
|
||||
}
|
||||
finishAlignment();
|
||||
}
|
||||
|
||||
void PartDynamicTextField::setAlignment(Qt::Alignment alignment) {
|
||||
m_alignment = alignment;
|
||||
emit alignmentChanged(m_alignment);
|
||||
m_alignment = alignment;
|
||||
emit alignmentChanged(m_alignment);
|
||||
}
|
||||
|
||||
Qt::Alignment PartDynamicTextField::alignment() const
|
||||
{
|
||||
return m_alignment;
|
||||
return m_alignment;
|
||||
}
|
||||
|
||||
void PartDynamicTextField::setFont(const QFont &font) {
|
||||
if (font == this -> font()) {
|
||||
return;
|
||||
}
|
||||
prepareAlignment();
|
||||
QGraphicsTextItem::setFont(font);
|
||||
finishAlignment();
|
||||
emit fontChanged(font);
|
||||
if (font == this -> font()) {
|
||||
return;
|
||||
}
|
||||
prepareAlignment();
|
||||
QGraphicsTextItem::setFont(font);
|
||||
finishAlignment();
|
||||
emit fontChanged(font);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartDynamicTextField::mouseMoveEvent
|
||||
@param event
|
||||
@brief PartDynamicTextField::mouseMoveEvent
|
||||
@param event
|
||||
*/
|
||||
void PartDynamicTextField::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if((event -> buttons() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable)) {
|
||||
QPointF pos = event -> scenePos() + (m_origine_pos - event -> buttonDownScenePos(Qt::LeftButton));
|
||||
event -> modifiers() == Qt::ControlModifier ? setPos(pos) : setPos(elementScene() -> snapToGrid(pos));
|
||||
}
|
||||
else
|
||||
QGraphicsObject::mouseMoveEvent(event);
|
||||
if((event -> buttons() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable)) {
|
||||
QPointF pos = event -> scenePos() + (m_origine_pos - event -> buttonDownScenePos(Qt::LeftButton));
|
||||
event -> modifiers() == Qt::ControlModifier ? setPos(pos) : setPos(elementScene() -> snapToGrid(pos));
|
||||
}
|
||||
else
|
||||
QGraphicsObject::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartDynamicTextField::mousePressEvent
|
||||
@param event
|
||||
@brief PartDynamicTextField::mousePressEvent
|
||||
@param event
|
||||
*/
|
||||
void PartDynamicTextField::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if(event -> button() == Qt::LeftButton)
|
||||
m_origine_pos = this -> pos();
|
||||
if(event -> button() == Qt::LeftButton)
|
||||
m_origine_pos = this -> pos();
|
||||
|
||||
QGraphicsObject::mousePressEvent(event);
|
||||
QGraphicsObject::mousePressEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartDynamicTextField::mouseReleaseEvent
|
||||
@param event
|
||||
@brief PartDynamicTextField::mouseReleaseEvent
|
||||
@param event
|
||||
*/
|
||||
void PartDynamicTextField::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if((event -> button() & Qt::LeftButton) &&
|
||||
(flags() & QGraphicsItem::ItemIsMovable) &&
|
||||
m_origine_pos != pos()) {
|
||||
QPropertyUndoCommand *undo =\
|
||||
new QPropertyUndoCommand(this, "pos", QVariant(m_origine_pos), QVariant(pos()));
|
||||
undo -> setText(tr("Déplacer un champ texte"));
|
||||
undo -> enableAnimation();
|
||||
elementScene() -> undoStack().push(undo);
|
||||
}
|
||||
if((event -> button() & Qt::LeftButton) &&
|
||||
(flags() & QGraphicsItem::ItemIsMovable) &&
|
||||
m_origine_pos != pos()) {
|
||||
QPropertyUndoCommand *undo =\
|
||||
new QPropertyUndoCommand(this, "pos", QVariant(m_origine_pos), QVariant(pos()));
|
||||
undo -> setText(tr("D??placer un champ texte"));
|
||||
undo -> enableAnimation();
|
||||
elementScene() -> undoStack().push(undo);
|
||||
}
|
||||
|
||||
QGraphicsObject::mouseReleaseEvent(event);
|
||||
QGraphicsObject::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartDynamicTextField::itemChange
|
||||
@param change
|
||||
@param value
|
||||
@return
|
||||
@brief PartDynamicTextField::itemChange
|
||||
@param change
|
||||
@param value
|
||||
@return
|
||||
*/
|
||||
QVariant PartDynamicTextField::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) {
|
||||
if (change == QGraphicsItem::ItemPositionHasChanged || change == QGraphicsItem::ItemSceneHasChanged) {
|
||||
updateCurrentPartEditor();
|
||||
if(change == QGraphicsItem::ItemSceneHasChanged &&
|
||||
m_first_add &&
|
||||
elementScene() != nullptr)
|
||||
{
|
||||
connect(elementScene(), &ElementScene::elementInfoChanged,
|
||||
this, &PartDynamicTextField::elementInfoChanged);
|
||||
m_first_add = false;
|
||||
}
|
||||
}
|
||||
else if ((change == QGraphicsItem::ItemSelectedHasChanged) && (value.toBool() == true))
|
||||
updateCurrentPartEditor();
|
||||
if (change == QGraphicsItem::ItemPositionHasChanged || change == QGraphicsItem::ItemSceneHasChanged) {
|
||||
updateCurrentPartEditor();
|
||||
if(change == QGraphicsItem::ItemSceneHasChanged &&
|
||||
m_first_add &&
|
||||
elementScene() != nullptr)
|
||||
{
|
||||
connect(elementScene(), &ElementScene::elementInfoChanged,
|
||||
this, &PartDynamicTextField::elementInfoChanged);
|
||||
m_first_add = false;
|
||||
}
|
||||
}
|
||||
else if ((change == QGraphicsItem::ItemSelectedHasChanged) && (value.toBool() == true))
|
||||
updateCurrentPartEditor();
|
||||
|
||||
return(QGraphicsTextItem::itemChange(change, value));
|
||||
return(QGraphicsTextItem::itemChange(change, value));
|
||||
}
|
||||
|
||||
void PartDynamicTextField::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
|
||||
QGraphicsTextItem::paint(painter, option, widget);
|
||||
QGraphicsTextItem::paint(painter, option, widget);
|
||||
|
||||
if (m_frame) {
|
||||
painter -> save();
|
||||
painter -> setFont(this -> font());
|
||||
if (m_frame) {
|
||||
painter -> save();
|
||||
painter -> setFont(this -> font());
|
||||
|
||||
//Adjust the thickness according to the font size,
|
||||
qreal w=0.3;
|
||||
if(this -> font().pointSize() >= 5) {
|
||||
w = this -> font().pointSizeF()*0.1;
|
||||
if(w > 2.5)
|
||||
w = 2.5;
|
||||
}
|
||||
//Adjust the thickness according to the font size,
|
||||
qreal w=0.3;
|
||||
if(this -> font().pointSize() >= 5) {
|
||||
w = this -> font().pointSizeF()*0.1;
|
||||
if(w > 2.5)
|
||||
w = 2.5;
|
||||
}
|
||||
|
||||
QPen pen;
|
||||
pen.setColor(color());
|
||||
pen.setWidthF(w);
|
||||
painter -> setPen(pen);
|
||||
painter -> setRenderHint(QPainter::Antialiasing);
|
||||
QPen pen;
|
||||
pen.setColor(color());
|
||||
pen.setWidthF(w);
|
||||
painter -> setPen(pen);
|
||||
painter -> setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
//Get the bounding rectangle of the text
|
||||
QSizeF size = document() -> size();
|
||||
size.setWidth(document() -> idealWidth());
|
||||
//Remove the margin. Size is exactly the bounding rect of the text
|
||||
size.rheight() -= document() -> documentMargin()*2;
|
||||
size.rwidth() -= document() -> documentMargin()*2;
|
||||
//Add a little margin only for a better visual;
|
||||
size.rheight() += 2;
|
||||
size.rwidth() += 2;
|
||||
//Get the bounding rectangle of the text
|
||||
QSizeF size = document() -> size();
|
||||
size.setWidth(document() -> idealWidth());
|
||||
//Remove the margin. Size is exactly the bounding rect of the text
|
||||
size.rheight() -= document() -> documentMargin()*2;
|
||||
size.rwidth() -= document() -> documentMargin()*2;
|
||||
//Add a little margin only for a better visual;
|
||||
size.rheight() += 2;
|
||||
size.rwidth() += 2;
|
||||
|
||||
//The pos of the rect
|
||||
QPointF pos = boundingRect().center();
|
||||
pos.rx() -= size.width()/2;
|
||||
pos.ry() -= size.height()/2;
|
||||
//The pos of the rect
|
||||
QPointF pos = boundingRect().center();
|
||||
pos.rx() -= size.width()/2;
|
||||
pos.ry() -= size.height()/2;
|
||||
|
||||
//Adjust the rounding of the rectangle according to the size of the font
|
||||
qreal ro = this -> font().pointSizeF()/3;
|
||||
painter -> drawRoundedRect(QRectF(pos, size), ro, ro);
|
||||
//Adjust the rounding of the rectangle according to the size of the font
|
||||
qreal ro = this -> font().pointSizeF()/3;
|
||||
painter -> drawRoundedRect(QRectF(pos, size), ro, ro);
|
||||
|
||||
painter -> restore();
|
||||
}
|
||||
painter -> restore();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartDynamicTextField::elementInfoChanged
|
||||
Used to up to date this text field,
|
||||
when the element information (see elementScene) changed
|
||||
@brief PartDynamicTextField::elementInfoChanged
|
||||
Used to up to date this text field,
|
||||
when the element information (see elementScene) changed
|
||||
*/
|
||||
void PartDynamicTextField::elementInfoChanged()
|
||||
{
|
||||
if(!elementScene())
|
||||
return;
|
||||
if(!elementScene())
|
||||
return;
|
||||
|
||||
if(m_text_from == DynamicElementTextItem::ElementInfo)
|
||||
setPlainText(elementScene() -> elementInformation().value(m_info_name).toString());
|
||||
else if (m_text_from == DynamicElementTextItem::CompositeText && elementScene())
|
||||
setPlainText(autonum::AssignVariables::replaceVariable(
|
||||
m_composite_text, elementScene() -> elementInformation()));
|
||||
if(m_text_from == DynamicElementTextItem::ElementInfo)
|
||||
setPlainText(elementScene() -> elementInformation().value(m_info_name).toString());
|
||||
else if (m_text_from == DynamicElementTextItem::CompositeText && elementScene())
|
||||
setPlainText(autonum::AssignVariables::replaceVariable(
|
||||
m_composite_text, elementScene() -> elementInformation()));
|
||||
}
|
||||
|
||||
void PartDynamicTextField::prepareAlignment()
|
||||
{
|
||||
m_alignment_rect = boundingRect();
|
||||
m_alignment_rect = boundingRect();
|
||||
}
|
||||
|
||||
void PartDynamicTextField::finishAlignment()
|
||||
{
|
||||
if(m_block_alignment)
|
||||
return;
|
||||
if(m_block_alignment)
|
||||
return;
|
||||
|
||||
QTransform transform;
|
||||
transform.rotate(this -> rotation());
|
||||
qreal x,xa, y,ya;
|
||||
x=xa=0;
|
||||
y=ya=0;
|
||||
QTransform transform;
|
||||
transform.rotate(this -> rotation());
|
||||
qreal x,xa, y,ya;
|
||||
x=xa=0;
|
||||
y=ya=0;
|
||||
|
||||
if(m_alignment &Qt::AlignRight) {
|
||||
x = m_alignment_rect.right();
|
||||
xa = boundingRect().right();
|
||||
}
|
||||
else if(m_alignment &Qt::AlignHCenter) {
|
||||
x = m_alignment_rect.center().x();
|
||||
xa = boundingRect().center().x();
|
||||
}
|
||||
if(m_alignment &Qt::AlignRight) {
|
||||
x = m_alignment_rect.right();
|
||||
xa = boundingRect().right();
|
||||
}
|
||||
else if(m_alignment &Qt::AlignHCenter) {
|
||||
x = m_alignment_rect.center().x();
|
||||
xa = boundingRect().center().x();
|
||||
}
|
||||
|
||||
if(m_alignment &Qt::AlignBottom) {
|
||||
y = m_alignment_rect.bottom();
|
||||
ya = boundingRect().bottom();
|
||||
}
|
||||
else if(m_alignment &Qt::AlignVCenter) {
|
||||
y = m_alignment_rect.center().y();
|
||||
ya = boundingRect().center().y();
|
||||
}
|
||||
if(m_alignment &Qt::AlignBottom) {
|
||||
y = m_alignment_rect.bottom();
|
||||
ya = boundingRect().bottom();
|
||||
}
|
||||
else if(m_alignment &Qt::AlignVCenter) {
|
||||
y = m_alignment_rect.center().y();
|
||||
ya = boundingRect().center().y();
|
||||
}
|
||||
|
||||
QPointF p = transform.map(QPointF(x,y));
|
||||
QPointF pa = transform.map(QPointF(xa,ya));
|
||||
QPointF diff = pa-p;
|
||||
QPointF p = transform.map(QPointF(x,y));
|
||||
QPointF pa = transform.map(QPointF(xa,ya));
|
||||
QPointF diff = pa-p;
|
||||
|
||||
setPos(this -> pos() - diff);
|
||||
setPos(this -> pos() - diff);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef PARTDYNAMICTEXTFIELD_H
|
||||
#define PARTDYNAMICTEXTFIELD_H
|
||||
@@ -23,106 +23,106 @@
|
||||
#include "dynamicelementtextitem.h"
|
||||
|
||||
/**
|
||||
@brief The PartDynamicTextField class
|
||||
This class represents an editable dynamic text field
|
||||
which may be used to compose the
|
||||
drawing of an electrical element within the element editor.
|
||||
The field will remain editable once the element is added onto
|
||||
a diagram
|
||||
@brief The PartDynamicTextField class
|
||||
This class represents an editable dynamic text field
|
||||
which may be used to compose the
|
||||
drawing of an electrical element within the element editor.
|
||||
The field will remain editable once the element is added onto
|
||||
a diagram
|
||||
*/
|
||||
class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
|
||||
Q_PROPERTY(DynamicElementTextItem::TextFrom textFrom READ textFrom WRITE setTextFrom NOTIFY textFromChanged)
|
||||
Q_PROPERTY(QString infoName READ infoName WRITE setInfoName NOTIFY infoNameChanged)
|
||||
Q_PROPERTY(QString compositeText READ compositeText WRITE setCompositeText NOTIFY compositeTextChanged)
|
||||
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
||||
Q_PROPERTY(bool frame READ frame WRITE setFrame NOTIFY frameChanged)
|
||||
Q_PROPERTY(qreal textWidth READ textWidth WRITE setTextWidth NOTIFY textWidthChanged)
|
||||
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
|
||||
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
|
||||
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
|
||||
Q_PROPERTY(DynamicElementTextItem::TextFrom textFrom READ textFrom WRITE setTextFrom NOTIFY textFromChanged)
|
||||
Q_PROPERTY(QString infoName READ infoName WRITE setInfoName NOTIFY infoNameChanged)
|
||||
Q_PROPERTY(QString compositeText READ compositeText WRITE setCompositeText NOTIFY compositeTextChanged)
|
||||
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
||||
Q_PROPERTY(bool frame READ frame WRITE setFrame NOTIFY frameChanged)
|
||||
Q_PROPERTY(qreal textWidth READ textWidth WRITE setTextWidth NOTIFY textWidthChanged)
|
||||
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
|
||||
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
|
||||
|
||||
public:
|
||||
///PROPERTY
|
||||
void setProperty(const char *name, const QVariant &value) override {QGraphicsTextItem::setProperty(name, value);}
|
||||
QVariant property(const char *name) const override {return QGraphicsTextItem::property(name);}
|
||||
public:
|
||||
///PROPERTY
|
||||
void setProperty(const char *name, const QVariant &value) override {QGraphicsTextItem::setProperty(name, value);}
|
||||
QVariant property(const char *name) const override {return QGraphicsTextItem::property(name);}
|
||||
|
||||
signals:
|
||||
void taggChanged(QString tagg);
|
||||
void textChanged(QString text);
|
||||
void textFromChanged(DynamicElementTextItem::TextFrom text_from);
|
||||
void infoNameChanged(QString info);
|
||||
void compositeTextChanged(QString text);
|
||||
void colorChanged(QColor color);
|
||||
void frameChanged(bool frame);
|
||||
void textWidthChanged(qreal width);
|
||||
void alignmentChanged(Qt::Alignment alignment);
|
||||
void fontChanged(QFont font);
|
||||
signals:
|
||||
void taggChanged(QString tagg);
|
||||
void textChanged(QString text);
|
||||
void textFromChanged(DynamicElementTextItem::TextFrom text_from);
|
||||
void infoNameChanged(QString info);
|
||||
void compositeTextChanged(QString text);
|
||||
void colorChanged(QColor color);
|
||||
void frameChanged(bool frame);
|
||||
void textWidthChanged(qreal width);
|
||||
void alignmentChanged(Qt::Alignment alignment);
|
||||
void fontChanged(QFont font);
|
||||
|
||||
public:
|
||||
PartDynamicTextField(QETElementEditor *editor, QGraphicsItem *parent = nullptr);
|
||||
public:
|
||||
PartDynamicTextField(QETElementEditor *editor, QGraphicsItem *parent = nullptr);
|
||||
|
||||
enum {Type = UserType + 1110};
|
||||
int type() const override {return Type;}
|
||||
enum {Type = UserType + 1110};
|
||||
int type() const override {return Type;}
|
||||
|
||||
QString name() const override;
|
||||
QString xmlName() const override;
|
||||
static QString xmlTaggName() {return QString("dynamic_text");}
|
||||
bool isUseless() const override {return false;}
|
||||
QRectF sceneGeometricRect() const override {return sceneBoundingRect();}
|
||||
void startUserTransformation(const QRectF &initial_selection_rect) override;
|
||||
void handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect) override;
|
||||
QString name() const override;
|
||||
QString xmlName() const override;
|
||||
static QString xmlTaggName() {return QString("dynamic_text");}
|
||||
bool isUseless() const override {return false;}
|
||||
QRectF sceneGeometricRect() const override {return sceneBoundingRect();}
|
||||
void startUserTransformation(const QRectF &initial_selection_rect) override;
|
||||
void handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect) override;
|
||||
|
||||
const QDomElement toXml(QDomDocument &dom_doc) const override;
|
||||
void fromXml(const QDomElement &dom_elmt) override;
|
||||
void fromTextFieldXml(const QDomElement &dom_element);
|
||||
const QDomElement toXml(QDomDocument &dom_doc) const override;
|
||||
void fromXml(const QDomElement &dom_elmt) override;
|
||||
void fromTextFieldXml(const QDomElement &dom_element);
|
||||
|
||||
DynamicElementTextItem::TextFrom textFrom() const;
|
||||
void setTextFrom (DynamicElementTextItem::TextFrom text_from);
|
||||
QString text() const;
|
||||
void setText(const QString &text);
|
||||
void setInfoName(const QString &info_name);
|
||||
QString infoName() const;
|
||||
void setCompositeText(const QString &text);
|
||||
QString compositeText() const;
|
||||
void setColor(const QColor& color);
|
||||
QColor color() const;
|
||||
void setFrame(bool frame);
|
||||
bool frame() const;
|
||||
void setTextWidth(qreal width);
|
||||
void setPlainText(const QString &text);
|
||||
void setAlignment(Qt::Alignment alignment);
|
||||
Qt::Alignment alignment() const;
|
||||
void setFont(const QFont &font);
|
||||
DynamicElementTextItem::TextFrom textFrom() const;
|
||||
void setTextFrom (DynamicElementTextItem::TextFrom text_from);
|
||||
QString text() const;
|
||||
void setText(const QString &text);
|
||||
void setInfoName(const QString &info_name);
|
||||
QString infoName() const;
|
||||
void setCompositeText(const QString &text);
|
||||
QString compositeText() const;
|
||||
void setColor(const QColor& color);
|
||||
QColor color() const;
|
||||
void setFrame(bool frame);
|
||||
bool frame() const;
|
||||
void setTextWidth(qreal width);
|
||||
void setPlainText(const QString &text);
|
||||
void setAlignment(Qt::Alignment alignment);
|
||||
Qt::Alignment alignment() const;
|
||||
void setFont(const QFont &font);
|
||||
|
||||
protected:
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
protected:
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
|
||||
private:
|
||||
void elementInfoChanged();
|
||||
void prepareAlignment();
|
||||
void finishAlignment();
|
||||
private:
|
||||
void elementInfoChanged();
|
||||
void prepareAlignment();
|
||||
void finishAlignment();
|
||||
|
||||
private:
|
||||
QPointF m_origine_pos,
|
||||
m_saved_point;
|
||||
QString m_text,
|
||||
m_info_name,
|
||||
m_composite_text;
|
||||
DynamicElementTextItem::TextFrom m_text_from = DynamicElementTextItem::UserText;
|
||||
QUuid m_uuid;
|
||||
bool m_frame = false,
|
||||
m_first_add = true,
|
||||
m_block_alignment = false;
|
||||
qreal m_text_width = -1;
|
||||
Qt::Alignment m_alignment = Qt::AlignTop|Qt::AlignLeft;
|
||||
QRectF m_alignment_rect;
|
||||
private:
|
||||
QPointF m_origine_pos,
|
||||
m_saved_point;
|
||||
QString m_text,
|
||||
m_info_name,
|
||||
m_composite_text;
|
||||
DynamicElementTextItem::TextFrom m_text_from = DynamicElementTextItem::UserText;
|
||||
QUuid m_uuid;
|
||||
bool m_frame = false,
|
||||
m_first_add = true,
|
||||
m_block_alignment = false;
|
||||
qreal m_text_width = -1;
|
||||
Qt::Alignment m_alignment = Qt::AlignTop|Qt::AlignLeft;
|
||||
QRectF m_alignment_rect;
|
||||
};
|
||||
|
||||
#endif // PARTDYNAMICTEXTFIELD_H
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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.
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "partellipse.h"
|
||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||
@@ -22,367 +22,367 @@
|
||||
#include "QetGraphicsItemModeler/qetgraphicshandlerutility.h"
|
||||
|
||||
/**
|
||||
@brief PartEllipse::PartEllipse
|
||||
Constructor
|
||||
@param editor : QETElementEditor of this part
|
||||
@param parent : parent item
|
||||
@brief PartEllipse::PartEllipse
|
||||
Constructor
|
||||
@param editor : QETElementEditor of this part
|
||||
@param parent : parent item
|
||||
*/
|
||||
PartEllipse::PartEllipse(QETElementEditor *editor, QGraphicsItem *parent) :
|
||||
AbstractPartEllipse(editor, parent),
|
||||
m_undo_command(nullptr)
|
||||
AbstractPartEllipse(editor, parent),
|
||||
m_undo_command(nullptr)
|
||||
{}
|
||||
|
||||
/**
|
||||
@brief PartEllipse::~PartEllipse
|
||||
Destructor
|
||||
@brief PartEllipse::~PartEllipse
|
||||
Destructor
|
||||
*/
|
||||
PartEllipse::~PartEllipse()
|
||||
{
|
||||
if(m_undo_command) delete m_undo_command;
|
||||
removeHandler();
|
||||
if(m_undo_command) delete m_undo_command;
|
||||
removeHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartEllipse::paint
|
||||
Draw this ellpise
|
||||
@param painter
|
||||
@param options
|
||||
@param widget
|
||||
@brief PartEllipse::paint
|
||||
Draw this ellpise
|
||||
@param painter
|
||||
@param options
|
||||
@param widget
|
||||
*/
|
||||
void PartEllipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(widget);
|
||||
applyStylesToQPainter(*painter);
|
||||
Q_UNUSED(widget);
|
||||
applyStylesToQPainter(*painter);
|
||||
|
||||
QPen t = painter -> pen();
|
||||
QPen t = painter -> pen();
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
||||
t.setCosmetic(options && options -> levelOfDetail < 1.0);
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
||||
t.setCosmetic(options && options -> levelOfDetail < 1.0);
|
||||
#else
|
||||
#if TODO_LIST
|
||||
#pragma message("@TODO remove code for QT 6 or later")
|
||||
#endif
|
||||
t.setCosmetic(options && options -> levelOfDetailFromTransform(painter->worldTransform()) < 1.0);
|
||||
t.setCosmetic(options && options -> levelOfDetailFromTransform(painter->worldTransform()) < 1.0);
|
||||
#endif
|
||||
if (isSelected())
|
||||
t.setColor(Qt::red);
|
||||
if (isSelected())
|
||||
t.setColor(Qt::red);
|
||||
|
||||
painter -> setPen(t);
|
||||
painter -> drawEllipse(rect());
|
||||
painter -> setPen(t);
|
||||
painter -> drawEllipse(rect());
|
||||
|
||||
if (m_hovered)
|
||||
drawShadowShape(painter);
|
||||
if (m_hovered)
|
||||
drawShadowShape(painter);
|
||||
|
||||
if (isSelected())
|
||||
drawCross(m_rect.center(), painter);
|
||||
if (isSelected())
|
||||
drawCross(m_rect.center(), painter);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartEllipse::toXml
|
||||
Export this ellipse in xml
|
||||
@param xml_document : Xml document to use for create the xml element.
|
||||
@return : an xml element that describe this ellipse
|
||||
@brief PartEllipse::toXml
|
||||
Export this ellipse in xml
|
||||
@param xml_document : Xml document to use for create the xml element.
|
||||
@return : an xml element that describe this ellipse
|
||||
*/
|
||||
const QDomElement PartEllipse::toXml(QDomDocument &xml_document) const
|
||||
{
|
||||
QDomElement xml_element;
|
||||
if (qFuzzyCompare(rect().width(), rect().height()))
|
||||
{
|
||||
xml_element = xml_document.createElement("circle");
|
||||
xml_element.setAttribute("diameter", QString("%1").arg(rect().width()));
|
||||
}
|
||||
else
|
||||
{
|
||||
xml_element = xml_document.createElement("ellipse");
|
||||
xml_element.setAttribute("width", QString("%1").arg(rect().width()));
|
||||
xml_element.setAttribute("height", QString("%1").arg(rect().height()));
|
||||
}
|
||||
QDomElement xml_element;
|
||||
if (qFuzzyCompare(rect().width(), rect().height()))
|
||||
{
|
||||
xml_element = xml_document.createElement("circle");
|
||||
xml_element.setAttribute("diameter", QString("%1").arg(rect().width()));
|
||||
}
|
||||
else
|
||||
{
|
||||
xml_element = xml_document.createElement("ellipse");
|
||||
xml_element.setAttribute("width", QString("%1").arg(rect().width()));
|
||||
xml_element.setAttribute("height", QString("%1").arg(rect().height()));
|
||||
}
|
||||
|
||||
QPointF top_left(sceneTopLeft());
|
||||
xml_element.setAttribute("x", QString("%1").arg(top_left.x()));
|
||||
xml_element.setAttribute("y", QString("%1").arg(top_left.y()));
|
||||
QPointF top_left(sceneTopLeft());
|
||||
xml_element.setAttribute("x", QString("%1").arg(top_left.x()));
|
||||
xml_element.setAttribute("y", QString("%1").arg(top_left.y()));
|
||||
|
||||
stylesToXml(xml_element);
|
||||
stylesToXml(xml_element);
|
||||
|
||||
return(xml_element);
|
||||
return(xml_element);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartEllipse::fromXml
|
||||
Import the properties of this ellipse from a xml element.
|
||||
@param qde : Xml document to use.
|
||||
@brief PartEllipse::fromXml
|
||||
Import the properties of this ellipse from a xml element.
|
||||
@param qde : Xml document to use.
|
||||
*/
|
||||
void PartEllipse::fromXml(const QDomElement &qde)
|
||||
{
|
||||
stylesFromXml(qde);
|
||||
qreal width, height;
|
||||
stylesFromXml(qde);
|
||||
qreal width, height;
|
||||
|
||||
if (qde.tagName() == "ellipse")
|
||||
{
|
||||
width = qde.attribute("width", "0").toDouble();
|
||||
height = qde.attribute("height", "0").toDouble();
|
||||
}
|
||||
else
|
||||
width = height = qde.attribute("diameter", "0").toDouble();
|
||||
if (qde.tagName() == "ellipse")
|
||||
{
|
||||
width = qde.attribute("width", "0").toDouble();
|
||||
height = qde.attribute("height", "0").toDouble();
|
||||
}
|
||||
else
|
||||
width = height = qde.attribute("diameter", "0").toDouble();
|
||||
|
||||
m_rect = QRectF(mapFromScene(qde.attribute("x", "0").toDouble(),
|
||||
qde.attribute("y", "0").toDouble()),
|
||||
QSizeF(width, height));
|
||||
m_rect = QRectF(mapFromScene(qde.attribute("x", "0").toDouble(),
|
||||
qde.attribute("y", "0").toDouble()),
|
||||
QSizeF(width, height));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartEllipse::shape
|
||||
@return the shape of this item
|
||||
@brief PartEllipse::shape
|
||||
@return the shape of this item
|
||||
*/
|
||||
QPainterPath PartEllipse::shape() const
|
||||
{
|
||||
QPainterPath shape;
|
||||
shape.addEllipse(m_rect);
|
||||
QPainterPath shape;
|
||||
shape.addEllipse(m_rect);
|
||||
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
||||
shape = pps.createStroke(shape);
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
||||
shape = pps.createStroke(shape);
|
||||
|
||||
return shape;
|
||||
return shape;
|
||||
}
|
||||
|
||||
QPainterPath PartEllipse::shadowShape() const
|
||||
{
|
||||
QPainterPath shape;
|
||||
shape.addEllipse(m_rect);
|
||||
QPainterPath shape;
|
||||
shape.addEllipse(m_rect);
|
||||
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(penWeight());
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(penWeight());
|
||||
|
||||
return (pps.createStroke(shape));
|
||||
return (pps.createStroke(shape));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartEllipse::mouseReleaseEvent
|
||||
Handle mouse release event
|
||||
@param event
|
||||
@brief PartEllipse::mouseReleaseEvent
|
||||
Handle mouse release event
|
||||
@param event
|
||||
*/
|
||||
void PartEllipse::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton && event->buttonDownPos(Qt::LeftButton) == event->pos())
|
||||
switchResizeMode();
|
||||
if (event->button() == Qt::LeftButton && event->buttonDownPos(Qt::LeftButton) == event->pos())
|
||||
switchResizeMode();
|
||||
|
||||
CustomElementGraphicPart::mouseReleaseEvent(event);
|
||||
CustomElementGraphicPart::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartEllipse::itemChange
|
||||
@param change
|
||||
@param value
|
||||
@return
|
||||
@brief PartEllipse::itemChange
|
||||
@param change
|
||||
@param value
|
||||
@return
|
||||
*/
|
||||
QVariant PartEllipse::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
if (change == ItemSelectedHasChanged && scene())
|
||||
{
|
||||
if (value.toBool() == true)
|
||||
{
|
||||
//When item is selected, he must to be up to date whene the selection in the scene change, for display or not the handler,
|
||||
//according to the number of selected items.
|
||||
connect(scene(), &QGraphicsScene::selectionChanged, this, &PartEllipse::sceneSelectionChanged);
|
||||
if (change == ItemSelectedHasChanged && scene())
|
||||
{
|
||||
if (value.toBool() == true)
|
||||
{
|
||||
//When item is selected, he must to be up to date whene the selection in the scene change, for display or not the handler,
|
||||
//according to the number of selected items.
|
||||
connect(scene(), &QGraphicsScene::selectionChanged, this, &PartEllipse::sceneSelectionChanged);
|
||||
|
||||
if (scene()->selectedItems().size() == 1)
|
||||
addHandler();
|
||||
}
|
||||
else
|
||||
{
|
||||
disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartEllipse::sceneSelectionChanged);
|
||||
removeHandler();
|
||||
}
|
||||
}
|
||||
else if (change == ItemPositionHasChanged)
|
||||
{
|
||||
adjusteHandlerPos();
|
||||
}
|
||||
else if (change == ItemSceneChange)
|
||||
{
|
||||
if(scene())
|
||||
disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartEllipse::sceneSelectionChanged);
|
||||
if (scene()->selectedItems().size() == 1)
|
||||
addHandler();
|
||||
}
|
||||
else
|
||||
{
|
||||
disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartEllipse::sceneSelectionChanged);
|
||||
removeHandler();
|
||||
}
|
||||
}
|
||||
else if (change == ItemPositionHasChanged)
|
||||
{
|
||||
adjusteHandlerPos();
|
||||
}
|
||||
else if (change == ItemSceneChange)
|
||||
{
|
||||
if(scene())
|
||||
disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartEllipse::sceneSelectionChanged);
|
||||
|
||||
setSelected(false); //This item is removed from scene, then we deselect this, and so, the handlers is also removed.
|
||||
}
|
||||
setSelected(false); //This item is removed from scene, then we deselect this, and so, the handlers is also removed.
|
||||
}
|
||||
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartEllipse::sceneEventFilter
|
||||
@param watched
|
||||
@param event
|
||||
@return
|
||||
@brief PartEllipse::sceneEventFilter
|
||||
@param watched
|
||||
@param event
|
||||
@return
|
||||
*/
|
||||
bool PartEllipse::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
||||
{
|
||||
//Watched must be an handler
|
||||
if(watched->type() == QetGraphicsHandlerItem::Type)
|
||||
{
|
||||
QetGraphicsHandlerItem *qghi = qgraphicsitem_cast<QetGraphicsHandlerItem *>(watched);
|
||||
//Watched must be an handler
|
||||
if(watched->type() == QetGraphicsHandlerItem::Type)
|
||||
{
|
||||
QetGraphicsHandlerItem *qghi = qgraphicsitem_cast<QetGraphicsHandlerItem *>(watched);
|
||||
|
||||
if(m_handler_vector.contains(qghi)) //Handler must be in m_vector_index, then we can start resize
|
||||
{
|
||||
m_vector_index = m_handler_vector.indexOf(qghi);
|
||||
if (m_vector_index != -1)
|
||||
{
|
||||
if(event->type() == QEvent::GraphicsSceneMousePress) //Click
|
||||
{
|
||||
handlerMousePressEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
else if(event->type() == QEvent::GraphicsSceneMouseMove) //Move
|
||||
{
|
||||
handlerMouseMoveEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
else if (event->type() == QEvent::GraphicsSceneMouseRelease) //Release
|
||||
{
|
||||
handlerMouseReleaseEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(m_handler_vector.contains(qghi)) //Handler must be in m_vector_index, then we can start resize
|
||||
{
|
||||
m_vector_index = m_handler_vector.indexOf(qghi);
|
||||
if (m_vector_index != -1)
|
||||
{
|
||||
if(event->type() == QEvent::GraphicsSceneMousePress) //Click
|
||||
{
|
||||
handlerMousePressEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
else if(event->type() == QEvent::GraphicsSceneMouseMove) //Move
|
||||
{
|
||||
handlerMouseMoveEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
else if (event->type() == QEvent::GraphicsSceneMouseRelease) //Release
|
||||
{
|
||||
handlerMouseReleaseEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void PartEllipse::switchResizeMode()
|
||||
{
|
||||
if (m_resize_mode == 1)
|
||||
{
|
||||
m_resize_mode = 2;
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector)
|
||||
qghi->setColor(Qt::darkGreen);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_resize_mode = 1;
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector)
|
||||
qghi->setColor(Qt::blue);
|
||||
}
|
||||
if (m_resize_mode == 1)
|
||||
{
|
||||
m_resize_mode = 2;
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector)
|
||||
qghi->setColor(Qt::darkGreen);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_resize_mode = 1;
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector)
|
||||
qghi->setColor(Qt::blue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartEllipse::adjusteHandlerPos
|
||||
@brief PartEllipse::adjusteHandlerPos
|
||||
*/
|
||||
void PartEllipse::adjusteHandlerPos()
|
||||
{
|
||||
if (m_handler_vector.isEmpty())
|
||||
return;
|
||||
if (m_handler_vector.isEmpty())
|
||||
return;
|
||||
|
||||
QVector <QPointF> points_vector = QetGraphicsHandlerUtility::pointsForRect(m_rect);
|
||||
QVector <QPointF> points_vector = QetGraphicsHandlerUtility::pointsForRect(m_rect);
|
||||
|
||||
if (m_handler_vector.size() == points_vector.size())
|
||||
{
|
||||
points_vector = mapToScene(points_vector);
|
||||
for (int i = 0 ; i < points_vector.size() ; ++i)
|
||||
m_handler_vector.at(i)->setPos(points_vector.at(i));
|
||||
}
|
||||
if (m_handler_vector.size() == points_vector.size())
|
||||
{
|
||||
points_vector = mapToScene(points_vector);
|
||||
for (int i = 0 ; i < points_vector.size() ; ++i)
|
||||
m_handler_vector.at(i)->setPos(points_vector.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartEllipse::handlerMousePressEvent
|
||||
@param qghi
|
||||
@param event
|
||||
@brief PartEllipse::handlerMousePressEvent
|
||||
@param qghi
|
||||
@param event
|
||||
*/
|
||||
void PartEllipse::handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(qghi);
|
||||
Q_UNUSED(event);
|
||||
Q_UNUSED(qghi);
|
||||
Q_UNUSED(event);
|
||||
|
||||
m_undo_command = new QPropertyUndoCommand(this, "rect", QVariant(m_rect));
|
||||
m_undo_command->setText(tr("Modifier un rectangle"));
|
||||
m_undo_command->enableAnimation();
|
||||
return;
|
||||
m_undo_command = new QPropertyUndoCommand(this, "rect", QVariant(m_rect));
|
||||
m_undo_command->setText(tr("Modifier un rectangle"));
|
||||
m_undo_command->enableAnimation();
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartEllipse::handlerMouseMoveEvent
|
||||
@param qghi
|
||||
@param event
|
||||
@brief PartEllipse::handlerMouseMoveEvent
|
||||
@param qghi
|
||||
@param event
|
||||
*/
|
||||
void PartEllipse::handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(qghi);
|
||||
Q_UNUSED(qghi);
|
||||
|
||||
QPointF new_pos = event->scenePos();
|
||||
if (event->modifiers() != Qt::ControlModifier)
|
||||
new_pos = elementScene()->snapToGrid(event->scenePos());
|
||||
new_pos = mapFromScene(new_pos);
|
||||
QPointF new_pos = event->scenePos();
|
||||
if (event->modifiers() != Qt::ControlModifier)
|
||||
new_pos = elementScene()->snapToGrid(event->scenePos());
|
||||
new_pos = mapFromScene(new_pos);
|
||||
|
||||
if (m_resize_mode == 1)
|
||||
setRect(QetGraphicsHandlerUtility::rectForPosAtIndex(m_rect, new_pos, m_vector_index));
|
||||
else
|
||||
setRect(QetGraphicsHandlerUtility::mirrorRectForPosAtIndex(m_rect, new_pos, m_vector_index));
|
||||
if (m_resize_mode == 1)
|
||||
setRect(QetGraphicsHandlerUtility::rectForPosAtIndex(m_rect, new_pos, m_vector_index));
|
||||
else
|
||||
setRect(QetGraphicsHandlerUtility::mirrorRectForPosAtIndex(m_rect, new_pos, m_vector_index));
|
||||
|
||||
adjusteHandlerPos();
|
||||
adjusteHandlerPos();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartEllipse::handlerMouseReleaseEvent
|
||||
@param qghi
|
||||
@param event
|
||||
@brief PartEllipse::handlerMouseReleaseEvent
|
||||
@param qghi
|
||||
@param event
|
||||
*/
|
||||
void PartEllipse::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(qghi);
|
||||
Q_UNUSED(event);
|
||||
Q_UNUSED(qghi);
|
||||
Q_UNUSED(event);
|
||||
|
||||
m_undo_command->setNewValue(QVariant(m_rect));
|
||||
elementScene()->undoStack().push(m_undo_command);
|
||||
m_undo_command = nullptr;
|
||||
m_vector_index = -1;
|
||||
m_undo_command->setNewValue(QVariant(m_rect));
|
||||
elementScene()->undoStack().push(m_undo_command);
|
||||
m_undo_command = nullptr;
|
||||
m_vector_index = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartEllipse::sceneSelectionChanged
|
||||
When the scene selection change, if there are several primitive selected, we remove the handler of this item
|
||||
@brief PartEllipse::sceneSelectionChanged
|
||||
When the scene selection change, if there are several primitive selected, we remove the handler of this item
|
||||
*/
|
||||
void PartEllipse::sceneSelectionChanged()
|
||||
{
|
||||
if (this->isSelected() && scene()->selectedItems().size() == 1)
|
||||
addHandler();
|
||||
else
|
||||
removeHandler();
|
||||
if (this->isSelected() && scene()->selectedItems().size() == 1)
|
||||
addHandler();
|
||||
else
|
||||
removeHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartEllipse::addHandler
|
||||
Add handlers for this item
|
||||
@brief PartEllipse::addHandler
|
||||
Add handlers for this item
|
||||
*/
|
||||
void PartEllipse::addHandler()
|
||||
{
|
||||
if (m_handler_vector.isEmpty() && scene())
|
||||
{
|
||||
m_handler_vector = QetGraphicsHandlerItem::handlerForPoint(mapToScene(QetGraphicsHandlerUtility::pointsForRect(m_rect)));
|
||||
if (m_handler_vector.isEmpty() && scene())
|
||||
{
|
||||
m_handler_vector = QetGraphicsHandlerItem::handlerForPoint(mapToScene(QetGraphicsHandlerUtility::pointsForRect(m_rect)));
|
||||
|
||||
for(QetGraphicsHandlerItem *handler : m_handler_vector)
|
||||
{
|
||||
QColor color = Qt::blue;
|
||||
if (m_resize_mode == 2)
|
||||
color = Qt::darkGreen;
|
||||
for(QetGraphicsHandlerItem *handler : m_handler_vector)
|
||||
{
|
||||
QColor color = Qt::blue;
|
||||
if (m_resize_mode == 2)
|
||||
color = Qt::darkGreen;
|
||||
|
||||
handler->setColor(color);
|
||||
scene()->addItem(handler);
|
||||
handler->installSceneEventFilter(this);
|
||||
handler->setZValue(this->zValue()+1);
|
||||
}
|
||||
}
|
||||
handler->setColor(color);
|
||||
scene()->addItem(handler);
|
||||
handler->installSceneEventFilter(this);
|
||||
handler->setZValue(this->zValue()+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartEllipse::removeHandler
|
||||
Remove the handlers of this item
|
||||
@brief PartEllipse::removeHandler
|
||||
Remove the handlers of this item
|
||||
*/
|
||||
void PartEllipse::removeHandler()
|
||||
{
|
||||
if (!m_handler_vector.isEmpty())
|
||||
{
|
||||
qDeleteAll(m_handler_vector);
|
||||
m_handler_vector.clear();
|
||||
}
|
||||
if (!m_handler_vector.isEmpty())
|
||||
{
|
||||
qDeleteAll(m_handler_vector);
|
||||
m_handler_vector.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef PART_ELLIPSE_H
|
||||
#define PART_ELLIPSE_H
|
||||
@@ -23,60 +23,60 @@
|
||||
class QPropertyUndoCommand;
|
||||
|
||||
/**
|
||||
@brief The PartEllipse class
|
||||
This class represents an ellipse primitive which may be used to compose the
|
||||
drawing of an electrical element within the element editor.
|
||||
@brief The PartEllipse class
|
||||
This class represents an ellipse primitive which may be used to compose the
|
||||
drawing of an electrical element within the element editor.
|
||||
*/
|
||||
class PartEllipse : public AbstractPartEllipse
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
// constructors, destructor
|
||||
public:
|
||||
PartEllipse(QETElementEditor *editor, QGraphicsItem * parent = nullptr);
|
||||
~PartEllipse() override;
|
||||
|
||||
private:
|
||||
PartEllipse(const PartEllipse &);
|
||||
|
||||
// methods
|
||||
public:
|
||||
enum { Type = UserType + 1103 };
|
||||
/**
|
||||
Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a PartEllipse.
|
||||
@return the QGraphicsItem type
|
||||
*/
|
||||
int type() const override { return Type; }
|
||||
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override;
|
||||
// constructors, destructor
|
||||
public:
|
||||
PartEllipse(QETElementEditor *editor, QGraphicsItem * parent = nullptr);
|
||||
~PartEllipse() override;
|
||||
|
||||
private:
|
||||
PartEllipse(const PartEllipse &);
|
||||
|
||||
// methods
|
||||
public:
|
||||
enum { Type = UserType + 1103 };
|
||||
/**
|
||||
Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a PartEllipse.
|
||||
@return the QGraphicsItem type
|
||||
*/
|
||||
int type() const override { return Type; }
|
||||
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override;
|
||||
|
||||
//Name and XML
|
||||
QString name() const override { return(QObject::tr("ellipse", "element part name")); }
|
||||
QString xmlName() const override { return(QString("ellipse")); }
|
||||
const QDomElement toXml (QDomDocument &) const override;
|
||||
void fromXml (const QDomElement &) override;
|
||||
QPainterPath shape() const override;
|
||||
QPainterPath shadowShape() const override;
|
||||
void setRect(const QRectF &rect) override {AbstractPartEllipse::setRect(rect); adjusteHandlerPos();}
|
||||
//Name and XML
|
||||
QString name() const override { return(QObject::tr("ellipse", "element part name")); }
|
||||
QString xmlName() const override { return(QString("ellipse")); }
|
||||
const QDomElement toXml (QDomDocument &) const override;
|
||||
void fromXml (const QDomElement &) override;
|
||||
QPainterPath shape() const override;
|
||||
QPainterPath shadowShape() const override;
|
||||
void setRect(const QRectF &rect) override {AbstractPartEllipse::setRect(rect); adjusteHandlerPos();}
|
||||
|
||||
protected:
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||
protected:
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||
|
||||
private:
|
||||
void switchResizeMode();
|
||||
void adjusteHandlerPos();
|
||||
void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void sceneSelectionChanged ();
|
||||
|
||||
void addHandler();
|
||||
void removeHandler();
|
||||
private:
|
||||
void switchResizeMode();
|
||||
void adjusteHandlerPos();
|
||||
void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void sceneSelectionChanged ();
|
||||
|
||||
void addHandler();
|
||||
void removeHandler();
|
||||
|
||||
private:
|
||||
QPropertyUndoCommand *m_undo_command;
|
||||
int m_resize_mode = 1,
|
||||
m_vector_index = -1;
|
||||
private:
|
||||
QPropertyUndoCommand *m_undo_command;
|
||||
int m_resize_mode = 1,
|
||||
m_vector_index = -1;
|
||||
};
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef PART_LINE_H
|
||||
#define PART_LINE_H
|
||||
@@ -25,104 +25,104 @@ class QPropertyUndoCommand;
|
||||
class QetGraphicsHandlerItem;
|
||||
|
||||
/**
|
||||
This class represents a line primitive which may be used to compose the
|
||||
drawing of an electrical element within the element editor. Lines may have
|
||||
specific visual ends (e.g. arrows) through the setFirstEndType and
|
||||
setSecondEndType methods. Their size can be defined using the
|
||||
setFirstEndLength and setSecondEndLength methods. Please note ends are not
|
||||
drawn if the required length for their drawing is longer than the line itself.
|
||||
In case there is room for a single end only, the first one get priority.
|
||||
This class represents a line primitive which may be used to compose the
|
||||
drawing of an electrical element within the element editor. Lines may have
|
||||
specific visual ends (e.g. arrows) through the setFirstEndType and
|
||||
setSecondEndType methods. Their size can be defined using the
|
||||
setFirstEndLength and setSecondEndLength methods. Please note ends are not
|
||||
drawn if the required length for their drawing is longer than the line itself.
|
||||
In case there is room for a single end only, the first one get priority.
|
||||
*/
|
||||
class PartLine : public CustomElementGraphicPart
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(Qet::EndType end1 READ firstEndType WRITE setFirstEndType)
|
||||
Q_PROPERTY(Qet::EndType end2 READ secondEndType WRITE setSecondEndType)
|
||||
Q_PROPERTY(qreal length1 READ firstEndLength WRITE setFirstEndLength)
|
||||
Q_PROPERTY(qreal length2 READ secondEndLength WRITE setSecondEndLength)
|
||||
Q_PROPERTY(QLineF line READ line WRITE setLine)
|
||||
Q_PROPERTY(Qet::EndType end1 READ firstEndType WRITE setFirstEndType)
|
||||
Q_PROPERTY(Qet::EndType end2 READ secondEndType WRITE setSecondEndType)
|
||||
Q_PROPERTY(qreal length1 READ firstEndLength WRITE setFirstEndLength)
|
||||
Q_PROPERTY(qreal length2 READ secondEndLength WRITE setSecondEndLength)
|
||||
Q_PROPERTY(QLineF line READ line WRITE setLine)
|
||||
|
||||
// constructors, destructor
|
||||
public:
|
||||
PartLine(QETElementEditor *, QGraphicsItem * = nullptr);
|
||||
~PartLine() override;
|
||||
private:
|
||||
PartLine(const PartLine &);
|
||||
// constructors, destructor
|
||||
public:
|
||||
PartLine(QETElementEditor *, QGraphicsItem * = nullptr);
|
||||
~PartLine() override;
|
||||
private:
|
||||
PartLine(const PartLine &);
|
||||
|
||||
signals:
|
||||
void lineChanged();
|
||||
void firstEndTypeChanged();
|
||||
void secondEndTypeChanged();
|
||||
void firstEndLengthChanged();
|
||||
void secondEndLengthChanged();
|
||||
signals:
|
||||
void lineChanged();
|
||||
void firstEndTypeChanged();
|
||||
void secondEndTypeChanged();
|
||||
void firstEndLengthChanged();
|
||||
void secondEndLengthChanged();
|
||||
|
||||
|
||||
// methods
|
||||
public:
|
||||
enum { Type = UserType + 1104 };
|
||||
|
||||
/**
|
||||
Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a PartLine.
|
||||
@return the QGraphicsItem type
|
||||
*/
|
||||
int type() const override { return Type; }
|
||||
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override;
|
||||
QString name() const override { return(QObject::tr("ligne", "element part name")); }
|
||||
QString xmlName() const override { return(QString("line")); }
|
||||
const QDomElement toXml(QDomDocument &) const override;
|
||||
void fromXml(const QDomElement &) override;
|
||||
virtual QPointF sceneP1() const;
|
||||
virtual QPointF sceneP2() const;
|
||||
QPainterPath shape() const override;
|
||||
QPainterPath shadowShape() const override;
|
||||
QRectF boundingRect() const override;
|
||||
bool isUseless() const override;
|
||||
QRectF sceneGeometricRect() const override;
|
||||
void startUserTransformation(const QRectF &) override;
|
||||
void handleUserTransformation(const QRectF &, const QRectF &) override;
|
||||
static uint requiredLengthForEndType(const Qet::EndType &);
|
||||
static QList<QPointF> fourEndPoints(const QPointF &, const QPointF &, const qreal &);
|
||||
|
||||
// methods
|
||||
public:
|
||||
enum { Type = UserType + 1104 };
|
||||
|
||||
/**
|
||||
Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a PartLine.
|
||||
@return the QGraphicsItem type
|
||||
*/
|
||||
int type() const override { return Type; }
|
||||
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override;
|
||||
QString name() const override { return(QObject::tr("ligne", "element part name")); }
|
||||
QString xmlName() const override { return(QString("line")); }
|
||||
const QDomElement toXml(QDomDocument &) const override;
|
||||
void fromXml(const QDomElement &) override;
|
||||
virtual QPointF sceneP1() const;
|
||||
virtual QPointF sceneP2() const;
|
||||
QPainterPath shape() const override;
|
||||
QPainterPath shadowShape() const override;
|
||||
QRectF boundingRect() const override;
|
||||
bool isUseless() const override;
|
||||
QRectF sceneGeometricRect() const override;
|
||||
void startUserTransformation(const QRectF &) override;
|
||||
void handleUserTransformation(const QRectF &, const QRectF &) override;
|
||||
static uint requiredLengthForEndType(const Qet::EndType &);
|
||||
static QList<QPointF> fourEndPoints(const QPointF &, const QPointF &, const qreal &);
|
||||
|
||||
QLineF line() const;
|
||||
void setLine(const QLineF &line);
|
||||
Qet::EndType firstEndType() const {return first_end;}
|
||||
void setFirstEndType(const Qet::EndType &et);
|
||||
Qet::EndType secondEndType() const {return second_end;}
|
||||
void setSecondEndType(const Qet::EndType &et);
|
||||
qreal firstEndLength() const {return first_length;}
|
||||
void setFirstEndLength(const qreal &l);
|
||||
qreal secondEndLength() const {return second_length;}
|
||||
void setSecondEndLength(const qreal &l);
|
||||
QLineF line() const;
|
||||
void setLine(const QLineF &line);
|
||||
Qet::EndType firstEndType() const {return first_end;}
|
||||
void setFirstEndType(const Qet::EndType &et);
|
||||
Qet::EndType secondEndType() const {return second_end;}
|
||||
void setSecondEndType(const Qet::EndType &et);
|
||||
qreal firstEndLength() const {return first_length;}
|
||||
void setFirstEndLength(const qreal &l);
|
||||
qreal secondEndLength() const {return second_length;}
|
||||
void setSecondEndLength(const qreal &l);
|
||||
|
||||
protected:
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||
|
||||
private:
|
||||
void adjusteHandlerPos();
|
||||
void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void sceneSelectionChanged ();
|
||||
|
||||
void addHandler();
|
||||
void removeHandler();
|
||||
|
||||
QPainterPath path() const;
|
||||
QRectF firstEndCircleRect() const;
|
||||
QRectF secondEndCircleRect() const;
|
||||
protected:
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||
|
||||
private:
|
||||
void adjusteHandlerPos();
|
||||
void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void sceneSelectionChanged ();
|
||||
|
||||
void addHandler();
|
||||
void removeHandler();
|
||||
|
||||
QPainterPath path() const;
|
||||
QRectF firstEndCircleRect() const;
|
||||
QRectF secondEndCircleRect() const;
|
||||
|
||||
/*****************/
|
||||
Qet::EndType first_end;
|
||||
qreal first_length;
|
||||
/*****************/
|
||||
Qet::EndType first_end;
|
||||
qreal first_length;
|
||||
|
||||
Qet::EndType second_end;
|
||||
qreal second_length;
|
||||
QList<QPointF> saved_points_;
|
||||
QLineF m_line;
|
||||
int m_vector_index = -1;
|
||||
QPropertyUndoCommand *m_undo_command;
|
||||
QVector<QetGraphicsHandlerItem *> m_handler_vector;
|
||||
Qet::EndType second_end;
|
||||
qreal second_length;
|
||||
QList<QPointF> saved_points_;
|
||||
QLineF m_line;
|
||||
int m_vector_index = -1;
|
||||
QPropertyUndoCommand *m_undo_command;
|
||||
QVector<QetGraphicsHandlerItem *> m_handler_vector;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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.
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "partpolygon.h"
|
||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||
@@ -25,593 +25,593 @@
|
||||
|
||||
|
||||
/**
|
||||
@brief PartPolygon::PartPolygon
|
||||
Constructor
|
||||
@param editor : editor of this item
|
||||
@param parent : parent item
|
||||
@brief PartPolygon::PartPolygon
|
||||
Constructor
|
||||
@param editor : editor of this item
|
||||
@param parent : parent item
|
||||
*/
|
||||
PartPolygon::PartPolygon(QETElementEditor *editor, QGraphicsItem *parent) :
|
||||
CustomElementGraphicPart(editor, parent),
|
||||
m_closed(false),
|
||||
m_undo_command(nullptr)
|
||||
CustomElementGraphicPart(editor, parent),
|
||||
m_closed(false),
|
||||
m_undo_command(nullptr)
|
||||
{
|
||||
m_insert_point = new QAction(tr("Ajouter un point"), this);
|
||||
m_insert_point->setIcon(QET::Icons::Add);
|
||||
connect(m_insert_point, &QAction::triggered, this, &PartPolygon::insertPoint);
|
||||
m_remove_point = new QAction(tr("Supprimer ce point"), this);
|
||||
m_remove_point->setIcon(QET::Icons::Remove);
|
||||
connect(m_remove_point, &QAction::triggered, this, &PartPolygon::removePoint);
|
||||
m_insert_point = new QAction(tr("Ajouter un point"), this);
|
||||
m_insert_point->setIcon(QET::Icons::Add);
|
||||
connect(m_insert_point, &QAction::triggered, this, &PartPolygon::insertPoint);
|
||||
m_remove_point = new QAction(tr("Supprimer ce point"), this);
|
||||
m_remove_point->setIcon(QET::Icons::Remove);
|
||||
connect(m_remove_point, &QAction::triggered, this, &PartPolygon::removePoint);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::~PartPolygon
|
||||
@brief PartPolygon::~PartPolygon
|
||||
*/
|
||||
PartPolygon::~PartPolygon()
|
||||
{
|
||||
if(m_undo_command) delete m_undo_command;
|
||||
removeHandler();
|
||||
if(m_undo_command) delete m_undo_command;
|
||||
removeHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::paint
|
||||
Draw this polygon
|
||||
@param painter
|
||||
@param options
|
||||
@param widget
|
||||
@brief PartPolygon::paint
|
||||
Draw this polygon
|
||||
@param painter
|
||||
@param options
|
||||
@param widget
|
||||
*/
|
||||
void PartPolygon::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(widget);
|
||||
Q_UNUSED(widget);
|
||||
|
||||
applyStylesToQPainter(*painter);
|
||||
applyStylesToQPainter(*painter);
|
||||
|
||||
QPen t = painter -> pen();
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
||||
t.setCosmetic(options && options -> levelOfDetail < 1.0);
|
||||
QPen t = painter -> pen();
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
||||
t.setCosmetic(options && options -> levelOfDetail < 1.0);
|
||||
#else
|
||||
#if TODO_LIST
|
||||
#pragma message("@TODO remove code for QT 6 or later")
|
||||
#endif
|
||||
t.setCosmetic(options && options -> levelOfDetailFromTransform(painter->worldTransform()) < 1.0);
|
||||
t.setCosmetic(options && options -> levelOfDetailFromTransform(painter->worldTransform()) < 1.0);
|
||||
#endif
|
||||
if (isSelected()) t.setColor(Qt::red);
|
||||
painter -> setPen(t);
|
||||
if (isSelected()) t.setColor(Qt::red);
|
||||
painter -> setPen(t);
|
||||
|
||||
m_closed ? painter -> drawPolygon (m_polygon) :
|
||||
painter -> drawPolyline(m_polygon);
|
||||
m_closed ? painter -> drawPolygon (m_polygon) :
|
||||
painter -> drawPolyline(m_polygon);
|
||||
|
||||
if (m_hovered)
|
||||
drawShadowShape(painter);
|
||||
if (m_hovered)
|
||||
drawShadowShape(painter);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::fromXml
|
||||
Import the properties of this polygon from a xml element
|
||||
@param qde : Xml document to use
|
||||
@brief PartPolygon::fromXml
|
||||
Import the properties of this polygon from a xml element
|
||||
@param qde : Xml document to use
|
||||
*/
|
||||
void PartPolygon::fromXml(const QDomElement &qde)
|
||||
{
|
||||
stylesFromXml(qde);
|
||||
stylesFromXml(qde);
|
||||
|
||||
int i = 1;
|
||||
while(true)
|
||||
{
|
||||
if (QET::attributeIsAReal(qde, QString("x%1").arg(i)) &&\
|
||||
QET::attributeIsAReal(qde, QString("y%1").arg(i)))
|
||||
++ i;
|
||||
int i = 1;
|
||||
while(true)
|
||||
{
|
||||
if (QET::attributeIsAReal(qde, QString("x%1").arg(i)) &&\
|
||||
QET::attributeIsAReal(qde, QString("y%1").arg(i)))
|
||||
++ i;
|
||||
|
||||
else break;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
||||
QPolygonF temp_polygon;
|
||||
for (int j = 1 ; j < i ; ++ j)
|
||||
{
|
||||
temp_polygon << QPointF(qde.attribute(QString("x%1").arg(j)).toDouble(),
|
||||
qde.attribute(QString("y%1").arg(j)).toDouble());
|
||||
}
|
||||
m_polygon = temp_polygon;
|
||||
QPolygonF temp_polygon;
|
||||
for (int j = 1 ; j < i ; ++ j)
|
||||
{
|
||||
temp_polygon << QPointF(qde.attribute(QString("x%1").arg(j)).toDouble(),
|
||||
qde.attribute(QString("y%1").arg(j)).toDouble());
|
||||
}
|
||||
m_polygon = temp_polygon;
|
||||
|
||||
m_closed = qde.attribute("closed") != "false";
|
||||
m_closed = qde.attribute("closed") != "false";
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::toXml
|
||||
Export this polygin in xml
|
||||
@param xml_document : Xml document to use for create the xml element
|
||||
@return an xml element that describe this polygon
|
||||
@brief PartPolygon::toXml
|
||||
Export this polygin in xml
|
||||
@param xml_document : Xml document to use for create the xml element
|
||||
@return an xml element that describe this polygon
|
||||
*/
|
||||
const QDomElement PartPolygon::toXml(QDomDocument &xml_document) const
|
||||
{
|
||||
QDomElement xml_element = xml_document.createElement("polygon");
|
||||
int i = 1;
|
||||
foreach(QPointF point, m_polygon) {
|
||||
point = mapToScene(point);
|
||||
xml_element.setAttribute(QString("x%1").arg(i), QString("%1").arg(point.x()));
|
||||
xml_element.setAttribute(QString("y%1").arg(i), QString("%1").arg(point.y()));
|
||||
++ i;
|
||||
}
|
||||
if (!m_closed) xml_element.setAttribute("closed", "false");
|
||||
stylesToXml(xml_element);
|
||||
return(xml_element);
|
||||
QDomElement xml_element = xml_document.createElement("polygon");
|
||||
int i = 1;
|
||||
foreach(QPointF point, m_polygon) {
|
||||
point = mapToScene(point);
|
||||
xml_element.setAttribute(QString("x%1").arg(i), QString("%1").arg(point.x()));
|
||||
xml_element.setAttribute(QString("y%1").arg(i), QString("%1").arg(point.y()));
|
||||
++ i;
|
||||
}
|
||||
if (!m_closed) xml_element.setAttribute("closed", "false");
|
||||
stylesToXml(xml_element);
|
||||
return(xml_element);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::isUseless
|
||||
@return true if this part is irrelevant and does not deserve to be Retained / registered.
|
||||
A polygon is relevant when he have 2 differents points
|
||||
@brief PartPolygon::isUseless
|
||||
@return true if this part is irrelevant and does not deserve to be Retained / registered.
|
||||
A polygon is relevant when he have 2 differents points
|
||||
*/
|
||||
bool PartPolygon::isUseless() const
|
||||
{
|
||||
if (m_polygon.count() < 2) return(true);
|
||||
if (m_polygon.count() < 2) return(true);
|
||||
|
||||
for (int i = 1 ; i < m_polygon.count() ; ++ i)
|
||||
if (m_polygon[i] != m_polygon[i-1]) return(false);
|
||||
for (int i = 1 ; i < m_polygon.count() ; ++ i)
|
||||
if (m_polygon[i] != m_polygon[i-1]) return(false);
|
||||
|
||||
return(true);
|
||||
return(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::sceneGeometricRect
|
||||
@return the minimum, margin-less rectangle this part can fit into, in scene
|
||||
coordinates. It is different from boundingRect() because it is not supposed
|
||||
to imply any margin, and it is different from shape because it is a regular
|
||||
rectangle, not a complex shape.
|
||||
@brief PartPolygon::sceneGeometricRect
|
||||
@return the minimum, margin-less rectangle this part can fit into, in scene
|
||||
coordinates. It is different from boundingRect() because it is not supposed
|
||||
to imply any margin, and it is different from shape because it is a regular
|
||||
rectangle, not a complex shape.
|
||||
*/
|
||||
QRectF PartPolygon::sceneGeometricRect() const
|
||||
{
|
||||
return(mapToScene(m_polygon.boundingRect()).boundingRect());
|
||||
return(mapToScene(m_polygon.boundingRect()).boundingRect());
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::startUserTransformation
|
||||
Start the user-induced transformation, provided this primitive is contained
|
||||
within the initial_selection_rect bounding rectangle.
|
||||
@param initial_selection_rect
|
||||
@brief PartPolygon::startUserTransformation
|
||||
Start the user-induced transformation, provided this primitive is contained
|
||||
within the initial_selection_rect bounding rectangle.
|
||||
@param initial_selection_rect
|
||||
*/
|
||||
void PartPolygon::startUserTransformation(const QRectF &initial_selection_rect)
|
||||
{
|
||||
Q_UNUSED(initial_selection_rect)
|
||||
saved_points_ = mapToScene(m_polygon).toList();
|
||||
Q_UNUSED(initial_selection_rect)
|
||||
saved_points_ = mapToScene(m_polygon).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::handleUserTransformation
|
||||
Handle the user-induced transformation from initial_selection_rect to new_selection_rect
|
||||
@param initial_selection_rect
|
||||
@param new_selection_rect
|
||||
@brief PartPolygon::handleUserTransformation
|
||||
Handle the user-induced transformation from initial_selection_rect to new_selection_rect
|
||||
@param initial_selection_rect
|
||||
@param new_selection_rect
|
||||
*/
|
||||
void PartPolygon::handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect)
|
||||
{
|
||||
QList<QPointF> mapped_points = mapPoints(initial_selection_rect, new_selection_rect, saved_points_);
|
||||
m_polygon = (mapFromScene(QPolygonF(mapped_points.toVector())));
|
||||
QList<QPointF> mapped_points = mapPoints(initial_selection_rect, new_selection_rect, saved_points_);
|
||||
m_polygon = (mapFromScene(QPolygonF(mapped_points.toVector())));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::preferredScalingMethod
|
||||
This method is called by the decorator when it needs to determine the best
|
||||
way to interactively scale a primitive. It is typically called when only a
|
||||
single primitive is being scaled.
|
||||
@return : This reimplementation systematically returns QET::RoundScaleRatios.
|
||||
@brief PartPolygon::preferredScalingMethod
|
||||
This method is called by the decorator when it needs to determine the best
|
||||
way to interactively scale a primitive. It is typically called when only a
|
||||
single primitive is being scaled.
|
||||
@return : This reimplementation systematically returns QET::RoundScaleRatios.
|
||||
*/
|
||||
QET::ScalingMethod PartPolygon::preferredScalingMethod() const
|
||||
{
|
||||
return(QET::RoundScaleRatios);
|
||||
return(QET::RoundScaleRatios);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::polygon
|
||||
@return the item's polygon, or an empty polygon if no polygon has been set.
|
||||
@brief PartPolygon::polygon
|
||||
@return the item's polygon, or an empty polygon if no polygon has been set.
|
||||
*/
|
||||
QPolygonF PartPolygon::polygon() const
|
||||
{
|
||||
return m_polygon;
|
||||
return m_polygon;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::setPolygon
|
||||
Sets the item's polygon to be the given polygon.
|
||||
@param polygon
|
||||
@brief PartPolygon::setPolygon
|
||||
Sets the item's polygon to be the given polygon.
|
||||
@param polygon
|
||||
*/
|
||||
void PartPolygon::setPolygon(const QPolygonF &polygon)
|
||||
{
|
||||
if (m_polygon == polygon) return;
|
||||
prepareGeometryChange();
|
||||
m_polygon = polygon;
|
||||
adjusteHandlerPos();
|
||||
emit polygonChanged();
|
||||
if (m_polygon == polygon) return;
|
||||
prepareGeometryChange();
|
||||
m_polygon = polygon;
|
||||
adjusteHandlerPos();
|
||||
emit polygonChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::addPoint
|
||||
Add new point to polygon
|
||||
@param point
|
||||
@brief PartPolygon::addPoint
|
||||
Add new point to polygon
|
||||
@param point
|
||||
*/
|
||||
void PartPolygon::addPoint(const QPointF &point)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
m_polygon << point;
|
||||
prepareGeometryChange();
|
||||
m_polygon << point;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::setLastPoint
|
||||
Set the last point of polygon to point
|
||||
@param point
|
||||
@brief PartPolygon::setLastPoint
|
||||
Set the last point of polygon to point
|
||||
@param point
|
||||
*/
|
||||
void PartPolygon::setLastPoint(const QPointF &point)
|
||||
{
|
||||
if (m_polygon.size())
|
||||
m_polygon.pop_back();
|
||||
if (m_polygon.size())
|
||||
m_polygon.pop_back();
|
||||
|
||||
prepareGeometryChange();
|
||||
m_polygon << point;
|
||||
prepareGeometryChange();
|
||||
m_polygon << point;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::removeLastPoint
|
||||
Remove the last point of polygon
|
||||
@brief PartPolygon::removeLastPoint
|
||||
Remove the last point of polygon
|
||||
*/
|
||||
void PartPolygon::removeLastPoint()
|
||||
{
|
||||
if (m_polygon.size())
|
||||
{
|
||||
prepareGeometryChange();
|
||||
m_polygon.pop_back();
|
||||
}
|
||||
if (m_polygon.size())
|
||||
{
|
||||
prepareGeometryChange();
|
||||
m_polygon.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void PartPolygon::setClosed(bool close)
|
||||
{
|
||||
if (m_closed == close) return;
|
||||
prepareGeometryChange();
|
||||
m_closed = close;
|
||||
emit closedChange();
|
||||
if (m_closed == close) return;
|
||||
prepareGeometryChange();
|
||||
m_closed = close;
|
||||
emit closedChange();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::setHandlerColor
|
||||
Set the handler at pos pos (in polygon coordinate) to color color.
|
||||
@param pos
|
||||
@param color
|
||||
@brief PartPolygon::setHandlerColor
|
||||
Set the handler at pos pos (in polygon coordinate) to color color.
|
||||
@param pos
|
||||
@param color
|
||||
*/
|
||||
void PartPolygon::setHandlerColor(QPointF pos, const QColor &color)
|
||||
{
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector) {
|
||||
if (qghi->pos() == mapToScene(pos)) {
|
||||
qghi->setColor(color);
|
||||
}
|
||||
}
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector) {
|
||||
if (qghi->pos() == mapToScene(pos)) {
|
||||
qghi->setColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::resetAllHandlerColor
|
||||
Reset the color of every handlers
|
||||
@brief PartPolygon::resetAllHandlerColor
|
||||
Reset the color of every handlers
|
||||
*/
|
||||
void PartPolygon::resetAllHandlerColor()
|
||||
{
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector) {
|
||||
qghi->setColor(Qt::blue);
|
||||
}
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector) {
|
||||
qghi->setColor(Qt::blue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::itemChange
|
||||
@param change
|
||||
@param value
|
||||
@return
|
||||
@brief PartPolygon::itemChange
|
||||
@param change
|
||||
@param value
|
||||
@return
|
||||
*/
|
||||
QVariant PartPolygon::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
if (change == ItemSelectedHasChanged && scene())
|
||||
{
|
||||
if (value.toBool() == true)
|
||||
{
|
||||
//When item is selected, he must to be up to date whene the selection in the scene change, for display or not the handler,
|
||||
//according to the number of selected items.
|
||||
connect(scene(), &QGraphicsScene::selectionChanged, this, &PartPolygon::sceneSelectionChanged);
|
||||
if (change == ItemSelectedHasChanged && scene())
|
||||
{
|
||||
if (value.toBool() == true)
|
||||
{
|
||||
//When item is selected, he must to be up to date whene the selection in the scene change, for display or not the handler,
|
||||
//according to the number of selected items.
|
||||
connect(scene(), &QGraphicsScene::selectionChanged, this, &PartPolygon::sceneSelectionChanged);
|
||||
|
||||
if (scene()->selectedItems().size() == 1)
|
||||
addHandler();
|
||||
}
|
||||
else
|
||||
{
|
||||
disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartPolygon::sceneSelectionChanged);
|
||||
removeHandler();
|
||||
}
|
||||
}
|
||||
else if (change == ItemPositionHasChanged)
|
||||
{
|
||||
adjusteHandlerPos();
|
||||
}
|
||||
else if (change == ItemSceneChange)
|
||||
{
|
||||
if(scene())
|
||||
disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartPolygon::sceneSelectionChanged);
|
||||
if (scene()->selectedItems().size() == 1)
|
||||
addHandler();
|
||||
}
|
||||
else
|
||||
{
|
||||
disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartPolygon::sceneSelectionChanged);
|
||||
removeHandler();
|
||||
}
|
||||
}
|
||||
else if (change == ItemPositionHasChanged)
|
||||
{
|
||||
adjusteHandlerPos();
|
||||
}
|
||||
else if (change == ItemSceneChange)
|
||||
{
|
||||
if(scene())
|
||||
disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartPolygon::sceneSelectionChanged);
|
||||
|
||||
setSelected(false); //This is item removed from scene, then we deselect this, and so, the handlers is also removed.
|
||||
}
|
||||
setSelected(false); //This is item removed from scene, then we deselect this, and so, the handlers is also removed.
|
||||
}
|
||||
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::sceneEventFilter
|
||||
@param watched
|
||||
@param event
|
||||
@return
|
||||
@brief PartPolygon::sceneEventFilter
|
||||
@param watched
|
||||
@param event
|
||||
@return
|
||||
*/
|
||||
bool PartPolygon::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
||||
{
|
||||
//Watched must be an handler
|
||||
if(watched->type() == QetGraphicsHandlerItem::Type)
|
||||
{
|
||||
QetGraphicsHandlerItem *qghi = qgraphicsitem_cast<QetGraphicsHandlerItem *>(watched);
|
||||
//Watched must be an handler
|
||||
if(watched->type() == QetGraphicsHandlerItem::Type)
|
||||
{
|
||||
QetGraphicsHandlerItem *qghi = qgraphicsitem_cast<QetGraphicsHandlerItem *>(watched);
|
||||
|
||||
if(m_handler_vector.contains(qghi)) //Handler must be in m_vector_index, then we can start resize
|
||||
{
|
||||
m_vector_index = m_handler_vector.indexOf(qghi);
|
||||
if (m_vector_index != -1)
|
||||
{
|
||||
if(event->type() == QEvent::GraphicsSceneMousePress) //Click
|
||||
{
|
||||
handlerMousePressEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
else if(event->type() == QEvent::GraphicsSceneMouseMove) //Move
|
||||
{
|
||||
handlerMouseMoveEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
else if (event->type() == QEvent::GraphicsSceneMouseRelease) //Release
|
||||
{
|
||||
handlerMouseReleaseEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(m_handler_vector.contains(qghi)) //Handler must be in m_vector_index, then we can start resize
|
||||
{
|
||||
m_vector_index = m_handler_vector.indexOf(qghi);
|
||||
if (m_vector_index != -1)
|
||||
{
|
||||
if(event->type() == QEvent::GraphicsSceneMousePress) //Click
|
||||
{
|
||||
handlerMousePressEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
else if(event->type() == QEvent::GraphicsSceneMouseMove) //Move
|
||||
{
|
||||
handlerMouseMoveEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
else if (event->type() == QEvent::GraphicsSceneMouseRelease) //Release
|
||||
{
|
||||
handlerMouseReleaseEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void PartPolygon::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
||||
{
|
||||
m_context_menu_pos = event->pos();
|
||||
event->ignore();
|
||||
if (isSelected() && elementScene() && (elementScene()->behavior() == ElementScene::Normal))
|
||||
{
|
||||
QList<QAction *> list;
|
||||
list << m_insert_point;
|
||||
if (m_handler_vector.count() > 2)
|
||||
{
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector)
|
||||
{
|
||||
if (qghi->contains(qghi->mapFromScene(event->scenePos())))
|
||||
{
|
||||
list << m_remove_point;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
elementScene()->editor()->contextMenu(event->screenPos(), list);
|
||||
event->accept();
|
||||
}
|
||||
m_context_menu_pos = event->pos();
|
||||
event->ignore();
|
||||
if (isSelected() && elementScene() && (elementScene()->behavior() == ElementScene::Normal))
|
||||
{
|
||||
QList<QAction *> list;
|
||||
list << m_insert_point;
|
||||
if (m_handler_vector.count() > 2)
|
||||
{
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector)
|
||||
{
|
||||
if (qghi->contains(qghi->mapFromScene(event->scenePos())))
|
||||
{
|
||||
list << m_remove_point;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
elementScene()->editor()->contextMenu(event->screenPos(), list);
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::adjusteHandlerPos
|
||||
@brief PartPolygon::adjusteHandlerPos
|
||||
*/
|
||||
void PartPolygon::adjusteHandlerPos()
|
||||
{
|
||||
if(m_handler_vector.isEmpty())
|
||||
return;
|
||||
if(m_handler_vector.isEmpty())
|
||||
return;
|
||||
|
||||
if (m_handler_vector.size() == m_polygon.size())
|
||||
{
|
||||
QVector <QPointF> points_vector = mapToScene(m_polygon);
|
||||
for (int i = 0 ; i < points_vector.size() ; ++i)
|
||||
m_handler_vector.at(i)->setPos(points_vector.at(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
qDeleteAll(m_handler_vector);
|
||||
m_handler_vector.clear();
|
||||
addHandler();
|
||||
}
|
||||
if (m_handler_vector.size() == m_polygon.size())
|
||||
{
|
||||
QVector <QPointF> points_vector = mapToScene(m_polygon);
|
||||
for (int i = 0 ; i < points_vector.size() ; ++i)
|
||||
m_handler_vector.at(i)->setPos(points_vector.at(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
qDeleteAll(m_handler_vector);
|
||||
m_handler_vector.clear();
|
||||
addHandler();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::handlerMousePressEvent
|
||||
@param qghi
|
||||
@param event
|
||||
@brief PartPolygon::handlerMousePressEvent
|
||||
@param qghi
|
||||
@param event
|
||||
*/
|
||||
void PartPolygon::handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(qghi);
|
||||
Q_UNUSED(event);
|
||||
Q_UNUSED(qghi);
|
||||
Q_UNUSED(event);
|
||||
|
||||
m_undo_command = new QPropertyUndoCommand(this, "polygon", QVariant(m_polygon));
|
||||
m_undo_command->setText(tr("Modifier un polygone"));
|
||||
m_undo_command = new QPropertyUndoCommand(this, "polygon", QVariant(m_polygon));
|
||||
m_undo_command->setText(tr("Modifier un polygone"));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::handlerMouseMoveEvent
|
||||
@param qghi
|
||||
@param event
|
||||
@brief PartPolygon::handlerMouseMoveEvent
|
||||
@param qghi
|
||||
@param event
|
||||
*/
|
||||
void PartPolygon::handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(qghi);
|
||||
Q_UNUSED(qghi);
|
||||
|
||||
QPointF new_pos = event->scenePos();
|
||||
if (event->modifiers() != Qt::ControlModifier)
|
||||
new_pos = elementScene()->snapToGrid(event->scenePos());
|
||||
new_pos = mapFromScene(new_pos);
|
||||
QPointF new_pos = event->scenePos();
|
||||
if (event->modifiers() != Qt::ControlModifier)
|
||||
new_pos = elementScene()->snapToGrid(event->scenePos());
|
||||
new_pos = mapFromScene(new_pos);
|
||||
|
||||
prepareGeometryChange();
|
||||
m_polygon.replace(m_vector_index, new_pos);
|
||||
adjusteHandlerPos();
|
||||
emit polygonChanged();
|
||||
prepareGeometryChange();
|
||||
m_polygon.replace(m_vector_index, new_pos);
|
||||
adjusteHandlerPos();
|
||||
emit polygonChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::handlerMouseReleaseEvent
|
||||
@param qghi
|
||||
@param event
|
||||
@brief PartPolygon::handlerMouseReleaseEvent
|
||||
@param qghi
|
||||
@param event
|
||||
*/
|
||||
void PartPolygon::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(qghi);
|
||||
Q_UNUSED(event);
|
||||
Q_UNUSED(qghi);
|
||||
Q_UNUSED(event);
|
||||
|
||||
m_undo_command->setNewValue(QVariant(m_polygon));
|
||||
elementScene()->undoStack().push(m_undo_command);
|
||||
m_undo_command = nullptr;
|
||||
m_vector_index = -1;
|
||||
m_undo_command->setNewValue(QVariant(m_polygon));
|
||||
elementScene()->undoStack().push(m_undo_command);
|
||||
m_undo_command = nullptr;
|
||||
m_vector_index = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::sceneSelectionChanged
|
||||
When the scene selection change, if there are several primitive selected, we remove the handler of this item
|
||||
@brief PartPolygon::sceneSelectionChanged
|
||||
When the scene selection change, if there are several primitive selected, we remove the handler of this item
|
||||
*/
|
||||
void PartPolygon::sceneSelectionChanged()
|
||||
{
|
||||
if (this->isSelected() && scene()->selectedItems().size() == 1)
|
||||
addHandler();
|
||||
else
|
||||
removeHandler();
|
||||
if (this->isSelected() && scene()->selectedItems().size() == 1)
|
||||
addHandler();
|
||||
else
|
||||
removeHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::addHandler
|
||||
Add handlers for this item
|
||||
@brief PartPolygon::addHandler
|
||||
Add handlers for this item
|
||||
*/
|
||||
void PartPolygon::addHandler()
|
||||
{
|
||||
if (m_handler_vector.isEmpty() && scene())
|
||||
{
|
||||
m_handler_vector = QetGraphicsHandlerItem::handlerForPoint(mapToScene(m_polygon));
|
||||
if (m_handler_vector.isEmpty() && scene())
|
||||
{
|
||||
m_handler_vector = QetGraphicsHandlerItem::handlerForPoint(mapToScene(m_polygon));
|
||||
|
||||
for(QetGraphicsHandlerItem *handler : m_handler_vector)
|
||||
{
|
||||
handler->setColor(Qt::blue);
|
||||
scene()->addItem(handler);
|
||||
handler->installSceneEventFilter(this);
|
||||
handler->setZValue(this->zValue()+1);
|
||||
}
|
||||
}
|
||||
for(QetGraphicsHandlerItem *handler : m_handler_vector)
|
||||
{
|
||||
handler->setColor(Qt::blue);
|
||||
scene()->addItem(handler);
|
||||
handler->installSceneEventFilter(this);
|
||||
handler->setZValue(this->zValue()+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::removeHandler
|
||||
Remove the handlers of this item
|
||||
@brief PartPolygon::removeHandler
|
||||
Remove the handlers of this item
|
||||
*/
|
||||
void PartPolygon::removeHandler()
|
||||
{
|
||||
if (!m_handler_vector.isEmpty())
|
||||
{
|
||||
qDeleteAll(m_handler_vector);
|
||||
m_handler_vector.clear();
|
||||
}
|
||||
if (!m_handler_vector.isEmpty())
|
||||
{
|
||||
qDeleteAll(m_handler_vector);
|
||||
m_handler_vector.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::insertPoint
|
||||
Insert a point in this polygone
|
||||
@brief PartPolygon::insertPoint
|
||||
Insert a point in this polygone
|
||||
*/
|
||||
void PartPolygon::insertPoint()
|
||||
{
|
||||
QPolygonF new_polygon = QetGraphicsHandlerUtility::polygonForInsertPoint(m_polygon, m_closed, elementScene()->snapToGrid(m_context_menu_pos));
|
||||
QPolygonF new_polygon = QetGraphicsHandlerUtility::polygonForInsertPoint(m_polygon, m_closed, elementScene()->snapToGrid(m_context_menu_pos));
|
||||
|
||||
if(new_polygon != m_polygon)
|
||||
{
|
||||
//Wrap the undo for avoid to merge the undo commands when user add several points.
|
||||
QUndoCommand *undo = new QUndoCommand(tr("Ajouter un point à un polygone"));
|
||||
new QPropertyUndoCommand(this, "polygon", m_polygon, new_polygon, undo);
|
||||
elementScene()->undoStack().push(undo);
|
||||
}
|
||||
if(new_polygon != m_polygon)
|
||||
{
|
||||
//Wrap the undo for avoid to merge the undo commands when user add several points.
|
||||
QUndoCommand *undo = new QUndoCommand(tr("Ajouter un point ?? un polygone"));
|
||||
new QPropertyUndoCommand(this, "polygon", m_polygon, new_polygon, undo);
|
||||
elementScene()->undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::removePoint
|
||||
remove a point on this polygon
|
||||
@brief PartPolygon::removePoint
|
||||
remove a point on this polygon
|
||||
*/
|
||||
void PartPolygon::removePoint()
|
||||
{
|
||||
if (m_handler_vector.size() == 2)
|
||||
return;
|
||||
if (m_handler_vector.size() == 2)
|
||||
return;
|
||||
|
||||
QPointF point = mapToScene(m_context_menu_pos);
|
||||
int index = -1;
|
||||
for (int i=0 ; i<m_handler_vector.size() ; i++)
|
||||
{
|
||||
QetGraphicsHandlerItem *qghi = m_handler_vector.at(i);
|
||||
if (qghi->contains(qghi->mapFromScene(point)))
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index > -1 && index<m_handler_vector.count())
|
||||
{
|
||||
QPolygonF polygon = this->polygon();
|
||||
qDebug() << index;
|
||||
polygon.removeAt(index);
|
||||
QPointF point = mapToScene(m_context_menu_pos);
|
||||
int index = -1;
|
||||
for (int i=0 ; i<m_handler_vector.size() ; i++)
|
||||
{
|
||||
QetGraphicsHandlerItem *qghi = m_handler_vector.at(i);
|
||||
if (qghi->contains(qghi->mapFromScene(point)))
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index > -1 && index<m_handler_vector.count())
|
||||
{
|
||||
QPolygonF polygon = this->polygon();
|
||||
qDebug() << index;
|
||||
polygon.removeAt(index);
|
||||
|
||||
//Wrap the undo for avoid to merge the undo commands when user add several points.
|
||||
QUndoCommand *undo = new QUndoCommand(tr("Supprimer un point d'un polygone"));
|
||||
new QPropertyUndoCommand(this, "polygon", this->polygon(), polygon, undo);
|
||||
elementScene()->undoStack().push(undo);
|
||||
}
|
||||
//Wrap the undo for avoid to merge the undo commands when user add several points.
|
||||
QUndoCommand *undo = new QUndoCommand(tr("Supprimer un point d'un polygone"));
|
||||
new QPropertyUndoCommand(this, "polygon", this->polygon(), polygon, undo);
|
||||
elementScene()->undoStack().push(undo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::shape
|
||||
@return the shape of this item
|
||||
@brief PartPolygon::shape
|
||||
@return the shape of this item
|
||||
*/
|
||||
QPainterPath PartPolygon::shape() const
|
||||
{
|
||||
QPainterPath shape;
|
||||
shape.addPolygon(m_polygon);
|
||||
QPainterPath shape;
|
||||
shape.addPolygon(m_polygon);
|
||||
|
||||
if (m_closed)
|
||||
shape.lineTo(m_polygon.first());
|
||||
if (m_closed)
|
||||
shape.lineTo(m_polygon.first());
|
||||
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
||||
shape = pps.createStroke(shape);
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
||||
shape = pps.createStroke(shape);
|
||||
|
||||
return shape;
|
||||
return shape;
|
||||
}
|
||||
|
||||
QPainterPath PartPolygon::shadowShape() const
|
||||
{
|
||||
QPainterPath shape;
|
||||
shape.addPolygon(m_polygon);
|
||||
QPainterPath shape;
|
||||
shape.addPolygon(m_polygon);
|
||||
|
||||
if (m_closed)
|
||||
shape.lineTo(m_polygon.first());
|
||||
if (m_closed)
|
||||
shape.lineTo(m_polygon.first());
|
||||
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(penWeight());
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(penWeight());
|
||||
|
||||
return (pps.createStroke(shape));
|
||||
return (pps.createStroke(shape));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartPolygon::boundingRect
|
||||
@return the bounding rect of this item
|
||||
@brief PartPolygon::boundingRect
|
||||
@return the bounding rect of this item
|
||||
*/
|
||||
QRectF PartPolygon::boundingRect() const
|
||||
{
|
||||
QRectF r = m_polygon.boundingRect();
|
||||
QRectF r = m_polygon.boundingRect();
|
||||
|
||||
qreal adjust = (SHADOWS_HEIGHT + penWeight()) / 2;
|
||||
//We add 0.5 because CustomElementGraphicPart::drawShadowShape
|
||||
//draw a shape bigger of 0.5 when pen weight is to 0.
|
||||
if (penWeight() == 0) adjust += 0.5;
|
||||
qreal adjust = (SHADOWS_HEIGHT + penWeight()) / 2;
|
||||
//We add 0.5 because CustomElementGraphicPart::drawShadowShape
|
||||
//draw a shape bigger of 0.5 when pen weight is to 0.
|
||||
if (penWeight() == 0) adjust += 0.5;
|
||||
|
||||
r.adjust(-adjust, -adjust, adjust, adjust);
|
||||
r.adjust(-adjust, -adjust, adjust, adjust);
|
||||
|
||||
return(r);
|
||||
return(r);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef PART_POLYGON_H
|
||||
#define PART_POLYGON_H
|
||||
@@ -26,93 +26,93 @@ class QetGraphicsHandlerItem;
|
||||
class QAction;
|
||||
|
||||
/**
|
||||
@brief The PartPolygon class
|
||||
This class represents a polygon primitive which may be used to compose the
|
||||
drawing of an electrical element within the element editor.
|
||||
@brief The PartPolygon class
|
||||
This class represents a polygon primitive which may be used to compose the
|
||||
drawing of an electrical element within the element editor.
|
||||
*/
|
||||
class PartPolygon : public CustomElementGraphicPart
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(bool closed READ isClosed WRITE setClosed)
|
||||
Q_PROPERTY(QPolygonF polygon READ polygon WRITE setPolygon)
|
||||
Q_PROPERTY(bool closed READ isClosed WRITE setClosed)
|
||||
Q_PROPERTY(QPolygonF polygon READ polygon WRITE setPolygon)
|
||||
|
||||
// constructors, destructor
|
||||
public:
|
||||
PartPolygon(QETElementEditor *editor, QGraphicsItem *parent = nullptr);
|
||||
~PartPolygon() override;
|
||||
|
||||
private:
|
||||
PartPolygon(const PartPolygon &);
|
||||
// constructors, destructor
|
||||
public:
|
||||
PartPolygon(QETElementEditor *editor, QGraphicsItem *parent = nullptr);
|
||||
~PartPolygon() override;
|
||||
|
||||
private:
|
||||
PartPolygon(const PartPolygon &);
|
||||
|
||||
signals:
|
||||
void closedChange();
|
||||
void polygonChanged();
|
||||
signals:
|
||||
void closedChange();
|
||||
void polygonChanged();
|
||||
|
||||
// methods
|
||||
public:
|
||||
enum { Type = UserType + 1105 };
|
||||
/**
|
||||
* Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a PartPolygon.
|
||||
* @return the QGraphicsItem type
|
||||
*/
|
||||
int type() const override { return Type; }
|
||||
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
|
||||
// methods
|
||||
public:
|
||||
enum { Type = UserType + 1105 };
|
||||
/**
|
||||
* Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a PartPolygon.
|
||||
* @return the QGraphicsItem type
|
||||
*/
|
||||
int type() const override { return Type; }
|
||||
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
|
||||
|
||||
QString name() const override { return(QObject::tr("polygone", "element part name")); }
|
||||
QString xmlName() const override { return(QString("polygon")); }
|
||||
void fromXml(const QDomElement &) override;
|
||||
const QDomElement toXml(QDomDocument &) const override;
|
||||
QString name() const override { return(QObject::tr("polygone", "element part name")); }
|
||||
QString xmlName() const override { return(QString("polygon")); }
|
||||
void fromXml(const QDomElement &) override;
|
||||
const QDomElement toXml(QDomDocument &) const override;
|
||||
|
||||
QPainterPath shape () const override;
|
||||
QPainterPath shadowShape() const override;
|
||||
QRectF boundingRect() const override;
|
||||
bool isUseless() const override;
|
||||
QRectF sceneGeometricRect() const override;
|
||||
QPainterPath shape () const override;
|
||||
QPainterPath shadowShape() const override;
|
||||
QRectF boundingRect() const override;
|
||||
bool isUseless() const override;
|
||||
QRectF sceneGeometricRect() const override;
|
||||
|
||||
void startUserTransformation(const QRectF &) override;
|
||||
void handleUserTransformation(const QRectF &, const QRectF &) override;
|
||||
QET::ScalingMethod preferredScalingMethod() const override;
|
||||
void startUserTransformation(const QRectF &) override;
|
||||
void handleUserTransformation(const QRectF &, const QRectF &) override;
|
||||
QET::ScalingMethod preferredScalingMethod() const override;
|
||||
|
||||
QPolygonF polygon () const;
|
||||
void setPolygon (const QPolygonF &polygon);
|
||||
QPolygonF polygon () const;
|
||||
void setPolygon (const QPolygonF &polygon);
|
||||
|
||||
void addPoint (const QPointF &point);
|
||||
void setLastPoint (const QPointF &point);
|
||||
void removeLastPoint ();
|
||||
void addPoint (const QPointF &point);
|
||||
void setLastPoint (const QPointF &point);
|
||||
void removeLastPoint ();
|
||||
|
||||
bool isClosed () const {return m_closed;}
|
||||
void setClosed (bool close);
|
||||
bool isClosed () const {return m_closed;}
|
||||
void setClosed (bool close);
|
||||
|
||||
void setHandlerColor(QPointF pos, const QColor &color) final;
|
||||
void resetAllHandlerColor() final;
|
||||
void setHandlerColor(QPointF pos, const QColor &color) final;
|
||||
void resetAllHandlerColor() final;
|
||||
|
||||
protected:
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||
|
||||
private:
|
||||
void adjusteHandlerPos();
|
||||
void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void sceneSelectionChanged ();
|
||||
|
||||
void addHandler();
|
||||
void removeHandler();
|
||||
void insertPoint();
|
||||
void removePoint();
|
||||
|
||||
|
||||
bool m_closed;
|
||||
QList<QPointF> saved_points_;
|
||||
QPolygonF m_polygon;
|
||||
QPropertyUndoCommand *m_undo_command;
|
||||
int m_vector_index = -1;
|
||||
QVector<QetGraphicsHandlerItem *> m_handler_vector;
|
||||
QAction *m_insert_point,
|
||||
*m_remove_point;
|
||||
QPointF m_context_menu_pos;
|
||||
protected:
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||
|
||||
private:
|
||||
void adjusteHandlerPos();
|
||||
void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void sceneSelectionChanged ();
|
||||
|
||||
void addHandler();
|
||||
void removeHandler();
|
||||
void insertPoint();
|
||||
void removePoint();
|
||||
|
||||
|
||||
bool m_closed;
|
||||
QList<QPointF> saved_points_;
|
||||
QPolygonF m_polygon;
|
||||
QPropertyUndoCommand *m_undo_command;
|
||||
int m_vector_index = -1;
|
||||
QVector<QetGraphicsHandlerItem *> m_handler_vector;
|
||||
QAction *m_insert_point,
|
||||
*m_remove_point;
|
||||
QPointF m_context_menu_pos;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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.
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "partrectangle.h"
|
||||
#include "elementscene.h"
|
||||
@@ -22,541 +22,541 @@
|
||||
#include "QetGraphicsItemModeler/qetgraphicshandlerutility.h"
|
||||
|
||||
/**
|
||||
@brief PartRectangle::PartRectangle
|
||||
Constructor
|
||||
@param editor the QETElementEditor of this item
|
||||
@param parent parent item
|
||||
@brief PartRectangle::PartRectangle
|
||||
Constructor
|
||||
@param editor the QETElementEditor of this item
|
||||
@param parent parent item
|
||||
*/
|
||||
PartRectangle::PartRectangle(QETElementEditor *editor, QGraphicsItem *parent) :
|
||||
CustomElementGraphicPart(editor, parent)
|
||||
CustomElementGraphicPart(editor, parent)
|
||||
{}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::~PartRectangle
|
||||
@brief PartRectangle::~PartRectangle
|
||||
*/
|
||||
PartRectangle::~PartRectangle()
|
||||
{
|
||||
removeHandler();
|
||||
removeHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::paint
|
||||
Draw this Rectangle
|
||||
@param painter
|
||||
@param options
|
||||
@param widget
|
||||
@brief PartRectangle::paint
|
||||
Draw this Rectangle
|
||||
@param painter
|
||||
@param options
|
||||
@param widget
|
||||
*/
|
||||
void PartRectangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(widget);
|
||||
applyStylesToQPainter(*painter);
|
||||
QPen t = painter -> pen();
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
||||
t.setCosmetic(options && options -> levelOfDetail < 1.0);
|
||||
Q_UNUSED(widget);
|
||||
applyStylesToQPainter(*painter);
|
||||
QPen t = painter -> pen();
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
||||
t.setCosmetic(options && options -> levelOfDetail < 1.0);
|
||||
#else
|
||||
#if TODO_LIST
|
||||
#pragma message("@TODO remove code for QT 6 or later")
|
||||
#endif
|
||||
t.setCosmetic(options && options -> levelOfDetailFromTransform(painter->worldTransform()) < 1.0);
|
||||
t.setCosmetic(options && options -> levelOfDetailFromTransform(painter->worldTransform()) < 1.0);
|
||||
#endif
|
||||
if (isSelected())
|
||||
t.setColor(Qt::red);
|
||||
if (isSelected())
|
||||
t.setColor(Qt::red);
|
||||
|
||||
t.setJoinStyle(Qt::MiterJoin);
|
||||
t.setJoinStyle(Qt::MiterJoin);
|
||||
|
||||
//Force the pen to width 0 if one of dimension is null
|
||||
if (!rect().width() || !rect().height())
|
||||
t.setWidth(0);
|
||||
//Force the pen to width 0 if one of dimension is null
|
||||
if (!rect().width() || !rect().height())
|
||||
t.setWidth(0);
|
||||
|
||||
painter->setPen(t);
|
||||
painter->drawRoundedRect(m_rect, m_xRadius, m_yRadius);
|
||||
painter->setPen(t);
|
||||
painter->drawRoundedRect(m_rect, m_xRadius, m_yRadius);
|
||||
|
||||
if (m_hovered)
|
||||
drawShadowShape(painter);
|
||||
if (m_hovered)
|
||||
drawShadowShape(painter);
|
||||
|
||||
if (isSelected())
|
||||
drawCross(m_rect.center(), painter);
|
||||
if (isSelected())
|
||||
drawCross(m_rect.center(), painter);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::toXml
|
||||
Export this rectangle in xml
|
||||
@param xml_document : Xml document to use for create the xml element.
|
||||
@return an xml element that describe this ellipse
|
||||
@brief PartRectangle::toXml
|
||||
Export this rectangle in xml
|
||||
@param xml_document : Xml document to use for create the xml element.
|
||||
@return an xml element that describe this ellipse
|
||||
*/
|
||||
const QDomElement PartRectangle::toXml(QDomDocument &xml_document) const
|
||||
{
|
||||
QDomElement xml_element = xml_document.createElement("rect");
|
||||
QPointF top_left(sceneTopLeft());
|
||||
xml_element.setAttribute("x", QString("%1").arg(top_left.x()));
|
||||
xml_element.setAttribute("y", QString("%1").arg(top_left.y()));
|
||||
xml_element.setAttribute("width", QString("%1").arg(m_rect.width()));
|
||||
xml_element.setAttribute("height", QString("%1").arg(m_rect.height()));
|
||||
QDomElement xml_element = xml_document.createElement("rect");
|
||||
QPointF top_left(sceneTopLeft());
|
||||
xml_element.setAttribute("x", QString("%1").arg(top_left.x()));
|
||||
xml_element.setAttribute("y", QString("%1").arg(top_left.y()));
|
||||
xml_element.setAttribute("width", QString("%1").arg(m_rect.width()));
|
||||
xml_element.setAttribute("height", QString("%1").arg(m_rect.height()));
|
||||
|
||||
QRectF rect = m_rect.normalized();
|
||||
qreal x = m_xRadius;
|
||||
if (x > rect.width()/2) {
|
||||
x = rect.width()/2;
|
||||
}
|
||||
qreal y = m_yRadius;
|
||||
if (y > rect.height()/2) {
|
||||
y = rect.height()/2;
|
||||
}
|
||||
QRectF rect = m_rect.normalized();
|
||||
qreal x = m_xRadius;
|
||||
if (x > rect.width()/2) {
|
||||
x = rect.width()/2;
|
||||
}
|
||||
qreal y = m_yRadius;
|
||||
if (y > rect.height()/2) {
|
||||
y = rect.height()/2;
|
||||
}
|
||||
|
||||
xml_element.setAttribute("rx", QString::number(m_xRadius));
|
||||
xml_element.setAttribute("ry", QString::number(m_yRadius));
|
||||
xml_element.setAttribute("rx", QString::number(m_xRadius));
|
||||
xml_element.setAttribute("ry", QString::number(m_yRadius));
|
||||
|
||||
stylesToXml(xml_element);
|
||||
return(xml_element);
|
||||
stylesToXml(xml_element);
|
||||
return(xml_element);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::fromXml
|
||||
Import the properties of this rectangle from a xml element.
|
||||
@param qde : Xml document to use.
|
||||
@brief PartRectangle::fromXml
|
||||
Import the properties of this rectangle from a xml element.
|
||||
@param qde : Xml document to use.
|
||||
*/
|
||||
void PartRectangle::fromXml(const QDomElement &qde)
|
||||
{
|
||||
stylesFromXml(qde);
|
||||
setPos(mapFromScene(qde.attribute("x", "0").toDouble(),
|
||||
qde.attribute("y", "0").toDouble()));
|
||||
stylesFromXml(qde);
|
||||
setPos(mapFromScene(qde.attribute("x", "0").toDouble(),
|
||||
qde.attribute("y", "0").toDouble()));
|
||||
|
||||
QRectF rect(QPointF(0,0), QSizeF(qde.attribute("width", "0").toDouble(),
|
||||
qde.attribute("height", "0").toDouble()));
|
||||
QRectF rect(QPointF(0,0), QSizeF(qde.attribute("width", "0").toDouble(),
|
||||
qde.attribute("height", "0").toDouble()));
|
||||
|
||||
setRect(rect.normalized());
|
||||
setXRadius(qde.attribute("rx", "0").toDouble());
|
||||
setYRadius(qde.attribute("ry", "0").toDouble());
|
||||
setRect(rect.normalized());
|
||||
setXRadius(qde.attribute("rx", "0").toDouble());
|
||||
setYRadius(qde.attribute("ry", "0").toDouble());
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::rect
|
||||
@return : Returns the item's rectangle.
|
||||
@brief PartRectangle::rect
|
||||
@return : Returns the item's rectangle.
|
||||
*/
|
||||
QRectF PartRectangle::rect() const
|
||||
{
|
||||
return m_rect;
|
||||
return m_rect;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::setRect
|
||||
Sets the item's rectangle to be the given rectangle.
|
||||
@param rect
|
||||
@brief PartRectangle::setRect
|
||||
Sets the item's rectangle to be the given rectangle.
|
||||
@param rect
|
||||
*/
|
||||
void PartRectangle::setRect(const QRectF &rect)
|
||||
{
|
||||
if (rect == m_rect) return;
|
||||
prepareGeometryChange();
|
||||
m_rect = rect;
|
||||
adjusteHandlerPos();
|
||||
emit rectChanged();
|
||||
if (rect == m_rect) return;
|
||||
prepareGeometryChange();
|
||||
m_rect = rect;
|
||||
adjusteHandlerPos();
|
||||
emit rectChanged();
|
||||
}
|
||||
|
||||
void PartRectangle::setXRadius(qreal X)
|
||||
{
|
||||
m_xRadius = X;
|
||||
update();
|
||||
adjusteHandlerPos();
|
||||
emit XRadiusChanged();
|
||||
m_xRadius = X;
|
||||
update();
|
||||
adjusteHandlerPos();
|
||||
emit XRadiusChanged();
|
||||
}
|
||||
|
||||
void PartRectangle::setYRadius(qreal Y)
|
||||
{
|
||||
m_yRadius = Y;
|
||||
update();
|
||||
adjusteHandlerPos();
|
||||
emit YRadiusChanged();
|
||||
m_yRadius = Y;
|
||||
update();
|
||||
adjusteHandlerPos();
|
||||
emit YRadiusChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::sceneGeometricRect
|
||||
@return the minimum, margin-less rectangle this part can fit into, in scene
|
||||
coordinates. It is different from boundingRect() because it is not supposed
|
||||
to imply any margin, and it is different from shape because it is a regular
|
||||
rectangle, not a complex shape.
|
||||
@brief PartRectangle::sceneGeometricRect
|
||||
@return the minimum, margin-less rectangle this part can fit into, in scene
|
||||
coordinates. It is different from boundingRect() because it is not supposed
|
||||
to imply any margin, and it is different from shape because it is a regular
|
||||
rectangle, not a complex shape.
|
||||
*/
|
||||
QRectF PartRectangle::sceneGeometricRect() const
|
||||
{
|
||||
return(mapToScene(rect()).boundingRect());
|
||||
return(mapToScene(rect()).boundingRect());
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::sceneTopLeft
|
||||
@return the top left of rectangle, in scene coordinate
|
||||
@brief PartRectangle::sceneTopLeft
|
||||
@return the top left of rectangle, in scene coordinate
|
||||
*/
|
||||
QPointF PartRectangle::sceneTopLeft() const
|
||||
{
|
||||
return(mapToScene(rect().topLeft()));
|
||||
return(mapToScene(rect().topLeft()));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::shape
|
||||
@return the shape of this item
|
||||
@brief PartRectangle::shape
|
||||
@return the shape of this item
|
||||
*/
|
||||
QPainterPath PartRectangle::shape() const
|
||||
{
|
||||
QPainterPath shape;
|
||||
shape.addRoundedRect(m_rect, m_xRadius, m_yRadius);
|
||||
QPainterPath shape;
|
||||
shape.addRoundedRect(m_rect, m_xRadius, m_yRadius);
|
||||
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
||||
shape = pps.createStroke(shape);
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
||||
shape = pps.createStroke(shape);
|
||||
|
||||
return shape;
|
||||
return shape;
|
||||
}
|
||||
|
||||
QPainterPath PartRectangle::shadowShape() const
|
||||
{
|
||||
QPainterPath shape;
|
||||
shape.addRoundedRect(m_rect, m_xRadius, m_yRadius);
|
||||
QPainterPath shape;
|
||||
shape.addRoundedRect(m_rect, m_xRadius, m_yRadius);
|
||||
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(penWeight());
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(penWeight());
|
||||
|
||||
return (pps.createStroke(shape));
|
||||
return (pps.createStroke(shape));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::boundingRect
|
||||
@return Bounding rectangle this part can fit into
|
||||
@brief PartRectangle::boundingRect
|
||||
@return Bounding rectangle this part can fit into
|
||||
*/
|
||||
QRectF PartRectangle::boundingRect() const
|
||||
{
|
||||
qreal adjust = (SHADOWS_HEIGHT + penWeight()) / 2;
|
||||
//We add 0.5 because CustomElementGraphicPart::drawShadowShape
|
||||
//draw a shape bigger of 0.5 when pen weight is to 0.
|
||||
if (penWeight() == 0) adjust += 0.5;
|
||||
qreal adjust = (SHADOWS_HEIGHT + penWeight()) / 2;
|
||||
//We add 0.5 because CustomElementGraphicPart::drawShadowShape
|
||||
//draw a shape bigger of 0.5 when pen weight is to 0.
|
||||
if (penWeight() == 0) adjust += 0.5;
|
||||
|
||||
QRectF r = m_rect.normalized();
|
||||
r.adjust(-adjust, -adjust, adjust, adjust);
|
||||
QRectF r = m_rect.normalized();
|
||||
r.adjust(-adjust, -adjust, adjust, adjust);
|
||||
|
||||
return(r);
|
||||
return(r);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::isUseless
|
||||
@return true if this part is irrelevant and does not deserve to be Retained / registered.
|
||||
An rectangle is relevant when he's not null.
|
||||
@brief PartRectangle::isUseless
|
||||
@return true if this part is irrelevant and does not deserve to be Retained / registered.
|
||||
An rectangle is relevant when he's not null.
|
||||
*/
|
||||
bool PartRectangle::isUseless() const
|
||||
{
|
||||
return(rect().isNull());
|
||||
return(rect().isNull());
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::startUserTransformation
|
||||
Start the user-induced transformation, provided this primitive is contained
|
||||
within the initial_selection_rect bounding rectangle.
|
||||
@param initial_selection_rect
|
||||
@brief PartRectangle::startUserTransformation
|
||||
Start the user-induced transformation, provided this primitive is contained
|
||||
within the initial_selection_rect bounding rectangle.
|
||||
@param initial_selection_rect
|
||||
*/
|
||||
void PartRectangle::startUserTransformation(const QRectF &initial_selection_rect)
|
||||
{
|
||||
Q_UNUSED(initial_selection_rect)
|
||||
// we keep track of our own rectangle at the moment in scene coordinates too
|
||||
saved_points_.clear();
|
||||
saved_points_ << mapToScene(rect().topLeft()) << mapToScene(rect().bottomRight());
|
||||
Q_UNUSED(initial_selection_rect)
|
||||
// we keep track of our own rectangle at the moment in scene coordinates too
|
||||
saved_points_.clear();
|
||||
saved_points_ << mapToScene(rect().topLeft()) << mapToScene(rect().bottomRight());
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::handleUserTransformation
|
||||
Handle the user-induced transformation from \a initial_selection_rect to \a new_selection_rect
|
||||
@param initial_selection_rect
|
||||
@param new_selection_rect
|
||||
@brief PartRectangle::handleUserTransformation
|
||||
Handle the user-induced transformation from \a initial_selection_rect to \a new_selection_rect
|
||||
@param initial_selection_rect
|
||||
@param new_selection_rect
|
||||
*/
|
||||
void PartRectangle::handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect)
|
||||
{
|
||||
QList<QPointF> mapped_points = mapPoints(initial_selection_rect, new_selection_rect, saved_points_);
|
||||
setRect(QRectF(mapFromScene(mapped_points.at(0)), mapFromScene(mapped_points.at(1))));
|
||||
QList<QPointF> mapped_points = mapPoints(initial_selection_rect, new_selection_rect, saved_points_);
|
||||
setRect(QRectF(mapFromScene(mapped_points.at(0)), mapFromScene(mapped_points.at(1))));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::mouseReleaseEvent
|
||||
Handle mouse release event
|
||||
@param event
|
||||
@brief PartRectangle::mouseReleaseEvent
|
||||
Handle mouse release event
|
||||
@param event
|
||||
*/
|
||||
void PartRectangle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton && event->buttonDownPos(Qt::LeftButton) == event->pos())
|
||||
switchResizeMode();
|
||||
if (event->button() == Qt::LeftButton && event->buttonDownPos(Qt::LeftButton) == event->pos())
|
||||
switchResizeMode();
|
||||
|
||||
CustomElementGraphicPart::mouseReleaseEvent(event);
|
||||
CustomElementGraphicPart::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::itemChange
|
||||
@param change
|
||||
@param value
|
||||
@return
|
||||
@brief PartRectangle::itemChange
|
||||
@param change
|
||||
@param value
|
||||
@return
|
||||
*/
|
||||
QVariant PartRectangle::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
if (change == ItemSelectedHasChanged && scene())
|
||||
{
|
||||
if (value.toBool() == true)
|
||||
{
|
||||
//When item is selected, he must to be up to date whene the selection in the scene change, for display or not the handler,
|
||||
//according to the number of selected items.
|
||||
connect(scene(), &QGraphicsScene::selectionChanged, this, &PartRectangle::sceneSelectionChanged);
|
||||
if (change == ItemSelectedHasChanged && scene())
|
||||
{
|
||||
if (value.toBool() == true)
|
||||
{
|
||||
//When item is selected, he must to be up to date whene the selection in the scene change, for display or not the handler,
|
||||
//according to the number of selected items.
|
||||
connect(scene(), &QGraphicsScene::selectionChanged, this, &PartRectangle::sceneSelectionChanged);
|
||||
|
||||
if (scene()->selectedItems().size() == 1)
|
||||
addHandler();
|
||||
}
|
||||
else
|
||||
{
|
||||
disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartRectangle::sceneSelectionChanged);
|
||||
removeHandler();
|
||||
}
|
||||
}
|
||||
else if (change == ItemPositionHasChanged)
|
||||
{
|
||||
adjusteHandlerPos();
|
||||
}
|
||||
else if (change == ItemSceneChange)
|
||||
{
|
||||
if(scene())
|
||||
disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartRectangle::sceneSelectionChanged);
|
||||
if (scene()->selectedItems().size() == 1)
|
||||
addHandler();
|
||||
}
|
||||
else
|
||||
{
|
||||
disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartRectangle::sceneSelectionChanged);
|
||||
removeHandler();
|
||||
}
|
||||
}
|
||||
else if (change == ItemPositionHasChanged)
|
||||
{
|
||||
adjusteHandlerPos();
|
||||
}
|
||||
else if (change == ItemSceneChange)
|
||||
{
|
||||
if(scene())
|
||||
disconnect(scene(), &QGraphicsScene::selectionChanged, this, &PartRectangle::sceneSelectionChanged);
|
||||
|
||||
setSelected(false); //This item is removed from scene, then we deselect this, and so, the handlers is also removed.
|
||||
}
|
||||
setSelected(false); //This item is removed from scene, then we deselect this, and so, the handlers is also removed.
|
||||
}
|
||||
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::sceneEventFilter
|
||||
@param watched
|
||||
@param event
|
||||
@return
|
||||
@brief PartRectangle::sceneEventFilter
|
||||
@param watched
|
||||
@param event
|
||||
@return
|
||||
*/
|
||||
bool PartRectangle::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
||||
{
|
||||
//Watched must be an handler
|
||||
if(watched->type() == QetGraphicsHandlerItem::Type)
|
||||
{
|
||||
QetGraphicsHandlerItem *qghi = qgraphicsitem_cast<QetGraphicsHandlerItem *>(watched);
|
||||
//Watched must be an handler
|
||||
if(watched->type() == QetGraphicsHandlerItem::Type)
|
||||
{
|
||||
QetGraphicsHandlerItem *qghi = qgraphicsitem_cast<QetGraphicsHandlerItem *>(watched);
|
||||
|
||||
if(m_handler_vector.contains(qghi)) //Handler must be in m_vector_index, then we can start resize
|
||||
{
|
||||
m_vector_index = m_handler_vector.indexOf(qghi);
|
||||
if (m_vector_index != -1)
|
||||
{
|
||||
if(event->type() == QEvent::GraphicsSceneMousePress) //Click
|
||||
{
|
||||
handlerMousePressEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
else if(event->type() == QEvent::GraphicsSceneMouseMove) //Move
|
||||
{
|
||||
handlerMouseMoveEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
else if (event->type() == QEvent::GraphicsSceneMouseRelease) //Release
|
||||
{
|
||||
handlerMouseReleaseEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(m_handler_vector.contains(qghi)) //Handler must be in m_vector_index, then we can start resize
|
||||
{
|
||||
m_vector_index = m_handler_vector.indexOf(qghi);
|
||||
if (m_vector_index != -1)
|
||||
{
|
||||
if(event->type() == QEvent::GraphicsSceneMousePress) //Click
|
||||
{
|
||||
handlerMousePressEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
else if(event->type() == QEvent::GraphicsSceneMouseMove) //Move
|
||||
{
|
||||
handlerMouseMoveEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
else if (event->type() == QEvent::GraphicsSceneMouseRelease) //Release
|
||||
{
|
||||
handlerMouseReleaseEvent(qghi, static_cast<QGraphicsSceneMouseEvent *>(event));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::switchResizeMode
|
||||
@brief PartRectangle::switchResizeMode
|
||||
*/
|
||||
void PartRectangle::switchResizeMode()
|
||||
{
|
||||
if (m_resize_mode == 1)
|
||||
{
|
||||
m_resize_mode = 2;
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector)
|
||||
qghi->setColor(Qt::darkGreen);
|
||||
}
|
||||
else if (m_resize_mode == 2)
|
||||
{
|
||||
m_resize_mode = 3;
|
||||
qDeleteAll(m_handler_vector);
|
||||
m_handler_vector.clear();
|
||||
addHandler();
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector) {
|
||||
qghi->setColor(Qt::magenta);
|
||||
}
|
||||
}
|
||||
else if (m_resize_mode == 3)
|
||||
{
|
||||
m_resize_mode = 1;
|
||||
qDeleteAll(m_handler_vector);
|
||||
m_handler_vector.clear();
|
||||
addHandler();
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector) {
|
||||
qghi->setColor(Qt::blue);
|
||||
}
|
||||
}
|
||||
if (m_resize_mode == 1)
|
||||
{
|
||||
m_resize_mode = 2;
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector)
|
||||
qghi->setColor(Qt::darkGreen);
|
||||
}
|
||||
else if (m_resize_mode == 2)
|
||||
{
|
||||
m_resize_mode = 3;
|
||||
qDeleteAll(m_handler_vector);
|
||||
m_handler_vector.clear();
|
||||
addHandler();
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector) {
|
||||
qghi->setColor(Qt::magenta);
|
||||
}
|
||||
}
|
||||
else if (m_resize_mode == 3)
|
||||
{
|
||||
m_resize_mode = 1;
|
||||
qDeleteAll(m_handler_vector);
|
||||
m_handler_vector.clear();
|
||||
addHandler();
|
||||
for (QetGraphicsHandlerItem *qghi : m_handler_vector) {
|
||||
qghi->setColor(Qt::blue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::adjusteHandlerPos
|
||||
@brief PartRectangle::adjusteHandlerPos
|
||||
*/
|
||||
void PartRectangle::adjusteHandlerPos()
|
||||
{
|
||||
if (m_handler_vector.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (m_handler_vector.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QVector <QPointF> points_vector;
|
||||
QVector <QPointF> points_vector;
|
||||
|
||||
if(m_resize_mode != 3) {
|
||||
points_vector = QetGraphicsHandlerUtility::pointsForRect(m_rect);
|
||||
}
|
||||
else {
|
||||
points_vector = QetGraphicsHandlerUtility::pointForRadiusRect(m_rect, m_xRadius, m_yRadius);
|
||||
}
|
||||
if(m_resize_mode != 3) {
|
||||
points_vector = QetGraphicsHandlerUtility::pointsForRect(m_rect);
|
||||
}
|
||||
else {
|
||||
points_vector = QetGraphicsHandlerUtility::pointForRadiusRect(m_rect, m_xRadius, m_yRadius);
|
||||
}
|
||||
|
||||
if (m_handler_vector.size() == points_vector.size())
|
||||
{
|
||||
points_vector = mapToScene(points_vector);
|
||||
for (int i = 0 ; i < points_vector.size() ; ++i)
|
||||
m_handler_vector.at(i)->setPos(points_vector.at(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
qDeleteAll(m_handler_vector);
|
||||
m_handler_vector.clear();
|
||||
addHandler();
|
||||
}
|
||||
if (m_handler_vector.size() == points_vector.size())
|
||||
{
|
||||
points_vector = mapToScene(points_vector);
|
||||
for (int i = 0 ; i < points_vector.size() ; ++i)
|
||||
m_handler_vector.at(i)->setPos(points_vector.at(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
qDeleteAll(m_handler_vector);
|
||||
m_handler_vector.clear();
|
||||
addHandler();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::handlerMousePressEvent
|
||||
@param qghi
|
||||
@param event
|
||||
@brief PartRectangle::handlerMousePressEvent
|
||||
@param qghi
|
||||
@param event
|
||||
*/
|
||||
void PartRectangle::handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(qghi)
|
||||
Q_UNUSED(event)
|
||||
Q_UNUSED(qghi)
|
||||
Q_UNUSED(event)
|
||||
|
||||
m_old_rect = m_rect;
|
||||
m_old_xRadius = m_xRadius;
|
||||
m_old_yRadius = m_yRadius;
|
||||
if(m_xRadius == 0 && m_yRadius == 0) {
|
||||
m_modifie_radius_equaly = true;
|
||||
}
|
||||
m_old_rect = m_rect;
|
||||
m_old_xRadius = m_xRadius;
|
||||
m_old_yRadius = m_yRadius;
|
||||
if(m_xRadius == 0 && m_yRadius == 0) {
|
||||
m_modifie_radius_equaly = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::handlerMouseMoveEvent
|
||||
@param qghi
|
||||
@param event
|
||||
@brief PartRectangle::handlerMouseMoveEvent
|
||||
@param qghi
|
||||
@param event
|
||||
*/
|
||||
void PartRectangle::handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(qghi)
|
||||
Q_UNUSED(qghi)
|
||||
|
||||
QPointF new_pos = event->scenePos();
|
||||
if (event->modifiers() != Qt::ControlModifier)
|
||||
new_pos = elementScene()->snapToGrid(event->scenePos());
|
||||
new_pos = mapFromScene(new_pos);
|
||||
QPointF new_pos = event->scenePos();
|
||||
if (event->modifiers() != Qt::ControlModifier)
|
||||
new_pos = elementScene()->snapToGrid(event->scenePos());
|
||||
new_pos = mapFromScene(new_pos);
|
||||
|
||||
if (m_resize_mode == 1)
|
||||
setRect(QetGraphicsHandlerUtility::rectForPosAtIndex(m_rect, new_pos, m_vector_index));
|
||||
else if (m_resize_mode == 2)
|
||||
setRect(QetGraphicsHandlerUtility::mirrorRectForPosAtIndex(m_rect, new_pos, m_vector_index));
|
||||
else
|
||||
{
|
||||
qreal radius = QetGraphicsHandlerUtility::radiusForPosAtIndex(m_rect, new_pos, m_vector_index);
|
||||
if(m_modifie_radius_equaly) {
|
||||
setXRadius(radius);
|
||||
setYRadius(radius);
|
||||
}
|
||||
else if(m_vector_index == 0) {
|
||||
setXRadius(radius);
|
||||
}
|
||||
else {
|
||||
setYRadius(radius);
|
||||
}
|
||||
}
|
||||
if (m_resize_mode == 1)
|
||||
setRect(QetGraphicsHandlerUtility::rectForPosAtIndex(m_rect, new_pos, m_vector_index));
|
||||
else if (m_resize_mode == 2)
|
||||
setRect(QetGraphicsHandlerUtility::mirrorRectForPosAtIndex(m_rect, new_pos, m_vector_index));
|
||||
else
|
||||
{
|
||||
qreal radius = QetGraphicsHandlerUtility::radiusForPosAtIndex(m_rect, new_pos, m_vector_index);
|
||||
if(m_modifie_radius_equaly) {
|
||||
setXRadius(radius);
|
||||
setYRadius(radius);
|
||||
}
|
||||
else if(m_vector_index == 0) {
|
||||
setXRadius(radius);
|
||||
}
|
||||
else {
|
||||
setYRadius(radius);
|
||||
}
|
||||
}
|
||||
|
||||
adjusteHandlerPos();
|
||||
adjusteHandlerPos();
|
||||
}
|
||||
|
||||
void PartRectangle::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(qghi)
|
||||
Q_UNUSED(event)
|
||||
Q_UNUSED(qghi)
|
||||
Q_UNUSED(event)
|
||||
|
||||
m_modifie_radius_equaly = false;
|
||||
m_modifie_radius_equaly = false;
|
||||
|
||||
QUndoCommand *undo = new QUndoCommand("Modifier un rectangle");
|
||||
if (m_old_rect != m_rect) {
|
||||
QPropertyUndoCommand *u = new QPropertyUndoCommand(this, "rect", QVariant(m_old_rect.normalized()), QVariant(m_rect.normalized()), undo);
|
||||
u->setAnimated(true, false);
|
||||
}
|
||||
if (m_old_xRadius != m_xRadius) {
|
||||
QPropertyUndoCommand *u = new QPropertyUndoCommand(this, "xRadius", QVariant(m_old_xRadius), QVariant(m_xRadius), undo);
|
||||
u->setAnimated();
|
||||
}
|
||||
if (m_old_yRadius != m_yRadius) {
|
||||
QPropertyUndoCommand *u = new QPropertyUndoCommand(this, "yRadius", QVariant(m_old_yRadius), QVariant(m_yRadius), undo);
|
||||
u->setAnimated();
|
||||
}
|
||||
QUndoCommand *undo = new QUndoCommand("Modifier un rectangle");
|
||||
if (m_old_rect != m_rect) {
|
||||
QPropertyUndoCommand *u = new QPropertyUndoCommand(this, "rect", QVariant(m_old_rect.normalized()), QVariant(m_rect.normalized()), undo);
|
||||
u->setAnimated(true, false);
|
||||
}
|
||||
if (m_old_xRadius != m_xRadius) {
|
||||
QPropertyUndoCommand *u = new QPropertyUndoCommand(this, "xRadius", QVariant(m_old_xRadius), QVariant(m_xRadius), undo);
|
||||
u->setAnimated();
|
||||
}
|
||||
if (m_old_yRadius != m_yRadius) {
|
||||
QPropertyUndoCommand *u = new QPropertyUndoCommand(this, "yRadius", QVariant(m_old_yRadius), QVariant(m_yRadius), undo);
|
||||
u->setAnimated();
|
||||
}
|
||||
|
||||
elementScene()->undoStack().push(undo);
|
||||
m_vector_index = -1;
|
||||
elementScene()->undoStack().push(undo);
|
||||
m_vector_index = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::sceneSelectionChanged
|
||||
When the scene selection change, if there are several primitive selected, we remove the handler of this item
|
||||
@brief PartRectangle::sceneSelectionChanged
|
||||
When the scene selection change, if there are several primitive selected, we remove the handler of this item
|
||||
*/
|
||||
void PartRectangle::sceneSelectionChanged()
|
||||
{
|
||||
if (this->isSelected() && scene()->selectedItems().size() == 1)
|
||||
addHandler();
|
||||
else
|
||||
removeHandler();
|
||||
if (this->isSelected() && scene()->selectedItems().size() == 1)
|
||||
addHandler();
|
||||
else
|
||||
removeHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::addHandler
|
||||
Add handlers for this item
|
||||
@brief PartRectangle::addHandler
|
||||
Add handlers for this item
|
||||
*/
|
||||
void PartRectangle::addHandler()
|
||||
{
|
||||
if (m_handler_vector.isEmpty() && scene())
|
||||
{
|
||||
if (m_resize_mode != 3) {
|
||||
m_handler_vector = QetGraphicsHandlerItem::handlerForPoint(mapToScene(QetGraphicsHandlerUtility::pointsForRect(m_rect)));
|
||||
}
|
||||
else {
|
||||
m_handler_vector = QetGraphicsHandlerItem::handlerForPoint(mapToScene(QetGraphicsHandlerUtility::pointForRadiusRect(m_rect, m_xRadius, m_yRadius)));
|
||||
}
|
||||
if (m_handler_vector.isEmpty() && scene())
|
||||
{
|
||||
if (m_resize_mode != 3) {
|
||||
m_handler_vector = QetGraphicsHandlerItem::handlerForPoint(mapToScene(QetGraphicsHandlerUtility::pointsForRect(m_rect)));
|
||||
}
|
||||
else {
|
||||
m_handler_vector = QetGraphicsHandlerItem::handlerForPoint(mapToScene(QetGraphicsHandlerUtility::pointForRadiusRect(m_rect, m_xRadius, m_yRadius)));
|
||||
}
|
||||
|
||||
for (QetGraphicsHandlerItem *handler : m_handler_vector)
|
||||
{
|
||||
QColor color;
|
||||
if(m_resize_mode == 1) {color = Qt::blue;}
|
||||
else if (m_resize_mode == 2) {color = Qt::darkGreen;}
|
||||
else {color = Qt::magenta;}
|
||||
for (QetGraphicsHandlerItem *handler : m_handler_vector)
|
||||
{
|
||||
QColor color;
|
||||
if(m_resize_mode == 1) {color = Qt::blue;}
|
||||
else if (m_resize_mode == 2) {color = Qt::darkGreen;}
|
||||
else {color = Qt::magenta;}
|
||||
|
||||
handler->setColor(color);
|
||||
scene()->addItem(handler);
|
||||
handler->installSceneEventFilter(this);
|
||||
handler->setZValue(this->zValue()+1);
|
||||
}
|
||||
}
|
||||
handler->setColor(color);
|
||||
scene()->addItem(handler);
|
||||
handler->installSceneEventFilter(this);
|
||||
handler->setZValue(this->zValue()+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartRectangle::removeHandler
|
||||
Remove the handlers of this item
|
||||
@brief PartRectangle::removeHandler
|
||||
Remove the handlers of this item
|
||||
*/
|
||||
void PartRectangle::removeHandler()
|
||||
{
|
||||
if (!m_handler_vector.isEmpty())
|
||||
{
|
||||
qDeleteAll(m_handler_vector);
|
||||
m_handler_vector.clear();
|
||||
}
|
||||
if (!m_handler_vector.isEmpty())
|
||||
{
|
||||
qDeleteAll(m_handler_vector);
|
||||
m_handler_vector.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef PART_RECTANGLE_H
|
||||
#define PART_RECTANGLE_H
|
||||
@@ -23,91 +23,91 @@
|
||||
class QetGraphicsHandlerItem;
|
||||
|
||||
/**
|
||||
This class represents a rectangle primitive which may be used to compose the
|
||||
drawing of an electrical element within the element editor.
|
||||
All coordinates is in item coordinate, except pos()
|
||||
This class represents a rectangle primitive which may be used to compose the
|
||||
drawing of an electrical element within the element editor.
|
||||
All coordinates is in item coordinate, except pos()
|
||||
*/
|
||||
class PartRectangle : public CustomElementGraphicPart
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QRectF rect READ rect WRITE setRect)
|
||||
Q_PROPERTY(qreal xRadius READ XRadius WRITE setXRadius NOTIFY XRadiusChanged)
|
||||
Q_PROPERTY(qreal yRadius READ YRadius WRITE setYRadius NOTIFY YRadiusChanged)
|
||||
Q_PROPERTY(QRectF rect READ rect WRITE setRect)
|
||||
Q_PROPERTY(qreal xRadius READ XRadius WRITE setXRadius NOTIFY XRadiusChanged)
|
||||
Q_PROPERTY(qreal yRadius READ YRadius WRITE setYRadius NOTIFY YRadiusChanged)
|
||||
|
||||
// constructors, destructor
|
||||
public:
|
||||
PartRectangle(QETElementEditor *, QGraphicsItem *parent = nullptr);
|
||||
~PartRectangle() override;
|
||||
|
||||
private:
|
||||
PartRectangle(const PartRectangle &);
|
||||
// constructors, destructor
|
||||
public:
|
||||
PartRectangle(QETElementEditor *, QGraphicsItem *parent = nullptr);
|
||||
~PartRectangle() override;
|
||||
|
||||
private:
|
||||
PartRectangle(const PartRectangle &);
|
||||
|
||||
signals:
|
||||
void rectChanged();
|
||||
void XRadiusChanged();
|
||||
void YRadiusChanged();
|
||||
|
||||
// methods
|
||||
public:
|
||||
enum { Type = UserType + 1109 };
|
||||
/**
|
||||
Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a PartRectangle.
|
||||
@return the QGraphicsItem type
|
||||
*/
|
||||
int type () const override { return Type; }
|
||||
void paint (QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override;
|
||||
QString name () const override { return(QObject::tr("rectangle", "element part name")); }
|
||||
signals:
|
||||
void rectChanged();
|
||||
void XRadiusChanged();
|
||||
void YRadiusChanged();
|
||||
|
||||
// methods
|
||||
public:
|
||||
enum { Type = UserType + 1109 };
|
||||
/**
|
||||
Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a PartRectangle.
|
||||
@return the QGraphicsItem type
|
||||
*/
|
||||
int type () const override { return Type; }
|
||||
void paint (QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override;
|
||||
QString name () const override { return(QObject::tr("rectangle", "element part name")); }
|
||||
|
||||
QString xmlName () const override { return(QString("rect")); }
|
||||
const QDomElement toXml (QDomDocument &) const override;
|
||||
void fromXml (const QDomElement &) override;
|
||||
QString xmlName () const override { return(QString("rect")); }
|
||||
const QDomElement toXml (QDomDocument &) const override;
|
||||
void fromXml (const QDomElement &) override;
|
||||
|
||||
QRectF rect() const;
|
||||
void setRect(const QRectF &rect);
|
||||
qreal XRadius() const {return m_xRadius;}
|
||||
void setXRadius(qreal X);
|
||||
qreal YRadius() const {return m_yRadius;}
|
||||
void setYRadius(qreal Y);
|
||||
QRectF rect() const;
|
||||
void setRect(const QRectF &rect);
|
||||
qreal XRadius() const {return m_xRadius;}
|
||||
void setXRadius(qreal X);
|
||||
qreal YRadius() const {return m_yRadius;}
|
||||
void setYRadius(qreal Y);
|
||||
|
||||
QRectF sceneGeometricRect() const override;
|
||||
virtual QPointF sceneTopLeft() const;
|
||||
QRectF sceneGeometricRect() const override;
|
||||
virtual QPointF sceneTopLeft() const;
|
||||
|
||||
QPainterPath shape () const override;
|
||||
QPainterPath shadowShape() const override;
|
||||
QRectF boundingRect() const override;
|
||||
bool isUseless() const override;
|
||||
QPainterPath shape () const override;
|
||||
QPainterPath shadowShape() const override;
|
||||
QRectF boundingRect() const override;
|
||||
bool isUseless() const override;
|
||||
|
||||
void startUserTransformation(const QRectF &) override;
|
||||
void handleUserTransformation(const QRectF &, const QRectF &) override;
|
||||
void startUserTransformation(const QRectF &) override;
|
||||
void handleUserTransformation(const QRectF &, const QRectF &) override;
|
||||
|
||||
protected:
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||
protected:
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||
|
||||
private:
|
||||
void switchResizeMode();
|
||||
void adjusteHandlerPos();
|
||||
void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void sceneSelectionChanged ();
|
||||
|
||||
void addHandler();
|
||||
void removeHandler();
|
||||
|
||||
private:
|
||||
QRectF m_rect,
|
||||
m_old_rect;
|
||||
QList<QPointF> saved_points_;
|
||||
int m_resize_mode = 1,
|
||||
m_vector_index = -1;
|
||||
QVector<QetGraphicsHandlerItem *> m_handler_vector;
|
||||
qreal m_xRadius = 0,
|
||||
m_yRadius = 0,
|
||||
m_old_xRadius,
|
||||
m_old_yRadius;
|
||||
bool m_modifie_radius_equaly = false;
|
||||
private:
|
||||
void switchResizeMode();
|
||||
void adjusteHandlerPos();
|
||||
void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
|
||||
void sceneSelectionChanged ();
|
||||
|
||||
void addHandler();
|
||||
void removeHandler();
|
||||
|
||||
private:
|
||||
QRectF m_rect,
|
||||
m_old_rect;
|
||||
QList<QPointF> saved_points_;
|
||||
int m_resize_mode = 1,
|
||||
m_vector_index = -1;
|
||||
QVector<QetGraphicsHandlerItem *> m_handler_vector;
|
||||
qreal m_xRadius = 0,
|
||||
m_yRadius = 0,
|
||||
m_old_xRadius,
|
||||
m_old_yRadius;
|
||||
bool m_modifie_radius_equaly = false;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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.
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "partterminal.h"
|
||||
#include "terminal.h"
|
||||
|
||||
/**
|
||||
@brief PartTerminal::PartTerminal
|
||||
@param editor :
|
||||
L'editeur d'element concerne
|
||||
@param parent :
|
||||
Le QGraphicsItem parent de cette borne
|
||||
@brief PartTerminal::PartTerminal
|
||||
@param editor :
|
||||
L'editeur d'element concerne
|
||||
@param parent :
|
||||
Le QGraphicsItem parent de cette borne
|
||||
*/
|
||||
PartTerminal::PartTerminal(QETElementEditor *editor, QGraphicsItem *parent) :
|
||||
CustomElementGraphicPart(editor, parent)
|
||||
CustomElementGraphicPart(editor, parent)
|
||||
{
|
||||
d = new TerminalData(this);
|
||||
d -> m_orientation = Qet::North;
|
||||
d -> m_uuid = QUuid::createUuid(); // if part is loaded this uuid will be overwritten, but being sure that terminal has a uuid
|
||||
updateSecondPoint();
|
||||
setZValue(100000);
|
||||
d = new TerminalData(this);
|
||||
d -> m_orientation = Qet::North;
|
||||
d -> m_uuid = QUuid::createUuid(); // if part is loaded this uuid will be overwritten, but being sure that terminal has a uuid
|
||||
updateSecondPoint();
|
||||
setZValue(100000);
|
||||
}
|
||||
|
||||
/// Destructeur
|
||||
@@ -41,181 +41,181 @@ PartTerminal::~PartTerminal()
|
||||
}
|
||||
|
||||
/**
|
||||
Importe les proprietes d'une borne depuis un element XML
|
||||
@param xml_elmt Element XML a lire
|
||||
Importe les proprietes d'une borne depuis un element XML
|
||||
@param xml_elmt Element XML a lire
|
||||
*/
|
||||
void PartTerminal::fromXml(const QDomElement &xml_elmt) {
|
||||
d -> fromXml(xml_elmt);
|
||||
setPos(d -> m_pos);
|
||||
updateSecondPoint();
|
||||
d -> fromXml(xml_elmt);
|
||||
setPos(d -> m_pos);
|
||||
updateSecondPoint();
|
||||
}
|
||||
|
||||
/**
|
||||
Exporte la borne en XML
|
||||
@param xml_document Document XML a utiliser pour creer l'element XML
|
||||
@return un element XML decrivant la borne
|
||||
Exporte la borne en XML
|
||||
@param xml_document Document XML a utiliser pour creer l'element XML
|
||||
@return un element XML decrivant la borne
|
||||
*/
|
||||
const QDomElement PartTerminal::toXml(QDomDocument &xml_document) const
|
||||
{
|
||||
return d -> toXml(xml_document);
|
||||
return d -> toXml(xml_document);
|
||||
}
|
||||
|
||||
/**
|
||||
Dessine la borne
|
||||
@param painter QPainter a utiliser pour rendre le dessin
|
||||
@param options Options pour affiner le rendu
|
||||
@param widget Widget sur lequel le rendu est effectue
|
||||
Dessine la borne
|
||||
@param painter QPainter a utiliser pour rendre le dessin
|
||||
@param options Options pour affiner le rendu
|
||||
@param widget Widget sur lequel le rendu est effectue
|
||||
*/
|
||||
void PartTerminal::paint(
|
||||
QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *options,
|
||||
QWidget *widget)
|
||||
QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *options,
|
||||
QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(widget);
|
||||
painter -> save();
|
||||
Q_UNUSED(widget);
|
||||
painter -> save();
|
||||
|
||||
// annulation des renderhints
|
||||
painter -> setRenderHint(QPainter::Antialiasing, false);
|
||||
painter -> setRenderHint(QPainter::TextAntialiasing, false);
|
||||
painter -> setRenderHint(QPainter::SmoothPixmapTransform, false);
|
||||
// annulation des renderhints
|
||||
painter -> setRenderHint(QPainter::Antialiasing, false);
|
||||
painter -> setRenderHint(QPainter::TextAntialiasing, false);
|
||||
painter -> setRenderHint(QPainter::SmoothPixmapTransform, false);
|
||||
|
||||
QPen t;
|
||||
t.setWidthF(1.0);
|
||||
QPen t;
|
||||
t.setWidthF(1.0);
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
||||
t.setCosmetic(options && options -> levelOfDetail < 1.0);
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
||||
t.setCosmetic(options && options -> levelOfDetail < 1.0);
|
||||
#else
|
||||
#if TODO_LIST
|
||||
#pragma message("@TODO remove code for QT 6 or later")
|
||||
#endif
|
||||
t.setCosmetic(
|
||||
options
|
||||
&& options->levelOfDetailFromTransform(
|
||||
painter->worldTransform())
|
||||
< 1.0);
|
||||
t.setCosmetic(
|
||||
options
|
||||
&& options->levelOfDetailFromTransform(
|
||||
painter->worldTransform())
|
||||
< 1.0);
|
||||
#endif
|
||||
// dessin de la borne en rouge
|
||||
t.setColor(isSelected() ? Terminal::neutralColor : Qt::red);
|
||||
painter -> setPen(t);
|
||||
painter -> drawLine(QPointF(0.0, 0.0), d -> second_point);
|
||||
// dessin de la borne en rouge
|
||||
t.setColor(isSelected() ? Terminal::neutralColor : Qt::red);
|
||||
painter -> setPen(t);
|
||||
painter -> drawLine(QPointF(0.0, 0.0), d -> second_point);
|
||||
|
||||
// dessin du point d'amarrage au conducteur en bleu
|
||||
t.setColor(isSelected() ? Qt::red : Terminal::neutralColor);
|
||||
painter -> setPen(t);
|
||||
painter -> setBrush(Terminal::neutralColor);
|
||||
painter -> drawPoint(QPointF(0.0, 0.0));
|
||||
painter -> restore();
|
||||
// dessin du point d'amarrage au conducteur en bleu
|
||||
t.setColor(isSelected() ? Qt::red : Terminal::neutralColor);
|
||||
painter -> setPen(t);
|
||||
painter -> setBrush(Terminal::neutralColor);
|
||||
painter -> drawPoint(QPointF(0.0, 0.0));
|
||||
painter -> restore();
|
||||
|
||||
if (m_hovered)
|
||||
drawShadowShape(painter);
|
||||
if (m_hovered)
|
||||
drawShadowShape(painter);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartTerminal::shape
|
||||
@return the shape of this item
|
||||
@brief PartTerminal::shape
|
||||
@return the shape of this item
|
||||
*/
|
||||
QPainterPath PartTerminal::shape() const
|
||||
{
|
||||
QPainterPath shape;
|
||||
shape.lineTo(d -> second_point);
|
||||
QPainterPath shape;
|
||||
shape.lineTo(d -> second_point);
|
||||
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(1);
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(1);
|
||||
|
||||
return (pps.createStroke(shape));
|
||||
return (pps.createStroke(shape));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartTerminal::boundingRect
|
||||
@return the bounding rect of this item
|
||||
@brief PartTerminal::boundingRect
|
||||
@return the bounding rect of this item
|
||||
*/
|
||||
QRectF PartTerminal::boundingRect() const
|
||||
{
|
||||
QRectF br(QPointF(0, 0), d -> second_point);
|
||||
br = br.normalized();
|
||||
QRectF br(QPointF(0, 0), d -> second_point);
|
||||
br = br.normalized();
|
||||
|
||||
qreal adjust = (SHADOWS_HEIGHT + 1) / 2;
|
||||
br.adjust(-adjust, -adjust, adjust, adjust);
|
||||
return(br);
|
||||
qreal adjust = (SHADOWS_HEIGHT + 1) / 2;
|
||||
br.adjust(-adjust, -adjust, adjust, adjust);
|
||||
return(br);
|
||||
}
|
||||
|
||||
/**
|
||||
Definit l'orientation de la borne
|
||||
@param ori la nouvelle orientation de la borne
|
||||
Definit l'orientation de la borne
|
||||
@param ori la nouvelle orientation de la borne
|
||||
*/
|
||||
void PartTerminal::setOrientation(Qet::Orientation ori) {
|
||||
if (d -> m_orientation == ori) return;
|
||||
prepareGeometryChange();
|
||||
d -> m_orientation = ori;
|
||||
updateSecondPoint();
|
||||
emit orientationChanged();
|
||||
if (d -> m_orientation == ori) return;
|
||||
prepareGeometryChange();
|
||||
d -> m_orientation = ori;
|
||||
updateSecondPoint();
|
||||
emit orientationChanged();
|
||||
}
|
||||
/**
|
||||
@brief PartTerminal::setName
|
||||
@param name
|
||||
@brief PartTerminal::setName
|
||||
@param name
|
||||
*/
|
||||
void PartTerminal::setName(QString& name) {
|
||||
if (d -> m_name == name) return;
|
||||
d -> m_name = name;
|
||||
emit nameChanged();
|
||||
if (d -> m_name == name) return;
|
||||
d -> m_name = name;
|
||||
emit nameChanged();
|
||||
}
|
||||
|
||||
void PartTerminal::setNewUuid()
|
||||
{
|
||||
d -> m_uuid = QUuid::createUuid();
|
||||
d -> m_uuid = QUuid::createUuid();
|
||||
}
|
||||
|
||||
/**
|
||||
Met a jour la position du second point en fonction de la position et de
|
||||
l'orientation de la borne.
|
||||
Met a jour la position du second point en fonction de la position et de
|
||||
l'orientation de la borne.
|
||||
*/
|
||||
void PartTerminal::updateSecondPoint()
|
||||
{
|
||||
qreal ts = 4.0; // terminal size
|
||||
switch(d -> m_orientation) {
|
||||
case Qet::North: d -> second_point = QPointF(0.0, ts); break;
|
||||
case Qet::East : d -> second_point = QPointF(-ts, 0.0); break;
|
||||
case Qet::South: d -> second_point = QPointF(0.0, -ts); break;
|
||||
case Qet::West : d -> second_point = QPointF(ts, 0.0); break;
|
||||
}
|
||||
qreal ts = 4.0; // terminal size
|
||||
switch(d -> m_orientation) {
|
||||
case Qet::North: d -> second_point = QPointF(0.0, ts); break;
|
||||
case Qet::East : d -> second_point = QPointF(-ts, 0.0); break;
|
||||
case Qet::South: d -> second_point = QPointF(0.0, -ts); break;
|
||||
case Qet::West : d -> second_point = QPointF(ts, 0.0); break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@return true si cette partie n'est pas pertinente et ne merite pas d'etre
|
||||
conservee / enregistree.
|
||||
Une borne est toujours pertinente ; cette fonction renvoie donc
|
||||
toujours false
|
||||
@return true si cette partie n'est pas pertinente et ne merite pas d'etre
|
||||
conservee / enregistree.
|
||||
Une borne est toujours pertinente ; cette fonction renvoie donc
|
||||
toujours false
|
||||
*/
|
||||
bool PartTerminal::isUseless() const
|
||||
{
|
||||
return(false);
|
||||
return(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@return the minimum, margin-less rectangle this part can fit into, in scene
|
||||
coordinates. It is different from boundingRect() because it is not supposed
|
||||
to imply any margin, and it is different from shape because it is a regular
|
||||
rectangle, not a complex shape.
|
||||
@return the minimum, margin-less rectangle this part can fit into, in scene
|
||||
coordinates. It is different from boundingRect() because it is not supposed
|
||||
to imply any margin, and it is different from shape because it is a regular
|
||||
rectangle, not a complex shape.
|
||||
*/
|
||||
QRectF PartTerminal::sceneGeometricRect() const
|
||||
{
|
||||
return(sceneBoundingRect());
|
||||
return(sceneBoundingRect());
|
||||
}
|
||||
|
||||
/**
|
||||
Start the user-induced transformation, provided this primitive is contained
|
||||
within the \a initial_selection_rect bounding rectangle.
|
||||
Start the user-induced transformation, provided this primitive is contained
|
||||
within the \a initial_selection_rect bounding rectangle.
|
||||
*/
|
||||
void PartTerminal::startUserTransformation(const QRectF &initial_selection_rect) {
|
||||
Q_UNUSED(initial_selection_rect)
|
||||
saved_position_ = scenePos();
|
||||
Q_UNUSED(initial_selection_rect)
|
||||
saved_position_ = scenePos();
|
||||
}
|
||||
|
||||
/**
|
||||
Handle the user-induced transformation from \a initial_selection_rect to \a new_selection_rect
|
||||
Handle the user-induced transformation from \a initial_selection_rect to \a new_selection_rect
|
||||
*/
|
||||
void PartTerminal::handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect) {
|
||||
QPointF mapped_point = mapPoints(
|
||||
initial_selection_rect, new_selection_rect, QList<QPointF>() << saved_position_).first();
|
||||
setPos(mapped_point);
|
||||
QPointF mapped_point = mapPoints(
|
||||
initial_selection_rect, new_selection_rect, QList<QPointF>() << saved_position_).first();
|
||||
setPos(mapped_point);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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.
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef PART_TERMINAL_H
|
||||
#define PART_TERMINAL_H
|
||||
@@ -24,61 +24,61 @@
|
||||
|
||||
|
||||
/**
|
||||
This class represents a terminal which may be used to compose the drawing of
|
||||
an electrical element within the element editor.
|
||||
This class represents a terminal which may be used to compose the drawing of
|
||||
an electrical element within the element editor.
|
||||
*/
|
||||
class PartTerminal : public CustomElementGraphicPart {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(Qet::Orientation orientation READ orientation WRITE setOrientation)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(Qet::Orientation orientation READ orientation WRITE setOrientation)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
|
||||
public:
|
||||
// constructors, destructor
|
||||
PartTerminal(QETElementEditor *editor, QGraphicsItem *parent = nullptr);
|
||||
~PartTerminal() override;
|
||||
private:
|
||||
PartTerminal(const PartTerminal &);
|
||||
public:
|
||||
// constructors, destructor
|
||||
PartTerminal(QETElementEditor *editor, QGraphicsItem *parent = nullptr);
|
||||
~PartTerminal() override;
|
||||
private:
|
||||
PartTerminal(const PartTerminal &);
|
||||
|
||||
signals:
|
||||
void orientationChanged();
|
||||
void nameChanged();
|
||||
signals:
|
||||
void orientationChanged();
|
||||
void nameChanged();
|
||||
|
||||
// methods
|
||||
public:
|
||||
enum { Type = UserType + 1106 };
|
||||
/**
|
||||
Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a PartTerminal.
|
||||
@return the QGraphicsItem type
|
||||
*/
|
||||
int type() const override { return Type; }
|
||||
QString name() const override { return d -> m_name; }
|
||||
QString xmlName() const override { return(QString("terminal")); }
|
||||
void fromXml(const QDomElement &) override;
|
||||
const QDomElement toXml(QDomDocument &) const override;
|
||||
void paint(
|
||||
QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *,
|
||||
QWidget *) override;
|
||||
// methods
|
||||
public:
|
||||
enum { Type = UserType + 1106 };
|
||||
/**
|
||||
Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a PartTerminal.
|
||||
@return the QGraphicsItem type
|
||||
*/
|
||||
int type() const override { return Type; }
|
||||
QString name() const override { return d -> m_name; }
|
||||
QString xmlName() const override { return(QString("terminal")); }
|
||||
void fromXml(const QDomElement &) override;
|
||||
const QDomElement toXml(QDomDocument &) const override;
|
||||
void paint(
|
||||
QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *,
|
||||
QWidget *) override;
|
||||
|
||||
QPainterPath shape() const override;
|
||||
QPainterPath shadowShape() const override {return shape();}
|
||||
QRectF boundingRect() const override;
|
||||
bool isUseless() const override;
|
||||
QRectF sceneGeometricRect() const override;
|
||||
void startUserTransformation(const QRectF &) override;
|
||||
void handleUserTransformation(const QRectF &, const QRectF &) override;
|
||||
QPainterPath shape() const override;
|
||||
QPainterPath shadowShape() const override {return shape();}
|
||||
QRectF boundingRect() const override;
|
||||
bool isUseless() const override;
|
||||
QRectF sceneGeometricRect() const override;
|
||||
void startUserTransformation(const QRectF &) override;
|
||||
void handleUserTransformation(const QRectF &, const QRectF &) override;
|
||||
|
||||
Qet::Orientation orientation() const {return d -> m_orientation;}
|
||||
void setOrientation(Qet::Orientation ori);
|
||||
Qet::Orientation orientation() const {return d -> m_orientation;}
|
||||
void setOrientation(Qet::Orientation ori);
|
||||
|
||||
void setName(QString& name);
|
||||
void setNewUuid();
|
||||
void setName(QString& name);
|
||||
void setNewUuid();
|
||||
|
||||
private:
|
||||
void updateSecondPoint();
|
||||
TerminalData* d; // pointer to the terminal data
|
||||
private:
|
||||
void updateSecondPoint();
|
||||
TerminalData* d; // pointer to the terminal data
|
||||
|
||||
private:
|
||||
QPointF saved_position_;
|
||||
private:
|
||||
QPointF saved_position_;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "parttext.h"
|
||||
#include "texteditor.h"
|
||||
@@ -23,38 +23,38 @@
|
||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@param editor L'editeur d'element concerne
|
||||
@param parent Le QGraphicsItem parent de ce texte statique
|
||||
Constructeur
|
||||
@param editor L'editeur d'element concerne
|
||||
@param parent Le QGraphicsItem parent de ce texte statique
|
||||
*/
|
||||
PartText::PartText(QETElementEditor *editor, QGraphicsItem *parent) :
|
||||
QGraphicsTextItem(parent),
|
||||
CustomElementPart(editor),
|
||||
previous_text()
|
||||
QGraphicsTextItem(parent),
|
||||
CustomElementPart(editor),
|
||||
previous_text()
|
||||
{
|
||||
document() -> setDocumentMargin(1.0);
|
||||
setDefaultTextColor(Qt::black);
|
||||
setFont(QETApp::diagramTextsFont());
|
||||
real_font_size_ = font().pointSize();
|
||||
setFlags(QGraphicsItem::ItemIsSelectable
|
||||
| QGraphicsItem::ItemSendsGeometryChanges
|
||||
| QGraphicsItem::ItemIsMovable);
|
||||
setAcceptHoverEvents(true);
|
||||
setDefaultTextColor(Qt::black);
|
||||
setPlainText(QObject::tr(
|
||||
"T",
|
||||
"default text when adding a text in the element editor"));
|
||||
document() -> setDocumentMargin(1.0);
|
||||
setDefaultTextColor(Qt::black);
|
||||
setFont(QETApp::diagramTextsFont());
|
||||
real_font_size_ = font().pointSize();
|
||||
setFlags(QGraphicsItem::ItemIsSelectable
|
||||
| QGraphicsItem::ItemSendsGeometryChanges
|
||||
| QGraphicsItem::ItemIsMovable);
|
||||
setAcceptHoverEvents(true);
|
||||
setDefaultTextColor(Qt::black);
|
||||
setPlainText(QObject::tr(
|
||||
"T",
|
||||
"default text when adding a text in the element editor"));
|
||||
|
||||
adjustItemPosition(1);
|
||||
// adjust textfield position after line additions/deletions
|
||||
connect(document(),
|
||||
SIGNAL(blockCountChanged(int)),
|
||||
this,
|
||||
SLOT(adjustItemPosition(int)));
|
||||
connect(document(),
|
||||
SIGNAL(contentsChanged()),
|
||||
this,
|
||||
SLOT(adjustItemPosition()));
|
||||
adjustItemPosition(1);
|
||||
// adjust textfield position after line additions/deletions
|
||||
connect(document(),
|
||||
SIGNAL(blockCountChanged(int)),
|
||||
this,
|
||||
SLOT(adjustItemPosition(int)));
|
||||
connect(document(),
|
||||
SIGNAL(contentsChanged()),
|
||||
this,
|
||||
SLOT(adjustItemPosition()));
|
||||
}
|
||||
|
||||
/// Destructeur
|
||||
@@ -63,303 +63,303 @@ PartText::~PartText()
|
||||
}
|
||||
|
||||
/**
|
||||
Importe les proprietes d'un texte statique depuis un element XML
|
||||
@param xml_element Element XML a lire
|
||||
Importe les proprietes d'un texte statique depuis un element XML
|
||||
@param xml_element Element XML a lire
|
||||
*/
|
||||
void PartText::fromXml(const QDomElement &xml_element) {
|
||||
bool ok;
|
||||
bool ok;
|
||||
|
||||
if (xml_element.hasAttribute("size")) {
|
||||
int font_size = xml_element.attribute("size").toInt(&ok);
|
||||
if (!ok || font_size < 1) {
|
||||
font_size = 20;
|
||||
}
|
||||
QFont font_ = this -> font();
|
||||
font_.setPointSize(font_size);
|
||||
setFont(font_);
|
||||
}
|
||||
else if (xml_element.hasAttribute("font")) {
|
||||
QFont font_;
|
||||
font_.fromString(xml_element.attribute("font"));
|
||||
setFont(font_);
|
||||
}
|
||||
if (xml_element.hasAttribute("size")) {
|
||||
int font_size = xml_element.attribute("size").toInt(&ok);
|
||||
if (!ok || font_size < 1) {
|
||||
font_size = 20;
|
||||
}
|
||||
QFont font_ = this -> font();
|
||||
font_.setPointSize(font_size);
|
||||
setFont(font_);
|
||||
}
|
||||
else if (xml_element.hasAttribute("font")) {
|
||||
QFont font_;
|
||||
font_.fromString(xml_element.attribute("font"));
|
||||
setFont(font_);
|
||||
}
|
||||
|
||||
setDefaultTextColor(QColor(xml_element.attribute("color", "#000000")));
|
||||
setPlainText(xml_element.attribute("text"));
|
||||
setPos(xml_element.attribute("x").toDouble(),
|
||||
xml_element.attribute("y").toDouble());
|
||||
setRotation(xml_element.attribute("rotation", QString::number(0)).toDouble());
|
||||
setDefaultTextColor(QColor(xml_element.attribute("color", "#000000")));
|
||||
setPlainText(xml_element.attribute("text"));
|
||||
setPos(xml_element.attribute("x").toDouble(),
|
||||
xml_element.attribute("y").toDouble());
|
||||
setRotation(xml_element.attribute("rotation", QString::number(0)).toDouble());
|
||||
}
|
||||
|
||||
/**
|
||||
Exporte le texte statique en XML
|
||||
@param xml_document Document XML a utiliser pour creer l'element XML
|
||||
@return un element XML decrivant le texte statique
|
||||
Exporte le texte statique en XML
|
||||
@param xml_document Document XML a utiliser pour creer l'element XML
|
||||
@return un element XML decrivant le texte statique
|
||||
*/
|
||||
const QDomElement PartText::toXml(QDomDocument &xml_document) const
|
||||
{
|
||||
QDomElement xml_element = xml_document.createElement(xmlName());
|
||||
QDomElement xml_element = xml_document.createElement(xmlName());
|
||||
|
||||
xml_element.setAttribute("x", QString::number(pos().x()));
|
||||
xml_element.setAttribute("y", QString::number(pos().y()));
|
||||
xml_element.setAttribute("text", toPlainText());
|
||||
xml_element.setAttribute("font", font().toString());
|
||||
xml_element.setAttribute("rotation", QString::number(rotation()));
|
||||
xml_element.setAttribute("color", defaultTextColor().name());
|
||||
xml_element.setAttribute("x", QString::number(pos().x()));
|
||||
xml_element.setAttribute("y", QString::number(pos().y()));
|
||||
xml_element.setAttribute("text", toPlainText());
|
||||
xml_element.setAttribute("font", font().toString());
|
||||
xml_element.setAttribute("rotation", QString::number(rotation()));
|
||||
xml_element.setAttribute("color", defaultTextColor().name());
|
||||
|
||||
return(xml_element);
|
||||
return(xml_element);
|
||||
}
|
||||
|
||||
/**
|
||||
@return Les coordonnees du point situe en bas a gauche du texte.
|
||||
@return Les coordonnees du point situe en bas a gauche du texte.
|
||||
*/
|
||||
QPointF PartText::margin() const
|
||||
{
|
||||
QFont used_font = font();
|
||||
QFontMetrics qfm(used_font);
|
||||
qreal document_margin = document() -> documentMargin();
|
||||
QFont used_font = font();
|
||||
QFontMetrics qfm(used_font);
|
||||
qreal document_margin = document() -> documentMargin();
|
||||
|
||||
QPointF margin(
|
||||
// marge autour du texte
|
||||
document_margin,
|
||||
// marge au-dessus du texte + distance entre le plafond du texte et la baseline
|
||||
document_margin + qfm.ascent()
|
||||
);
|
||||
return(margin);
|
||||
QPointF margin(
|
||||
// marge autour du texte
|
||||
document_margin,
|
||||
// marge au-dessus du texte + distance entre le plafond du texte et la baseline
|
||||
document_margin + qfm.ascent()
|
||||
);
|
||||
return(margin);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartText::focusInEvent
|
||||
@param e : The QFocusEvent object describing the focus gain.
|
||||
Start text edition when the item gains focus.
|
||||
@see QGraphicsItem::focusInEvent(QFocusEvent *)
|
||||
@brief PartText::focusInEvent
|
||||
@param e : The QFocusEvent object describing the focus gain.
|
||||
Start text edition when the item gains focus.
|
||||
@see QGraphicsItem::focusInEvent(QFocusEvent *)
|
||||
*/
|
||||
void PartText::focusInEvent(QFocusEvent *e) {
|
||||
startEdition();
|
||||
QGraphicsTextItem::focusInEvent(e);
|
||||
startEdition();
|
||||
QGraphicsTextItem::focusInEvent(e);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartText::focusOutEvent
|
||||
@param e : The QFocusEvent object describing the focus loss.
|
||||
End text edition when the item loses focus.
|
||||
@see QGraphicsItem::focusOutEvent(QFocusEvent *)
|
||||
@brief PartText::focusOutEvent
|
||||
@param e : The QFocusEvent object describing the focus loss.
|
||||
End text edition when the item loses focus.
|
||||
@see QGraphicsItem::focusOutEvent(QFocusEvent *)
|
||||
*/
|
||||
void PartText::focusOutEvent(QFocusEvent *e) {
|
||||
QGraphicsTextItem::focusOutEvent(e);
|
||||
endEdition();
|
||||
QGraphicsTextItem::focusOutEvent(e);
|
||||
endEdition();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartText::keyPressEvent
|
||||
Used to handle the escape key when the event is delivered to the field,
|
||||
not to the decorator.
|
||||
@param event
|
||||
@see QGraphicsTextItem::keyPressEvent()
|
||||
@brief PartText::keyPressEvent
|
||||
Used to handle the escape key when the event is delivered to the field,
|
||||
not to the decorator.
|
||||
@param event
|
||||
@see QGraphicsTextItem::keyPressEvent()
|
||||
*/
|
||||
void PartText::keyPressEvent(QKeyEvent *event) {
|
||||
if (event -> key() == Qt::Key_Escape) {
|
||||
endEdition();
|
||||
}
|
||||
else {
|
||||
QGraphicsTextItem::keyPressEvent(event);
|
||||
}
|
||||
if (event -> key() == Qt::Key_Escape) {
|
||||
endEdition();
|
||||
}
|
||||
else {
|
||||
QGraphicsTextItem::keyPressEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Permet a l'element texte de devenir editable lorsqu'on double-clique dessus
|
||||
@param e Le QGraphicsSceneMouseEvent qui decrit le double-clic
|
||||
Permet a l'element texte de devenir editable lorsqu'on double-clique dessus
|
||||
@param e Le QGraphicsSceneMouseEvent qui decrit le double-clic
|
||||
*/
|
||||
void PartText::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) {
|
||||
QGraphicsTextItem::mouseDoubleClickEvent(e);
|
||||
if (e -> button() == Qt::LeftButton) {
|
||||
setEditable(true);
|
||||
}
|
||||
QGraphicsTextItem::mouseDoubleClickEvent(e);
|
||||
if (e -> button() == Qt::LeftButton) {
|
||||
setEditable(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Gere les changements intervenant sur cette partie
|
||||
@param change Type de changement
|
||||
@param value Valeur numerique relative au changement
|
||||
Gere les changements intervenant sur cette partie
|
||||
@param change Type de changement
|
||||
@param value Valeur numerique relative au changement
|
||||
*/
|
||||
QVariant PartText::itemChange(GraphicsItemChange change, const QVariant &value) {
|
||||
if (change == QGraphicsItem::ItemPositionHasChanged ||
|
||||
change == QGraphicsItem::ItemSceneHasChanged ||
|
||||
change == QGraphicsItem::ItemSelectedHasChanged) {
|
||||
updateCurrentPartEditor();
|
||||
}
|
||||
return(QGraphicsTextItem::itemChange(change, value));
|
||||
if (change == QGraphicsItem::ItemPositionHasChanged ||
|
||||
change == QGraphicsItem::ItemSceneHasChanged ||
|
||||
change == QGraphicsItem::ItemSelectedHasChanged) {
|
||||
updateCurrentPartEditor();
|
||||
}
|
||||
return(QGraphicsTextItem::itemChange(change, value));
|
||||
}
|
||||
|
||||
/**
|
||||
@return le rectangle delimitant cette partie.
|
||||
@return le rectangle delimitant cette partie.
|
||||
*/
|
||||
QRectF PartText::boundingRect() const
|
||||
{
|
||||
QRectF r = QGraphicsTextItem::boundingRect();
|
||||
r.adjust(0.0, -1.1, 0.0, 0.0);
|
||||
return(r);
|
||||
QRectF r = QGraphicsTextItem::boundingRect();
|
||||
r.adjust(0.0, -1.1, 0.0, 0.0);
|
||||
return(r);
|
||||
}
|
||||
|
||||
/**
|
||||
@return true si cette partie n'est pas pertinente et ne merite pas d'etre
|
||||
conservee / enregistree.
|
||||
Un texte statique n'est pas pertinent lorsque son texte est vide.
|
||||
@return true si cette partie n'est pas pertinente et ne merite pas d'etre
|
||||
conservee / enregistree.
|
||||
Un texte statique n'est pas pertinent lorsque son texte est vide.
|
||||
*/
|
||||
bool PartText::isUseless() const
|
||||
{
|
||||
return(toPlainText().isEmpty());
|
||||
return(toPlainText().isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@return the minimum, margin-less rectangle this part can fit into, in scene
|
||||
coordinates. It is different from boundingRect() because it is not supposed
|
||||
to imply any margin, and it is different from shape because it is a regular
|
||||
rectangle, not a complex shape.
|
||||
@return the minimum, margin-less rectangle this part can fit into, in scene
|
||||
coordinates. It is different from boundingRect() because it is not supposed
|
||||
to imply any margin, and it is different from shape because it is a regular
|
||||
rectangle, not a complex shape.
|
||||
*/
|
||||
QRectF PartText::sceneGeometricRect() const
|
||||
{
|
||||
return(sceneBoundingRect());
|
||||
return(sceneBoundingRect());
|
||||
}
|
||||
|
||||
/**
|
||||
Start the user-induced transformation, provided this primitive is contained
|
||||
within the \a rect bounding rectangle.
|
||||
Start the user-induced transformation, provided this primitive is contained
|
||||
within the \a rect bounding rectangle.
|
||||
*/
|
||||
void PartText::startUserTransformation(const QRectF &rect) {
|
||||
Q_UNUSED(rect)
|
||||
saved_point_ = pos(); // scene coordinates, no need to mapFromScene()
|
||||
saved_font_size_ = real_font_size_;
|
||||
Q_UNUSED(rect)
|
||||
saved_point_ = pos(); // scene coordinates, no need to mapFromScene()
|
||||
saved_font_size_ = real_font_size_;
|
||||
}
|
||||
|
||||
/**
|
||||
Handle the user-induced transformation from \a initial_selection_rect to \a new_selection_rect
|
||||
Handle the user-induced transformation from \a initial_selection_rect to \a new_selection_rect
|
||||
*/
|
||||
void PartText::handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect) {
|
||||
// let's try the naive approach
|
||||
QPointF new_pos = mapPoints(initial_selection_rect, new_selection_rect, QList<QPointF>() << saved_point_).first();
|
||||
setPos(new_pos);
|
||||
// let's try the naive approach
|
||||
QPointF new_pos = mapPoints(initial_selection_rect, new_selection_rect, QList<QPointF>() << saved_point_).first();
|
||||
setPos(new_pos);
|
||||
|
||||
// adjust the font size following the vertical scale factor
|
||||
qreal sy = new_selection_rect.height() / initial_selection_rect.height();
|
||||
qreal new_font_size = saved_font_size_ * sy;
|
||||
setProperty("real_size", qMax(1, qRound(new_font_size)));
|
||||
// adjust the font size following the vertical scale factor
|
||||
qreal sy = new_selection_rect.height() / initial_selection_rect.height();
|
||||
qreal new_font_size = saved_font_size_ * sy;
|
||||
setProperty("real_size", qMax(1, qRound(new_font_size)));
|
||||
}
|
||||
|
||||
void PartText::setDefaultTextColor(const QColor &color) {
|
||||
if (color != this -> defaultTextColor()) {
|
||||
QGraphicsTextItem::setDefaultTextColor(color);
|
||||
emit colorChanged(color);
|
||||
}
|
||||
if (color != this -> defaultTextColor()) {
|
||||
QGraphicsTextItem::setDefaultTextColor(color);
|
||||
emit colorChanged(color);
|
||||
}
|
||||
}
|
||||
|
||||
void PartText::setPlainText(const QString &text) {
|
||||
if (text != this -> toPlainText()) {
|
||||
QGraphicsTextItem::setPlainText(text);
|
||||
emit plainTextChanged(text);
|
||||
}
|
||||
if (text != this -> toPlainText()) {
|
||||
QGraphicsTextItem::setPlainText(text);
|
||||
emit plainTextChanged(text);
|
||||
}
|
||||
}
|
||||
|
||||
void PartText::setFont(const QFont &font) {
|
||||
if (font != this -> font()) {
|
||||
QGraphicsTextItem::setFont(font);
|
||||
emit fontChanged(font);
|
||||
}
|
||||
if (font != this -> font()) {
|
||||
QGraphicsTextItem::setFont(font);
|
||||
emit fontChanged(font);
|
||||
}
|
||||
}
|
||||
|
||||
void PartText::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if((event -> buttons() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable)) {
|
||||
QPointF pos = event -> scenePos() + (m_origine_pos - event -> buttonDownScenePos(Qt::LeftButton));
|
||||
event -> modifiers() == Qt::ControlModifier ? setPos(pos) : setPos(elementScene() -> snapToGrid(pos));
|
||||
}
|
||||
else {
|
||||
QGraphicsObject::mouseMoveEvent(event);
|
||||
}
|
||||
if((event -> buttons() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable)) {
|
||||
QPointF pos = event -> scenePos() + (m_origine_pos - event -> buttonDownScenePos(Qt::LeftButton));
|
||||
event -> modifiers() == Qt::ControlModifier ? setPos(pos) : setPos(elementScene() -> snapToGrid(pos));
|
||||
}
|
||||
else {
|
||||
QGraphicsObject::mouseMoveEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void PartText::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if(event -> button() == Qt::LeftButton)
|
||||
m_origine_pos = this -> pos();
|
||||
if(event -> button() == Qt::LeftButton)
|
||||
m_origine_pos = this -> pos();
|
||||
|
||||
QGraphicsObject::mousePressEvent(event);
|
||||
QGraphicsObject::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void PartText::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if((event -> button() & Qt::LeftButton) &&
|
||||
(flags() & QGraphicsItem::ItemIsMovable) &&
|
||||
m_origine_pos != pos())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(this, "pos", QVariant(m_origine_pos), QVariant(pos()));
|
||||
undo -> setText(tr("Déplacer un texte"));
|
||||
undo -> enableAnimation();
|
||||
elementScene() -> undoStack().push(undo);
|
||||
}
|
||||
if((event -> button() & Qt::LeftButton) &&
|
||||
(flags() & QGraphicsItem::ItemIsMovable) &&
|
||||
m_origine_pos != pos())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(this, "pos", QVariant(m_origine_pos), QVariant(pos()));
|
||||
undo -> setText(tr("Déplacer un texte"));
|
||||
undo -> enableAnimation();
|
||||
elementScene() -> undoStack().push(undo);
|
||||
}
|
||||
|
||||
QGraphicsObject::mouseReleaseEvent(event);
|
||||
QGraphicsObject::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
Cette methode s'assure que la position du champ de texte est coherente
|
||||
en repositionnant son origine (c-a-d le milieu du bord gauche du champ de
|
||||
texte) a la position originale. Cela est notamment utile lorsque le champ
|
||||
de texte est agrandi ou retreci verticalement (ajout ou retrait de lignes).
|
||||
@param new_block_count Nombre de blocs dans le PartText
|
||||
Cette methode s'assure que la position du champ de texte est coherente
|
||||
en repositionnant son origine (c-a-d le milieu du bord gauche du champ de
|
||||
texte) a la position originale. Cela est notamment utile lorsque le champ
|
||||
de texte est agrandi ou retreci verticalement (ajout ou retrait de lignes).
|
||||
@param new_block_count Nombre de blocs dans le PartText
|
||||
*/
|
||||
void PartText::adjustItemPosition(int new_block_count) {
|
||||
Q_UNUSED(new_block_count);
|
||||
QPointF origin_offset = margin();
|
||||
Q_UNUSED(new_block_count);
|
||||
QPointF origin_offset = margin();
|
||||
|
||||
QTransform base_translation;
|
||||
base_translation.translate(-origin_offset.x(), -origin_offset.y());
|
||||
setTransform(base_translation, false);
|
||||
setTransformOriginPoint(origin_offset);
|
||||
QTransform base_translation;
|
||||
base_translation.translate(-origin_offset.x(), -origin_offset.y());
|
||||
setTransform(base_translation, false);
|
||||
setTransformOriginPoint(origin_offset);
|
||||
}
|
||||
|
||||
/**
|
||||
@param editable Whether this text item should be interactively editable.
|
||||
@param editable Whether this text item should be interactively editable.
|
||||
*/
|
||||
void PartText::setEditable(bool editable) {
|
||||
if (editable) {
|
||||
setFlag(QGraphicsItem::ItemIsFocusable, true);
|
||||
setTextInteractionFlags(Qt::TextEditorInteraction);
|
||||
setFocus(Qt::MouseFocusReason);
|
||||
}
|
||||
else {
|
||||
setTextInteractionFlags(Qt::NoTextInteraction);
|
||||
setFlag(QGraphicsItem::ItemIsFocusable, false);
|
||||
}
|
||||
if (editable) {
|
||||
setFlag(QGraphicsItem::ItemIsFocusable, true);
|
||||
setTextInteractionFlags(Qt::TextEditorInteraction);
|
||||
setFocus(Qt::MouseFocusReason);
|
||||
}
|
||||
else {
|
||||
setTextInteractionFlags(Qt::NoTextInteraction);
|
||||
setFlag(QGraphicsItem::ItemIsFocusable, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Start text edition by storing the former value of the text.
|
||||
Start text edition by storing the former value of the text.
|
||||
*/
|
||||
void PartText::startEdition()
|
||||
{
|
||||
// !previous_text.isNull() means the text is being edited
|
||||
previous_text = toPlainText();
|
||||
// !previous_text.isNull() means the text is being edited
|
||||
previous_text = toPlainText();
|
||||
}
|
||||
|
||||
/**
|
||||
End text edition, potentially generating a ChangePartCommand if the text
|
||||
has changed.
|
||||
End text edition, potentially generating a ChangePartCommand if the text
|
||||
has changed.
|
||||
*/
|
||||
void PartText::endEdition()
|
||||
{
|
||||
if (!previous_text.isNull()) {
|
||||
// the text was being edited
|
||||
QString new_text = toPlainText();
|
||||
if (previous_text != new_text) {
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(this, "text", previous_text, new_text);
|
||||
undo -> setText(tr("Modifier un champ texte"));
|
||||
undoStack().push(undo);
|
||||
previous_text = QString();
|
||||
}
|
||||
}
|
||||
if (!previous_text.isNull()) {
|
||||
// the text was being edited
|
||||
QString new_text = toPlainText();
|
||||
if (previous_text != new_text) {
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(this, "text", previous_text, new_text);
|
||||
undo -> setText(tr("Modifier un champ texte"));
|
||||
undoStack().push(undo);
|
||||
previous_text = QString();
|
||||
}
|
||||
}
|
||||
|
||||
// deselectionne le texte
|
||||
QTextCursor qtc = textCursor();
|
||||
qtc.clearSelection();
|
||||
setTextCursor(qtc);
|
||||
// deselectionne le texte
|
||||
QTextCursor qtc = textCursor();
|
||||
qtc.clearSelection();
|
||||
setTextCursor(qtc);
|
||||
|
||||
setEditable(false);
|
||||
setEditable(false);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef PART_TEXT_H
|
||||
#define PART_TEXT_H
|
||||
@@ -24,81 +24,81 @@
|
||||
class TextEditor;
|
||||
class ElementPrimitiveDecorator;
|
||||
/**
|
||||
This class represents an static text primitive which may be used to compose
|
||||
the drawing of an electrical element within the element editor.
|
||||
This class represents an static text primitive which may be used to compose
|
||||
the drawing of an electrical element within the element editor.
|
||||
*/
|
||||
class PartText : public QGraphicsTextItem, public CustomElementPart {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(qreal real_size READ realSize WRITE setRealSize)
|
||||
Q_PROPERTY(QColor color READ defaultTextColor WRITE setDefaultTextColor NOTIFY colorChanged)
|
||||
Q_PROPERTY(QString text READ toPlainText WRITE setPlainText NOTIFY plainTextChanged)
|
||||
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(qreal real_size READ realSize WRITE setRealSize)
|
||||
Q_PROPERTY(QColor color READ defaultTextColor WRITE setDefaultTextColor NOTIFY colorChanged)
|
||||
Q_PROPERTY(QString text READ toPlainText WRITE setPlainText NOTIFY plainTextChanged)
|
||||
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
|
||||
|
||||
signals:
|
||||
void fontChanged(const QFont &font);
|
||||
void colorChanged(const QColor &color);
|
||||
void plainTextChanged(const QString &text);
|
||||
signals:
|
||||
void fontChanged(const QFont &font);
|
||||
void colorChanged(const QColor &color);
|
||||
void plainTextChanged(const QString &text);
|
||||
|
||||
// constructors, destructor
|
||||
public:
|
||||
PartText(QETElementEditor *, QGraphicsItem * = nullptr);
|
||||
~PartText() override;
|
||||
// constructors, destructor
|
||||
public:
|
||||
PartText(QETElementEditor *, QGraphicsItem * = nullptr);
|
||||
~PartText() override;
|
||||
|
||||
private:
|
||||
PartText(const PartText &);
|
||||
private:
|
||||
PartText(const PartText &);
|
||||
|
||||
// methods
|
||||
public:
|
||||
enum { Type = UserType + 1107 };
|
||||
/**
|
||||
Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a
|
||||
PartText.
|
||||
@return the QGraphicsItem type
|
||||
*/
|
||||
int type() const override { return Type; }
|
||||
QString name() const override { return(QObject::tr("texte", "element part name")); }
|
||||
QString xmlName() const override { return(QString("text")); }
|
||||
void fromXml(const QDomElement &) override;
|
||||
const QDomElement toXml(QDomDocument &) const override;
|
||||
void setRotation(qreal angle) {(QGraphicsObject::setRotation(QET::correctAngle(angle)));}
|
||||
bool isUseless() const override;
|
||||
QRectF sceneGeometricRect() const override;
|
||||
void startUserTransformation(const QRectF &) override;
|
||||
void handleUserTransformation(const QRectF &, const QRectF &) override;
|
||||
// methods
|
||||
public:
|
||||
enum { Type = UserType + 1107 };
|
||||
/**
|
||||
Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a
|
||||
PartText.
|
||||
@return the QGraphicsItem type
|
||||
*/
|
||||
int type() const override { return Type; }
|
||||
QString name() const override { return(QObject::tr("texte", "element part name")); }
|
||||
QString xmlName() const override { return(QString("text")); }
|
||||
void fromXml(const QDomElement &) override;
|
||||
const QDomElement toXml(QDomDocument &) const override;
|
||||
void setRotation(qreal angle) {(QGraphicsObject::setRotation(QET::correctAngle(angle)));}
|
||||
bool isUseless() const override;
|
||||
QRectF sceneGeometricRect() const override;
|
||||
void startUserTransformation(const QRectF &) override;
|
||||
void handleUserTransformation(const QRectF &, const QRectF &) override;
|
||||
|
||||
void setProperty(const char *name, const QVariant &value) override {QGraphicsTextItem::setProperty(name, value);}
|
||||
QVariant property(const char *name) const override {return QGraphicsTextItem::property(name);}
|
||||
void setProperty(const char *name, const QVariant &value) override {QGraphicsTextItem::setProperty(name, value);}
|
||||
QVariant property(const char *name) const override {return QGraphicsTextItem::property(name);}
|
||||
|
||||
qreal realSize() const {return real_font_size_;}
|
||||
void setRealSize(qreal rs) {real_font_size_ = rs;}
|
||||
void setDefaultTextColor(const QColor &color);
|
||||
void setPlainText(const QString &text);
|
||||
void setFont(const QFont &font);
|
||||
qreal realSize() const {return real_font_size_;}
|
||||
void setRealSize(qreal rs) {real_font_size_ = rs;}
|
||||
void setDefaultTextColor(const QColor &color);
|
||||
void setPlainText(const QString &text);
|
||||
void setFont(const QFont &font);
|
||||
|
||||
public slots:
|
||||
void adjustItemPosition(int = 0);
|
||||
void setEditable(bool);
|
||||
void startEdition();
|
||||
void endEdition();
|
||||
public slots:
|
||||
void adjustItemPosition(int = 0);
|
||||
void setEditable(bool);
|
||||
void startEdition();
|
||||
void endEdition();
|
||||
|
||||
protected:
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void focusInEvent(QFocusEvent *) override;
|
||||
void focusOutEvent(QFocusEvent *) override;
|
||||
void keyPressEvent(QKeyEvent *) override;
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) override;
|
||||
QVariant itemChange(GraphicsItemChange, const QVariant &) override;
|
||||
QRectF boundingRect() const override;
|
||||
protected:
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void focusInEvent(QFocusEvent *) override;
|
||||
void focusOutEvent(QFocusEvent *) override;
|
||||
void keyPressEvent(QKeyEvent *) override;
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) override;
|
||||
QVariant itemChange(GraphicsItemChange, const QVariant &) override;
|
||||
QRectF boundingRect() const override;
|
||||
|
||||
private:
|
||||
QPointF margin() const;
|
||||
QString previous_text;
|
||||
qreal real_font_size_;
|
||||
QPointF saved_point_;
|
||||
qreal saved_font_size_;
|
||||
QGraphicsItem *decorator_;
|
||||
QPointF m_origine_pos;
|
||||
private:
|
||||
QPointF margin() const;
|
||||
QString previous_text;
|
||||
qreal real_font_size_;
|
||||
QPointF saved_point_;
|
||||
qreal saved_font_size_;
|
||||
QGraphicsItem *decorator_;
|
||||
QPointF m_origine_pos;
|
||||
};
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user