mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 08:34:52 -07:00
move SearchLineEdit into custom_line_edit file (#5281)
This commit is contained in:
parent
91d2485940
commit
6ea333d0f1
4 changed files with 36 additions and 34 deletions
|
|
@ -50,22 +50,6 @@
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
void SearchLineEdit::keyPressEvent(QKeyEvent *event)
|
|
||||||
{
|
|
||||||
// List of key events that must be handled by the card list instead of the search box
|
|
||||||
static const QVector<Qt::Key> forwardToTreeView = {Qt::Key_Up, Qt::Key_Down, Qt::Key_PageDown, Qt::Key_PageUp};
|
|
||||||
// forward only if the search text is empty
|
|
||||||
static const QVector<Qt::Key> forwardWhenEmpty = {Qt::Key_Home, Qt::Key_End};
|
|
||||||
Qt::Key key = static_cast<Qt::Key>(event->key());
|
|
||||||
if (treeView) {
|
|
||||||
if (forwardToTreeView.contains(key))
|
|
||||||
QCoreApplication::sendEvent(treeView, event);
|
|
||||||
if (text().isEmpty() && forwardWhenEmpty.contains(key))
|
|
||||||
QCoreApplication::sendEvent(treeView, event);
|
|
||||||
}
|
|
||||||
LineEditUnfocusable::keyPressEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabDeckEditor::createDeckDock()
|
void TabDeckEditor::createDeckDock()
|
||||||
{
|
{
|
||||||
deckModel = new DeckListModel(this);
|
deckModel = new DeckListModel(this);
|
||||||
|
|
|
||||||
|
|
@ -29,24 +29,6 @@ class QVBoxLayout;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
class QDockWidget;
|
class QDockWidget;
|
||||||
|
|
||||||
class SearchLineEdit : public LineEditUnfocusable
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
QTreeView *treeView;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void keyPressEvent(QKeyEvent *event) override;
|
|
||||||
|
|
||||||
public:
|
|
||||||
SearchLineEdit() : LineEditUnfocusable(), treeView(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
void setTreeView(QTreeView *_treeView)
|
|
||||||
{
|
|
||||||
treeView = _treeView;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class TabDeckEditor : public Tab
|
class TabDeckEditor : public Tab
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QTreeView>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
LineEditUnfocusable::LineEditUnfocusable(QWidget *parent) : QLineEdit(parent)
|
LineEditUnfocusable::LineEditUnfocusable(QWidget *parent) : QLineEdit(parent)
|
||||||
|
|
@ -69,3 +70,19 @@ bool LineEditUnfocusable::eventFilter(QObject *watched, QEvent *event)
|
||||||
|
|
||||||
return QLineEdit::eventFilter(watched, event);
|
return QLineEdit::eventFilter(watched, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SearchLineEdit::keyPressEvent(QKeyEvent *event)
|
||||||
|
{
|
||||||
|
// List of key events that must be handled by the card list instead of the search box
|
||||||
|
static const QVector<Qt::Key> forwardToTreeView = {Qt::Key_Up, Qt::Key_Down, Qt::Key_PageDown, Qt::Key_PageUp};
|
||||||
|
// forward only if the search text is empty
|
||||||
|
static const QVector<Qt::Key> forwardWhenEmpty = {Qt::Key_Home, Qt::Key_End};
|
||||||
|
Qt::Key key = static_cast<Qt::Key>(event->key());
|
||||||
|
if (treeView) {
|
||||||
|
if (forwardToTreeView.contains(key))
|
||||||
|
QCoreApplication::sendEvent(treeView, event);
|
||||||
|
if (text().isEmpty() && forwardWhenEmpty.contains(key))
|
||||||
|
QCoreApplication::sendEvent(treeView, event);
|
||||||
|
}
|
||||||
|
LineEditUnfocusable::keyPressEvent(event);
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
|
||||||
|
class QTreeView;
|
||||||
class QKeyEvent;
|
class QKeyEvent;
|
||||||
class QWidget;
|
class QWidget;
|
||||||
class QString;
|
class QString;
|
||||||
|
|
@ -25,4 +26,22 @@ protected:
|
||||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SearchLineEdit : public LineEditUnfocusable
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
QTreeView *treeView;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void keyPressEvent(QKeyEvent *event) override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SearchLineEdit() : LineEditUnfocusable(), treeView(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void setTreeView(QTreeView *_treeView)
|
||||||
|
{
|
||||||
|
treeView = _treeView;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue