Fix includes
[quassel.git] / src / qtui / verticaldock.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005/06 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  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #include "verticaldock.h"
22
23 #include <qdrawutil.h>
24 #include <QLayout>
25 #include <QPainter>
26
27 #include <QDebug>
28
29 VerticalDockTitle::VerticalDockTitle(QDockWidget *parent)
30   : QWidget(parent)
31 {
32 }
33
34 QSize VerticalDockTitle::sizeHint() const {
35   return QSize(8, 15);
36 }
37
38 QSize VerticalDockTitle::minimumSizeHint() const {
39   return QSize(8, 10);
40 }
41
42 void VerticalDockTitle::paintEvent(QPaintEvent *event) {
43   Q_UNUSED(event);
44
45   QPainter painter(this);
46   
47   if(rect().isValid() && rect().height() > minimumSizeHint().height()) {
48     for(int i = 0; i < 2; i++) {
49       QPoint topLeft = rect().topLeft() + QPoint(3 + i*2, 2);
50       QPoint bottomRight = rect().topLeft() + QPoint(3 + i*2, rect().height() - 2);
51       qDrawShadeLine(&painter, topLeft, bottomRight, palette());
52     }
53   }
54 }
55
56 // ==============================
57 //  Vertical Dock
58 // ==============================
59 VerticalDock::VerticalDock(const QString &title, QWidget *parent, Qt::WindowFlags flags)
60   : QDockWidget(title, parent, flags)
61 {
62   setDefaultTitleWidget();
63 }
64
65 VerticalDock::VerticalDock(QWidget *parent, Qt::WindowFlags flags)
66   : QDockWidget(parent, flags)
67 {
68   setDefaultTitleWidget();
69   setContentsMargins(0, 0, 0, 0);
70 }
71
72 void VerticalDock::setDefaultTitleWidget() {
73   QWidget *oldDockTitle = titleBarWidget();
74   QWidget *newDockTitle = new VerticalDockTitle(this);
75
76   setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
77   setFeatures(features() | QDockWidget::DockWidgetVerticalTitleBar);
78   setTitleBarWidget(newDockTitle);
79   
80   if(oldDockTitle)
81     oldDockTitle->deleteLater();
82 }
83
84 void VerticalDock::showTitle(bool show) {
85   QWidget *oldDockTitle = titleBarWidget();
86   QWidget *newDockTitle = 0;
87   
88   if(show)
89     newDockTitle = new VerticalDockTitle(this);
90   else
91     newDockTitle = new EmptyDockTitle(this);
92
93   setTitleBarWidget(newDockTitle);
94   if(oldDockTitle)
95     oldDockTitle->deleteLater();
96 }