Implemented reset image size button.

This commit is contained in:
Jim Evins
2017-01-02 02:01:26 -05:00
parent bd41164816
commit 9d39b9804a
10 changed files with 438 additions and 166 deletions
+1
View File
@@ -62,6 +62,7 @@ set (glabels_sources
SelectProductDialog.cpp
Settings.cpp
SimplePreview.cpp
Size.cpp
StartupView.cpp
TemplatePicker.cpp
TemplatePickerItem.cpp
+25
View File
@@ -20,6 +20,7 @@
#include "LabelModelImageObject.h"
#include "Size.h"
#include <QBrush>
#include <QPen>
#include <QImage>
@@ -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
///
+5
View File
@@ -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
+33
View File
@@ -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)
///
+9 -1
View File
@@ -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 );
+21 -5
View File
@@ -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 )
+1
View File
@@ -87,6 +87,7 @@ private slots:
void onLineSizeControlsChanged();
void onTextControlsChanged();
void onTextInsertFieldKeySelected( QString key );
void onResetImageSize();
void onShadowControlsChanged();
void onChanged();
+87
View File
@@ -0,0 +1,87 @@
/* Size.cpp
*
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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;
}
+77
View File
@@ -0,0 +1,77 @@
/* Size.h
*
* Copyright (C) 2017 Jim Evins <evins@snaught.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef Size_h
#define Size_h
#include <QSizeF>
#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
+179 -160
View File
@@ -32,45 +32,10 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="titleImageLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../icons.qrc">:/icons/24x24/actions/glabels-object-properties.png</pixmap>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="titleLabel">
<property name="font">
<font>
<family>Sans Serif</family>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Object properties</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QTabWidget" name="notebook">
<property name="currentIndex">
<number>0</number>
<number>4</number>
</property>
<widget class="QWidget" name="textPage">
<attribute name="title">
@@ -1140,128 +1105,6 @@
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="sizeRectFrame">
<property name="title">
<string>Size</string>
</property>
<layout class="QGridLayout" name="gridLayout_22">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_19">
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QDoubleSpinBox" name="sizeWSpin"/>
</item>
<item>
<spacer name="horizontalSpacer_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_29">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Width:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QDoubleSpinBox" name="sizeHSpin"/>
</item>
<item>
<spacer name="horizontalSpacer_23">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="1">
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QCheckBox" name="sizeAspectCheck">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>132</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Lock aspect ratio</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="sizeResetImageButton">
<property name="text">
<string>Reset image size</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_30">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Height:</string>
</property>
</widget>
</item>
<item row="3" column="2">
<spacer name="horizontalSpacer_25">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="sizeLineFrame">
<property name="title">
@@ -1344,15 +1187,156 @@
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="sizeRectFrame">
<property name="title">
<string>Size</string>
</property>
<layout class="QGridLayout" name="gridLayout_22">
<item row="1" column="0">
<widget class="QWidget" name="sizeOriginalSizeGroup" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_26">
<property name="spacing">
<number>15</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="sizeOriginalSizeLabel">
<property name="text">
<string>Original size:</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="sizeResetImageButton">
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_25">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_19">
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QDoubleSpinBox" name="sizeWSpin"/>
</item>
<item>
<spacer name="horizontalSpacer_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_29">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Width:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QDoubleSpinBox" name="sizeHSpin"/>
</item>
<item>
<spacer name="horizontalSpacer_23">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="1">
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QCheckBox" name="sizeAspectCheck">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>132</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Lock aspect ratio</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_30">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Height:</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer_9">
<spacer name="verticalSpacer_8">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>368</height>
<height>40</height>
</size>
</property>
</spacer>
@@ -1522,6 +1506,41 @@
</widget>
</widget>
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="titleImageLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../icons.qrc">:/icons/24x24/actions/glabels-object-properties.png</pixmap>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="titleLabel">
<property name="font">
<font>
<family>Sans Serif</family>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Object properties</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>