miniprojecttargetselector.cpp 47.2 KB
Newer Older
Tobias Hunger's avatar
Tobias Hunger committed
1 2 3 4
/**************************************************************************
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
Tobias Hunger's avatar
Tobias Hunger committed
6
**
Eike Ziller's avatar
Eike Ziller committed
7
** Contact: http://www.qt-project.org/
Tobias Hunger's avatar
Tobias Hunger committed
8 9 10 11
**
**
** GNU Lesser General Public License Usage
**
hjk's avatar
hjk committed
12 13 14 15 16 17
** 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.
Tobias Hunger's avatar
Tobias Hunger committed
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21 22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23 24 25 26 27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
Tobias Hunger's avatar
Tobias Hunger committed
28 29 30
**
**************************************************************************/

31
#include "miniprojecttargetselector.h"
32
#include "target.h"
33 34 35 36 37

#include <utils/qtcassert.h>
#include <utils/styledbar.h>
#include <utils/stylehelper.h>

38
#include <coreplugin/idocument.h>
39
#include <coreplugin/icore.h>
con's avatar
con committed
40
#include <coreplugin/coreconstants.h>
41
#include <coreplugin/modemanager.h>
42 43 44 45 46

#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <projectexplorer/project.h>
#include <projectexplorer/buildconfiguration.h>
Daniel Teske's avatar
Daniel Teske committed
47
#include <projectexplorer/deployconfiguration.h>
Tobias Hunger's avatar
Tobias Hunger committed
48
#include <projectexplorer/kitmanager.h>
49
#include <projectexplorer/projectmodels.h>
Daniel Teske's avatar
Daniel Teske committed
50
#include <projectexplorer/runconfiguration.h>
51

52 53 54 55 56 57 58 59 60 61
#include <QTimer>
#include <QLayout>
#include <QLabel>
#include <QListWidget>
#include <QStatusBar>
#include <QKeyEvent>
#include <QPainter>
#include <QAction>
#include <QItemDelegate>
#include <QApplication>
62

63 64 65 66 67 68 69
static QIcon createCenteredIcon(const QIcon &icon, const QIcon &overlay)
{
    QPixmap targetPixmap;
    targetPixmap = QPixmap(Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE);
    targetPixmap.fill(Qt::transparent);
    QPainter painter(&targetPixmap);

70 71 72
    QPixmap pixmap = icon.pixmap(Core::Constants::TARGET_ICON_SIZE);
    painter.drawPixmap((Core::Constants::TARGET_ICON_SIZE - pixmap.width())/2,
                       (Core::Constants::TARGET_ICON_SIZE - pixmap.height())/2, pixmap);
73
    if (!overlay.isNull()) {
74 75 76
        pixmap = overlay.pixmap(Core::Constants::TARGET_ICON_SIZE);
        painter.drawPixmap((Core::Constants::TARGET_ICON_SIZE - pixmap.width())/2,
                           (Core::Constants::TARGET_ICON_SIZE - pixmap.height())/2, pixmap);
77 78 79 80
    }
    return QIcon(targetPixmap);
}

81 82 83
using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;

84 85 86 87 88 89 90 91 92
static bool projectLesserThan(Project *p1, Project *p2)
{
    int result = caseFriendlyCompare(p1->displayName(), p2->displayName());
    if (result != 0)
        return result < 0;
    else
        return p1 < p2;
}

Daniel Teske's avatar
Daniel Teske committed
93 94 95
////////
// TargetSelectorDelegate
////////
96 97 98 99 100
class TargetSelectorDelegate : public QItemDelegate
{
public:
    TargetSelectorDelegate(QObject *parent) : QItemDelegate(parent) { }
private:
Daniel Teske's avatar
Daniel Teske committed
101
    QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
102 103 104 105 106 107
    void paint(QPainter *painter,
               const QStyleOptionViewItem &option,
               const QModelIndex &index) const;
    mutable QImage selectionGradient;
};

Daniel Teske's avatar
Daniel Teske committed
108 109 110 111 112 113 114
QSize TargetSelectorDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    Q_UNUSED(option)
    Q_UNUSED(index)
    return QSize(190, 30);
}

115 116
void TargetSelectorDelegate::paint(QPainter *painter,
                                   const QStyleOptionViewItem &option,
Daniel Teske's avatar
Daniel Teske committed
117
                                   const QModelIndex &index) const
118 119 120 121 122 123 124 125
{
    painter->save();
    painter->setClipping(false);

    if (selectionGradient.isNull())
        selectionGradient.load(QLatin1String(":/projectexplorer/images/targetpanel_gradient.png"));

    if (option.state & QStyle::State_Selected) {
126 127 128 129
        QColor color =(option.state & QStyle::State_HasFocus) ?
                      option.palette.highlight().color() :
                      option.palette.dark().color();
        painter->fillRect(option.rect, color.darker(140));
130 131 132 133 134 135 136 137
        Utils::StyleHelper::drawCornerImage(selectionGradient, painter, option.rect.adjusted(0, 0, 0, -1), 5, 5, 5, 5);
        painter->setPen(QColor(255, 255, 255, 60));
        painter->drawLine(option.rect.topLeft(), option.rect.topRight());
        painter->setPen(QColor(255, 255, 255, 30));
        painter->drawLine(option.rect.bottomLeft() - QPoint(0,1), option.rect.bottomRight() -  QPoint(0,1));
        painter->setPen(QColor(0, 0, 0, 80));
        painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
    }
Daniel Teske's avatar
Daniel Teske committed
138 139 140 141 142 143 144 145

    QFontMetrics fm(option.font);
    QString text = index.data(Qt::DisplayRole).toString();
    painter->setPen(QColor(255, 255, 255, 160));
    QString elidedText = fm.elidedText(text, Qt::ElideMiddle, option.rect.width() - 12);
    if (elidedText != text)
        const_cast<QAbstractItemModel *>(index.model())->setData(index, text, Qt::ToolTipRole);
    else
146
        const_cast<QAbstractItemModel *>(index.model())->setData(index, QString(), Qt::ToolTipRole);
Daniel Teske's avatar
Daniel Teske committed
147 148
    painter->drawText(option.rect.left() + 6, option.rect.top() + (option.rect.height() - fm.height()) / 2 + fm.ascent(), elidedText);

149 150 151
    painter->restore();
}

Daniel Teske's avatar
Daniel Teske committed
152 153 154 155 156
////////
// ListWidget
////////
ListWidget::ListWidget(QWidget *parent)
    : QListWidget(parent), m_maxCount(0)
