ProjectWindow update

* Indent widgets using contentsmargins. That way the individual
   widgets can override this.
 * Remove spme spacers in favour of yet more contents margins.
 * Remove unused headers and forward declarations.
 * Define some constants for spacings we might want to tweak later on.

Reviewed-by: dt
This commit is contained in:
Tobias Hunger
2009-11-30 16:23:28 +01:00
parent 7d50367ba4
commit 7ebf60dce2
2 changed files with 82 additions and 82 deletions

View File

@@ -44,28 +44,28 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/ifile.h> #include <coreplugin/ifile.h>
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <utils/qtcassert.h>
#include <utils/styledbar.h> #include <utils/styledbar.h>
#include <utils/stylehelper.h> #include <utils/stylehelper.h>
#include <QtCore/QDebug>
#include <QtGui/QApplication> #include <QtGui/QApplication>
#include <QtGui/QBoxLayout> #include <QtGui/QBoxLayout>
#include <QtGui/QComboBox> #include <QtGui/QComboBox>
#include <QtGui/QScrollArea> #include <QtGui/QScrollArea>
#include <QtGui/QTabWidget>
#include <QtGui/QTreeWidget>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel> #include <QtGui/QLabel>
#include <QtGui/QPainter> #include <QtGui/QPainter>
#include <QtGui/QPaintEvent> #include <QtGui/QPaintEvent>
#include <QtGui/QMenu> #include <QtGui/QMenu>
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal; using namespace ProjectExplorer::Internal;
namespace { namespace {
const int ICON_SIZE(64); const int ICON_SIZE(64);
const int ABOVE_HEADING_MARGIN(10);
const int ABOVE_CONTENTS_MARGIN(4);
const int BELOW_CONTENTS_MARGIN(16);
} }
/// ///
@@ -84,8 +84,9 @@ public:
} }
void paintEvent(QPaintEvent *e) void paintEvent(QPaintEvent *e)
{ {
Q_UNUSED(e);
QPainter p(this); QPainter p(this);
p.fillRect(e->rect(), QBrush(Utils::StyleHelper::borderColor())); p.fillRect(contentsRect(), QBrush(Utils::StyleHelper::borderColor()));
} }
}; };
@@ -94,7 +95,7 @@ public:
/// ///
PanelsWidget::Panel::Panel(QWidget * w) : PanelsWidget::Panel::Panel(QWidget * w) :
iconLabel(0), lineWidget(0), nameLabel(0), panelWidget(w), spacer(0) iconLabel(0), lineWidget(0), nameLabel(0), panelWidget(w)
{ } { }
PanelsWidget::Panel::~Panel() PanelsWidget::Panel::~Panel()
@@ -103,7 +104,6 @@ PanelsWidget::Panel::~Panel()
delete lineWidget; delete lineWidget;
delete nameLabel; delete nameLabel;
// do not delete panelWidget, we do not own it! // do not delete panelWidget, we do not own it!
delete spacer;
} }
/// ///
@@ -118,16 +118,10 @@ PanelsWidget::PanelsWidget(QWidget *parent) :
// side of the screen. // side of the screen.
m_root->setMaximumWidth(800); m_root->setMaximumWidth(800);
// The layout holding the individual panels: // The layout holding the individual panels:
m_layout = new QGridLayout; m_layout = new QGridLayout(m_root);
m_layout->setColumnMinimumWidth(0, ICON_SIZE); m_layout->setColumnMinimumWidth(0, ICON_SIZE + 4);
m_layout->setSpacing(0);
// A helper layout to glue some stretch to the button of m_layout->setRowStretch(0, 10);
// the panel layout:
QVBoxLayout * vbox = new QVBoxLayout;
vbox->addLayout(m_layout);
vbox->addStretch(10);
m_root->setLayout(vbox);
// Add horizontal space to the left of our widget: // Add horizontal space to the left of our widget:
QHBoxLayout *hbox = new QHBoxLayout; QHBoxLayout *hbox = new QHBoxLayout;
@@ -155,15 +149,17 @@ PanelsWidget::~PanelsWidget()
* Add a widget into the grid layout of the PanelsWidget. * Add a widget into the grid layout of the PanelsWidget.
* *
* ... * ...
* +--------+-------------------------------------------+ * +--------+-------------------------------------------+ ABOVE_CONTENTS_MARGIN
* | | widget | * | widget (with contentsmargins adjusted!) |
* +--------+-------------------------------------------+ * +--------+-------------------------------------------+ BELOW_CONTENTS_MARGIN
*/ */
void PanelsWidget::addWidget(QWidget *widget) void PanelsWidget::addWidget(QWidget *widget)
{ {
Panel *p = new Panel(widget); QTC_ASSERT(widget, return);
m_layout->addWidget(widget, m_layout->rowCount(), 1);
m_panels.append(p); const int row(m_layout->rowCount() - 1);
m_layout->setRowStretch(row, 0);
addPanelWidget(new Panel(widget), row);
} }
/* /*
@@ -171,52 +167,49 @@ void PanelsWidget::addWidget(QWidget *widget)
* layout of the PanelsWidget. * layout of the PanelsWidget.
* *
* ... * ...
* +--------+-------------------------------------------+ * +--------+-------------------------------------------+ ABOVE_HEADING_MARGIN
* | | spacer |
* +--------+-------------------------------------------+
* | icon | name | * | icon | name |
* + +-------------------------------------------+ * + +-------------------------------------------+
* | | Line | * | | line |
* + +-------------------------------------------+ * +--------+-------------------------------------------+ ABOVE_CONTENTS_MARGIN
* | | widget | * | widget (with contentsmargins adjusted!) |
* +--------+-------------------------------------------+ * +--------+-------------------------------------------+ BELOW_CONTENTS_MARGIN
*/ */
void PanelsWidget::addWidget(const QString &name, QWidget *widget, const QIcon & icon) void PanelsWidget::addWidget(const QString &name, QWidget *widget, const QIcon & icon)
{ {
QTC_ASSERT(widget, return);
Panel *p = new Panel(widget); Panel *p = new Panel(widget);
// spacer:
const int spacerRow(m_layout->rowCount());
p->spacer = new QSpacerItem(1, 10, QSizePolicy::Fixed, QSizePolicy::Fixed);
m_layout->addItem(p->spacer, spacerRow, 1);
// icon: // icon:
const int headerRow(spacerRow + 1); const int headerRow(m_layout->rowCount() - 1);
m_layout->setRowStretch(headerRow, 0);
if (!icon.isNull()) { if (!icon.isNull()) {
p->iconLabel = new QLabel(m_root); p->iconLabel = new QLabel(m_root);
p->iconLabel->setPixmap(icon.pixmap(ICON_SIZE, ICON_SIZE)); p->iconLabel->setPixmap(icon.pixmap(ICON_SIZE, ICON_SIZE));
m_layout->addWidget(p->iconLabel, headerRow, 0, 3, 1, Qt::AlignTop | Qt::AlignHCenter); p->iconLabel->setContentsMargins(0, ABOVE_HEADING_MARGIN, 0, 0);
m_layout->addWidget(p->iconLabel, headerRow, 0, 2, 1, Qt::AlignTop | Qt::AlignHCenter);
} }
// name: // name:
p->nameLabel = new QLabel(m_root); p->nameLabel = new QLabel(m_root);
p->nameLabel->setText(name); p->nameLabel->setText(name);
p->nameLabel->setContentsMargins(0, ABOVE_HEADING_MARGIN, 0, 0);
QFont f = p->nameLabel->font(); QFont f = p->nameLabel->font();
f.setBold(true); f.setBold(true);
f.setPointSizeF(f.pointSizeF() * 1.4); f.setPointSizeF(f.pointSizeF() * 1.4);
p->nameLabel->setFont(f); p->nameLabel->setFont(f);
m_layout->addWidget(p->nameLabel, headerRow, 1); m_layout->addWidget(p->nameLabel, headerRow, 1, 1, 1, Qt::AlignBottom | Qt::AlignLeft);
// line: // line:
const int lineRow(headerRow + 1); const int lineRow(headerRow + 1);
p->lineWidget = new OnePixelBlackLine(m_root); p->lineWidget = new OnePixelBlackLine(m_root);
m_layout->addWidget(p->lineWidget, lineRow, 1); m_layout->addWidget(p->lineWidget, lineRow, 1);
// widget: // add the widget:
const int widgetRow(lineRow + 1); const int widgetRow(lineRow + 1);
m_layout->addWidget(p->panelWidget, widgetRow, 1); addPanelWidget(p, widgetRow);
m_panels.append(p);
} }
QWidget *PanelsWidget::rootWidget() const QWidget *PanelsWidget::rootWidget() const
@@ -235,13 +228,24 @@ void PanelsWidget::clear()
m_layout->removeWidget(p->nameLabel); m_layout->removeWidget(p->nameLabel);
if (p->panelWidget) if (p->panelWidget)
m_layout->removeWidget(p->panelWidget); m_layout->removeWidget(p->panelWidget);
if (p->spacer)
m_layout->removeItem(p->spacer);
delete p; delete p;
} }
m_panels.clear(); m_panels.clear();
} }
void PanelsWidget::addPanelWidget(Panel *panel, int row)
{
panel->panelWidget->setContentsMargins(m_layout->columnMinimumWidth(0),
ABOVE_CONTENTS_MARGIN, 0,
BELOW_CONTENTS_MARGIN);
m_layout->addWidget(panel->panelWidget, row, 0, 1, 2);
const int stretchRow(row + 1);
m_layout->setRowStretch(stretchRow, 10);
m_panels.append(panel);
}
//// ////
// ActiveConfigurationWidget // ActiveConfigurationWidget
//// ////
@@ -523,7 +527,7 @@ BuildConfigurationComboBox::BuildConfigurationComboBox(Project *p, QWidget *pare
m_comboBox->setCurrentIndex(index); m_comboBox->setCurrentIndex(index);
// TODO // TODO
// connect(p, SIGNAL(buildConfigurationDisplayNameChanged(ProjectExplorer::BuildConfiguration *)), // connect(p, SIGNAL(buildConfigurationDisplayNameChanged(QString)),
// this, SLOT(nameChanged(ProjectExplorer::BuildConfiguration *))); // this, SLOT(nameChanged(ProjectExplorer::BuildConfiguration *)));
connect(p, SIGNAL(activeBuildConfigurationChanged()), connect(p, SIGNAL(activeBuildConfigurationChanged()),
this, SLOT(activeConfigurationChanged())); this, SLOT(activeConfigurationChanged()));
@@ -542,7 +546,7 @@ BuildConfigurationComboBox::~BuildConfigurationComboBox()
void BuildConfigurationComboBox::nameChanged(BuildConfiguration *bc) void BuildConfigurationComboBox::nameChanged(BuildConfiguration *bc)
{ {
int index = nameToIndex(bc); const int index(buildConfigurationToIndex(bc));
if (index == -1) if (index == -1)
return; return;
const QString &displayName = bc->displayName(); const QString &displayName = bc->displayName();
@@ -551,7 +555,7 @@ void BuildConfigurationComboBox::nameChanged(BuildConfiguration *bc)
m_label->setText(displayName); m_label->setText(displayName);
} }
int BuildConfigurationComboBox::nameToIndex(BuildConfiguration *bc) int BuildConfigurationComboBox::buildConfigurationToIndex(BuildConfiguration *bc)
{ {
for (int i=0; i < m_comboBox->count(); ++i) for (int i=0; i < m_comboBox->count(); ++i)
if (m_comboBox->itemData(i).value<BuildConfiguration *>() == bc) if (m_comboBox->itemData(i).value<BuildConfiguration *>() == bc)
@@ -561,7 +565,7 @@ int BuildConfigurationComboBox::nameToIndex(BuildConfiguration *bc)
void BuildConfigurationComboBox::activeConfigurationChanged() void BuildConfigurationComboBox::activeConfigurationChanged()
{ {
int index = nameToIndex(m_project->activeBuildConfiguration()); const int index(buildConfigurationToIndex(m_project->activeBuildConfiguration()));
if (index == -1) if (index == -1)
return; return;
ignoreIndexChange = true; ignoreIndexChange = true;
@@ -569,8 +573,10 @@ void BuildConfigurationComboBox::activeConfigurationChanged()
ignoreIndexChange = false; ignoreIndexChange = false;
} }
void BuildConfigurationComboBox::addedBuildConfiguration(ProjectExplorer::Project *,BuildConfiguration *bc) void BuildConfigurationComboBox::addedBuildConfiguration(ProjectExplorer::Project *project,
BuildConfiguration *bc)
{ {
Q_UNUSED(project);
ignoreIndexChange = true; ignoreIndexChange = true;
m_comboBox->addItem(bc->displayName(), QVariant::fromValue(bc)); m_comboBox->addItem(bc->displayName(), QVariant::fromValue(bc));
@@ -579,10 +585,14 @@ void BuildConfigurationComboBox::addedBuildConfiguration(ProjectExplorer::Projec
ignoreIndexChange = false; ignoreIndexChange = false;
} }
void BuildConfigurationComboBox::removedBuildConfiguration(ProjectExplorer::Project *, BuildConfiguration *bc) void BuildConfigurationComboBox::removedBuildConfiguration(ProjectExplorer::Project *project,
BuildConfiguration * bc)
{ {
Q_UNUSED(project);
ignoreIndexChange = true; ignoreIndexChange = true;
int index = nameToIndex(bc); const int index(buildConfigurationToIndex(bc));
if (index == -1)
return;
m_comboBox->removeItem(index); m_comboBox->removeItem(index);
if (m_comboBox->count() == 1) { if (m_comboBox->count() == 1) {
m_label->setText(m_comboBox->itemText(0)); m_label->setText(m_comboBox->itemText(0));
@@ -719,19 +729,13 @@ ProjectWindow::ProjectWindow(QWidget *parent)
m_panelsWidget = new PanelsWidget(this); m_panelsWidget = new PanelsWidget(this);
viewLayout->addWidget(m_panelsWidget); viewLayout->addWidget(m_panelsWidget);
// Run and build configuration selection area: // Run and build configuration selection panel:
m_activeConfigurationWidget = new ActiveConfigurationWidget(m_panelsWidget->rootWidget()); m_activeConfigurationWidget = new ActiveConfigurationWidget(m_panelsWidget->rootWidget());
// Spacer and line: // Spacer and line panel:
m_spacerBetween = new QWidget(m_panelsWidget->rootWidget()); m_spacerBetween = new OnePixelBlackLine(m_panelsWidget->rootWidget());
QVBoxLayout *spacerVbox = new QVBoxLayout(m_spacerBetween);
spacerVbox->setMargin(0);
m_spacerBetween->setLayout(spacerVbox);
spacerVbox->addSpacerItem(new QSpacerItem(10, 15, QSizePolicy::Fixed, QSizePolicy::Fixed));
spacerVbox->addWidget(new OnePixelBlackLine(m_spacerBetween));
spacerVbox->addSpacerItem(new QSpacerItem(10, 15, QSizePolicy::Fixed, QSizePolicy::Fixed));
// Project chooser: // Project chooser panel:
m_projectChooser = new QWidget(m_panelsWidget->rootWidget()); m_projectChooser = new QWidget(m_panelsWidget->rootWidget());
QHBoxLayout *hbox = new QHBoxLayout(m_projectChooser); QHBoxLayout *hbox = new QHBoxLayout(m_projectChooser);
hbox->setMargin(0); hbox->setMargin(0);

View File

@@ -30,32 +30,25 @@
#ifndef PROJECTWINDOW_H #ifndef PROJECTWINDOW_H
#define PROJECTWINDOW_H #define PROJECTWINDOW_H
#include <QtGui/QWidget>
#include <QtGui/QScrollArea>
#include <QtGui/QComboBox>
#include <QtCore/QPair> #include <QtCore/QPair>
#include <QtGui/QStackedWidget> #include <QtCore/QMap>
#include <QtGui/QPushButton> #include <QtGui/QComboBox>
#include <QtGui/QToolButton>
#include <QtGui/QLabel> #include <QtGui/QLabel>
#include <QtGui/QPushButton>
#include <QtGui/QScrollArea>
#include <QtGui/QStackedWidget>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QLabel; class QLabel;
class QGridLayout; class QGridLayout;
class QModelIndex;
class QTabWidget;
class QHBoxLayout;
class QComboBox;
class QMenu; class QMenu;
class QSpacerItem;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace ProjectExplorer { namespace ProjectExplorer {
class IPropertiesPanel; class IPropertiesPanel;
class Project; class Project;
class ProjectExplorerPlugin;
class SessionManager;
class BuildConfiguration; class BuildConfiguration;
namespace Internal { namespace Internal {
@@ -86,10 +79,11 @@ private:
QWidget *lineWidget; QWidget *lineWidget;
QLabel *nameLabel; QLabel *nameLabel;
QWidget *panelWidget; QWidget *panelWidget;
QSpacerItem *spacer;
}; };
QList<Panel *> m_panels; QList<Panel *> m_panels;
void addPanelWidget(Panel *panel, int row);
QGridLayout *m_layout; QGridLayout *m_layout;
QWidget *m_root; QWidget *m_root;
}; };
@@ -101,13 +95,15 @@ public:
BuildConfigurationComboBox(ProjectExplorer::Project *p, QWidget *parent = 0); BuildConfigurationComboBox(ProjectExplorer::Project *p, QWidget *parent = 0);
~BuildConfigurationComboBox(); ~BuildConfigurationComboBox();
private slots: private slots:
void nameChanged(ProjectExplorer::BuildConfiguration *bc); void nameChanged(BuildConfiguration *bc);
void activeConfigurationChanged(); void activeConfigurationChanged();
void addedBuildConfiguration(ProjectExplorer::Project *, ProjectExplorer::BuildConfiguration *bc); void addedBuildConfiguration(ProjectExplorer::Project *project,
void removedBuildConfiguration(ProjectExplorer::Project *, ProjectExplorer::BuildConfiguration *bc); BuildConfiguration *bc);
void removedBuildConfiguration(ProjectExplorer::Project *project,
BuildConfiguration *bc);
void changedIndex(int newIndex); void changedIndex(int newIndex);
private: private:
int nameToIndex(ProjectExplorer::BuildConfiguration *bc); int buildConfigurationToIndex(BuildConfiguration *bc);
bool ignoreIndexChange; bool ignoreIndexChange;
ProjectExplorer::Project *m_project; ProjectExplorer::Project *m_project;
QComboBox *m_comboBox; QComboBox *m_comboBox;