From 9d39b9804a1c1211121eeada05c7c7c3d4a96f2c Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Mon, 2 Jan 2017 02:01:26 -0500 Subject: [PATCH] Implemented reset image size button. --- glabels/CMakeLists.txt | 1 + glabels/LabelModelImageObject.cpp | 25 +++ glabels/LabelModelImageObject.h | 5 + glabels/LabelModelObject.cpp | 33 +++ glabels/LabelModelObject.h | 10 +- glabels/ObjectEditor.cpp | 26 ++- glabels/ObjectEditor.h | 1 + glabels/Size.cpp | 87 ++++++++ glabels/Size.h | 77 +++++++ glabels/ui/ObjectEditor.ui | 339 ++++++++++++++++-------------- 10 files changed, 438 insertions(+), 166 deletions(-) create mode 100644 glabels/Size.cpp create mode 100644 glabels/Size.h diff --git a/glabels/CMakeLists.txt b/glabels/CMakeLists.txt index 9db507a..df38b2f 100644 --- a/glabels/CMakeLists.txt +++ b/glabels/CMakeLists.txt @@ -62,6 +62,7 @@ set (glabels_sources SelectProductDialog.cpp Settings.cpp SimplePreview.cpp + Size.cpp StartupView.cpp TemplatePicker.cpp TemplatePickerItem.cpp diff --git a/glabels/LabelModelImageObject.cpp b/glabels/LabelModelImageObject.cpp index 7338cf2..9b3f03c 100644 --- a/glabels/LabelModelImageObject.cpp +++ b/glabels/LabelModelImageObject.cpp @@ -20,6 +20,7 @@ #include "LabelModelImageObject.h" +#include "Size.h" #include #include #include @@ -118,6 +119,30 @@ void LabelModelImageObject::setFilenameNode( const TextNode& value ) } +/// +/// Image originalSize Property Getter (assumes 72 DPI, i.e. 1pixel == 1pt) +/// +Size LabelModelImageObject::originalSize() const +{ + Size size( glabels::Distance::pt(72), glabels::Distance::pt(72) ); + + if ( mImage ) + { + QSize qsize = mImage->size(); + size.setW( glabels::Distance::pt( qsize.width() ) ); + size.setH( glabels::Distance::pt( qsize.height() ) ); + } + else if ( mSvg ) + { + QSize qsize = mSvg->defaultSize(); + size.setW( glabels::Distance::pt( qsize.width() ) ); + size.setH( glabels::Distance::pt( qsize.height() ) ); + } + + return size; +} + + /// /// Draw shadow of object /// diff --git a/glabels/LabelModelImageObject.h b/glabels/LabelModelImageObject.h index a6610af..efbc904 100644 --- a/glabels/LabelModelImageObject.h +++ b/glabels/LabelModelImageObject.h @@ -58,6 +58,11 @@ public: virtual TextNode filenameNode( void ) const; virtual void setFilenameNode( const TextNode& value ); + // + // Image Property: originalSize + // + virtual Size originalSize() const; + /////////////////////////////////////////////////////////////// // Capability Implementations diff --git a/glabels/LabelModelObject.cpp b/glabels/LabelModelObject.cpp index e77ade4..6415120 100644 --- a/glabels/LabelModelObject.cpp +++ b/glabels/LabelModelObject.cpp @@ -27,6 +27,7 @@ #include "TextNode.h" #include "BarcodeStyle.h" #include "LabelRegion.h" +#include "Size.h" /// @@ -573,6 +574,16 @@ void LabelModelObject::setFilenameNode( const TextNode& value ) } +/// +/// Virtual Original Size Property Default Getter +/// (Overridden by concrete class) +/// +Size LabelModelObject::originalSize() const +{ + return Size( glabels::Distance::pt(0), glabels::Distance::pt(0) ); +} + + /// /// Virtual Line Width Property Default Getter /// (Overridden by concrete class) @@ -816,6 +827,15 @@ void LabelModelObject::setPositionRelative( const glabels::Distance& dx, } +/// +/// Get Size +/// +Size LabelModelObject::size() const +{ + return Size( mW, mH ); +} + + /// /// Set Size /// @@ -830,6 +850,19 @@ void LabelModelObject::setSize( const glabels::Distance& w, } +/// +/// Set Size +/// +void LabelModelObject::setSize( const Size& size ) +{ + mW = size.w(); + mH = size.h(); + + sizeUpdated(); + emit changed(); +} + + /// /// Set Size (But Maintain Current Aspect Ratio) /// diff --git a/glabels/LabelModelObject.h b/glabels/LabelModelObject.h index 7e4c4d7..c1b01a2 100644 --- a/glabels/LabelModelObject.h +++ b/glabels/LabelModelObject.h @@ -37,6 +37,7 @@ // Forward References class LabelRegion; +class Size; /// @@ -240,7 +241,12 @@ public: // virtual TextNode filenameNode() const; virtual void setFilenameNode( const TextNode &value ); - + + // + // Virtual Image Property: originalSize (read-only) + // + virtual Size originalSize() const; + /////////////////////////////////////////////////////////////// // Shape Properties Virtual Interface @@ -329,7 +335,9 @@ public: public: void setPosition( const glabels::Distance& x0, const glabels::Distance& y0 ); void setPositionRelative( const glabels::Distance& dx, const glabels::Distance& dy ); + Size size() const; void setSize( const glabels::Distance& w, const glabels::Distance& h ); + void setSize( const Size& size ); void setSizeHonorAspect( const glabels::Distance& w, const glabels::Distance& h ); void setWHonorAspect( const glabels::Distance& w ); void setHHonorAspect( const glabels::Distance& h ); diff --git a/glabels/ObjectEditor.cpp b/glabels/ObjectEditor.cpp index 99b3dca..c2fdb93 100644 --- a/glabels/ObjectEditor.cpp +++ b/glabels/ObjectEditor.cpp @@ -29,6 +29,7 @@ #include "LabelModelLineObject.h" #include "LabelModelTextObject.h" #include "UndoRedoModel.h" +#include "Size.h" #include "Merge/Merge.h" @@ -175,6 +176,14 @@ void ObjectEditor::loadRectSizePage() sizeWSpin->setValue( mObject->w().inUnits(mUnits) ); sizeHSpin->setValue( mObject->h().inUnits(mUnits) ); + Size originalSize = mObject->originalSize(); + QString originalSizeString = QString( "%1: %2 x %3 %4" ) + .arg( tr("Original size") ) + .arg( originalSize.w().inUnits(mUnits), 0, 'f', mSpinDigits ) + .arg( originalSize.h().inUnits(mUnits), 0, 'f', mSpinDigits ) + .arg( mUnits.toIdString() ); + sizeOriginalSizeLabel->setText( originalSizeString ); + mBlocked = false; } } @@ -303,7 +312,7 @@ void ObjectEditor::onSelectionChanged() fillFrame->setVisible( true ); sizeRectFrame->setVisible( true ); - sizeResetImageButton->setVisible( false ); + sizeOriginalSizeGroup->setVisible( false ); sizeLineFrame->setVisible( false ); loadLineFillPage(); @@ -324,7 +333,7 @@ void ObjectEditor::onSelectionChanged() fillFrame->setVisible( true ); sizeRectFrame->setVisible( true ); - sizeResetImageButton->setVisible( false ); + sizeOriginalSizeGroup->setVisible( false ); sizeLineFrame->setVisible( false ); loadLineFillPage(); @@ -344,11 +353,12 @@ void ObjectEditor::onSelectionChanged() notebook->addTab( shadowPage, "shadow" ); sizeRectFrame->setVisible( true ); - sizeResetImageButton->setVisible( true ); + sizeOriginalSizeGroup->setVisible( true ); sizeLineFrame->setVisible( false ); loadImagePage(); loadPositionPage(); + loadRectSizePage(); loadShadowPage(); setEnabled( true ); @@ -364,7 +374,7 @@ void ObjectEditor::onSelectionChanged() fillFrame->setVisible( false ); sizeRectFrame->setVisible( false ); - sizeResetImageButton->setVisible( false ); + sizeOriginalSizeGroup->setVisible( false ); sizeLineFrame->setVisible( true ); loadLineFillPage(); @@ -384,7 +394,7 @@ void ObjectEditor::onSelectionChanged() notebook->addTab( shadowPage, "shadow" ); sizeRectFrame->setVisible( true ); - sizeResetImageButton->setVisible( false ); + sizeOriginalSizeGroup->setVisible( false ); sizeLineFrame->setVisible( false ); loadTextPage(); @@ -639,6 +649,12 @@ void ObjectEditor::onTextInsertFieldKeySelected( QString key ) } +void ObjectEditor::onResetImageSize() +{ + mObject->setSize( mObject->originalSize() ); +} + + void ObjectEditor::onShadowControlsChanged() { if ( !mBlocked ) diff --git a/glabels/ObjectEditor.h b/glabels/ObjectEditor.h index 16fef3f..8ead622 100644 --- a/glabels/ObjectEditor.h +++ b/glabels/ObjectEditor.h @@ -87,6 +87,7 @@ private slots: void onLineSizeControlsChanged(); void onTextControlsChanged(); void onTextInsertFieldKeySelected( QString key ); + void onResetImageSize(); void onShadowControlsChanged(); void onChanged(); diff --git a/glabels/Size.cpp b/glabels/Size.cpp new file mode 100644 index 0000000..a1090a2 --- /dev/null +++ b/glabels/Size.cpp @@ -0,0 +1,87 @@ +/* Size.cpp + * + * Copyright (C) 2013-2016 Jim Evins + * + * This file is part of gLabels-qt. + * + * gLabels-qt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels-qt 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 gLabels-qt. If not, see . + */ + +#include "Size.h" + + +/// +/// Constructor +/// +Size::Size() : mW(0), mH(0) +{ +} + + +/// +/// Constructor +/// +Size::Size( const glabels::Distance& w, const glabels::Distance& h ) : mW(w), mH(h) +{ +} + + +/// +/// Get w +/// +glabels::Distance Size::w( void ) const +{ + return mW; +} + + +/// +/// Set w +/// +void Size::setW( const glabels::Distance& value ) +{ + mW = value; +} + + +/// +/// Get h +/// +glabels::Distance Size::h( void ) const +{ + return mH; +} + + +/// +/// Set h +/// +void Size::setH( const glabels::Distance& value ) +{ + mH = value; +} + + +/// +/// Convert to a QSizeF +/// +QSizeF Size::qSizeF() const +{ + QSizeF s; + + s.setWidth( mW.pt() ); + s.setHeight( mH.pt() ); + + return s; +} diff --git a/glabels/Size.h b/glabels/Size.h new file mode 100644 index 0000000..b8a7a2c --- /dev/null +++ b/glabels/Size.h @@ -0,0 +1,77 @@ +/* Size.h + * + * Copyright (C) 2017 Jim Evins + * + * This file is part of gLabels-qt. + * + * gLabels-qt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels-qt 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 gLabels-qt. If not, see . + */ + +#ifndef Size_h +#define Size_h + +#include +#include "libglabels/Distance.h" + + +/// +/// Size Type +/// +class Size +{ + + ///////////////////////////////// + // Constructors + ///////////////////////////////// +public: + Size(); + Size( const glabels::Distance& w, const glabels::Distance& h ); + + + ///////////////////////////////// + // Properties + ///////////////////////////////// +public: + // + // w Property + // + glabels::Distance w( void ) const; + void setW( const glabels::Distance& value ); + + + // + // H Property + // + glabels::Distance h( void ) const; + void setH( const glabels::Distance& value ); + + + ///////////////////////////////// + // Methods + ///////////////////////////////// +public: + QSizeF qSizeF() const; + + + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: + glabels::Distance mW; + glabels::Distance mH; + +}; + + +#endif // Size_h diff --git a/glabels/ui/ObjectEditor.ui b/glabels/ui/ObjectEditor.ui index f87bbd0..e0da56f 100644 --- a/glabels/ui/ObjectEditor.ui +++ b/glabels/ui/ObjectEditor.ui @@ -32,45 +32,10 @@ Form - - - - - - - 0 - 0 - - - - - - - :/icons/24x24/actions/glabels-object-properties.png - - - - - - - - Sans Serif - 10 - 75 - true - - - - Object properties - - - - - - 0 + 4 @@ -1140,128 +1105,6 @@ - - - - Size - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - 50 - 0 - - - - Width: - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - 0 - 0 - - - - - 132 - 0 - - - - Lock aspect ratio - - - - - - - - - Reset image size - - - - - - - - 50 - 0 - - - - Height: - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - @@ -1344,15 +1187,156 @@ + + + + Size + + + + + + + 15 + + + 0 + + + + + Original size: + + + + + + + Reset + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 50 + 0 + + + + Width: + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + + 132 + 0 + + + + Lock aspect ratio + + + + + + + + + + 50 + 0 + + + + Height: + + + + + + + + - + Qt::Vertical 20 - 368 + 40 @@ -1522,6 +1506,41 @@ + + + + + + + 0 + 0 + + + + + + + :/icons/24x24/actions/glabels-object-properties.png + + + + + + + + Sans Serif + 10 + 75 + true + + + + Object properties + + + + +