summaryrefslogtreecommitdiffstats
path: root/examples/helpsystem/whatsthis.cpp
blob: 1e0991fcf0e6343c989591ece0444e5d52729a78 (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
/****************************************************************************
**
** Copyright (C) 1992-2008 Trolltech ASA.  All rights reserved.
**
** This file is part of an example program for TQt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#include <ntqapplication.h>
#include <tqdir.h>
#include <ntqheader.h>
#include <ntqtable.h>

#include "whatsthis.h"

WhatsThis::WhatsThis( TQWidget *w, TQWidget *watch )
: TQWhatsThis( watch ? watch : w ), widget( w )
{
}

TQWidget *WhatsThis::parentWidget() const
{
    return widget;
}

bool WhatsThis::clicked( const TQString &link )
{
    if ( !link.isEmpty() )
	emit linkClicked( link );

    return TRUE;
}

HeaderWhatsThis::HeaderWhatsThis( TQHeader *h ) 
: WhatsThis( h )
{
}

TQString HeaderWhatsThis::text( const TQPoint &p )
{
    TQHeader *header = (TQHeader*)parentWidget();

    TQString orient;
    int section;
    if ( header->orientation() == TQObject::Horizontal ) {
	orient = "horizontal";
	section = header->sectionAt( p.x() );
    } else {
	orient = "vertical";
	section = header->sectionAt( p.y() );
    }
    if( section == -1 )
	return "This is empty space.";
    TQString docsPath = TQDir("../../doc").absPath();
    return TQString("This is section number %1 in the %2 <a href=%2/html/ntqheader.html>header</a>.").
	arg(section + 1).
	arg(orient).
	arg(docsPath);
}

TableWhatsThis::TableWhatsThis( TQTable *t ) 
: WhatsThis( t, t->viewport() )
{
}


TQString TableWhatsThis::text( const TQPoint &p )
{
    TQTable *table = (TQTable*)parentWidget();

    TQPoint cp = table->viewportToContents( p );
    int row = table->rowAt( cp.y() );
    int col = table->columnAt( cp.x() );

    if ( row == -1 || col == -1 )
	return "This is empty space.";

    TQTableItem* i = table->item( row,col  );
    if ( !i )
	return "This is an empty cell.";

    TQString docsPath = TQDir("../../doc").absPath();

    if ( TQTableItem::RTTI == i->rtti() ) {
	return TQString("This is a <a href=%1/html/qtableitem.html>TQTableItem</a>.").
		       arg(docsPath);
    } else if ( TQComboTableItem::RTTI == i->rtti() ) {
	return TQString("This is a <a href=%1/html/qcombotableitem.html>TQComboTableItem</a>."
		       "<br>It can be used to provide multiple-choice items in a table.").
		       arg(docsPath);
    } else if ( TQCheckTableItem::RTTI == i->rtti() ) {
	return TQString("This is a <a href=%1/html/qchecktableitem.html>TQCheckTableItem</a>."
		       "<br>It provide <a href=%1/html/ntqcheckbox.html>checkboxes</a> in tables.").
		       arg(docsPath).arg(docsPath);
    }

    return "This is a user defined table item.";
}