miniprojecttargetselector.cpp 18.6 KB
Newer Older
Tobias Hunger's avatar
Tobias Hunger committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "miniprojecttargetselector.h"

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

#include <coreplugin/icore.h>
#include <coreplugin/mainwindow.h>

#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <projectexplorer/project.h>
#include <projectexplorer/runconfiguration.h>
#include <projectexplorer/buildconfiguration.h>

#include <QtGui/QLayout>
#include <QtGui/QFormLayout>
#include <QtGui/QLabel>
#include <QtGui/QComboBox>
#include <QtGui/QListWidget>
#include <QtGui/QStatusBar>
#include <QtGui/QStackedWidget>
Tobias Hunger's avatar
Tobias Hunger committed
52
#include <QtGui/QKeyEvent>
53

Tobias Hunger's avatar
Tobias Hunger committed
54
#include <QtGui/QApplication>
55
56
57
58

using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;

Tobias Hunger's avatar
Tobias Hunger committed
59
60
61
62
63
64
65
66
67
68
69
70
ProjectListWidget::ProjectListWidget(ProjectExplorer::Project *project, QWidget *parent)
    : QListWidget(parent), m_project(project)
{
    setFocusPolicy(Qt::NoFocus);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setAlternatingRowColors(false);
    setFocusPolicy(Qt::WheelFocus);

    connect(this, SIGNAL(currentRowChanged(int)), SLOT(setTarget(int)));
}

ProjectExplorer::Project *ProjectListWidget::project() const
71
{
Tobias Hunger's avatar
Tobias Hunger committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
    return m_project;
}

QSize ProjectListWidget::sizeHint() const
{
    int height = 0;
    for (int itemPos = 0; itemPos < count(); ++itemPos)
        height += item(itemPos)->sizeHint().height();

    return QListWidget::sizeHint().expandedTo(QSize(0, height));
}

void ProjectListWidget::setRunComboPopup()
{
    QWidget *w = itemWidget(currentItem());
    MiniTargetWidget *mtw = qobject_cast<MiniTargetWidget*>(w);
    if (mtw->runSettingsComboBox())
        mtw->runSettingsComboBox()->showPopup();
}

void ProjectListWidget::setBuildComboPopup()
{
    QWidget *w = itemWidget(currentItem());
    MiniTargetWidget *mtw = qobject_cast<MiniTargetWidget*>(w);
    if (mtw->buildSettingsComboBox())
        mtw->buildSettingsComboBox()->showPopup();
}

void ProjectListWidget::setTarget(int index)
{
    QList<Target *> targets(m_project->targets());
    if (index >= 0 && index < targets.count())
        m_project->setActiveTarget(targets.at(index));
}