Tobias Hunger's avatar
Tobias Hunger committed
157 158 159 160 161
{
    setFocusPolicy(Qt::NoFocus);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setAlternatingRowColors(false);
    setFocusPolicy(Qt::WheelFocus);
162
    setItemDelegate(new TargetSelectorDelegate(this));
163
    setAttribute(Qt::WA_MacShowFocusRect, false);
Daniel Teske's avatar
Daniel Teske committed
164 165
    setStyleSheet(QString::fromLatin1("QListWidget { background: #464646; border-style: none; }"));
    setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
Tobias Hunger's avatar
Tobias Hunger committed
166 167 168
}


Daniel Teske's avatar
Daniel Teske committed
169
QSize ListWidget::sizeHint() const
Tobias Hunger's avatar
Tobias Hunger committed
170
{
Daniel Teske's avatar
Daniel Teske committed
171 172
    int height = m_maxCount * 30;
    int width = 190;
Tobias Hunger's avatar
Tobias Hunger committed
173

174
    // We try to keep the height of the popup equal to the actionbar
175
    QSize size(width, height);
hjk's avatar
hjk committed
176 177
    static QStatusBar *statusBar = Core::ICore::statusBar();
    static QWidget *actionBar = Core::ICore::mainWindow()->findChild<QWidget*>(QLatin1String("actionbar"));
178 179 180
    Q_ASSERT(actionBar);

    QMargins popupMargins = window()->contentsMargins();
Daniel Teske's avatar
Daniel Teske committed
181 182 183
    int alignedWithActionHeight
            = actionBar->height() - statusBar->height() - (popupMargins.top() + popupMargins.bottom());
    size.setHeight(qBound(alignedWithActionHeight, height, 2 * alignedWithActionHeight));
184
    return size;
Tobias Hunger's avatar
Tobias Hunger committed
185 186
}

Daniel Teske's avatar
Daniel Teske committed
187
void ListWidget::keyPressEvent(QKeyEvent *event)
Tobias Hunger's avatar
Tobias Hunger committed
188
{
Daniel Teske's avatar
Daniel Teske committed
189 190 191 192 193 194
    if (event->key() == Qt::Key_Left)
        focusPreviousChild();
    else if (event->key() == Qt::Key_Right)
        focusNextChild();
    else
        QListWidget::keyPressEvent(event);
Tobias Hunger's avatar
Tobias Hunger committed
195 196
}

Daniel Teske's avatar
Daniel Teske committed
197
void ListWidget::keyReleaseEvent(QKeyEvent *event)
Tobias Hunger's avatar
Tobias Hunger committed
198
{
199
    if (event->key() != Qt::Key_Left && event->key() != Qt::Key_Right)
Daniel Teske's avatar
Daniel Teske committed
200 201
        QListWidget::keyReleaseEvent(event);
}
Tobias Hunger's avatar
Tobias Hunger committed
202

Daniel Teske's avatar
Daniel Teske committed
203 204 205 206 207 208 209 210
void ListWidget::setMaxCount(int maxCount)
{
    // Note: the current assumption is that, this is not called while the listwidget is visible
    // Otherwise we would need to add code to MiniProjectTargetSelector reacting to the
    // updateGeometry (which then would jump ugly)
    m_maxCount = maxCount;
    updateGeometry();
}
Tobias Hunger's avatar
Tobias Hunger committed
211

Daniel Teske's avatar
Daniel Teske committed
212 213 214 215 216 217 218 219 220 221 222 223
////////
// ProjectListWidget
////////
ProjectListWidget::ProjectListWidget(SessionManager *sessionManager, QWidget *parent)
    : ListWidget(parent), m_sessionManager(sessionManager), m_ignoreIndexChange(false)
{
    connect(m_sessionManager, SIGNAL(projectAdded(ProjectExplorer::Project*)),
            this, SLOT(addProject(ProjectExplorer::Project*)));
    connect(m_sessionManager, SIGNAL(aboutToRemoveProject(ProjectExplorer::Project*)),
            this, SLOT(removeProject(ProjectExplorer::Project*)));
    connect(m_sessionManager, SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
            this, SLOT(changeStartupProject(ProjectExplorer::Project*)));
224 225
    connect(m_sessionManager, SIGNAL(projectDisplayNameChanged(ProjectExplorer::Project*)),
            this, SLOT(projectDisplayNameChanged(ProjectExplorer::Project*)));
Daniel Teske's avatar
Daniel Teske committed
226 227 228 229 230 231 232 233 234 235
    connect(this, SIGNAL(currentRowChanged(int)),
            this, SLOT(setProject(int)));
}

QListWidgetItem *ProjectListWidget::itemForProject(Project *project)
{
    for (int i = 0; i < count(); ++i) {
        QListWidgetItem *currentItem = item(i);
        if (currentItem->data(Qt::UserRole).value<Project*>() == project)
            return currentItem;
Tobias Hunger's avatar
Tobias Hunger committed
236
    }
Daniel Teske's avatar
Daniel Teske committed
237 238 239 240 241
    return 0;
}

QString ProjectListWidget::fullName(ProjectExplorer::Project *project)
{
242
    return tr("%1 (%2)").arg(project->displayName(), project->document()->fileName());
Daniel Teske's avatar
Daniel Teske committed
243
}
244

Daniel Teske's avatar
Daniel Teske committed
245 246 247
void ProjectListWidget::addProject(Project *project)
{
    m_ignoreIndexChange = true;
248

249
    int pos = count();
Daniel Teske's avatar
Daniel Teske committed
250 251
    for (int i=0; i < count(); ++i) {
        Project *p = item(i)->data(Qt::UserRole).value<Project*>();
252
        if (projectLesserThan(project, p)) {
Daniel Teske's avatar
Daniel Teske committed
253
            pos = i;
254 255
            break;
        }
Daniel Teske's avatar
Daniel Teske committed
256
    }
257

Daniel Teske's avatar
Daniel Teske committed
258 259 260 261 262 263 264 265
    bool useFullName = false;
    for (int i = 0; i < count(); ++i) {
        Project *p = item(i)->data(Qt::UserRole).value<Project*>();
        if (p->displayName() == project->displayName()) {
            useFullName = true;
            item(i)->setText(fullName(p));
        }
    }
266

Daniel Teske's avatar
Daniel Teske committed
267 268 269 270 271
    QString displayName = useFullName ? fullName(project) : project->displayName();
    QListWidgetItem *item = new QListWidgetItem();
    item->setData(Qt::UserRole, QVariant::fromValue(project));
    item->setText(displayName);
    insertItem(pos, item);
Tobias Hunger's avatar
Tobias Hunger committed
272

Daniel Teske's avatar
Daniel Teske committed
273 274
    if (project == ProjectExplorerPlugin::instance()->startupProject()) {
        setCurrentItem(item);
Tobias Hunger's avatar
Tobias Hunger committed
275
    }
276

Daniel Teske's avatar
Daniel Teske committed
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
    m_ignoreIndexChange = false;
}

void ProjectListWidget::removeProject(Project *project)
{
    m_ignoreIndexChange = true;

    QListWidgetItem *listItem = itemForProject(project);
    delete listItem;

    // Update display names
    QString name = project->displayName();
    int countDisplayName = 0;
    int otherIndex = -1;
    for (int i = 0; i < count(); ++i) {
        Project *p = item(i)->data(Qt::UserRole).value<Project *>();
        if (p->displayName() == name) {
            ++countDisplayName;
            otherIndex = i;
        }
    }
    if (countDisplayName == 1) {
        Project *p = item(otherIndex)->data(Qt::UserRole).value<Project *>();
        item(otherIndex)->setText(p->displayName());
Tobias Hunger's avatar
Tobias Hunger committed
301
    }
302

Daniel Teske's avatar
Daniel Teske committed
303 304
    m_ignoreIndexChange = false;

305 306
}

307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
void ProjectListWidget::projectDisplayNameChanged(Project *project)
{
    m_ignoreIndexChange = true;

    int oldPos = 0;
    bool useFullName = false;
    for (int i = 0; i < count(); ++i) {
        Project *p = item(i)->data(Qt::UserRole).value<Project*>();
        if (p == project) {
            oldPos = i;
        } else if (p->displayName() == project->displayName()) {
            useFullName = true;
            item(i)->setText(fullName(p));
        }
    }

    bool isCurrentItem = (oldPos == currentRow());
    QListWidgetItem *projectItem = takeItem(oldPos);

    int pos = count();
    for (int i = 0; i < count(); ++i) {
        Project *p = item(i)->data(Qt::UserRole).value<Project*>();
329
        if (projectLesserThan(project, p)) {
330 331 332 333 334 335 336 337 338 339 340 341 342 343
            pos = i;
            break;
        }
    }

    QString displayName = useFullName ? fullName(project) : project->displayName();
    projectItem->setText(displayName);
    insertItem(pos, projectItem);
    if (isCurrentItem)
        setCurrentRow(pos);

    m_ignoreIndexChange = false;
}

Daniel Teske's avatar
Daniel Teske committed
344
void ProjectListWidget::setProject(int index)
con's avatar
con committed
345
{
Daniel Teske's avatar
Daniel Teske committed
346 347 348 349 350 351
    if (m_ignoreIndexChange)
        return;
    if (index < 0)
        return;
    Project *p = item(index)->data(Qt::UserRole).value<Project *>();
    m_sessionManager->setStartupProject(p);
con's avatar
con committed
352 353
}

Daniel Teske's avatar
Daniel Teske committed
354
void ProjectListWidget::changeStartupProject(Project *project)
Tobias Hunger's avatar
Tobias Hunger committed
355
{
Daniel Teske's avatar
Daniel Teske committed
356
    setCurrentItem(itemForProject(project));
Tobias Hunger's avatar
Tobias Hunger committed
357 358
}

Daniel Teske's avatar
Daniel Teske committed
359 360 361 362 363 364
/////////
// GenericListWidget
/////////

GenericListWidget::GenericListWidget(QWidget *parent)
    : ListWidget(parent), m_ignoreIndexChange(false)
365
{
Daniel Teske's avatar
Daniel Teske committed
366 367
    connect(this, SIGNAL(currentRowChanged(int)),
            this, SLOT(rowChanged(int)));
368 369
}

Daniel Teske's avatar
Daniel Teske committed
370
void GenericListWidget::setProjectConfigurations(const QList<ProjectConfiguration *> &list, ProjectConfiguration *active)
371
{
Daniel Teske's avatar
Daniel Teske committed
372 373 374 375 376 377 378 379 380 381 382
    m_ignoreIndexChange = true;
    clear();
    for (int i = 0; i < count(); ++i) {
        ProjectConfiguration *p = item(i)->data(Qt::UserRole).value<ProjectConfiguration *>();
        disconnect(p, SIGNAL(displayNameChanged()),
                   this, SLOT(displayNameChanged()));
    }
    foreach (ProjectConfiguration *pc, list)
        addProjectConfiguration(pc);
    setActiveProjectConfiguration(active);
    m_ignoreIndexChange = false;
383
}
dt's avatar
dt committed
384

Daniel Teske's avatar
Daniel Teske committed
385
void GenericListWidget::setActiveProjectConfiguration(ProjectConfiguration *active)
386
{
Daniel Teske's avatar
Daniel Teske committed
387 388
    QListWidgetItem *item = itemForProjectConfiguration(active);
    setCurrentItem(item);
389 390
}

Daniel Teske's avatar
Daniel Teske committed
391
void GenericListWidget::addProjectConfiguration(ProjectExplorer::ProjectConfiguration *pc)
392
{
Daniel Teske's avatar
Daniel Teske committed
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
    m_ignoreIndexChange = true;
    QListWidgetItem *lwi = new QListWidgetItem();
    lwi->setText(pc->displayName());
    lwi->setData(Qt::UserRole, QVariant::fromValue(pc));

    // Figure out pos
    int pos = count();
    for (int i = 0; i < count(); ++i) {
        ProjectConfiguration *p = item(i)->data(Qt::UserRole).value<ProjectConfiguration *>();
        if (pc->displayName() < p->displayName()) {
            pos = i;
            break;
        }
    }
    insertItem(pos, lwi);

    connect(pc, SIGNAL(displayNameChanged()),
            this, SLOT(displayNameChanged()));
    m_ignoreIndexChange = false;
412 413
}

Daniel Teske's avatar
Daniel Teske committed
414
void GenericListWidget::removeProjectConfiguration(ProjectExplorer::ProjectConfiguration *pc)
415
{
Daniel Teske's avatar
Daniel Teske committed
416 417 418 419 420
    m_ignoreIndexChange = true;
    disconnect(pc, SIGNAL(displayNameChanged()),
               this, SLOT(displayNameChanged()));
    delete itemForProjectConfiguration(pc);
    m_ignoreIndexChange = false;
421 422
}

Daniel Teske's avatar
Daniel Teske committed
423
void GenericListWidget::rowChanged(int index)
424
{
Daniel Teske's avatar
Daniel Teske committed
425 426 427 428 429
    if (m_ignoreIndexChange)
        return;
    if (index < 0)
        return;
    emit changeActiveProjectConfiguration(item(index)->data(Qt::UserRole).value<ProjectConfiguration *>());
430 431
}

