File: taskview_button.cpp

package info (click to toggle)
ukui-panel 4.0.0.6-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,148 kB
  • sloc: cpp: 28,423; xml: 476; sh: 51; makefile: 18
file content (117 lines) | stat: -rw-r--r-- 4,132 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU  Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
 *
 */

#include "taskview_button.h"
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusConnection>

#define ORG_UKUI_STYLE            "org.ukui.style"
#define STYLE_NAME                "styleName"

TaskViewButton::TaskViewButton(IUKUIPanelPlugin *plugin,QWidget *parent):
    QToolButton(parent),
    m_parent(parent),
    m_plugin(plugin)
{
    this->setParent(parent);
    setFocusPolicy(Qt::NoFocus);
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    this->setToolTip(tr("Show Taskview"));
    setProperty("useButtonPalette",true);
    setAutoRaise(true);
    setSystemStyle();
    const QByteArray id(ORG_UKUI_STYLE);
    if (QGSettings::isSchemaInstalled(id)) {
        m_gsettings = new QGSettings(id);
        connect(m_gsettings, &QGSettings::changed, this, [=] (const QString &key) {
            if (key==STYLE_NAME) {
                setSystemStyle();
            }
        });
    }
    
    this->setIcon(QIcon::fromTheme("ukui-taskview-black-symbolic",QIcon("/usr/share/ukui-panel/panel/img/taskview-dark.svg")));
    this->setProperty("useIconHighlightEffect", 0x2);
    this->setIconSize(QSize(m_plugin->panel()->iconSize(),m_plugin->panel()->iconSize()));
    this->setContextMenuPolicy(Qt::PreventContextMenu);
}
TaskViewButton::~TaskViewButton(){
}

void TaskViewButton::setSystemStyle()
{
    QPalette pal = this->palette();
    QColor col = pal.color(QPalette::Active, QPalette::BrightText);
    col.setAlphaF(0.13);
    pal.setColor(QPalette::Button, col);
    this->setPalette(pal);
}
void TaskViewButton::realign()
{
    if (m_plugin->panel()->isHorizontal()) {
        this->setFixedSize(m_plugin->panel()->panelSize(),m_plugin->panel()->panelSize());
    } else {
        this->setFixedSize(m_plugin->panel()->panelSize(),m_plugin->panel()->panelSize());
    }
    this->setIconSize(QSize(m_plugin->panel()->iconSize(),m_plugin->panel()->iconSize()));
}

void TaskViewButton::mousePressEvent(QMouseEvent *event)
{
    const Qt::MouseButton b = event->button();
#if 0
    //调用dbus接口
    QString object = QString(getenv("DISPLAY"));
    object = object.trimmed().replace(":", "_").replace(".", "_").replace("-", "_");
    object = "/org/ukui/WindowSwitch/display/" + object;
    QDBusInterface interface("org.ukui.WindowSwitch", object,
                             "org.ukui.WindowSwitch",
                             QDBusConnection::sessionBus());
    if (!interface.isValid()) {
        qCritical() << QDBusConnection::sessionBus().lastError().message();
    }

    if (Qt::LeftButton == b  && interface.isValid())
    {
        /* Call binary display task view
         * system("ukui-window-switch --show-workspace");
         */

        /*调用远程的value方法*/
        QDBusReply<bool> reply = interface.call("handleWorkspace");
        if (reply.isValid()) {
            if (!reply.value())
                qWarning() << "Handle Workspace View Failed";
        } else {
            qCritical() << "Call Dbus method failed";
        }
    }
#endif

    //调用命令
    if (Qt::LeftButton == b){
        QDBusInterface iface("org.ukui.KWin",
                             "/MultitaskView",
                             "org.ukui.KWin.MultitaskView",
                             QDBusConnection::sessionBus());
        iface.call("show");
        system("ukui-window-switch --show-workspace");
    }

    QWidget::mousePressEvent(event);
}