1 /***************************************************************************
2                           rkhelpsearchwindow  -  description
3                              -------------------
4     begin                : Fri Feb 25 2005
5     copyright            : (C) 2005, 2006, 2007, 2009, 2010, 2011 by Thomas Friedrichsmeier
6     email                : thomas.friedrichsmeier@kdemail.net
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef RKHELPSEARCHWINDOW_H
19 #define RKHELPSEARCHWINDOW_H
20 
21 #include <qwidget.h>
22 #include <QAbstractTableModel>
23 
24 #include "../rbackend/rcommandreceiver.h"
25 #include "rkmdiwindow.h"
26 
27 class QFocusEvent;
28 class QComboBox;
29 class QCheckBox;
30 class QPushButton;
31 class RKHelpSearchResultsModel;
32 class QTreeView;
33 class QSortFilterProxyModel;
34 class RCommandChain;
35 
36 /** Provides a UI interface for help-search.
37 
38 @author Pierre Ecochard */
39 class RKHelpSearchWindow : public RKMDIWindow, public RCommandReceiver {
40 	Q_OBJECT
41 public:
42 	RKHelpSearchWindow (QWidget *parent, bool tool_window, const char *name=0);
43 	~RKHelpSearchWindow ();
44 	void rCommandDone (RCommand *command) override;
45 /** small convenience function to get context help for RKCommandEditorWindow and RKConsole.
46 @param context_line The current line
47 @param cursor_pos cursor position in the current line
48 Will figure out the word under the cursor, and provide help on that (if there is such a word, and such help exists) */
49 	void getContextHelp (const QString &context_line, int cursor_pos);
50 	void getFunctionHelp (const QString &function_name, const QString &package=QString(), const QString &type=QString ());
mainHelpSearch()51 	static RKHelpSearchWindow *mainHelpSearch () { return main_help_search; };
52 public slots:
53 	void slotFindButtonClicked();
54 	void resultDoubleClicked (const QModelIndex& index);
55 	void updateInstalledPackages ();
56 protected:
57 /** reimplemnented from QWidget to make the input focus default to the input field */
58 	void focusInEvent (QFocusEvent *e) override;
59 private:
60 	QComboBox* field;
61 	QComboBox* fieldsList;
62 	QComboBox* packagesList;
63 	QCheckBox* caseSensitiveCheckBox;
64 	QCheckBox* fuzzyCheckBox;
65 	QPushButton* findButton;
66 	QTreeView* results_view;
67 	RKHelpSearchResultsModel* results;
68 	QSortFilterProxyModel* proxy_model;
69 
70 friend class RKWardMainWindow;
71 	static RKHelpSearchWindow *main_help_search;
72 };
73 
74 /** An item model meant for use by RKHelpSearchWindow. Since it is fairly specialized, it is unlikely to be of any use in any other context. NOTE: This class is pretty useless, really, we should just switch to a QTree/TableWidget with predefined model, whenever we need to make the next big change to the RKHelpSearchWindow.
75 @author Thomas Friedrichsmeier */
76 class RKHelpSearchResultsModel : public QAbstractTableModel {
77 public:
78 	explicit RKHelpSearchResultsModel (QObject *parent);
79 	~RKHelpSearchResultsModel ();
80 
81 /** Set the results. The model will assume ownership of the results */
82 	void setResults (const QStringList &new_results);
83 
84 	int rowCount (const QModelIndex& parent=QModelIndex()) const override;
85 	int columnCount (const QModelIndex& parent=QModelIndex()) const override;
86 	QVariant data (const QModelIndex& index, int role=Qt::DisplayRole) const override;
87 	QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override;
88 	QString resultsType (int row);
89 private:
90 	QStringList topics;
91 	QStringList titles;
92 	QStringList packages;
93 	QStringList types;
94 	int result_count;
95 };
96 
97 #endif
98