stfl_query_widget_lineedit.hpp 1.23 KB
Newer Older
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
#ifndef CVVISUAL_STFL_QUERY_WIDGET_LINEEDIT_HPP
#define CVVISUAL_STFL_QUERY_WIDGET_LINEEDIT_HPP

#include <QStringList>
#include <QLineEdit>
#include <QKeyEvent>
#include <QAbstractItemView>

#include "stfl_query_widget_completer.hpp"

namespace cvv
{
namespace qtutil
{

/**
 * @brief A line edit class, capable of showing suggestions.
 * @note It's heavily based on
 * http://www.qtcentre.org/archive/index.php/t-23518.html
 */
class STFLQueryWidgetLineEdit : public QLineEdit
{
	Q_OBJECT
      public:
	/**
	 * @brief Contructor of this class.
	 * @param parent widget.
	 */
	STFLQueryWidgetLineEdit(QWidget *parent = 0);

	/**
	 * @brief Gets the inherited completer.
	 * @return the inherited completer
	 */
	STFLQueryWidgetCompleter *completer();

	/**
	 * @brief Show the given suggestions in a list.
	 * @param suggestions given suggestions
	 */
	void showSuggestions(QStringList suggestions);

      protected:
	void keyPressEvent(QKeyEvent *e);

signals:
	/**
	 * @brief New suggestions are requested for the given user input.
	 * @param input given user input
	 */
	void requestSuggestions(QString input);

      private
slots:
	void insertCompletion(const QString &completion);

      private:
	STFLQueryWidgetCompleter *queryCompleter;
};
}
}
#endif