modernize: Reformat ALL the source... again!
[quassel.git] / src / qtui / verticaldock.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #include "verticaldock.h"
22
23 #include <QDebug>
24 #include <QLayout>
25 #include <QPainter>
26 #include <qdrawutil.h>
27
28 VerticalDockTitle::VerticalDockTitle(QDockWidget* parent)
29     : QWidget(parent)
30 {}
31
32 QSize VerticalDockTitle::sizeHint() const
33 {
34     return {8, 15};
35 }
36
37 QSize VerticalDockTitle::minimumSizeHint() const
38 {
39     return {8, 10};
40 }
41
42 void VerticalDockTitle::paintEvent(QPaintEvent* event)
43 {
44     Q_UNUSED(event);
45
46     QPainter painter(this);
47
48     if (rect().isValid() && rect().height() > minimumSizeHint().height()) {
49         for (int i = 0; i < 2; i++) {
50             QPoint topLeft = rect().topLeft() + QPoint(3 + i * 2, 2);
51             QPoint bottomRight = rect().topLeft() + QPoint(3 + i * 2, rect().height() - 2);
52             qDrawShadeLine(&painter, topLeft, bottomRight, palette());
53         }
54     }
55 }
56
57 // ==============================
58 //  Vertical Dock
59 // ==============================
60 VerticalDock::VerticalDock(const QString& title, QWidget* parent, Qt::WindowFlags flags)
61     : QDockWidget(title, parent, flags)
62 {
63     setDefaultTitleWidget();
64 }
65
66 VerticalDock::VerticalDock(QWidget* parent, Qt::WindowFlags flags)
67     : QDockWidget(parent, flags)
68 {
69     setDefaultTitleWidget();
70     setContentsMargins(0, 0, 0, 0);
71 }
72
73 void VerticalDock::setDefaultTitleWidget()
74 {
75     QWidget* oldDockTitle = titleBarWidget();
76     QWidget* newDockTitle = new VerticalDockTitle(this);
77
78     setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
79     setFeatures(features() | QDockWidget::DockWidgetVerticalTitleBar);
80     setTitleBarWidget(newDockTitle);
81
82     if (oldDockTitle)
83         oldDockTitle->deleteLater();
84 }
85
86 void VerticalDock::showTitle(bool show)
87 {
88     QWidget* oldDockTitle = titleBarWidget();
89     QWidget* newDockTitle = nullptr;
90
91     if (show)
92         newDockTitle = new VerticalDockTitle(this);
93     else
94         newDockTitle = new EmptyDockTitle(this);
95
96     setTitleBarWidget(newDockTitle);
97     if (oldDockTitle)
98         oldDockTitle->deleteLater();
99 }