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:
Martin Gräßlin 2010-04-18 18:54:23 +00:00
parent 6776cfcdb2
commit 65acab3e20
7 changed files with 94 additions and 27 deletions

View file

@ -51,6 +51,7 @@ AuroraeButton::AuroraeButton(AuroraeTheme* theme, AuroraeButtonType type)
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
setAcceptHoverEvents(true);
setAcceptedMouseButtons(Qt::LeftButton);
connect(m_theme, SIGNAL(buttonSizesChanged()), SLOT(buttonSizesChanged()));
}
AuroraeButton::~AuroraeButton()
@ -88,34 +89,36 @@ QSizeF AuroraeButton::sizeHint(Qt::SizeHint which, const QSizeF& constraint) con
{
Q_UNUSED(which)
Q_UNUSED(constraint)
const qreal factor = m_theme->buttonSizeFactor();
switch (m_type) {
case MinimizeButton:
return QSizeF(m_theme->themeConfig().buttonWidthMinimize(),
m_theme->themeConfig().buttonHeight());
return QSizeF(m_theme->themeConfig().buttonWidthMinimize()*factor,
m_theme->themeConfig().buttonHeight()*factor);
case MaximizeButton:
case RestoreButton:
return QSizeF(m_theme->themeConfig().buttonWidthMaximizeRestore(),
m_theme->themeConfig().buttonHeight());
return QSizeF(m_theme->themeConfig().buttonWidthMaximizeRestore()*factor,
m_theme->themeConfig().buttonHeight()*factor);
case CloseButton:
return QSizeF(m_theme->themeConfig().buttonWidthClose(),
m_theme->themeConfig().buttonHeight());
return QSizeF(m_theme->themeConfig().buttonWidthClose()*factor,
m_theme->themeConfig().buttonHeight()*factor);
case AllDesktopsButton:
return QSizeF(m_theme->themeConfig().buttonWidthAllDesktops(),
m_theme->themeConfig().buttonHeight());
return QSizeF(m_theme->themeConfig().buttonWidthAllDesktops()*factor,
m_theme->themeConfig().buttonHeight()*factor);
case KeepAboveButton:
return QSizeF(m_theme->themeConfig().buttonWidthKeepAbove(),
m_theme->themeConfig().buttonHeight());
return QSizeF(m_theme->themeConfig().buttonWidthKeepAbove()*factor,
m_theme->themeConfig().buttonHeight()*factor);
case KeepBelowButton:
return QSizeF(m_theme->themeConfig().buttonWidthKeepBelow(),
m_theme->themeConfig().buttonHeight());
return QSizeF(m_theme->themeConfig().buttonWidthKeepBelow()*factor,
m_theme->themeConfig().buttonHeight()*factor);
case ShadeButton:
return QSizeF(m_theme->themeConfig().buttonWidthShade(),
m_theme->themeConfig().buttonHeight());
return QSizeF(m_theme->themeConfig().buttonWidthShade()*factor,
m_theme->themeConfig().buttonHeight()*factor);
case HelpButton:
return QSizeF(m_theme->themeConfig().buttonWidthHelp(),
m_theme->themeConfig().buttonHeight());
return QSizeF(m_theme->themeConfig().buttonWidthHelp()*factor,
m_theme->themeConfig().buttonHeight()*factor);
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)
@ -309,6 +312,12 @@ void AuroraeButton::setAnimationProgress(qreal progress)
update();
}
void AuroraeButton::buttonSizesChanged()
{
updateGeometry();
static_cast<AuroraeScene*>(scene())->updateLayout();
}
/***********************************************
* AuroraeMaximizeButton
***********************************************/

View file

