2
* chatsplitter.cpp - QSplitter replacement that masquerades it
3
* Copyright (C) 2007 Michail Pishchagin
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
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.
15
* You should have received a copy of the GNU General Public License
16
* along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#include "chatsplitter.h"
24
#include <QVBoxLayout>
25
#include <QChildEvent>
27
#include "psioptions.h"
31
* Handy widget that masquerades itself as QSplitter, and could work
32
* in both QSplitter mode, and QSplitter-less mode.
34
ChatSplitter::ChatSplitter(QWidget* parent)
36
, splitterEnabled_(true)
40
connect(PsiOptions::instance(), SIGNAL(optionChanged(const QString&)), SLOT(optionsChanged()));
48
* Dummy function to fool Qt Designer-generated forms.
50
void ChatSplitter::setOrientation(Qt::Orientation orientation)
52
Q_ASSERT(orientation == Qt::Vertical);
53
Q_UNUSED(orientation);
57
* Adds the given \a widget to the splitter's layout after all the
58
* other items. Don't call this function if widget is already added
59
* to the splitter's layout.
61
void ChatSplitter::addWidget(QWidget* widget)
63
Q_ASSERT(!children_.contains(widget));
65
connect(widget, SIGNAL(destroyed(QObject*)), SLOT(childDestroyed(QObject*)));
66
updateChildLayout(widget);
70
* If splitter mode is enabled, the \a list is passed to the
71
* actual splitter. Has no effect otherwise.
73
void ChatSplitter::setSizes(const QList<int>& list)
76
splitter_->setSizes(list);
80
* Moves \a child either to the real QSplitter, or adds it to the
83
void ChatSplitter::updateChildLayout(QWidget* child)
85
if (splitterEnabled() && splitter_) {
86
splitter_->addWidget(child);
89
layout_->addWidget(child);
94
* Removes destroyed widget from the splitter's child list.
96
void ChatSplitter::childDestroyed(QObject* obj)
98
Q_ASSERT(obj->isWidgetType());
99
children_.removeAll(static_cast<QWidget*>(obj));
103
* If \a enable is true, the true QSplitter gets enabled, otherwise
104
* all widgets are managed by QLayout.
106
void ChatSplitter::setSplitterEnabled(bool enable)
108
if (splitterEnabled_ == enable)
111
splitterEnabled_ = enable;
116
* Invalidates layout and moves all child widgets to the proper position.
118
void ChatSplitter::updateLayout()
120
foreach(QWidget* child, children_)
121
child->setParent(this);
125
splitter_ = new QSplitter(this);
126
layout_ = new QVBoxLayout(this);
127
layout_->setMargin(0);
128
layout_->addWidget(splitter_);
129
splitter_->setOrientation(Qt::Vertical);
130
splitter_->setVisible(splitterEnabled());
132
foreach(QWidget* child, children_)
133
updateChildLayout(child);
137
* Updates layout according to current options.
138
* FIXME: When option.chatLineEdit finally makes it to PsiOptions, make this slot
141
void ChatSplitter::optionsChanged()
143
setSplitterEnabled(!option.chatLineEdit);