diff --git a/src/plugins/qt4projectmanager/wizards/targetsetuppage.cpp b/src/plugins/qt4projectmanager/wizards/targetsetuppage.cpp index 4e1dd07a373315b5284ddb31c58b2c24e0108707..66cfce6d61399dd3a4a5abd443b4effef015dca4 100644 --- a/src/plugins/qt4projectmanager/wizards/targetsetuppage.cpp +++ b/src/plugins/qt4projectmanager/wizards/targetsetuppage.cpp @@ -41,10 +41,12 @@ #include <projectexplorer/taskhub.h> #include <utils/qtcassert.h> +#include <QtGui/QAction> #include <QtGui/QFileDialog> #include <QtGui/QHeaderView> #include <QtGui/QLabel> #include <QtGui/QLayout> +#include <QtGui/QMenu> #include <QtGui/QMessageBox> #include <QtGui/QPushButton> #include <QtGui/QTreeWidget> @@ -63,18 +65,24 @@ TargetSetupPage::TargetSetupPage(QWidget *parent) : QWizardPage(parent), m_preferMobile(false), m_toggleWillCheck(false), - m_ui(new Ui::TargetSetupPage) + m_ui(new Ui::TargetSetupPage), + m_contextMenu(0) { m_ui->setupUi(this); m_ui->versionTree->header()->setResizeMode(0, QHeaderView::ResizeToContents); m_ui->versionTree->header()->setResizeMode(1, QHeaderView::ResizeToContents); + m_ui->versionTree->setContextMenuPolicy(Qt::CustomContextMenu); + m_contextMenu = new QMenu(this); + connect(m_ui->importButton, SIGNAL(clicked()), this, SLOT(addShadowBuildLocation())); connect(m_ui->uncheckButton, SIGNAL(clicked()), - this, SLOT(toggleAll())); + this, SLOT(checkAllButtonClicked())); connect(m_ui->versionTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(handleDoubleClicks(QTreeWidgetItem*,int))); + connect(m_ui->versionTree, SIGNAL(customContextMenuRequested(QPoint)), + this, SLOT(contextMenuRequested(QPoint))); } TargetSetupPage::~TargetSetupPage() @@ -443,21 +451,56 @@ void TargetSetupPage::addShadowBuildLocation() setImportInfos(tmp); } -void TargetSetupPage::toggleAll() +void TargetSetupPage::checkAll(bool checked) { for (int i = 0; i < m_ui->versionTree->topLevelItemCount(); ++i) { QTreeWidgetItem *current = m_ui->versionTree->topLevelItem(i); - for (int j = 0; j < current->childCount(); ++j) { - QTreeWidgetItem *child = current->child(j); - child->setCheckState(0, m_toggleWillCheck ? Qt::Checked : Qt::Unchecked); - } + for (int j = 0; j < current->childCount(); ++j) + checkOne(checked, current->child(j)); } +} + +void TargetSetupPage::checkOne(bool checked, QTreeWidgetItem *item) +{ + Q_ASSERT(item->parent()); // we are a version item + item->setCheckState(0, checked ? Qt::Checked : Qt::Unchecked); +} + +void TargetSetupPage::checkAllButtonClicked() +{ + checkAll(m_toggleWillCheck); + m_toggleWillCheck = !m_toggleWillCheck; m_ui->uncheckButton->setText(m_toggleWillCheck ? tr("Check all") : tr("Uncheck all")); m_ui->uncheckButton->setToolTip(m_toggleWillCheck ? tr("Check all Qt versions") : tr("Uncheck all Qt versions")); } +void TargetSetupPage::checkAllTriggered() +{ + m_toggleWillCheck = true; + checkAllButtonClicked(); +} + +void TargetSetupPage::uncheckAllTriggered() +{ + m_toggleWillCheck = false; + checkAllButtonClicked(); +} + +void TargetSetupPage::checkOneTriggered() +{ + QAction * action = qobject_cast<QAction *>(sender()); + if (!action) + return; + QTreeWidgetItem *item = static_cast<QTreeWidgetItem *>(action->data().value<void *>()); + if (!item || !item->parent()) + return; + + checkAll(false); + checkOne(true, item); +} + void TargetSetupPage::handleDoubleClicks(QTreeWidgetItem *item, int column) { int idx = item->data(NAME_COLUMN, Qt::UserRole).toInt(); @@ -469,6 +512,31 @@ void TargetSetupPage::handleDoubleClicks(QTreeWidgetItem *item, int column) } } +void TargetSetupPage::contextMenuRequested(const QPoint & position) +{ + m_contextMenu->clear(); + + QTreeWidgetItem *item = m_ui->versionTree->itemAt(position); + m_contextMenu = new QMenu(this); + if (item->parent()) { + // Qt version item + QAction *onlyThisAction = new QAction(tr("Check only this version"), m_contextMenu); + connect(onlyThisAction, SIGNAL(triggered()), this, SLOT(checkOneTriggered())); + onlyThisAction->setData(QVariant::fromValue(static_cast<void *>(item))); + m_contextMenu->addAction(onlyThisAction); + + QAction *checkAllAction = new QAction(tr("Check all versions"), m_contextMenu); + connect(checkAllAction, SIGNAL(triggered()), this, SLOT(checkAllTriggered())); + m_contextMenu->addAction(checkAllAction); + + QAction *uncheckAllAction = new QAction(tr("Uncheck all versions"), m_contextMenu); + connect(uncheckAllAction, SIGNAL(triggered()), this, SLOT(uncheckAllTriggered())); + m_contextMenu->addAction(uncheckAllAction); + } + if (!m_contextMenu->isEmpty()) + m_contextMenu->popup(m_ui->versionTree->mapToGlobal(position)); +} + void TargetSetupPage::resetInfos() { m_ui->versionTree->clear(); diff --git a/src/plugins/qt4projectmanager/wizards/targetsetuppage.h b/src/plugins/qt4projectmanager/wizards/targetsetuppage.h index 8de65cc4255f664f5daf0b6e81ca1332692558c6..822c3a8a12ddca31c1e34b011099201210eaa3de 100644 --- a/src/plugins/qt4projectmanager/wizards/targetsetuppage.h +++ b/src/plugins/qt4projectmanager/wizards/targetsetuppage.h @@ -42,6 +42,7 @@ QT_BEGIN_NAMESPACE class QLabel; +class QMenu; class QPushButton; class QTreeWidget; class QTreeWidgetItem; @@ -118,12 +119,18 @@ public: public slots: void setProFilePath(const QString &dir); + void checkAll(bool checked); + void checkOne(bool, QTreeWidgetItem *); private slots: void itemWasChanged(); + void checkAllButtonClicked(); + void checkAllTriggered(); + void uncheckAllTriggered(); + void checkOneTriggered(); void addShadowBuildLocation(); - void toggleAll(); void handleDoubleClicks(QTreeWidgetItem *, int); + void contextMenuRequested(const QPoint & pos); private: void resetInfos(); @@ -137,6 +144,8 @@ private: QString m_defaultShadowBuildLocation; Ui::TargetSetupPage *m_ui; + + QMenu *m_contextMenu; }; } // namespace Internal