WQtMessageDialog.cpp 3.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

#include <iostream>

#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>

#include "WMainWindow.h"

#include "WQtMessageDialog.h"
#include "WQtMessageDialog.moc"

WQtMessageDialog::WQtMessageDialog( QString msgID, QString title, QWidget* content, QSettings& settings, QWidget* parent ): // NOLINT - yes use a non-const ref
    QDialog( parent ),
    m_content( content ),
    m_msgID( msgID ),
    m_settings( settings )
{
    setWindowTitle( title );
    setModal( false );

    // setup contents
    QVBoxLayout* mainLayout = new QVBoxLayout();

47 48
    // text widget. Force stretching the content instead of the button bar
    mainLayout->addWidget( m_content, 100 );
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

    // dialog buttons and checkbox to bottom layout
    QHBoxLayout* bottomLayout = new QHBoxLayout();
    QWidget* bottomWidget = new QWidget( this );
    bottomWidget->setLayout( bottomLayout );
    mainLayout->addWidget( bottomWidget );
    this->setLayout( mainLayout );

    m_checkBox = new QCheckBox( bottomWidget );
    m_checkBox->setText( "Do not show again" );
    m_buttonBox = new QDialogButtonBox( bottomWidget );
    m_buttonBox->setOrientation( Qt::Horizontal );
    m_buttonBox->setStandardButtons( QDialogButtonBox::Ok );
    bottomLayout->addWidget( m_checkBox );
    bottomLayout->addWidget( m_buttonBox );

    // connect dialog box to close event
    QObject::connect( m_buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
    QObject::connect( m_buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
}

WQtMessageDialog::~WQtMessageDialog()
{
    // cleanup
}

void WQtMessageDialog::show()
76 77 78 79 80
{
    show( false );  // NOTE: this also calls QDialog::show.
}

void WQtMessageDialog::show( bool force )
81 82 83 84 85
{
    // check if message is allowed
    bool show = m_settings.value( m_msgID + "_showAgain", true ).toBool();
    m_checkBox->setCheckState( show ? Qt::Unchecked : Qt::Checked );

86 87 88 89
    // forced to show?
    // NOTE: we set the m_checkBox earlier to keep the old showAgain state
    show = show || force;

90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
    // only show if wanted by user
    if( !show )
    {
        return;
    }

    QDialog::show();
}

void WQtMessageDialog::reject()
{
    QDialog::reject();
}

void WQtMessageDialog::accept()
{
    handleClose();
    QDialog::accept();
}

void WQtMessageDialog::handleClose()
{
    m_settings.setValue( m_msgID + "_showAgain", m_checkBox->checkState() == Qt::Unchecked );
}