@ -75,6 +75,9 @@ public:
Q_SIGNALS:
void clicked();
private Q_SLOTS:
void buttonSizesChanged();
protected:
enum ButtonState {
Active = 0x1,

View file

@ -99,7 +99,7 @@ void AuroraeScene::init()
titleLayout->addItem(tab);
m_title->setLayout(titleLayout);
addItem(m_title);
tab->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
tab->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
setActive(m_active, false);
updateLayout();
@ -183,6 +183,8 @@ void AuroraeScene::drawBackground(QPainter *painter, const QRectF &rect)
frame->setEnabledBorders(Plasma::FrameSvg::AllBorders);
}
QRectF r = sceneRect();
const qreal titleHeight = qMax((qreal)conf.titleHeight(),
conf.buttonHeight()*m_theme->buttonSizeFactor() + conf.buttonMarginTop());
if (maximized) {
r = QRectF(conf.paddingLeft(), conf.paddingTop(),
sceneRect().width() - conf.paddingRight() - conf.paddingLeft(),
@ -190,7 +192,7 @@ void AuroraeScene::drawBackground(QPainter *painter, const QRectF &rect)
if (true/*transparentRect().isNull()*/) {
r = QRectF(conf.paddingLeft(), conf.paddingTop(),
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());
@ -257,6 +259,8 @@ void AuroraeScene::updateLayout()
const int left = config.paddingLeft();
const int genericTop = config.paddingTop() + marginTop;
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
const int top = genericTop + config.titleEdgeTopMaximized();
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 titleWidth = m_rightButtons->geometry().left() - config.titleBorderRight() - leftTitle;
m_title->setGeometry(leftTitle, config.paddingTop() + config.titleEdgeTopMaximized(),
titleWidth, config.titleHeight());
titleWidth, titleHeight);
m_title->layout()->invalidate();
} else {
const int top = genericTop + config.titleEdgeTop();
@ -277,7 +281,7 @@ void AuroraeScene::updateLayout()
const int leftTitle = m_leftButtons->geometry().right() + config.titleBorderLeft();
const int titleWidth = m_rightButtons->geometry().left() - config.titleBorderRight() - leftTitle;
m_title->setGeometry(leftTitle, config.paddingTop() + config.titleEdgeTop(),
titleWidth, config.titleHeight());
titleWidth, titleHeight);
m_title->layout()->invalidate();
}
}

View file

@ -43,6 +43,7 @@ AuroraeTab::AuroraeTab(AuroraeTheme* theme, const QString& caption)
setGraphicsEffect(m_effect);
}
setAcceptedMouseButtons(Qt::NoButton);
connect(m_theme, SIGNAL(buttonSizesChanged()), SLOT(buttonSizesChanged()));
}
AuroraeTab::~AuroraeTab()
@ -150,18 +151,25 @@ QSizeF AuroraeTab::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
{
QFont titleFont = KGlobalSettings::windowTitleFont();
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) {
case Qt::MinimumSize:
fm.boundingRect(m_caption.left(3)).size();
break;
return QSizeF(fm.boundingRect(m_caption.left(3)).width(), titleHeight);
case Qt::PreferredSize:
return fm.boundingRect(m_caption).size();
return QSizeF(fm.boundingRect(m_caption).width(), titleHeight);
case Qt::MaximumSize:
return QSizeF(scene()->sceneRect().width(), m_theme->themeConfig().titleHeight());
return QSizeF(scene()->sceneRect().width(), titleHeight);
default:
return QGraphicsWidget::sizeHint(which, constraint);
}
return QGraphicsWidget::sizeHint(which, constraint);
}
void AuroraeTab::buttonSizesChanged()
{
updateGeometry();
}
} // namespace

View file

@ -39,6 +39,9 @@ public:
public Q_SLOTS:
void activeChanged();
private Q_SLOTS:
void buttonSizesChanged();
protected:
virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint = QSizeF()) const;

View file

@ -49,6 +49,7 @@ public:
bool activeCompositing;
KDecorationDefines::BorderSize borderSize;
bool showTooltips;
KDecorationDefines::BorderSize buttonSize;
};
AuroraeThemePrivate::AuroraeThemePrivate()
@ -56,6 +57,7 @@ AuroraeThemePrivate::AuroraeThemePrivate()
, activeCompositing(true)
, borderSize(KDecoration::BorderNormal)
, 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
{
const qreal titleHeight = qMax((qreal)d->themeConfig.titleHeight(),
d->themeConfig.buttonHeight()*buttonSizeFactor() +
d->themeConfig.buttonMarginTop());
if (maximized) {
left = 0;
right = 0;
bottom = 0;
top = d->themeConfig.titleHeight() + d->themeConfig.titleEdgeTopMaximized() + d->themeConfig.titleEdgeBottomMaximized();
top = titleHeight + d->themeConfig.titleEdgeTopMaximized() + d->themeConfig.titleEdgeBottomMaximized();
} else {
switch (d->borderSize) {
case KDecoration::BorderTiny:
@ -303,7 +308,7 @@ void AuroraeTheme::borders(int& left, int& top, int& right, int& bottom, bool ma
left += d->themeConfig.borderLeft();
right += d->themeConfig.borderRight();
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);
}
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

View file

@ -104,6 +104,13 @@ public:
QString defaultButtonsRight() const;
void setBorderSize(KDecorationDefines::BorderSize size);
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
static QLatin1String mapButtonToName(AuroraeButtonType type);
@ -115,6 +122,7 @@ public Q_SLOTS:
Q_SIGNALS:
void themeChanged();
void showTooltipsChanged(bool show);
void buttonSizesChanged();
private:
const ThemeConfig &themeConfig() const;