Add grid settings to preferences (#224)
- Allow origin to be either at the top-left corner or center of label (#174) - For non-rectangular labels (cd, round, etc.) the origin will still always be at the center of the label. - User controllable grid spacing
This commit is contained in:
+12
-10
@@ -68,7 +68,6 @@ namespace glabels
|
||||
|
||||
const QColor gridLineColor( 192, 192, 192 );
|
||||
const double gridLineWidthPixels = 1;
|
||||
const model::Distance gridSpacing = model::Distance::pt(9); // TODO: determine from locale.
|
||||
|
||||
const QColor markupLineColor( 240, 99, 99 );
|
||||
const double markupLineWidthPixels = 1;
|
||||
@@ -93,7 +92,6 @@ namespace glabels
|
||||
mScale = 1;
|
||||
mMarkupVisible = true;
|
||||
mGridVisible = true;
|
||||
mGridSpacing = 18;
|
||||
|
||||
mState = IdleState;
|
||||
|
||||
@@ -1161,18 +1159,20 @@ namespace glabels
|
||||
{
|
||||
if ( mGridVisible )
|
||||
{
|
||||
auto gridSpacing = model::Settings::gridSpacing();
|
||||
auto gridOrigin = model::Settings::gridOrigin();
|
||||
|
||||
bool isRectangular = dynamic_cast<const model::FrameRect*>( mModel->frame() );
|
||||
|
||||
model::Distance w = mModel->frame()->w();
|
||||
model::Distance h = mModel->frame()->h();
|
||||
|
||||
model::Distance x0, y0;
|
||||
if ( dynamic_cast<const model::FrameRect*>( mModel->frame() ) )
|
||||
// Set origin of grid. For non-rectangular labels (e.g. round, cd, etc.),
|
||||
// ignore the gridOrigin setting and always use the center of the label.
|
||||
auto x0 = gridSpacing;
|
||||
auto y0 = gridSpacing;
|
||||
if ( gridOrigin == model::Settings::ORIGIN_CENTER || !isRectangular )
|
||||
{
|
||||
x0 = gridSpacing;
|
||||
y0 = gridSpacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* round labels, adjust grid to line up with center of label. */
|
||||
x0 = fmod( w/2, gridSpacing );
|
||||
y0 = fmod( h/2, gridSpacing );
|
||||
}
|
||||
@@ -1325,6 +1325,8 @@ namespace glabels
|
||||
model::Units units = model::Settings::units();
|
||||
|
||||
mStepSize = model::Distance( units.resolution(), units );
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -34,7 +34,10 @@ namespace glabels
|
||||
{
|
||||
setupUi( this );
|
||||
|
||||
switch ( model::Settings::units().toEnum() )
|
||||
|
||||
auto units = model::Settings::units();
|
||||
|
||||
switch ( units.toEnum() )
|
||||
{
|
||||
case model::Units::IN:
|
||||
unitsInchesRadio->setChecked( true );
|
||||
@@ -52,6 +55,33 @@ namespace glabels
|
||||
unitsPointsRadio->setChecked( true );
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
switch ( model::Settings::gridOrigin() )
|
||||
{
|
||||
case model::Settings::ORIGIN_CENTER:
|
||||
gridOriginCenterRadio->setChecked( true );
|
||||
break;
|
||||
case model::Settings::ORIGIN_TL:
|
||||
gridOriginTlRadio->setChecked( true );
|
||||
break;
|
||||
default:
|
||||
gridOriginTlRadio->setChecked( true );
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
auto gridSpacing = model::Settings::gridSpacing();
|
||||
|
||||
gridSpacingSpin->setDecimals( units.resolutionDigits() );
|
||||
gridSpacingSpin->setSingleStep( units.resolution() );
|
||||
gridSpacingSpin->setMinimum( units.resolution() );
|
||||
gridSpacingSpin->setSuffix( " " + units.toIdString() );
|
||||
gridSpacingSpin->setValue( gridSpacing.inUnits( units ) );
|
||||
|
||||
|
||||
connect( model::Settings::instance(), SIGNAL(changed()),
|
||||
this, SLOT(onSettingsChanged()) );
|
||||
}
|
||||
|
||||
|
||||
@@ -82,4 +112,61 @@ namespace glabels
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Grid Origin Radios Changed
|
||||
///
|
||||
void PreferencesDialog::onGridOriginRadiosChanged()
|
||||
{
|
||||
if ( gridOriginTlRadio->isChecked() )
|
||||
{
|
||||
model::Settings::setGridOrigin( model::Settings::ORIGIN_TL );
|
||||
}
|
||||
else if ( gridOriginCenterRadio->isChecked() )
|
||||
{
|
||||
model::Settings::setGridOrigin( model::Settings::ORIGIN_CENTER );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Grid Spacing Spin Changed
|
||||
///
|
||||
void PreferencesDialog::onGridSpacingSpinChanged()
|
||||
{
|
||||
auto units = model::Settings::units();
|
||||
|
||||
auto spacing = model::Distance( gridSpacingSpin->value(), units );
|
||||
|
||||
model::Settings::setGridSpacing( spacing );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Grid Spacing Reset Button Clicked
|
||||
///
|
||||
void PreferencesDialog::onGridSpacingResetButtonClicked()
|
||||
{
|
||||
model::Settings::resetGridSpacing();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Settings Changed
|
||||
///
|
||||
void PreferencesDialog::onSettingsChanged()
|
||||
{
|
||||
auto units = model::Settings::units();
|
||||
auto gridSpacing = model::Settings::gridSpacing();
|
||||
|
||||
gridSpacingSpin->blockSignals( true );
|
||||
gridSpacingSpin->setDecimals( units.resolutionDigits() );
|
||||
gridSpacingSpin->setSingleStep( units.resolution() );
|
||||
gridSpacingSpin->setMinimum( units.resolution() );
|
||||
gridSpacingSpin->setSuffix( " " + units.toIdString() );
|
||||
gridSpacingSpin->setValue( gridSpacing.inUnits( units ) );
|
||||
gridSpacingSpin->blockSignals( false );
|
||||
}
|
||||
|
||||
|
||||
} // namespace glabels
|
||||
|
||||
@@ -47,6 +47,10 @@ namespace glabels
|
||||
/////////////////////////////////
|
||||
private slots:
|
||||
void onUnitsRadiosChanged();
|
||||
void onGridOriginRadiosChanged();
|
||||
void onGridSpacingSpinChanged();
|
||||
void onGridSpacingResetButtonClicked();
|
||||
void onSettingsChanged();
|
||||
|
||||
};
|
||||
|
||||
|
||||
+173
-16
@@ -7,14 +7,14 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>318</width>
|
||||
<height>295</height>
|
||||
<height>357</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>gLabels - Preferences</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
@@ -90,9 +90,100 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Grid</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Configure grid behavior.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Origin</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="gridOriginTlRadio">
|
||||
<property name="text">
|
||||
<string>Top left corner</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="gridOriginCenterRadio">
|
||||
<property name="text">
|
||||
<string>Center</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Spacing</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="gridSpacingSpin"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="gridSpacingResetButton">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Reset</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<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>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="1" column="0">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@@ -113,8 +204,8 @@
|
||||
<slot>close()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>289</x>
|
||||
<y>368</y>
|
||||
<x>298</x>
|
||||
<y>347</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>298</x>
|
||||
@@ -129,8 +220,8 @@
|
||||
<slot>onUnitsRadiosChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>269</x>
|
||||
<y>184</y>
|
||||
<x>285</x>
|
||||
<y>246</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>298</x>
|
||||
@@ -145,8 +236,8 @@
|
||||
<slot>onUnitsRadiosChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>269</x>
|
||||
<y>102</y>
|
||||
<x>285</x>
|
||||
<y>144</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>298</x>
|
||||
@@ -161,8 +252,8 @@
|
||||
<slot>onUnitsRadiosChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>269</x>
|
||||
<y>131</y>
|
||||
<x>285</x>
|
||||
<y>178</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>298</x>
|
||||
@@ -177,8 +268,8 @@
|
||||
<slot>onUnitsRadiosChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>264</x>
|
||||
<y>154</y>
|
||||
<x>285</x>
|
||||
<y>212</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>295</x>
|
||||
@@ -193,8 +284,8 @@
|
||||
<slot>onUnitsRadiosChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>243</x>
|
||||
<y>215</y>
|
||||
<x>266</x>
|
||||
<y>280</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>295</x>
|
||||
@@ -202,9 +293,75 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>gridSpacingSpin</sender>
|
||||
<signal>valueChanged(double)</signal>
|
||||
<receiver>PreferencesDialog</receiver>
|
||||
<slot>onGridSpacingSpinChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>114</x>
|
||||
<y>206</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>7</x>
|
||||
<y>240</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>gridOriginTlRadio</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>PreferencesDialog</receiver>
|
||||
<slot>onGridOriginRadiosChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>264</x>
|
||||
<y>128</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>311</x>
|
||||
<y>36</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>gridOriginCenterRadio</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>PreferencesDialog</receiver>
|
||||
<slot>onGridOriginRadiosChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>129</x>
|
||||
<y>156</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>318</x>
|
||||
<y>235</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>gridSpacingResetButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>PreferencesDialog</receiver>
|
||||
<slot>onGridSpacingResetButtonClicked()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>177</x>
|
||||
<y>213</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>313</x>
|
||||
<y>267</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>onUnitsRadiosChanged()</slot>
|
||||
<slot>onPreferedPaperSizesRadiosChanged()</slot>
|
||||
<slot>onGridSpacingSpinChanged()</slot>
|
||||
<slot>onGridOriginRadiosChanged()</slot>
|
||||
<slot>onGridSpacingResetButtonClicked()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
||||
@@ -66,7 +66,6 @@ namespace glabels
|
||||
QString toString( Units::Enum unitsEnum ) const;
|
||||
QString toString( const QString& unitsId ) const;
|
||||
|
||||
|
||||
Distance& operator+=( const Distance& d );
|
||||
Distance& operator-=( const Distance& d );
|
||||
Distance& operator*=( double f );
|
||||
|
||||
@@ -375,5 +375,69 @@ namespace glabels
|
||||
mInstance->endGroup();
|
||||
}
|
||||
|
||||
|
||||
Settings::GridOrigin Settings::gridOrigin()
|
||||
{
|
||||
mInstance->beginGroup( "Grid" );
|
||||
QString value = mInstance->value( "origin", "top_left" ).toString();
|
||||
mInstance->endGroup();
|
||||
|
||||
return (value == "top_left") ? ORIGIN_TL : ORIGIN_CENTER;
|
||||
}
|
||||
|
||||
|
||||
void Settings::setGridOrigin( GridOrigin origin )
|
||||
{
|
||||
mInstance->beginGroup( "Grid" );
|
||||
mInstance->setValue( "origin", origin == ORIGIN_TL ? "top_left" : "center" );
|
||||
mInstance->endGroup();
|
||||
|
||||
emit mInstance->changed();
|
||||
}
|
||||
|
||||
|
||||
Distance Settings::gridSpacing()
|
||||
{
|
||||
// Guess at a suitable default
|
||||
QString defaultSpacingString;
|
||||
if ( QLocale::system().measurementSystem() == QLocale::ImperialSystem )
|
||||
{
|
||||
defaultSpacingString = Distance::in(0.125).toString( Units::IN );
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultSpacingString = Distance::mm(5).toString( Units::MM );
|
||||
}
|
||||
|
||||
mInstance->beginGroup( "Grid" );
|
||||
QString spacingString = mInstance->value( "spacing", defaultSpacingString ).toString();
|
||||
mInstance->endGroup();
|
||||
|
||||
return Distance::fromString( spacingString );
|
||||
}
|
||||
|
||||
|
||||
void Settings::setGridSpacing( Distance spacing )
|
||||
{
|
||||
QString spacingString = spacing.toString( Settings::units() );
|
||||
|
||||
mInstance->beginGroup( "Grid" );
|
||||
mInstance->setValue( "spacing", spacingString );
|
||||
mInstance->endGroup();
|
||||
|
||||
emit mInstance->changed();
|
||||
}
|
||||
|
||||
|
||||
void Settings::resetGridSpacing()
|
||||
{
|
||||
mInstance->beginGroup( "Grid" );
|
||||
mInstance->remove( "spacing" );
|
||||
mInstance->endGroup();
|
||||
|
||||
emit mInstance->changed();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -43,7 +43,8 @@ namespace glabels
|
||||
|
||||
public:
|
||||
enum PageSizeFamily { ISO, US, };
|
||||
|
||||
enum GridOrigin { ORIGIN_TL, ORIGIN_CENTER };
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
@@ -101,6 +102,13 @@ namespace glabels
|
||||
static QString recentPrinter();
|
||||
static void setRecentPrinter( const QString& printer );
|
||||
|
||||
static GridOrigin gridOrigin();
|
||||
static void setGridOrigin( GridOrigin origin );
|
||||
|
||||
static Distance gridSpacing();
|
||||
static void setGridSpacing( Distance spacing );
|
||||
static void resetGridSpacing();
|
||||
|
||||
|
||||
private:
|
||||
static Settings* mInstance;
|
||||
|
||||
@@ -528,6 +528,34 @@
|
||||
<source>Picas</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Grid</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Configure grid behavior.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Origin</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Center</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Spacing</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Top left corner</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Reset</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>PrintView</name>
|
||||
|
||||
Reference in New Issue
Block a user