BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
WidgetMoverButton.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/SampleDesigner/WidgetMoverButton.h
6 //! @brief Defines class WidgetMoverButton
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2021
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_WIDGETMOVERBUTTON_H
16 #define BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_WIDGETMOVERBUTTON_H
17 
18 #include <QMap>
19 #include <QTimer>
20 #include <QToolButton>
21 
22 class QScrollArea;
23 class QPropertyAnimation;
24 
25 //! Button to move a widget vertically in a layout.
26 //!
27 //! With this button, the "move layer" feature in the layer oriented sample editor is realized
28 //! (it is the button on each LayerForm).
29 //!
30 //! When pressing the button, the parent layout of the widget is deactivated, and the widget is
31 //! moved to the position where the pressed mouse cursor is moved.
32 //! When the mouse is released, the layout is again activated and a signal finishedMoving() is
33 //! emitted. Any reordering of the widgets in the layout then has to be handled outside - no
34 //! reordering is done in here.
35 class WidgetMoverButton : public QToolButton {
36  Q_OBJECT
37 public:
38  //! Create a widget mover button.
39  //!
40  //! If the widget shall not be able to be dragged on the top position, this can be defined by
41  //! ignoreOnTop (the number of widgets at the top of the layout which shall not be affected by
42  //! the reordering). In the case of the layer moving, the topmost Form (the sample
43  //! properties) shall not be part of reordering.
44  WidgetMoverButton(QWidget* parent, QWidget* widgetToMove, int ignoreOnTop = 0);
45 
46 protected:
47  void mousePressEvent(QMouseEvent* event) override;
48  void mouseReleaseEvent(QMouseEvent* event) override;
49  void mouseMoveEvent(QMouseEvent* event) override;
50 
51 signals:
53  void finishedMoving(QWidget* widgetToMove, QWidget* moveAboveThisWidget);
54 
55 private:
56  void scrollParent(bool up);
57 
58 private:
59  bool m_started = false;
61  QLayout* m_layoutToDeactivate = nullptr;
62  QWidget* m_widgetToMove;
68  QScrollArea* m_scrollArea;
69  QPoint m_hotSpot; //!< The mouse-down coordinates in the widget to move
70  QMap<QWidget*, QPropertyAnimation*> m_animations;
71 };
72 
73 
74 #endif // BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_WIDGETMOVERBUTTON_H
Button to move a widget vertically in a layout.
void mouseMoveEvent(QMouseEvent *event) override
void mousePressEvent(QMouseEvent *event) override
WidgetMoverButton(QWidget *parent, QWidget *widgetToMove, int ignoreOnTop=0)
Create a widget mover button.
void mouseReleaseEvent(QMouseEvent *event) override
QScrollArea * m_scrollArea
QLayout * m_layoutToDeactivate
void finishedMoving(QWidget *widgetToMove, QWidget *moveAboveThisWidget)
QMap< QWidget *, QPropertyAnimation * > m_animations
QWidget * m_dropAboveThisWidget
void scrollParent(bool up)
QPoint m_hotSpot
The mouse-down coordinates in the widget to move.