summaryrefslogtreecommitdiffstats
path: root/src/gui/contexthelp.cpp
blob: f7a2432f1619356a0db28a363092d8e6d3bfb546 (plain)
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
/***************************************************************************
 *   Copyright (C) 2003-2005 by David Saxton                               *
 *   david@bluehaze.org                                                    *
 *                                                                         *
 *   This program 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.                                   *
 ***************************************************************************/

#include "cnitem.h"
#include "cnitemgroup.h"
#include "contexthelp.h"
#include "itemlibrary.h"
#include "katemdi.h"

#include <klocale.h>

#include <tqlayout.h>
#include <tqlabel.h>
#include <tqregexp.h>
#include <tqtextbrowser.h>
#include <tqwhatsthis.h>

#include <assert.h>

ContextHelp * ContextHelp::m_pSelf = 0l;

ContextHelp * ContextHelp::self( KateMDI::ToolView * parent )
{
	if (!m_pSelf)
	{
		assert(parent);
		m_pSelf = new ContextHelp(parent);
	}
	return m_pSelf;
}


ContextHelp::ContextHelp( KateMDI::ToolView * parent )
	: TQWidget( parent, "Context Help" )
{
	TQWhatsThis::add( this, i18n("Provides context-sensitive help relevant to the current editing being performed.") );
	
	TQVBoxLayout *vtqlayout = new TQVBoxLayout( this, 0, 6 );

	m_nameLbl = new TQLabel( this, "" );
	vtqlayout->addWidget(m_nameLbl);
	vtqlayout->addSpacing(8);
	
	m_info = new TQTextBrowser( this, "" );
	vtqlayout->addWidget(m_info);
	m_info->tqsetSizePolicy( TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding );
	
	TQSpacerItem *spacer3 = new TQSpacerItem( 1, 1, TQSizePolicy::Preferred, TQSizePolicy::Preferred );
	vtqlayout->addItem(spacer3);
	
	slotClear();
} 


ContextHelp::~ContextHelp()
{
}


void ContextHelp::slotUpdate( Item *item )
{
	if (!item)
	{
		slotClear();
		return;
	}
	m_nameLbl->setText("<h2>"+item->name()+"</h2>");
	m_info->setText( "<b></b>"+item->description() );
}


void ContextHelp::slotClear()
{
	m_nameLbl->setText(i18n("<h2>No Item Selected</h2>"));
	m_info->setText("");
}


void ContextHelp::slotMultipleSelected()
{
	m_nameLbl->setText(i18n("<h2>Multiple Items</h2>"));
	m_info->setText("");
}


void ContextHelp::setContextHelp(const TQString& name, const TQString& help)
{
	m_nameLbl->setText("<h2>"+name+"</h2>");
	TQString parsed = help;
	parseInfo(parsed);
	m_info->setText( "<b></b>"+parsed );
}

void ContextHelp::parseInfo( TQString &info )
{
	info.replace("<example>","<br><br><b>Example:</b><blockquote>");
	info.replace("</example>","</blockquote>");
}

#include "contexthelp.moc"