| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#ifndef AVOGADRO_QTGUI_PERIODICTABLEVIEW_H |
| 7 |
#define AVOGADRO_QTGUI_PERIODICTABLEVIEW_H |
| 8 |
|
| 9 |
#include "avogadroqtguiexport.h" |
| 10 |
|
| 11 |
#include <QtWidgets/QGraphicsView> |
| 12 |
|
| 13 |
namespace Avogadro { |
| 14 |
namespace QtGui { |
| 15 |
|
| 16 |
/** |
| 17 |
* @class PeriodicTableView periodictableview.h |
| 18 |
* <avogadro/qtgui/periodictableview.h> |
| 19 |
* @author Marcus D. Hanwell |
| 20 |
* @brief This class implements the view of the periodic table showing all |
| 21 |
* elements. |
| 22 |
* |
| 23 |
* This is the class that actually draws the widget onto screen. This is |
| 24 |
* the class that should normally be instantiated in order to display a |
| 25 |
* Periodic Table. |
| 26 |
*/ |
| 27 |
class AVOGADROQTGUI_EXPORT PeriodicTableView : public QGraphicsView |
| 28 |
{ |
| 29 |
Q_OBJECT |
| 30 |
|
| 31 |
public: |
| 32 |
/** |
| 33 |
* Constructor - constructs a new PeriodicTableView with an internal instance |
| 34 |
* of PeriodicTableScene. |
| 35 |
*/ |
| 36 |
explicit PeriodicTableView(QWidget* parent_ = nullptr); |
| 37 |
~PeriodicTableView() override; |
| 38 |
|
| 39 |
/** |
| 40 |
* @return The currently selected element. |
| 41 |
*/ |
| 42 |
int element() const { return m_element; } |
| 43 |
|
| 44 |
public slots: |
| 45 |
/** |
| 46 |
* @param element_ The currently selected element. |
| 47 |
*/ |
| 48 |
void setElement(int element_); |
| 49 |
|
| 50 |
/** |
| 51 |
* This slot is called to clear the key buffer (e.g. after a delay in typing). |
| 52 |
*/ |
| 53 |
void clearKeyPressBuffer(); |
| 54 |
|
| 55 |
private slots: |
| 56 |
/** |
| 57 |
* Use this slot to change the active element. |
| 58 |
*/ |
| 59 |
void elementClicked(int element); |
| 60 |
|
| 61 |
signals: |
| 62 |
/** |
| 63 |
* Signal emitted when the active element in the PeriodicTableView changes. |
| 64 |
*/ |
| 65 |
void elementChanged(int element); |
| 66 |
|
| 67 |
protected: |
| 68 |
/** |
| 69 |
* Double click event - select an element and hide the PeriodicTableView. |
| 70 |
*/ |
| 71 |
void mouseDoubleClickEvent(QMouseEvent* event) override; |
| 72 |
|
| 73 |
/** |
| 74 |
* Handles the keyboard events to change the active element. |
| 75 |
*/ |
| 76 |
void keyPressEvent(QKeyEvent* event_) override; |
| 77 |
|
| 78 |
/** |
| 79 |
* Handle resize events. |
| 80 |
*/ |
| 81 |
void resizeEvent(QResizeEvent* event) override; |
| 82 |
|
| 83 |
private: |
| 84 |
/** |
| 85 |
* Proton number of the active element. |
| 86 |
*/ |
| 87 |
int m_element; |
| 88 |
|
| 89 |
QString m_keyPressBuffer; |
| 90 |
}; |
| 91 |
|
| 92 |
} // namespace QtGui |
| 93 |
} // namespace Avogadro |
| 94 |
|
| 95 |
#endif |