SILICON
Toggle main menu visibility
Loading...
Searching...
No Matches
componentSearchBox.hpp
Go to the documentation of this file.
1
/*
2
Copyright (c) 2025. Giulio Cocconi
3
4
This program is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#pragma once
19
20
#include <ranges>
21
22
#include <QAbstractItemView>
23
#include <QCompleter>
24
#include <QEvent>
25
#include <QGraphicsProxyWidget>
26
#include <QKeyEvent>
27
#include <QLineEdit>
28
#include <QStringListModel>
29
30
#include <
ui/circuit/diagram/enums.hpp
>
31
32
33
namespace
SILICON::ui
{
34
35
class
ComponentSearchBox
:
public
QGraphicsProxyWidget {
36
Q_OBJECT
37
public
:
38
explicit
ComponentSearchBox
(std::vector<std::string>
completionList
= {},
39
QString title =
"Insert component..."
,
40
QGraphicsItem* parent =
nullptr
);
41
void
showCompleter
()
const
;
42
43
void
keyPressEvent
(QKeyEvent* event)
override
;
44
bool
eventFilter
(QObject* watched, QEvent* event)
override
;
45
46
void
focus
() {
le
->setFocus(Qt::OtherFocusReason); }
47
void
clear
() {
le
->clear(); }
48
49
void
setCompletionList
(std::vector<std::string> list)
50
{
51
this->
completionList
= std::move(list);
52
updateCompletionModel
();
53
}
54
55
signals:
56
57
void
requestHide
();
58
void
requestCancel
();
59
void
selectedComponent
(std::string typeName, QPointF pos);
60
61
private
:
62
void
updateCompletionModel
()
const
;
63
[[nodiscard]] std::string
selectedTypeName
()
const
;
64
[[nodiscard]] QString
activeCompletionText
()
const
;
65
[[nodiscard]] std::string
typeNameForCompletion
(QString completion)
const
;
66
void
acceptCompletion
(QString completion);
67
68
QLineEdit*
le
;
69
QCompleter*
completer
;
70
QStringListModel*
completionModel
;
71
QGraphicsTextItem*
titleItem
;
72
73
std::vector<std::string>
completionList
;
74
};
75
76
}
// namespace SILICON::ui
SILICON::ui::ComponentSearchBox::setCompletionList
void setCompletionList(std::vector< std::string > list)
Definition
componentSearchBox.hpp:49
SILICON::ui::ComponentSearchBox::requestHide
void requestHide()
SILICON::ui::ComponentSearchBox::activeCompletionText
QString activeCompletionText() const
Definition
componentSearchBox.cpp:156
SILICON::ui::ComponentSearchBox::keyPressEvent
void keyPressEvent(QKeyEvent *event) override
Definition
componentSearchBox.cpp:94
SILICON::ui::ComponentSearchBox::typeNameForCompletion
std::string typeNameForCompletion(QString completion) const
Definition
componentSearchBox.cpp:168
SILICON::ui::ComponentSearchBox::eventFilter
bool eventFilter(QObject *watched, QEvent *event) override
Definition
componentSearchBox.cpp:116
SILICON::ui::ComponentSearchBox::ComponentSearchBox
ComponentSearchBox(std::vector< std::string > completionList={}, QString title="Insert component...", QGraphicsItem *parent=nullptr)
Definition
componentSearchBox.cpp:29
SILICON::ui::ComponentSearchBox::le
QLineEdit * le
Definition
componentSearchBox.hpp:68
SILICON::ui::ComponentSearchBox::selectedComponent
void selectedComponent(std::string typeName, QPointF pos)
SILICON::ui::ComponentSearchBox::updateCompletionModel
void updateCompletionModel() const
Definition
componentSearchBox.cpp:131
SILICON::ui::ComponentSearchBox::selectedTypeName
std::string selectedTypeName() const
Definition
componentSearchBox.cpp:151
SILICON::ui::ComponentSearchBox::clear
void clear()
Definition
componentSearchBox.hpp:47
SILICON::ui::ComponentSearchBox::completionModel
QStringListModel * completionModel
Definition
componentSearchBox.hpp:70
SILICON::ui::ComponentSearchBox::showCompleter
void showCompleter() const
Definition
componentSearchBox.cpp:80
SILICON::ui::ComponentSearchBox::focus
void focus()
Definition
componentSearchBox.hpp:46
SILICON::ui::ComponentSearchBox::completer
QCompleter * completer
Definition
componentSearchBox.hpp:69
SILICON::ui::ComponentSearchBox::titleItem
QGraphicsTextItem * titleItem
Definition
componentSearchBox.hpp:71
SILICON::ui::ComponentSearchBox::requestCancel
void requestCancel()
SILICON::ui::ComponentSearchBox::completionList
std::vector< std::string > completionList
Definition
componentSearchBox.hpp:73
SILICON::ui::ComponentSearchBox::acceptCompletion
void acceptCompletion(QString completion)
Definition
componentSearchBox.cpp:183
enums.hpp
SILICON::ui
Definition
actionGroups.hpp:14
src
ui
circuit
editor
componentSearchBox.hpp
Generated by
1.17.0