Daniel Teske's avatar
Daniel Teske committed
432
void GenericListWidget::displayNameChanged()
433
{
Daniel Teske's avatar
Daniel Teske committed
434
    m_ignoreIndexChange = true;
435 436 437 438
    ProjectConfiguration *activeProjectConfiguration = 0;
    if (currentItem())
        activeProjectConfiguration = currentItem()->data(Qt::UserRole).value<ProjectConfiguration *>();

Daniel Teske's avatar
Daniel Teske committed
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
    ProjectConfiguration *pc = qobject_cast<ProjectConfiguration *>(sender());
    int index = -1;
    int i = 0;
    for (; i < count(); ++i) {
        QListWidgetItem *lwi = item(i);
        if (lwi->data(Qt::UserRole).value<ProjectConfiguration *>() == pc) {
            index = i;
            break;
        }
    }
    if (index == -1)
        return;
    QListWidgetItem *lwi = takeItem(i);
    lwi->setText(pc->displayName());
    int pos = count();
    for (int i = 0; i < count(); ++i) {
        ProjectConfiguration *p = item(i)->data(Qt::UserRole).value<ProjectConfiguration *>();
        if (pc->displayName() < p->displayName()) {
            pos = i;
            break;
        }
    }
    insertItem(pos, lwi);
462 463
    if (activeProjectConfiguration)
        setCurrentItem(itemForProjectConfiguration(activeProjectConfiguration));
Daniel Teske's avatar
Daniel Teske committed
464
    m_ignoreIndexChange = false;
465 466
}

Daniel Teske's avatar
Daniel Teske committed
467
QListWidgetItem *GenericListWidget::itemForProjectConfiguration(ProjectConfiguration *pc)
468
{
Daniel Teske's avatar
Daniel Teske committed
469 470 471 472 473 474 475
    for (int i = 0; i < count(); ++i) {
        QListWidgetItem *lwi = item(i);
        if (lwi->data(Qt::UserRole).value<ProjectConfiguration *>() == pc) {
            return lwi;
        }
    }
    return 0;
476 477
}

Daniel Teske's avatar
Daniel Teske committed
478
QWidget *createTitleLabel(const QString &text)
Tobias Hunger's avatar
Tobias Hunger committed
479
{
Daniel Teske's avatar
Daniel Teske committed
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
    Utils::StyledBar *bar = new Utils::StyledBar;
    bar->setSingleRow(true);
    QVBoxLayout *toolLayout = new QVBoxLayout(bar);
    toolLayout->setMargin(0);
    toolLayout->setSpacing(0);

    QLabel *l = new QLabel(text);
    l->setIndent(6);
    QFont f = l->font();
    f.setBold(true);
    l->setFont(f);
    toolLayout->addWidget(l);

    int panelHeight = l->fontMetrics().height() + 12;
    bar->ensurePolished(); // Required since manhattanstyle overrides height
    bar->setFixedHeight(panelHeight);
    return bar;
Tobias Hunger's avatar
Tobias Hunger committed
497 498
}

Daniel Teske's avatar
Daniel Teske committed
499
class OnePixelGreyLine : public QWidget
500
{
Daniel Teske's avatar
Daniel Teske committed
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
public:
    OnePixelGreyLine(QWidget *parent)
        : QWidget(parent)
    {
        setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
        setMinimumWidth(1);
        setMaximumWidth(1);
    }
    void paintEvent(QPaintEvent *e)
    {
        Q_UNUSED(e);
        QPainter p(this);
        p.fillRect(contentsRect(), QColor(160, 160, 160, 255));
    }
};

MiniProjectTargetSelector::MiniProjectTargetSelector(QAction *targetSelectorAction, SessionManager *sessionManager, QWidget *parent) :
    QWidget(parent), m_projectAction(targetSelectorAction), m_sessionManager(sessionManager),
    m_project(0),
    m_target(0),
    m_buildConfiguration(0),
    m_deployConfiguration(0),
    m_runConfiguration(0),
    m_hideOnRelease(false)
{
    QPalette p = palette();
    p.setColor(QPalette::Text, QColor(255, 255, 255, 160));
    setPalette(p);
529 530
    setProperty("panelwidget", true);
    setContentsMargins(QMargins(0, 1, 1, 8));
531 532 533 534 535
    setWindowFlags(Qt::Popup);

    targetSelectorAction->setIcon(style()->standardIcon(QStyle::SP_ComputerIcon));
    targetSelectorAction->setProperty("titledAction", true);

Daniel Teske's avatar
Daniel Teske committed
536 537 538 539 540 541 542 543
    QGridLayout *grid = new QGridLayout(this);
    grid->setMargin(0);
    grid->setSpacing(0);

    m_summaryLabel = new QLabel(this);
    m_summaryLabel->setMargin(3);
    m_summaryLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop);
    m_summaryLabel->setStyleSheet(QString::fromLatin1("background: #464646;"));
544 545
    m_summaryLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
    m_summaryLabel->setTextInteractionFlags(m_summaryLabel->textInteractionFlags() | Qt::LinksAccessibleByMouse);
Daniel Teske's avatar
Daniel Teske committed
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561

    grid->addWidget(m_summaryLabel, 0, 0, 1, 2 * LAST - 1);

    m_listWidgets.resize(LAST);
    m_titleWidgets.resize(LAST);
    m_separators.resize(LAST);
    m_listWidgets[PROJECT] = 0; //project is not a generic list widget

    m_titleWidgets[PROJECT] = createTitleLabel(tr("Project"));
    grid->addWidget(m_titleWidgets[PROJECT], 1, 0, 1, 2);
    m_projectListWidget = new ProjectListWidget(m_sessionManager, this);
    grid->addWidget(m_projectListWidget, 2, 0);
    m_separators[PROJECT] = new OnePixelGreyLine(this);
    grid->addWidget(m_separators[PROJECT], 2, 1);

    QStringList titles;
Tobias Hunger's avatar
Tobias Hunger committed
562
    titles << tr("Kit") << tr("Build")
Daniel Teske's avatar
Daniel Teske committed
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
           << tr("Deploy") << tr("Run");

    for (int i = TARGET; i < LAST; ++i) {
        m_titleWidgets[i] = createTitleLabel(titles.at(i -1));
        grid->addWidget(m_titleWidgets[i], 1, 2 * i, 1, 2);
        m_listWidgets[i] = new GenericListWidget(this);
        grid->addWidget(m_listWidgets[i], 2, 2 *i);
        m_separators[i] = new OnePixelGreyLine(this);
        grid->addWidget(m_separators[i], 2, 1 + 2 * i);
    }

    changeStartupProject(m_sessionManager->startupProject());
    if (m_sessionManager->startupProject())
        activeTargetChanged(m_sessionManager->startupProject()->activeTarget());

578 579 580
    connect(m_summaryLabel, SIGNAL(linkActivated(QString)),
            this, SLOT(switchToProjectsMode()));

Daniel Teske's avatar
Daniel Teske committed
581 582 583 584 585 586 587
    connect(m_sessionManager, SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
            this, SLOT(changeStartupProject(ProjectExplorer::Project*)));

    connect(m_sessionManager, SIGNAL(projectAdded(ProjectExplorer::Project*)),
            this, SLOT(projectAdded(ProjectExplorer::Project*)));
    connect(m_sessionManager, SIGNAL(projectRemoved(ProjectExplorer::Project*)),
            this, SLOT(projectRemoved(ProjectExplorer::Project*)));
588 589
    connect(m_sessionManager, SIGNAL(projectDisplayNameChanged(ProjectExplorer::Project*)),
            this, SLOT(updateActionAndSummary()));
Daniel Teske's avatar
Daniel Teske committed
590

Tobias Hunger's avatar
Tobias Hunger committed
591
    // for icon changes:
Tobias Hunger's avatar
Tobias Hunger committed
592 593
    connect(ProjectExplorer::KitManager::instance(), SIGNAL(kitUpdated(ProjectExplorer::Kit*)),
            this, SLOT(kitChanged(ProjectExplorer::Kit*)));
Tobias Hunger's avatar
Tobias Hunger committed
594

