File indexing completed on 2024-06-09 09:10:17

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 
0015 uint Util::getKeyFromString(QString key)
0016 {
0017     QKeySequence seq = QKeySequence(key);
0018     return seq.count() > 0 ? seq[0] : 0;
0019 }
0020 
0021 void Util::setBlur(QQuickItem *item, bool blur)
0022 {
0023     auto setWindows = [item, blur]() {
0024         auto reg = QRect(QPoint(0, 0), item->window()->size());
0025         KWindowEffects::enableBackgroundContrast(item->window(), blur, 1, 1, 1, reg);
0026         KWindowEffects::enableBlurBehind(item->window(), blur, reg);
0027     };
0028 
0029     disconnect(item->window(), &QQuickWindow::heightChanged, this, nullptr);
0030     disconnect(item->window(), &QQuickWindow::widthChanged, this, nullptr);
0031     connect(item->window(), &QQuickWindow::heightChanged, this, setWindows);
0032     connect(item->window(), &QQuickWindow::widthChanged, this, setWindows);
0033     setWindows();
0034 }
0035 
0036 void Util::setInitialWorkDir(QString &&initialWorkDir)
0037 {
0038     m_initialWorkDir = std::move(initialWorkDir);
0039     Q_EMIT initialWorkDirChanged();
0040 }
0041 
0042 void Util::setInitialCommand(QString &&command)
0043 {
0044     m_initialCommand = std::move(command);
0045     Q_EMIT initialCommandChanged();
0046 }