SILICON
Toggle main menu visibility
Loading...
Searching...
No Matches
graphicalFlipFlops.cpp
Go to the documentation of this file.
1
/*
2
Copyright (c) 2026. 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
#include "
graphicalFlipFlops.hpp
"
19
20
#include <
ui/shell/theme.hpp
>
21
22
#include <QGraphicsRectItem>
23
#include <QPainter>
24
#include <QTextOption>
25
26
27
namespace
SILICON::ui
{
28
using namespace
SILICON::core;
29
30
namespace
{
31
32
constexpr
QRectF FlipFlopBodyRect(0.0, 0.0, 80.0, 80.0);
33
34
std::shared_ptr<DFlipFlop> makeDFlipFlop()
35
{
36
return
std::make_shared<DFlipFlop>(
Wire_ptr
{},
Wire_ptr
{},
Wire_ptr
{},
Wire_ptr
{},
37
Wire_ptr
{},
Wire_ptr
{});
38
}
39
40
std::shared_ptr<EFlipFlop> makeEFlipFlop()
41
{
42
return
std::make_shared<EFlipFlop>(
Wire_ptr
{},
Wire_ptr
{},
Wire_ptr
{},
Wire_ptr
{},
43
Wire_ptr
{},
Wire_ptr
{},
Wire_ptr
{});
44
}
45
46
std::shared_ptr<DLatch> makeDLatch()
47
{
48
return
std::make_shared<DLatch>(
Wire_ptr
{},
Wire_ptr
{},
Wire_ptr
{},
Wire_ptr
{});
49
}
50
51
std::shared_ptr<JKFlipFlop> makeJKFlipFlop()
52
{
53
return
std::make_shared<JKFlipFlop>(
Wire_ptr
{},
Wire_ptr
{},
Wire_ptr
{},
Wire_ptr
{},
54
Wire_ptr
{},
Wire_ptr
{},
Wire_ptr
{});
55
}
56
57
class
FlipFlopShape :
public
QGraphicsRectItem {
58
public
:
59
explicit
FlipFlopShape(QGraphicsItem* parent =
nullptr
)
60
: QGraphicsRectItem(FlipFlopBodyRect, parent)
61
{
62
}
63
64
void
paint(QPainter* painter,
const
QStyleOptionGraphicsItem* option,
65
QWidget* widget)
override
66
{
67
Q_UNUSED(option);
68
Q_UNUSED(widget);
69
70
const
QColor ink =
ThemeEngine::getColor
(
theme::ColorToken::Ink
);
71
72
painter->setRenderHint(QPainter::Antialiasing,
false
);
73
painter->setPen(QPen(ink, 3));
74
painter->setBrush(
ThemeEngine::getColor
(
theme::ColorToken::Internal
));
75
painter->drawRect(rect());
76
}
77
};
78
79
}
// namespace
80
81
GraphicalFlipFlop::GraphicalFlipFlop
(
const
Component_ptr
& component,
82
QGraphicsItem* parent)
83
:
GraphicalLogicComponent
(component, new FlipFlopShape(parent), parent)
84
{
85
isEditable
=
false
;
86
printPortNames
=
true
;
87
}
88
89
GraphicalDFlipFlop::GraphicalDFlipFlop
(QGraphicsItem* parent)
90
:
GraphicalFlipFlop
(makeDFlipFlop(), parent)
91
{
92
setPorts
({
PortPair
{
"d"
, QPoint(-20, 20)},
PortPair
{
"clk"
, QPoint(-20, 60)},
93
PortPair
{
"clr"
, QPoint(40, -20)},
PortPair
{
"pre"
, QPoint(40, 100)}},
94
{
PortPair
{
"q"
, QPoint(100, 20)},
PortPair
{
"!q"
, QPoint(100, 60)}});
95
}
96
97
GraphicalEFlipFlop::GraphicalEFlipFlop
(QGraphicsItem* parent)
98
:
GraphicalFlipFlop
(makeEFlipFlop(), parent)
99
{
100
setPorts
({
PortPair
{
"d"
, QPoint(-20, 20)},
PortPair
{
"en"
, QPoint(-20, 40)},
101
PortPair
{
"clk"
, QPoint(-20, 60)},
PortPair
{
"clr"
, QPoint(40, -20)},
102
PortPair
{
"pre"
, QPoint(40, 100)}},
103
{
PortPair
{
"q"
, QPoint(100, 20)},
PortPair
{
"!q"
, QPoint(100, 60)}});
104
}
105
106
GraphicalDLatch::GraphicalDLatch
(QGraphicsItem* parent)
107
:
GraphicalFlipFlop
(makeDLatch(), parent)
108
{
109
setPorts
({
PortPair
{
"d"
, QPoint(-20, 20)},
PortPair
{
"en"
, QPoint(-20, 60)}},
110
{
PortPair
{
"q"
, QPoint(100, 20)},
PortPair
{
"!q"
, QPoint(100, 60)}});
111
}
112
113
GraphicalJKFlipFlop::GraphicalJKFlipFlop
(QGraphicsItem* parent)
114
:
GraphicalFlipFlop
(makeJKFlipFlop(), parent)
115
{
116
setPorts
({
PortPair
{
"j"
, QPoint(-20, 20)},
PortPair
{
"k"
, QPoint(-20, 40)},
117
PortPair
{
"clk"
, QPoint(-20, 60)},
PortPair
{
"clr"
, QPoint(40, -20)},
118
PortPair
{
"pre"
, QPoint(40, 100)}},
119
{
PortPair
{
"q"
, QPoint(100, 20)},
PortPair
{
"!q"
, QPoint(100, 60)}});
120
}
121
122
}
// namespace SILICON::ui
SILICON::ui::GraphicalComponent::printPortNames
bool printPortNames
Whether to print port names.
Definition
graphicalComponent.hpp:259
SILICON::ui::GraphicalDFlipFlop::GraphicalDFlipFlop
GraphicalDFlipFlop(QGraphicsItem *parent=nullptr)
Definition
graphicalFlipFlops.cpp:89
SILICON::ui::GraphicalDLatch::GraphicalDLatch
GraphicalDLatch(QGraphicsItem *parent=nullptr)
Definition
graphicalFlipFlops.cpp:106
SILICON::ui::GraphicalEFlipFlop::GraphicalEFlipFlop
GraphicalEFlipFlop(QGraphicsItem *parent=nullptr)
Definition
graphicalFlipFlops.cpp:97
SILICON::ui::GraphicalFlipFlop::GraphicalFlipFlop
GraphicalFlipFlop(const Component_ptr &component, QGraphicsItem *parent=nullptr)
Definition
graphicalFlipFlops.cpp:81
SILICON::ui::GraphicalJKFlipFlop::GraphicalJKFlipFlop
GraphicalJKFlipFlop(QGraphicsItem *parent=nullptr)
Definition
graphicalFlipFlops.cpp:113
SILICON::ui::GraphicalLogicComponent::setPorts
void setPorts(const std::vector< PortPair > &busToPortInputs, const std::vector< PortPair > &busToPortOutputs) override
Sets ports and validates against component I/O.
Definition
graphicalLogicComponent.cpp:143
SILICON::ui::GraphicalLogicComponent::isEditable
bool isEditable
Whether the component allows property editing.
Definition
graphicalLogicComponent.hpp:65
SILICON::ui::GraphicalLogicComponent::GraphicalLogicComponent
GraphicalLogicComponent(ItemCategory category, const Component_ptr &component, QGraphicsItem *shape, QGraphicsItem *parent, bool scanShape=false)
Definition
graphicalLogicComponent.cpp:26
SILICON::ui::ThemeEngine::getColor
static const QColor & getColor(theme::ColorToken token)
Definition
theme.hpp:92
graphicalFlipFlops.hpp
SILICON::core::Component_ptr
std::shared_ptr< Component > Component_ptr
Definition
component_registry.hpp:33
SILICON::core::Wire_ptr
std::shared_ptr< Wire > Wire_ptr
Definition
wire.hpp:116
SILICON::ui::theme::ColorToken::Ink
@ Ink
Definition
theme.hpp:40
SILICON::ui::theme::ColorToken::Internal
@ Internal
Definition
theme.hpp:39
SILICON::ui
Definition
actionGroups.hpp:14
SILICON::ui::PortPair
std::pair< QString, QPoint > PortPair
Definition
graphicalComponent.hpp:42
theme.hpp
src
ui
circuit
components
graphicalFlipFlops.cpp
Generated by
1.17.0