1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the designer application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "spacer_widget_p.h"
30
#include "layoutinfo_p.h"
32
#include <QtDesigner/abstractformwindow.h>
34
#include <QtGui/QLayout>
35
#include <QtGui/QPainter>
36
#include <QtCore/qdebug.h>
38
Spacer::Spacer(QWidget *parent)
40
orient(Qt::Vertical), interactive(true), sh(20, 40)
42
setAttribute(Qt::WA_MouseNoMask);
43
m_formWindow = QDesignerFormWindowInterface::findFormWindow(this);
45
setSizeType(QSizePolicy::Expanding);
48
void Spacer::paintEvent(QPaintEvent *)
50
// Only draw spacers when we're editting widgets
51
if (m_formWindow != 0 && m_formWindow->currentTool() != 0)
57
if (orient == Qt::Horizontal) {
59
const int amplitude = qMin(3, height() / 3);
60
const int base = height() / 2;
63
for (i = 0; i < width() / 3 +2; ++i)
64
p.drawLine(i * dist, base - amplitude, i * dist + dist / 2, base + amplitude);
66
for (i = 0; i < width() / 3 +2; ++i)
67
p.drawLine(i * dist + dist / 2, base + amplitude, i * dist + dist, base - amplitude);
69
p.drawLine(0, y-10, 0, y+10);
70
p.drawLine(width() - 1, y-10, width() - 1, y+10);
73
const int amplitude = qMin(3, width() / 3);
74
const int base = width() / 2;
77
for (i = 0; i < height() / 3 +2; ++i)
78
p.drawLine(base - amplitude, i * dist, base + amplitude,i * dist + dist / 2);
80
for (i = 0; i < height() / 3 +2; ++i)
81
p.drawLine(base + amplitude, i * dist + dist / 2, base - amplitude, i * dist + dist);
83
p.drawLine(x-10, 0, x+10, 0);
84
p.drawLine(x-10, height() - 1, x+10, height() - 1);
88
void Spacer::resizeEvent(QResizeEvent* e)
90
QWidget::resizeEvent(e);
96
if (!parentWidget() || (m_formWindow && LayoutInfo::layoutType(m_formWindow->core(), parentWidget()) == LayoutInfo::NoLayout))
100
void Spacer::updateMask()
103
if (orient == Qt::Horizontal) {
104
const int amplitude = qMin(3, height() / 3);
105
const int base = height() / 2;
106
r = r.subtract(QRect(1, 0, width() - 2, base - amplitude));
107
r = r.subtract(QRect(1, base + amplitude, width() - 2, height() - base - amplitude));
109
const int amplitude = qMin(3, width() / 3);
110
const int base = width() / 2;
111
r = r.subtract(QRect(0, 1, base - amplitude, height() - 2));
112
r = r.subtract(QRect(base + amplitude, 1, width() - base - amplitude, height() - 2));
117
void Spacer::setSizeType(QSizePolicy::Policy t)
120
if (orient == Qt::Vertical)
121
sizeP = QSizePolicy(QSizePolicy::Minimum, t);
123
sizeP = QSizePolicy(t, QSizePolicy::Minimum);
124
setSizePolicy(sizeP);
128
QSizePolicy::Policy Spacer::sizeType() const
130
if (orient == Qt::Vertical)
131
return sizePolicy().verticalPolicy();
132
return sizePolicy().horizontalPolicy();
135
Qt::Alignment Spacer::alignment() const
137
if (orient == Qt::Vertical)
138
return Qt::AlignHCenter;
139
return Qt::AlignVCenter;
142
QSize Spacer::minimumSize() const
144
QSize s = QSize(20,20);
145
if (sizeType() == QSizePolicy::Expanding)
146
if (orient == Qt::Vertical)
153
QSize Spacer::sizeHint() const
158
void Spacer::setSizeHint(const QSize &s)
162
if (!parentWidget() || (m_formWindow && LayoutInfo::layoutType(m_formWindow->core(), parentWidget()) == LayoutInfo::NoLayout))
168
Qt::Orientation Spacer::orientation() const
173
void Spacer::setOrientation(Qt::Orientation o)
178
QSizePolicy::Policy st = sizeType();
183
sh = QSize(sh.height(), sh.width());
184
if (!parentWidget() || (m_formWindow && LayoutInfo::layoutType(m_formWindow->core(), parentWidget()) == LayoutInfo::NoLayout))
185
resize(height(), width());