You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
3.5 KiB
85 lines
3.5 KiB
10 years ago
|
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 3/8] 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 3b1479a..f633065 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 9eb6c65..ccdc6a6 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.1
|
||
|
|