Skip to content

Commit

Permalink
Use QgsFontButton everywhere we can
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 6, 2017
1 parent 0fd1f8e commit 43f11f4
Show file tree
Hide file tree
Showing 28 changed files with 510 additions and 308 deletions.
48 changes: 24 additions & 24 deletions src/app/composer/qgscomposerattributetablewidget.cpp
Expand Up @@ -40,6 +40,9 @@ QgsComposerAttributeTableWidget::QgsComposerAttributeTableWidget( QgsComposerAtt
setupUi( this );
setPanelTitle( tr( "Table properties" ) );

mContentFontToolButton->setMode( QgsFontButton::ModeQFont );
mHeaderFontToolButton->setMode( QgsFontButton::ModeQFont );

blockAllSignals( true );

mResizeModeComboBox->addItem( tr( "Use existing frames" ), QgsComposerMultiFrame::UseExistingFrames );
Expand Down Expand Up @@ -106,6 +109,9 @@ QgsComposerAttributeTableWidget::QgsComposerAttributeTableWidget( QgsComposerAtt
QgsComposerItemWidget *itemPropertiesWidget = new QgsComposerItemWidget( this, mFrame );
mainLayout->addWidget( itemPropertiesWidget );
}

connect( mHeaderFontToolButton, &QgsFontButton::changed, this, &QgsComposerAttributeTableWidget::headerFontChanged );
connect( mContentFontToolButton, &QgsFontButton::changed, this, &QgsComposerAttributeTableWidget::contentFontChanged );
}

QgsComposerAttributeTableWidget::~QgsComposerAttributeTableWidget()
Expand Down Expand Up @@ -238,24 +244,19 @@ void QgsComposerAttributeTableWidget::on_mMarginSpinBox_valueChanged( double d )
}
}

void QgsComposerAttributeTableWidget::on_mHeaderFontPushButton_clicked()
void QgsComposerAttributeTableWidget::headerFontChanged()
{
if ( !mComposerTable )
return;

bool ok;
QFont newFont = QgsGuiUtils::getFont( ok, mComposerTable->headerFont(), tr( "Select Font" ) );
if ( ok )
{
QgsComposition *composition = mComposerTable->composition();
if ( composition )
composition->beginMultiFrameCommand( mComposerTable, tr( "Table header font" ) );
QgsComposition *composition = mComposerTable->composition();
if ( composition )
composition->beginMultiFrameCommand( mComposerTable, tr( "Table header font" ) );

mComposerTable->setHeaderFont( newFont );
mComposerTable->setHeaderFont( mHeaderFontToolButton->currentFont() );

if ( composition )
composition->endMultiFrameCommand();
}
if ( composition )
composition->endMultiFrameCommand();
}

void QgsComposerAttributeTableWidget::on_mHeaderFontColorButton_colorChanged( const QColor &newColor )
Expand All @@ -277,26 +278,21 @@ void QgsComposerAttributeTableWidget::on_mHeaderFontColorButton_colorChanged( co
}
}

void QgsComposerAttributeTableWidget::on_mContentFontPushButton_clicked()
void QgsComposerAttributeTableWidget::contentFontChanged()
{
if ( !mComposerTable )
{
return;
}

bool ok;
QFont newFont = QgsGuiUtils::getFont( ok, mComposerTable->contentFont(), tr( "Select Font" ) );
if ( ok )
{
QgsComposition *composition = mComposerTable->composition();
if ( composition )
composition->beginMultiFrameCommand( mComposerTable, tr( "Table content font" ) );
QgsComposition *composition = mComposerTable->composition();
if ( composition )
composition->beginMultiFrameCommand( mComposerTable, tr( "Table content font" ) );

mComposerTable->setContentFont( newFont );
mComposerTable->setContentFont( mContentFontToolButton->currentFont() );

if ( composition )
composition->endMultiFrameCommand();
}
if ( composition )
composition->endMultiFrameCommand();
}

void QgsComposerAttributeTableWidget::on_mContentFontColorButton_colorChanged( const QColor &newColor )
Expand Down Expand Up @@ -479,6 +475,8 @@ void QgsComposerAttributeTableWidget::updateGuiElements()

mHeaderFontColorButton->setColor( mComposerTable->headerFontColor() );
mContentFontColorButton->setColor( mComposerTable->contentFontColor() );
mHeaderFontToolButton->setCurrentFont( mComposerTable->headerFont() );
mContentFontToolButton->setCurrentFont( mComposerTable->contentFont() );