Daniel Teske's avatar
Daniel Teske committed
595
    connect(m_listWidgets[TARGET], SIGNAL(changeActiveProjectConfiguration(ProjectExplorer::ProjectConfiguration*)),
Robert Loehning's avatar
Robert Loehning committed
596
            this, SLOT(setActiveTarget(ProjectExplorer::ProjectConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
597
    connect(m_listWidgets[BUILD], SIGNAL(changeActiveProjectConfiguration(ProjectExplorer::ProjectConfiguration*)),
Robert Loehning's avatar
Robert Loehning committed
598
            this, SLOT(setActiveBuildConfiguration(ProjectExplorer::ProjectConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
599
    connect(m_listWidgets[DEPLOY], SIGNAL(changeActiveProjectConfiguration(ProjectExplorer::ProjectConfiguration*)),
Robert Loehning's avatar
Robert Loehning committed
600
            this, SLOT(setActiveDeployConfiguration(ProjectExplorer::ProjectConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
601
    connect(m_listWidgets[RUN], SIGNAL(changeActiveProjectConfiguration(ProjectExplorer::ProjectConfiguration*)),
Robert Loehning's avatar
Robert Loehning committed
602
            this, SLOT(setActiveRunConfiguration(ProjectExplorer::ProjectConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
603
}
604

Daniel Teske's avatar
Daniel Teske committed
605 606 607 608
void MiniProjectTargetSelector::setActiveTarget(ProjectExplorer::ProjectConfiguration *pc)
{
    m_project->setActiveTarget(static_cast<Target *>(pc));
}
609

Daniel Teske's avatar
Daniel Teske committed
610 611 612 613
void MiniProjectTargetSelector::setActiveBuildConfiguration(ProjectExplorer::ProjectConfiguration *pc)
{
    m_target->setActiveBuildConfiguration(static_cast<BuildConfiguration *>(pc));
}
614

Daniel Teske's avatar
Daniel Teske committed
615 616 617 618 619 620 621 622 623
void MiniProjectTargetSelector::setActiveDeployConfiguration(ProjectExplorer::ProjectConfiguration *pc)
{
    m_target->setActiveDeployConfiguration(static_cast<DeployConfiguration *>(pc));
}

void MiniProjectTargetSelector::setActiveRunConfiguration(ProjectExplorer::ProjectConfiguration *pc)
{
    m_target->setActiveRunConfiguration(static_cast<RunConfiguration *>(pc));
}
624

Daniel Teske's avatar
Daniel Teske committed
625 626 627
void MiniProjectTargetSelector::projectAdded(ProjectExplorer::Project *project)
{
    connect(project, SIGNAL(addedTarget(ProjectExplorer::Target*)),
628
            this, SLOT(slotAddedTarget(ProjectExplorer::Target*)));
629

Daniel Teske's avatar
Daniel Teske committed
630
    connect(project, SIGNAL(removedTarget(ProjectExplorer::Target*)),
631
            this, SLOT(slotRemovedTarget(ProjectExplorer::Target*)));
632

Daniel Teske's avatar
Daniel Teske committed
633 634
    foreach (Target *t, project->targets())
        addedTarget(t);
635

Daniel Teske's avatar
Daniel Teske committed
636 637 638 639 640
    updateProjectListVisible();
    updateTargetListVisible();
    updateBuildListVisible();
    updateDeployListVisible();
    updateRunListVisible();
641 642
}

Daniel Teske's avatar
Daniel Teske committed
643
void MiniProjectTargetSelector::projectRemoved(ProjectExplorer::Project *project)
644
{
Daniel Teske's avatar
Daniel Teske committed
645
    disconnect(project, SIGNAL(addedTarget(ProjectExplorer::Target*)),
646
               this, SLOT(slotAddedTarget(ProjectExplorer::Target*)));
647

Daniel Teske's avatar
Daniel Teske committed
648
    disconnect(project, SIGNAL(removedTarget(ProjectExplorer::Target*)),
649
               this, SLOT(slotRemovedTarget(ProjectExplorer::Target*)));
650

Daniel Teske's avatar
Daniel Teske committed
651 652
    foreach (Target *t, project->targets())
        removedTarget(t);
653

Daniel Teske's avatar
Daniel Teske committed
654 655 656 657 658
    updateProjectListVisible();
    updateTargetListVisible();
    updateBuildListVisible();
    updateDeployListVisible();
    updateRunListVisible();
659 660
}

Daniel Teske's avatar
Daniel Teske committed
661
void MiniProjectTargetSelector::addedTarget(ProjectExplorer::Target *target)
662
{
Daniel Teske's avatar
Daniel Teske committed
663
    connect(target, SIGNAL(addedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
664
            this, SLOT(slotAddedBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
665
    connect(target, SIGNAL(removedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
666
            this, SLOT(slotRemovedBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
667 668

    connect(target, SIGNAL(addedDeployConfiguration(ProjectExplorer::DeployConfiguration*)),
669
            this, SLOT(slotAddedDeployConfiguration(ProjectExplorer::DeployConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
670
    connect(target, SIGNAL(removedDeployConfiguration(ProjectExplorer::DeployConfiguration*)),
671
            this, SLOT(slotRemovedDeployConfiguration(ProjectExplorer::DeployConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
672 673

    connect(target, SIGNAL(addedRunConfiguration(ProjectExplorer::RunConfiguration*)),
674
            this, SLOT(slotAddedRunConfiguration(ProjectExplorer::RunConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
675
    connect(target, SIGNAL(removedRunConfiguration(ProjectExplorer::RunConfiguration*)),
676
            this, SLOT(slotRemovedRunConfiguration(ProjectExplorer::RunConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
677 678 679 680 681 682 683 684 685 686

    if (target->project() == m_project)
        m_listWidgets[TARGET]->addProjectConfiguration(target);

    foreach (BuildConfiguration *bc, target->buildConfigurations())
        addedBuildConfiguration(bc);
    foreach (DeployConfiguration *dc, target->deployConfigurations())
        addedDeployConfiguration(dc);
    foreach (RunConfiguration *rc, target->runConfigurations())
        addedRunConfiguration(rc);
687
}
Daniel Teske's avatar
Daniel Teske committed
688

689 690 691
void MiniProjectTargetSelector::slotAddedTarget(ProjectExplorer::Target *target)
{
    addedTarget(target);
Daniel Teske's avatar
Daniel Teske committed
692 693 694 695
    updateTargetListVisible();
    updateBuildListVisible();
    updateDeployListVisible();
    updateRunListVisible();
696 697
}

Daniel Teske's avatar
Daniel Teske committed
698
void MiniProjectTargetSelector::removedTarget(ProjectExplorer::Target *target)
699
{
Daniel Teske's avatar
Daniel Teske committed
700
    disconnect(target, SIGNAL(addedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
701
               this, SLOT(slotAddedBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
702
    disconnect(target, SIGNAL(removedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
703
               this, SLOT(slotRemovedBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
704 705

    disconnect(target, SIGNAL(addedDeployConfiguration(ProjectExplorer::DeployConfiguration*)),
706
               this, SLOT(slotAddedDeployConfiguration(ProjectExplorer::DeployConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
707
    disconnect(target, SIGNAL(removedDeployConfiguration(ProjectExplorer::DeployConfiguration*)),
708
               this, SLOT(slotRemovedDeployConfiguration(ProjectExplorer::DeployConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
709 710

    disconnect(target, SIGNAL(addedRunConfiguration(ProjectExplorer::RunConfiguration*)),
711
               this, SLOT(slotAddedRunConfiguration(ProjectExplorer::RunConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
712
    disconnect(target, SIGNAL(removedRunConfiguration(ProjectExplorer::RunConfiguration*)),
713
               this, SLOT(slotRemovedRunConfiguration(ProjectExplorer::RunConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
714 715 716 717 718 719 720 721 722 723

    if (target->project() == m_project)
        m_listWidgets[TARGET]->removeProjectConfiguration(target);

    foreach (BuildConfiguration *bc, target->buildConfigurations())
        removedBuildConfiguration(bc);
    foreach (DeployConfiguration *dc, target->deployConfigurations())
        removedDeployConfiguration(dc);
    foreach (RunConfiguration *rc, target->runConfigurations())
        removedRunConfiguration(rc);
724 725 726 727 728
}

void MiniProjectTargetSelector::slotRemovedTarget(ProjectExplorer::Target *target)
{
    removedTarget(target);
Daniel Teske's avatar
Daniel Teske committed
729 730 731 732 733

    updateTargetListVisible();
    updateBuildListVisible();
    updateDeployListVisible();
    updateRunListVisible();
734 735
}

736

Daniel Teske's avatar
Daniel Teske committed
737
void MiniProjectTargetSelector::addedBuildConfiguration(ProjectExplorer::BuildConfiguration *bc)
738 739 740 741 742 743
{
    if (bc->target() == m_target)
        m_listWidgets[BUILD]->addProjectConfiguration(bc);
}

void MiniProjectTargetSelector::slotAddedBuildConfiguration(ProjectExplorer::BuildConfiguration *bc)
744
{
Daniel Teske's avatar
Daniel Teske committed
745 746 747 748
    if (bc->target() == m_target)
        m_listWidgets[BUILD]->addProjectConfiguration(bc);
    updateBuildListVisible();
}
749

Daniel Teske's avatar
Daniel Teske committed
750
void MiniProjectTargetSelector::removedBuildConfiguration(ProjectExplorer::BuildConfiguration *bc)
751 752 753 754 755 756
{
    if (bc->target() == m_target)
        m_listWidgets[BUILD]->removeProjectConfiguration(bc);
}

void MiniProjectTargetSelector::slotRemovedBuildConfiguration(ProjectExplorer::BuildConfiguration *bc)
Daniel Teske's avatar
Daniel Teske committed
757 758 759 760 761
{
    if (bc->target() == m_target)
        m_listWidgets[BUILD]->removeProjectConfiguration(bc);
    updateBuildListVisible();
}
dt's avatar
dt committed
762

Daniel Teske's avatar
Daniel Teske committed
763
void MiniProjectTargetSelector::addedDeployConfiguration(ProjectExplorer::DeployConfiguration *dc)
764 765 766 767 768 769
{
    if (dc->target() == m_target)
        m_listWidgets[DEPLOY]->addProjectConfiguration(dc);
}

void MiniProjectTargetSelector::slotAddedDeployConfiguration(ProjectExplorer::DeployConfiguration *dc)
Daniel Teske's avatar
Daniel Teske committed
770 771 772 773 774
{
    if (dc->target() == m_target)
        m_listWidgets[DEPLOY]->addProjectConfiguration(dc);
    updateDeployListVisible();
}
dt's avatar
dt committed
775

Daniel Teske's avatar
Daniel Teske committed
776
void MiniProjectTargetSelector::removedDeployConfiguration(ProjectExplorer::DeployConfiguration *dc)
777 778 779 780 781 782
{
    if (dc->target() == m_target)
        m_listWidgets[DEPLOY]->removeProjectConfiguration(dc);
}

void MiniProjectTargetSelector::slotRemovedDeployConfiguration(ProjectExplorer::DeployConfiguration *dc)
Daniel Teske's avatar
Daniel Teske committed
783 784 785 786 787
{
    if (dc->target() == m_target)
        m_listWidgets[DEPLOY]->removeProjectConfiguration(dc);
    updateDeployListVisible();
}
dt's avatar
dt committed
788

Daniel Teske's avatar
Daniel Teske committed
789
void MiniProjectTargetSelector::addedRunConfiguration(ProjectExplorer::RunConfiguration *rc)
790 791 792 793 794 795
{
    if (rc->target() == m_target)
        m_listWidgets[RUN]->addProjectConfiguration(rc);
}

void MiniProjectTargetSelector::slotAddedRunConfiguration(ProjectExplorer::RunConfiguration *rc)
Daniel Teske's avatar
Daniel Teske committed
796 797 798 799 800
{
    if (rc->target() == m_target)
        m_listWidgets[RUN]->addProjectConfiguration(rc);
    updateRunListVisible();
}
801

Daniel Teske's avatar
Daniel Teske committed
802
void MiniProjectTargetSelector::removedRunConfiguration(ProjectExplorer::RunConfiguration *rc)
803 804 805 806 807 808
{
    if (rc->target() == m_target)
        m_listWidgets[RUN]->removeProjectConfiguration(rc);
}

void MiniProjectTargetSelector::slotRemovedRunConfiguration(ProjectExplorer::RunConfiguration *rc)
Daniel Teske's avatar
Daniel Teske committed
809 810 811 812 813
{
    if (rc->target() == m_target)
        m_listWidgets[RUN]->removeProjectConfiguration(rc);
    updateRunListVisible();
}
814

Daniel Teske's avatar
Daniel Teske committed
815 816 817
void MiniProjectTargetSelector::updateProjectListVisible()
{
    bool visible = m_sessionManager->projects().size() > 1;
818

Daniel Teske's avatar
Daniel Teske committed
819 820 821
    m_projectListWidget->setVisible(visible);
    m_projectListWidget->setMaxCount(m_sessionManager->projects().size());
    m_titleWidgets[PROJECT]->setVisible(visible);
822

Daniel Teske's avatar
Daniel Teske committed
823 824 825
    updateSummary();
    updateSeparatorVisible();
}
Tobias Hunger's avatar
Tobias Hunger committed
826

Daniel Teske's avatar
Daniel Teske committed
827 828 829 830 831 832 833 834 835 836 837 838 839
void MiniProjectTargetSelector::updateTargetListVisible()
{
    int maxCount = 0;
    foreach (Project *p, m_sessionManager->projects())
        maxCount = qMax(p->targets().size(), maxCount);

    bool visible = maxCount > 1;
    m_listWidgets[TARGET]->setVisible(visible);
    m_listWidgets[TARGET]->setMaxCount(maxCount);
    m_titleWidgets[TARGET]->setVisible(visible);
    updateSummary();
    updateSeparatorVisible();
}
dt's avatar
dt committed
840

Daniel Teske's avatar
Daniel Teske committed
841 842 843 844 845 846 847 848 849 850 851 852 853 854
void MiniProjectTargetSelector::updateBuildListVisible()
{
    int maxCount = 0;
    foreach (Project *p, m_sessionManager->projects())
        foreach (Target *t, p->targets())
            maxCount = qMax(t->buildConfigurations().size(), maxCount);

    bool visible = maxCount > 1;
    m_listWidgets[BUILD]->setVisible(visible);
    m_listWidgets[BUILD]->setMaxCount(maxCount);
    m_titleWidgets[BUILD]->setVisible(visible);
    updateSummary();
    updateSeparatorVisible();
}
855

Daniel Teske's avatar
Daniel Teske committed
856 857 858 859 860 861 862 863 864 865 866 867 868
void MiniProjectTargetSelector::updateDeployListVisible()
{
    int maxCount = 0;
    foreach (Project *p, m_sessionManager->projects())
        foreach (Target *t, p->targets())
            maxCount = qMax(t->deployConfigurations().size(), maxCount);

    bool visible = maxCount > 1;
    m_listWidgets[DEPLOY]->setVisible(visible);
    m_listWidgets[DEPLOY]->setMaxCount(maxCount);
    m_titleWidgets[DEPLOY]->setVisible(visible);
    updateSummary();
    updateSeparatorVisible();
869 870
}

Daniel Teske's avatar
Daniel Teske committed
871
void MiniProjectTargetSelector::updateRunListVisible()
872
{
Daniel Teske's avatar
Daniel Teske committed
873 874 875 876 877 878 879 880 881 882 883 884
    int maxCount = 0;
    foreach (Project *p, m_sessionManager->projects())
        foreach (Target *t, p->targets())
            maxCount = qMax(t->runConfigurations().size(), maxCount);

    bool visible = maxCount > 1;
    m_listWidgets[RUN]->setVisible(visible);
    m_listWidgets[RUN]->setMaxCount(maxCount);
    m_titleWidgets[RUN]->setVisible(visible);
    updateSummary();
    updateSeparatorVisible();
}
885

Daniel Teske's avatar
Daniel Teske committed
886 887 888 889 890 891 892 893 894 895 896 897 898 899
void MiniProjectTargetSelector::changeStartupProject(ProjectExplorer::Project *project)
{
    if (m_project) {
        disconnect(m_project, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
                   this, SLOT(activeTargetChanged(ProjectExplorer::Target*)));
    }
    m_project = project;
    if (m_project) {
        connect(m_project, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
                this, SLOT(activeTargetChanged(ProjectExplorer::Target*)));
        activeTargetChanged(m_project->activeTarget());
    } else {
        activeTargetChanged(0);
    }
900

Daniel Teske's avatar
Daniel Teske committed
901 902 903 904 905 906 907
    if (project) {
        QList<ProjectConfiguration *> list;
        foreach (Target *t, project->targets())
            list.append(t);
        m_listWidgets[TARGET]->setProjectConfigurations(list, project->activeTarget());
    } else {
        m_listWidgets[TARGET]->setProjectConfigurations(QList<ProjectConfiguration *>(), 0);
908
    }
Daniel Teske's avatar
Daniel Teske committed
909 910 911 912 913 914 915 916 917 918 919

    updateActionAndSummary();
}

void MiniProjectTargetSelector::activeTargetChanged(ProjectExplorer::Target *target)
{
    if (m_target) {
        disconnect(m_target, SIGNAL(displayNameChanged()),
                   this, SLOT(updateActionAndSummary()));
        disconnect(m_target, SIGNAL(toolTipChanged()),
                   this, SLOT(updateActionAndSummary()));
Tobias Hunger's avatar
Tobias Hunger committed
920 921
        disconnect(m_target, SIGNAL(iconChanged()),
                   this, SLOT(updateActionAndSummary()));
Daniel Teske's avatar
Daniel Teske committed
922 923 924 925 926 927
        disconnect(m_target, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
                   this, SLOT(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)));
        disconnect(m_target, SIGNAL(activeDeployConfigurationChanged(ProjectExplorer::DeployConfiguration*)),
                   this, SLOT(activeDeployConfigurationChanged(ProjectExplorer::DeployConfiguration*)));
        disconnect(m_target, SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
                   this, SLOT(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)));
928 929
    }

Daniel Teske's avatar
Daniel Teske committed
930 931
    m_target = target;

932 933
    m_listWidgets[TARGET]->setActiveProjectConfiguration(m_target);

Daniel Teske's avatar
Daniel Teske committed
934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977
    if (m_buildConfiguration)
        disconnect(m_buildConfiguration, SIGNAL(displayNameChanged()),
                   this, SLOT(updateActionAndSummary()));
    if (m_deployConfiguration)
        disconnect(m_deployConfiguration, SIGNAL(displayNameChanged()),
                   this, SLOT(updateActionAndSummary()));

    if (m_runConfiguration)
        disconnect(m_runConfiguration, SIGNAL(displayNameChanged()),
                   this, SLOT(updateActionAndSummary()));

    if (m_target) {
        QList<ProjectConfiguration *> bl;
        foreach (BuildConfiguration *bc, target->buildConfigurations())
            bl.append(bc);
        m_listWidgets[BUILD]->setProjectConfigurations(bl, target->activeBuildConfiguration());

        QList<ProjectConfiguration *> dl;
        foreach (DeployConfiguration *dc, target->deployConfigurations())
            dl.append(dc);
        m_listWidgets[DEPLOY]->setProjectConfigurations(dl, target->activeDeployConfiguration());

        QList<ProjectConfiguration *> rl;
        foreach (RunConfiguration *rc, target->runConfigurations())
            rl.append(rc);
        m_listWidgets[RUN]->setProjectConfigurations(rl, target->activeRunConfiguration());

        m_buildConfiguration = m_target->activeBuildConfiguration();
        if (m_buildConfiguration)
            connect(m_buildConfiguration, SIGNAL(displayNameChanged()),
                    this, SLOT(updateActionAndSummary()));
        m_deployConfiguration = m_target->activeDeployConfiguration();
        if (m_deployConfiguration)
            connect(m_deployConfiguration, SIGNAL(displayNameChanged()),
                    this, SLOT(updateActionAndSummary()));
        m_runConfiguration = m_target->activeRunConfiguration();
        if (m_runConfiguration)
            connect(m_runConfiguration, SIGNAL(displayNameChanged()),
                    this, SLOT(updateActionAndSummary()));

        connect(m_target, SIGNAL(displayNameChanged()),
                this, SLOT(updateActionAndSummary()));
        connect(m_target, SIGNAL(toolTipChanged()),
                this, SLOT(updateActionAndSummary()));
Tobias Hunger's avatar
Tobias Hunger committed
978 979
        connect(m_target, SIGNAL(iconChanged()),
                this, SLOT(updateActionAndSummary()));
Daniel Teske's avatar
Daniel Teske committed
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994
        connect(m_target, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
                this, SLOT(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)));
        connect(m_target, SIGNAL(activeDeployConfigurationChanged(ProjectExplorer::DeployConfiguration*)),
                this, SLOT(activeDeployConfigurationChanged(ProjectExplorer::DeployConfiguration*)));
        connect(m_target, SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
                this, SLOT(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)));
    } else {
        m_listWidgets[BUILD]->setProjectConfigurations(QList<ProjectConfiguration *>(), 0);
        m_listWidgets[DEPLOY]->setProjectConfigurations(QList<ProjectConfiguration *>(), 0);
        m_listWidgets[RUN]->setProjectConfigurations(QList<ProjectConfiguration *>(), 0);
        m_buildConfiguration = 0;
        m_deployConfiguration = 0;
        m_runConfiguration = 0;
    }
    updateActionAndSummary();
995 996
}

Tobias Hunger's avatar
Tobias Hunger committed
997
void MiniProjectTargetSelector::kitChanged(Kit *k)
Tobias Hunger's avatar
Tobias Hunger committed
998
{
Tobias Hunger's avatar
Tobias Hunger committed
999
    if (m_target && m_target->kit() == k)
Tobias Hunger's avatar
Tobias Hunger committed
1000 1001 1002
        updateActionAndSummary();
}

Daniel Teske's avatar
Daniel Teske committed
1003
void MiniProjectTargetSelector::activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration *bc)
Tobias Hunger's avatar
Tobias Hunger committed
1004
{
Daniel Teske's avatar
Daniel Teske committed
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
    if (m_buildConfiguration)
        disconnect(m_buildConfiguration, SIGNAL(displayNameChanged()),
                   this, SLOT(updateActionAndSummary()));
    m_buildConfiguration = bc;
    if (m_buildConfiguration)
        connect(m_buildConfiguration, SIGNAL(displayNameChanged()),
                this, SLOT(updateActionAndSummary()));
    m_listWidgets[BUILD]->setActiveProjectConfiguration(bc);
    updateActionAndSummary();
}
Tobias Hunger's avatar
Tobias Hunger committed
1015

Daniel Teske's avatar
Daniel Teske committed
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
void MiniProjectTargetSelector::activeDeployConfigurationChanged(ProjectExplorer::DeployConfiguration *dc)
{
    if (m_deployConfiguration)
        disconnect(m_deployConfiguration, SIGNAL(displayNameChanged()),
                   this, SLOT(updateActionAndSummary()));
    m_deployConfiguration = dc;
    if (m_deployConfiguration)
        connect(m_deployConfiguration, SIGNAL(displayNameChanged()),
                this, SLOT(updateActionAndSummary()));
    m_listWidgets[DEPLOY]->setActiveProjectConfiguration(dc);
1026
    updateActionAndSummary();
Daniel Teske's avatar
Daniel Teske committed
1027
}
Tobias Hunger's avatar
Tobias Hunger committed
1028

Daniel Teske's avatar
Daniel Teske committed
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
void MiniProjectTargetSelector::activeRunConfigurationChanged(ProjectExplorer::RunConfiguration *rc)
{
    if (m_runConfiguration)
        disconnect(m_runConfiguration, SIGNAL(displayNameChanged()),
                   this, SLOT(updateActionAndSummary()));
    m_runConfiguration = rc;
    if (m_runConfiguration)
        connect(m_runConfiguration, SIGNAL(displayNameChanged()),
                this, SLOT(updateActionAndSummary()));
    m_listWidgets[RUN]->setActiveProjectConfiguration(rc);
    updateActionAndSummary();
}
1041

Daniel Teske's avatar
Daniel Teske committed
1042 1043 1044 1045 1046 1047 1048 1049 1050