The complete source code of IdealIRC
http://www.idealirc.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.2 KiB
62 lines
1.2 KiB
/*
|
|
* IdealIRC - Internet Relay Chat client
|
|
* Copyright (C) 2021 Tom-Andre Barstad.
|
|
* This software is licensed under the Software Attribution License.
|
|
* See LICENSE for more information.
|
|
*/
|
|
|
|
#ifndef ILINEEDIT_H
|
|
#define ILINEEDIT_H
|
|
|
|
#include <QLineEdit>
|
|
#include <QKeyEvent>
|
|
#include <QFocusEvent>
|
|
#include <QDebug>
|
|
#include <QStringList>
|
|
#include <functional>
|
|
|
|
class ILineEdit : public QLineEdit
|
|
{
|
|
Q_OBJECT
|
|
friend class KeyEventFilter;
|
|
|
|
public:
|
|
using TabCompleteCb = std::function<int(int, QString&)>;
|
|
ILineEdit(TabCompleteCb&& tabCompleteCb, QWidget* parent = nullptr);
|
|
|
|
signals:
|
|
void newLine(const QString& line);
|
|
|
|
private:
|
|
void loadConfig();
|
|
void keyTab();
|
|
void keyUp();
|
|
void keyDown();
|
|
void resetCompletePattern();
|
|
|
|
void keyPressEvent(QKeyEvent* evt) override;
|
|
QString currentLine;
|
|
QStringList prevLines;
|
|
int logidx{ -1 };
|
|
int completeidx{ 0 };
|
|
QString completePattern;
|
|
TabCompleteCb tabCb;
|
|
};
|
|
|
|
class KeyEventFilter : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
KeyEventFilter(QObject* parent)
|
|
: QObject(parent)
|
|
{}
|
|
|
|
signals:
|
|
void newLine(const QString& line);
|
|
|
|
private:
|
|
bool eventFilter(QObject* obj, QEvent *evt) override;
|
|
};
|
|
|
|
#endif // ILINEEDIT_H
|
|
|