2010-01-21 21:12:40 +01:00
|
|
|
/********************Q******************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "fancyactionbar.h"
|
2010-02-09 19:05:15 +01:00
|
|
|
#include "coreconstants.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-01-21 21:12:40 +01:00
|
|
|
#include <utils/stylehelper.h>
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/mainwindow.h>
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QHBoxLayout>
|
|
|
|
|
#include <QtGui/QPainter>
|
|
|
|
|
#include <QtGui/QPicture>
|
|
|
|
|
#include <QtGui/QVBoxLayout>
|
2009-08-20 18:44:02 +02:00
|
|
|
#include <QtGui/QAction>
|
2010-01-21 21:12:40 +01:00
|
|
|
#include <QtGui/QStatusBar>
|
|
|
|
|
#include <QtGui/QStyle>
|
|
|
|
|
#include <QtGui/QStyleOption>
|
2010-02-17 17:09:00 +01:00
|
|
|
#include <QtCore/QEvent>
|
|
|
|
|
#include <QtGui/QMouseEvent>
|
|
|
|
|
#include <QtCore/QAnimationGroup>
|
|
|
|
|
#include <QtCore/QPropertyAnimation>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
using namespace Core;
|
|
|
|
|
using namespace Internal;
|
|
|
|
|
|
|
|
|
|
FancyToolButton::FancyToolButton(QWidget *parent)
|
2010-02-17 17:20:31 +01:00
|
|
|
: QToolButton(parent), m_fader(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
setAttribute(Qt::WA_Hover, true);
|
2009-07-13 18:04:08 +02:00
|
|
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-17 17:09:00 +01:00
|
|
|
bool FancyToolButton::event(QEvent *e)
|
|
|
|
|
{
|
|
|
|
|
switch(e->type()) {
|
|
|
|
|
case QEvent::Enter:
|
|
|
|
|
{
|
|
|
|
|
QPropertyAnimation *animation = new QPropertyAnimation(this, "fader");
|
2010-02-17 17:20:31 +01:00
|
|
|
animation->setDuration(125);
|
2010-02-17 17:09:00 +01:00
|
|
|
animation->setEndValue(1.0);
|
|
|
|
|
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case QEvent::Leave:
|
|
|
|
|
{
|
|
|
|
|
QPropertyAnimation *animation = new QPropertyAnimation(this, "fader");
|
2010-02-17 17:20:31 +01:00
|
|
|
animation->setDuration(125);
|
2010-02-17 17:09:00 +01:00
|
|
|
animation->setEndValue(0.0);
|
|
|
|
|
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return QToolButton::event(e);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void FancyToolButton::paintEvent(QPaintEvent *event)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(event)
|
2010-01-22 18:04:24 +01:00
|
|
|
QPainter painter(this);
|
2010-01-21 21:12:40 +01:00
|
|
|
|
2010-01-22 18:04:24 +01:00
|
|
|
// draw borders
|
2010-01-21 21:12:40 +01:00
|
|
|
bool isTitledAction = defaultAction()->property("titledAction").toBool();
|
|
|
|
|
|
2009-06-03 20:45:49 +02:00
|
|
|
#ifndef Q_WS_MAC // Mac UIs usually don't hover
|
2010-02-18 12:50:26 +01:00
|
|
|
if (m_fader > 0 && isEnabled() && !isDown() && !isChecked()) {
|
2010-02-17 17:09:00 +01:00
|
|
|
painter.save();
|
2010-02-18 12:50:26 +01:00
|
|
|
int fader = int(40 * m_fader);
|
|
|
|
|
QLinearGradient grad(rect().topLeft(), rect().topRight());
|
|
|
|
|
grad.setColorAt(0, Qt::transparent);
|
|
|
|
|
grad.setColorAt(0.5, QColor(255, 255, 255, fader));
|
|
|
|
|
grad.setColorAt(1, Qt::transparent);
|
|
|
|
|
painter.fillRect(rect(), grad);
|
|
|
|
|
painter.setPen(QPen(grad, 1.0));
|
|
|
|
|
painter.drawLine(rect().topLeft(), rect().topRight());
|
|
|
|
|
painter.drawLine(rect().bottomLeft(), rect().bottomRight());
|
2010-02-17 17:09:00 +01:00
|
|
|
painter.restore();
|
2010-02-18 12:50:26 +01:00
|
|
|
} else
|
2010-02-24 19:54:35 +01:00
|
|
|
#endif
|
2010-02-17 17:09:00 +01:00
|
|
|
if (isDown() || isChecked()) {
|
|
|
|
|
painter.save();
|
2010-02-18 12:50:26 +01:00
|
|
|
QLinearGradient grad(rect().topLeft(), rect().topRight());
|
|
|
|
|
grad.setColorAt(0, Qt::transparent);
|
|
|
|
|
grad.setColorAt(0.5, QColor(0, 0, 0, 50));
|
|
|
|
|
grad.setColorAt(1, Qt::transparent);
|
|
|
|
|
painter.fillRect(rect(), grad);
|
|
|
|
|
painter.setPen(QPen(grad, 1.0));
|
|
|
|
|
painter.drawLine(rect().topLeft(), rect().topRight());
|
|
|
|
|
painter.drawLine(rect().topLeft(), rect().topRight());
|
|
|
|
|
painter.drawLine(rect().topLeft() + QPoint(0,1), rect().topRight() + QPoint(0,1));
|
|
|
|
|
painter.drawLine(rect().bottomLeft(), rect().bottomRight());
|
|
|
|
|
painter.drawLine(rect().bottomLeft(), rect().bottomRight());
|
|
|
|
|
painter.drawLine(rect().topLeft() - QPoint(0,1), rect().topRight() - QPoint(0,1));
|
2010-02-17 17:09:00 +01:00
|
|
|
painter.restore();
|
2010-01-21 21:12:40 +01:00
|
|
|
}
|
2010-01-22 18:04:24 +01:00
|
|
|
QPixmap borderPixmap;
|
|
|
|
|
QMargins margins;
|
2010-01-21 21:12:40 +01:00
|
|
|
|
2010-02-09 19:05:15 +01:00
|
|
|
QPixmap pix = icon().pixmap(Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE, isEnabled() ? QIcon::Normal : QIcon::Disabled);
|
2010-01-22 18:04:24 +01:00
|
|
|
QPoint center = rect().center();
|
|
|
|
|
QSizeF halfPixSize = pix.size()/2.0;
|
2010-01-21 21:12:40 +01:00
|
|
|
|
2010-01-22 18:04:24 +01:00
|
|
|
painter.drawPixmap(center-QPointF(halfPixSize.width()-1, halfPixSize.height()-1), pix);
|
|
|
|
|
// draw popup texts
|
2010-01-21 21:12:40 +01:00
|
|
|
if (isTitledAction) {
|
2010-01-22 18:04:24 +01:00
|
|
|
QFont normalFont(painter.font());
|
|
|
|
|
normalFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize());
|
|
|
|
|
QFont boldFont(normalFont);
|
|
|
|
|
boldFont.setBold(true);
|
|
|
|
|
QFontMetrics fm(normalFont);
|
|
|
|
|
QFontMetrics boldFm(boldFont);
|
|
|
|
|
int lineHeight = boldFm.height();
|
|
|
|
|
|
|
|
|
|
int textFlags = Qt::AlignVCenter|Qt::AlignHCenter;
|
|
|
|
|
|
|
|
|
|
painter.setFont(normalFont);
|
|
|
|
|
|
|
|
|
|
QPoint textOffset = center - QPoint(pix.rect().width()/2, pix.rect().height()/2);
|
|
|
|
|
textOffset = textOffset - QPoint(0, lineHeight+5);
|
|
|
|
|
QRectF r(0, textOffset.y(), rect().width(), lineHeight);
|
2010-01-21 21:12:40 +01:00
|
|
|
QColor penColor;
|
|
|
|
|
if (isEnabled())
|
|
|
|
|
penColor = Qt::white;
|
|
|
|
|
else
|
|
|
|
|
penColor = Qt::gray;
|
2010-01-22 18:04:24 +01:00
|
|
|
painter.setPen(penColor);
|
2010-01-21 21:12:40 +01:00
|
|
|
const QString projectName = defaultAction()->property("heading").toString();
|
2010-02-24 19:54:35 +01:00
|
|
|
QString ellidedProjectName = fm.elidedText(projectName, Qt::ElideMiddle, r.width() - 6);
|
2010-01-21 21:12:40 +01:00
|
|
|
if (isEnabled()) {
|
2010-01-22 18:04:24 +01:00
|
|
|
const QRectF shadowR = r.translated(0, 1);
|
|
|
|
|
painter.setPen(QColor(30, 30, 30, 80));
|
|
|
|
|
painter.drawText(shadowR, textFlags, ellidedProjectName);
|
|
|
|
|
painter.setPen(penColor);
|
2010-01-21 21:12:40 +01:00
|
|
|
}
|
2010-01-22 18:04:24 +01:00
|
|
|
painter.drawText(r, textFlags, ellidedProjectName);
|
|
|
|
|
textOffset = center + QPoint(pix.rect().width()/2, pix.rect().height()/2);
|
|
|
|
|
r = QRectF(0, textOffset.y()+5, rect().width(), lineHeight);
|
2010-01-21 21:12:40 +01:00
|
|
|
const QString buildConfiguration = defaultAction()->property("subtitle").toString();
|
2010-01-22 18:04:24 +01:00
|
|
|
painter.setFont(boldFont);
|
|
|
|
|
QString ellidedBuildConfiguration = boldFm.elidedText(buildConfiguration, Qt::ElideMiddle, r.width());
|
2010-01-21 21:12:40 +01:00
|
|
|
if (isEnabled()) {
|
2010-01-22 18:04:24 +01:00
|
|
|
const QRectF shadowR = r.translated(0, 1);
|
|
|
|
|
painter.setPen(QColor(30, 30, 30, 80));
|
|
|
|
|
painter.drawText(shadowR, textFlags, ellidedBuildConfiguration);
|
|
|
|
|
painter.setPen(penColor);
|
2010-01-21 21:12:40 +01:00
|
|
|
}
|
2010-01-22 18:04:24 +01:00
|
|
|
painter.drawText(r, textFlags, ellidedBuildConfiguration);
|
2010-02-17 17:09:00 +01:00
|
|
|
QStyleOption opt;
|
|
|
|
|
opt.initFrom(this);
|
2010-02-26 16:12:10 +01:00
|
|
|
opt.rect = rect().adjusted(rect().width() - 16, 0, -8, 0);
|
2010-02-17 17:09:00 +01:00
|
|
|
Utils::StyleHelper::drawArrow(QStyle::PE_IndicatorArrowRight, &painter, &opt);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-02-18 12:50:26 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FancyActionBar::paintEvent(QPaintEvent *event)
|
|
|
|
|
{
|
2010-02-17 17:09:00 +01:00
|
|
|
QPainter painter(this);
|
2008-12-02 12:01:29 +01:00
|
|
|
Q_UNUSED(event)
|
2010-02-18 11:41:58 +01:00
|
|
|
QColor light = Utils::StyleHelper::sidebarHighlight();
|
|
|
|
|
QColor dark = Utils::StyleHelper::sidebarShadow();
|
2010-02-17 17:09:00 +01:00
|
|
|
painter.setPen(dark);
|
|
|
|
|
painter.drawLine(rect().topLeft(), rect().topRight());
|
|
|
|
|
painter.setPen(light);
|
2010-02-19 18:05:42 +01:00
|
|
|
painter.drawLine(rect().topLeft() + QPoint(1,1), rect().topRight() + QPoint(0,1));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-02-17 17:09:00 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QSize FancyToolButton::sizeHint() const
|
|
|
|
|
{
|
2010-02-17 17:09:00 +01:00
|
|
|
QSizeF buttonSize = iconSize().expandedTo(QSize(64, 36));
|
2010-01-21 21:12:40 +01:00
|
|
|
if (defaultAction()->property("titledAction").toBool()) {
|
2010-01-22 18:04:24 +01:00
|
|
|
QFont boldFont(font());
|
|
|
|
|
boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize());
|
|
|
|
|
boldFont.setBold(true);
|
|
|
|
|
QFontMetrics fm(boldFont);
|
|
|
|
|
qreal lineHeight = fm.height();
|
|
|
|
|
buttonSize += QSizeF(0, (lineHeight*3.5));
|
2010-01-21 21:12:40 +01:00
|
|
|
}
|
2010-01-22 18:04:24 +01:00
|
|
|
return buttonSize.toSize();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-07-13 18:04:08 +02:00
|
|
|
QSize FancyToolButton::minimumSizeHint() const
|
|
|
|
|
{
|
|
|
|
|
return QSize(8, 8);
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-16 15:50:52 +02:00
|
|
|
void FancyToolButton::actionChanged()
|
|
|
|
|
{
|
|
|
|
|
// the default action changed in some way, e.g. it might got hidden
|
|
|
|
|
// since we inherit a tool button we won't get invisible, so do this here
|
|
|
|
|
if (QAction* action = defaultAction())
|
|
|
|
|
setVisible(action->isVisible());
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
FancyActionBar::FancyActionBar(QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
{
|
2010-02-24 19:23:40 +01:00
|
|
|
setObjectName(QString::fromUtf8("actionbar"));
|
2008-12-02 12:01:29 +01:00
|
|
|
m_actionsLayout = new QVBoxLayout;
|
2010-01-21 21:12:40 +01:00
|
|
|
QVBoxLayout *spacerLayout = new QVBoxLayout;
|
|
|
|
|
spacerLayout->addLayout(m_actionsLayout);
|
|
|
|
|
int sbh = ICore::instance()->statusBar()->height();
|
|
|
|
|
spacerLayout->addSpacing(sbh);
|
|
|
|
|
spacerLayout->setMargin(0);
|
|
|
|
|
spacerLayout->setSpacing(0);
|
2010-02-17 17:09:00 +01:00
|
|
|
setLayout(spacerLayout);
|
|
|
|
|
setContentsMargins(0,2,0,0);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-21 21:12:40 +01:00
|
|
|
void FancyActionBar::addProjectSelector(QAction *action)
|
|
|
|
|
{
|
|
|
|
|
FancyToolButton* toolButton = new FancyToolButton(this);
|
|
|
|
|
toolButton->setDefaultAction(action);
|
|
|
|
|
connect(action, SIGNAL(changed()), toolButton, SLOT(actionChanged()));
|
|
|
|
|
m_actionsLayout->insertWidget(0, toolButton);
|
|
|
|
|
|
|
|
|
|
}
|
2010-01-22 18:04:24 +01:00
|
|
|
void FancyActionBar::insertAction(int index, QAction *action)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
FancyToolButton *toolButton = new FancyToolButton(this);
|
|
|
|
|
toolButton->setDefaultAction(action);
|
2009-10-16 15:50:52 +02:00
|
|
|
connect(action, SIGNAL(changed()), toolButton, SLOT(actionChanged()));
|
2008-12-02 12:01:29 +01:00
|
|
|
m_actionsLayout->insertWidget(index, toolButton);
|
|
|
|
|
}
|
2009-08-20 18:44:02 +02:00
|
|
|
|
2010-01-21 21:12:40 +01:00
|
|
|
QLayout *FancyActionBar::actionsLayout() const
|
|
|
|
|
{
|
|
|
|
|
return m_actionsLayout;
|
|
|
|
|
}
|