~ubuntu-branches/ubuntu/raring/openwalnut/raring

« back to all changes in this revision

Viewing changes to src/qt4gui/qt4/WSettingMenu.cpp

  • Committer: Package Import Robot
  • Author(s): Sebastian Eichelbaum
  • Date: 2012-12-12 11:26:32 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20121212112632-xhiuwkxuz5h0idkh
Tags: 1.3.1+hg5849-1
* Minor changes compared to 1.3.0 but included several bug fixes.
* See http://www.openwalnut.org/versions/4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//---------------------------------------------------------------------------
2
 
//
3
 
// Project: OpenWalnut ( http://www.openwalnut.org )
4
 
//
5
 
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
 
// For more information see http://www.openwalnut.org/copying
7
 
//
8
 
// This file is part of OpenWalnut.
9
 
//
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.
14
 
//
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.
19
 
//
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/>.
22
 
//
23
 
//---------------------------------------------------------------------------
24
 
 
25
 
#include <QtGui/QMessageBox>
26
 
 
27
 
#include "WQt4Gui.h"
28
 
#include "WMainWindow.h"
29
 
 
30
 
#include "WSettingMenu.h"
31
 
#include "WSettingMenu.moc"
32
 
 
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 )
38
 
{
39
 
    m_currentItem = WQt4Gui::getSettings().value( m_settingName, defaultValue ).toUInt();
40
 
 
41
 
    // setup this menu
42
 
    setToolTip( QString::fromStdString( tooltip ) );
43
 
 
44
 
    QActionGroup* actionGroup = new QActionGroup( parent );
45
 
 
46
 
    // add an action for each option to the menu and the action group
47
 
    unsigned int i = 0;
48
 
    for( QList< QString >::const_iterator iter = options.begin(); iter != options.end(); ++iter )
49
 
    {
50
 
        QAction* action = new QAction( *iter, parent );
51
 
        action->setCheckable( true );
52
 
        action->setData( i );
53
 
        action->setActionGroup( actionGroup );
54
 
        addAction( action );
55
 
 
56
 
        // is this currently active?
57
 
        if( i == m_currentItem )
58
 
        {
59
 
            action->setChecked( true );
60
 
        }
61
 
 
62
 
        ++i;
63
 
    }
64
 
 
65
 
    // get notified about changes
66
 
    connect( actionGroup, SIGNAL( triggered( QAction* ) ), this, SLOT( handleUpdate( QAction* ) ) );
67
 
}
68
 
 
69
 
WSettingMenu::~WSettingMenu()
70
 
{
71
 
}
72
 
 
73
 
void WSettingMenu::handleUpdate( QAction* action )
74
 
{
75
 
    // update setting and emit signal
76
 
    m_currentItem = action->data().toUInt();
77
 
    WQt4Gui::getSettings().setValue( m_settingName, m_currentItem );
78
 
 
79
 
    // does this setting require restart?
80
 
    if( m_showRestartInfo )
81
 
    {
82
 
        QMessageBox::information( WQt4Gui::getMainWindow(), QString( "Restart required" ), QString( "This setting is applied after restart." ) );
83
 
    }
84
 
 
85
 
    emit change( m_currentItem );
86
 
}
87
 
 
88
 
unsigned int WSettingMenu::get() const
89
 
{
90
 
    return m_currentItem;
91
 
}
92