Skip to content
Permalink
Browse files
[FEATURE] Add custom group box settings to Options
- Add options to set group box title to bold, and to draw platform-consistent custom border and background
- Useful for group boxes on Ubuntu (default have no borders/backgrounds) and Mac (default are a bit funky-looking)
- NOT tested yet on Windows
  • Loading branch information
dakcarto committed Jan 21, 2013
1 parent 2231971 commit 181a7393c15b80c03e608e8e8bd38529d1338c50
Showing with 134 additions and 27 deletions.
  1. +51 −3 src/app/qgisappstylesheet.cpp
  2. +22 −6 src/app/qgsoptions.cpp
  3. +10 −0 src/app/qgsoptions.h
  4. +9 −1 src/gui/qgscollapsiblegroupbox.cpp
  5. +42 −17 src/ui/qgsoptionsbase.ui
@@ -87,7 +87,7 @@ QMap<QString, QVariant> QgisAppStyleSheet::defaultOptions()
mDefaultFont = qApp->font(); // save before it is changed in any way

// the following default values, before insertion in opts, can be
// configured using the platform(s) and window server(s) defined in the
// configured using the platforms and window servers defined in the
// constructor to set reasonable non-Qt defaults for the app stylesheet
QSettings settings;
// handle move from old QSettings group (/) to new (/qgis/stylesheet)
@@ -130,7 +130,13 @@ QMap<QString, QVariant> QgisAppStyleSheet::defaultOptions()
QgsDebugMsg( QString( "fontFamily: %1" ).arg( fontFamily ) );
opts.insert( "fontFamily", QVariant( fontFamily ) );

settings.endGroup();
bool gbxCustom = false;
opts.insert( "groupBoxCustom", settings.value( "groupBoxCustom", QVariant( gbxCustom ) ) );

bool gbxBoldTitle = false;
opts.insert( "groupBoxBoldTitle", settings.value( "groupBoxBoldTitle", QVariant( gbxBoldTitle ) ) );

settings.endGroup(); // "qgis/stylesheet"

return opts;
}
@@ -139,6 +145,8 @@ void QgisAppStyleSheet::buildStyleSheet( const QMap<QString, QVariant>& opts )
{
QString ss = QString( "" );


// QgisApp-wide font
QString fontSize = opts.value( "fontPointSize" ).toString();
QgsDebugMsg( QString( "fontPointSize: %1" ).arg( fontSize ) );
if ( fontSize.isEmpty() ) { return; }
@@ -149,6 +157,46 @@ void QgisAppStyleSheet::buildStyleSheet( const QMap<QString, QVariant>& opts )

ss += QString( "* { font: %1pt \"%2\"} " ).arg( fontSize ).arg( fontFamily );

// QGroupBox and QgsCollapsibleGroupBox, mostly for Ubuntu and Mac
// TODO: test on/adjust for Windows
bool gbxCustom = opts.value( "groupBoxCustom" ).toBool();
QgsDebugMsg( QString( "groupBoxCustom: %1" ).arg( gbxCustom ) );
bool gbxBoldTitle = opts.value( "groupBoxBoldTitle" ).toBool();
QgsDebugMsg( QString( "groupBoxBoldTitle: %1" ).arg( gbxBoldTitle ) );
if ( gbxCustom || gbxBoldTitle )
{
ss += "QGroupBox{";
if ( gbxBoldTitle )
{
// doesn't work for QGroupBox::title
ss += QString( "color: rgb(%1,%1,%1);" ).arg( mMacWS ? 25 : 60 );
ss += "font-weight: bold;";
}
if ( gbxCustom )
{
ss += QString( "background-color: rgba(%1,%1,%1,90%);" ).arg( mMacWS ? 225 : 235 );
ss += "border: 1px solid #c0c0c0;";
ss += "border-radius: 5px;";
ss += "margin-top: 2.5ex;";
ss += QString( "margin-bottom: %1ex;" ).arg( mMacWS ? 1.5 : 1 );
}
ss += "} ";
if ( gbxCustom )
{
ss += "QGroupBox:flat{";
ss += "background-color: rgba(0,0,0,0);";
ss += "border: rgba(0,0,0,0);";
ss += "} ";

ss += "QGroupBox::title{";
ss += "subcontrol-origin: margin;";
ss += "subcontrol-position: top left;";
ss += "margin-left: 6px;";
ss += "background-color: rgba(0,0,0,0);";
ss += "} ";
}
}

QgsDebugMsg( QString( "Stylesheet built: %1" ).arg( ss ) );

emit appStyleSheetChanged( ss );
@@ -165,5 +213,5 @@ void QgisAppStyleSheet::saveToSettings( const QMap<QString, QVariant>& opts )
settings.setValue( QString( opt.key() ), opt.value() );
++opt;
}
settings.endGroup();
settings.endGroup(); // "qgis/stylesheet"
}
@@ -455,8 +455,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
mFontFamilyRadioCustom->blockSignals( true );
mFontFamilyComboBox->blockSignals( true );

