source: trunk/tools/designer/src/components/widgetbox/widgetbox.cpp

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 6.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the Qt Designer of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "widgetbox.h"
43#include "widgetboxtreewidget.h"
44#include "widgetbox_dnditem.h"
45
46#include <QtDesigner/QDesignerFormEditorInterface>
47#include <QtDesigner/QDesignerFormWindowManagerInterface>
48
49#include <iconloader_p.h>
50#include <qdesigner_utils_p.h>
51#include <filterwidget_p.h>
52
53#include <QtGui/QDropEvent>
54#include <QtGui/QVBoxLayout>
55#include <QtGui/QApplication>
56#include <QtGui/QToolBar>
57#include <QtGui/QIcon>
58
59QT_BEGIN_NAMESPACE
60
61namespace qdesigner_internal {
62
63WidgetBox::WidgetBox(QDesignerFormEditorInterface *core, QWidget *parent, Qt::WindowFlags flags)
64 : QDesignerWidgetBox(parent, flags),
65 m_core(core),
66 m_view(new WidgetBoxTreeWidget(m_core))
67{
68
69 QVBoxLayout *l = new QVBoxLayout(this);
70 l->setMargin(0);
71 l->setSpacing(0);
72
73 // Prevent the filter from grabbing focus since Our view has Qt::NoFocus
74 FilterWidget *filterWidget = new FilterWidget(0, FilterWidget::LayoutAlignNone);
75 filterWidget->setRefuseFocus(true);
76 connect(filterWidget, SIGNAL(filterChanged(QString)), m_view, SLOT(filter(QString)));
77
78 QToolBar *toolBar = new QToolBar(this);
79 toolBar->addWidget(filterWidget);
80 l->addWidget(toolBar);
81
82 // View
83 connect(m_view, SIGNAL(pressed(QString,QString,QPoint)),
84 this, SLOT(handleMousePress(QString,QString,QPoint)));
85 l->addWidget(m_view);
86
87 setAcceptDrops (true);
88}
89
90WidgetBox::~WidgetBox()
91{
92}
93
94QDesignerFormEditorInterface *WidgetBox::core() const
95{
96 return m_core;
97}
98
99void WidgetBox::handleMousePress(const QString &name, const QString &xml, const QPoint &global_mouse_pos)
100{
101 if (QApplication::mouseButtons() != Qt::LeftButton)
102 return;
103
104 DomUI *ui = xmlToUi(name, xml, true);
105 if (ui == 0)
106 return;
107 QList<QDesignerDnDItemInterface*> item_list;
108 item_list.append(new WidgetBoxDnDItem(core(), ui, global_mouse_pos));
109 m_core->formWindowManager()->dragItems(item_list);
110}
111
112int WidgetBox::categoryCount() const
113{
114 return m_view->categoryCount();
115}
116
117QDesignerWidgetBoxInterface::Category WidgetBox::category(int cat_idx) const
118{
119 return m_view->category(cat_idx);
120}
121
122void WidgetBox::addCategory(const Category &cat)
123{
124 m_view->addCategory(cat);
125}
126