if ( mComposerTable->displayOnlyVisibleFeatures() && mShowOnlyVisibleFeaturesCheckBox->isEnabled() )
{
Expand Down Expand Up @@ -628,6 +626,8 @@ void QgsComposerAttributeTableWidget::blockAllSignals( bool b )
mDrawEmptyCheckBox->blockSignals( b );
mWrapStringLineEdit->blockSignals( b );
mWrapBehaviorComboBox->blockSignals( b );
mContentFontToolButton->blockSignals( b );
mHeaderFontToolButton->blockSignals( b );
}

void QgsComposerAttributeTableWidget::setMaximumNumberOfFeatures( int n )
Expand Down
4 changes: 2 additions & 2 deletions src/app/composer/qgscomposerattributetablewidget.h
Expand Up @@ -51,9 +51,9 @@ class QgsComposerAttributeTableWidget: public QgsComposerItemBaseWidget, private
void on_mGridStrokeWidthSpinBox_valueChanged( double d );
void on_mGridColorButton_colorChanged( const QColor &newColor );
void on_mBackgroundColorButton_colorChanged( const QColor &newColor );
void on_mHeaderFontPushButton_clicked();
void headerFontChanged();
void on_mHeaderFontColorButton_colorChanged( const QColor &newColor );
void on_mContentFontPushButton_clicked();
void contentFontChanged();
void on_mContentFontColorButton_colorChanged( const QColor &newColor );
void on_mDrawHorizontalGrid_toggled( bool state );
void on_mDrawVerticalGrid_toggled( bool state );
Expand Down
24 changes: 12 additions & 12 deletions src/app/composer/qgscomposerlabelwidget.cpp
Expand Up @@ -31,6 +31,8 @@ QgsComposerLabelWidget::QgsComposerLabelWidget( QgsComposerLabel *label ): QgsCo
setupUi( this );
setPanelTitle( tr( "Label properties" ) );

mFontButton->setMode( QgsFontButton::ModeQFont );

//add widget for general composer item properties
QgsComposerItemWidget *itemPropertiesWidget = new QgsComposerItemWidget( this, label );
mainLayout->addWidget( itemPropertiesWidget );
Expand All @@ -46,6 +48,8 @@ QgsComposerLabelWidget::QgsComposerLabelWidget( QgsComposerLabel *label ): QgsCo
setGuiElementValues();
connect( mComposerLabel, &QgsComposerObject::itemChanged, this, &QgsComposerLabelWidget::setGuiElementValues );
}

connect( mFontButton, &QgsFontButton::changed, this, &QgsComposerLabelWidget::fontChanged );
}

void QgsComposerLabelWidget::on_mHtmlCheckBox_stateChanged( int state )
Expand Down Expand Up @@ -80,19 +84,15 @@ void QgsComposerLabelWidget::on_mTextEdit_textChanged()
}
}

void QgsComposerLabelWidget::on_mFontButton_clicked()
void QgsComposerLabelWidget::fontChanged()
{
if ( mComposerLabel )
{
bool ok;
QFont newFont = QgsGuiUtils::getFont( ok, mComposerLabel->font() );
if ( ok )
{
mComposerLabel->beginCommand( tr( "Label font changed" ) );
mComposerLabel->setFont( newFont );
mComposerLabel->update();
mComposerLabel->endCommand();
}
QFont newFont = mFontButton->currentFont();
mComposerLabel->beginCommand( tr( "Label font changed" ) );
mComposerLabel->setFont( newFont );
mComposerLabel->update();
mComposerLabel->endCommand();
}
}

Expand Down Expand Up @@ -243,8 +243,7 @@ void QgsComposerLabelWidget::setGuiElementValues()
mCenterRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignHCenter );
mRightRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignRight );
mFontColorButton->setColor( mComposerLabel->fontColor() );


