Changeset View
Changeset View
Standalone View
Standalone View
kdecoration/breezedecoration.cpp
Show First 20 Lines • Show All 176 Lines • ▼ Show 20 Line(s) | 152 | { | |||
---|---|---|---|---|---|
177 | // full reconfiguration | 177 | // full reconfiguration | ||
178 | connect(s.data(), &KDecoration2::DecorationSettings::reconfigured, this, &Decoration::reconfigure); | 178 | connect(s.data(), &KDecoration2::DecorationSettings::reconfigured, this, &Decoration::reconfigure); | ||
179 | connect(s.data(), &KDecoration2::DecorationSettings::reconfigured, SettingsProvider::self(), &SettingsProvider::reconfigure, Qt::UniqueConnection ); | 179 | connect(s.data(), &KDecoration2::DecorationSettings::reconfigured, SettingsProvider::self(), &SettingsProvider::reconfigure, Qt::UniqueConnection ); | ||
180 | connect(s.data(), &KDecoration2::DecorationSettings::reconfigured, this, &Decoration::updateButtonsGeometryDelayed); | 180 | connect(s.data(), &KDecoration2::DecorationSettings::reconfigured, this, &Decoration::updateButtonsGeometryDelayed); | ||
181 | 181 | | |||
182 | connect(c, &KDecoration2::DecoratedClient::adjacentScreenEdgesChanged, this, &Decoration::recalculateBorders); | 182 | connect(c, &KDecoration2::DecoratedClient::adjacentScreenEdgesChanged, this, &Decoration::recalculateBorders); | ||
183 | connect(c, &KDecoration2::DecoratedClient::maximizedHorizontallyChanged, this, &Decoration::recalculateBorders); | 183 | connect(c, &KDecoration2::DecoratedClient::maximizedHorizontallyChanged, this, &Decoration::recalculateBorders); | ||
184 | connect(c, &KDecoration2::DecoratedClient::maximizedVerticallyChanged, this, &Decoration::recalculateBorders); | 184 | connect(c, &KDecoration2::DecoratedClient::maximizedVerticallyChanged, this, &Decoration::recalculateBorders); | ||
185 | connect(c, &KDecoration2::DecoratedClient::shadedChanged, this, &Decoration::recalculateBorders); | ||||
185 | connect(c, &KDecoration2::DecoratedClient::captionChanged, this, | 186 | connect(c, &KDecoration2::DecoratedClient::captionChanged, this, | ||
186 | [this]() | 187 | [this]() | ||
187 | { | 188 | { | ||
188 | // update the caption area | 189 | // update the caption area | ||
189 | update(titleBar()); | 190 | update(titleBar()); | ||
190 | } | 191 | } | ||
191 | ); | 192 | ); | ||
192 | 193 | | |||
193 | connect(c, &KDecoration2::DecoratedClient::activeChanged, this, &Decoration::updateAnimationState); | 194 | connect(c, &KDecoration2::DecoratedClient::activeChanged, this, &Decoration::updateAnimationState); | ||
194 | connect(c, &KDecoration2::DecoratedClient::paletteChanged, this, | 195 | connect(c, &KDecoration2::DecoratedClient::paletteChanged, this, | ||
195 | [this]() { | 196 | [this]() { | ||
196 | auto c = client().data(); | 197 | auto c = client().data(); | ||
197 | m_useSeparator = (c->palette().color( QPalette::Window ) != c->color( ColorGroup::Active, ColorRole::TitleBar ) ); | 198 | m_useSeparator = (c->palette().color( QPalette::Window ) != c->color( ColorGroup::Active, ColorRole::TitleBar ) ); | ||
198 | update(); | 199 | update(); | ||
199 | } | 200 | } | ||
200 | ); | 201 | ); | ||
201 | connect(c, &KDecoration2::DecoratedClient::widthChanged, this, &Decoration::updateTitleBar); | 202 | connect(c, &KDecoration2::DecoratedClient::widthChanged, this, &Decoration::updateTitleBar); | ||
202 | connect(c, &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::updateTitleBar); | 203 | connect(c, &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::updateTitleBar); | ||
203 | connect(c, &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::setOpaque); | 204 | connect(c, &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::setOpaque); | ||
204 | 205 | | |||
205 | connect(c, &KDecoration2::DecoratedClient::widthChanged, this, &Decoration::updateButtonsGeometry); | 206 | connect(c, &KDecoration2::DecoratedClient::widthChanged, this, &Decoration::updateButtonsGeometry); | ||
206 | connect(c, &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::updateButtonsGeometry); | 207 | connect(c, &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::updateButtonsGeometry); | ||
207 | connect(c, &KDecoration2::DecoratedClient::shadedChanged, this, &Decoration::recalculateBorders); | 208 | connect(c, &KDecoration2::DecoratedClient::adjacentScreenEdgesChanged, this, &Decoration::updateButtonsGeometry); | ||
208 | connect(c, &KDecoration2::DecoratedClient::shadedChanged, this, &Decoration::updateButtonsGeometry); | 209 | connect(c, &KDecoration2::DecoratedClient::shadedChanged, this, &Decoration::updateButtonsGeometry); | ||
209 | 210 | | |||
210 | createButtons(); | 211 | createButtons(); | ||
211 | createShadow(); | 212 | createShadow(); | ||
212 | } | 213 | } | ||
213 | 214 | | |||
214 | //________________________________________________________________ | 215 | //________________________________________________________________ | ||
215 | void Decoration::updateTitleBar() | 216 | void Decoration::updateTitleBar() | ||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | 293 | { | |||
307 | else deleteSizeGrip(); | 308 | else deleteSizeGrip(); | ||
308 | 309 | | |||
309 | } | 310 | } | ||
310 | 311 | | |||
311 | //________________________________________________________________ | 312 | //________________________________________________________________ | ||
312 | void Decoration::recalculateBorders() | 313 | void Decoration::recalculateBorders() | ||
313 | { | 314 | { | ||
314 | auto s = settings(); | 315 | auto s = settings(); | ||
315 | auto c = client().data(); | | |||
316 | auto edges = c->adjacentScreenEdges(); | | |||
317 | 316 | | |||
318 | // left, right and bottom borders | 317 | // left, right and bottom borders | ||
319 | auto testFlag = [&]( Qt::Edge edge ) { return edges.testFlag(edge) && !m_internalSettings->drawBorderOnMaximizedWindows(); }; | 318 | const int left = isLeftEdge() ? 0 : borderSize(); | ||
320 | const int left = isMaximizedHorizontally() || testFlag(Qt::LeftEdge) ? 0 : borderSize(); | 319 | const int right = isRightEdge() ? 0 : borderSize(); | ||
321 | const int right = isMaximizedHorizontally() || testFlag(Qt::RightEdge) ? 0 : borderSize(); | 320 | const int bottom = isBottomEdge() ? 0 : borderSize(true); | ||
322 | const int bottom = isMaximizedVertically() || c->isShaded() || testFlag(Qt::BottomEdge) ? 0 : borderSize(true); | | |||
323 | 321 | | |||
324 | int top = 0; | 322 | int top = 0; | ||
325 | if( hideTitleBar() ) top = bottom; | 323 | if( hideTitleBar() ) top = bottom; | ||
326 | else { | 324 | else { | ||
327 | 325 | | |||
328 | QFontMetrics fm(s->font()); | 326 | QFontMetrics fm(s->font()); | ||
329 | top += qMax(fm.height(), buttonHeight() ); | 327 | top += qMax(fm.height(), buttonHeight() ); | ||
330 | 328 | | |||
Show All 37 Lines | |||||
368 | 366 | | |||
369 | //________________________________________________________________ | 367 | //________________________________________________________________ | ||
370 | void Decoration::updateButtonsGeometryDelayed() | 368 | void Decoration::updateButtonsGeometryDelayed() | ||
371 | { QTimer::singleShot( 0, this, &Decoration::updateButtonsGeometry ); } | 369 | { QTimer::singleShot( 0, this, &Decoration::updateButtonsGeometry ); } | ||
372 | 370 | | |||
373 | //________________________________________________________________ | 371 | //________________________________________________________________ | ||
374 | void Decoration::updateButtonsGeometry() | 372 | void Decoration::updateButtonsGeometry() | ||
375 | { | 373 | { | ||
376 | auto s = settings(); | 374 | const auto s = settings(); | ||
377 | 375 | | |||
378 | // adjust button position | 376 | // adjust button position | ||
379 | const int bHeight = captionHeight() + (isMaximized() ? s->smallSpacing()*Metrics::TitleBar_TopMargin:0); | 377 | const int bHeight = captionHeight() + (isTopEdge() ? s->smallSpacing()*Metrics::TitleBar_TopMargin:0); | ||
380 | const int bWidth = buttonHeight(); | 378 | const int bWidth = buttonHeight(); | ||
381 | const int verticalOffset = (isMaximized() ? s->smallSpacing()*Metrics::TitleBar_TopMargin:0) + (captionHeight()-buttonHeight())/2; | 379 | const int verticalOffset = (isTopEdge() ? s->smallSpacing()*Metrics::TitleBar_TopMargin:0) + (captionHeight()-buttonHeight())/2; | ||
382 | foreach( const QPointer<KDecoration2::DecorationButton>& button, m_leftButtons->buttons() + m_rightButtons->buttons() ) | 380 | foreach( const QPointer<KDecoration2::DecorationButton>& button, m_leftButtons->buttons() + m_rightButtons->buttons() ) | ||
383 | { | 381 | { | ||
384 | button.data()->setGeometry( QRectF( QPoint( 0, 0 ), QSizeF( bWidth, bHeight ) ) ); | 382 | button.data()->setGeometry( QRectF( QPoint( 0, 0 ), QSizeF( bWidth, bHeight ) ) ); | ||
385 | static_cast<Button*>( button.data() )->setOffset( QPointF( 0, verticalOffset ) ); | 383 | static_cast<Button*>( button.data() )->setOffset( QPointF( 0, verticalOffset ) ); | ||
386 | static_cast<Button*>( button.data() )->setIconSize( QSize( bWidth, bWidth ) ); | 384 | static_cast<Button*>( button.data() )->setIconSize( QSize( bWidth, bWidth ) ); | ||
387 | } | 385 | } | ||
388 | 386 | | |||
389 | // left buttons | 387 | // left buttons | ||
390 | if( !m_leftButtons->buttons().isEmpty() ) | 388 | if( !m_leftButtons->buttons().isEmpty() ) | ||
391 | { | 389 | { | ||
392 | 390 | | |||
393 | // spacing | 391 | // spacing | ||
394 | m_leftButtons->setSpacing(s->smallSpacing()*Metrics::TitleBar_ButtonSpacing); | 392 | m_leftButtons->setSpacing(s->smallSpacing()*Metrics::TitleBar_ButtonSpacing); | ||
395 | 393 | | |||
396 | // padding | 394 | // padding | ||
397 | const int vPadding = isMaximized() ? 0 : s->smallSpacing()*Metrics::TitleBar_TopMargin; | 395 | const int vPadding = isTopEdge() ? 0 : s->smallSpacing()*Metrics::TitleBar_TopMargin; | ||
398 | const int hPadding = s->smallSpacing()*Metrics::TitleBar_SideMargin; | 396 | const int hPadding = s->smallSpacing()*Metrics::TitleBar_SideMargin; | ||
399 | if( isMaximizedHorizontally() ) | 397 | if( isLeftEdge() ) | ||
400 | { | 398 | { | ||
401 | // add offsets on the side buttons, to preserve padding, but satisfy Fitts law | 399 | // add offsets on the side buttons, to preserve padding, but satisfy Fitts law | ||
402 | auto button = static_cast<Button*>( m_leftButtons->buttons().front().data() ); | 400 | auto button = static_cast<Button*>( m_leftButtons->buttons().front().data() ); | ||
403 | button->setGeometry( QRectF( QPoint( 0, 0 ), QSizeF( bWidth + hPadding, bHeight ) ) ); | 401 | button->setGeometry( QRectF( QPoint( 0, 0 ), QSizeF( bWidth + hPadding, bHeight ) ) ); | ||
404 | button->setFlag( Button::FlagFirstInList ); | 402 | button->setFlag( Button::FlagFirstInList ); | ||
405 | button->setHorizontalOffset( hPadding ); | 403 | button->setHorizontalOffset( hPadding ); | ||
406 | 404 | | |||
407 | m_leftButtons->setPos(QPointF(0, vPadding)); | 405 | m_leftButtons->setPos(QPointF(0, vPadding)); | ||
408 | 406 | | |||
409 | } else m_leftButtons->setPos(QPointF(hPadding + borderLeft(), vPadding)); | 407 | } else m_leftButtons->setPos(QPointF(hPadding + borderLeft(), vPadding)); | ||
410 | 408 | | |||
411 | } | 409 | } | ||
412 | 410 | | |||
413 | // right buttons | 411 | // right buttons | ||
414 | if( !m_rightButtons->buttons().isEmpty() ) | 412 | if( !m_rightButtons->buttons().isEmpty() ) | ||
415 | { | 413 | { | ||
416 | 414 | | |||
417 | // spacing | 415 | // spacing | ||
418 | m_rightButtons->setSpacing(s->smallSpacing()*Metrics::TitleBar_ButtonSpacing); | 416 | m_rightButtons->setSpacing(s->smallSpacing()*Metrics::TitleBar_ButtonSpacing); | ||
419 | 417 | | |||
420 | // padding | 418 | // padding | ||
421 | const int vPadding = isMaximized() ? 0 : s->smallSpacing()*Metrics::TitleBar_TopMargin; | 419 | const int vPadding = isTopEdge() ? 0 : s->smallSpacing()*Metrics::TitleBar_TopMargin; | ||
422 | const int hPadding = s->smallSpacing()*Metrics::TitleBar_SideMargin; | 420 | const int hPadding = s->smallSpacing()*Metrics::TitleBar_SideMargin; | ||
423 | if( isMaximizedHorizontally() ) | 421 | if( isRightEdge() ) | ||
424 | { | 422 | { | ||
425 | 423 | | |||
426 | auto button = static_cast<Button*>( m_rightButtons->buttons().back().data() ); | 424 | auto button = static_cast<Button*>( m_rightButtons->buttons().back().data() ); | ||
427 | button->setGeometry( QRectF( QPoint( 0, 0 ), QSizeF( bWidth + hPadding, bHeight ) ) ); | 425 | button->setGeometry( QRectF( QPoint( 0, 0 ), QSizeF( bWidth + hPadding, bHeight ) ) ); | ||
428 | button->setFlag( Button::FlagLastInList ); | 426 | button->setFlag( Button::FlagLastInList ); | ||
429 | 427 | | |||
430 | m_rightButtons->setPos(QPointF(size().width() - m_rightButtons->geometry().width(), vPadding)); | 428 | m_rightButtons->setPos(QPointF(size().width() - m_rightButtons->geometry().width(), vPadding)); | ||
431 | 429 | | |||
432 | } else m_rightButtons->setPos(QPointF(size().width() - m_rightButtons->geometry().width() - hPadding - borderRight(), vPadding)); | 430 | } else m_rightButtons->setPos(QPointF(size().width() - m_rightButtons->geometry().width() - hPadding - borderRight(), vPadding)); | ||
433 | 431 | | |||
434 | } | 432 | } | ||
435 | 433 | | |||
436 | update(); | 434 | update(); | ||
437 | 435 | | |||
438 | | ||||
439 | } | 436 | } | ||
440 | 437 | | |||
441 | //________________________________________________________________ | 438 | //________________________________________________________________ | ||
442 | void Decoration::paint(QPainter *painter, const QRect &repaintRegion) | 439 | void Decoration::paint(QPainter *painter, const QRect &repaintRegion) | ||
443 | { | 440 | { | ||
444 | // TODO: optimize based on repaintRegion | 441 | // TODO: optimize based on repaintRegion | ||
445 | auto c = client().data(); | 442 | auto c = client().data(); | ||
446 | auto s = settings(); | 443 | auto s = settings(); | ||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Line(s) | 507 | { | |||
512 | painter->drawRect(titleRect); | 509 | painter->drawRect(titleRect); | ||
513 | 510 | | |||
514 | } else if( c->isShaded() ) { | 511 | } else if( c->isShaded() ) { | ||
515 | 512 | | |||
516 | painter->drawRoundedRect(titleRect, Metrics::Frame_FrameRadius, Metrics::Frame_FrameRadius); | 513 | painter->drawRoundedRect(titleRect, Metrics::Frame_FrameRadius, Metrics::Frame_FrameRadius); | ||
517 | 514 | | |||
518 | } else { | 515 | } else { | ||
519 | 516 | | |||
520 | // we make the rect a little bit larger to be able to clip away the rounded corners on bottom | | |||
521 | painter->setClipRect(titleRect, Qt::IntersectClip); | 517 | painter->setClipRect(titleRect, Qt::IntersectClip); | ||
522 | painter->drawRoundedRect(titleRect.adjusted(0, 0, 0, Metrics::Frame_FrameRadius), Metrics::Frame_FrameRadius, Metrics::Frame_FrameRadius); | 518 | | ||
519 | // the rect is made a little bit larger to be able to clip away the rounded corners at the bottom and sides | ||||
520 | painter->drawRoundedRect(titleRect.adjusted( | ||||
521 | isLeftEdge() ? -Metrics::Frame_FrameRadius:0, | ||||
522 | isTopEdge() ? -Metrics::Frame_FrameRadius:0, | ||||
523 | isRightEdge() ? Metrics::Frame_FrameRadius:0, | ||||
524 | Metrics::Frame_FrameRadius), | ||||
525 | Metrics::Frame_FrameRadius, Metrics::Frame_FrameRadius); | ||||
523 | 526 | | |||
524 | } | 527 | } | ||
525 | 528 | | |||
526 | const QColor outlineColor( this->outlineColor() ); | 529 | const QColor outlineColor( this->outlineColor() ); | ||
527 | if( !c->isShaded() && outlineColor.isValid() ) | 530 | if( !c->isShaded() && outlineColor.isValid() ) | ||
528 | { | 531 | { | ||
529 | // outline | 532 | // outline | ||
530 | painter->setRenderHint( QPainter::Antialiasing, false ); | 533 | painter->setRenderHint( QPainter::Antialiasing, false ); | ||
▲ Show 20 Lines • Show All 214 Lines • Show Last 20 Lines |