2008-02-21 19:42:34 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file GuiCompleter.h
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Stefan Schimanski
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GUICOMPLETER_H
|
|
|
|
#define GUICOMPLETER_H
|
|
|
|
|
|
|
|
#include "frontends/WorkArea.h"
|
|
|
|
|
|
|
|
#include "DocIterator.h"
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
#include "support/docstring.h"
|
|
|
|
|
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QCompleter>
|
|
|
|
#include <QStringListModel>
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
class Buffer;
|
|
|
|
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
class GuiWorkArea;
|
2008-06-03 22:00:47 +00:00
|
|
|
class CompleterItemDelegate;
|
|
|
|
class GuiCompletionModel;
|
2008-02-21 19:42:34 +00:00
|
|
|
|
|
|
|
class GuiCompleter : private QCompleter
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
GuiCompleter(GuiWorkArea * gui, QObject * parent = 0);
|
|
|
|
///
|
|
|
|
virtual ~GuiCompleter();
|
|
|
|
|
|
|
|
///
|
|
|
|
bool popupVisible() const;
|
|
|
|
///
|
|
|
|
bool inlineVisible() const;
|
|
|
|
///
|
|
|
|
bool popupPossible(Cursor const & cur) const;
|
|
|
|
///
|
|
|
|
bool inlinePossible(Cursor const & cur) const;
|
2008-02-28 12:41:43 +00:00
|
|
|
///
|
|
|
|
bool completionAvailable() const;
|
2008-02-21 19:42:34 +00:00
|
|
|
/// Activate the current completion, i.e. finalize it.
|
|
|
|
void activate();
|
|
|
|
/// Do a completion as far as it is unique, but at least one character.
|
|
|
|
void tab();
|
|
|
|
|
|
|
|
/// Update the visibility of the popup and the inline completion.
|
|
|
|
/// This method might set the update flags of the cursor to request
|
|
|
|
/// a redraw.
|
|
|
|
void updateVisibility(Cursor & cur, bool start, bool keep, bool cursorInView = true);
|
|
|
|
/// Update the visibility of the popup and the inline completion.
|
|
|
|
/// This method handles the redraw if needed.
|
|
|
|
void updateVisibility(bool start, bool keep);
|
|
|
|
///
|
|
|
|
QString currentCompletion() const;
|
|
|
|
///
|
|
|
|
docstring longestUniqueCompletion() const;
|
2008-11-16 17:02:40 +00:00
|
|
|
///
|
|
|
|
bool uniqueCompletionAvailable() const;
|
2008-02-21 19:42:34 +00:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
/// Show the popup.
|
|
|
|
void showPopup();
|
|
|
|
/// Show the inline completion.
|
|
|
|
void showInline();
|
|
|
|
|
2008-02-26 19:19:34 +00:00
|
|
|
/// Hide the popup.
|
|
|
|
void hidePopup();
|
|
|
|
/// Hide the inline completion.
|
|
|
|
void hideInline();
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
private Q_SLOTS:
|
|
|
|
///
|
|
|
|
void popupActivated(const QString & completion);
|
|
|
|
///
|
|
|
|
void popupHighlighted(const QString & completion);
|
2008-02-28 12:41:57 +00:00
|
|
|
///
|
|
|
|
void updateAvailability();
|
2008-03-04 12:44:48 +00:00
|
|
|
/// the asynchronous part of updatePopup(cur)
|
|
|
|
void asyncUpdatePopup();
|
|
|
|
/// the asynchronous part of hidePopup(cur)
|
|
|
|
void asyncHidePopup();
|
|
|
|
/// the asynchronous part of hideInline(cur)
|
|
|
|
void asyncHideInline();
|
2008-02-21 19:42:34 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
void setCurrentCompletion(QString const & s);
|
|
|
|
///
|
|
|
|
void showPopup(Cursor & cur);
|
|
|
|
///
|
|
|
|
void showInline(Cursor & cur);
|
|
|
|
///
|
2008-02-26 13:10:04 +00:00
|
|
|
void hidePopup(Cursor & cur);
|
|
|
|
///
|
|
|
|
void hideInline(Cursor & cur);
|
|
|
|
///
|
2008-02-21 19:42:34 +00:00
|
|
|
void updatePopup(Cursor & cur);
|
|
|
|
///
|
|
|
|
void updateInline(Cursor & cur, QString const & completion);
|
|
|
|
///
|
|
|
|
void updatePrefix(Cursor & cur);
|
|
|
|
///
|
|
|
|
void updateModel(Cursor & cur, bool popupUpdate, bool inlineUpdate);
|
|
|
|
///
|
|
|
|
bool eventFilter(QObject * watched, QEvent * event);
|
|
|
|
|
|
|
|
///
|
|
|
|
GuiWorkArea * gui_;
|
|
|
|
///
|
|
|
|
DocIterator old_cursor_;
|
|
|
|
///
|
|
|
|
QTimer popup_timer_;
|
|
|
|
///
|
|
|
|
QTimer inline_timer_;
|
|
|
|
///
|
|
|
|
QString last_selection_;
|
2008-02-21 19:43:16 +00:00
|
|
|
/// lock to stop updates of the inline completion
|
|
|
|
int updateLock_;
|
2008-02-23 03:15:34 +00:00
|
|
|
/// the BufferView::inlineCursorPos might be reset by destructive
|
|
|
|
/// operations like backspace. Hence, we have to keep this flag
|
2008-02-26 13:07:59 +00:00
|
|
|
/// in addition to know whether the completion is to be kept visible.
|
2008-02-23 03:15:34 +00:00
|
|
|
bool inlineVisible_;
|
2008-02-24 00:49:57 +00:00
|
|
|
///
|
2008-03-04 09:43:32 +00:00
|
|
|
bool popupVisible_;
|
2008-03-04 12:44:48 +00:00
|
|
|
/// the model reset is asynchronous in hidePopup/Inline. So let's mark
|
|
|
|
/// a coming reset here by setting it to false.
|
|
|
|
bool modelActive_;
|
2008-03-04 09:43:32 +00:00
|
|
|
///
|
2008-06-03 22:00:47 +00:00
|
|
|
CompleterItemDelegate * itemDelegate_;
|
|
|
|
///
|
|
|
|
GuiCompletionModel * model_;
|
2008-02-21 19:42:34 +00:00
|
|
|
}; // GuiCompleter
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#endif // GUICOMPLETER_H
|