miniprojecttargetselector.h 6.97 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Tobias Hunger's avatar
Tobias Hunger committed
2
**
3
** Copyright (C) 2013 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
** 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.
Tobias Hunger's avatar
Tobias Hunger committed
23
**
hjk's avatar
hjk committed
24 25
** 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 31 32
#ifndef MINIPROJECTTARGETSELECTOR_H
#define MINIPROJECTTARGETSELECTOR_H

33 34
#include <QListWidget>
#include <QDateTime>
35 36 37 38 39 40 41 42

QT_BEGIN_NAMESPACE
class QComboBox;
class QLabel;
class QStackedWidget;
QT_END_NAMESPACE

namespace ProjectExplorer {
Tobias Hunger's avatar
Tobias Hunger committed
43
class Kit;
44
class Project;
Tobias Hunger's avatar
Tobias Hunger committed
45
class Target;
46
class BuildConfiguration;
Daniel Teske's avatar
Daniel Teske committed
47 48 49
class DeployConfiguration;
class ProjectConfiguration;
class RunConfiguration;
50 51 52 53

namespace Internal {

// helper classes
Daniel Teske's avatar
Daniel Teske committed
54
class ListWidget : public QListWidget
55 56 57
{
    Q_OBJECT
public:
Daniel Teske's avatar
Daniel Teske committed
58 59 60 61
    ListWidget(QWidget *parent);
    void keyPressEvent(QKeyEvent *event);
    void keyReleaseEvent(QKeyEvent *event);
    void setMaxCount(int maxCount);
62
    int maxCount();
63

64 65 66 67
    int optimalWidth() const;
    void setOptimalWidth(int width);

    int padding();
Daniel Teske's avatar
Daniel Teske committed
68 69
private:
    int m_maxCount;
70
    int m_optimalWidth;
71 72
};

Daniel Teske's avatar
Daniel Teske committed
73
class ProjectListWidget : public ListWidget
74 75 76
{
    Q_OBJECT
public:
77
    explicit ProjectListWidget(QWidget *parent = 0);
78
private slots:
Daniel Teske's avatar
Daniel Teske committed
79 80
    void addProject(ProjectExplorer::Project *project);
    void removeProject(ProjectExplorer::Project *project);
81
    void projectDisplayNameChanged(ProjectExplorer::Project *project);
Daniel Teske's avatar
Daniel Teske committed
82 83
    void changeStartupProject(ProjectExplorer::Project *project);
    void setProject(int index);
84
private:
Daniel Teske's avatar
Daniel Teske committed
85 86 87 88
    QListWidgetItem *itemForProject(Project *project);
    QString fullName(ProjectExplorer::Project *project);
    bool m_ignoreIndexChange;
};
Tobias Hunger's avatar
Tobias Hunger committed
89

Daniel Teske's avatar
Daniel Teske committed
90 91 92
class GenericListWidget : public ListWidget
{
    Q_OBJECT
Tobias Hunger's avatar
Tobias Hunger committed
93
public:
Daniel Teske's avatar
Daniel Teske committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107
    GenericListWidget(QWidget *parent = 0);
signals:
    void changeActiveProjectConfiguration(ProjectExplorer::ProjectConfiguration *dc);
public:
    void setProjectConfigurations(const QList<ProjectConfiguration *> &list, ProjectConfiguration *active);
    void setActiveProjectConfiguration(ProjectConfiguration *active);
    void addProjectConfiguration(ProjectExplorer::ProjectConfiguration *pc);
    void removeProjectConfiguration(ProjectExplorer::ProjectConfiguration *pc);
private slots:
    void rowChanged(int index);
    void displayNameChanged();
private:
    QListWidgetItem *itemForProjectConfiguration(ProjectConfiguration *pc);
    bool m_ignoreIndexChange;
108 109 110 111 112 113 114
};

// main class
class MiniProjectTargetSelector : public QWidget
{
    Q_OBJECT
public:
115
    explicit MiniProjectTargetSelector(QAction *projectAction, QWidget *parent = 0);
116 117
    void setVisible(bool visible);

118
    void keyPressEvent(QKeyEvent *ke);
Daniel Teske's avatar
Daniel Teske committed
119
    void keyReleaseEvent(QKeyEvent *ke);
120
    bool event(QEvent *event);
Daniel Teske's avatar
Daniel Teske committed
121 122 123
public slots:
    void toggleVisible();
    void nextOrShow();
124 125

private slots:
Daniel Teske's avatar
Daniel Teske committed
126 127
    void projectAdded(ProjectExplorer::Project *project);
    void projectRemoved(ProjectExplorer::Project *project);
128 129 130 131 132 133 134 135
    void slotAddedTarget(ProjectExplorer::Target *target);
    void slotRemovedTarget(ProjectExplorer::Target *target);
    void slotAddedBuildConfiguration(ProjectExplorer::BuildConfiguration *bc);
    void slotRemovedBuildConfiguration(ProjectExplorer::BuildConfiguration *bc);
    void slotAddedDeployConfiguration(ProjectExplorer::DeployConfiguration *dc);
    void slotRemovedDeployConfiguration(ProjectExplorer::DeployConfiguration *dc);
    void slotAddedRunConfiguration(ProjectExplorer::RunConfiguration *rc);
    void slotRemovedRunConfiguration(ProjectExplorer::RunConfiguration *rc);
Daniel Teske's avatar
Daniel Teske committed
136

137
    void changeStartupProject(ProjectExplorer::Project *project);
Daniel Teske's avatar
Daniel Teske committed
138
    void activeTargetChanged(ProjectExplorer::Target *target);
Tobias Hunger's avatar
Tobias Hunger committed
139
    void kitChanged(ProjectExplorer::Kit *k);
Daniel Teske's avatar
Daniel Teske committed
140 141 142 143 144 145 146 147 148 149 150
    void activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration *bc);
    void activeDeployConfigurationChanged(ProjectExplorer::DeployConfiguration *dc);
    void activeRunConfigurationChanged(ProjectExplorer::RunConfiguration *rc);

