Changeset View
Changeset View
Standalone View
Standalone View
plugins/scenes/qpainter/scene_qpainter.cpp
Show First 20 Lines • Show All 185 Lines • ▼ Show 20 Line(s) | 180 | { | |||
---|---|---|---|---|---|
186 | painter->drawImage(w->geometry(), buffer); | 186 | painter->drawImage(w->geometry(), buffer); | ||
187 | } | 187 | } | ||
188 | 188 | | |||
189 | Scene::Window *SceneQPainter::createWindow(Toplevel *toplevel) | 189 | Scene::Window *SceneQPainter::createWindow(Toplevel *toplevel) | ||
190 | { | 190 | { | ||
191 | return new SceneQPainter::Window(this, toplevel); | 191 | return new SceneQPainter::Window(this, toplevel); | ||
192 | } | 192 | } | ||
193 | 193 | | |||
194 | Scene::EffectFrame *SceneQPainter::createEffectFrame(EffectFrameImpl *frame) | | |||
195 | { | | |||
196 | return new QPainterEffectFrame(frame, this); | | |||
197 | } | | |||
198 | | ||||
199 | Shadow *SceneQPainter::createShadow(Toplevel *toplevel) | 194 | Shadow *SceneQPainter::createShadow(Toplevel *toplevel) | ||
200 | { | 195 | { | ||
201 | return new SceneQPainterShadow(toplevel); | 196 | return new SceneQPainterShadow(toplevel); | ||
202 | } | 197 | } | ||
203 | 198 | | |||
204 | void SceneQPainter::screenGeometryChanged(const QSize &size) | 199 | void SceneQPainter::screenGeometryChanged(const QSize &size) | ||
205 | { | 200 | { | ||
206 | Scene::screenGeometryChanged(size); | 201 | Scene::screenGeometryChanged(size); | ||
▲ Show 20 Lines • Show All 254 Lines • ▼ Show 20 Line(s) | |||||
461 | bool QPainterWindowPixmap::isValid() const | 456 | bool QPainterWindowPixmap::isValid() const | ||
462 | { | 457 | { | ||
463 | if (!m_image.isNull()) { | 458 | if (!m_image.isNull()) { | ||
464 | return true; | 459 | return true; | ||
465 | } | 460 | } | ||
466 | return WindowPixmap::isValid(); | 461 | return WindowPixmap::isValid(); | ||
467 | } | 462 | } | ||
468 | 463 | | |||
469 | QPainterEffectFrame::QPainterEffectFrame(EffectFrameImpl *frame, SceneQPainter *scene) | | |||
470 | : Scene::EffectFrame(frame) | | |||
471 | , m_scene(scene) | | |||
472 | { | | |||
473 | } | | |||
474 | | ||||
475 | QPainterEffectFrame::~QPainterEffectFrame() | | |||
476 | { | | |||
477 | } | | |||
478 | | ||||
479 | void QPainterEffectFrame::render(QRegion region, double opacity, double frameOpacity) | | |||
480 | { | | |||
481 | Q_UNUSED(region) | | |||
482 | Q_UNUSED(opacity) | | |||
483 | // TODO: adjust opacity | | |||
484 | if (m_effectFrame->geometry().isEmpty()) { | | |||
485 | return; // Nothing to display | | |||
486 | } | | |||
487 | QPainter *painter = m_scene->scenePainter(); | | |||
488 | | ||||
489 | | ||||
490 | // Render the actual frame | | |||
491 | if (m_effectFrame->style() == EffectFrameUnstyled) { | | |||
492 | painter->save(); | | |||
493 | painter->setPen(Qt::NoPen); | | |||
494 | QColor color(Qt::black); | | |||
495 | color.setAlphaF(frameOpacity); | | |||
496 | painter->setBrush(color); | | |||
497 | painter->setRenderHint(QPainter::Antialiasing); | | |||
498 | painter->drawRoundedRect(m_effectFrame->geometry().adjusted(-5, -5, 5, 5), 5.0, 5.0); | | |||
499 | painter->restore(); | | |||
500 | } else if (m_effectFrame->style() == EffectFrameStyled) { | | |||
501 | qreal left, top, right, bottom; | | |||
502 | m_effectFrame->frame().getMargins(left, top, right, bottom); // m_geometry is the inner geometry | | |||
503 | QRect geom = m_effectFrame->geometry().adjusted(-left, -top, right, bottom); | | |||
504 | painter->drawPixmap(geom, m_effectFrame->frame().framePixmap()); | | |||
505 | } | | |||
506 | if (!m_effectFrame->selection().isNull()) { | | |||
507 | painter->drawPixmap(m_effectFrame->selection(), m_effectFrame->selectionFrame().framePixmap()); | | |||
508 | } | | |||
509 | | ||||
510 | // Render icon | | |||
511 | if (!m_effectFrame->icon().isNull() && !m_effectFrame->iconSize().isEmpty()) { | | |||
512 | const QPoint topLeft(m_effectFrame->geometry().x(), | | |||
513 | m_effectFrame->geometry().center().y() - m_effectFrame->iconSize().height() / 2); | | |||
514 | | ||||
515 | const QRect geom = QRect(topLeft, m_effectFrame->iconSize()); | | |||
516 | painter->drawPixmap(geom, m_effectFrame->icon().pixmap(m_effectFrame->iconSize())); | | |||
517 | } | | |||
518 | | ||||
519 | // Render text | | |||
520 | if (!m_effectFrame->text().isEmpty()) { | | |||
521 | // Determine position on texture to paint text | | |||
522 | QRect rect(QPoint(0, 0), m_effectFrame->geometry().size()); | | |||
523 | if (!m_effectFrame->icon().isNull() && !m_effectFrame->iconSize().isEmpty()) { | | |||
524 | rect.setLeft(m_effectFrame->iconSize().width()); | | |||
525 | } | | |||
526 | | ||||
527 | // If static size elide text as required | | |||
528 | QString text = m_effectFrame->text(); | | |||
529 | if (m_effectFrame->isStatic()) { | | |||
530 | QFontMetrics metrics(m_effectFrame->text()); | | |||
531 | text = metrics.elidedText(text, Qt::ElideRight, rect.width()); | | |||
532 | } | | |||
533 | | ||||
534 | painter->save(); | | |||
535 | painter->setFont(m_effectFrame->font()); | | |||
536 | if (m_effectFrame->style() == EffectFrameStyled) { | | |||
537 | painter->setPen(m_effectFrame->styledTextColor()); | | |||
538 | } else { | | |||
539 | // TODO: What about no frame? Custom color setting required | | |||
540 | painter->setPen(Qt::white); | | |||
541 | } | | |||
542 | painter->drawText(rect.translated(m_effectFrame->geometry().topLeft()), m_effectFrame->alignment(), text); | | |||
543 | painter->restore(); | | |||
544 | } | | |||
545 | } | | |||
546 | | ||||
547 | //**************************************** | 464 | //**************************************** | ||
548 | // QPainterShadow | 465 | // QPainterShadow | ||
549 | //**************************************** | 466 | //**************************************** | ||
550 | SceneQPainterShadow::SceneQPainterShadow(Toplevel* toplevel) | 467 | SceneQPainterShadow::SceneQPainterShadow(Toplevel* toplevel) | ||
551 | : Shadow(toplevel) | 468 | : Shadow(toplevel) | ||
552 | { | 469 | { | ||
553 | } | 470 | } | ||
554 | 471 | | |||
▲ Show 20 Lines • Show All 349 Lines • Show Last 20 Lines |