miniprojecttargetselector.cpp 57.1 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Tobias Hunger's avatar
Tobias Hunger committed
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
Tobias Hunger's avatar
Tobias Hunger committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
Tobias Hunger's avatar
Tobias Hunger committed
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
Tobias Hunger's avatar
Tobias Hunger committed
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
Tobias Hunger's avatar
Tobias Hunger committed
29

30
#include "miniprojecttargetselector.h"
31 32 33
#include "kit.h"
#include "kitconfigwidget.h"
#include "kitmanager.h"
34
#include "target.h"
35 36 37 38 39

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

#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
#include <QTimer>
#include <QLayout>
#include <QLabel>
#include <QListWidget>
#include <QStatusBar>
#include <QKeyEvent>
#include <QPainter>
#include <QAction>
#include <QItemDelegate>
61

62 63 64 65
#if QT_VERSION >= 0x050100
#include <QGuiApplication>
#endif

66 67 68
static QIcon createCenteredIcon(const QIcon &icon, const QIcon &overlay)
{
    QPixmap targetPixmap;
69 70 71 72 73 74 75 76 77
    qreal appDevicePixelRatio = 1.0;
#if QT_VERSION >= 0x050100
    appDevicePixelRatio = qApp->devicePixelRatio();
#endif
    int deviceSpaceIconSize = Core::Constants::TARGET_ICON_SIZE * appDevicePixelRatio;
    targetPixmap = QPixmap(deviceSpaceIconSize, deviceSpaceIconSize);
#if QT_VERSION >= 0x050100
    targetPixmap.setDevicePixelRatio(appDevicePixelRatio);
#endif
78
    targetPixmap.fill(Qt::transparent);
79
    QPainter painter(&targetPixmap); // painter in user space
80

81 82 83 84 85 86 87
    QPixmap pixmap = icon.pixmap(Core::Constants::TARGET_ICON_SIZE); // already takes app devicePixelRatio into account
    qreal pixmapDevicePixelRatio = 1.0;
#if QT_VERSION >= 0x050100
    pixmapDevicePixelRatio = pixmap.devicePixelRatio();
#endif
    painter.drawPixmap((Core::Constants::TARGET_ICON_SIZE - pixmap.width() / pixmapDevicePixelRatio) / 2,
                       (Core::Constants::TARGET_ICON_SIZE - pixmap.height() / pixmapDevicePixelRatio) / 2, pixmap);
88
    if (!overlay.isNull()) {
89 90 91 92 93 94 95
        pixmap = overlay.pixmap(Core::Constants::TARGET_ICON_SIZE); // already takes app devicePixelRatio into account
        pixmapDevicePixelRatio = 1.0;
#if QT_VERSION >= 0x050100
        pixmapDevicePixelRatio = pixmap.devicePixelRatio();
#endif
        painter.drawPixmap((Core::Constants::TARGET_ICON_SIZE - pixmap.width() / pixmapDevicePixelRatio) / 2,
                           (Core::Constants::TARGET_ICON_SIZE - pixmap.height() / pixmapDevicePixelRatio) / 2, pixmap);
96
    }
97

98 99 100
    return QIcon(targetPixmap);
}

101 102 103
using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;

104 105 106 107 108 109 110 111 112
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
113 114 115
////////
// TargetSelectorDelegate
////////
116 117 118
class TargetSelectorDelegate : public QItemDelegate
{
public:
119
    TargetSelectorDelegate(ListWidget *parent) : QItemDelegate(parent), m_listWidget(parent) { }
120
private:
Daniel Teske's avatar
Daniel Teske committed
121
    QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
122 123 124 125
    void paint(QPainter *painter,
               const QStyleOptionViewItem &option,
               const QModelIndex &index) const;
    mutable QImage selectionGradient;
126
    ListWidget *m_listWidget;
127 128
};

Daniel Teske's avatar
Daniel Teske committed
129 130 131 132
QSize TargetSelectorDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    Q_UNUSED(option)
    Q_UNUSED(index)
133
    return QSize(m_listWidget->size().width(), 30);
Daniel Teske's avatar
Daniel Teske committed
134 135
}

136 137
void TargetSelectorDelegate::paint(QPainter *painter,
                                   const QStyleOptionViewItem &option,
Daniel Teske's avatar
Daniel Teske committed
138
                                   const QModelIndex &index) const
