Button size support in Aurorae. (UI to change the size still missing)
svn path=/trunk/KDE/kdebase/workspace/; revision=1116153
This commit is contained in:
parent
6776cfcdb2
commit
65acab3e20
7 changed files with 94 additions and 27 deletions
|
@ -51,6 +51,7 @@ AuroraeButton::AuroraeButton(AuroraeTheme* theme, AuroraeButtonType type)
|
||||||
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
setAcceptedMouseButtons(Qt::LeftButton);
|
setAcceptedMouseButtons(Qt::LeftButton);
|
||||||
|
connect(m_theme, SIGNAL(buttonSizesChanged()), SLOT(buttonSizesChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
AuroraeButton::~AuroraeButton()
|
AuroraeButton::~AuroraeButton()
|
||||||
|
@ -88,34 +89,36 @@ QSizeF AuroraeButton::sizeHint(Qt::SizeHint which, const QSizeF& constraint) con
|
||||||
{
|
{
|
||||||
Q_UNUSED(which)
|
Q_UNUSED(which)
|
||||||
Q_UNUSED(constraint)
|
Q_UNUSED(constraint)
|
||||||
|
const qreal factor = m_theme->buttonSizeFactor();
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case MinimizeButton:
|
case MinimizeButton:
|
||||||
return QSizeF(m_theme->themeConfig().buttonWidthMinimize(),
|
return QSizeF(m_theme->themeConfig().buttonWidthMinimize()*factor,
|
||||||
m_theme->themeConfig().buttonHeight());
|
m_theme->themeConfig().buttonHeight()*factor);
|
||||||
case MaximizeButton:
|
case MaximizeButton:
|
||||||
case RestoreButton:
|
case RestoreButton:
|
||||||
return QSizeF(m_theme->themeConfig().buttonWidthMaximizeRestore(),
|
return QSizeF(m_theme->themeConfig().buttonWidthMaximizeRestore()*factor,
|
||||||
m_theme->themeConfig().buttonHeight());
|
m_theme->themeConfig().buttonHeight()*factor);
|
||||||
case CloseButton:
|
case CloseButton:
|
||||||
return QSizeF(m_theme->themeConfig().buttonWidthClose(),
|
return QSizeF(m_theme->themeConfig().buttonWidthClose()*factor,
|
||||||
m_theme->themeConfig().buttonHeight());
|
m_theme->themeConfig().buttonHeight()*factor);
|
||||||
case AllDesktopsButton:
|
case AllDesktopsButton:
|
||||||
return QSizeF(m_theme->themeConfig().buttonWidthAllDesktops(),
|
return QSizeF(m_theme->themeConfig().buttonWidthAllDesktops()*factor,
|
||||||
m_theme->themeConfig().buttonHeight());
|
m_theme->themeConfig().buttonHeight()*factor);
|
||||||
case KeepAboveButton:
|
case KeepAboveButton:
|
||||||
return QSizeF(m_theme->themeConfig().buttonWidthKeepAbove(),
|
return QSizeF(m_theme->themeConfig().buttonWidthKeepAbove()*factor,
|
||||||
m_theme->themeConfig().buttonHeight());
|
m_theme->themeConfig().buttonHeight()*factor);
|
||||||
case KeepBelowButton:
|
case KeepBelowButton:
|
||||||
return QSizeF(m_theme->themeConfig().buttonWidthKeepBelow(),
|
return QSizeF(m_theme->themeConfig().buttonWidthKeepBelow()*factor,
|
||||||
m_theme->themeConfig().buttonHeight());
|
m_theme->themeConfig().buttonHeight()*factor);
|
||||||
case ShadeButton:
|
case ShadeButton:
|
||||||
return QSizeF(m_theme->themeConfig().buttonWidthShade(),
|
return QSizeF(m_theme->themeConfig().buttonWidthShade()*factor,
|
||||||
m_theme->themeConfig().buttonHeight());
|
m_theme->themeConfig().buttonHeight()*factor);
|
||||||
case HelpButton:
|
case HelpButton:
|
||||||
return QSizeF(m_theme->themeConfig().buttonWidthHelp(),
|
return QSizeF(m_theme->themeConfig().buttonWidthHelp()*factor,
|
||||||
m_theme->themeConfig().buttonHeight());
|
m_theme->themeConfig().buttonHeight()*factor);
|
||||||
default:
|
default:
|
||||||
return QSizeF(m_theme->themeConfig().buttonWidth(), m_theme->themeConfig().buttonHeight());
|
return QSizeF(m_theme->themeConfig().buttonWidth()*factor,
|
||||||
|
m_theme->themeConfig().buttonHeight()*factor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void AuroraeButton::mousePressEvent(QGraphicsSceneMouseEvent* event)
|
void AuroraeButton::mousePressEvent(QGraphicsSceneMouseEvent* event)
|
||||||
|
@ -309,6 +312,12 @@ void AuroraeButton::setAnimationProgress(qreal progress)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AuroraeButton::buttonSizesChanged()
|
||||||
|
{
|
||||||
|
updateGeometry();
|
||||||
|
static_cast<AuroraeScene*>(scene())->updateLayout();
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************************
|
/***********************************************
|
||||||
* AuroraeMaximizeButton
|
* AuroraeMaximizeButton
|
||||||
***********************************************/
|
***********************************************/
|
||||||
|
|
|
@ -75,6 +75,9 @@ public:
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void clicked();
|
void clicked();
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void buttonSizesChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum ButtonState {
|
enum ButtonState {
|
||||||
Active = 0x1,
|
Active = 0x1,
|
||||||
|
|
|
@ -99,7 +99,7 @@ void AuroraeScene::init()
|
||||||
titleLayout->addItem(tab);
|
titleLayout->addItem(tab);
|
||||||
m_title->setLayout(titleLayout);
|
m_title->setLayout(titleLayout);
|
||||||
addItem(m_title);
|
addItem(m_title);
|
||||||
tab->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
tab->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
|
||||||
setActive(m_active, false);
|
setActive(m_active, false);
|
||||||
updateLayout();
|
updateLayout();
|
||||||
|
@ -183,6 +183,8 @@ void AuroraeScene::drawBackground(QPainter *painter, const QRectF &rect)
|
||||||
frame->setEnabledBorders(Plasma::FrameSvg::AllBorders);
|
frame->setEnabledBorders(Plasma::FrameSvg::AllBorders);
|
||||||
}
|
}
|
||||||
QRectF r = sceneRect();
|
QRectF r = sceneRect();
|
||||||
|
const qreal titleHeight = qMax((qreal)conf.titleHeight(),
|
||||||
|
conf.buttonHeight()*m_theme->buttonSizeFactor() + conf.buttonMarginTop());
|
||||||
if (maximized) {
|
if (maximized) {
|
||||||
r = QRectF(conf.paddingLeft(), conf.paddingTop(),
|
r = QRectF(conf.paddingLeft(), conf.paddingTop(),
|
||||||
sceneRect().width() - conf.paddingRight() - conf.paddingLeft(),
|
sceneRect().width() - conf.paddingRight() - conf.paddingLeft(),
|
||||||
|
@ -190,7 +192,7 @@ void AuroraeScene::drawBackground(QPainter *painter, const QRectF &rect)
|
||||||
if (true/*transparentRect().isNull()*/) {
|
if (true/*transparentRect().isNull()*/) {
|
||||||
r = QRectF(conf.paddingLeft(), conf.paddingTop(),
|
r = QRectF(conf.paddingLeft(), conf.paddingTop(),
|
||||||
sceneRect().width() - conf.paddingRight() - conf.paddingLeft(),
|
sceneRect().width() - conf.paddingRight() - conf.paddingLeft(),
|
||||||
conf.titleEdgeTopMaximized() + conf.titleHeight() + conf.titleEdgeBottomMaximized());
|
conf.titleEdgeTopMaximized() + titleHeight + conf.titleEdgeBottomMaximized());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QRectF sourceRect = QRectF(QPointF(0, 0), r.size());
|
QRectF sourceRect = QRectF(QPointF(0, 0), r.size());
|
||||||
|
@ -257,6 +259,8 @@ void AuroraeScene::updateLayout()
|
||||||
const int left = config.paddingLeft();
|
const int left = config.paddingLeft();
|
||||||
const int genericTop = config.paddingTop() + marginTop;
|
const int genericTop = config.paddingTop() + marginTop;
|
||||||
const int right = sceneRect().width() - m_rightButtons->preferredWidth() - config.paddingRight();
|
const int right = sceneRect().width() - m_rightButtons->preferredWidth() - config.paddingRight();
|
||||||
|
const qreal titleHeight = qMax((qreal)config.titleHeight(),
|
||||||
|
config.buttonHeight()*m_theme->buttonSizeFactor() + config.buttonMarginTop());
|
||||||
if (m_maximizeMode == KDecorationDefines::MaximizeFull) { // TODO: check option
|
if (m_maximizeMode == KDecorationDefines::MaximizeFull) { // TODO: check option
|
||||||
const int top = genericTop + config.titleEdgeTopMaximized();
|
const int top = genericTop + config.titleEdgeTopMaximized();
|
||||||
m_leftButtons->setGeometry(QRectF(QPointF(left + config.titleEdgeLeftMaximized(), top),
|
m_leftButtons->setGeometry(QRectF(QPointF(left + config.titleEdgeLeftMaximized(), top),
|
||||||
|
@ -267,7 +271,7 @@ void AuroraeScene::updateLayout()
|
||||||
const int leftTitle = m_leftButtons->geometry().right() + config.titleBorderLeft();
|
const int leftTitle = m_leftButtons->geometry().right() + config.titleBorderLeft();
|
||||||
const int titleWidth = m_rightButtons->geometry().left() - config.titleBorderRight() - leftTitle;
|
const int titleWidth = m_rightButtons->geometry().left() - config.titleBorderRight() - leftTitle;
|
||||||
m_title->setGeometry(leftTitle, config.paddingTop() + config.titleEdgeTopMaximized(),
|
m_title->setGeometry(leftTitle, config.paddingTop() + config.titleEdgeTopMaximized(),
|
||||||
titleWidth, config.titleHeight());
|
titleWidth, titleHeight);
|
||||||
m_title->layout()->invalidate();
|
m_title->layout()->invalidate();
|
||||||
} else {
|
} else {
|
||||||
const int top = genericTop + config.titleEdgeTop();
|
const int top = genericTop + config.titleEdgeTop();
|
||||||
|
@ -277,7 +281,7 @@ void AuroraeScene::updateLayout()
|
||||||
const int leftTitle = m_leftButtons->geometry().right() + config.titleBorderLeft();
|
const int leftTitle = m_leftButtons->geometry().right() + config.titleBorderLeft();
|
||||||
const int titleWidth = m_rightButtons->geometry().left() - config.titleBorderRight() - leftTitle;
|
const int titleWidth = m_rightButtons->geometry().left() - config.titleBorderRight() - leftTitle;
|
||||||
m_title->setGeometry(leftTitle, config.paddingTop() + config.titleEdgeTop(),
|
m_title->setGeometry(leftTitle, config.paddingTop() + config.titleEdgeTop(),
|
||||||
titleWidth, config.titleHeight());
|
titleWidth, titleHeight);
|
||||||
m_title->layout()->invalidate();
|
m_title->layout()->invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ AuroraeTab::AuroraeTab(AuroraeTheme* theme, const QString& caption)
|
||||||
setGraphicsEffect(m_effect);
|
setGraphicsEffect(m_effect);
|
||||||
}
|
}
|
||||||
setAcceptedMouseButtons(Qt::NoButton);
|
setAcceptedMouseButtons(Qt::NoButton);
|
||||||
|
connect(m_theme, SIGNAL(buttonSizesChanged()), SLOT(buttonSizesChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
AuroraeTab::~AuroraeTab()
|
AuroraeTab::~AuroraeTab()
|
||||||
|
@ -150,18 +151,25 @@ QSizeF AuroraeTab::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
|
||||||
{
|
{
|
||||||
QFont titleFont = KGlobalSettings::windowTitleFont();
|
QFont titleFont = KGlobalSettings::windowTitleFont();
|
||||||
QFontMetricsF fm(titleFont);
|
QFontMetricsF fm(titleFont);
|
||||||
|
const qreal titleHeight = qMax((qreal)m_theme->themeConfig().titleHeight(),
|
||||||
|
m_theme->themeConfig().buttonHeight()*m_theme->buttonSizeFactor() +
|
||||||
|
m_theme->themeConfig().buttonMarginTop());
|
||||||
switch (which) {
|
switch (which) {
|
||||||
case Qt::MinimumSize:
|
case Qt::MinimumSize:
|
||||||
fm.boundingRect(m_caption.left(3)).size();
|
return QSizeF(fm.boundingRect(m_caption.left(3)).width(), titleHeight);
|
||||||
break;
|
|
||||||
case Qt::PreferredSize:
|
case Qt::PreferredSize:
|
||||||
return fm.boundingRect(m_caption).size();
|
return QSizeF(fm.boundingRect(m_caption).width(), titleHeight);
|
||||||
case Qt::MaximumSize:
|
case Qt::MaximumSize:
|
||||||
return QSizeF(scene()->sceneRect().width(), m_theme->themeConfig().titleHeight());
|
return QSizeF(scene()->sceneRect().width(), titleHeight);
|
||||||
default:
|
default:
|
||||||
return QGraphicsWidget::sizeHint(which, constraint);
|
return QGraphicsWidget::sizeHint(which, constraint);
|
||||||
}
|
}
|
||||||
return QGraphicsWidget::sizeHint(which, constraint);
|
return QGraphicsWidget::sizeHint(which, constraint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AuroraeTab::buttonSizesChanged()
|
||||||
|
{
|
||||||
|
updateGeometry();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -39,6 +39,9 @@ public:
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void activeChanged();
|
void activeChanged();
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void buttonSizesChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint = QSizeF()) const;
|
virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint = QSizeF()) const;
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ public:
|
||||||
bool activeCompositing;
|
bool activeCompositing;
|
||||||
KDecorationDefines::BorderSize borderSize;
|
KDecorationDefines::BorderSize borderSize;
|
||||||
bool showTooltips;
|
bool showTooltips;
|
||||||
|
KDecorationDefines::BorderSize buttonSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
AuroraeThemePrivate::AuroraeThemePrivate()
|
AuroraeThemePrivate::AuroraeThemePrivate()
|
||||||
|
@ -56,6 +57,7 @@ AuroraeThemePrivate::AuroraeThemePrivate()
|
||||||
, activeCompositing(true)
|
, activeCompositing(true)
|
||||||
, borderSize(KDecoration::BorderNormal)
|
, borderSize(KDecoration::BorderNormal)
|
||||||
, showTooltips(true)
|
, showTooltips(true)
|
||||||
|
, buttonSize(KDecoration::BorderNormal)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,11 +265,14 @@ const Aurorae::ThemeConfig &AuroraeTheme::themeConfig() const
|
||||||
|
|
||||||
void AuroraeTheme::borders(int& left, int& top, int& right, int& bottom, bool maximized) const
|
void AuroraeTheme::borders(int& left, int& top, int& right, int& bottom, bool maximized) const
|
||||||
{
|
{
|
||||||
|
const qreal titleHeight = qMax((qreal)d->themeConfig.titleHeight(),
|
||||||
|
d->themeConfig.buttonHeight()*buttonSizeFactor() +
|
||||||
|
d->themeConfig.buttonMarginTop());
|
||||||
if (maximized) {
|
if (maximized) {
|
||||||
left = 0;
|
left = 0;
|
||||||
right = 0;
|
right = 0;
|
||||||
bottom = 0;
|
bottom = 0;
|
||||||
top = d->themeConfig.titleHeight() + d->themeConfig.titleEdgeTopMaximized() + d->themeConfig.titleEdgeBottomMaximized();
|
top = titleHeight + d->themeConfig.titleEdgeTopMaximized() + d->themeConfig.titleEdgeBottomMaximized();
|
||||||
} else {
|
} else {
|
||||||
switch (d->borderSize) {
|
switch (d->borderSize) {
|
||||||
case KDecoration::BorderTiny:
|
case KDecoration::BorderTiny:
|
||||||
|
@ -303,7 +308,7 @@ void AuroraeTheme::borders(int& left, int& top, int& right, int& bottom, bool ma
|
||||||
left += d->themeConfig.borderLeft();
|
left += d->themeConfig.borderLeft();
|
||||||
right += d->themeConfig.borderRight();
|
right += d->themeConfig.borderRight();
|
||||||
bottom += d->themeConfig.borderBottom();
|
bottom += d->themeConfig.borderBottom();
|
||||||
top = d->themeConfig.titleHeight() + d->themeConfig.titleEdgeTop() + d->themeConfig.titleEdgeBottom();
|
top = titleHeight + d->themeConfig.titleEdgeTop() + d->themeConfig.titleEdgeBottom();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,4 +378,31 @@ void AuroraeTheme::setShowTooltips(bool show)
|
||||||
emit showTooltipsChanged(show);
|
emit showTooltipsChanged(show);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AuroraeTheme::setButtonSize(KDecorationDefines::BorderSize size)
|
||||||
|
{
|
||||||
|
d->buttonSize = size;
|
||||||
|
emit buttonSizesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal AuroraeTheme::buttonSizeFactor() const
|
||||||
|
{
|
||||||
|
switch (d->buttonSize) {
|
||||||
|
case KDecorationDefines::BorderTiny:
|
||||||
|
return 0.8;
|
||||||
|
case KDecorationDefines::BorderLarge:
|
||||||
|
return 1.2;
|
||||||
|
case KDecorationDefines::BorderVeryLarge:
|
||||||
|
return 1.4;
|
||||||
|
case KDecorationDefines::BorderHuge:
|
||||||
|
return 1.6;
|
||||||
|
case KDecorationDefines::BorderVeryHuge:
|
||||||
|
return 1.8;
|
||||||
|
case KDecorationDefines::BorderOversized:
|
||||||
|
return 2.0;
|
||||||
|
case KDecorationDefines::BorderNormal: // fall through
|
||||||
|
default:
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -104,6 +104,13 @@ public:
|
||||||
QString defaultButtonsRight() const;
|
QString defaultButtonsRight() const;
|
||||||
void setBorderSize(KDecorationDefines::BorderSize size);
|
void setBorderSize(KDecorationDefines::BorderSize size);
|
||||||
bool isShowTooltips() const;
|
bool isShowTooltips() const;
|
||||||
|
/**
|
||||||
|
* Sets the size of the buttons.
|
||||||
|
* The available sizes are identical to border sizes, therefore BorderSize is used.
|
||||||
|
* @param size The buttons size
|
||||||
|
*/
|
||||||
|
void setButtonSize(KDecorationDefines::BorderSize size);
|
||||||
|
qreal buttonSizeFactor() const;
|
||||||
|
|
||||||
// TODO: move to namespace
|
// TODO: move to namespace
|
||||||
static QLatin1String mapButtonToName(AuroraeButtonType type);
|
static QLatin1String mapButtonToName(AuroraeButtonType type);
|
||||||
|
@ -115,6 +122,7 @@ public Q_SLOTS:
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void themeChanged();
|
void themeChanged();
|
||||||
void showTooltipsChanged(bool show);
|
void showTooltipsChanged(bool show);
|
||||||
|
void buttonSizesChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const ThemeConfig &themeConfig() const;
|
const ThemeConfig &themeConfig() const;
|
||||||
|
|
Loading…
Reference in a new issue