spinFontSize->setValue( mStyleSheetNewOpts.value( "fontPointSize" ).toInt() );
QString fontFamily = mStyleSheetNewOpts.value( "fontFamily" ).toString();
spinFontSize->setValue( mStyleSheetOldOpts.value( "fontPointSize" ).toInt() );
QString fontFamily = mStyleSheetOldOpts.value( "fontFamily" ).toString();
bool isQtDefault = ( fontFamily == mStyleSheetBuilder->defaultFont().family() );
mFontFamilyRadioQt->setChecked( isQtDefault );
mFontFamilyRadioCustom->setChecked( !isQtDefault );
@@ -477,6 +477,10 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
mFontFamilyRadioCustom->blockSignals( false );
mFontFamilyComboBox->blockSignals( false );

// custom group boxes
mCustomGroupBoxChkBx->setChecked( mStyleSheetOldOpts.value( "groupBoxCustom" ).toBool() );
mBoldGroupBoxTitleChkBx->setChecked( mStyleSheetOldOpts.value( "groupBoxBoldTitle" ).toBool() );

mMessageTimeoutSpnBx->setValue( settings.value( "/qgis/messageTimeout", 5 ).toInt() );

QString name = QApplication::style()->objectName();
@@ -1247,15 +1251,15 @@ void QgsOptions::rejectOptions()

void QgsOptions::on_spinFontSize_valueChanged( int fontSize )
{
mStyleSheetNewOpts.insert( "fontPointSize", fontSize );
mStyleSheetNewOpts.insert( "fontPointSize", QVariant( fontSize ) );
mStyleSheetBuilder->buildStyleSheet( mStyleSheetNewOpts );
}

void QgsOptions::on_mFontFamilyRadioQt_released()
{
if ( mStyleSheetNewOpts.value( "fontFamily" ).toString() != mStyleSheetBuilder->defaultFont().family() )
{
mStyleSheetNewOpts.insert( "fontFamily", mStyleSheetBuilder->defaultFont().family() );
mStyleSheetNewOpts.insert( "fontFamily", QVariant( mStyleSheetBuilder->defaultFont().family() ) );
mStyleSheetBuilder->buildStyleSheet( mStyleSheetNewOpts );
}
}
@@ -1264,7 +1268,7 @@ void QgsOptions::on_mFontFamilyRadioCustom_released()
{
if ( mFontFamilyComboBox->currentFont().family() != mStyleSheetBuilder->defaultFont().family() )
{
mStyleSheetNewOpts.insert( "fontFamily", mFontFamilyComboBox->currentFont().family() );
mStyleSheetNewOpts.insert( "fontFamily", QVariant( mFontFamilyComboBox->currentFont().family() ) );
mStyleSheetBuilder->buildStyleSheet( mStyleSheetNewOpts );
}
}
@@ -1274,11 +1278,23 @@ void QgsOptions::on_mFontFamilyComboBox_currentFontChanged( const QFont& font )
if ( mFontFamilyRadioCustom->isChecked()
&& mStyleSheetNewOpts.value( "fontFamily" ).toString() != font.family() )
{
mStyleSheetNewOpts.insert( "fontFamily", font.family() );
mStyleSheetNewOpts.insert( "fontFamily", QVariant( font.family() ) );
mStyleSheetBuilder->buildStyleSheet( mStyleSheetNewOpts );
}
}