139 140 141 142 143 144 145 146
{
    painter->save();
    painter->setClipping(false);

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

    if (option.state & QStyle::State_Selected) {
147 148 149 150
        QColor color =(option.state & QStyle::State_HasFocus) ?
                      option.palette.highlight().color() :
                      option.palette.dark().color();
        painter->fillRect(option.rect, color.darker(140));
151 152 153 154 155 156 157 158
        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
159 160 161 162 163 164 165 166

    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
167
        const_cast<QAbstractItemModel *>(index.model())->setData(index, QString(), Qt::ToolTipRole);
Daniel Teske's avatar
Daniel Teske committed
168 169
    painter->drawText(option.rect.left() + 6, option.rect.top() + (option.rect.height() - fm.height()) / 2 + fm.ascent(), elidedText);

170 171 172
    painter->restore();
}

Daniel Teske's avatar
Daniel Teske committed
173 174 175 176
////////
// ListWidget
////////
ListWidget::ListWidget(QWidget *parent)
177
    : QListWidget(parent), m_maxCount(0), m_optimalWidth(0)
Tobias Hunger's avatar
Tobias Hunger committed
178 179 180 181 182
{
    setFocusPolicy(Qt::NoFocus);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setAlternatingRowColors(false);
    setFocusPolicy(Qt::WheelFocus);
183
    setItemDelegate(new TargetSelectorDelegate(this));
184
    setAttribute(Qt::WA_MacShowFocusRect, false);
Daniel Teske's avatar
Daniel Teske committed
185 186
    setStyleSheet(QString::fromLatin1("QListWidget { background: #464646; border-style: none; }"));
    setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
Tobias Hunger's avatar
Tobias Hunger committed
187 188
}

Daniel Teske's avatar
Daniel Teske committed
189
void ListWidget::keyPressEvent(QKeyEvent *event)
Tobias Hunger's avatar
Tobias Hunger committed
190
{
Daniel Teske's avatar
Daniel Teske committed
191 192 193 194 195 196
    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
197 198
}

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

Daniel Teske's avatar
Daniel Teske committed
205 206 207 208 209
void ListWidget::setMaxCount(int maxCount)
{
    m_maxCount = maxCount;
    updateGeometry();
}
Tobias Hunger's avatar
Tobias Hunger committed
210

211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
int ListWidget::maxCount()
{
    return m_maxCount;
}

int ListWidget::optimalWidth() const
{
    return m_optimalWidth;
}

void ListWidget::setOptimalWidth(int width)
{
    m_optimalWidth = width;
    updateGeometry();
}

int ListWidget::padding()
{
    // there needs to be enough extra pixels to show a scrollbar
    return 30;
}

Daniel Teske's avatar
Daniel Teske committed
233 234 235
////////
// ProjectListWidget
////////
236 237
ProjectListWidget::ProjectListWidget(QWidget *parent)
    : ListWidget(parent), m_ignoreIndexChange(false)
Daniel Teske's avatar
Daniel Teske committed
238
{
239 240
    QObject *sessionManager = SessionManager::instance();
    connect(sessionManager, SIGNAL(projectAdded(ProjectExplorer::Project*)),
Daniel Teske's avatar
Daniel Teske committed
241
            this, SLOT(addProject(ProjectExplorer::Project*)));
242
    connect(sessionManager, SIGNAL(aboutToRemoveProject(ProjectExplorer::Project*)),
Daniel Teske's avatar
Daniel Teske committed
243
            this, SLOT(removeProject(ProjectExplorer::Project*)));
244
    connect(sessionManager, SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
Daniel Teske's avatar
Daniel Teske committed
245
            this, SLOT(changeStartupProject(ProjectExplorer::Project*)));
246
    connect(sessionManager, SIGNAL(projectDisplayNameChanged(ProjectExplorer::Project*)),
247
            this, SLOT(projectDisplayNameChanged(ProjectExplorer::Project*)));
Daniel Teske's avatar
Daniel Teske committed
248 249 250 251 252 253 254 255 256 257
    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
258
    }
Daniel Teske's avatar
Daniel Teske committed
259 260 261 262 263
    return 0;
}

QString ProjectListWidget::fullName(ProjectExplorer::Project *project)
{
264
    return tr("%1 (%2)").arg(project->displayName(), project->projectFilePath());
Daniel Teske's avatar
Daniel Teske committed
265
}
266

Daniel Teske's avatar
Daniel Teske committed
267 268 269
void ProjectListWidget::addProject(Project *project)
{
    m_ignoreIndexChange = true;
270

271
    int pos = count();
Daniel Teske's avatar
Daniel Teske committed
272 273
    for (int i=0; i < count(); ++i) {
        Project *p = item(i)->data(Qt::UserRole).value<Project*>();
274
        if (projectLesserThan(project, p)) {
Daniel Teske's avatar
Daniel Teske committed
275
            pos = i;
276 277
            break;
        }
Daniel Teske's avatar
Daniel Teske committed
278
    }
279

Daniel Teske's avatar
Daniel Teske committed
280 281 282 283 284 285 286 287
    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));
        }
    }
288

Daniel Teske's avatar
Daniel Teske committed
289 290 291 292 293
    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
294

hjk's avatar
hjk committed
295
    if (project == SessionManager::startupProject())
Daniel Teske's avatar
Daniel Teske committed
296
        setCurrentItem(item);
297

298
    QFontMetrics fn(font());
299
    int width = fn.width(displayName) + padding();
300 301 302
    if (width > optimalWidth())
        setOptimalWidth(width);

Daniel Teske's avatar
Daniel Teske committed
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
    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
