Files
qt-creator/src/plugins/texteditor/completionwidget.h

137 lines
3.7 KiB
C
Raw Normal View History

/**************************************************************************
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator
**
2011-01-11 16:28:15 +01:00
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
2008-12-02 12:01:29 +01:00
**
2011-04-13 08:42:33 +02:00
** Contact: Nokia Corporation (info@qt.nokia.com)
2008-12-02 12:01:29 +01:00
**
**
** GNU Lesser General Public License Usage
**
2011-04-13 08:42:33 +02:00
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
2010-12-17 16:01:08 +01:00
** In addition, as a special exception, Nokia gives you certain additional
2011-04-13 08:42:33 +02:00
** rights. These rights are described in the Nokia Qt LGPL Exception
2010-12-17 16:01:08 +01:00
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
2011-04-13 08:42:33 +02:00
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
2010-12-17 16:01:08 +01:00
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
2008-12-02 12:01:29 +01:00
**
**************************************************************************/
2008-12-02 16:19:05 +01:00
2008-12-02 12:01:29 +01:00
#ifndef COMPLETIONWIDGET_H
#define COMPLETIONWIDGET_H
#include <QtGui/QListView>
#include <QtCore/QPointer>
#include <QtCore/QTimer>
2008-12-02 12:01:29 +01:00
namespace TextEditor {
class CompletionItem;
class ITextEditor;
class CompletionSupport;
2008-12-02 12:01:29 +01:00
namespace Internal {
class AutoCompletionModel;
class CompletionListView;
2010-04-09 12:59:20 +02:00
class CompletionInfoFrame;
2008-12-02 12:01:29 +01:00
/* The completion widget is responsible for showing a list of possible completions.
It is only used by the CompletionSupport.
*/
class CompletionWidget : public QFrame
2008-12-02 12:01:29 +01:00
{
Q_OBJECT
public:
CompletionWidget(CompletionSupport *support, ITextEditor *editor);
~CompletionWidget();
2008-12-02 12:01:29 +01:00
void setCompletionItems(const QList<TextEditor::CompletionItem> &completionitems);
void showCompletions(int startPos);
QChar typedChar() const;
CompletionItem currentCompletionItem() const;
void setCurrentIndex(int index);
bool explicitlySelected() const;
signals:
void itemSelected(const TextEditor::CompletionItem &item);
void completionListClosed();
public slots:
2008-12-02 12:01:29 +01:00
void closeList(const QModelIndex &index = QModelIndex());
private:
void updatePositionAndSize(int startPos);
private:
CompletionSupport *m_support;
ITextEditor *m_editor;
CompletionListView *m_completionListView;
};
class CompletionListView : public QListView
{
Q_OBJECT
public:
~CompletionListView();
2008-12-02 12:01:29 +01:00
CompletionItem currentCompletionItem() const;
bool explicitlySelected() const;
2008-12-02 12:01:29 +01:00
signals:
void itemSelected(const TextEditor::CompletionItem &item);
void completionListClosed();
protected:
bool event(QEvent *e);
2008-12-02 12:01:29 +01:00
2010-04-09 12:59:20 +02:00
void currentChanged(const QModelIndex &current, const QModelIndex &previous);
2008-12-02 12:01:29 +01:00
private:
friend class CompletionWidget;
CompletionListView(CompletionSupport *support, ITextEditor *editor, CompletionWidget *completionWidget);
void setCompletionItems(const QList<TextEditor::CompletionItem> &completionitems);
void keyboardSearch(const QString &search);
void closeList(const QModelIndex &index);
2010-04-09 14:15:21 +02:00
private slots:
2010-04-09 12:59:20 +02:00
void maybeShowInfoTip();
2008-12-02 12:01:29 +01:00
private:
2008-12-02 12:01:29 +01:00
bool m_blockFocusOut;
ITextEditor *m_editor;
2008-12-02 12:01:29 +01:00
QWidget *m_editorWidget;
CompletionWidget *m_completionWidget;
2008-12-02 12:01:29 +01:00
AutoCompletionModel *m_model;
CompletionSupport *m_support;
2010-04-09 12:59:20 +02:00
QPointer<CompletionInfoFrame> m_infoFrame;
QTimer m_infoTimer;
QChar m_typedChar;
bool m_explicitlySelected;
2008-12-02 12:01:29 +01:00
};
} // namespace Internal
} // namespace TextEditor
#endif // COMPLETIONWIDGET_H