6822a3be |
1 | // Created on: 2017-06-16 |
2 | // Created by: Natalia ERMOLAEVA |
3 | // Copyright (c) 2017 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #ifndef View_ToolButton_H |
17 | #define View_ToolButton_H |
18 | |
19 | #include <Standard_WarningsDisable.hxx> |
20 | #include <QToolButton> |
21 | #include <QMouseEvent> |
22 | #include <QWidget> |
23 | #include <Standard_WarningsRestore.hxx> |
24 | |
25 | //! \class View_Widget |
26 | //! \brief It is a Qt control that implements change checked state for button by double click event |
27 | //! Button becomes checked by double click mouse pressed and unchecked by the next press mouse |
28 | class View_ToolButton : public QToolButton |
29 | { |
30 | Q_OBJECT |
31 | |
32 | public: |
33 | View_ToolButton (QWidget* theParent) : QToolButton (theParent) {} |
34 | ~View_ToolButton() {} |
35 | |
36 | //! Sets the button checkable, set whether the button checkable or not |
37 | //! \param theChecked boolean value |
38 | void SetButtonChecked (const bool theChecked) {setCheckable (theChecked); setChecked (theChecked); emit checkedStateChanged (theChecked); } |
39 | |
40 | signals: |
41 | //! Sends a signal about checked state is changed |
42 | //! \param theState the checked state |
43 | void checkedStateChanged (bool theState); |
44 | |
45 | protected: |
46 | //! Sets the button unchecked if it was checked |
47 | virtual void mousePressEvent (QMouseEvent* theEvent) |
48 | { |
49 | if (isChecked()) |
50 | SetButtonChecked (false); |
51 | else |
52 | QToolButton::mousePressEvent (theEvent); |
53 | } |
54 | |
55 | //! Sets the button checked if it was unchecked |
56 | virtual void mouseDoubleClickEvent (QMouseEvent* theEvent) |
57 | { |
58 | QToolButton::mouseDoubleClickEvent (theEvent); |
59 | if (!isChecked()) |
60 | SetButtonChecked (true); |
61 | } |
62 | }; |
63 | |
64 | #endif |