327
    }
328

329 330 331 332
    QFontMetrics fn(font());

    // recheck optimal width
    int width = 0;
333 334
    for (int i = 0; i < count(); ++i)
        width = qMax(fn.width(item(i)->text()) + padding(), width);
335
    setOptimalWidth(width);
Daniel Teske's avatar
Daniel Teske committed
336

337
    m_ignoreIndexChange = false;
338 339
}

340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
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*>();
362
        if (projectLesserThan(project, p)) {
363 364 365 366 367 368 369 370 371 372 373
            pos = i;
            break;
        }
    }

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

374 375 376
    // recheck optimal width
    QFontMetrics fn(font());
    int width = 0;
377 378
    for (int i = 0; i < count(); ++i)
        width = qMax(fn.width(item(i)->text()) + padding(), width);
379 380
    setOptimalWidth(width);

381 382 383
    m_ignoreIndexChange = false;
}

Daniel Teske's avatar
Daniel Teske committed
384
void ProjectListWidget::setProject(int index)
con's avatar
con committed
385
{
Daniel Teske's avatar
Daniel Teske committed
386 387 388 389 390
    if (m_ignoreIndexChange)
        return;
    if (index < 0)
        return;
    Project *p = item(index)->data(Qt::UserRole).value<Project *>();
391
    SessionManager::setStartupProject(p);
con's avatar
con committed
392 393
}

Daniel Teske's avatar
Daniel Teske committed
394
void ProjectListWidget::changeStartupProject(Project *project)
Tobias Hunger's avatar
Tobias Hunger committed
395
{
Daniel Teske's avatar
Daniel Teske committed
396
    setCurrentItem(itemForProject(project));
Tobias Hunger's avatar
Tobias Hunger committed
397 398
}

Daniel Teske's avatar
Daniel Teske committed
399 400 401 402 403 404
/////////
// GenericListWidget
/////////

GenericListWidget::GenericListWidget(QWidget *parent)
    : ListWidget(parent), m_ignoreIndexChange(false)
405
{
Daniel Teske's avatar
Daniel Teske committed
406 407
    connect(this, SIGNAL(currentRowChanged(int)),
            this, SLOT(rowChanged(int)));
408 409
}

Daniel Teske's avatar
Daniel Teske committed
410
void GenericListWidget::setProjectConfigurations(const QList<ProjectConfiguration *> &list, ProjectConfiguration *active)
411
{
Daniel Teske's avatar
Daniel Teske committed
412 413 414 415 416 417 418
    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()));
    }
419 420 421 422

    QFontMetrics fn(font());
    int width = 0;
    foreach (ProjectConfiguration *pc, list) {
Daniel Teske's avatar
Daniel Teske committed
423
        addProjectConfiguration(pc);
424 425 426
        width = qMax(width, fn.width(pc->displayName()) + padding());
    }
    setOptimalWidth(width);
Daniel Teske's avatar
Daniel Teske committed
427
    setActiveProjectConfiguration(active);
428

Daniel Teske's avatar
Daniel Teske committed
429
    m_ignoreIndexChange = false;
430
}
dt's avatar
dt committed
431

Daniel Teske's avatar
Daniel Teske committed
432
void GenericListWidget::setActiveProjectConfiguration(ProjectConfiguration *active)
433
{
Daniel Teske's avatar
Daniel Teske committed
434 435
    QListWidgetItem *item = itemForProjectConfiguration(active);
    setCurrentItem(item);
436 437
}

Daniel Teske's avatar
Daniel Teske committed
438
void GenericListWidget::addProjectConfiguration(ProjectExplorer::ProjectConfiguration *pc)
439
{
Daniel Teske's avatar
Daniel Teske committed
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
    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()));
458 459 460 461 462

    QFontMetrics fn(font());
    int width = fn.width(pc->displayName()) + padding();
    if (width > optimalWidth())
        setOptimalWidth(width);
Daniel Teske's avatar
Daniel Teske committed
463
    m_ignoreIndexChange = false;
464 465
}

Daniel Teske's avatar
Daniel Teske committed
466
void GenericListWidget::removeProjectConfiguration(ProjectExplorer::ProjectConfiguration *pc)
467
{
Daniel Teske's avatar
Daniel Teske committed
468 469 470 471
    m_ignoreIndexChange = true;
    disconnect(pc, SIGNAL(displayNameChanged()),
               this, SLOT(displayNameChanged()));
    delete itemForProjectConfiguration(pc);
472 473 474 475 476 477 478 479 480

    QFontMetrics fn(font());
    int width = 0;
    for (int i = 0; i < count(); ++i) {
        ProjectConfiguration *p = item(i)->data(Qt::UserRole).value<ProjectConfiguration *>();
        width = qMax(width, fn.width(p->displayName()) + padding());
    }
    setOptimalWidth(width);

Daniel Teske's avatar
Daniel Teske committed
481
    m_ignoreIndexChange = false;
482 483
}

