Scribus
Open source desktop publishing at your fingertips
tablesideselector.h
1 /*
2 Copyright (C) 2011 Elvis Stansvik <elvstone@gmail.com>
3 
4 For general Scribus (>=1.3.2) copyright and licensing information please refer
5 to the COPYING file provided with the program. Following this notice may exist
6 a copyright and/or license notice that predates the release of Scribus 1.3.2
7 for which a new license (GPL+exception) is in place.
8 */
9 #ifndef TABLESIDESELECTOR_H
10 #define TABLESIDESELECTOR_H
11 
12 #include <QFlags>
13 #include <QPen>
14 #include <QList>
15 #include <QFrame>
16 
17 class QPaintEvent;
18 class QMouseEvent;
19 class QEvent;
20 
26 class TableSideSelector : public QFrame
27 {
28  Q_OBJECT
29 
30  Q_PROPERTY(Sides selection READ selection WRITE setSelection RESET clearSelection NOTIFY selectionChanged)
31  Q_PROPERTY(Style style READ style WRITE setStyle)
32 
33 public:
38  enum Side
39  {
40  None = 0,
41  Left = 1,
42  Right = 2,
43  Top = 4,
44  Bottom = 8,
45  All = Left | Right | Top | Bottom
46  };
47  Q_DECLARE_FLAGS(Sides, Side)
48 
49 
53  enum Style
54  {
57  };
58 
60  TableSideSelector(QWidget* parent);
61 
63  Sides selection() const { return m_selection; }
64 
66  QList<TableSideSelector::Side> selectionList() const;
67 
69  void setSelection(Sides selection) { m_selection = selection; emit selectionChanged(); }
70 
72  void clearSelection() { m_selection = None; emit selectionChanged(); }
73 
75  Style style() const { return m_style; }
76 
78  void setStyle(Style style) { m_style = style; }
79 
81  QSize sizeHint() const { return QSize(80, 80); }
82 
84  int heightForWidth(int width) const { return width; }
85 
86 signals:
88  void selectionChanged();
89 
90 protected:
92  void paintEvent(QPaintEvent* event);
94  void mousePressEvent(QMouseEvent* event);
96  void mouseMoveEvent(QMouseEvent* event);
98  void leaveEvent(QEvent* event);
99 
100 private:
102  Side closestSide(const QPointF& point) const;
103 
104 private:
106  Sides m_selection;
107 
109  Style m_style;
110 
112  Side m_highlighted;
113 
115  QLineF m_left;
116 
118  QLineF m_right;
119 
121  QLineF m_top;
122 
124  QLineF m_bottom;
125 };
126 
127 Q_DECLARE_OPERATORS_FOR_FLAGS(TableSideSelector::Sides)
128 
129 #endif // TABLESIDESELECTOR_H
void mouseMoveEvent(QMouseEvent *event)
Highlights the edge closest to mouse pointer.
Definition: tablesideselector.cpp:108
Definition: tablesideselector.h:44
int heightForWidth(int width) const
Returns width, as the selector is supposed to be square shaped.
Definition: tablesideselector.h:84
void mousePressEvent(QMouseEvent *event)
Toggles selection of the edge closest to mouse pointer.
Definition: tablesideselector.cpp:101
Side
Definition: tablesideselector.h:38
Style style() const
Returns the current style of the selector.
Definition: tablesideselector.h:75
void leaveEvent(QEvent *event)
Removes any highlighted edge.
Definition: tablesideselector.cpp:114
Sides selection() const
Returns the current selection as an ORed combination of enum flags.
Definition: tablesideselector.h:63
Definition: tablesideselector.h:26
Definition: tablesideselector.h:43
void selectionChanged()
Emitted when the selections has changed.
Definition: style.h:37
void setStyle(Style style)
Sets the style of the selector to style.
Definition: tablesideselector.h:78
void paintEvent(QPaintEvent *event)
Paints the table side selector.
Definition: tablesideselector.cpp:50
void setSelection(Sides selection)
Sets the current selection to selection.
Definition: tablesideselector.h:69
QList< TableSideSelector::Side > selectionList() const
Returns the current selection as a list of enum values.
Definition: tablesideselector.cpp:36
void clearSelection()
Clears the current selection.
Definition: tablesideselector.h:72
Definition: tablesideselector.h:42
Definition: tablesideselector.h:41
Definition: tablesideselector.h:40
QSize sizeHint() const
Returns the size hint of the table side selector.
Definition: tablesideselector.h:81
Definition: tablesideselector.h:56
TableSideSelector(QWidget *parent)
Creates a new side selector with all sides selected.
Definition: tablesideselector.cpp:26
Definition: tablesideselector.h:55