mFontButton->setCurrentFont( mComposerLabel->font() );
mVerticalAlignementLabel->setDisabled( mComposerLabel->htmlState() );
mTopRadioButton->setDisabled( mComposerLabel->htmlState() );
mMiddleRadioButton->setDisabled( mComposerLabel->htmlState() );
Expand All @@ -266,4 +265,5 @@ void QgsComposerLabelWidget::blockAllSignals( bool block )
mCenterRadioButton->blockSignals( block );
mRightRadioButton->blockSignals( block );
mFontColorButton->blockSignals( block );
mFontButton->blockSignals( block );
}
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposerlabelwidget.h
Expand Up @@ -35,7 +35,6 @@ class QgsComposerLabelWidget: public QgsComposerItemBaseWidget, private Ui::QgsC
public slots:
void on_mHtmlCheckBox_stateChanged( int i );
void on_mTextEdit_textChanged();
void on_mFontButton_clicked();
void on_mInsertExpressionButton_clicked();
void on_mMarginXDoubleSpinBox_valueChanged( double d );
void on_mMarginYDoubleSpinBox_valueChanged( double d );
Expand All @@ -49,6 +48,7 @@ class QgsComposerLabelWidget: public QgsComposerItemBaseWidget, private Ui::QgsC

private slots:
void setGuiElementValues();
void fontChanged();

private:
QgsComposerLabel *mComposerLabel = nullptr;
Expand Down
86 changes: 42 additions & 44 deletions src/app/composer/qgscomposerlegendwidget.cpp
Expand Up @@ -63,6 +63,11 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend *legend )
setupUi( this );
setPanelTitle( tr( "Legend properties" ) );

mTitleFontButton->setMode( QgsFontButton::ModeQFont );
mGroupFontButton->setMode( QgsFontButton::ModeQFont );
mLayerFontButton->setMode( QgsFontButton::ModeQFont );
mItemFontButton->setMode( QgsFontButton::ModeQFont );

// setup icons
mAddToolButton->setIcon( QIcon( QgsApplication::iconPath( "symbologyAdd.svg" ) ) );
mEditPushButton->setIcon( QIcon( QgsApplication::iconPath( "symbologyEdit.png" ) ) );
Expand Down Expand Up @@ -108,6 +113,10 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend *legend )

connect( mItemTreeView->selectionModel(), &QItemSelectionModel::currentChanged,
this, &QgsComposerLegendWidget::selectedChanged );
connect( mTitleFontButton, &QgsFontButton::changed, this, &QgsComposerLegendWidget::titleFontChanged );
connect( mGroupFontButton, &QgsFontButton::changed, this, &QgsComposerLegendWidget::groupFontChanged );
connect( mLayerFontButton, &QgsFontButton::changed, this, &QgsComposerLegendWidget::layerFontChanged );
connect( mItemFontButton, &QgsFontButton::changed, this, &QgsComposerLegendWidget::itemFontChanged );
}

QgsComposerLegendWidget::QgsComposerLegendWidget(): QgsComposerItemBaseWidget( nullptr, nullptr ), mLegend( nullptr )
Expand Down Expand Up @@ -162,6 +171,11 @@ void QgsComposerLegendWidget::setGuiElements()
const QgsComposerMap *map = mLegend->composerMap();
mMapComboBox->setItem( map );
mFontColorButton->setColor( mLegend->fontColor() );
mTitleFontButton->setCurrentFont( mLegend->style( QgsLegendStyle::Title ).font() );
mGroupFontButton->setCurrentFont( mLegend->style( QgsLegendStyle::Group ).font() );
mLayerFontButton->setCurrentFont( mLegend->style( QgsLegendStyle::Subgroup ).font() );
mItemFontButton->setCurrentFont( mLegend->style( QgsLegendStyle::SymbolLabel ).font() );

blockAllSignals( false );

on_mCheckBoxAutoUpdate_stateChanged( mLegend->autoUpdateModel() ? Qt::Checked : Qt::Unchecked );
Expand Down Expand Up @@ -353,71 +367,51 @@ void QgsComposerLegendWidget::on_mIconLabelSpaceSpinBox_valueChanged( double d )
}
}

void QgsComposerLegendWidget::on_mTitleFontButton_clicked()
void QgsComposerLegendWidget::titleFontChanged()
{
if ( mLegend )
{
bool ok;
QFont newFont = QgsGuiUtils::getFont( ok, mLegend->style( QgsLegendStyle::Title ).font() );
if ( ok )
{
mLegend->beginCommand( tr( "Title font changed" ) );
mLegend->setStyleFont( QgsLegendStyle::Title, newFont );
mLegend->adjustBoxSize();
mLegend->update();
mLegend->endCommand();
}
mLegend->beginCommand( tr( "Title font changed" ) );
mLegend->setStyleFont( QgsLegendStyle::Title, mTitleFontButton->currentFont() );
mLegend->adjustBoxSize();
mLegend->update();
mLegend->endCommand();
}
}