Daniel Teske's avatar
Daniel Teske committed
484
void GenericListWidget::rowChanged(int index)
485
{
Daniel Teske's avatar
Daniel Teske committed
486 487 488 489 490
    if (m_ignoreIndexChange)
        return;
    if (index < 0)
        return;
    emit changeActiveProjectConfiguration(item(index)->data(Qt::UserRole).value<ProjectConfiguration *>());
491 492
}

Daniel Teske's avatar
Daniel Teske committed
493
void GenericListWidget::displayNameChanged()
494
{
Daniel Teske's avatar
Daniel Teske committed
495
    m_ignoreIndexChange = true;
496 497 498 499
    ProjectConfiguration *activeProjectConfiguration = 0;
    if (currentItem())
        activeProjectConfiguration = currentItem()->data(Qt::UserRole).value<ProjectConfiguration *>();

Daniel Teske's avatar
Daniel Teske committed
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
    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);
523 524
    if (activeProjectConfiguration)
        setCurrentItem(itemForProjectConfiguration(activeProjectConfiguration));
525 526 527 528 529 530 531 532 533

    QFontMetrics fn(font());
    int width = 0;
    for (int i = 0; i < count(); ++i) {
        ProjectConfiguration *p = item(i)->data(Qt::UserRole).value<ProjectConfiguration *>();
        width = qMax(width, fn.width(p->displayName()) + padding());
    }
    setOptimalWidth(width);

Daniel Teske's avatar
Daniel Teske committed
534
    m_ignoreIndexChange = false;
535 536
}

Daniel Teske's avatar
Daniel Teske committed
537
QListWidgetItem *GenericListWidget::itemForProjectConfiguration(ProjectConfiguration *pc)
538
{
Daniel Teske's avatar
Daniel Teske committed
539 540
    for (int i = 0; i < count(); ++i) {
        QListWidgetItem *lwi = item(i);
541
        if (lwi->data(Qt::UserRole).value<ProjectConfiguration *>() == pc)
Daniel Teske's avatar
Daniel Teske committed
542 543 544
            return lwi;
    }
    return 0;
545 546
}

547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
/////////
// KitAreaWidget
/////////

KitAreaWidget::KitAreaWidget(QWidget *parent) : QWidget(parent),
    m_layout(new QGridLayout(this)), m_kit(0)
{
    m_layout->setMargin(3);
    setKit(0);
}

void KitAreaWidget::setKit(Kit *k)
{
    foreach (KitConfigWidget *w, m_widgets)
        w->deleteLater();
    m_widgets.clear();
    foreach (QLabel *l, m_labels)
        l->deleteLater();
    m_labels.clear();

    if (m_kit) {
        disconnect(KitManager::instance(), SIGNAL(kitUpdated(ProjectExplorer::Kit*)),
                   this, SLOT(updateKit(ProjectExplorer::Kit*)));
    }

    int row = 0;
    foreach (KitInformation *ki, KitManager::kitInformation()) {
        if (k && k->isMutable(ki->id())) {
            KitConfigWidget *widget = ki->createConfigWidget(k);
            m_widgets << widget;
            QLabel *label = new QLabel(widget->displayName());
            m_labels << label;

            m_layout->addWidget(label, row, 0);
            m_layout->addWidget(widget->mainWidget(), row, 1);
            ++row;
        }
    }
    m_kit = k;

    if (m_kit) {
        connect(KitManager::instance(), SIGNAL(kitUpdated(ProjectExplorer::Kit*)),
                this, SLOT(updateKit(ProjectExplorer::Kit*)));
    }

    setHidden(m_widgets.isEmpty());
}

void KitAreaWidget::updateKit(Kit *k)
{
    if (!m_kit || m_kit != k)
        return;

    // Check whether our widgets changed
    bool mustRegenerate = false;
    QList<Core::Id> knownIdList;
    foreach (KitConfigWidget *w, m_widgets)
        knownIdList << w->kitInformationId();

    foreach (KitInformation *ki, KitManager::kitInformation()) {
        Core::Id currentId = ki->id();
        if (m_kit->isMutable(currentId) && !knownIdList.removeOne(currentId)) {
            mustRegenerate = true;
            break;
        }
    }

    if (mustRegenerate || !knownIdList.isEmpty())
        setKit(m_kit);
}

/////////
// MiniProjectTargetSelector
/////////

622
QWidget *MiniProjectTargetSelector::createTitleLabel(const QString &text)
Tobias Hunger's avatar
Tobias Hunger committed
623
{
624
    Utils::StyledBar *bar = new Utils::StyledBar(this);
Daniel Teske's avatar
Daniel Teske committed
625 626
    bar->setSingleRow(true);
    QVBoxLayout *toolLayout = new QVBoxLayout(bar);
627
    toolLayout->setContentsMargins(6, 0, 6, 0);
Daniel Teske's avatar
Daniel Teske committed
628 629 630 631 632 633 634 635 636 637 638 639
    toolLayout->setSpacing(0);

    QLabel *l = new QLabel(text);
    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
640 641
}

