summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@nokia.com>2010-06-29 12:56:08 +0200
committerTobias Hunger <tobias.hunger@nokia.com>2010-06-29 12:58:43 +0200
commitedfe3fec1c96962106d20a1792567472219af129 (patch)
treed6c9160b6c6835bdccd0d39bbe3c8a653acef373
parentd8ad6aa275ce4ab7e0827aa342d75c6a2f5c3f5c (diff)
downloadqt-creator-edfe3fec1c96962106d20a1792567472219af129.tar.gz
Use popup menu when selecting new targets
Use a popup menu when adding new targets in projects mode. Task-number: QTCREATORBUG-1763
-rw-r--r--src/plugins/projectexplorer/addtargetdialog.cpp78
-rw-r--r--src/plugins/projectexplorer/addtargetdialog.h64
-rw-r--r--src/plugins/projectexplorer/addtargetdialog.ui77
-rw-r--r--src/plugins/projectexplorer/projectexplorer.pro5
-rw-r--r--src/plugins/projectexplorer/targetselector.cpp13
-rw-r--r--src/plugins/projectexplorer/targetselector.h8
-rw-r--r--src/plugins/projectexplorer/targetsettingspanel.cpp38
-rw-r--r--src/plugins/projectexplorer/targetsettingspanel.h8
-rw-r--r--src/plugins/projectexplorer/targetsettingswidget.cpp7
-rw-r--r--src/plugins/projectexplorer/targetsettingswidget.h6
10 files changed, 66 insertions, 238 deletions
diff --git a/src/plugins/projectexplorer/addtargetdialog.cpp b/src/plugins/projectexplorer/addtargetdialog.cpp
deleted file mode 100644
index 00e85ff4fd..0000000000
--- a/src/plugins/projectexplorer/addtargetdialog.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/**************************************************************************
-**
-** This file is part of Qt Creator
-**
-** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
-**
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** Commercial Usage
-**
-** Licensees holding valid Qt Commercial licenses may use this file in
-** accordance with the Qt Commercial License Agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Nokia.
-**
-** GNU Lesser General Public License Usage
-**
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
-**
-**************************************************************************/
-
-#include "addtargetdialog.h"
-
-#include "ui_addtargetdialog.h"
-
-#include "project.h"
-
-using namespace ProjectExplorer;
-using namespace ProjectExplorer::Internal;
-
-AddTargetDialog::AddTargetDialog(Project *project, QWidget *parent) :
- QDialog(parent),
- m_project(project),
- ui(new Ui::AddTargetDialog)
-{
- ui->setupUi(this);
-
- foreach (const QString &id, m_project->possibleTargetIds()) {
- for (int i = 0; i <= ui->targetComboBox->count(); ++i) {
- const QString displayName = m_project->targetFactory()->displayNameForId(id);
- if (i == ui->targetComboBox->count() ||
- ui->targetComboBox->itemText(i) > displayName) {
- ui->targetComboBox->insertItem(i, displayName, id);
- break;
- }
- }
- }
- ui->targetComboBox->setCurrentIndex(0);
-
- connect(ui->buttonBox, SIGNAL(accepted()),
- this, SLOT(accept()));
-}
-
-AddTargetDialog::~AddTargetDialog()
-{
- delete ui;
-}
-
-void AddTargetDialog::accept()
-{
- int index = ui->targetComboBox->currentIndex();
- QString id(ui->targetComboBox->itemData(index).toString());
- Target *target(m_project->targetFactory()->create(m_project, id));
- if (!target)
- return;
- m_project->addTarget(target);
-
- done(QDialog::Accepted);
-}
-
diff --git a/src/plugins/projectexplorer/addtargetdialog.h b/src/plugins/projectexplorer/addtargetdialog.h
deleted file mode 100644
index fd8f2d4d5d..0000000000
--- a/src/plugins/projectexplorer/addtargetdialog.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/**************************************************************************
-**
-** This file is part of Qt Creator
-**
-** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
-**
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** Commercial Usage
-**
-** Licensees holding valid Qt Commercial licenses may use this file in
-** accordance with the Qt Commercial License Agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Nokia.
-**
-** GNU Lesser General Public License Usage
-**
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
-**
-**************************************************************************/
-
-#ifndef ADDTARGETDIALOG_H
-#define ADDTARGETDIALOG_H
-
-#include <QDialog>
-
-namespace ProjectExplorer {
-
-class Project;
-
-namespace Internal {
-
-namespace Ui {
-class AddTargetDialog;
-}
-
-class AddTargetDialog : public QDialog
-{
- Q_OBJECT
-
-public:
- explicit AddTargetDialog(Project *project, QWidget *parent = 0);
- ~AddTargetDialog();
-
-private slots:
- void accept();
-
-private:
- Project *m_project;
- Ui::AddTargetDialog *ui;
-};
-
-} // namespace Internal
-} // namespace ProjectExplorer
-
-#endif // ADDTARGETDIALOG_H
diff --git a/src/plugins/projectexplorer/addtargetdialog.ui b/src/plugins/projectexplorer/addtargetdialog.ui
deleted file mode 100644
index 58f230ac92..0000000000
--- a/src/plugins/projectexplorer/addtargetdialog.ui
+++ /dev/null
@@ -1,77 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>ProjectExplorer::Internal::AddTargetDialog</class>
- <widget class="QDialog" name="ProjectExplorer::Internal::AddTargetDialog">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>343</width>
- <height>67</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Add target</string>
- </property>
- <layout class="QFormLayout" name="formLayout">
- <property name="fieldGrowthPolicy">
- <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
- </property>
- <item row="0" column="0">
- <widget class="QLabel" name="label">
- <property name="text">
- <string>Target:</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QComboBox" name="targetComboBox"/>
- </item>
- <item row="1" column="0" colspan="2">
- <widget class="QDialogButtonBox" name="buttonBox">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="standardButtons">
- <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections>
- <connection>
- <sender>buttonBox</sender>
- <signal>accepted()</signal>
- <receiver>ProjectExplorer::Internal::AddTargetDialog</receiver>
- <slot>accept()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>248</x>
- <y>254</y>
- </hint>
- <hint type="destinationlabel">
- <x>157</x>
- <y>274</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>buttonBox</sender>
- <signal>rejected()</signal>
- <receiver>ProjectExplorer::Internal::AddTargetDialog</receiver>
- <slot>reject()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>316</x>
- <y>260</y>
- </hint>
- <hint type="destinationlabel">
- <x>286</x>
- <y>274</y>
- </hint>
- </hints>
- </connection>
- </connections>
-</ui>
diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro
index 7d5f198a9e..96e0b66b7e 100644
--- a/src/plugins/projectexplorer/projectexplorer.pro
+++ b/src/plugins/projectexplorer/projectexplorer.pro
@@ -80,7 +80,6 @@ HEADERS += projectexplorer.h \
targetselector.h \
targetsettingswidget.h \
doubletabwidget.h \
- addtargetdialog.h \
buildenvironmentwidget.h \
buildconfigdialog.h \
ldparser.h \
@@ -154,7 +153,6 @@ SOURCES += projectexplorer.cpp \
targetselector.cpp \
targetsettingswidget.cpp \
doubletabwidget.cpp \
- addtargetdialog.cpp \
buildenvironmentwidget.cpp \
buildconfigdialog.cpp \
ldparser.cpp \
@@ -171,8 +169,7 @@ FORMS += processstep.ui \
projectexplorersettingspage.ui \
projectwelcomepagewidget.ui \
targetsettingswidget.ui \
- doubletabwidget.ui \
- addtargetdialog.ui
+ doubletabwidget.ui
equals(TEST, 1) {
SOURCES += \
diff --git a/src/plugins/projectexplorer/targetselector.cpp b/src/plugins/projectexplorer/targetselector.cpp
index dd920ec46e..c17433feba 100644
--- a/src/plugins/projectexplorer/targetselector.cpp
+++ b/src/plugins/projectexplorer/targetselector.cpp
@@ -4,6 +4,7 @@
#include <utils/stylehelper.h>
#include <QtGui/QPainter>
+#include <QtGui/QMenu>
#include <QtGui/QMouseEvent>
#include <QtGui/QFontMetrics>
@@ -23,7 +24,8 @@ TargetSelector::TargetSelector(QWidget *parent) :
m_targetremovebuttondisabled(QLatin1String(":/projectexplorer/images/targetremovebutton_disabled.png")),
m_currentTargetIndex(-1),
m_addButtonEnabled(true),
- m_removeButtonEnabled(false)
+ m_removeButtonEnabled(false),
+ m_addButtonMenu(0)
{
QFont f = font();
f.setPixelSize(10);
@@ -94,6 +96,11 @@ void TargetSelector::setRemoveButtonEnabled(bool enabled)
m_removeButtonEnabled = enabled;
}
+void TargetSelector::setAddButtonMenu(QMenu *menu)
+{
+ m_addButtonMenu = menu;
+}
+
void TargetSelector::setCurrentSubIndex(int subindex)
{
if (subindex < 0 ||
@@ -148,8 +155,8 @@ void TargetSelector::mousePressEvent(QMouseEvent *event)
} else if (event->x() > ADDBUTTON_WIDTH + (targetWidth() + 1) * m_targets.size()) {
// check for add button
event->accept();
- if (m_addButtonEnabled)
- emit addButtonClicked();
+ if (m_addButtonEnabled && m_addButtonMenu)
+ m_addButtonMenu->popup(mapToGlobal(event->pos()));
} else {
// find the clicked target button
int x = ADDBUTTON_WIDTH;
diff --git a/src/plugins/projectexplorer/targetselector.h b/src/plugins/projectexplorer/targetselector.h
index b6c2037e4e..322e508580 100644
--- a/src/plugins/projectexplorer/targetselector.h
+++ b/src/plugins/projectexplorer/targetselector.h
@@ -4,6 +4,10 @@
#include <QtGui/QWidget>
#include <QtGui/QPixmap>
+QT_BEGIN_NAMESPACE
+class QMenu;
+QT_END_NAMESPACE
+
namespace ProjectExplorer {
namespace Internal {
@@ -40,9 +44,9 @@ public slots:
void setCurrentSubIndex(int subindex);
void setAddButtonEnabled(bool enabled);
void setRemoveButtonEnabled(bool enabled);
+ void setAddButtonMenu(QMenu *menu);
signals:
- void addButtonClicked();
void removeButtonClicked();
// This signal is emited whenever the target pointed to by the indices
// has changed.
@@ -66,6 +70,8 @@ private:
int m_currentTargetIndex;
bool m_addButtonEnabled;
bool m_removeButtonEnabled;
+
+ QMenu *m_addButtonMenu;
};
} // namespace Internal
diff --git a/src/plugins/projectexplorer/targetsettingspanel.cpp b/src/plugins/projectexplorer/targetsettingspanel.cpp
index 7bcd1b5db2..69a77ae983 100644
--- a/src/plugins/projectexplorer/targetsettingspanel.cpp
+++ b/src/plugins/projectexplorer/targetsettingspanel.cpp
@@ -29,7 +29,6 @@
#include "targetsettingspanel.h"
-#include "addtargetdialog.h"
#include "buildsettingspropertiespage.h"
#include "project.h"
#include "projectwindow.h"
@@ -41,6 +40,7 @@
#include <QtCore/QCoreApplication>
#include <QtGui/QLabel>
+#include <QtGui/QMenu>
#include <QtGui/QMessageBox>
#include <QtGui/QVBoxLayout>
@@ -63,6 +63,8 @@ TargetSettingsPanelWidget::TargetSettingsPanelWidget(Project *project) :
m_panelWidgets[0] = 0;
m_panelWidgets[1] = 0;
+ m_addMenu = new QMenu(this);
+
setupUi();
connect(m_project, SIGNAL(addedTarget(ProjectExplorer::Target*)),
@@ -124,11 +126,13 @@ void TargetSettingsPanelWidget::setupUi()
connect(m_selector, SIGNAL(currentChanged(int,int)),
this, SLOT(currentTargetChanged(int,int)));
- connect(m_selector, SIGNAL(addButtonClicked()),
- this, SLOT(addTarget()));
connect(m_selector, SIGNAL(removeButtonClicked()),
this, SLOT(removeTarget()));
+ m_selector->setAddButtonMenu(m_addMenu);
+ connect(m_addMenu, SIGNAL(triggered(QAction*)),
+ this, SLOT(addTarget(QAction*)));
+
updateTargetAddAndRemoveButtons();
}
@@ -192,10 +196,13 @@ void TargetSettingsPanelWidget::currentTargetChanged(int targetIndex, int subInd
m_project->setActiveTarget(target);
}
-void TargetSettingsPanelWidget::addTarget()
+void TargetSettingsPanelWidget::addTarget(QAction *action)
{
- AddTargetDialog dialog(m_project);
- dialog.exec();
+ QString id = action->data().toString();
+ Target *target(m_project->targetFactory()->create(m_project, id));
+ if (!target)
+ return;
+ m_project->addTarget(target);
}
void TargetSettingsPanelWidget::removeTarget()
@@ -257,6 +264,23 @@ void TargetSettingsPanelWidget::updateTargetAddAndRemoveButtons()
if (!m_selector)
return;
- m_selector->setAddButtonEnabled(m_project->possibleTargetIds().count() > 0);
+ m_addMenu->clear();
+
+ foreach (const QString &id, m_project->possibleTargetIds()) {
+ QString displayName = m_project->targetFactory()->displayNameForId(id);
+ QAction *action = new QAction(displayName, m_addMenu);
+ action->setData(QVariant(id));
+ bool added = false;
+ foreach(QAction *existing, m_addMenu->actions()) {
+ if (existing->text() > action->text()) {
+ m_addMenu->insertAction(existing, action);
+ added = true;
+ }
+ }
+
+ if (!added)
+ m_addMenu->addAction(action);
+ }
+ m_selector->setAddButtonEnabled(!m_addMenu->actions().isEmpty());
m_selector->setRemoveButtonEnabled(m_project->targets().count() > 1);
}
diff --git a/src/plugins/projectexplorer/targetsettingspanel.h b/src/plugins/projectexplorer/targetsettingspanel.h
index fa510c69a6..6d449ec1c7 100644
--- a/src/plugins/projectexplorer/targetsettingspanel.h
+++ b/src/plugins/projectexplorer/targetsettingspanel.h
@@ -35,6 +35,11 @@
#include <QtGui/QStackedWidget>
#include <QtGui/QWidget>
+QT_BEGIN_NAMESPACE
+class QAction;
+class QMenu;
+QT_END_NAMESPACE
+
namespace ProjectExplorer {
class Target;
@@ -55,8 +60,8 @@ public:
private slots:
void currentTargetChanged(int targetIndex, int subIndex);
- void addTarget();
void removeTarget();
+ void addTarget(QAction *);
void targetAdded(ProjectExplorer::Target *target);
void removedTarget(ProjectExplorer::Target *target);
void activeTargetChanged(ProjectExplorer::Target *target);
@@ -70,6 +75,7 @@ private:
QWidget *m_noTargetLabel;
PanelsWidget *m_panelWidgets[2];
QList<Target *> m_targets;
+ QMenu *m_addMenu;
};
} // namespace Internal
diff --git a/src/plugins/projectexplorer/targetsettingswidget.cpp b/src/plugins/projectexplorer/targetsettingswidget.cpp
index c5a101664d..36be122706 100644
--- a/src/plugins/projectexplorer/targetsettingswidget.cpp
+++ b/src/plugins/projectexplorer/targetsettingswidget.cpp
@@ -15,8 +15,6 @@ TargetSettingsWidget::TargetSettingsWidget(QWidget *parent) :
"background-image: url(:/projectexplorer/images/targetseparatorbackground.png);"
"}"));
m_targetSelector->raise();
- connect(m_targetSelector, SIGNAL(addButtonClicked()),
- this, SIGNAL(addButtonClicked()));
connect(m_targetSelector, SIGNAL(removeButtonClicked()),
this, SIGNAL(removeButtonClicked()));
connect(m_targetSelector, SIGNAL(currentChanged(int,int)),
@@ -75,6 +73,11 @@ void TargetSettingsWidget::setAddButtonEnabled(bool enabled)
m_targetSelector->setAddButtonEnabled(enabled);
}
+void TargetSettingsWidget::setAddButtonMenu(QMenu *menu)
+{
+ m_targetSelector->setAddButtonMenu(menu);
+}
+
void TargetSettingsWidget::setRemoveButtonEnabled(bool enabled)
{
m_targetSelector->setRemoveButtonEnabled(enabled);
diff --git a/src/plugins/projectexplorer/targetsettingswidget.h b/src/plugins/projectexplorer/targetsettingswidget.h
index b2c987fbbb..35a2c6faf1 100644
--- a/src/plugins/projectexplorer/targetsettingswidget.h
+++ b/src/plugins/projectexplorer/targetsettingswidget.h
@@ -5,6 +5,10 @@
#include <QWidget>
+QT_BEGIN_NAMESPACE
+class QMenu;
+QT_END_NAMESPACE
+
namespace ProjectExplorer {
namespace Internal {
@@ -36,10 +40,10 @@ public slots:
void setCurrentIndex(int index);
void setCurrentSubIndex(int index);
void setAddButtonEnabled(bool enabled);
+ void setAddButtonMenu(QMenu *menu);
void setRemoveButtonEnabled(bool enabled);
signals:
- void addButtonClicked();
void removeButtonClicked();
void currentChanged(int targetIndex, int subIndex);