void QgsOptions::on_mCustomGroupBoxChkBx_clicked( bool chkd )
{
mStyleSheetNewOpts.insert( "groupBoxCustom", QVariant( chkd ) );
mStyleSheetBuilder->buildStyleSheet( mStyleSheetNewOpts );
}

void QgsOptions::on_mBoldGroupBoxTitleChkBx_clicked( bool chkd )
{
mStyleSheetNewOpts.insert( "groupBoxBoldTitle", QVariant( chkd ) );
mStyleSheetBuilder->buildStyleSheet( mStyleSheetNewOpts );
}

void QgsOptions::on_pbnSelectProjection_clicked()
{
QSettings settings;
@@ -108,6 +108,16 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
*/
void on_mFontFamilyComboBox_currentFontChanged( const QFont& font );

/** Slot to set whether to use custom group boxes
* @note added in QGIS 1.9
*/
void on_mCustomGroupBoxChkBx_clicked( bool chkd );

/** Slot to set whether to bold group box titles
* @note added in QGIS 1.9
*/
void on_mBoldGroupBoxTitleChkBx_clicked( bool chkd );

/*!
* Slot to select the default map selection color
*/
@@ -245,7 +245,15 @@ void QgsCollapsibleGroupBox::updateStyle()
int marginRight = 5; // a little bit of space on the right, to match space on the left
int offsetLeft = 0; // offset for oxygen theme
int offsetTop = 0;
int offsetTop2 = 0; // offset for triangle
// int offsetTop2 = 0; // offset for triangle

// starting top offset for custom groupboxes in app stylesheet
QStyleOptionGroupBox box;
initStyleOption( &box );
QRect rectCheckBox = style()->subControlRect( QStyle::CC_GroupBox, &box,
QStyle::SC_GroupBoxCheckBox, this );
int offsetTop2 = rectCheckBox.top(); // offset for triangle

This comment has been minimized.

Copy link
@dakcarto

dakcarto Jan 22, 2013

Author Member

Etienne,

This editing to QgsCollapsibleGroupBox may affect the layout for them in the Oxygen theme (which I can't test here). Can you verify?

Also, the new app stylesheet will now cause a collapsed (flat) QgsCollapsibleGroupBox to not show a line under it (i.e. the border should now be 0% alpha), if the new 'Use custom group boxes' is checked under Options-->General section, Application group. I think this looks better than any line showing up (which varies a lot between OSes).

Thanks


// calculate offset if frame overlaps triangle (oxygen theme)
// using an offset of 6 pixels from frame border
@@ -267,7 +267,7 @@
<x>0</x>
<y>0</y>
<width>654</width>
<height>522</height>
<height>529</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_28">
@@ -521,18 +521,43 @@
</layout>
</item>
<item>
<widget class="QCheckBox" name="cbxHideSplash">
<property name="text">
<string>Hide splash screen at startup</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbxShowTips">
<property name="text">
<string>Show tips at start up</string>
</property>
</widget>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="1" rowspan="2">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QCheckBox" name="mCustomGroupBoxChkBx">
<property name="text">
<string>Use custom group boxes</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="cbxShowTips">
<property name="text">
<string>Show tips at start up</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="mBoldGroupBoxTitleChkBx">
<property name="text">
<string>Bold group box titles</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="cbxHideSplash">
<property name="text">
<string>Hide splash screen at startup</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
@@ -1884,8 +1909,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>669</width>
<height>490</height>
<width>498</width>
<height>332</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_25">
@@ -2123,7 +2148,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>654</width>
<width>556</width>
<height>718</height>
</rect>
</property>
@@ -3413,7 +3438,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>654</width>
<width>521</width>
<height>650</height>
</rect>
</property>

0 comments on commit 181a739

Please sign in to comment.