~ubuntu-branches/ubuntu/karmic/psi/karmic

« back to all changes in this revision

Viewing changes to src/chatsplitter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-04-14 18:57:30 UTC
  • mfrom: (2.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080414185730-528re3zp0m2hdlhi
Tags: 0.11-8
* added CONFIG -= link_prl to .pro files and removed dependencies
  which are made unnecessary by this change
* Fix segfault when closing last chat tab with qt4.4
  (This is from upstream svn, rev. 1101) (Closes: Bug#476122)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * chatsplitter.cpp - QSplitter replacement that masquerades it
 
3
 * Copyright (C) 2007  Michail Pishchagin
 
4
 *
 
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.
 
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 library; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 *
 
19
 */
 
20
 
 
21
#include "chatsplitter.h"
 
22
 
 
23
#include <QSplitter>
 
24
#include <QVBoxLayout>
 
25
#include <QChildEvent>
 
26
 
 
27
#include "psioptions.h"
 
28
#include "common.h"
 
29
 
 
30
/**
 
31
 * Handy widget that masquerades itself as QSplitter, and could work
 
32
 * in both QSplitter mode, and QSplitter-less mode.
 
33
 */
 
34
ChatSplitter::ChatSplitter(QWidget* parent)
 
35
        : QWidget(parent)
 
36
        , splitterEnabled_(true)
 
37
        , splitter_(0)
 
38
        , layout_(0)
 
39
{
 
40
        connect(PsiOptions::instance(), SIGNAL(optionChanged(const QString&)), SLOT(optionsChanged()));
 
41
        optionsChanged();
 
42
 
 
43
        if (!layout_)
 
44
                updateLayout();
 
45
}
 
46
 
 
47
/**
 
48
 * Dummy function to fool Qt Designer-generated forms.
 
49
 */
 
50
void ChatSplitter::setOrientation(Qt::Orientation orientation)
 
51
{
 
52
        Q_ASSERT(orientation == Qt::Vertical);
 
53
        Q_UNUSED(orientation);
 
54
}
 
55
 
 
56
/**
 
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.
 
60
 */
 
61
void ChatSplitter::addWidget(QWidget* widget)
 
62
{
 
63
        Q_ASSERT(!children_.contains(widget));
 
64
        children_ << widget;
 
65
        connect(widget, SIGNAL(destroyed(QObject*)), SLOT(childDestroyed(QObject*)));
 
66
        updateChildLayout(widget);
 
67
}
 
68
 
 
69
/**
 
70
 * If splitter mode is enabled, the \a list is passed to the
 
71
 * actual splitter. Has no effect otherwise.
 
72
 */
 
73
void ChatSplitter::setSizes(const QList<int>& list)
 
74
{
 
75
        if (splitter_)
 
76
                splitter_->setSizes(list);
 
77
}
 
78
 
 
79
/**
 
80
 * Moves \a child either to the real QSplitter, or adds it to the
 
81
 * private layout.
 
82
 */
 
83
void ChatSplitter::updateChildLayout(QWidget* child)
 
84
{
 
85
        if (splitterEnabled() && splitter_) {
 
86
                splitter_->addWidget(child);
 
87
        }
 
88
        else {
 
89
                layout_->addWidget(child);
 
90
        }
 
91
}
 
92
 
 
93
/**
 
94
 * Removes destroyed widget from the splitter's child list.
 
95
 */
 
96
void ChatSplitter::childDestroyed(QObject* obj)
 
97
{
 
98
        Q_ASSERT(obj->isWidgetType());
 
99
        children_.removeAll(static_cast<QWidget*>(obj));
 
100
}
 
101
 
 
102
/**
 
103
 * If \a enable is true, the true QSplitter gets enabled, otherwise
 
104
 * all widgets are managed by QLayout.
 
105
 */
 
106
void ChatSplitter::setSplitterEnabled(bool enable)
 
107
{
 
108
        if (splitterEnabled_ == enable)
 
109
                return;
 
110
 
 
111
        splitterEnabled_ = enable;
 
112
        updateLayout();
 
113
}
 
114
 
 
115
/**
 
116
 * Invalidates layout and moves all child widgets to the proper position.
 
117
 */
 
118
void ChatSplitter::updateLayout()
 
119
{
 
120
        foreach(QWidget* child, children_)
 
121
                child->setParent(this);
 
122
 
 
123
        delete splitter_;
 
124
        delete layout_;
 
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());
 
131
 
 
132
        foreach(QWidget* child, children_)
 
133
                updateChildLayout(child);
 
134
}
 
135
 
 
136
/**
 
137
 * Updates layout according to current options.
 
138
 * FIXME: When option.chatLineEdit finally makes it to PsiOptions, make this slot
 
139
 *        private.
 
140
 */
 
141
void ChatSplitter::optionsChanged()
 
142
{
 
143
        setSplitterEnabled(!option.chatLineEdit);
 
144
}