MiniTargetWidget::MiniTargetWidget(Target *target, QWidget *parent) :
    QWidget(parent), m_target(target)
{
    Q_ASSERT(m_target);

    if (hasBuildConfiguration()) {
        m_buildComboBox = new QComboBox;
        m_buildComboBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
        m_buildComboBox->setToolTip(tr("Make active and press 'b' to select."));
    } else {
        m_buildComboBox = 0;
    }
 
120
121
    m_runComboBox = new QComboBox;
    m_runComboBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
Tobias Hunger's avatar
Tobias Hunger committed
122
    m_runComboBox->setToolTip(tr("Make active and press 'r' to select."));
123
124

    int fontSize = font().pointSize();
125
126
127
128
129
130
131
    setStyleSheet(QString::fromLatin1("QWidget { font-size: %1pt; color: white; } "
                                      "QLabel#targetName {  font-size: %2pt; font-weight: bold; } "
                                      "QComboBox { background-color: transparent; margin: 0; border: none; } "
                                      "QComboBox QWidget { background-color: %3;  border: 1px solid lightgrey; } "
                                      "QComboBox::drop-down { border: none; }"
                                      "QComboBox::down-arrow { image: url(:/welcome/images/combobox_arrow.png); } "
                                      ).arg(fontSize-1).arg(fontSize).arg(Utils::StyleHelper::baseColor().name()));
132
133
134

    QGridLayout *gridLayout = new QGridLayout(this);

Tobias Hunger's avatar
Tobias Hunger committed
135
136
    m_targetName = new QLabel(m_target->displayName());
    m_targetName->setObjectName(QLatin1String("target"));
137
    m_targetIcon = new QLabel();
Tobias Hunger's avatar
Tobias Hunger committed
138
139
140
141
142
    m_targetIcon->setPixmap(m_target->icon().pixmap(48, 48));

    if (hasBuildConfiguration()) {
        Q_FOREACH(BuildConfiguration* bc, m_target->buildConfigurations())
                addBuildConfiguration(bc);
143

Tobias Hunger's avatar
Tobias Hunger committed
144
145
146
147
148
149
150
151
152
        connect(m_target, SIGNAL(addedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
                SLOT(addBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
        connect(m_target, SIGNAL(removedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
                SLOT(addBuildConfiguration(ProjectExplorer::BuildConfiguration*)));

        connect(m_target, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
                SLOT(setActiveBuildConfiguration()));
        connect(m_buildComboBox, SIGNAL(currentIndexChanged(int)), SLOT(setActiveBuildConfiguration(int)));
    }
153

Tobias Hunger's avatar
Tobias Hunger committed
154
    Q_FOREACH(RunConfiguration* rc, m_target->runConfigurations())
155
156
            addRunConfiguration(rc);

Tobias Hunger's avatar
Tobias Hunger committed
157
    connect(m_target, SIGNAL(addedRunConfiguration(ProjectExplorer::RunConfiguration*)),
158
            SLOT(addRunConfiguration(ProjectExplorer::RunConfiguration*)));
Tobias Hunger's avatar
Tobias Hunger committed
159
    connect(m_target, SIGNAL(removedRunConfiguration(ProjectExplorer::RunConfiguration*)),
160
161
162
163
            SLOT(removeRunConfiguration(ProjectExplorer::RunConfiguration*)));

    connect(m_runComboBox, SIGNAL(currentIndexChanged(int)), SLOT(setActiveRunConfiguration(int)));

Tobias Hunger's avatar
Tobias Hunger committed
164
165
166
167
168
169
170
171
172
173
    connect(m_target, SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
            SLOT(setActiveRunConfiguration()));

    QHBoxLayout *buildHelperLayout = 0;
    if (hasBuildConfiguration()) {
        buildHelperLayout= new QHBoxLayout;
        buildHelperLayout->setMargin(0);
        buildHelperLayout->setSpacing(0);
        buildHelperLayout->addWidget(m_buildComboBox);
    }
174
175
176
177
178
179
180

    QHBoxLayout *runHelperLayout = new QHBoxLayout;
    runHelperLayout->setMargin(0);
    runHelperLayout->setSpacing(0);
    runHelperLayout->addWidget(m_runComboBox);

    QFormLayout *formLayout = new QFormLayout;
Tobias Hunger's avatar
Tobias Hunger committed
181
182
183
184
185
186
    QLabel *lbl;
    if (hasBuildConfiguration()) {
        lbl = new QLabel(tr("Build:"));
        lbl->setIndent(6);
        formLayout->addRow(lbl, buildHelperLayout);
    }
187
188
189
190
191
192
193
194
195
    lbl = new QLabel(tr("Run:"));
    lbl->setIndent(6);
    formLayout->addRow(lbl, runHelperLayout);

    gridLayout->addWidget(m_targetName, 0, 0);
    gridLayout->addWidget(m_targetIcon, 0, 1, 2, 1, Qt::AlignTop|Qt::AlignHCenter);
    gridLayout->addLayout(formLayout, 1, 0);
}

Tobias Hunger's avatar
Tobias Hunger committed
196
197
198
199
200
ProjectExplorer::Target *MiniTargetWidget::target() const
{
    return m_target;
}

201
202
203
204
void MiniTargetWidget::setActiveBuildConfiguration(int index)
{
    ProjectExplorer::BuildConfiguration* bc =
            m_buildComboBox->itemData(index).value<ProjectExplorer::BuildConfiguration*>();
Tobias Hunger's avatar
Tobias Hunger committed
205
    m_target->setActiveBuildConfiguration(bc);
206
    emit changed();
207
208
209
210
}

void MiniTargetWidget::setActiveRunConfiguration(int index)
{
Tobias Hunger's avatar
Tobias Hunger committed
211
    m_target->setActiveRunConfiguration(
212
            m_runComboBox->itemData(index).value<ProjectExplorer::RunConfiguration*>());
213
    emit changed();
214
215
216
}
void MiniTargetWidget::setActiveBuildConfiguration()
{
Tobias Hunger's avatar
Tobias Hunger committed
217
    QTC_ASSERT(m_buildComboBox, return)
218
    m_buildComboBox->setCurrentIndex(m_buildComboBox->findData(
Tobias Hunger's avatar
Tobias Hunger committed
219
            QVariant::fromValue(m_target->activeBuildConfiguration())));
220
221
222
223
224
}

void MiniTargetWidget::setActiveRunConfiguration()
{
    m_runComboBox->setCurrentIndex(m_runComboBox->findData(
Tobias Hunger's avatar
Tobias Hunger committed
225
            QVariant::fromValue(m_target->activeRunConfiguration())));
226
227
}

Tobias Hunger's avatar
Tobias Hunger committed
228
void MiniTargetWidget::addRunConfiguration(ProjectExplorer::RunConfiguration* rc)
229
{
Tobias Hunger's avatar
Tobias Hunger committed
230
231
232
    connect(rc, SIGNAL(displayNameChanged()), SLOT(updateDisplayName()));
    m_runComboBox->addItem(rc->displayName(), QVariant::fromValue(rc));
    if (m_target->activeRunConfiguration() == rc)
233
234
235
        m_runComboBox->setCurrentIndex(m_runComboBox->count()-1);
}

Tobias Hunger's avatar
Tobias Hunger committed
236
void MiniTargetWidget::removeRunConfiguration(ProjectExplorer::RunConfiguration* rc)
237
{
Tobias Hunger's avatar
Tobias Hunger committed
238
    m_runComboBox->removeItem(m_runComboBox->findData(QVariant::fromValue(rc)));
239
240
}

Tobias Hunger's avatar
Tobias Hunger committed
241
void MiniTargetWidget::addBuildConfiguration(ProjectExplorer::BuildConfiguration* bc)
242
{
Tobias Hunger's avatar
Tobias Hunger committed
243
244
245
246
    QTC_ASSERT(m_buildComboBox, return);
    connect(bc, SIGNAL(displayNameChanged()), SLOT(updateDisplayName()));
    m_buildComboBox->addItem(bc->displayName(), QVariant::fromValue(bc));
    if (m_target->activeBuildConfiguration() == bc)
247
248
249
        m_buildComboBox->setCurrentIndex(m_buildComboBox->count()-1);
}

Tobias Hunger's avatar
Tobias Hunger committed
250
void MiniTargetWidget::removeBuildConfiguration(ProjectExplorer::BuildConfiguration* bc)
251
{
Tobias Hunger's avatar
Tobias Hunger committed
252
253
    QTC_ASSERT(m_buildComboBox, return);
    m_buildComboBox->removeItem(m_buildComboBox->findData(QVariant::fromValue(bc)));
254
255
256
257
258
}

void MiniTargetWidget::updateDisplayName()
{
    QObject *obj = sender();
Tobias Hunger's avatar
Tobias Hunger committed
259
260
261
262
263
264
265
266
    RunConfiguration *rc = qobject_cast<RunConfiguration*>(obj);
    BuildConfiguration *bc = qobject_cast<BuildConfiguration*>(obj);
    if (rc) {
        m_runComboBox->setItemText(m_runComboBox->findData(QVariant::fromValue(rc)),
                                   rc->displayName());
    } else if (bc) {
        m_buildComboBox->setItemText(m_buildComboBox->findData(QVariant::fromValue(bc)),
                                     bc->displayName());
267
    }
268
    emit changed();
269
270
}

Tobias Hunger's avatar
Tobias Hunger committed
271
272
273
274
275
bool MiniTargetWidget::hasBuildConfiguration() const
{
    return (m_target->buildConfigurationFactory() != 0);
}

276
277
278
279
280

MiniProjectTargetSelector::MiniProjectTargetSelector(QAction *targetSelectorAction, QWidget *parent) :
    QWidget(parent), m_projectAction(targetSelectorAction)
{
    setWindowFlags(Qt::Popup);
Tobias Hunger's avatar
Tobias Hunger committed
281
    setFocusPolicy(Qt::WheelFocus);
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302

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

    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->setMargin(0);
    layout->setSpacing(0);

    Utils::StyledBar *bar = new Utils::StyledBar;
    bar->setSingleRow(true);
    layout->addWidget(bar);
    QHBoxLayout *toolLayout = new QHBoxLayout(bar);
    toolLayout->setMargin(0);
    toolLayout->setSpacing(0);

    QLabel *lbl = new QLabel(tr("Project"));
    lbl->setIndent(6);
    QFont f = lbl->font();
    f.setBold(true);
    lbl->setFont(f);
    m_projectsBox = new QComboBox;
Tobias Hunger's avatar
Tobias Hunger committed
303
304
    m_projectsBox->setObjectName(QLatin1String("ProjectsBox"));
    m_projectsBox->setFocusPolicy(Qt::WheelFocus);
305
306
    m_projectsBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
    m_projectsBox->setMaximumWidth(200);
Tobias Hunger's avatar
Tobias Hunger committed
307
    m_projectsBox->installEventFilter(this);
308
309
310
311
312
313

    toolLayout->addWidget(lbl);
    toolLayout->addWidget(new Utils::StyledSeparator);
    toolLayout->addWidget(m_projectsBox);

    m_widgetStack = new QStackedWidget;
Tobias Hunger's avatar
Tobias Hunger committed
314
315
    m_widgetStack->setFocusPolicy(Qt::WheelFocus);
    m_widgetStack->installEventFilter(this);
316
317
    layout->addWidget(m_widgetStack);

Tobias Hunger's avatar
Tobias Hunger committed
318
319
    connect(m_projectsBox, SIGNAL(activated(int)),
            SLOT(emitStartupProjectChanged(int)));
320
321
322
323
324
325
326
327
328
329
330
331
}

void MiniProjectTargetSelector::setVisible(bool visible)
{
    if (visible) {
        resize(sizeHint());
        QStatusBar *statusBar = Core::ICore::instance()->statusBar();
        QPoint moveTo = statusBar->mapToGlobal(QPoint(0,0));
        moveTo -= QPoint(0, sizeHint().height());
        move(moveTo);
    }
    QWidget::setVisible(visible);
Tobias Hunger's avatar
Tobias Hunger committed
332
333
    if (m_widgetStack->currentWidget())
        m_widgetStack->currentWidget()->setFocus();
334
335
336
337
338
339
}

void MiniProjectTargetSelector::addProject(ProjectExplorer::Project* project)
{
    QTC_ASSERT(project, return);
    ProjectListWidget *targetList = new ProjectListWidget(project);
Tobias Hunger's avatar
Tobias Hunger committed
340
    targetList->installEventFilter(this);
341
342
    targetList->setStyleSheet(QString::fromLatin1("QListWidget { background: %1; border: none; }")
                              .arg(Utils::StyleHelper::baseColor().name()));
343
344
345
346
    int pos = m_widgetStack->addWidget(targetList);

    m_projectsBox->addItem(project->displayName(), QVariant::fromValue(project));

Tobias Hunger's avatar
Tobias Hunger committed
347
348
    connect(project, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
            SLOT(updateAction()));
349

Tobias Hunger's avatar
Tobias Hunger committed
350
351
352
353
    connect(project, SIGNAL(addedTarget(ProjectExplorer::Target*)),
            SLOT(addTarget(ProjectExplorer::Target*)));
    connect(project, SIGNAL(removedTarget(ProjectExplorer::Target*)),
            SLOT(removeTarget(ProjectExplorer::Target*)));
354
355
356
357
358

    if (project == ProjectExplorerPlugin::instance()->startupProject()) {
        m_projectsBox->setCurrentIndex(pos);
        m_widgetStack->setCurrentIndex(pos);
    }
Tobias Hunger's avatar
Tobias Hunger committed
359
360
361

    foreach (Target *t, project->targets())
        addTarget(t, t == project->activeTarget());
362
363
364
365
}

void MiniProjectTargetSelector::removeProject(ProjectExplorer::Project* project)
{
Tobias Hunger's avatar
Tobias Hunger committed
366
367
368
369
370
371
    int index = indexFor(project);
    if (index < 0)
        return;
    ProjectListWidget *plw = qobject_cast<ProjectListWidget*>(m_widgetStack->widget(index));
    m_projectsBox->removeItem(index);
    delete plw;
372
373
}

Tobias Hunger's avatar
Tobias Hunger committed
374
375
376
377
378
379
380
381
382
383
384
385
386
void MiniProjectTargetSelector::addTarget(ProjectExplorer::Target *target, bool activeTarget)
{
    QTC_ASSERT(target, return);

    int index = indexFor(target->project());
    if (index < 0)
        return;

    ProjectListWidget *plw = qobject_cast<ProjectListWidget*>(m_widgetStack->widget(index));

    QListWidgetItem *lwi = new QListWidgetItem();
    plw->addItem(lwi);
    MiniTargetWidget *targetWidget = new MiniTargetWidget(target);
387
    connect(targetWidget, SIGNAL(changed()), this, SLOT(updateAction()));
Tobias Hunger's avatar
Tobias Hunger committed
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
    targetWidget->installEventFilter(this);
    if (targetWidget->buildSettingsComboBox())
        targetWidget->buildSettingsComboBox()->installEventFilter(this);
    if (targetWidget->runSettingsComboBox())
        targetWidget->runSettingsComboBox()->installEventFilter(this);
    targetWidget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
    // width==0 size hint to avoid horizontal scrolling in list widget
    lwi->setSizeHint(QSize(0, targetWidget->sizeHint().height()));
    plw->setItemWidget(lwi, targetWidget);

    if (activeTarget)
        plw->setCurrentItem(lwi, QItemSelectionModel::SelectCurrent);
}

void MiniProjectTargetSelector::removeTarget(ProjectExplorer::Target *target)
{
    QTC_ASSERT(target, return);

    int index = indexFor(target->project());
    if (index < 0)
        return;

    ProjectListWidget *plw = qobject_cast<ProjectListWidget*>(m_widgetStack->widget(index));
    for (int i = 0; i < plw->count(); ++i) {
        QListWidgetItem *itm(plw->item(i));
        MiniTargetWidget *mtw(qobject_cast<MiniTargetWidget *>(plw->itemWidget(itm)));
        if (!mtw)
            continue;
        if (target != mtw->target())
            continue;
        delete plw->takeItem(i);
        delete mtw;
    }
}
422
423
424
425
426
427

void MiniProjectTargetSelector::updateAction()
{
    Project *project = ProjectExplorerPlugin::instance()->startupProject();

    QString projectName = tr("No Project");
428
429
430
    QString targetName;
    QString buildConfig;
    QString runConfig;
431
432
433

    if (project) {
        projectName = project->displayName();
Tobias Hunger's avatar
Tobias Hunger committed
434

435
436
437
438
439
        if (Target *target = project->activeTarget()) {
            if (project->targets().count() > 1) {
                targetName = project->activeTarget()->displayName();
            }
            if (BuildConfiguration *bc = target->activeBuildConfiguration()) {
Tobias Hunger's avatar
Tobias Hunger committed
440
                buildConfig = bc->displayName();
441
442
443
444
445
            }

            if (RunConfiguration *rc = target->activeRunConfiguration()) {
                runConfig = rc->displayName();
            }
Tobias Hunger's avatar
Tobias Hunger committed
446
        }
447
448
449
    }
    m_projectAction->setProperty("heading", projectName);
    m_projectAction->setProperty("subtitle", buildConfig);
450
    if (project && project->activeTarget())
Tobias Hunger's avatar
Tobias Hunger committed
451
        m_projectAction->setIcon(project->activeTarget()->icon());
452
453
454
455
456
457
    QString toolTip = tr("<html><b>Project:</b> %1<br/>%2%3<b>Run:</b> %4</html>");
    QString targetTip = targetName.isEmpty() ? QLatin1String("")
        : tr("<b>Target:</b> %1<br/>").arg(targetName);
    QString buildTip = buildConfig.isEmpty() ? QLatin1String("")
        : tr("<b>Build:</b> %2<br/>").arg(buildConfig);
    m_projectAction->setToolTip(toolTip.arg(projectName, targetTip, buildTip, runConfig));
Tobias Hunger's avatar
Tobias Hunger committed
458
459
460
461
462
463
464
465
466
467
}

int MiniProjectTargetSelector::indexFor(ProjectExplorer::Project *project) const
{
    for (int i = 0; i < m_widgetStack->count(); ++i) {
        ProjectListWidget *plw = qobject_cast<ProjectListWidget*>(m_widgetStack->widget(i));
        if (plw && plw->project() == project)
            return i;
    }
    return -1;
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
}

void MiniProjectTargetSelector::emitStartupProjectChanged(int index)
{
    Project *project = m_projectsBox->itemData(index).value<Project*>();
    QTC_ASSERT(project, return;)
    emit startupProjectChanged(project);
}

void MiniProjectTargetSelector::changeStartupProject(ProjectExplorer::Project *project)
{
    for (int i = 0; i < m_widgetStack->count(); ++i) {
        ProjectListWidget *plw = qobject_cast<ProjectListWidget*>(m_widgetStack->widget(i));
        if (plw && plw->project() == project) {
            m_projectsBox->setCurrentIndex(i);
            m_widgetStack->setCurrentIndex(i);
        }
    }
    updateAction();
}
Tobias Hunger's avatar
Tobias Hunger committed
488
489
490
491
492
493
494
495
496
497
498
499
500
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
529
530
531
532

bool MiniProjectTargetSelector::eventFilter(QObject *o, QEvent *ev)
{
    switch(ev->type()) 
    {
    case QEvent::KeyPress: {

        QKeyEvent *kev = static_cast<QKeyEvent*>(ev);

        if (kev->key() == Qt::Key_Tab) {
            if(o == m_projectsBox) {
                if (m_widgetStack->currentWidget())
                    m_widgetStack->currentWidget()->setFocus();
                return true;
            } else {
                m_projectsBox->setFocus();
                return true;
            }
        }

        if (o == m_widgetStack->currentWidget()) {
            if (kev->key() == Qt::Key_Return) {
                hide();
                return true;
            }

            ProjectListWidget *plw = qobject_cast<ProjectListWidget*>(m_widgetStack->currentWidget());
            if (kev->key() == Qt::Key_B)
            {
                plw->setBuildComboPopup();
                return true;
            }
            if (kev->key() == Qt::Key_R)
            {
                plw->setRunComboPopup();
                return true;
            }
        }
    }
    default:
      return false;

    }
    return false;
}