forked from qt-creator/qt-creator
Core: Modernize FancyToolButton and FancyTabWidget
I got much help from clang-tidy, clazy and clang-format. In preparation of QTCREATORBUG-18845 Change-Id: Ie881efd5093d86dc8a345e0a5badd93a6ccecbb9 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -24,24 +24,25 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "fancyactionbar.h"
|
#include "fancyactionbar.h"
|
||||||
|
|
||||||
#include "coreconstants.h"
|
#include "coreconstants.h"
|
||||||
|
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/stylehelper.h>
|
|
||||||
#include <utils/stringutils.h>
|
#include <utils/stringutils.h>
|
||||||
#include <utils/tooltip/tooltip.h>
|
#include <utils/stylehelper.h>
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
|
#include <utils/tooltip/tooltip.h>
|
||||||
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QStyle>
|
#include <QDebug>
|
||||||
#include <QStyleOption>
|
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include <QPainter>
|
||||||
#include <QPixmapCache>
|
#include <QPixmapCache>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QDebug>
|
#include <QStyle>
|
||||||
|
#include <QStyleOption>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
@@ -49,7 +50,7 @@ namespace Core {
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
FancyToolButton::FancyToolButton(QAction *action, QWidget *parent)
|
FancyToolButton::FancyToolButton(QAction *action, QWidget *parent)
|
||||||
: QToolButton(parent), m_fader(0)
|
: QToolButton(parent)
|
||||||
{
|
{
|
||||||
setDefaultAction(action);
|
setDefaultAction(action);
|
||||||
connect(action, &QAction::changed, this, &FancyToolButton::actionChanged);
|
connect(action, &QAction::changed, this, &FancyToolButton::actionChanged);
|
||||||
@@ -62,35 +63,31 @@ FancyToolButton::FancyToolButton(QAction *action, QWidget *parent)
|
|||||||
bool FancyToolButton::event(QEvent *e)
|
bool FancyToolButton::event(QEvent *e)
|
||||||
{
|
{
|
||||||
switch (e->type()) {
|
switch (e->type()) {
|
||||||
case QEvent::Enter:
|
case QEvent::Enter: {
|
||||||
{
|
auto animation = new QPropertyAnimation(this, "fader");
|
||||||
QPropertyAnimation *animation = new QPropertyAnimation(this, "fader");
|
animation->setDuration(125);
|
||||||
animation->setDuration(125);
|
animation->setEndValue(1.0);
|
||||||
animation->setEndValue(1.0);
|
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||||
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
} break;
|
||||||
}
|
case QEvent::Leave: {
|
||||||
break;
|
auto animation = new QPropertyAnimation(this, "fader");
|
||||||
case QEvent::Leave:
|
animation->setDuration(125);
|
||||||
{
|
animation->setEndValue(0.0);
|
||||||
QPropertyAnimation *animation = new QPropertyAnimation(this, "fader");
|
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||||
animation->setDuration(125);
|
} break;
|
||||||
animation->setEndValue(0.0);
|
case QEvent::ToolTip: {
|
||||||
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
auto he = static_cast<QHelpEvent *>(e);
|
||||||
}
|
ToolTip::show(mapToGlobal(he->pos()), toolTip(), this);
|
||||||
break;
|
return true;
|
||||||
case QEvent::ToolTip:
|
|
||||||
{
|
|
||||||
QHelpEvent *he = static_cast<QHelpEvent *>(e);
|
|
||||||
ToolTip::show(mapToGlobal(he->pos()), toolTip(), this);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return QToolButton::event(e);
|
|
||||||
}
|
}
|
||||||
return false;
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return QToolButton::event(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QVector<QString> splitInTwoLines(const QString &text, const QFontMetrics &fontMetrics,
|
static QVector<QString> splitInTwoLines(const QString &text,
|
||||||
|
const QFontMetrics &fontMetrics,
|
||||||
qreal availableWidth)
|
qreal availableWidth)
|
||||||
{
|
{
|
||||||
// split in two lines.
|
// split in two lines.
|
||||||
@@ -98,12 +95,11 @@ static QVector<QString> splitInTwoLines(const QString &text, const QFontMetrics
|
|||||||
// to put them in the second line. First line is drawn with ellipsis,
|
// to put them in the second line. First line is drawn with ellipsis,
|
||||||
// second line gets ellipsis if it couldn't split off full words.
|
// second line gets ellipsis if it couldn't split off full words.
|
||||||
QVector<QString> splitLines(2);
|
QVector<QString> splitLines(2);
|
||||||
QRegExp rx(QLatin1String("\\s+"));
|
const QRegExp rx(QLatin1String("\\s+"));
|
||||||
int splitPos = -1;
|
int splitPos = -1;
|
||||||
int nextSplitPos = text.length();
|
int nextSplitPos = text.length();
|
||||||
do {
|
do {
|
||||||
nextSplitPos = rx.lastIndexIn(text,
|
nextSplitPos = rx.lastIndexIn(text, nextSplitPos - text.length() - 1);
|
||||||
nextSplitPos - text.length() - 1);
|
|
||||||
if (nextSplitPos != -1) {
|
if (nextSplitPos != -1) {
|
||||||
int splitCandidate = nextSplitPos + rx.matchedLength();
|
int splitCandidate = nextSplitPos + rx.matchedLength();
|
||||||
if (fontMetrics.width(text.mid(splitCandidate)) <= availableWidth)
|
if (fontMetrics.width(text.mid(splitCandidate)) <= availableWidth)
|
||||||
@@ -114,8 +110,7 @@ static QVector<QString> splitInTwoLines(const QString &text, const QFontMetrics
|
|||||||
} while (nextSplitPos > 0 && fontMetrics.width(text.left(nextSplitPos)) > availableWidth);
|
} while (nextSplitPos > 0 && fontMetrics.width(text.left(nextSplitPos)) > availableWidth);
|
||||||
// check if we could split at white space at all
|
// check if we could split at white space at all
|
||||||
if (splitPos < 0) {
|
if (splitPos < 0) {
|
||||||
splitLines[0] = fontMetrics.elidedText(text, Qt::ElideRight,
|
splitLines[0] = fontMetrics.elidedText(text, Qt::ElideRight, int(availableWidth));
|
||||||
availableWidth);
|
|
||||||
QString common = Utils::commonPrefix(QStringList({splitLines[0], text}));
|
QString common = Utils::commonPrefix(QStringList({splitLines[0], text}));
|
||||||
splitLines[1] = text.mid(common.length());
|
splitLines[1] = text.mid(common.length());
|
||||||
// elide the second line even if it fits, since it is cut off in mid-word
|
// elide the second line even if it fits, since it is cut off in mid-word
|
||||||
@@ -126,7 +121,9 @@ static QVector<QString> splitInTwoLines(const QString &text, const QFontMetrics
|
|||||||
}
|
}
|
||||||
splitLines[1] = QChar(0x2026) /*'...'*/ + splitLines[1];
|
splitLines[1] = QChar(0x2026) /*'...'*/ + splitLines[1];
|
||||||
} else {
|
} else {
|
||||||
splitLines[0] = fontMetrics.elidedText(text.left(splitPos).trimmed(), Qt::ElideRight, availableWidth);
|
splitLines[0] = fontMetrics.elidedText(text.left(splitPos).trimmed(),
|
||||||
|
Qt::ElideRight,
|
||||||
|
int(availableWidth));
|
||||||
splitLines[1] = text.mid(splitPos);
|
splitLines[1] = text.mid(splitPos);
|
||||||
}
|
}
|
||||||
return splitLines;
|
return splitLines;
|
||||||
@@ -138,11 +135,10 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
|
|||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|
||||||
// draw borders
|
// draw borders
|
||||||
bool isTitledAction = defaultAction()->property("titledAction").toBool();
|
const bool isTitledAction = defaultAction()->property("titledAction").toBool();
|
||||||
|
|
||||||
|
|
||||||
if (!HostOsInfo::isMacHost() // Mac UIs usually don't hover
|
if (!HostOsInfo::isMacHost() // Mac UIs usually don't hover
|
||||||
&& m_fader > 0 && isEnabled() && !isDown() && !isChecked()) {
|
&& m_fader > 0 && isEnabled() && !isDown() && !isChecked()) {
|
||||||
painter.save();
|
painter.save();
|
||||||
if (creatorTheme()->flag(Theme::FlatToolBars)) {
|
if (creatorTheme()->flag(Theme::FlatToolBars)) {
|
||||||
const QColor hoverColor = creatorTheme()->color(Theme::FancyToolButtonHoverColor);
|
const QColor hoverColor = creatorTheme()->color(Theme::FancyToolButtonHoverColor);
|
||||||
@@ -169,79 +165,83 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
|
|||||||
const QRectF borderRectF(QRectF(rect()).adjusted(0.5, 0.5, -0.5, -0.5));
|
const QRectF borderRectF(QRectF(rect()).adjusted(0.5, 0.5, -0.5, -0.5));
|
||||||
painter.drawLine(borderRectF.topLeft(), borderRectF.topRight());
|
painter.drawLine(borderRectF.topLeft(), borderRectF.topRight());
|
||||||
painter.drawLine(borderRectF.topLeft(), borderRectF.topRight());
|
painter.drawLine(borderRectF.topLeft(), borderRectF.topRight());
|
||||||
painter.drawLine(borderRectF.topLeft() + QPointF(0, 1), borderRectF.topRight() + QPointF(0, 1));
|
painter.drawLine(borderRectF.topLeft() + QPointF(0, 1),
|
||||||
|
borderRectF.topRight() + QPointF(0, 1));
|
||||||
painter.drawLine(borderRectF.bottomLeft(), borderRectF.bottomRight());
|
painter.drawLine(borderRectF.bottomLeft(), borderRectF.bottomRight());
|
||||||
painter.drawLine(borderRectF.bottomLeft(), borderRectF.bottomRight());
|
painter.drawLine(borderRectF.bottomLeft(), borderRectF.bottomRight());
|
||||||
}
|
}
|
||||||
painter.restore();
|
painter.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
const QIcon::Mode iconMode = isEnabled() ? ((isDown() || isChecked()) ? QIcon::Active : QIcon::Normal)
|
const QIcon::Mode iconMode = isEnabled()
|
||||||
: QIcon::Disabled;
|
? ((isDown() || isChecked()) ? QIcon::Active : QIcon::Normal)
|
||||||
|
: QIcon::Disabled;
|
||||||
QRect iconRect(0, 0, Constants::MODEBAR_ICON_SIZE, Constants::MODEBAR_ICON_SIZE);
|
QRect iconRect(0, 0, Constants::MODEBAR_ICON_SIZE, Constants::MODEBAR_ICON_SIZE);
|
||||||
// draw popup texts
|
// draw popup texts
|
||||||
if (isTitledAction) {
|
if (isTitledAction) {
|
||||||
|
|
||||||
QFont normalFont(painter.font());
|
QFont normalFont(painter.font());
|
||||||
QRect centerRect = rect();
|
QRect centerRect = rect();
|
||||||
normalFont.setPointSizeF(StyleHelper::sidebarFontSize());
|
normalFont.setPointSizeF(StyleHelper::sidebarFontSize());
|
||||||
QFont boldFont(normalFont);
|
QFont boldFont(normalFont);
|
||||||
boldFont.setBold(true);
|
boldFont.setBold(true);
|
||||||
QFontMetrics fm(normalFont);
|
const QFontMetrics fm(normalFont);
|
||||||
QFontMetrics boldFm(boldFont);
|
const QFontMetrics boldFm(boldFont);
|
||||||
int lineHeight = boldFm.height();
|
const int lineHeight = boldFm.height();
|
||||||
int textFlags = Qt::AlignVCenter|Qt::AlignHCenter;
|
const int textFlags = Qt::AlignVCenter | Qt::AlignHCenter;
|
||||||
|
|
||||||
const QString projectName = defaultAction()->property("heading").toString();
|
const QString projectName = defaultAction()->property("heading").toString();
|
||||||
if (!projectName.isNull())
|
if (!projectName.isNull())
|
||||||
centerRect.adjust(0, lineHeight + 4, 0, 0);
|
centerRect.adjust(0, lineHeight + 4, 0, 0);
|
||||||
|
|
||||||
centerRect.adjust(0, 0, 0, -lineHeight*2 - 4);
|
centerRect.adjust(0, 0, 0, -lineHeight * 2 - 4);
|
||||||
|
|
||||||
iconRect.moveCenter(centerRect.center());
|
iconRect.moveCenter(centerRect.center());
|
||||||
StyleHelper::drawIconWithShadow(icon(), iconRect, &painter, iconMode);
|
StyleHelper::drawIconWithShadow(icon(), iconRect, &painter, iconMode);
|
||||||
painter.setFont(normalFont);
|
painter.setFont(normalFont);
|
||||||
|
|
||||||
QPoint textOffset = centerRect.center() - QPoint(iconRect.width()/2, iconRect.height()/2);
|
QPoint textOffset = centerRect.center()
|
||||||
|
- QPoint(iconRect.width() / 2, iconRect.height() / 2);
|
||||||
textOffset = textOffset - QPoint(0, lineHeight + 3);
|
textOffset = textOffset - QPoint(0, lineHeight + 3);
|
||||||
QRectF r(0, textOffset.y(), rect().width(), lineHeight);
|
const QRectF r(0, textOffset.y(), rect().width(), lineHeight);
|
||||||
painter.setPen(creatorTheme()->color(isEnabled()
|
painter.setPen(creatorTheme()->color(isEnabled() ? Theme::PanelTextColorLight
|
||||||
? Theme::PanelTextColorLight
|
: Theme::IconsDisabledColor));
|
||||||
: Theme::IconsDisabledColor));
|
|
||||||
|
|
||||||
// draw project name
|
// draw project name
|
||||||
const int margin = 6;
|
const int margin = 6;
|
||||||
const qreal availableWidth = r.width() - margin;
|
const qreal availableWidth = r.width() - margin;
|
||||||
QString ellidedProjectName = fm.elidedText(projectName, Qt::ElideMiddle, availableWidth);
|
const QString ellidedProjectName = fm.elidedText(projectName,
|
||||||
|
Qt::ElideMiddle,
|
||||||
|
int(availableWidth));
|
||||||
painter.drawText(r, textFlags, ellidedProjectName);
|
painter.drawText(r, textFlags, ellidedProjectName);
|
||||||
|
|
||||||
// draw build configuration name
|
// draw build configuration name
|
||||||
textOffset = iconRect.center() + QPoint(iconRect.width()/2, iconRect.height()/2);
|
textOffset = iconRect.center() + QPoint(iconRect.width() / 2, iconRect.height() / 2);
|
||||||
QRectF buildConfigRect[2];
|
QRectF buildConfigRect[2];
|
||||||
buildConfigRect[0] = QRectF(0, textOffset.y() + 4, rect().width(), lineHeight);
|
buildConfigRect[0] = QRectF(0, textOffset.y() + 4, rect().width(), lineHeight);
|
||||||
buildConfigRect[1] = QRectF(0, textOffset.y() + 4 + lineHeight, rect().width(), lineHeight);
|
buildConfigRect[1] = QRectF(0, textOffset.y() + 4 + lineHeight, rect().width(), lineHeight);
|
||||||
painter.setFont(boldFont);
|
painter.setFont(boldFont);
|
||||||
QVector<QString> splitBuildConfiguration(2);
|
QVector<QString> splitBuildConfiguration(2);
|
||||||
const QString buildConfiguration = defaultAction()->property("subtitle").toString();
|
const QString buildConfiguration = defaultAction()->property("subtitle").toString();
|
||||||
if (boldFm.width(buildConfiguration) <= availableWidth) {
|
if (boldFm.width(buildConfiguration) <= availableWidth)
|
||||||
// text fits in one line
|
// text fits in one line
|
||||||
splitBuildConfiguration[0] = buildConfiguration;
|
splitBuildConfiguration[0] = buildConfiguration;
|
||||||
} else {
|
else
|
||||||
splitBuildConfiguration = splitInTwoLines(buildConfiguration, boldFm, availableWidth);
|
splitBuildConfiguration = splitInTwoLines(buildConfiguration, boldFm, availableWidth);
|
||||||
}
|
|
||||||
|
|
||||||
// draw the two text lines for the build configuration
|
// draw the two text lines for the build configuration
|
||||||
painter.setPen(creatorTheme()->color(isEnabled()
|
painter.setPen(
|
||||||
// Intentionally using the "Unselected" colors,
|
creatorTheme()->color(isEnabled()
|
||||||
// because the text color won't change in the pressed
|
// Intentionally using the "Unselected" colors,
|
||||||
// state as they would do on the mode buttons.
|
// because the text color won't change in the pressed
|
||||||
? Theme::FancyTabWidgetEnabledUnselectedTextColor
|
// state as they would do on the mode buttons.
|
||||||
: Theme::FancyTabWidgetDisabledUnselectedTextColor));
|
? Theme::FancyTabWidgetEnabledUnselectedTextColor
|
||||||
|
: Theme::FancyTabWidgetDisabledUnselectedTextColor));
|
||||||
|
|
||||||
for (int i = 0; i < 2; ++i) {
|
for (int i = 0; i < 2; ++i) {
|
||||||
if (splitBuildConfiguration[i].isEmpty())
|
const QString &buildConfigText = splitBuildConfiguration[i];
|
||||||
|
if (buildConfigText.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
painter.drawText(buildConfigRect[i], textFlags, splitBuildConfiguration[i]);
|
painter.drawText(buildConfigRect[i], textFlags, buildConfigText);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pop up arrow next to icon
|
// pop up arrow next to icon
|
||||||
@@ -271,7 +271,8 @@ void FancyActionBar::paintEvent(QPaintEvent *event)
|
|||||||
painter.setPen(StyleHelper::sidebarShadow());
|
painter.setPen(StyleHelper::sidebarShadow());
|
||||||
painter.drawLine(borderRect.topLeft(), borderRect.topRight());
|
painter.drawLine(borderRect.topLeft(), borderRect.topRight());
|
||||||
painter.setPen(StyleHelper::sidebarHighlight());
|
painter.setPen(StyleHelper::sidebarHighlight());
|
||||||
painter.drawLine(borderRect.topLeft() + QPointF(1, 1), borderRect.topRight() + QPointF(0, 1));
|
painter.drawLine(borderRect.topLeft() + QPointF(1, 1),
|
||||||
|
borderRect.topRight() + QPointF(0, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,28 +283,28 @@ QSize FancyToolButton::sizeHint() const
|
|||||||
QFont boldFont(font());
|
QFont boldFont(font());
|
||||||
boldFont.setPointSizeF(StyleHelper::sidebarFontSize());
|
boldFont.setPointSizeF(StyleHelper::sidebarFontSize());
|
||||||
boldFont.setBold(true);
|
boldFont.setBold(true);
|
||||||
QFontMetrics fm(boldFont);
|
const QFontMetrics fm(boldFont);
|
||||||
qreal lineHeight = fm.height();
|
const qreal lineHeight = fm.height();
|
||||||
const QString projectName = defaultAction()->property("heading").toString();
|
const QString projectName = defaultAction()->property("heading").toString();
|
||||||
buttonSize += QSizeF(0, 10);
|
buttonSize += QSizeF(0, 10);
|
||||||
if (!projectName.isEmpty())
|
if (!projectName.isEmpty())
|
||||||
buttonSize += QSizeF(0, lineHeight + 2);
|
buttonSize += QSizeF(0, lineHeight + 2);
|
||||||
|
|
||||||
buttonSize += QSizeF(0, lineHeight*2 + 2);
|
buttonSize += QSizeF(0, lineHeight * 2 + 2);
|
||||||
}
|
}
|
||||||
return buttonSize.toSize();
|
return buttonSize.toSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize FancyToolButton::minimumSizeHint() const
|
QSize FancyToolButton::minimumSizeHint() const
|
||||||
{
|
{
|
||||||
return QSize(8, 8);
|
return {8, 8};
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyToolButton::hoverOverlay(QPainter *painter, const QRect &spanRect)
|
void FancyToolButton::hoverOverlay(QPainter *painter, const QRect &spanRect)
|
||||||
{
|
{
|
||||||
const QSize logicalSize = spanRect.size();
|
const QSize logicalSize = spanRect.size();
|
||||||
const QString cacheKey = QLatin1String(Q_FUNC_INFO) + QString::number(logicalSize.width())
|
const QString cacheKey = QLatin1String(Q_FUNC_INFO) + QString::number(logicalSize.width())
|
||||||
+ QLatin1Char('x') + QString::number(logicalSize.height());
|
+ QLatin1Char('x') + QString::number(logicalSize.height());
|
||||||
QPixmap overlay;
|
QPixmap overlay;
|
||||||
if (!QPixmapCache::find(cacheKey, &overlay)) {
|
if (!QPixmapCache::find(cacheKey, &overlay)) {
|
||||||
const int dpr = painter->device()->devicePixelRatio();
|
const int dpr = painter->device()->devicePixelRatio();
|
||||||
@@ -336,29 +337,28 @@ void FancyToolButton::actionChanged()
|
|||||||
{
|
{
|
||||||
// the default action changed in some way, e.g. it might got hidden
|
// 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
|
// since we inherit a tool button we won't get invisible, so do this here
|
||||||
if (QAction* action = defaultAction())
|
if (QAction *action = defaultAction())
|
||||||
setVisible(action->isVisible());
|
setVisible(action->isVisible());
|
||||||
}
|
}
|
||||||
|
|
||||||
FancyActionBar::FancyActionBar(QWidget *parent)
|
FancyActionBar::FancyActionBar(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
setObjectName(QLatin1String("actionbar"));
|
setObjectName("actionbar");
|
||||||
m_actionsLayout = new QVBoxLayout;
|
m_actionsLayout = new QVBoxLayout;
|
||||||
QVBoxLayout *spacerLayout = new QVBoxLayout;
|
auto spacerLayout = new QVBoxLayout;
|
||||||
spacerLayout->addLayout(m_actionsLayout);
|
spacerLayout->addLayout(m_actionsLayout);
|
||||||
int sbh = 8;
|
const int sbh = 8;
|
||||||
spacerLayout->addSpacing(sbh);
|
spacerLayout->addSpacing(sbh);
|
||||||
spacerLayout->setMargin(0);
|
spacerLayout->setMargin(0);
|
||||||
spacerLayout->setSpacing(0);
|
spacerLayout->setSpacing(0);
|
||||||
setLayout(spacerLayout);
|
setLayout(spacerLayout);
|
||||||
setContentsMargins(0,2,0,0);
|
setContentsMargins(0, 2, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyActionBar::addProjectSelector(QAction *action)
|
void FancyActionBar::addProjectSelector(QAction *action)
|
||||||
{
|
{
|
||||||
m_actionsLayout->insertWidget(0, new FancyToolButton(action, this));
|
m_actionsLayout->insertWidget(0, new FancyToolButton(action, this));
|
||||||
|
|
||||||
}
|
}
|
||||||
void FancyActionBar::insertAction(int index, QAction *action)
|
void FancyActionBar::insertAction(int index, QAction *action)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,24 +38,29 @@ class FancyToolButton : public QToolButton
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(float fader READ fader WRITE setFader)
|
Q_PROPERTY(qreal fader READ fader WRITE setFader CONSTANT)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FancyToolButton(QAction *action, QWidget *parent = 0);
|
FancyToolButton(QAction *action, QWidget *parent = nullptr);
|
||||||
|
|
||||||
void paintEvent(QPaintEvent *event);
|
void paintEvent(QPaintEvent *event) override;
|
||||||
bool event(QEvent *e);
|
bool event(QEvent *e) override;
|
||||||
QSize sizeHint() const;
|
QSize sizeHint() const override;
|
||||||
QSize minimumSizeHint() const;
|
QSize minimumSizeHint() const override;
|
||||||
|
|
||||||
float m_fader;
|
qreal fader() const { return m_fader; }
|
||||||
float fader() { return m_fader; }
|
void setFader(qreal value)
|
||||||
void setFader(float value) { m_fader = value; update(); }
|
{
|
||||||
|
m_fader = value;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
static void hoverOverlay(QPainter *painter, const QRect &spanRect);
|
static void hoverOverlay(QPainter *painter, const QRect &spanRect);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void actionChanged();
|
void actionChanged();
|
||||||
|
|
||||||
|
qreal m_fader = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FancyActionBar : public QWidget
|
class FancyActionBar : public QWidget
|
||||||
@@ -63,13 +68,13 @@ class FancyActionBar : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FancyActionBar(QWidget *parent = 0);
|
FancyActionBar(QWidget *parent = nullptr);
|
||||||
|
|
||||||
void paintEvent(QPaintEvent *event);
|
void paintEvent(QPaintEvent *event) override;
|
||||||
void insertAction(int index, QAction *action);
|
void insertAction(int index, QAction *action);
|
||||||
void addProjectSelector(QAction *action);
|
void addProjectSelector(QAction *action);
|
||||||
QLayout *actionsLayout() const;
|
QLayout *actionsLayout() const;
|
||||||
QSize minimumSizeHint() const;
|
QSize minimumSizeHint() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVBoxLayout *m_actionsLayout;
|
QVBoxLayout *m_actionsLayout;
|
||||||
|
|||||||
@@ -24,26 +24,27 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "fancytabwidget.h"
|
#include "fancytabwidget.h"
|
||||||
#include "fancyactionbar.h"
|
|
||||||
#include "coreconstants.h"
|
|
||||||
|
|
||||||
|
#include "coreconstants.h"
|
||||||
|
#include "fancyactionbar.h"
|
||||||
|
|
||||||
|
#include <utils/asconst.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/stylehelper.h>
|
|
||||||
#include <utils/styledbar.h>
|
#include <utils/styledbar.h>
|
||||||
|
#include <utils/stylehelper.h>
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QStyleFactory>
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPixmapCache>
|
#include <QPixmapCache>
|
||||||
#include <QStackedLayout>
|
#include <QStackedLayout>
|
||||||
#include <QStatusBar>
|
#include <QStatusBar>
|
||||||
|
#include <QStyleFactory>
|
||||||
#include <QStyleOption>
|
#include <QStyleOption>
|
||||||
#include <QToolTip>
|
#include <QToolTip>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace Internal;
|
using namespace Internal;
|
||||||
@@ -53,31 +54,29 @@ static const int kMenuButtonWidth = 16;
|
|||||||
|
|
||||||
void FancyTab::fadeIn()
|
void FancyTab::fadeIn()
|
||||||
{
|
{
|
||||||
animator.stop();
|
m_animator.stop();
|
||||||
animator.setDuration(80);
|
m_animator.setDuration(80);
|
||||||
animator.setEndValue(1);
|
m_animator.setEndValue(1);
|
||||||
animator.start();
|
m_animator.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyTab::fadeOut()
|
void FancyTab::fadeOut()
|
||||||
{
|
{
|
||||||
animator.stop();
|
m_animator.stop();
|
||||||
animator.setDuration(160);
|
m_animator.setDuration(160);
|
||||||
animator.setEndValue(0);
|
m_animator.setEndValue(0);
|
||||||
animator.start();
|
m_animator.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyTab::setFader(float value)
|
void FancyTab::setFader(qreal value)
|
||||||
{
|
{
|
||||||
m_fader = value;
|
m_fader = value;
|
||||||
tabbar->update();
|
m_tabbar->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
FancyTabBar::FancyTabBar(QWidget *parent)
|
FancyTabBar::FancyTabBar(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
m_hoverIndex = -1;
|
|
||||||
m_currentIndex = -1;
|
|
||||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||||
setMinimumWidth(44);
|
setMinimumWidth(44);
|
||||||
setAttribute(Qt::WA_Hover, true);
|
setAttribute(Qt::WA_Hover, true);
|
||||||
@@ -90,17 +89,17 @@ QSize FancyTabBar::tabSizeHint(bool minimum) const
|
|||||||
QFont boldFont(font());
|
QFont boldFont(font());
|
||||||
boldFont.setPointSizeF(StyleHelper::sidebarFontSize());
|
boldFont.setPointSizeF(StyleHelper::sidebarFontSize());
|
||||||
boldFont.setBold(true);
|
boldFont.setBold(true);
|
||||||
QFontMetrics fm(boldFont);
|
const QFontMetrics fm(boldFont);
|
||||||
int spacing = 8;
|
const int spacing = 8;
|
||||||
int width = 60 + spacing + 2;
|
const int width = 60 + spacing + 2;
|
||||||
int maxLabelwidth = 0;
|
int maxLabelwidth = 0;
|
||||||
for (int tab=0 ; tab<count() ;++tab) {
|
for (auto tab : asConst(m_tabs)) {
|
||||||
int width = fm.width(m_tabs.at(tab)->text);
|
const int width = fm.width(tab->text);
|
||||||
if (width > maxLabelwidth)
|
if (width > maxLabelwidth)
|
||||||
maxLabelwidth = width;
|
maxLabelwidth = width;
|
||||||
}
|
}
|
||||||
int iconHeight = minimum ? 0 : 32;
|
const int iconHeight = minimum ? 0 : 32;
|
||||||
return QSize(qMax(width, maxLabelwidth + 4), iconHeight + spacing + fm.height());
|
return {qMax(width, maxLabelwidth + 4), iconHeight + spacing + fm.height()};
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyTabBar::paintEvent(QPaintEvent *event)
|
void FancyTabBar::paintEvent(QPaintEvent *event)
|
||||||
@@ -122,12 +121,12 @@ void FancyTabBar::paintEvent(QPaintEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle hover events for mouse fade ins
|
// Handle hover events for mouse fade ins
|
||||||
void FancyTabBar::mouseMoveEvent(QMouseEvent *e)
|
void FancyTabBar::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
int newHover = -1;
|
int newHover = -1;
|
||||||
for (int i = 0; i < count(); ++i) {
|
for (int i = 0; i < count(); ++i) {
|
||||||
QRect area = tabRect(i);
|
const QRect area = tabRect(i);
|
||||||
if (area.contains(e->pos())) {
|
if (area.contains(event->pos())) {
|
||||||
newHover = i;
|
newHover = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -150,9 +149,9 @@ bool FancyTabBar::event(QEvent *event)
|
|||||||
{
|
{
|
||||||
if (event->type() == QEvent::ToolTip) {
|
if (event->type() == QEvent::ToolTip) {
|
||||||
if (validIndex(m_hoverIndex)) {
|
if (validIndex(m_hoverIndex)) {
|
||||||
QString tt = tabToolTip(m_hoverIndex);
|
const QString tt = tabToolTip(m_hoverIndex);
|
||||||
if (!tt.isEmpty()) {
|
if (!tt.isEmpty()) {
|
||||||
QToolTip::showText(static_cast<QHelpEvent*>(event)->globalPos(), tt, this);
|
QToolTip::showText(static_cast<QHelpEvent *>(event)->globalPos(), tt, this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,34 +160,33 @@ bool FancyTabBar::event(QEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Resets hover animation on mouse enter
|
// Resets hover animation on mouse enter
|
||||||
void FancyTabBar::enterEvent(QEvent *e)
|
void FancyTabBar::enterEvent(QEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(e)
|
Q_UNUSED(event)
|
||||||
m_hoverRect = QRect();
|
m_hoverRect = QRect();
|
||||||
m_hoverIndex = -1;
|
m_hoverIndex = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resets hover animation on mouse enter
|
// Resets hover animation on mouse enter
|
||||||
void FancyTabBar::leaveEvent(QEvent *e)
|
void FancyTabBar::leaveEvent(QEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(e)
|
Q_UNUSED(event)
|
||||||
m_hoverIndex = -1;
|
m_hoverIndex = -1;
|
||||||
m_hoverRect = QRect();
|
m_hoverRect = QRect();
|
||||||
for (int i = 0 ; i < m_tabs.count() ; ++i) {
|
for (auto tab : asConst(m_tabs))
|
||||||
m_tabs[i]->fadeOut();
|
tab->fadeOut();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize FancyTabBar::sizeHint() const
|
QSize FancyTabBar::sizeHint() const
|
||||||
{
|
{
|
||||||
QSize sh = tabSizeHint();
|
const QSize sh = tabSizeHint();
|
||||||
return QSize(sh.width(), sh.height() * m_tabs.count());
|
return {sh.width(), sh.height() * m_tabs.count()};
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize FancyTabBar::minimumSizeHint() const
|
QSize FancyTabBar::minimumSizeHint() const
|
||||||
{
|
{
|
||||||
QSize sh = tabSizeHint(true);
|
const QSize sh = tabSizeHint(true);
|
||||||
return QSize(sh.width(), sh.height() * m_tabs.count());
|
return {sh.width(), sh.height() * m_tabs.count()};
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect FancyTabBar::tabRect(int index) const
|
QRect FancyTabBar::tabRect(int index) const
|
||||||
@@ -198,20 +196,20 @@ QRect FancyTabBar::tabRect(int index) const
|
|||||||
if (sh.height() * m_tabs.count() > height())
|
if (sh.height() * m_tabs.count() > height())
|
||||||
sh.setHeight(height() / m_tabs.count());
|
sh.setHeight(height() / m_tabs.count());
|
||||||
|
|
||||||
return QRect(0, index * sh.height(), sh.width(), sh.height());
|
return {0, index * sh.height(), sh.width(), sh.height()};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyTabBar::mousePressEvent(QMouseEvent *e)
|
void FancyTabBar::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
e->accept();
|
event->accept();
|
||||||
for (int index = 0; index < m_tabs.count(); ++index) {
|
for (int index = 0; index < m_tabs.count(); ++index) {
|
||||||
const QRect rect = tabRect(index);
|
const QRect rect = tabRect(index);
|
||||||
if (rect.contains(e->pos())) {
|
if (rect.contains(event->pos())) {
|
||||||
if (isTabEnabled(index)) {
|
if (isTabEnabled(index)) {
|
||||||
if (m_tabs.at(index)->hasMenu && rect.right() - e->pos().x() <= kMenuButtonWidth) {
|
if (m_tabs.at(index)->hasMenu
|
||||||
|
&& rect.right() - event->pos().x() <= kMenuButtonWidth) {
|
||||||
// menu arrow clicked
|
// menu arrow clicked
|
||||||
emit menuTriggered(index, e);
|
emit menuTriggered(index, event);
|
||||||
} else {
|
} else {
|
||||||
m_currentIndex = index;
|
m_currentIndex = index;
|
||||||
update();
|
update();
|
||||||
@@ -229,8 +227,8 @@ static void paintSelectedTabBackground(QPainter *painter, const QRect &spanRect)
|
|||||||
const int verticalOverlap = 2; // Grows up and down for the overlaps
|
const int verticalOverlap = 2; // Grows up and down for the overlaps
|
||||||
const int dpr = painter->device()->devicePixelRatio();
|
const int dpr = painter->device()->devicePixelRatio();
|
||||||
const QString cacheKey = QLatin1String(Q_FUNC_INFO) + QString::number(spanRect.width())
|
const QString cacheKey = QLatin1String(Q_FUNC_INFO) + QString::number(spanRect.width())
|
||||||
+ QLatin1Char('x') + QString::number(spanRect.height())
|
+ QLatin1Char('x') + QString::number(spanRect.height())
|
||||||
+ QLatin1Char('@') + QString::number(dpr);
|
+ QLatin1Char('@') + QString::number(dpr);
|
||||||
QPixmap selection;
|
QPixmap selection;
|
||||||
if (!QPixmapCache::find(cacheKey, &selection)) {
|
if (!QPixmapCache::find(cacheKey, &selection)) {
|
||||||
selection = QPixmap(QSize(spanRect.width(), spanRect.height() + 2 * verticalOverlap) * dpr);
|
selection = QPixmap(QSize(spanRect.width(), spanRect.height() + 2 * verticalOverlap) * dpr);
|
||||||
@@ -260,11 +258,13 @@ static void paintSelectedTabBackground(QPainter *painter, const QRect &spanRect)
|
|||||||
//highlights
|
//highlights
|
||||||
p.setPen(QColor(255, 255, 255, 50));
|
p.setPen(QColor(255, 255, 255, 50));
|
||||||
p.drawLine(borderRect.topLeft() + QPointF(0, -2), borderRect.topRight() - QPointF(0, 2));
|
p.drawLine(borderRect.topLeft() + QPointF(0, -2), borderRect.topRight() - QPointF(0, 2));
|
||||||
p.drawLine(borderRect.bottomLeft() + QPointF(0, 1), borderRect.bottomRight() + QPointF(0, 1));
|
p.drawLine(borderRect.bottomLeft() + QPointF(0, 1),
|
||||||
|
borderRect.bottomRight() + QPointF(0, 1));
|
||||||
p.setPen(QColor(255, 255, 255, 40));
|
p.setPen(QColor(255, 255, 255, 40));
|
||||||
p.drawLine(borderRect.topLeft() + QPointF(0, 0), borderRect.topRight());
|
p.drawLine(borderRect.topLeft() + QPointF(0, 0), borderRect.topRight());
|
||||||
p.drawLine(borderRect.topRight() + QPointF(0, 1), borderRect.bottomRight() - QPointF(0, 1));
|
p.drawLine(borderRect.topRight() + QPointF(0, 1), borderRect.bottomRight() - QPointF(0, 1));
|
||||||
p.drawLine(borderRect.bottomLeft() + QPointF(0, -1), borderRect.bottomRight() - QPointF(0, 1));
|
p.drawLine(borderRect.bottomLeft() + QPointF(0, -1),
|
||||||
|
borderRect.bottomRight() - QPointF(0, 1));
|
||||||
p.end();
|
p.end();
|
||||||
|
|
||||||
QPixmapCache::insert(cacheKey, selection);
|
QPixmapCache::insert(cacheKey, selection);
|
||||||
@@ -280,21 +280,21 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
|
|||||||
}
|
}
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
FancyTab *tab = m_tabs.at(tabIndex);
|
const FancyTab *tab = m_tabs.at(tabIndex);
|
||||||
QRect rect = tabRect(tabIndex);
|
const QRect rect = tabRect(tabIndex);
|
||||||
bool selected = (tabIndex == m_currentIndex);
|
const bool selected = (tabIndex == m_currentIndex);
|
||||||
bool enabled = isTabEnabled(tabIndex);
|
const bool enabled = isTabEnabled(tabIndex);
|
||||||
|
|
||||||
if (selected) {
|
if (selected) {
|
||||||
if (creatorTheme()->flag(Theme::FlatToolBars)) {
|
if (creatorTheme()->flag(Theme::FlatToolBars)) {
|
||||||
// background color of a fancy tab that is active
|
// background color of a fancy tab that is active
|
||||||
painter->fillRect(rect, creatorTheme()->color(Theme::FancyToolButtonSelectedColor));
|
painter->fillRect(rect, creatorTheme()->color(Theme::FancyToolButtonSelectedColor));
|
||||||
} else {
|
} else {
|
||||||
paintSelectedTabBackground(painter, rect);
|
paintSelectedTabBackground(painter, rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString tabText(tab->text);
|
const QString tabText(tab->text);
|
||||||
QRect tabTextRect(rect);
|
QRect tabTextRect(rect);
|
||||||
const bool drawIcon = rect.height() > 36;
|
const bool drawIcon = rect.height() > 36;
|
||||||
QRect tabIconRect(tabTextRect);
|
QRect tabIconRect(tabTextRect);
|
||||||
@@ -304,9 +304,10 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
|
|||||||
boldFont.setBold(true);
|
boldFont.setBold(true);
|
||||||
painter->setFont(boldFont);
|
painter->setFont(boldFont);
|
||||||
painter->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110));
|
painter->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110));
|
||||||
const int textFlags = Qt::AlignCenter | (drawIcon ? Qt::AlignBottom : Qt::AlignVCenter) | Qt::TextWordWrap;
|
const int textFlags = Qt::AlignCenter | (drawIcon ? Qt::AlignBottom : Qt::AlignVCenter)
|
||||||
|
| Qt::TextWordWrap;
|
||||||
|
|
||||||
const float fader = m_tabs[tabIndex]->fader();
|
const qreal fader = tab->fader();
|
||||||
if (fader > 0 && !HostOsInfo::isMacHost() && !selected && enabled) {
|
if (fader > 0 && !HostOsInfo::isMacHost() && !selected && enabled) {
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->setOpacity(fader);
|
painter->setOpacity(fader);
|
||||||
@@ -321,7 +322,11 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
|
|||||||
painter->setOpacity(0.7);
|
painter->setOpacity(0.7);
|
||||||
|
|
||||||
if (drawIcon) {
|
if (drawIcon) {
|
||||||
int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height();
|
const int textHeight = painter->fontMetrics()
|
||||||
|
.boundingRect(QRect(0, 0, width(), height()),
|
||||||
|
Qt::TextWordWrap,
|
||||||
|
tabText)
|
||||||
|
.height();
|
||||||
tabIconRect.adjust(0, 4, 0, -textHeight);
|
tabIconRect.adjust(0, 4, 0, -textHeight);
|
||||||
const QIcon::Mode iconMode = enabled ? (selected ? QIcon::Active : QIcon::Normal)
|
const QIcon::Mode iconMode = enabled ? (selected ? QIcon::Active : QIcon::Normal)
|
||||||
: QIcon::Disabled;
|
: QIcon::Disabled;
|
||||||
@@ -333,13 +338,13 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
|
|||||||
|
|
||||||
painter->setOpacity(1.0); //FIXME: was 0.7 before?
|
painter->setOpacity(1.0); //FIXME: was 0.7 before?
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
painter->setPen(selected
|
painter->setPen(
|
||||||
? creatorTheme()->color(Theme::FancyTabWidgetEnabledSelectedTextColor)
|
selected ? creatorTheme()->color(Theme::FancyTabWidgetEnabledSelectedTextColor)
|
||||||
: creatorTheme()->color(Theme::FancyTabWidgetEnabledUnselectedTextColor));
|
: creatorTheme()->color(Theme::FancyTabWidgetEnabledUnselectedTextColor));
|
||||||
} else {
|
} else {
|
||||||
painter->setPen(selected
|
painter->setPen(
|
||||||
? creatorTheme()->color(Theme::FancyTabWidgetDisabledSelectedTextColor)
|
selected ? creatorTheme()->color(Theme::FancyTabWidgetDisabledSelectedTextColor)
|
||||||
: creatorTheme()->color(Theme::FancyTabWidgetDisabledUnselectedTextColor));
|
: creatorTheme()->color(Theme::FancyTabWidgetDisabledUnselectedTextColor));
|
||||||
}
|
}
|
||||||
painter->translate(0, -1);
|
painter->translate(0, -1);
|
||||||
painter->drawText(tabTextRect, textFlags, tabText);
|
painter->drawText(tabTextRect, textFlags, tabText);
|
||||||
@@ -354,7 +359,8 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
|
|||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyTabBar::setCurrentIndex(int index) {
|
void FancyTabBar::setCurrentIndex(int index)
|
||||||
|
{
|
||||||
if (isTabEnabled(index) && index != m_currentIndex) {
|
if (isTabEnabled(index) && index != m_currentIndex) {
|
||||||
m_currentIndex = index;
|
m_currentIndex = index;
|
||||||
update();
|
update();
|
||||||
@@ -384,35 +390,27 @@ bool FancyTabBar::isTabEnabled(int index) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//////
|
|
||||||
// FancyColorButton
|
|
||||||
//////
|
|
||||||
|
|
||||||
class FancyColorButton : public QWidget
|
class FancyColorButton : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FancyColorButton(QWidget *parent = 0)
|
explicit FancyColorButton(QWidget *parent = nullptr)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mousePressEvent(QMouseEvent *ev)
|
void mousePressEvent(QMouseEvent *ev) override { emit clicked(ev->button(), ev->modifiers()); }
|
||||||
{
|
|
||||||
emit clicked(ev->button(), ev->modifiers());
|
|
||||||
}
|
|
||||||
|
|
||||||
void paintEvent(QPaintEvent *event)
|
void paintEvent(QPaintEvent *event) override
|
||||||
{
|
{
|
||||||
QWidget::paintEvent(event);
|
QWidget::paintEvent(event);
|
||||||
|
|
||||||
// Some Themes do not want highlights, shadows and borders in the toolbars.
|
// Some Themes do not want highlights, shadows and borders in the toolbars.
|
||||||
// But we definitely want a separator between FancyColorButton and FancyTabBar
|
// But we definitely want a separator between FancyColorButton and FancyTabBar
|
||||||
if (!creatorTheme()->flag(Theme::DrawToolBarHighlights)
|
if (!creatorTheme()->flag(Theme::DrawToolBarHighlights)
|
||||||
&& !creatorTheme()->flag(Theme::DrawToolBarBorders)) {
|
&& !creatorTheme()->flag(Theme::DrawToolBarBorders)) {
|
||||||
QPainter p(this);
|
QPainter p(this);
|
||||||
p.setPen(StyleHelper::toolBarBorderColor());
|
p.setPen(StyleHelper::toolBarBorderColor());
|
||||||
const QRectF innerRect = QRectF(rect()).adjusted(0.5, 0.5, -0.5, -0.5);
|
const QRectF innerRect = QRectF(rect()).adjusted(0.5, 0.5, -0.5, -0.5);
|
||||||
@@ -434,12 +432,12 @@ FancyTabWidget::FancyTabWidget(QWidget *parent)
|
|||||||
m_tabBar = new FancyTabBar(this);
|
m_tabBar = new FancyTabBar(this);
|
||||||
|
|
||||||
m_selectionWidget = new QWidget(this);
|
m_selectionWidget = new QWidget(this);
|
||||||
QVBoxLayout *selectionLayout = new QVBoxLayout;
|
auto selectionLayout = new QVBoxLayout;
|
||||||
selectionLayout->setSpacing(0);
|
selectionLayout->setSpacing(0);
|
||||||
selectionLayout->setMargin(0);
|
selectionLayout->setMargin(0);
|
||||||
|
|
||||||
StyledBar *bar = new StyledBar;
|
auto bar = new StyledBar;
|
||||||
QHBoxLayout *layout = new QHBoxLayout(bar);
|
auto layout = new QHBoxLayout(bar);
|
||||||
layout->setMargin(0);
|
layout->setMargin(0);
|
||||||
layout->setSpacing(0);
|
layout->setSpacing(0);
|
||||||
auto fancyButton = new FancyColorButton(this);
|
auto fancyButton = new FancyColorButton(this);
|
||||||
@@ -455,7 +453,7 @@ FancyTabWidget::FancyTabWidget(QWidget *parent)
|
|||||||
m_cornerWidgetContainer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
m_cornerWidgetContainer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
||||||
m_cornerWidgetContainer->setAutoFillBackground(false);
|
m_cornerWidgetContainer->setAutoFillBackground(false);
|
||||||
|
|
||||||
QVBoxLayout *cornerWidgetLayout = new QVBoxLayout;
|
auto cornerWidgetLayout = new QVBoxLayout;
|
||||||
cornerWidgetLayout->setSpacing(0);
|
cornerWidgetLayout->setSpacing(0);
|
||||||
cornerWidgetLayout->setMargin(0);
|
cornerWidgetLayout->setMargin(0);
|
||||||
cornerWidgetLayout->addStretch();
|
cornerWidgetLayout->addStretch();
|
||||||
@@ -467,13 +465,13 @@ FancyTabWidget::FancyTabWidget(QWidget *parent)
|
|||||||
m_statusBar = new QStatusBar;
|
m_statusBar = new QStatusBar;
|
||||||
m_statusBar->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
|
m_statusBar->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
|
||||||
|
|
||||||
QVBoxLayout *vlayout = new QVBoxLayout;
|
auto vlayout = new QVBoxLayout;
|
||||||
vlayout->setMargin(0);
|
vlayout->setMargin(0);
|
||||||
vlayout->setSpacing(0);
|
vlayout->setSpacing(0);
|
||||||
vlayout->addLayout(m_modesStack);
|
vlayout->addLayout(m_modesStack);
|
||||||
vlayout->addWidget(m_statusBar);
|
vlayout->addWidget(m_statusBar);
|
||||||
|
|
||||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
auto mainLayout = new QHBoxLayout;
|
||||||
mainLayout->setMargin(0);
|
mainLayout->setMargin(0);
|
||||||
mainLayout->setSpacing(1);
|
mainLayout->setSpacing(1);
|
||||||
mainLayout->addWidget(m_selectionWidget);
|
mainLayout->addWidget(m_selectionWidget);
|
||||||
@@ -494,8 +492,7 @@ bool FancyTabWidget::isSelectionWidgetVisible() const
|
|||||||
return m_selectionWidget->isVisible();
|
return m_selectionWidget->isVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyTabWidget::insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label,
|
void FancyTabWidget::insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label, bool hasMenu)
|
||||||
bool hasMenu)
|
|
||||||
{
|
{
|
||||||
m_modesStack->insertWidget(index, tab);
|
m_modesStack->insertWidget(index, tab);
|
||||||
m_tabBar->insertTab(index, icon, label, hasMenu);
|
m_tabBar->insertTab(index, icon, label, hasMenu);
|
||||||
@@ -533,7 +530,7 @@ void FancyTabWidget::paintEvent(QPaintEvent *event)
|
|||||||
painter.setPen(StyleHelper::borderColor());
|
painter.setPen(StyleHelper::borderColor());
|
||||||
painter.drawLine(boderRect.topRight(), boderRect.bottomRight());
|
painter.drawLine(boderRect.topRight(), boderRect.bottomRight());
|
||||||
|
|
||||||
QColor light = StyleHelper::sidebarHighlight();
|
const QColor light = StyleHelper::sidebarHighlight();
|
||||||
painter.setPen(light);
|
painter.setPen(light);
|
||||||
painter.drawLine(boderRect.bottomLeft(), boderRect.bottomRight());
|
painter.drawLine(boderRect.bottomLeft(), boderRect.bottomRight());
|
||||||
}
|
}
|
||||||
@@ -542,7 +539,7 @@ void FancyTabWidget::paintEvent(QPaintEvent *event)
|
|||||||
|
|
||||||
void FancyTabWidget::insertCornerWidget(int pos, QWidget *widget)
|
void FancyTabWidget::insertCornerWidget(int pos, QWidget *widget)
|
||||||
{
|
{
|
||||||
QVBoxLayout *layout = static_cast<QVBoxLayout *>(m_cornerWidgetContainer->layout());
|
auto layout = static_cast<QVBoxLayout *>(m_cornerWidgetContainer->layout());
|
||||||
layout->insertWidget(pos, widget);
|
layout->insertWidget(pos, widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,8 @@
|
|||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QPainter;
|
class QPainter;
|
||||||
@@ -44,14 +44,18 @@ class FancyTab : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(float fader READ fader WRITE setFader)
|
Q_PROPERTY(qreal fader READ fader WRITE setFader CONSTANT)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FancyTab(QWidget *tabbar) : tabbar(tabbar){
|
FancyTab(QWidget *tabbar)
|
||||||
animator.setPropertyName("fader");
|
: m_tabbar(tabbar)
|
||||||
animator.setTargetObject(this);
|
{
|
||||||
|
m_animator.setPropertyName("fader");
|
||||||
|
m_animator.setTargetObject(this);
|
||||||
}
|
}
|
||||||
float fader() { return m_fader; }
|
|
||||||
void setFader(float value);
|
qreal fader() const { return m_fader; }
|
||||||
|
void setFader(qreal qreal);
|
||||||
|
|
||||||
void fadeIn();
|
void fadeIn();
|
||||||
void fadeOut();
|
void fadeOut();
|
||||||
@@ -63,9 +67,9 @@ public:
|
|||||||
bool hasMenu = false;
|
bool hasMenu = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPropertyAnimation animator;
|
QPropertyAnimation m_animator;
|
||||||
QWidget *tabbar;
|
QWidget *m_tabbar;
|
||||||
float m_fader = 0;
|
qreal m_fader = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FancyTabBar : public QWidget
|
class FancyTabBar : public QWidget
|
||||||
@@ -73,26 +77,27 @@ class FancyTabBar : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FancyTabBar(QWidget *parent = 0);
|
FancyTabBar(QWidget *parent = nullptr);
|
||||||
|
|
||||||
bool event(QEvent *event);
|
bool event(QEvent *event) override;
|
||||||
|
|
||||||
void paintEvent(QPaintEvent *event);
|
void paintEvent(QPaintEvent *event) override;
|
||||||
void paintTab(QPainter *painter, int tabIndex) const;
|
void paintTab(QPainter *painter, int tabIndex) const;
|
||||||
void mousePressEvent(QMouseEvent *);
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
void mouseMoveEvent(QMouseEvent *);
|
void mouseMoveEvent(QMouseEvent *event) override;
|
||||||
void enterEvent(QEvent *);
|
void enterEvent(QEvent *event) override;
|
||||||
void leaveEvent(QEvent *);
|
void leaveEvent(QEvent *event) override;
|
||||||
bool validIndex(int index) const { return index >= 0 && index < m_tabs.count(); }
|
bool validIndex(int index) const { return index >= 0 && index < m_tabs.count(); }
|
||||||
|
|
||||||
QSize sizeHint() const;
|
QSize sizeHint() const override;
|
||||||
QSize minimumSizeHint() const;
|
QSize minimumSizeHint() const override;
|
||||||
|
|
||||||
void setTabEnabled(int index, bool enable);
|
void setTabEnabled(int index, bool enable);
|
||||||
bool isTabEnabled(int index) const;
|
bool isTabEnabled(int index) const;
|
||||||
|
|
||||||
void insertTab(int index, const QIcon &icon, const QString &label, bool hasMenu) {
|
void insertTab(int index, const QIcon &icon, const QString &label, bool hasMenu)
|
||||||
FancyTab *tab = new FancyTab(this);
|
{
|
||||||
|
auto tab = new FancyTab(this);
|
||||||
tab->icon = icon;
|
tab->icon = icon;
|
||||||
tab->text = label;
|
tab->text = label;
|
||||||
tab->hasMenu = hasMenu;
|
tab->hasMenu = hasMenu;
|
||||||
@@ -102,7 +107,8 @@ public:
|
|||||||
updateGeometry();
|
updateGeometry();
|
||||||
}
|
}
|
||||||
void setEnabled(int index, bool enabled);
|
void setEnabled(int index, bool enabled);
|
||||||
void removeTab(int index) {
|
void removeTab(int index)
|
||||||
|
{
|
||||||
FancyTab *tab = m_tabs.takeAt(index);
|
FancyTab *tab = m_tabs.takeAt(index);
|
||||||
delete tab;
|
delete tab;
|
||||||
updateGeometry();
|
updateGeometry();
|
||||||
@@ -110,10 +116,10 @@ public:
|
|||||||
void setCurrentIndex(int index);
|
void setCurrentIndex(int index);
|
||||||
int currentIndex() const { return m_currentIndex; }
|
int currentIndex() const { return m_currentIndex; }
|
||||||
|
|
||||||
void setTabToolTip(int index, QString toolTip) { m_tabs[index]->toolTip = toolTip; }
|
void setTabToolTip(int index, const QString &toolTip) { m_tabs[index]->toolTip = toolTip; }
|
||||||
QString tabToolTip(int index) const { return m_tabs.at(index)->toolTip; }
|
QString tabToolTip(int index) const { return m_tabs.at(index)->toolTip; }
|
||||||
|
|
||||||
int count() const {return m_tabs.count(); }
|
int count() const { return m_tabs.count(); }
|
||||||
QRect tabRect(int index) const;
|
QRect tabRect(int index) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@@ -122,11 +128,10 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QRect m_hoverRect;
|
QRect m_hoverRect;
|
||||||
int m_hoverIndex;
|
int m_hoverIndex = -1;
|
||||||
int m_currentIndex;
|
int m_currentIndex = -1;
|
||||||
QList<FancyTab*> m_tabs;
|
QList<FancyTab *> m_tabs;
|
||||||
QSize tabSizeHint(bool minimum = false) const;
|
QSize tabSizeHint(bool minimum = false) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class FancyTabWidget : public QWidget
|
class FancyTabWidget : public QWidget
|
||||||
@@ -134,7 +139,7 @@ class FancyTabWidget : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FancyTabWidget(QWidget *parent = 0);
|
FancyTabWidget(QWidget *parent = nullptr);
|
||||||
|
|
||||||
void insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label, bool hasMenu);
|
void insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label, bool hasMenu);
|
||||||
void removeTab(int index);
|
void removeTab(int index);
|
||||||
@@ -144,7 +149,7 @@ public:
|
|||||||
int cornerWidgetCount() const;
|
int cornerWidgetCount() const;
|
||||||
void setTabToolTip(int index, const QString &toolTip);
|
void setTabToolTip(int index, const QString &toolTip);
|
||||||
|
|
||||||
void paintEvent(QPaintEvent *event);
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
int currentIndex() const;
|
int currentIndex() const;
|
||||||
QStatusBar *statusBar() const;
|
QStatusBar *statusBar() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user