Changeset View
Changeset View
Standalone View
Standalone View
kdecoration/breezebutton.cpp
| 1 | /* | 1 | /* | ||
|---|---|---|---|---|---|
| 2 | * Copyright 2014 Martin Gräßlin <mgraesslin@kde.org> | 2 | * Copyright 2014 Martin Gräßlin <mgraesslin@kde.org> | ||
| 3 | * Copyright 2014 Hugo Pereira Da Costa <hugo.pereira@free.fr> | 3 | * Copyright 2014 Hugo Pereira Da Costa <hugo.pereira@free.fr> | ||
| 4 | * Copyright 2020 Paul McAuley <kde@paulmcauley.com> | ||||
| 4 | * | 5 | * | ||
| 5 | * This program is free software; you can redistribute it and/or | 6 | * This program is free software; you can redistribute it and/or | ||
| 6 | * modify it under the terms of the GNU General Public License as | 7 | * modify it under the terms of the GNU General Public License as | ||
| Context not available. | |||||
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 20 | */ | 21 | */ | ||
| 21 | #include "breezebutton.h" | 22 | #include "breezebutton.h" | ||
| 23 | #include "breezerenderdecorationbuttonicon.h" | ||||
| 22 | 24 | | |||
| 23 | #include <KDecoration2/DecoratedClient> | 25 | #include <KDecoration2/DecoratedClient> | ||
| 24 | #include <KColorUtils> | 26 | #include <KColorUtils> | ||
| Context not available. | |||||
| 188 | 190 | | |||
| 189 | // setup painter | 191 | // setup painter | ||
| 190 | QPen pen( foregroundColor ); | 192 | QPen pen( foregroundColor ); | ||
| 191 | pen.setCapStyle( Qt::RoundCap ); | | |||
| 192 | pen.setJoinStyle( Qt::MiterJoin ); | | |||
| 193 | pen.setWidthF( PenWidth::Symbol*qMax((qreal)1.0, 20/width ) ); | 193 | pen.setWidthF( PenWidth::Symbol*qMax((qreal)1.0, 20/width ) ); | ||
| 194 | 194 | | |||
| 195 | painter->setPen( pen ); | 195 | auto d = qobject_cast<Decoration*>( decoration() ); | ||
| 196 | painter->setBrush( Qt::NoBrush ); | 196 | | ||
| 197 | std::unique_ptr<RenderDecorationButtonIcon18By18> iconRenderer; | ||||
| 198 | if (d) iconRenderer = RenderDecorationButtonIcon18By18::factory( painter, pen, d->internalSettings()->buttonIconStyle(), false ); | ||||
| 199 | else iconRenderer = RenderDecorationButtonIcon18By18::factory( painter, pen ); | ||||
| 197 | 200 | | |||
| 198 | switch( type() ) | 201 | switch( type() ) | ||
| 199 | { | 202 | { | ||
| 200 | 203 | | |||
| 201 | case DecorationButtonType::Close: | 204 | case DecorationButtonType::Close: | ||
| 202 | { | 205 | { | ||
| 203 | painter->drawLine( QPointF( 5, 5 ), QPointF( 13, 13 ) ); | 206 | iconRenderer->renderCloseIcon(); | ||
| 204 | painter->drawLine( 13, 5, 5, 13 ); | | |||
| 205 | break; | 207 | break; | ||
| 206 | } | 208 | } | ||
| 207 | 209 | | |||
| 208 | case DecorationButtonType::Maximize: | 210 | case DecorationButtonType::Maximize: | ||
| 209 | { | 211 | { | ||
| 210 | if( isChecked() ) | 212 | if( isChecked() ) iconRenderer->renderRestoreIcon(); | ||
| 211 | { | 213 | else iconRenderer->renderMaximizeIcon(); | ||
| 212 | pen.setJoinStyle( Qt::RoundJoin ); | | |||
| 213 | painter->setPen( pen ); | | |||
| 214 | | ||||
| 215 | painter->drawPolygon( QVector<QPointF>{ | | |||
| 216 | QPointF( 4, 9 ), | | |||
| 217 | QPointF( 9, 4 ), | | |||
| 218 | QPointF( 14, 9 ), | | |||
| 219 | QPointF( 9, 14 )} ); | | |||
| 220 | | ||||
| 221 | } else { | | |||
| 222 | painter->drawPolyline( QVector<QPointF>{ | | |||
| 223 | QPointF( 4, 11 ), | | |||
| 224 | QPointF( 9, 6 ), | | |||
| 225 | QPointF( 14, 11 )}); | | |||
| 226 | } | | |||
| 227 | break; | 214 | break; | ||
| 228 | } | 215 | } | ||
| 229 | 216 | | |||
| 230 | case DecorationButtonType::Minimize: | 217 | case DecorationButtonType::Minimize: | ||
| 231 | { | 218 | { | ||
| 232 | painter->drawPolyline( QVector<QPointF>{ | 219 | iconRenderer->renderMinimizeIcon(); | ||
| 233 | QPointF( 4, 7 ), | | |||
| 234 | QPointF( 9, 12 ), | | |||
| 235 | QPointF( 14, 7 ) }); | | |||
| 236 | break; | 220 | break; | ||
| 237 | } | 221 | } | ||
| 238 | 222 | | |||
| 239 | case DecorationButtonType::OnAllDesktops: | 223 | case DecorationButtonType::OnAllDesktops: | ||
| 240 | { | 224 | { | ||
| 241 | painter->setPen( Qt::NoPen ); | 225 | if( isChecked()) iconRenderer->renderPinnedOnAllDesktopsIcon(); | ||
| 242 | painter->setBrush( foregroundColor ); | 226 | else iconRenderer->renderPinOnAllDesktopsIcon(); | ||
| 243 | | ||||
| 244 | if( isChecked()) | | |||
| 245 | { | | |||
| 246 | | ||||
| 247 | // outer ring | | |||
| 248 | painter->drawEllipse( QRectF( 3, 3, 12, 12 ) ); | | |||
| 249 | | ||||
| 250 | // center dot | | |||
| 251 | QColor backgroundColor( this->backgroundColor() ); | | |||
| 252 | auto d = qobject_cast<Decoration*>( decoration() ); | | |||
| 253 | if( !backgroundColor.isValid() && d ) backgroundColor = d->titleBarColor(); | | |||
| 254 | | ||||
| 255 | if( backgroundColor.isValid() ) | | |||
| 256 | { | | |||
| 257 | painter->setBrush( backgroundColor ); | | |||
| 258 | painter->drawEllipse( QRectF( 8, 8, 2, 2 ) ); | | |||
| 259 | } | | |||
| 260 | | ||||
| 261 | } else { | | |||
| 262 | | ||||
| 263 | painter->drawPolygon( QVector<QPointF> { | | |||
| 264 | QPointF( 6.5, 8.5 ), | | |||
| 265 | QPointF( 12, 3 ), | | |||
| 266 | QPointF( 15, 6 ), | | |||
| 267 | QPointF( 9.5, 11.5 )} ); | | |||
| 268 | | ||||
| 269 | painter->setPen( pen ); | | |||
| 270 | painter->drawLine( QPointF( 5.5, 7.5 ), QPointF( 10.5, 12.5 ) ); | | |||
| 271 | painter->drawLine( QPointF( 12, 6 ), QPointF( 4.5, 13.5 ) ); | | |||
| 272 | } | | |||
| 273 | break; | 227 | break; | ||
| 274 | } | 228 | } | ||
| 275 | 229 | | |||
| 276 | case DecorationButtonType::Shade: | 230 | case DecorationButtonType::Shade: | ||
| 277 | { | 231 | { | ||
| 278 | 232 | | |||
| 279 | if (isChecked()) | 233 | if (isChecked()) iconRenderer->renderUnShadeIcon(); | ||
| 280 | { | 234 | else iconRenderer->renderShadeIcon(); | ||
| 281 | | ||||
| 282 | painter->drawLine( QPointF( 4, 5.5 ), QPointF( 14, 5.5 ) ); | | |||
| 283 | painter->drawPolyline( QVector<QPointF> { | | |||
| 284 | QPointF( 4, 8 ), | | |||
| 285 | QPointF( 9, 13 ), | | |||
| 286 | QPointF( 14, 8 )} ); | | |||
| 287 | | ||||
| 288 | } else { | | |||
| 289 | | ||||
| 290 | painter->drawLine( QPointF( 4, 5.5 ), QPointF( 14, 5.5 ) ); | | |||
| 291 | painter->drawPolyline( QVector<QPointF> { | | |||
| 292 | QPointF( 4, 13 ), | | |||
| 293 | QPointF( 9, 8 ), | | |||
| 294 | QPointF( 14, 13 ) }); | | |||
| 295 | } | | |||
| 296 | | ||||
| 297 | break; | 235 | break; | ||
| 298 | 236 | | |||
| 299 | } | 237 | } | ||
| Context not available. | |||||
| 301 | case DecorationButtonType::KeepBelow: | 239 | case DecorationButtonType::KeepBelow: | ||
| 302 | { | 240 | { | ||
| 303 | 241 | | |||
| 304 | painter->drawPolyline( QVector<QPointF> { | 242 | iconRenderer->renderKeepBehindIcon(); | ||
| 305 | QPointF( 4, 5 ), | | |||
| 306 | QPointF( 9, 10 ), | | |||
| 307 | QPointF( 14, 5 ) }); | | |||
| 308 | | ||||
| 309 | painter->drawPolyline( QVector<QPointF> { | | |||
| 310 | QPointF( 4, 9 ), | | |||
| 311 | QPointF( 9, 14 ), | | |||
| 312 | QPointF( 14, 9 ) }); | | |||
| 313 | break; | 243 | break; | ||
| 314 | 244 | | |||
| 315 | } | 245 | } | ||
| 316 | 246 | | |||
| 317 | case DecorationButtonType::KeepAbove: | 247 | case DecorationButtonType::KeepAbove: | ||
| 318 | { | 248 | { | ||
| 319 | painter->drawPolyline( QVector<QPointF> { | 249 | iconRenderer->renderKeepInFrontIcon(); | ||
| 320 | QPointF( 4, 9 ), | | |||
| 321 | QPointF( 9, 4 ), | | |||
| 322 | QPointF( 14, 9 ) }); | | |||
| 323 | | ||||
| 324 | painter->drawPolyline( QVector<QPointF> { | | |||
| 325 | QPointF( 4, 13 ), | | |||
| 326 | QPointF( 9, 8 ), | | |||
| 327 | QPointF( 14, 13 ) }); | | |||
| 328 | break; | 250 | break; | ||
| 329 | } | 251 | } | ||
| 330 | 252 | | |||
| 331 | 253 | | |||
| 332 | case DecorationButtonType::ApplicationMenu: | 254 | case DecorationButtonType::ApplicationMenu: | ||
| 333 | { | 255 | { | ||
| 334 | painter->drawRect( QRectF( 3.5, 4.5, 11, 1 ) ); | 256 | iconRenderer->renderApplicationMenuIcon(); | ||
| 335 | painter->drawRect( QRectF( 3.5, 8.5, 11, 1 ) ); | | |||
| 336 | painter->drawRect( QRectF( 3.5, 12.5, 11, 1 ) ); | | |||
| 337 | break; | 257 | break; | ||
| 338 | } | 258 | } | ||
| 339 | 259 | | |||
| 340 | case DecorationButtonType::ContextHelp: | 260 | case DecorationButtonType::ContextHelp: | ||
| 341 | { | 261 | { | ||
| 342 | QPainterPath path; | 262 | iconRenderer->renderContextHelpIcon(); | ||
| 343 | path.moveTo( 5, 6 ); | | |||
| 344 | path.arcTo( QRectF( 5, 3.5, 8, 5 ), 180, -180 ); | | |||
| 345 | path.cubicTo( QPointF(12.5, 9.5), QPointF( 9, 7.5 ), QPointF( 9, 11.5 ) ); | | |||
| 346 | painter->drawPath( path ); | | |||
| 347 | | ||||
| 348 | painter->drawRect( QRectF( 9, 15, 0.5, 0.5 ) ); | | |||
| 349 | | ||||
| 350 | break; | 263 | break; | ||
| 351 | } | 264 | } | ||
| 352 | 265 | | |||
| Context not available. | |||||