dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
minisplitter.cpp
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #include "minisplitter.h"
29 
30 #include <QPaintEvent>
31 #include <QPainter>
32 #include <QSplitterHandle>
33 
34 namespace Core {
35 namespace Internal {
36 
37  class MiniSplitterHandle : public QSplitterHandle
38  {
39  public:
40  MiniSplitterHandle(Qt::Orientation orientation, QSplitter *parent)
41  : QSplitterHandle(orientation, parent)
42  {
43  setMask(QRegion(contentsRect()));
44  setAttribute(Qt::WA_MouseNoMask, true);
45  }
46 
47  protected:
48  void resizeEvent(QResizeEvent *event);
49  void paintEvent(QPaintEvent *event);
50  };
51 
52 } // namespace Internal
53 } // namespace Core
54 
55 using namespace Core;
56 using namespace Core::Internal;
57 
58 void MiniSplitterHandle::resizeEvent(QResizeEvent *event)
59 {
60  // Warning: We specifically replace the QSplitterHandle::resizeEvent,
61  // since there's no way of doing this while still calling it.
62  // That's because it has pretty much identical code (in 4.7.0) which
63  // undoes what we do here. And they didn't make that code configurable :)
64  // This means that with Qt upgrades it's worthwhile to see if anything changed
65  // in QSplitterHandle::resizeEvent, to see if there's anything important we miss.
66 
67  if (orientation() == Qt::Horizontal)
68  setContentsMargins(6, 0, 6, 0);
69  else
70  setContentsMargins(0, 6, 0, 6);
71  setMask(QRegion(contentsRect()));
72 
73  QWidget::resizeEvent(event);
74 }
75 
76 void MiniSplitterHandle::paintEvent(QPaintEvent *event)
77 {
78  QPainter painter(this);
79  painter.fillRect(event->rect(), QColor(48, 48, 48));
80 }
81 
82 QSplitterHandle *MiniSplitter::createHandle()
83 {
84  return new MiniSplitterHandle(orientation(), this);
85 }
86 
88  : QSplitter(parent)
89 {
90  setHandleWidth(1);
91  setChildrenCollapsible(false);
92  setProperty("minisplitter", true);
93 }
94 
95 MiniSplitter::MiniSplitter(Qt::Orientation orientation)
96  : QSplitter(orientation)
97 {
98  setHandleWidth(1);
99  setChildrenCollapsible(false);
100  setProperty("minisplitter", true);
101 }
MiniSplitterHandle(Qt::Orientation orientation, QSplitter *parent)
QSplitterHandle * createHandle()
void resizeEvent(QResizeEvent *event)
void paintEvent(QPaintEvent *event)
MiniSplitter(QWidget *parent=nullptr)