Changeset View
Changeset View
Standalone View
Standalone View
effects.cpp
Show First 20 Lines • Show All 451 Lines • ▼ Show 20 Line(s) | |||||
452 | } | 452 | } | ||
453 | 453 | | |||
454 | void EffectsHandlerImpl::paintEffectFrame(EffectFrame* frame, const QRegion ®ion, double opacity, double frameOpacity) | 454 | void EffectsHandlerImpl::paintEffectFrame(EffectFrame* frame, const QRegion ®ion, double opacity, double frameOpacity) | ||
455 | { | 455 | { | ||
456 | if (m_currentPaintEffectFrameIterator != m_activeEffects.constEnd()) { | 456 | if (m_currentPaintEffectFrameIterator != m_activeEffects.constEnd()) { | ||
457 | (*m_currentPaintEffectFrameIterator++)->paintEffectFrame(frame, region, opacity, frameOpacity); | 457 | (*m_currentPaintEffectFrameIterator++)->paintEffectFrame(frame, region, opacity, frameOpacity); | ||
458 | --m_currentPaintEffectFrameIterator; | 458 | --m_currentPaintEffectFrameIterator; | ||
459 | } else { | 459 | } else { | ||
460 | const EffectFrameImpl* frameImpl = static_cast<const EffectFrameImpl*>(frame); | 460 | frame->render(region, opacity, frameOpacity); | ||
461 | frameImpl->finalRender(region, opacity, frameOpacity); | | |||
462 | } | 461 | } | ||
463 | } | 462 | } | ||
464 | 463 | | |||
465 | void EffectsHandlerImpl::postPaintWindow(EffectWindow* w) | 464 | void EffectsHandlerImpl::postPaintWindow(EffectWindow* w) | ||
466 | { | 465 | { | ||
467 | if (m_currentPaintWindowIterator != m_activeEffects.constEnd()) { | 466 | if (m_currentPaintWindowIterator != m_activeEffects.constEnd()) { | ||
468 | (*m_currentPaintWindowIterator++)->postPaintWindow(w); | 467 | (*m_currentPaintWindowIterator++)->postPaintWindow(w); | ||
469 | --m_currentPaintWindowIterator; | 468 | --m_currentPaintWindowIterator; | ||
▲ Show 20 Lines • Show All 1071 Lines • ▼ Show 20 Line(s) | |||||
1541 | KWayland::Server::Display *EffectsHandlerImpl::waylandDisplay() const | 1540 | KWayland::Server::Display *EffectsHandlerImpl::waylandDisplay() const | ||
1542 | { | 1541 | { | ||
1543 | if (waylandServer()) { | 1542 | if (waylandServer()) { | ||
1544 | return waylandServer()->display(); | 1543 | return waylandServer()->display(); | ||
1545 | } | 1544 | } | ||
1546 | return nullptr; | 1545 | return nullptr; | ||
1547 | } | 1546 | } | ||
1548 | 1547 | | |||
1549 | EffectFrame* EffectsHandlerImpl::effectFrame(EffectFrameStyle style, bool staticSize, const QPoint& position, Qt::Alignment alignment) const | | |||
1550 | { | | |||
1551 | return new EffectFrameImpl(style, staticSize, position, alignment); | | |||
1552 | } | | |||
1553 | | ||||
1554 | | ||||
1555 | QVariant EffectsHandlerImpl::kwinOption(KWinOption kwopt) | 1548 | QVariant EffectsHandlerImpl::kwinOption(KWinOption kwopt) | ||
1556 | { | 1549 | { | ||
1557 | switch (kwopt) { | 1550 | switch (kwopt) { | ||
1558 | case CloseButtonCorner: | 1551 | case CloseButtonCorner: | ||
1559 | // TODO: this could become per window and be derived from the actual position in the deco | 1552 | // TODO: this could become per window and be derived from the actual position in the deco | ||
1560 | return Decoration::DecorationBridge::self()->settings()->decorationButtonsLeft().contains(KDecoration2::DecorationButtonType::Close) ? Qt::TopLeftCorner : Qt::TopRightCorner; | 1553 | return Decoration::DecorationBridge::self()->settings()->decorationButtonsLeft().contains(KDecoration2::DecorationButtonType::Close) ? Qt::TopLeftCorner : Qt::TopRightCorner; | ||
1561 | case SwitchDesktopOnScreenEdge: | 1554 | case SwitchDesktopOnScreenEdge: | ||
1562 | return ScreenEdges::self()->isDesktopSwitching(); | 1555 | return ScreenEdges::self()->isDesktopSwitching(); | ||
▲ Show 20 Lines • Show All 602 Lines • ▼ Show 20 Line(s) | 2156 | { | |||
2165 | EffectWindowList ret; | 2158 | EffectWindowList ret; | ||
2166 | ret.reserve(memberList.size()); | 2159 | ret.reserve(memberList.size()); | ||
2167 | std::transform(std::cbegin(memberList), std::cend(memberList), | 2160 | std::transform(std::cbegin(memberList), std::cend(memberList), | ||
2168 | std::back_inserter(ret), | 2161 | std::back_inserter(ret), | ||
2169 | [](auto toplevel) { return toplevel->effectWindow(); }); | 2162 | [](auto toplevel) { return toplevel->effectWindow(); }); | ||
2170 | return ret; | 2163 | return ret; | ||
2171 | } | 2164 | } | ||
2172 | 2165 | | |||
2173 | //**************************************** | | |||
2174 | // EffectFrameImpl | | |||
2175 | //**************************************** | | |||
2176 | | ||||
2177 | EffectFrameImpl::EffectFrameImpl(EffectFrameStyle style, bool staticSize, QPoint position, Qt::Alignment alignment) | | |||
2178 | : QObject(nullptr) | | |||
2179 | , EffectFrame() | | |||
2180 | , m_style(style) | | |||
2181 | , m_static(staticSize) | | |||
2182 | , m_point(position) | | |||
2183 | , m_alignment(alignment) | | |||
2184 | , m_shader(nullptr) | | |||
2185 | , m_theme(new Plasma::Theme(this)) | | |||
2186 | { | | |||
2187 | if (m_style == EffectFrameStyled) { | | |||
2188 | m_frame.setImagePath(QStringLiteral("widgets/background")); | | |||
2189 | m_frame.setCacheAllRenderedFrames(true); | | |||
2190 | connect(m_theme, SIGNAL(themeChanged()), this, SLOT(plasmaThemeChanged())); | | |||
2191 | } | | |||
2192 | m_selection.setImagePath(QStringLiteral("widgets/viewitem")); | | |||
2193 | m_selection.setElementPrefix(QStringLiteral("hover")); | | |||
2194 | m_selection.setCacheAllRenderedFrames(true); | | |||
2195 | m_selection.setEnabledBorders(Plasma::FrameSvg::AllBorders); | | |||
2196 | | ||||
2197 | m_sceneFrame = Compositor::self()->scene()->createEffectFrame(this); | | |||
2198 | } | | |||
2199 | | ||||
2200 | EffectFrameImpl::~EffectFrameImpl() | | |||
2201 | { | | |||
2202 | delete m_sceneFrame; | | |||
2203 | } | | |||
2204 | | ||||
2205 | const QFont& EffectFrameImpl::font() const | | |||
2206 | { | | |||
2207 | return m_font; | | |||
2208 | } | | |||
2209 | | ||||
2210 | void EffectFrameImpl::setFont(const QFont& font) | | |||
2211 | { | | |||
2212 | if (m_font == font) { | | |||
2213 | return; | | |||
2214 | } | | |||
2215 | m_font = font; | | |||
2216 | QRect oldGeom = m_geometry; | | |||
2217 | if (!m_text.isEmpty()) { | | |||
2218 | autoResize(); | | |||
2219 | } | | |||
2220 | if (oldGeom == m_geometry) { | | |||
2221 | // Wasn't updated in autoResize() | | |||
2222 | m_sceneFrame->freeTextFrame(); | | |||
2223 | } | | |||
2224 | } | | |||
2225 | | ||||
2226 | void EffectFrameImpl::free() | | |||
2227 | { | | |||
2228 | m_sceneFrame->free(); | | |||
2229 | } | | |||
2230 | | ||||
2231 | const QRect& EffectFrameImpl::geometry() const | | |||
2232 | { | | |||
2233 | return m_geometry; | | |||
2234 | } | | |||
2235 | | ||||
2236 | void EffectFrameImpl::setGeometry(const QRect& geometry, bool force) | | |||
2237 | { | | |||
2238 | QRect oldGeom = m_geometry; | | |||
2239 | m_geometry = geometry; | | |||
2240 | if (m_geometry == oldGeom && !force) { | | |||
2241 | return; | | |||
2242 | } | | |||
2243 | effects->addRepaint(oldGeom); | | |||
2244 | effects->addRepaint(m_geometry); | | |||
2245 | if (m_geometry.size() == oldGeom.size() && !force) { | | |||
2246 | return; | | |||
2247 | } | | |||
2248 | | ||||
2249 | if (m_style == EffectFrameStyled) { | | |||
2250 | qreal left, top, right, bottom; | | |||
2251 | m_frame.getMargins(left, top, right, bottom); // m_geometry is the inner geometry | | |||
2252 | m_frame.resizeFrame(m_geometry.adjusted(-left, -top, right, bottom).size()); | | |||
2253 | } | | |||
2254 | | ||||
2255 | free(); | | |||
2256 | } | | |||
2257 | | ||||
2258 | const QIcon& EffectFrameImpl::icon() const | | |||
2259 | { | | |||
2260 | return m_icon; | | |||
2261 | } | | |||
2262 | | ||||
2263 | void EffectFrameImpl::setIcon(const QIcon& icon) | | |||
2264 | { | | |||
2265 | m_icon = icon; | | |||
2266 | if (isCrossFade()) { | | |||
2267 | m_sceneFrame->crossFadeIcon(); | | |||
2268 | } | | |||
2269 | if (m_iconSize.isEmpty() && !m_icon.availableSizes().isEmpty()) { // Set a size if we don't already have one | | |||
2270 | setIconSize(m_icon.availableSizes().first()); | | |||
2271 | } | | |||
2272 | m_sceneFrame->freeIconFrame(); | | |||
2273 | } | | |||
2274 | | ||||
2275 | const QSize& EffectFrameImpl::iconSize() const | | |||
2276 | { | | |||
2277 | return m_iconSize; | | |||
2278 | } | | |||
2279 | | ||||
2280 | void EffectFrameImpl::setIconSize(const QSize& size) | | |||
2281 | { | | |||
2282 | if (m_iconSize == size) { | | |||
2283 | return; | | |||
2284 | } | | |||
2285 | m_iconSize = size; | | |||
2286 | autoResize(); | | |||
2287 | m_sceneFrame->freeIconFrame(); | | |||
2288 | } | | |||
2289 | | ||||
2290 | void EffectFrameImpl::plasmaThemeChanged() | | |||
2291 | { | | |||
2292 | free(); | | |||
2293 | } | | |||
2294 | | ||||
2295 | void EffectFrameImpl::render(const QRegion ®ion, double opacity, double frameOpacity) | | |||
2296 | { | | |||
2297 | if (m_geometry.isEmpty()) { | | |||
2298 | return; // Nothing to display | | |||
2299 | } | | |||
2300 | m_shader = nullptr; | | |||
2301 | setScreenProjectionMatrix(static_cast<EffectsHandlerImpl*>(effects)->scene()->screenProjectionMatrix()); | | |||
2302 | effects->paintEffectFrame(this, region, opacity, frameOpacity); | | |||
2303 | } | | |||
2304 | | ||||
2305 | void EffectFrameImpl::finalRender(QRegion region, double opacity, double frameOpacity) const | | |||
2306 | { | | |||
2307 | region = infiniteRegion(); // TODO: Old region doesn't seem to work with OpenGL | | |||
2308 | | ||||
2309 | m_sceneFrame->render(region, opacity, frameOpacity); | | |||
2310 | } | | |||
2311 | | ||||
2312 | Qt::Alignment EffectFrameImpl::alignment() const | | |||
2313 | { | | |||
2314 | return m_alignment; | | |||
2315 | } | | |||
2316 | | ||||
2317 | | ||||
2318 | void | | |||
2319 | EffectFrameImpl::align(QRect &geometry) | | |||
2320 | { | | |||
2321 | if (m_alignment & Qt::AlignLeft) | | |||
2322 | geometry.moveLeft(m_point.x()); | | |||
2323 | else if (m_alignment & Qt::AlignRight) | | |||
2324 | geometry.moveLeft(m_point.x() - geometry.width()); | | |||
2325 | else | | |||
2326 | geometry.moveLeft(m_point.x() - geometry.width() / 2); | | |||
2327 | if (m_alignment & Qt::AlignTop) | | |||
2328 | geometry.moveTop(m_point.y()); | | |||
2329 | else if (m_alignment & Qt::AlignBottom) | | |||
2330 | geometry.moveTop(m_point.y() - geometry.height()); | | |||
2331 | else | | |||
2332 | geometry.moveTop(m_point.y() - geometry.height() / 2); | | |||
2333 | } | | |||
2334 | | ||||
2335 | | ||||
2336 | void EffectFrameImpl::setAlignment(Qt::Alignment alignment) | | |||
2337 | { | | |||
2338 | m_alignment = alignment; | | |||
2339 | align(m_geometry); | | |||
2340 | setGeometry(m_geometry); | | |||
2341 | } | | |||
2342 | | ||||
2343 | void EffectFrameImpl::setPosition(const QPoint& point) | | |||
2344 | { | | |||
2345 | m_point = point; | | |||
2346 | QRect geometry = m_geometry; // this is important, setGeometry need call repaint for old & new geometry | | |||
2347 | align(geometry); | | |||
2348 | setGeometry(geometry); | | |||
2349 | } | | |||
2350 | | ||||
2351 | const QString& EffectFrameImpl::text() const | | |||
2352 | { | | |||
2353 | return m_text; | | |||
2354 | } | | |||
2355 | | ||||
2356 | void EffectFrameImpl::setText(const QString& text) | | |||
2357 | { | | |||
2358 | if (m_text == text) { | | |||
2359 | return; | | |||
2360 | } | | |||
2361 | if (isCrossFade()) { | | |||
2362 | m_sceneFrame->crossFadeText(); | | |||
2363 | } | | |||
2364 | m_text = text; | | |||
2365 | QRect oldGeom = m_geometry; | | |||
2366 | autoResize(); | | |||
2367 | if (oldGeom == m_geometry) { | | |||
2368 | // Wasn't updated in autoResize() | | |||
2369 | m_sceneFrame->freeTextFrame(); | | |||
2370 | } | | |||
2371 | } | | |||
2372 | | ||||
2373 | void EffectFrameImpl::setSelection(const QRect& selection) | | |||
2374 | { | | |||
2375 | if (selection == m_selectionGeometry) { | | |||
2376 | return; | | |||
2377 | } | | |||
2378 | m_selectionGeometry = selection; | | |||
2379 | if (m_selectionGeometry.size() != m_selection.frameSize().toSize()) { | | |||
2380 | m_selection.resizeFrame(m_selectionGeometry.size()); | | |||
2381 | } | | |||
2382 | // TODO; optimize to only recreate when resizing | | |||
2383 | m_sceneFrame->freeSelection(); | | |||
2384 | } | | |||
2385 | | ||||
2386 | void EffectFrameImpl::autoResize() | | |||
2387 | { | | |||
2388 | if (m_static) | | |||
2389 | return; // Not automatically resizing | | |||
2390 | | ||||
2391 | QRect geometry; | | |||
2392 | // Set size | | |||
2393 | if (!m_text.isEmpty()) { | | |||
2394 | QFontMetrics metrics(m_font); | | |||
2395 | geometry.setSize(metrics.size(0, m_text)); | | |||
2396 | } | | |||
2397 | if (!m_icon.isNull() && !m_iconSize.isEmpty()) { | | |||
2398 | geometry.setLeft(-m_iconSize.width()); | | |||
2399 | if (m_iconSize.height() > geometry.height()) | | |||
2400 | geometry.setHeight(m_iconSize.height()); | | |||
2401 | } | | |||
2402 | | ||||
2403 | align(geometry); | | |||
2404 | setGeometry(geometry); | | |||
2405 | } | | |||
2406 | | ||||
2407 | QColor EffectFrameImpl::styledTextColor() | | |||
2408 | { | | |||
2409 | return m_theme->color(Plasma::Theme::TextColor); | | |||
2410 | } | | |||
2411 | | ||||
2412 | } // namespace | 2166 | } // namespace |