contexthelp.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2003-2005 by David Saxton                               *
00003  *   david@bluehaze.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #include "cnitem.h"
00012 #include "cnitemgroup.h"
00013 #include "contexthelp.h"
00014 #include "itemlibrary.h"
00015 #include "katemdi.h"
00016 
00017 #include <klocale.h>
00018 
00019 #include <qlayout.h>
00020 #include <qlabel.h>
00021 #include <qregexp.h>
00022 #include <qtextbrowser.h>
00023 #include <qwhatsthis.h>
00024 
00025 #include <cassert>
00026 
00027 ContextHelp * ContextHelp::m_pSelf = 0;
00028 
00029 ContextHelp * ContextHelp::self( KateMDI::ToolView * parent )
00030 {
00031         if (!m_pSelf)
00032         {
00033                 assert(parent);
00034                 m_pSelf = new ContextHelp(parent);
00035         }
00036         return m_pSelf;
00037 }
00038 
00039 
00040 ContextHelp::ContextHelp( KateMDI::ToolView * parent )
00041         : QWidget( parent, "Context Help" )
00042 {
00043         QWhatsThis::add( this, i18n("Provides context-sensitive help relevant to the current editing being performed.") );
00044         
00045         QVBoxLayout *vlayout = new QVBoxLayout( this, 0, 6 );
00046 
00047         m_nameLbl = new QLabel( this, "" );
00048         vlayout->addWidget(m_nameLbl);
00049         vlayout->addSpacing(8);
00050         
00051         m_info = new QTextBrowser( this, "" );
00052         vlayout->addWidget(m_info);
00053         m_info->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );
00054         
00055         QSpacerItem *spacer3 = new QSpacerItem( 1, 1, QSizePolicy::Preferred, QSizePolicy::Preferred );
00056         vlayout->addItem(spacer3);
00057         
00058         slotClear();
00059 } 
00060 
00061 
00062 ContextHelp::~ContextHelp()
00063 {
00064 }
00065 
00066 
00067 void ContextHelp::slotUpdate( Item *item )
00068 {
00069         if (!item)
00070         {
00071                 slotClear();
00072                 return;
00073         }
00074         m_nameLbl->setText("<h2>"+item->name()+"</h2>");
00075         m_info->setText( "<b></b>"+item->description() );
00076 }
00077 
00078 
00079 void ContextHelp::slotClear()
00080 {
00081         m_nameLbl->setText(i18n("<h2>No Item Selected</h2>"));
00082         m_info->setText("");
00083 }
00084 
00085 
00086 void ContextHelp::slotMultipleSelected()
00087 {
00088         m_nameLbl->setText(i18n("<h2>Multiple Items</h2>"));
00089         m_info->setText("");
00090 }
00091 
00092 
00093 void ContextHelp::setContextHelp(const QString& name, const QString& help)
00094 {
00095         m_nameLbl->setText("<h2>"+name+"</h2>");
00096         QString parsed = help;
00097         parseInfo(parsed);
00098         m_info->setText( "<b></b>"+parsed );
00099 }
00100 
00101 void ContextHelp::parseInfo( QString &info )
00102 {
00103         info.replace("<example>","<br><br><b>Example:</b><blockquote>");
00104         info.replace("</example>","</blockquote>");
00105 }
00106 
00107 #include "contexthelp.moc"

Generated on Tue May 8 17:05:28 2007 for KTechLab by  doxygen 1.5.1