642 643
MiniProjectTargetSelector::MiniProjectTargetSelector(QAction *targetSelectorAction, QWidget *parent) :
    QWidget(parent), m_projectAction(targetSelectorAction),
Daniel Teske's avatar
Daniel Teske committed
644 645 646 647 648 649 650
    m_project(0),
    m_target(0),
    m_buildConfiguration(0),
    m_deployConfiguration(0),
    m_runConfiguration(0),
    m_hideOnRelease(false)
{
Lorenz Haas's avatar
Lorenz Haas committed
651
    QPalette p;
Daniel Teske's avatar
Daniel Teske committed
652 653
    p.setColor(QPalette::Text, QColor(255, 255, 255, 160));
    setPalette(p);
654 655
    setProperty("panelwidget", true);
    setContentsMargins(QMargins(0, 1, 1, 8));
656 657 658 659 660
    setWindowFlags(Qt::Popup);

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

661 662
    m_kitAreaWidget = new KitAreaWidget(this);

Daniel Teske's avatar
Daniel Teske committed
663 664 665 666
    m_summaryLabel = new QLabel(this);
    m_summaryLabel->setMargin(3);
    m_summaryLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop);
    m_summaryLabel->setStyleSheet(QString::fromLatin1("background: #464646;"));
667 668
    m_summaryLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
    m_summaryLabel->setTextInteractionFlags(m_summaryLabel->textInteractionFlags() | Qt::LinksAccessibleByMouse);
Daniel Teske's avatar
Daniel Teske committed
669 670 671 672 673 674

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

    m_titleWidgets[PROJECT] = createTitleLabel(tr("Project"));
675
    m_projectListWidget = new ProjectListWidget(this);
Daniel Teske's avatar
Daniel Teske committed
676 677

    QStringList titles;
Tobias Hunger's avatar
Tobias Hunger committed
678
    titles << tr("Kit") << tr("Build")
Daniel Teske's avatar
Daniel Teske committed
679 680 681 682 683 684 685
           << tr("Deploy") << tr("Run");

    for (int i = TARGET; i < LAST; ++i) {
        m_titleWidgets[i] = createTitleLabel(titles.at(i -1));
        m_listWidgets[i] = new GenericListWidget(this);
    }

686 687 688 689
    Project *startup = SessionManager::startupProject();
    changeStartupProject(startup);
    if (startup)
        activeTargetChanged(startup->activeTarget());
Daniel Teske's avatar
Daniel Teske committed
690

691 692 693
    connect(m_summaryLabel, SIGNAL(linkActivated(QString)),
            this, SLOT(switchToProjectsMode()));

694 695
    QObject *sessionManager = SessionManager::instance();
    connect(sessionManager, SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
Daniel Teske's avatar
Daniel Teske committed
696 697
            this, SLOT(changeStartupProject(ProjectExplorer::Project*)));

698
    connect(sessionManager, SIGNAL(projectAdded(ProjectExplorer::Project*)),
Daniel Teske's avatar
Daniel Teske committed
699
            this, SLOT(projectAdded(ProjectExplorer::Project*)));
700
    connect(sessionManager, SIGNAL(projectRemoved(ProjectExplorer::Project*)),
Daniel Teske's avatar
Daniel Teske committed
701
            this, SLOT(projectRemoved(ProjectExplorer::Project*)));
702
    connect(sessionManager, SIGNAL(projectDisplayNameChanged(ProjectExplorer::Project*)),
703
            this, SLOT(updateActionAndSummary()));
Daniel Teske's avatar
Daniel Teske committed
704

Tobias Hunger's avatar
Tobias Hunger committed
705
    // for icon changes:
Tobias Hunger's avatar
Tobias Hunger committed
706 707
    connect(ProjectExplorer::KitManager::instance(), SIGNAL(kitUpdated(ProjectExplorer::Kit*)),
            this, SLOT(kitChanged(ProjectExplorer::Kit*)));
Tobias Hunger's avatar
Tobias Hunger committed
708

