SHA256
1
0
forked from pool/breeze
breeze/0001-Added-an-explicit-flag-as-output-from-captionRect-to.patch

85 lines
3.6 KiB
Diff

From a8d2104ab36c91053da1fee3ad31d68c979965a7 Mon Sep 17 00:00:00 2001
From: Hugo Pereira Da Costa <hugo.pereira@free.fr>
Date: Thu, 26 Feb 2015 00:17:18 +0100
Subject: [PATCH 1/4] Added an explicit flag as output from captionRect to tell
whether caption must be ellided or not. BUG: 344552
---
kdecoration/breezedecoration.cpp | 18 ++++++++++--------
kdecoration/breezedecoration.h | 8 +++++++-
2 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/kdecoration/breezedecoration.cpp b/kdecoration/breezedecoration.cpp
index 3b1479a82b19ca8427690ccc7b00b2f36f2289aa..f63306524e1301477904f284037c54ed09bbe276 100644
--- a/kdecoration/breezedecoration.cpp
+++ b/kdecoration/breezedecoration.cpp
@@ -440,10 +440,13 @@ namespace Breeze
// draw caption
painter->setFont(s->font());
- const QRect cR = captionRect();
- const QString caption = painter->fontMetrics().elidedText(c->caption(), Qt::ElideMiddle, cR.width());
+ const auto cR = captionRect();
+ const QString caption = cR.second ?
+ painter->fontMetrics().elidedText(c->caption(), Qt::ElideMiddle, cR.first.width()):
+ c->caption();
+
painter->setPen(m_colorSettings.font(c->isActive()));
- painter->drawText(cR, Qt::AlignVCenter| Qt::AlignLeft | Qt::TextSingleLine, caption);
+ painter->drawText(cR.first, Qt::AlignVCenter| Qt::AlignLeft | Qt::TextSingleLine, caption);
// draw all buttons
m_leftButtons->paint(painter, repaintRegion);
@@ -470,7 +473,7 @@ namespace Breeze
{ return borderTop() - settings()->smallSpacing()*(Metrics::TitleBar_BottomMargin + Metrics::TitleBar_TopMargin ) - 1; }
//________________________________________________________________
- QRect Decoration::captionRect() const
+ QPair<QRect,bool> Decoration::captionRect() const
{
const int leftOffset = m_leftButtons->geometry().x() + m_leftButtons->geometry().width() + Metrics::TitleBar_SideMargin*settings()->smallSpacing();
const int rightOffset = size().width() - m_rightButtons->geometry().x() + Metrics::TitleBar_SideMargin*settings()->smallSpacing();
@@ -480,9 +483,8 @@ namespace Breeze
boundingRect.setTop( yOffset );
boundingRect.setHeight( captionHeight() );
- /* need to increase the bounding rect because it is sometime (font dependent)
- too small, resulting in text being elided */
- boundingRect.setWidth( boundingRect.width()+4 );
+ // store original width to detect when text ellision is needed
+ const int boundingRectWidth( boundingRect.width() );
switch( m_internalSettings->titleAlignment() )
{
@@ -518,7 +520,7 @@ namespace Breeze
boundingRect.setLeft( qMax( boundingRect.left(), leftOffset ) );
}
- return boundingRect;
+ return qMakePair( boundingRect, boundingRect.width() < boundingRectWidth );
}
diff --git a/kdecoration/breezedecoration.h b/kdecoration/breezedecoration.h
index 9eb6c659fb657e66d2c4dc006b22beef7b22a02c..ccdc6a67c65aad4a17e083b3f3360fc3cb57ddbc 100644
--- a/kdecoration/breezedecoration.h
+++ b/kdecoration/breezedecoration.h
@@ -109,7 +109,13 @@ namespace Breeze
void updateAnimationState();
private:
- QRect captionRect() const;
+
+ /**
+ return the smallest rect in which caption will be drawn,
+ properly positionned inside the title bar. Second return parameter
+ is set to true when text ellision is required
+ */
+ QPair<QRect,bool> captionRect() const;
void createButtons();
void paintTitleBar(QPainter *painter, const QRect &repaintRegion);
--
2.3.0