summaryrefslogtreecommitdiffstats
path: root/parts/documentation/documentation_widget.cpp
blob: 567237e2fdf3a6576a4dc3f6052304157f03ea89 (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
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
/***************************************************************************
 *   Copyright (C) 2004 by Alexander Dymo                                  *
 *   cloudtemple@mksat.net                                                 *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   This program 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, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/
#include "documentation_widget.h"

#include <tqlayout.h>
#include <tqtoolbox.h>

#include <klineedit.h>
#include <tdeparts/part.h>
#include <klibloader.h>
#include <kurl.h>
#include <klocale.h>
#include <kdebug.h>
#include <kapplication.h>
#include <kconfig.h>

#include <kdevcore.h>
#include <kdevdocumentationplugin.h>

#include "documentation_part.h"
#include "contentsview.h"
#include "indexview.h"
#include "searchview.h"
#include "bookmarkview.h"
#include "find_documentation.h"

DocumentationWidget::DocumentationWidget(DocumentationPart *part)
    :TQWidget(0, "documentation widget"), m_part(part)
{
    TQVBoxLayout *l = new TQVBoxLayout(this, 0, 0);
    
    m_tab = new TQToolBox(this);
    l->addWidget(m_tab);
    
    m_contents = new ContentsView(this);
    m_tab->addItem(m_contents, i18n("Contents"));
    
    m_index = new IndexView(this);
    m_tab->addItem(m_index, i18n("Index"));
    
    m_finder = new FindDocumentation(this);
    m_tab->addItem(m_finder,i18n("Finder"));
    
    m_search = new SearchView(m_part, this);
    m_tab->addItem(m_search, i18n("Search"));
    
    m_bookmarks = new BookmarkView(this);
    m_tab->addItem(m_bookmarks, i18n("Bookmarks"));
    
    connect(m_tab, TQT_SIGNAL(currentChanged(int)), this, TQT_SLOT(tabChanged(int)));
}

DocumentationWidget::~DocumentationWidget()
{
    TDEConfig *config = kapp->config();
    config->setGroup("Documentation");
    config->writeEntry("LastPage", m_tab->currentIndex());
}

void DocumentationWidget::tabChanged(int t)
{
    if (!m_tab->item(t))
        return;
    m_tab->item(t)->setFocus();
    if (m_tab->item(t) == m_index)
        m_part->emitIndexSelected(m_index->indexBox());
}

IndexBox *DocumentationWidget::index() const
{
    return m_index->indexBox();
}

void DocumentationWidget::searchInDocumentation()
{
    m_tab->setCurrentItem(m_search);
    m_search->askSearchTerm();
}

void DocumentationWidget::searchInDocumentation(const TQString &term)
{
    m_tab->setCurrentItem(m_search);
    m_search->setSearchTerm(term);
    m_search->search();
}

void DocumentationWidget::lookInDocumentationIndex()
{
    m_tab->setCurrentItem(m_index);
    m_index->askSearchTerm();
}

void DocumentationWidget::lookInDocumentationIndex(const TQString &term)
{
    m_tab->setCurrentItem(m_index);
    m_index->setSearchTerm(term);
    //adymo: let's allow the user to press enter here ;)
//    m_index->searchInIndex();
}

void DocumentationWidget::findInDocumentation(const TQString &term)
{
   m_tab->setCurrentItem(m_finder);
   m_finder->setSearchTerm(term);
   m_finder->startSearch();
}

void DocumentationWidget::findInDocumentation()
{
   m_tab->setCurrentItem(m_finder);
   m_finder->search_term->setFocus();
}

void DocumentationWidget::focusInEvent(TQFocusEvent */*e*/)
{
    if (m_tab->currentItem())
        m_tab->currentItem()->setFocus();
}

KListView * DocumentationWidget::contents( ) const
{
    return m_contents->view();
}

#include "documentation_widget.moc"