Skip to content

Commit b7612f2

Browse files
committedJan 17, 2014
UI: dialog base: add current category to dialog title
1 parent 8b6d180 commit b7612f2

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed
 

‎src/gui/qgsoptionsdialogbase.cpp

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929

3030

3131
QgsOptionsDialogBase::QgsOptionsDialogBase( QString settingsKey, QWidget* parent, Qt::WFlags fl )
32-
: QDialog( parent, fl ), mOptsKey( settingsKey ), mInit( false )
32+
: QDialog( parent, fl )
33+
, mOptsKey( settingsKey )
34+
, mInit( false )
35+
, mDialogTitle( "" )
3336
{
3437
}
3538

@@ -46,6 +49,10 @@ QgsOptionsDialogBase::~QgsOptionsDialogBase()
4649

4750
void QgsOptionsDialogBase::initOptionsBase( bool restoreUi )
4851
{
52+
// save original dialog title so it can be used to be concatenated
53+
// with category title in icon-only mode
54+
mDialogTitle = windowTitle();
55+
4956
// don't add to dialog margins
5057
// redefine now, or those in inherited .ui file will be added
5158
if ( layout() )
@@ -68,7 +75,10 @@ void QgsOptionsDialogBase::initOptionsBase( bool restoreUi )
6875

6976
QSettings settings;
7077
int size = settings.value( "/IconSize", 24 ).toInt();
71-
mOptListWidget->setIconSize( QSize( size, size ) );
78+
// buffer size to match displayed icon size in toolbars, and expected geometry restore
79+
// newWidth (above) may need adjusted if you adjust iconBuffer here
80+
int iconBuffer = 4;
81+
mOptListWidget->setIconSize( QSize( size + iconBuffer, size + iconBuffer ) );
7282
mOptListWidget->setFrameStyle( QFrame::NoFrame );
7383

7484
optionsFrame->layout()->setContentsMargins( 0, 3, 3, 3 );
@@ -109,6 +119,9 @@ void QgsOptionsDialogBase::restoreOptionsBaseUi()
109119
return;
110120
}
111121

122+
// re-save original dialog title in case it was changed after dialog initialization
123+
mDialogTitle = windowTitle();
124+
112125
QSettings settings;
113126
restoreGeometry( settings.value( QString( "/Windows/%1/geometry" ).arg( mOptsKey ) ).toByteArray() );
114127
// mOptListWidget width is fixed to take up less space in QtDesigner
@@ -148,6 +161,7 @@ void QgsOptionsDialogBase::showEvent( QShowEvent* e )
148161
if ( mInit )
149162
{
150163
updateOptionsListVerticalTabs();
164+
optionsStackedWidget_CurrentChanged( mOptListWidget->currentRow() );
151165
}
152166
else
153167
{
@@ -179,23 +193,25 @@ void QgsOptionsDialogBase::updateOptionsListVerticalTabs()
179193
int snapToIconWidth = iconWidth + 32;
180194

181195
QList<int> splitSizes = mOptSplitter->sizes();
182-
bool iconOnly = ( splitSizes.at( 0 ) <= snapToIconWidth );
196+
mIconOnly = ( splitSizes.at( 0 ) <= snapToIconWidth );
183197

184-
int newWidth = mOptListWidget->verticalScrollBar()->isVisible() ? iconWidth + 26 : iconWidth + 12;
198+
// iconBuffer (above) may need adjusted if you adjust iconWidth here
199+
int newWidth = mOptListWidget->verticalScrollBar()->isVisible() ? iconWidth + 22 : iconWidth + 9;
185200
bool diffWidth = mOptListWidget->minimumWidth() != newWidth;
186201

187202
if ( diffWidth )
188203
mOptListWidget->setMinimumWidth( newWidth );
189204

190-
if ( iconOnly && ( diffWidth || mOptListWidget->width() != newWidth ) )
205+
if ( mIconOnly && ( diffWidth || mOptListWidget->width() != newWidth ) )
191206
{
192207
splitSizes[1] = splitSizes.at( 1 ) - ( splitSizes.at( 0 ) - newWidth );
193208
splitSizes[0] = newWidth;
194209
mOptSplitter->setSizes( splitSizes );
195210
}
196-
if ( mOptListWidget->wordWrap() && iconOnly )
211+
212+
if ( mOptListWidget->wordWrap() && mIconOnly )
197213
mOptListWidget->setWordWrap( false );
198-
if ( !mOptListWidget->wordWrap() && !iconOnly )
214+
if ( !mOptListWidget->wordWrap() && !mIconOnly )
199215
mOptListWidget->setWordWrap( true );
200216
}
201217

@@ -204,6 +220,16 @@ void QgsOptionsDialogBase::optionsStackedWidget_CurrentChanged( int indx )
204220
mOptListWidget->blockSignals( true );
205221
mOptListWidget->setCurrentRow( indx );
206222
mOptListWidget->blockSignals( false );
223+
224+
QListWidgetItem *curitem = mOptListWidget->currentItem();
225+
if ( curitem )
226+
{
227+
setWindowTitle( QString( "%1 - %2" ).arg( mDialogTitle ).arg( curitem->text() ) );
228+
}
229+
else
230+
{
231+
setWindowTitle( mDialogTitle );
232+
}
207233
}
208234

209235
void QgsOptionsDialogBase::optionsStackedWidget_WidgetRemoved( int indx )

‎src/gui/qgsoptionsdialogbase.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,14 @@ class GUI_EXPORT QgsOptionsDialogBase : public QDialog
6464

6565
/** Restore the base ui.
6666
* Sometimes useful to do at end of subclass's constructor.
67+
* e.g. if setWindowTitle is used after initOptionsBase.
6768
*/
6869
void restoreOptionsBaseUi();
6970

71+
/** determine if the options list is in icon only mode
72+
*/
73+
bool iconOnly() {return mIconOnly;}
74+
7075
protected slots:
7176
void updateOptionsListVerticalTabs();
7277
void optionsStackedWidget_CurrentChanged( int indx );
@@ -83,6 +88,8 @@ class GUI_EXPORT QgsOptionsDialogBase : public QDialog
8388
QStackedWidget* mOptStackedWidget;
8489
QSplitter* mOptSplitter;
8590
QDialogButtonBox* mOptButtonBox;
91+
QString mDialogTitle;
92+
bool mIconOnly;
8693
};
8794

8895
#endif // QGSOPTIONSDIALOGBASE_H

0 commit comments

Comments
 (0)
Please sign in to comment.