    void setActiveTarget(ProjectExplorer::ProjectConfiguration *pc);
    void setActiveBuildConfiguration(ProjectExplorer::ProjectConfiguration *pc);
    void setActiveDeployConfiguration(ProjectExplorer::ProjectConfiguration *pc);
    void setActiveRunConfiguration(ProjectExplorer::ProjectConfiguration *pc);

    void delayedHide();
    void updateActionAndSummary();
151
    void switchToProjectsMode();
Daniel Teske's avatar
Daniel Teske committed
152
private:
153 154 155 156 157 158 159 160 161
    void addedTarget(ProjectExplorer::Target *target);
    void removedTarget(ProjectExplorer::Target *target);
    void addedBuildConfiguration(ProjectExplorer::BuildConfiguration* bc);
    void removedBuildConfiguration(ProjectExplorer::BuildConfiguration* bc);
    void addedDeployConfiguration(ProjectExplorer::DeployConfiguration *dc);
    void removedDeployConfiguration(ProjectExplorer::DeployConfiguration *dc);
    void addedRunConfiguration(ProjectExplorer::RunConfiguration *rc);
    void removedRunConfiguration(ProjectExplorer::RunConfiguration *rc);

Daniel Teske's avatar
Daniel Teske committed
162 163 164 165 166 167
    void updateProjectListVisible();
    void updateTargetListVisible();
    void updateBuildListVisible();
    void updateDeployListVisible();
    void updateRunListVisible();
    void updateSummary();
168
    void paintEvent(QPaintEvent *);
169
    void mousePressEvent(QMouseEvent *);
170

171 172 173 174
    void doLayout(bool keepSize);
    QVector<int> listWidgetWidths(int minSize, int maxSize);
    QWidget *createTitleLabel(const QString &text);

175
    QAction *m_projectAction;
Daniel Teske's avatar
Daniel Teske committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189

    enum TYPES { PROJECT = 0, TARGET = 1, BUILD = 2, DEPLOY = 3, RUN = 4, LAST = 5 };
    ProjectListWidget *m_projectListWidget;
    QVector<GenericListWidget *> m_listWidgets;
    QVector<QWidget *> m_titleWidgets;
    QLabel *m_summaryLabel;

    Project *m_project;
    Target *m_target;
    BuildConfiguration *m_buildConfiguration;
    DeployConfiguration *m_deployConfiguration;
    RunConfiguration *m_runConfiguration;
    bool m_hideOnRelease;
    QDateTime m_earliestHidetime;
190 191
};

Tobias Hunger's avatar
Tobias Hunger committed
192 193 194
} // namespace Internal
} // namespace ProjectExplorer

195
#endif // MINIPROJECTTARGETSELECTOR_H