JKQtExtras
a library of useful Qt widgets and tools
jkqtevisiblehandlesplitter.h
1 /*
2  Copyright (c) 2008-2020 Jan W. Krieger (<jan@jkrieger.de>)
3 
4  This software is free software: you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License (LGPL) as published by
6  the Free Software Foundation, either version 2.1 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU Lesser General Public License (LGPL) for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License (LGPL)
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef JKQTEVISIBLEHANDLESPLITTER_H
19 #define JKQTEVISIBLEHANDLESPLITTER_H
20 
21 #include <QSplitter>
22 #include <QSplitterHandle>
23 #include "jkqtextras_imexport.h"
24 
25 /*! \brief a QSplitter that has a really visible Splitter handle
26  \ingroup JKQtExtrasWidgetsLayout
27 
28  This is a simple replacement for <a href="https://doc.qt.io/qt-5/qsplitter.html">QSplitter</a>,
29  which only adds sime visual tweaks:
30  - a better visible handle
31  - a highlighting/hover effect
32  - a changeable grip width
33  .
34 
35  The splitter looks like this:
36  \image html JKQTEVisibleHandleSplitter.png
37  \image html JKQTEVisibleHandleSplitterHover.png
38 
39  Usage is simple:
40 
41  \snippet jkqtextras_test/testmainwindow.cpp Example: JKQTEVisibleHandleSplitter
42 
43  */
45  Q_OBJECT
46  Q_PROPERTY(bool decorated READ decorated WRITE setDecorated USER true)
47  Q_PROPERTY(bool hoverEffect READ hoverEffect WRITE setHoverEffect USER true)
48  Q_PROPERTY(int gripWidth READ gripWidth WRITE setGripWidth USER true)
49  public:
50  explicit JKQTEVisibleHandleSplitter(Qt::Orientation orientation, QWidget *parent = nullptr);
51  explicit JKQTEVisibleHandleSplitter(QWidget *parent = nullptr);
52  /** \brief indicates whether the decoration of the handle is on or off (decoration is a roughed up surface area) */
53  bool decorated() const;
54  /** \brief indicates whether the hover effect of the handle is on or off (hover effect highlights the handle when the mouse hovers over it) */
55  bool hoverEffect() const;
56  /** \brief the width of the handle */
57  int gripWidth() const;
58  public slots:
59  /** \brief switches the decoration of the handle on or off (decoration is a roughed up surface area) */
60  void setDecorated(bool enabled);
61  /** \brief switches the hover effect of the handle on or off (hover effect highlights the handle when the mouse hovers over it) */
62  void setHoverEffect(bool enabled);
63  /** \brief sets the width of the handle */
64  void setGripWidth(int width);
65  signals:
66 
67  public slots:
68 
69  protected:
70  QSplitterHandle *createHandle();
71 
72 };
73 
74 
75 
76 /*! \brief a QSplitterHandle that is really visible Splitter handle (used by JKQTEVisibleHandleSplitter)
77  \ingroup JKQtExtrasWidgetsLayout
78 
79  \see JKQTEVisibleHandleSplitter
80 
81  */
83  Q_OBJECT
84  public:
85  JKQTEVisibleHandleSplitterHandle(Qt::Orientation orientation, QSplitter * parent=nullptr);
86  /** \brief switches the decoration of the handle on or off (decoration is a roughed up surface area) */
87  void setDecorated(bool enabled);
88  /** \brief indicates whether the decoration of the handle is on or off (decoration is a roughed up surface area) */
89  bool decorated() const;
90  /** \brief switches the hover effect of the handle on or off (hover effect highlights the handle when the mouse hovers over it) */
91  void setHoverEffect(bool enabled);
92  /** \brief indicates whether the hover effect of the handle is on or off (hover effect highlights the handle when the mouse hovers over it) */
93  bool hoverEffect() const;
94  /** \brief sets the width of the handle */
95  void setGripWidth(int width);
96  /** \brief the width of the handle */
97  int gripWidth() const;
98  protected:
99  virtual void leaveEvent(QEvent* event);
100  virtual void enterEvent(QEvent* event);
101  virtual void paintEvent(QPaintEvent* event);
103  bool m_inside;
104  bool m_lightup;
106 };
107 
108 #endif // JKQTEVISIBLEHANDLESPLITTER_H
JKQTEVisibleHandleSplitter::JKQTEVisibleHandleSplitter
JKQTEVisibleHandleSplitter(Qt::Orientation orientation, QWidget *parent=nullptr)
JKQTEVisibleHandleSplitter::hoverEffect
bool hoverEffect() const
indicates whether the hover effect of the handle is on or off (hover effect highlights the handle whe...
JKQTEVisibleHandleSplitterHandle::gripWidth
int gripWidth() const
the width of the handle
JKQTEVisibleHandleSplitterHandle::m_drawGrip
bool m_drawGrip
Definition: jkqtevisiblehandlesplitter.h:105
JKQTEVisibleHandleSplitter
a QSplitter that has a really visible Splitter handle
Definition: jkqtevisiblehandlesplitter.h:44
JKQTEVisibleHandleSplitter::createHandle
QSplitterHandle * createHandle()
JKQTEVisibleHandleSplitter::decorated
bool decorated() const
indicates whether the decoration of the handle is on or off (decoration is a roughed up surface area)
JKQTEVisibleHandleSplitter::JKQTEVisibleHandleSplitter
JKQTEVisibleHandleSplitter(QWidget *parent=nullptr)
JKQTEVisibleHandleSplitterHandle::m_lightup
bool m_lightup
Definition: jkqtevisiblehandlesplitter.h:104
JKQTEVisibleHandleSplitterHandle
a QSplitterHandle that is really visible Splitter handle (used by JKQTEVisibleHandleSplitter)
Definition: jkqtevisiblehandlesplitter.h:82
JKQTEXTRAS_LIB_EXPORT
#define JKQTEXTRAS_LIB_EXPORT
Definition: jkqtextras_imexport.h:95
JKQTEVisibleHandleSplitterHandle::m_gripHeight
int m_gripHeight
Definition: jkqtevisiblehandlesplitter.h:102
JKQTEVisibleHandleSplitter::setHoverEffect
void setHoverEffect(bool enabled)
switches the hover effect of the handle on or off (hover effect highlights the handle when the mouse ...
JKQTEVisibleHandleSplitterHandle::setHoverEffect
void setHoverEffect(bool enabled)
switches the hover effect of the handle on or off (hover effect highlights the handle when the mouse ...
JKQTEVisibleHandleSplitterHandle::setDecorated
void setDecorated(bool enabled)
switches the decoration of the handle on or off (decoration is a roughed up surface area)
JKQTEVisibleHandleSplitterHandle::setGripWidth
void setGripWidth(int width)
sets the width of the handle
JKQTEVisibleHandleSplitterHandle::m_inside
bool m_inside
Definition: jkqtevisiblehandlesplitter.h:103
JKQTEVisibleHandleSplitterHandle::paintEvent
virtual void paintEvent(QPaintEvent *event)
JKQTEVisibleHandleSplitterHandle::hoverEffect
bool hoverEffect() const
indicates whether the hover effect of the handle is on or off (hover effect highlights the handle whe...
JKQTEVisibleHandleSplitterHandle::decorated
bool decorated() const
indicates whether the decoration of the handle is on or off (decoration is a roughed up surface area)
JKQTEVisibleHandleSplitterHandle::leaveEvent
virtual void leaveEvent(QEvent *event)
JKQTEVisibleHandleSplitterHandle::enterEvent
virtual void enterEvent(QEvent *event)
JKQTEVisibleHandleSplitter::setDecorated
void setDecorated(bool enabled)
switches the decoration of the handle on or off (decoration is a roughed up surface area)
JKQTEVisibleHandleSplitter::gripWidth
int gripWidth() const
the width of the handle
JKQTEVisibleHandleSplitterHandle::JKQTEVisibleHandleSplitterHandle
JKQTEVisibleHandleSplitterHandle(Qt::Orientation orientation, QSplitter *parent=nullptr)
JKQTEVisibleHandleSplitter::setGripWidth
void setGripWidth(int width)
sets the width of the handle