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 47 48 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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/******************************************************************************
*
* Copyright (C) 2002 Hugo PEREIRA <mailto: hugo.pereira@free.fr>
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This software 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 General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
*******************************************************************************/
#include "HelpDialog.h"
#include "HelpManager.h"
#include "HelpManager.h"
#include "HelpModel.h"
#include "QuestionDialog.h"
#include "Singleton.h"
#include "TextEditor.h"
#include "TextEditionDelegate.h"
#include "TreeView.h"
#include "XmlOptions.h"
#include <QAction>
#include <QHeaderView>
#include <QLayout>
#include <QPushButton>
#include <QToolButton>
#include <QShortcut>
#include <QTextStream>
namespace Base
{
//_________________________________________________________
HelpDialog::HelpDialog( HelpManager& manager, QWidget *parent ):
CustomDialog( parent, CloseButton ),
manager_( &manager )
{
Debug::Throw( "HelpDialog::HelpDialog.\n" );
// customize layout
layout()->setMargin(0);
layout()->setSpacing(0);
buttonLayout().setMargin(5);
// tell dialog to delete when close
setAttribute( Qt::WA_DeleteOnClose );
setOptionName( "HELP_DIALOG" );
QHBoxLayout *layout = new QHBoxLayout();
layout->setMargin(0);
layout->setSpacing(2);
mainLayout().addLayout( layout );
// add help list
list_ = new TreeView( this );
list_->setMaximumWidth(150);
layout->addWidget( list_ );
list_->setModel( &model_ );
list_->setSortingEnabled( false );
list_->header()->hide();
// stack widget to switch between html and plain text editor
layout->addWidget( htmlFrame_ = new QWidget( this ) );
// vbox layout for editor and button
QVBoxLayout *vLayout = new QVBoxLayout();
vLayout->setMargin(0);
htmlFrame_->setLayout( vLayout );
vLayout->addWidget( htmlEditor_ = new TextEditor( htmlFrame_ ) );
htmlEditor_->setReadOnly( true );
htmlEditor_->setWrapFromOptions( false );
htmlEditor_->wrapModeAction().setChecked( true );
// connect list to text edit
connect( list_->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(_display(QModelIndex,QModelIndex)) );
// add close accelerator
connect( new QShortcut( QKeySequence::Quit, this ), SIGNAL(activated()), SLOT(close()) );
connect( Singleton::get().application(), SIGNAL(configurationChanged()), SLOT(_updateConfiguration()) );
_updateConfiguration();
}
//_________________________________________________________
void HelpDialog::setItems( const HelpItem::List& items )
{
Debug::Throw( "HelpDialog::setItems.\n" );
// clear list and editors
htmlEditor_->clear();
// set items
model_.set( items );
// select first index
if( (!list_->selectionModel()->currentIndex().isValid()) && model_.hasIndex(0,0) )
{ list_->selectionModel()->setCurrentIndex( model_.index(0,0), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows ); }
return;
}
//_________________________________________________________
void HelpDialog::_display( const QModelIndex& current, const QModelIndex& previous )
{
Debug::Throw( "HelpDialog::_Display.\n" );
// check validity
if( !current.isValid() ) htmlEditor_->clear();
else {
// retrieve item
const HelpItem& item( model_.get( current ) );
htmlEditor_->setHtml( item.text() );
}
return;
}
//_________________________________________________________
void HelpDialog::_updateConfiguration( void )
{
Debug::Throw( "HelpDialog::_updateConfiguration.\n" );
htmlEditor_->setFont( qApp->font() );
}
}
|