HAL
graph_widget.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4 // Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5 // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6 // Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
26 #pragma once
27 
28 #include "hal_core/defines.h"
29 
30 #include "gui/gui_globals.h"
31 #include "gui/gui_def.h"
33 
34 #include <deque>
35 
36 namespace hal
37 {
38  class WidgetOverlay;
39  class GraphContext;
40  class GraphGraphicsView;
41  class SpinnerWidget;
42  class SettingsItemSpinbox;
43  class GraphNavigationWidget;
44  class AbstractBusyIndicator;
45  class CommentWidget;
46 
54  class GraphWidget : public ContentWidget
55  {
56  Q_OBJECT
57 
58  public:
65  explicit GraphWidget(GraphContext* context, QWidget* parent = nullptr);
66 
70  ~GraphWidget();
71 
77  GraphContext* getContext() const;
78 
83  void handleSceneAvailable();
89 
94 
98  void storeViewport();
99 
106 
110  void ensureSelectionVisible();
111 
116  void showProgress(int percent, const QString& text=QString());
117 
122  void showComments(const Node& nd);
123 
124  void showBusy(int percent, const QString& text);
125 
126  void focusGate(u32 gateId);
127  void focusNet(u32 netId);
128  void focusModule(u32 moduleId);
129  static void pluginProgressIndicator(int percent, const std::string& msg);
130 
131  protected:
138  void keyPressEvent(QKeyEvent* event) override;
139 
140  private Q_SLOTS:
141  void handleNavigationJumpRequested(const Node& origin, const u32 via_net, const QSet<u32>& to_gates, const QSet<u32>& to_modules);
142  void handleModuleDoubleClicked(const u32 id);
143  void resetFocus();
144  void hideOverlay();
145 
146  private:
147  void handleNavigationLeftRequest();
148  void handleNavigationRightRequest();
149  void handleNavigationUpRequest();
150  void handleNavigationDownRequest();
151 
152  void substituteByVisibleModules(const QSet<u32>& gates, const QSet<u32>& modules, QSet<u32>& insert_gates, QSet<u32>& insert_modules,
153  QSet<u32>& remove_gates, QSet<u32>& remove_modules) const;
154 
155  void handleEnterModuleRequested(const u32 id);
156 
157  void ensureItemsVisible(const QSet<u32>& gates, const QSet<u32>& modules);
158 
159  void focusRect(QRectF targetRect, bool applyCenterFix);
160 
161  bool hasFocusedItem(SelectionRelay::Subfocus navigateDirection) const;
162 
163  bool hasGate(const Gate* g) const;
164 
165  GraphGraphicsView* mView;
166  GraphContext* mContext;
167 
168  WidgetOverlay* mOverlay;
169  GraphNavigationWidget* mNavigationWidgetV3;
170  AbstractBusyIndicator* mProgressBar;
171 
172  SpinnerWidget* mSpinnerWidget;
173  CommentWidget* mCommentWidget;
174 
175  u32 mCurrentExpansion;
176 
177  QRectF mRectAfterFocus;
178  QRectF mLastTargetRect;
179 
180  class StoreViewport
181  {
182  public:
183  bool mValid;
184  QRectF mRect;
185  QPair<QPoint,QPointF> mGrid;
186  StoreViewport() : mValid(false) {;}
187  };
188 
189  QRectF restoreViewport(bool reset = true);
190 
191  StoreViewport mStoreViewport;
192 
193  static SettingsItemSpinbox* sSettingAnimationDuration;
194 
195  static GraphWidget* sInstance;
196 
197  };
198 }
Abstract class for Widgets within HAL's ContentArea.
Definition: gate.h:58
Logical container for modules, gates, and nets.
Definition: graph_context.h:55
A view to display the rendered graph (needs a GraphicsScene).
Wraps a GraphContext and a GraphGraphicsView.
Definition: graph_widget.h:55
GraphWidget(GraphContext *context, QWidget *parent=nullptr)
void ensureSelectionVisible()
void keyPressEvent(QKeyEvent *event) override
void handleSceneUnavailable()
void showBusy(int percent, const QString &text)
GraphContext * getContext() const
void showProgress(int percent, const QString &text=QString())
static void pluginProgressIndicator(int percent, const std::string &msg)
void handleSceneAvailable()
void focusGate(u32 gateId)
void focusModule(u32 moduleId)
GraphGraphicsView * view()
void showComments(const Node &nd)
void focusNet(u32 netId)
void handleContextAboutToBeDeleted()
The Node class object represents a module or a gate.
Definition: gui_def.h:61
A SettingsItem that represents a spinbox.
A loading wheel.
Container for a QWidget that overlays another one.
quint32 u32
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
QObject * parent() const const
virtual bool event(QEvent *event) override