File indexing completed on 2024-09-08 10:48:54
0001 // SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org> 0002 // SPDX-License-Identifier: GPL-2.0-or-later 0003 0004 #include "util.h" 0005 0006 #include <QQuickWindow> 0007 0008 #include <KWindowEffects> 0009 0010 Util::Util(QObject *parent) 0011 : QObject{ parent } 0012 {} 0013 0014 uint Util::getKeyFromString(QString key) 0015 { 0016 QKeySequence seq = QKeySequence(key); 0017 return seq.count() > 0 ? seq[0] : 0; 0018 } 0019 0020 void Util::setBlur(QQuickItem *item, bool blur) 0021 { 0022 auto setWindows = [item, blur]() { 0023 auto reg = QRect(QPoint(0, 0), item->window()->size()); 0024 KWindowEffects::enableBackgroundContrast(item->window(), blur, 1, 1, 1, reg); 0025 KWindowEffects::enableBlurBehind(item->window(), blur, reg); 0026 }; 0027 0028 disconnect(item->window(), &QQuickWindow::heightChanged, this, nullptr); 0029 disconnect(item->window(), &QQuickWindow::widthChanged, this, nullptr); 0030 connect(item->window(), &QQuickWindow::heightChanged, this, setWindows); 0031 connect(item->window(), &QQuickWindow::widthChanged, this, setWindows); 0032 setWindows(); 0033 } 0034 0035 void Util::setInitialWorkDir(QString &&initialWorkDir) 0036 { 0037 m_initialWorkDir = std::move(initialWorkDir); 0038 Q_EMIT initialWorkDirChanged(); 0039 } 0040 0041 void Util::setInitialCommand(QString &&command) 0042 { 0043 m_initialCommand = std::move(command); 0044 Q_EMIT initialCommandChanged(); 0045 }