source: trunk/tools/designer/src/components/taskmenu/combobox_taskmenu.cpp@ 651

Last change on this file since 651 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 4.3 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 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 "combobox_taskmenu.h"
43#include "listwidgeteditor.h"
44#include "qdesigner_utils_p.h"
45#include <qdesigner_command_p.h>
46
47#include <QtDesigner/QDesignerFormWindowInterface>
48
49#include <QtGui/QAction>
50#include <QtGui/QStyle>
51#include <QtGui/QLineEdit>
52#include <QtGui/QFontComboBox>
53#include <QtGui/QStyleOption>
54
55#include <QtCore/QEvent>
56#include <QtCore/QVariant>
57#include <QtCore/qdebug.h>
58
59QT_BEGIN_NAMESPACE
60
61using namespace qdesigner_internal;
62
63ComboBoxTaskMenu::ComboBoxTaskMenu(QComboBox *button, QObject *parent)
64 : QDesignerTaskMenu(button, parent),
65 m_comboBox(button)
66{
67 m_editItemsAction = new QAction(this);
68 m_editItemsAction->setText(tr("Edit Items..."));
69 connect(m_editItemsAction, SIGNAL(triggered()), this, SLOT(editItems()));
70 m_taskActions.append(m_editItemsAction);
71
72 QAction *sep = new QAction(this);
73 sep->setSeparator(true);
74 m_taskActions.append(sep);
75}
76
77ComboBoxTaskMenu::~ComboBoxTaskMenu()
78{
79}
80
81QAction *ComboBoxTaskMenu::preferredEditAction() const
82{
83 return m_editItemsAction;
84}
85
86QList<QAction*> ComboBoxTaskMenu::taskActions() const
87{
88 return m_taskActions + QDesignerTaskMenu::taskActions();
89}
90
91void ComboBoxTaskMenu::editItems()
92{
93 m_formWindow = QDesignerFormWindowInterface::findFormWindow(m_comboBox);
94 if (m_formWindow.isNull())
95 return;
96
97 Q_ASSERT(m_comboBox != 0);
98
99 ListWidgetEditor dlg(m_formWindow, m_comboBox->window());
100 ListContents oldItems = dlg.fillContentsFromComboBox(m_comboBox);
101 if (dlg.exec() == QDialog::Accepted) {
102 ListContents items = dlg.contents();
103 if (items != oldItems) {
104 ChangeListContentsCommand *cmd = new ChangeListContentsCommand(m_formWindow);
105 cmd->init(m_comboBox, oldItems, items);
106 cmd->setText(tr("Change Combobox Contents"));
107 m_formWindow->commandHistory()->push(cmd);
108 }
109 }
110}
111
112ComboBoxTaskMenuFactory::ComboBoxTaskMenuFactory(const QString &iid, QExtensionManager *extensionManager) :
113 ExtensionFactory<QDesignerTaskMenuExtension, QComboBox, ComboBoxTaskMenu>(iid, extensionManager)
114{
115}
116
117QComboBox *ComboBoxTaskMenuFactory::checkObject(QObject *qObject) const
118{
119 QComboBox *combo = qobject_cast<QComboBox*>(qObject);
120 if (!combo)
121 return 0;
122 if (qobject_cast<QFontComboBox*>(combo))
123 return 0;
124 return combo;
125}
126
127void ComboBoxTaskMenu::updateSelection()
128{
129 if (m_editor)
130 m_editor->deleteLater();
131}
132
133QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.