work save

This commit is contained in:
royqh1979@gmail.com 2021-08-24 09:59:44 +08:00
parent ed7da7b487
commit 74f2d689d6
2 changed files with 57 additions and 8 deletions

View File

@ -1,14 +1,46 @@
#include "codecompletionview.h"
#include "ui_codecompletionview.h"
#include <QKeyEvent>
CodeCompletionView::CodeCompletionView(QWidget *parent) :
QWidget(parent),
ui(new Ui::CodeCompletionView)
QWidget(parent)
{
ui->setupUi(this);
setWindowFlags(Qt::Popup);
mListView = new CodeCompletionListView(this);
setLayout(new QVBoxLayout());
layout()->addWidget(mListView);
layout()->setMargin(0);
}
CodeCompletionView::~CodeCompletionView()
{
delete ui;
}
void CodeCompletionView::setKeypressedCallback(const KeyPressedCallback &newKeypressedCallback)
{
mListView->setKeypressedCallback(newKeypressedCallback);
}
CodeCompletionListView::CodeCompletionListView(QWidget *parent) : QListView(parent)
{
}
void CodeCompletionListView::keyPressEvent(QKeyEvent *event)
{
if (!mKeypressedCallback(event)) {
QListView::keyPressEvent(event);
}
}
const KeyPressedCallback &CodeCompletionListView::keypressedCallback() const
{
return mKeypressedCallback;
}
void CodeCompletionListView::setKeypressedCallback(const KeyPressedCallback &newKeypressedCallback)
{
mKeypressedCallback = newKeypressedCallback;
}

View File

@ -1,11 +1,25 @@
#ifndef CODECOMPLETIONVIEW_H
#define CODECOMPLETIONVIEW_H
#include <QListView>
#include <QWidget>
namespace Ui {
class CodeCompletionView;
}
using KeyPressedCallback = std::function<bool (QKeyEvent *)>;
class CodeCompletionListView: public QListView {
Q_OBJECT
public:
explicit CodeCompletionListView(QWidget *parent = nullptr);
// QWidget interface
const KeyPressedCallback &keypressedCallback() const;
void setKeypressedCallback(const KeyPressedCallback &newKeypressedCallback);
protected:
void keyPressEvent(QKeyEvent *event) override;
private:
KeyPressedCallback mKeypressedCallback;
};
class CodeCompletionView : public QWidget
{
@ -15,8 +29,11 @@ public:
explicit CodeCompletionView(QWidget *parent = nullptr);
~CodeCompletionView();
void setKeypressedCallback(const KeyPressedCallback &newKeypressedCallback);
private:
Ui::CodeCompletionView *ui;
CodeCompletionListView * mListView;
};
#endif // CODECOMPLETIONVIEW_H