1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
10
// OpenWalnut is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
15
// OpenWalnut is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Lesser General Public License for more details.
20
// You should have received a copy of the GNU Lesser General Public License
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
23
//---------------------------------------------------------------------------
25
#include <QtGui/QMessageBox>
28
#include "WMainWindow.h"
30
#include "WSettingMenu.h"
31
#include "WSettingMenu.moc"
33
WSettingMenu::WSettingMenu( QWidget* parent, std::string settingName, std::string menuName, std::string tooltip, unsigned int defaultValue,
34
const QList< QString >& options, bool showRestartInfo ):
35
QMenu( QString::fromStdString( menuName ), parent ),
36
m_settingName( QString::fromStdString( settingName ) ),
37
m_showRestartInfo( showRestartInfo )
39
m_currentItem = WQt4Gui::getSettings().value( m_settingName, defaultValue ).toUInt();
42
setToolTip( QString::fromStdString( tooltip ) );
44
QActionGroup* actionGroup = new QActionGroup( parent );
46
// add an action for each option to the menu and the action group
48
for( QList< QString >::const_iterator iter = options.begin(); iter != options.end(); ++iter )
50
QAction* action = new QAction( *iter, parent );
51
action->setCheckable( true );
53
action->setActionGroup( actionGroup );
56
// is this currently active?
57
if( i == m_currentItem )
59
action->setChecked( true );
65
// get notified about changes
66
connect( actionGroup, SIGNAL( triggered( QAction* ) ), this, SLOT( handleUpdate( QAction* ) ) );
69
WSettingMenu::~WSettingMenu()
73
void WSettingMenu::handleUpdate( QAction* action )
75
// update setting and emit signal
76
m_currentItem = action->data().toUInt();
77
WQt4Gui::getSettings().setValue( m_settingName, m_currentItem );
79
// does this setting require restart?
80
if( m_showRestartInfo )
82
QMessageBox::information( WQt4Gui::getMainWindow(), QString( "Restart required" ), QString( "This setting is applied after restart." ) );
85
emit change( m_currentItem );
88
unsigned int WSettingMenu::get() const