mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-24 03:10:52 +01:00
replace 4 spaces by a tab
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 (QDomDocument &xml_document, QDomElement &) const;
|
||||
void stylesFromXml(const QDomElement &);
|
||||
void resetStyles ();
|
||||
void applyStylesToQPainter(QPainter &) const;
|
||||
void drawShadowShape (QPainter *painter);
|
||||
protected:
|
||||
void stylesToXml (QDomDocument &xml_document, 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
|
||||
@@ -30,86 +30,86 @@ 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: public PropertiesInterface {
|
||||
// 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:
|
||||
/**
|
||||
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:
|
||||
/**
|
||||
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,173 +23,173 @@
|
||||
|
||||
|
||||
/**
|
||||
@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
|
||||
*/
|
||||
QDomElement PartArc::toXml(QDomDocument &xml_document) const {
|
||||
{
|
||||
QDomElement xml_element = xml_document.createElement("arc");
|
||||
QPointF top_left(sceneTopLeft());
|
||||
QDomElement xml_element = xml_document.createElement("arc");
|
||||
QPointF top_left(sceneTopLeft());
|
||||
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "x", top_left.x()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "y", top_left.y()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "width", rect().width()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "height", rect().height()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "x", top_left.x()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "y", top_left.y()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "width", rect().width()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "height", rect().height()));
|
||||
|
||||
//to maintain compatibility with the previous version, we write the angle in degrees.
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "start", m_start_angle / 16));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "angle", m_span_angle / 16));
|
||||
//to maintain compatibility with the previous version, we write the angle in degrees.
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "start", m_start_angle / 16));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "angle", m_span_angle / 16));
|
||||
|
||||
|
||||
stylesToXml(xml_document, xml_element);
|
||||
return(xml_element);
|
||||
stylesToXml(xml_document, 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.
|
||||
*/
|
||||
bool PartArc::fromXml(const QDomElement &qde) {
|
||||
stylesFromXml(qde);
|
||||
stylesFromXml(qde);
|
||||
|
||||
double x=0, y=0, w=0, h=0;
|
||||
if (propertyDouble(qde, "x", &x) == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(qde, "y", &y) == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(qde, "width", &w) == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(qde, "height", &h) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
double x=0, y=0, w=0, h=0;
|
||||
if (propertyDouble(qde, "x", &x) == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(qde, "y", &y) == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(qde, "width", &w) == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(qde, "height", &h) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
|
||||
m_rect = QRectF(mapFromScene(x, y), QSizeF(w, h) );
|
||||
m_rect = QRectF(mapFromScene(x, y), QSizeF(w, h) );
|
||||
|
||||
m_start_angle = 0;
|
||||
if (propertyDouble(qde, "start", &m_start_angle) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
m_start_angle *= 16;
|
||||
m_start_angle = 0;
|
||||
if (propertyDouble(qde, "start", &m_start_angle) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
m_start_angle *= 16;
|
||||
|
||||
m_span_angle = -1440;
|
||||
if (propertyDouble(qde, "angle", &m_span_angle) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
m_span_angle *= 16;
|
||||
m_span_angle = -1440;
|
||||
if (propertyDouble(qde, "angle", &m_span_angle) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
m_span_angle *= 16;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PartArc::valideXml(QDomElement& element) {
|
||||
|
||||
if (propertyDouble(element, "x") == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(element, "y") == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(element, "width") == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(element, "height") == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(element, "start") == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(element, "angle") == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
return true;
|
||||
if (propertyDouble(element, "x") == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(element, "y") == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(element, "width") == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(element, "height") == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(element, "start") == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(element, "angle") == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@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));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,327 +203,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,66 +24,66 @@ 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")); }
|
||||
QDomElement toXml (QDomDocument &) const override;
|
||||
bool fromXml (const QDomElement &) override;
|
||||
static bool valideXml(QDomElement& element);
|
||||
//Name and XML
|
||||
QString name() const override { return(QObject::tr("arc", "element part name")); }
|
||||
QString xmlName() const override { return(QString("arc")); }
|
||||
QDomElement toXml (QDomDocument &) const override;
|
||||
bool fromXml (const QDomElement &) override;
|
||||
static bool valideXml(QDomElement& element);
|
||||
|
||||
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
|
||||
|
||||
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 PARTDYNAMICTEXTFIELD_H
|
||||
#define PARTDYNAMICTEXTFIELD_H
|
||||
@@ -23,107 +23,107 @@
|
||||
#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;
|
||||
|
||||
QDomElement toXml(QDomDocument &dom_doc) const override;
|
||||
bool fromXml(const QDomElement &dom_elmt) override;
|
||||
void fromTextFieldXml(const QDomElement &dom_element);
|
||||
static bool valideXml(QDomElement& dom_elmt);
|
||||
QDomElement toXml(QDomDocument &dom_doc) const override;
|
||||
bool fromXml(const QDomElement &dom_elmt) override;
|
||||
void fromTextFieldXml(const QDomElement &dom_element);
|
||||
static bool valideXml(QDomElement& dom_elmt);
|
||||
|
||||
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{QUuid::createUuid()};
|
||||
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{QUuid::createUuid()};
|
||||
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,396 +22,396 @@
|
||||
#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
|
||||
*/
|
||||
QDomElement PartEllipse::toXml(QDomDocument &xml_document) const
|
||||
{
|
||||
QDomElement xml_element;
|
||||
if (qFuzzyCompare(rect().width(), rect().height()))
|
||||
{
|
||||
xml_element = xml_document.createElement("circle");
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "diameter", rect().width()));
|
||||
}
|
||||
else
|
||||
{
|
||||
xml_element = xml_document.createElement("ellipse");
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "width", rect().width()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "height", rect().height()));
|
||||
}
|
||||
QDomElement xml_element;
|
||||
if (qFuzzyCompare(rect().width(), rect().height()))
|
||||
{
|
||||
xml_element = xml_document.createElement("circle");
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "diameter", rect().width()));
|
||||
}
|
||||
else
|
||||
{
|
||||
xml_element = xml_document.createElement("ellipse");
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "width", rect().width()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "height", rect().height()));
|
||||
}
|
||||
|
||||
QPointF top_left(sceneTopLeft());
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "x", top_left.x()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "y", top_left.y()));
|
||||
QPointF top_left(sceneTopLeft());
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "x", top_left.x()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "y", top_left.y()));
|
||||
|
||||
stylesToXml(xml_document, xml_element);
|
||||
stylesToXml(xml_document, 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.
|
||||
*/
|
||||
bool PartEllipse::fromXml(const QDomElement &qde)
|
||||
{
|
||||
stylesFromXml(qde);
|
||||
double x=0, y=0, width=0, height=0;
|
||||
stylesFromXml(qde);
|
||||
double x=0, y=0, width=0, height=0;
|
||||
|
||||
if (qde.tagName() == "ellipse")
|
||||
{
|
||||
if (propertyDouble(qde, "width", &width) == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(qde, "height", &height) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if (propertyDouble(qde, "diameter", &width) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
height = width;
|
||||
}
|
||||
if (qde.tagName() == "ellipse")
|
||||
{
|
||||
if (propertyDouble(qde, "width", &width) == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(qde, "height", &height) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if (propertyDouble(qde, "diameter", &width) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
height = width;
|
||||
}
|
||||
|
||||
|
||||
if (propertyDouble(qde, "x", &x) == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(qde, "y", &y) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
if (propertyDouble(qde, "x", &x) == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(qde, "y", &y) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
|
||||
m_rect = QRectF(mapFromScene(x, y), QSizeF(width, height));
|
||||
m_rect = QRectF(mapFromScene(x, y), QSizeF(width, height));
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PartEllipse::valideXml(QDomElement& element) {
|
||||
if (element.tagName() == "ellipse")
|
||||
{
|
||||
if (propertyDouble(element, "width") & PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(element, "height") & PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if (propertyDouble(element, "diameter") & PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
}
|
||||
if (element.tagName() == "ellipse")
|
||||
{
|
||||
if (propertyDouble(element, "width") & PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(element, "height") & PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if (propertyDouble(element, "diameter") & PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if ((propertyDouble(element, "x") & PropertyFlags::NoValidConversion) ||
|
||||
(propertyDouble(element, "y") & PropertyFlags::NoValidConversion))
|
||||
return false;
|
||||
if ((propertyDouble(element, "x") & PropertyFlags::NoValidConversion) ||
|
||||
(propertyDouble(element, "y") & PropertyFlags::NoValidConversion))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@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,61 +23,61 @@
|
||||
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")); }
|
||||
QDomElement toXml (QDomDocument &) const override;
|
||||
bool fromXml (const QDomElement &) override;
|
||||
static bool valideXml(QDomElement& element);
|
||||
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")); }
|
||||
QDomElement toXml (QDomDocument &) const override;
|
||||
bool fromXml (const QDomElement &) override;
|
||||
static bool valideXml(QDomElement& element);
|
||||
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,105 +25,105 @@ 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")); }
|
||||
QDomElement toXml(QDomDocument &) const override;
|
||||
bool fromXml(const QDomElement &) override;
|
||||
bool valideXml(QDomElement& element) const;
|
||||
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")); }
|
||||
QDomElement toXml(QDomDocument &) const override;
|
||||
bool fromXml(const QDomElement &) override;
|
||||
bool valideXml(QDomElement& element) const;
|
||||
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{1.5};
|
||||
/*****************/
|
||||
Qet::EndType first_end;
|
||||
qreal first_length{1.5};
|
||||
|
||||
Qet::EndType second_end;
|
||||
qreal second_length{1.5};
|
||||
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{1.5};
|
||||
QList<QPointF> saved_points_;
|
||||
QLineF m_line;
|
||||
int m_vector_index = -1;
|
||||
QPropertyUndoCommand *m_undo_command;
|
||||
QVector<QetGraphicsHandlerItem *> m_handler_vector;
|
||||
};
|
||||
#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_POLYGON_H
|
||||
#define PART_POLYGON_H
|
||||
@@ -26,95 +26,95 @@ 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")); }
|
||||
bool fromXml(const QDomElement &) override;
|
||||
QDomElement toXml(QDomDocument &) const override;
|
||||
static bool valideXml(QDomElement& element);
|
||||
QString name() const override { return(QObject::tr("polygone", "element part name")); }
|
||||
QString xmlName() const override { return(QString("polygon")); }
|
||||
bool fromXml(const QDomElement &) override;
|
||||
QDomElement toXml(QDomDocument &) const override;
|
||||
static bool valideXml(QDomElement& element);
|
||||
|
||||
|
||||
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,572 +22,572 @@
|
||||
#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
|
||||
*/
|
||||
QDomElement PartRectangle::toXml(QDomDocument &xml_document) const
|
||||
{
|
||||
QDomElement xml_element = xml_document.createElement("rect");
|
||||
QPointF top_left(sceneTopLeft());
|
||||
QDomElement xml_element = xml_document.createElement("rect");
|
||||
QPointF top_left(sceneTopLeft());
|
||||
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "x", top_left.x()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "y", top_left.y()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "width", m_rect.width()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "height", m_rect.height()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "x", top_left.x()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "y", top_left.y()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "width", m_rect.width()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "height", 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));
|
||||
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "rx", m_xRadius));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "ry", m_yRadius));
|
||||
|
||||
stylesToXml(xml_document, xml_element);
|
||||
return(xml_element);
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "rx", m_xRadius));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "ry", m_yRadius));
|
||||
|
||||
stylesToXml(xml_document, 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.
|
||||
*/
|
||||
bool PartRectangle::fromXml(const QDomElement &qde)
|
||||
{
|
||||
stylesFromXml(qde);
|
||||
stylesFromXml(qde);
|
||||
|
||||
double x=0, y=0, w=0, h=0, rx=0, ry=0;
|
||||
if (propertyDouble(qde, "x", &x) == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(qde, "y", &y) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
double x=0, y=0, w=0, h=0, rx=0, ry=0;
|
||||
if (propertyDouble(qde, "x", &x) == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(qde, "y", &y) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
|
||||
setPos(mapFromScene(x, y));
|
||||
setPos(mapFromScene(x, y));
|
||||
|
||||
if (propertyDouble(qde, "width", &w) == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(qde, "width", &h) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
if (propertyDouble(qde, "width", &w) == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(qde, "width", &h) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
|
||||
QRectF rect(QPointF(x,y), QSizeF(w, h));
|
||||
QRectF rect(QPointF(x,y), QSizeF(w, h));
|
||||
|
||||
setRect(rect.normalized());
|
||||
setRect(rect.normalized());
|
||||
|
||||
if (propertyDouble(qde, "rx", &rx) == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(qde, "ry", &ry) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
if (propertyDouble(qde, "rx", &rx) == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(qde, "ry", &ry) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
|
||||
setXRadius(rx);
|
||||
setYRadius(ry);
|
||||
setXRadius(rx);
|
||||
setYRadius(ry);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PartRectangle::valideXml(QDomElement& element) {
|
||||
// parameters have default values so no value is not a non valid xml element
|
||||
if ((propertyDouble(element, "x") & PropertyFlags::NoValidConversion) |
|
||||
(propertyDouble(element, "y") & PropertyFlags::NoValidConversion) |
|
||||
(propertyDouble(element, "width") & PropertyFlags::NoValidConversion) |
|
||||
(propertyDouble(element, "width") & PropertyFlags::NoValidConversion) |
|
||||
(propertyDouble(element, "rx") & PropertyFlags::NoValidConversion) |
|
||||
(propertyDouble(element, "ry") & PropertyFlags::NoValidConversion))
|
||||
return false;
|
||||
return true;
|
||||
// parameters have default values so no value is not a non valid xml element
|
||||
if ((propertyDouble(element, "x") & PropertyFlags::NoValidConversion) |
|
||||
(propertyDouble(element, "y") & PropertyFlags::NoValidConversion) |
|
||||
(propertyDouble(element, "width") & PropertyFlags::NoValidConversion) |
|
||||
(propertyDouble(element, "width") & PropertyFlags::NoValidConversion) |
|
||||
(propertyDouble(element, "rx") & PropertyFlags::NoValidConversion) |
|
||||
(propertyDouble(element, "ry") & PropertyFlags::NoValidConversion))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@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,92 +23,92 @@
|
||||
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")); }
|
||||
QDomElement toXml (QDomDocument &) const override;
|
||||
bool fromXml (const QDomElement &) override;
|
||||
static bool valideXml(QDomElement& element);
|
||||
QString xmlName () const override { return(QString("rect")); }
|
||||
QDomElement toXml (QDomDocument &) const override;
|
||||
bool fromXml (const QDomElement &) override;
|
||||
static bool valideXml(QDomElement& element);
|
||||
|
||||
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,39 +1,39 @@
|
||||
/*
|
||||
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_name = tr("terminal");
|
||||
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_name = tr("terminal");
|
||||
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
|
||||
@@ -42,208 +42,208 @@ 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
|
||||
*/
|
||||
bool PartTerminal::fromXml(const QDomElement &xml_elmt) {
|
||||
|
||||
QUuid uuid;
|
||||
// update part and add uuid, which is used in the new version to connect terminals together
|
||||
// if the attribute not exists, means, the element is created with an older version of qet. So use the legacy approach
|
||||
// to identify terminals
|
||||
propertyUuid(xml_elmt, "uuid", &d->m_uuid);
|
||||
QUuid uuid;
|
||||
// update part and add uuid, which is used in the new version to connect terminals together
|
||||
// if the attribute not exists, means, the element is created with an older version of qet. So use the legacy approach
|
||||
// to identify terminals
|
||||
propertyUuid(xml_elmt, "uuid", &d->m_uuid);
|
||||
|
||||
if (!d->fromXml(xml_elmt))
|
||||
return false;
|
||||
if (!d->fromXml(xml_elmt))
|
||||
return false;
|
||||
|
||||
setPos(d -> m_pos);
|
||||
updateSecondPoint();
|
||||
setPos(d -> m_pos);
|
||||
updateSecondPoint();
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
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
|
||||
*/
|
||||
QDomElement PartTerminal::toXml(QDomDocument &xml_document) const {
|
||||
|
||||
QDomElement qdo = xml_document.createElement("terminal");
|
||||
QDomElement qdo = xml_document.createElement("terminal");
|
||||
|
||||
qdo.appendChild(createXmlProperty(xml_document, "uuid", d->m_uuid));
|
||||
qdo.appendChild(createXmlProperty(xml_document, "uuid", d->m_uuid));
|
||||
|
||||
d->m_pos = pos();
|
||||
d->m_pos = pos();
|
||||
|
||||
// Do not store terminal data in its own child
|
||||
QDomElement terminalDataElement = d->toXml(xml_document);
|
||||
for (int i=0; i < terminalDataElement.childNodes().length(); i++) {
|
||||
qdo.appendChild(terminalDataElement.childNodes().at(i).cloneNode()); // cloneNode() is important, otherwise no deep clone is made
|
||||
}
|
||||
// Do not store terminal data in its own child
|
||||
QDomElement terminalDataElement = d->toXml(xml_document);
|
||||
for (int i=0; i < terminalDataElement.childNodes().length(); i++) {
|
||||
qdo.appendChild(terminalDataElement.childNodes().at(i).cloneNode()); // cloneNode() is important, otherwise no deep clone is made
|
||||
}
|
||||
|
||||
return qdo;
|
||||
return qdo;
|
||||
}
|
||||
|
||||
bool PartTerminal::valideXml(QDomElement& element) {
|
||||
return TerminalData::valideXml(element);
|
||||
return TerminalData::valideXml(element);
|
||||
}
|
||||
|
||||
/**
|
||||
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,62 +24,62 @@
|
||||
|
||||
|
||||
/**
|
||||
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")); }
|
||||
bool fromXml(const QDomElement &) override;
|
||||
QDomElement toXml(QDomDocument &) const override;
|
||||
static bool valideXml(QDomElement& element);
|
||||
// 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")); }
|
||||
bool fromXml(const QDomElement &) override;
|
||||
QDomElement toXml(QDomDocument &) const override;
|
||||
static bool valideXml(QDomElement& element);
|
||||
void paint(
|
||||
QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *,
|
||||
QWidget *) override;
|
||||
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,346 +63,346 @@ 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
|
||||
*/
|
||||
bool PartText::fromXml(const QDomElement &xml_element)
|
||||
int size;
|
||||
QString font;
|
||||
int size;
|
||||
QString font;
|
||||
|
||||
if (propertyInteger(xml_element, "size", &size) != PropertyFlags::NotFound)
|
||||
{
|
||||
if (size < 1) {
|
||||
size = 20;
|
||||
}
|
||||
QFont font_ = this -> font();
|
||||
font_.setPointSize(size);
|
||||
setFont(font_);
|
||||
}
|
||||
else if (propertyString(xml_element, "font", &font) != PropertyFlags::NotFound)
|
||||
{
|
||||
QFont font_;
|
||||
font_.fromString(font);
|
||||
setFont(font_);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (propertyInteger(xml_element, "size", &size) != PropertyFlags::NotFound)
|
||||
{
|
||||
if (size < 1) {
|
||||
size = 20;
|
||||
}
|
||||
QFont font_ = this -> font();
|
||||
font_.setPointSize(size);
|
||||
setFont(font_);
|
||||
}
|
||||
else if (propertyString(xml_element, "font", &font) != PropertyFlags::NotFound)
|
||||
{
|
||||
QFont font_;
|
||||
font_.fromString(font);
|
||||
setFont(font_);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
QColor color;
|
||||
QString text;
|
||||
propertyColor(xml_element, "color", &color);
|
||||
setDefaultTextColor(color);
|
||||
QColor color;
|
||||
QString text;
|
||||
propertyColor(xml_element, "color", &color);
|
||||
setDefaultTextColor(color);
|
||||
|
||||
|
||||
propertyString(xml_element, "text", &text);
|
||||
setPlainText(text);
|
||||
propertyString(xml_element, "text", &text);
|
||||
setPlainText(text);
|
||||
|
||||
double x=0, y=0, rot=0;
|
||||
if (propertyDouble(xml_element, "x", &x) == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(xml_element, "y", &y) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
setPos(x, y);
|
||||
double x=0, y=0, rot=0;
|
||||
if (propertyDouble(xml_element, "x", &x) == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(xml_element, "y", &y) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
setPos(x, y);
|
||||
|
||||
if (propertyDouble(xml_element, "rotation", &rot) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
setRotation(rot);
|
||||
if (propertyDouble(xml_element, "rotation", &rot) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
setRotation(rot);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
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
|
||||
*/
|
||||
QDomElement PartText::toXml(QDomDocument &xml_document) const
|
||||
{
|
||||
QDomElement xml_element = xml_document.createElement(xmlName());
|
||||
QDomElement xml_element = xml_document.createElement(xmlName());
|
||||
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "x", pos().x()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "y", pos().y()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "text", toPlainText()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "font", font().toString()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "rotation", rotation()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "color", defaultTextColor().name()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "x", pos().x()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "y", pos().y()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "text", toPlainText()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "font", font().toString()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "rotation", rotation()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "color", defaultTextColor().name()));
|
||||
|
||||
return(xml_element);
|
||||
return(xml_element);
|
||||
}
|
||||
|
||||
bool PartText::valideXml(QDomElement& element) {
|
||||
|
||||
if (propertyInteger(element, "size") == PropertyFlags::NotFound ||
|
||||
propertyString(element, "font") == PropertyFlags::NotFound) {
|
||||
return false;
|
||||
}
|
||||
if (propertyInteger(element, "size") == PropertyFlags::NotFound ||
|
||||
propertyString(element, "font") == PropertyFlags::NotFound) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (propertyString(element, "color") == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
if (propertyString(element, "color") == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
|
||||
|
||||
if (propertyString(element, "text"))
|
||||
return false;
|
||||
if (propertyString(element, "text"))
|
||||
return false;
|
||||
|
||||
if (propertyDouble(element, "x") == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(element, "y") == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
if (propertyDouble(element, "x") == PropertyFlags::NoValidConversion ||
|
||||
propertyDouble(element, "y") == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
|
||||
if (propertyDouble(element, "rotation", 0) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
if (propertyDouble(element, "rotation", 0) == PropertyFlags::NoValidConversion)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@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,82 +24,82 @@
|
||||
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")); }
|
||||
bool fromXml(const QDomElement &) override;
|
||||
static bool valideXml(QDomElement& element);
|
||||
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")); }
|
||||
bool fromXml(const QDomElement &) override;
|
||||
static bool valideXml(QDomElement& element);
|
||||
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