Daniel Teske's avatar
Daniel Teske committed
709
    connect(m_listWidgets[TARGET], SIGNAL(changeActiveProjectConfiguration(ProjectExplorer::ProjectConfiguration*)),
Robert Loehning's avatar
Robert Loehning committed
710
            this, SLOT(setActiveTarget(ProjectExplorer::ProjectConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
711
    connect(m_listWidgets[BUILD], SIGNAL(changeActiveProjectConfiguration(ProjectExplorer::ProjectConfiguration*)),
Robert Loehning's avatar
Robert Loehning committed
712
            this, SLOT(setActiveBuildConfiguration(ProjectExplorer::ProjectConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
713
    connect(m_listWidgets[DEPLOY], SIGNAL(changeActiveProjectConfiguration(ProjectExplorer::ProjectConfiguration*)),
Robert Loehning's avatar
Robert Loehning committed
714
            this, SLOT(setActiveDeployConfiguration(ProjectExplorer::ProjectConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
715
    connect(m_listWidgets[RUN], SIGNAL(changeActiveProjectConfiguration(ProjectExplorer::ProjectConfiguration*)),
Robert Loehning's avatar
Robert Loehning committed
716
            this, SLOT(setActiveRunConfiguration(ProjectExplorer::ProjectConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
717
}
718

719 720
bool MiniProjectTargetSelector::event(QEvent *event)
{
721 722 723 724 725 726 727 728 729 730 731
    if (event->type() == QEvent::LayoutRequest) {
        doLayout(true);
        return true;
    } else if (event->type() == QEvent::ShortcutOverride) {
        if (static_cast<QKeyEvent *>(event)->key() == Qt::Key_Escape) {
            event->accept();
            return true;
        }
    }
    return QWidget::event(event);

732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
}

class IndexSorter
{
public:
    enum SortOrder { Less = 0, Greater = 1};

    IndexSorter(QVector<int> result, SortOrder order)
        : m_result(result), m_order(order)
    { }

    bool operator()(int i, int j)
    { return (m_result[i] < m_result[j]) ^ bool(m_order); }

private:
    QVector<int> m_result;
    SortOrder m_order;
};

// does some fancy calculations to ensure proper widths for the list widgets
QVector<int> MiniProjectTargetSelector::listWidgetWidths(int minSize, int maxSize)
{
    QVector<int> result;
    result.resize(LAST);
    if (m_projectListWidget->isVisibleTo(this))
        result[PROJECT] = m_projectListWidget->optimalWidth();
    else
        result[PROJECT] = -1;

    for (int i = TARGET; i < LAST; ++i) {
        if (m_listWidgets[i]->isVisibleTo(this))
            result[i] = m_listWidgets[i]->optimalWidth();
        else
            result[i] = -1;
    }

    int totalWidth = 0;
    // Adjust to minimum width of title
    for (int i = PROJECT; i < LAST; ++i) {
        if (result[i] != -1) {
            // We want at least 100 pixels per column
            int width = qMax(m_titleWidgets[i]->sizeHint().width(), 100);
            if (result[i] < width)
                result[i] = width;
            totalWidth += result[i];
        }
    }

    if (totalWidth == 0) // All hidden
        return result;

    bool tooSmall;
    if (totalWidth < minSize)
        tooSmall = true;
    else if (totalWidth > maxSize)
        tooSmall = false;
    else
        return result;

    int widthToDistribute = tooSmall ? (minSize - totalWidth)
                                     : (totalWidth - maxSize);
    QVector<int> indexes;
    indexes.reserve(LAST);
    for (int i = PROJECT; i < LAST; ++i)
        if (result[i] != -1)
            indexes.append(i);

    IndexSorter indexSorter(result, tooSmall ? IndexSorter::Less : IndexSorter::Greater);
    qSort(indexes.begin(), indexes.end(), indexSorter);

    int i = 0;
    int first = result[indexes.first()]; // biggest or smallest

    // we resize the biggest columns until they are the same size as the second biggest
    // since it looks prettiest if all the columns are the same width
    while (true) {
        for (; i < indexes.size(); ++i) {
            if (result[indexes[i]] != first)
                break;
        }
        int next = tooSmall ? INT_MAX : 0;
        if (i < indexes.size())
            next = result[indexes[i]];

        int delta;
        if (tooSmall)
            delta = qMin(next - first, widthToDistribute / i);
        else
            delta = qMin(first - next, widthToDistribute / i);

        if (delta == 0)
            return result;

        if (tooSmall) {
            for (int j = 0; j < i; ++j)
                result[indexes[j]] += delta;
        } else {
            for (int j = 0; j < i; ++j)
                result[indexes[j]] -= delta;
        }

        widthToDistribute -= delta * i;
        if (widthToDistribute == 0)
            return result;

        first = result[indexes.first()];
        i = 0; // TODO can we do better?
    }
}

void MiniProjectTargetSelector::doLayout(bool keepSize)
{
    // An unconfigured project shows empty build/deploy/run sections
    // if there's a configured project in the seesion
    // that could be improved
    static QStatusBar *statusBar = Core::ICore::statusBar();
    static QWidget *actionBar = Core::ICore::mainWindow()->findChild<QWidget*>(QLatin1String("actionbar"));
    Q_ASSERT(actionBar);

851 852 853 854 855 856
    m_kitAreaWidget->move(0, 0);

    int oldSummaryLabelY = m_summaryLabel->y();

    int kitAreaHeight = m_kitAreaWidget->isVisible() ? m_kitAreaWidget->sizeHint().height() : 0;

857
    // 1. Calculate the summary label height
858 859
    int summaryLabelY = 1 + kitAreaHeight;

860 861 862 863 864 865 866 867 868 869 870 871 872 873
    int summaryLabelHeight = 0;
    int oldSummaryLabelHeight = m_summaryLabel->height();
    bool onlySummary = false;
    // Count the number of lines
    int visibleLineCount = m_projectListWidget->isVisibleTo(this) ? 0 : 1;
    for (int i = TARGET; i < LAST; ++i)
        visibleLineCount += m_listWidgets[i]->isVisibleTo(this) ? 0 : 1;

    if (visibleLineCount == LAST) {
        summaryLabelHeight = visibleLineCount * QFontMetrics(m_summaryLabel->font()).height()
                + m_summaryLabel->margin() *2;
        onlySummary = true;
    } else {
        if (visibleLineCount < 3) {
874
            foreach (Project *p, SessionManager::projects()) {
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891
                if (p->needsConfiguration()) {
                    visibleLineCount = 3;
                    break;
                }
            }
        }
        if (visibleLineCount)
            summaryLabelHeight = visibleLineCount * QFontMetrics(m_summaryLabel->font()).height()
                    + m_summaryLabel->margin() *2;
    }

    if (keepSize && oldSummaryLabelHeight > summaryLabelHeight)
        summaryLabelHeight = oldSummaryLabelHeight;

    m_summaryLabel->move(0, summaryLabelY);

    // Height to be aligned with side bar button
892 893 894
    int alignedWithActionHeight = 210;
    if (actionBar->isVisible())
        alignedWithActionHeight = actionBar->height() - statusBar->height();
895
    int bottomMargin = 9;
896
    int heightWithoutKitArea = 0;
897 898 899 900 901 902 903 904 905

    if (!onlySummary) {
        // list widget heigth
        int maxItemCount = m_projectListWidget->maxCount();
        for (int i = TARGET; i < LAST; ++i)
            maxItemCount = qMax(maxItemCount, m_listWidgets[i]->maxCount());

        int titleWidgetsHeight = m_titleWidgets.first()->height();
        if (keepSize) {
906
            heightWithoutKitArea = height() - oldSummaryLabelY + 1;
907 908 909 910
        } else {
            // Clamp the size of the listwidgets to be
            // at least as high as the the sidebar button
            // and at most twice as high
911 912 913 914
            heightWithoutKitArea = summaryLabelHeight
                    + qBound(alignedWithActionHeight,
                             maxItemCount * 30 + bottomMargin + titleWidgetsHeight,
                             alignedWithActionHeight * 2);
915 916 917 918
        }

        int titleY = summaryLabelY + summaryLabelHeight;
        int listY = titleY + titleWidgetsHeight;
919
        int listHeight = heightWithoutKitArea + kitAreaHeight - bottomMargin - listY + 1;
920 921 922

        // list widget widths
        int minWidth = qMax(m_summaryLabel->sizeHint().width(), 250);
923
        minWidth = qMax(minWidth, m_kitAreaWidget->sizeHint().width());
924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949
        if (keepSize) {
            // Do not make the widget smaller then it was before
            int oldTotalListWidgetWidth = m_projectListWidget->isVisibleTo(this) ?
                    m_projectListWidget->width() : 0;
            for (int i = TARGET; i < LAST; ++i)
                oldTotalListWidgetWidth += m_listWidgets[i]->width();
            minWidth = qMax(minWidth, oldTotalListWidgetWidth);
        }

        QVector<int> widths = listWidgetWidths(minWidth, 1000);
        int x = 0;
        for (int i = PROJECT; i < LAST; ++i) {
            int optimalWidth = widths[i];
            if (i == PROJECT) {
                m_projectListWidget->resize(optimalWidth, listHeight);
                m_projectListWidget->move(x, listY);
            } else {
                m_listWidgets[i]->resize(optimalWidth, listHeight);
                m_listWidgets[i]->move(x, listY);
            }
            m_titleWidgets[i]->resize(optimalWidth, titleWidgetsHeight);
            m_titleWidgets[i]->move(x, titleY);
            x += optimalWidth + 1; //1 extra pixel for the separators or the right border
        }

        m_summaryLabel->resize(x - 1, summaryLabelHeight);
950 951
        m_kitAreaWidget->resize(x - 1, kitAreaHeight);
        setFixedSize(x, heightWithoutKitArea + kitAreaHeight);
952 953
    } else {
        if (keepSize)
954
            heightWithoutKitArea = height() - oldSummaryLabelY + 1;
955
        else
956 957 958 959
            heightWithoutKitArea = qMax(summaryLabelHeight + bottomMargin, alignedWithActionHeight);
        m_summaryLabel->resize(m_summaryLabel->sizeHint().width(), heightWithoutKitArea - bottomMargin);
        m_kitAreaWidget->resize(m_kitAreaWidget->sizeHint());
        setFixedSize(m_summaryLabel->width() + 1, heightWithoutKitArea + kitAreaHeight); //1 extra pixel for the border
960 961 962 963
    }

    if (isVisibleTo(parentWidget())) {
        QPoint moveTo = statusBar->mapToGlobal(QPoint(0,0));
964
        moveTo -= QPoint(0, height());
965 966 967 968
        move(moveTo);
    }
}

Daniel Teske's avatar
Daniel Teske committed
969 970 971 972
void MiniProjectTargetSelector::setActiveTarget(ProjectExplorer::ProjectConfiguration *pc)
{
    m_project->setActiveTarget(static_cast<Target *>(pc));
}
973

Daniel Teske's avatar
Daniel Teske committed
974 975 976 977
void MiniProjectTargetSelector::setActiveBuildConfiguration(ProjectExplorer::ProjectConfiguration *pc)
{
    m_target->setActiveBuildConfiguration(static_cast<BuildConfiguration *>(pc));
}
978

Daniel Teske's avatar
Daniel Teske committed
979 980 981 982 983 984 985 986 987
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));
}
988

Daniel Teske's avatar
Daniel Teske committed
989 990 991
void MiniProjectTargetSelector::projectAdded(ProjectExplorer::Project *project)
{
    connect(project, SIGNAL(addedTarget(ProjectExplorer::Target*)),
992
            this, SLOT(slotAddedTarget(ProjectExplorer::Target*)));
993

Daniel Teske's avatar
Daniel Teske committed
994
    connect(project, SIGNAL(removedTarget(ProjectExplorer::Target*)),
995
            this, SLOT(slotRemovedTarget(ProjectExplorer::Target*)));
996

Daniel Teske's avatar
Daniel Teske committed
997 998
    foreach (Target *t, project->targets())
        addedTarget(t);
999

Daniel Teske's avatar
Daniel Teske committed
1000 1001 1002 1003 1004
    updateProjectListVisible();
    updateTargetListVisible();
    updateBuildListVisible();
    updateDeployListVisible();
    updateRunListVisible();
1005 1006
}

Daniel Teske's avatar
Daniel Teske committed
1007
void MiniProjectTargetSelector::projectRemoved(ProjectExplorer::Project *project)
1008
{
Daniel Teske's avatar
Daniel Teske committed
1009
    disconnect(project, SIGNAL(addedTarget(ProjectExplorer::Target*)),
1010
               this, SLOT(slotAddedTarget(ProjectExplorer::Target*)));
1011

Daniel Teske's avatar
Daniel Teske committed
1012
    disconnect(project, SIGNAL(removedTarget(ProjectExplorer::Target*)),
1013
               this, SLOT(slotRemovedTarget(ProjectExplorer::Target*)));
1014

Daniel Teske's avatar
Daniel Teske committed
1015 1016
    foreach (Target *t, project->targets())
        removedTarget(t);
1017

Daniel Teske's avatar
Daniel Teske committed
1018 1019 1020 1021 1022
    updateProjectListVisible();
    updateTargetListVisible();
    updateBuildListVisible();
    updateDeployListVisible();
    updateRunListVisible();
1023 1024
}

Daniel Teske's avatar
Daniel Teske committed
1025
void MiniProjectTargetSelector::addedTarget(ProjectExplorer::Target *target)
1026
{
Daniel Teske's avatar
Daniel Teske committed
1027
    connect(target, SIGNAL(addedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
1028
            this, SLOT(slotAddedBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
1029
    connect(target, SIGNAL(removedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
1030
            this, SLOT(slotRemovedBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
1031 1032

    connect(target, SIGNAL(addedDeployConfiguration(ProjectExplorer::DeployConfiguration*)),
1033
            this, SLOT(slotAddedDeployConfiguration(ProjectExplorer::DeployConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
1034
    connect(target, SIGNAL(removedDeployConfiguration(ProjectExplorer::DeployConfiguration*)),
1035
            this, SLOT(slotRemovedDeployConfiguration(ProjectExplorer::DeployConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
1036 1037

    connect(target, SIGNAL(addedRunConfiguration(ProjectExplorer::RunConfiguration*)),
1038
            this, SLOT(slotAddedRunConfiguration(ProjectExplorer::RunConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
1039
    connect(target, SIGNAL(removedRunConfiguration(ProjectExplorer::RunConfiguration*)),
1040
            this, SLOT(slotRemovedRunConfiguration(ProjectExplorer::RunConfiguration*)));
Daniel Teske's avatar
Daniel Teske committed
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050

    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);
1051
}
Daniel Teske's avatar
Daniel Teske committed
1052

1053 1054 1055
void MiniProjectTargetSelector::slotAddedTarget(ProjectExplorer::Target *target)
{
    addedTarget(target);
Daniel Teske's avatar
Daniel Teske committed
1056 1057 1058 1059
    updateTargetListVisible();
    updateBuildListVisible();
    updateDeployListVisible();
    updateRunListVisible();
1060 1061
}

Daniel Teske's avatar
Daniel Teske committed
1062
void MiniProjectTargetSelector::removedTarget(ProjectExplorer::Target *target)
1063
{
Daniel Teske's avatar
Daniel Teske committed
1064
    disconnect(target, SIGNAL(addedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
1065
               this, SLOT(slotAddedBuildConfiguration(ProjectExplorer::BuildConfiguration*)));