void QgsComposerLegendWidget::on_mGroupFontButton_clicked()
void QgsComposerLegendWidget::groupFontChanged()
{
if ( mLegend )
{
bool ok;
QFont newFont = QgsGuiUtils::getFont( ok, mLegend->style( QgsLegendStyle::Group ).font() );
if ( ok )
{
mLegend->beginCommand( tr( "Legend group font changed" ) );
mLegend->setStyleFont( QgsLegendStyle::Group, newFont );
mLegend->adjustBoxSize();
mLegend->update();
mLegend->endCommand();
}
mLegend->beginCommand( tr( "Legend group font changed" ) );
mLegend->setStyleFont( QgsLegendStyle::Group, mGroupFontButton->currentFont() );
mLegend->adjustBoxSize();
mLegend->update();
mLegend->endCommand();
}
}

void QgsComposerLegendWidget::on_mLayerFontButton_clicked()
void QgsComposerLegendWidget::layerFontChanged()
{
if ( mLegend )
{
bool ok;
QFont newFont = QgsGuiUtils::getFont( ok, mLegend->style( QgsLegendStyle::Subgroup ).font() );
if ( ok )
{
mLegend->beginCommand( tr( "Legend layer font changed" ) );
mLegend->setStyleFont( QgsLegendStyle::Subgroup, newFont );
mLegend->adjustBoxSize();
mLegend->update();
mLegend->endCommand();
}
mLegend->beginCommand( tr( "Legend layer font changed" ) );
mLegend->setStyleFont( QgsLegendStyle::Subgroup, mLayerFontButton->currentFont() );
mLegend->adjustBoxSize();
mLegend->update();
mLegend->endCommand();
}
}

void QgsComposerLegendWidget::on_mItemFontButton_clicked()
void QgsComposerLegendWidget::itemFontChanged()
{
if ( mLegend )
{
bool ok;
QFont newFont = QgsGuiUtils::getFont( ok, mLegend->style( QgsLegendStyle::SymbolLabel ).font() );
if ( ok )
{
mLegend->beginCommand( tr( "Legend item font changed" ) );
mLegend->setStyleFont( QgsLegendStyle::SymbolLabel, newFont );
mLegend->adjustBoxSize();
mLegend->update();
mLegend->endCommand();
}
mLegend->beginCommand( tr( "Legend item font changed" ) );
mLegend->setStyleFont( QgsLegendStyle::SymbolLabel, mItemFontButton->currentFont() );
mLegend->adjustBoxSize();
mLegend->update();
mLegend->endCommand();
}
}

Expand Down Expand Up @@ -939,6 +933,10 @@ void QgsComposerLegendWidget::blockAllSignals( bool b )
mCheckboxResizeContents->blockSignals( b );
mTitleSpaceBottomSpinBox->blockSignals( b );
mFilterLegendByAtlasCheckBox->blockSignals( b );
mTitleFontButton->blockSignals( b );
mGroupFontButton->blockSignals( b );
mLayerFontButton->blockSignals( b );
mItemFontButton->blockSignals( b );
}

void QgsComposerLegendWidget::selectedChanged( const QModelIndex &current, const QModelIndex &previous )
Expand Down
8 changes: 4 additions & 4 deletions src/app/composer/qgscomposerlegendwidget.h
Expand Up @@ -59,10 +59,6 @@ class QgsComposerLegendWidget: public QgsComposerItemBaseWidget, private Ui::Qgs
void on_mLayerSpaceSpinBox_valueChanged( double d );
void on_mSymbolSpaceSpinBox_valueChanged( double d );
void on_mIconLabelSpaceSpinBox_valueChanged( double d );
void on_mTitleFontButton_clicked();
void on_mGroupFontButton_clicked();
void on_mLayerFontButton_clicked();
void on_mItemFontButton_clicked();
void on_mFontColorButton_colorChanged( const QColor &newFontColor );
void on_mBoxSpaceSpinBox_valueChanged( double d );
void on_mColumnSpaceSpinBox_valueChanged( double d );
Expand Down Expand Up @@ -102,6 +98,10 @@ class QgsComposerLegendWidget: public QgsComposerItemBaseWidget, private Ui::Qgs
void updateFilterLegendByAtlasButton();

void on_mItemTreeView_doubleClicked( const QModelIndex &index );
void titleFontChanged();
void groupFontChanged();
void layerFontChanged();
void itemFontChanged();

private:
QgsComposerLegendWidget();
Expand Down

0 comments on commit 43f11f4

Please sign in to comment.