Quassel IRC  Pre-Release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
verticaldock.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2015 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 <qdrawutil.h>
24 #include <QLayout>
25 #include <QPainter>
26 
27 #include <QDebug>
28 
30  : QWidget(parent)
31 {
32 }
33 
34 
36 {
37  return QSize(8, 15);
38 }
39 
40 
42 {
43  return QSize(8, 10);
44 }
45 
46 
47 void VerticalDockTitle::paintEvent(QPaintEvent *event)
48 {
49  Q_UNUSED(event);
50 
51  QPainter painter(this);
52 
53  if (rect().isValid() && rect().height() > minimumSizeHint().height()) {
54  for (int i = 0; i < 2; i++) {
55  QPoint topLeft = rect().topLeft() + QPoint(3 + i*2, 2);
56  QPoint bottomRight = rect().topLeft() + QPoint(3 + i*2, rect().height() - 2);
57  qDrawShadeLine(&painter, topLeft, bottomRight, palette());
58  }
59  }
60 }
61 
62 
63 // ==============================
64 // Vertical Dock
65 // ==============================
66 VerticalDock::VerticalDock(const QString &title, QWidget *parent, Qt::WindowFlags flags)
67  : QDockWidget(title, parent, flags)
68 {
70 }
71 
72 
73 VerticalDock::VerticalDock(QWidget *parent, Qt::WindowFlags flags)
74  : QDockWidget(parent, flags)
75 {
77  setContentsMargins(0, 0, 0, 0);
78 }
79 
80 
82 {
83  QWidget *oldDockTitle = titleBarWidget();
84  QWidget *newDockTitle = new VerticalDockTitle(this);
85 
86  setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
87  setFeatures(features() | QDockWidget::DockWidgetVerticalTitleBar);
88  setTitleBarWidget(newDockTitle);
89 
90  if (oldDockTitle)
91  oldDockTitle->deleteLater();
92 }
93 
94 
95 void VerticalDock::showTitle(bool show)
96 {
97  QWidget *oldDockTitle = titleBarWidget();
98  QWidget *newDockTitle = 0;
99 
100  if (show)
101  newDockTitle = new VerticalDockTitle(this);
102  else
103  newDockTitle = new EmptyDockTitle(this);
104 
105  setTitleBarWidget(newDockTitle);
106  if (oldDockTitle)
107  oldDockTitle->deleteLater();
108 }