File: startbar.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 (135 lines) | stat: -rw-r--r-- 3,993 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * 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 "startbar.h"
#include <QMouseEvent>
#include <QHBoxLayout>
#include <QScreen>
#include <QDebug>
#include <QMenu>

#include <QStyle>
#define THEME_QT_SCHEMA                     "org.ukui.style"
#define THEME_Style_Name                    "styleName"
#define UKUI_PANEL_SETTINGS                 "org.ukui.panel.settings"
#define SHOW_TASKVIEW                       "showtaskview"

UKUIStartbarPlugin::UKUIStartbarPlugin(const IUKUIPanelPluginStartupInfo &startupInfo):
    QObject(),
    IUKUIPanelPlugin(startupInfo),
    m_widget(new UKUIStartBarWidget(this))
{

    m_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

}

UKUIStartbarPlugin::~UKUIStartbarPlugin()
{
    delete m_widget;
}

QWidget *UKUIStartbarPlugin::widget()
{
    return m_widget;
}

void UKUIStartbarPlugin::realign()
{
    m_widget->realign();
}

UKUIStartBarWidget::UKUIStartBarWidget( IUKUIPanelPlugin *plugin, QWidget* parent ):
    m_plugin(plugin),
    m_layout(new QBoxLayout(QBoxLayout::LeftToRight, this)),
    m_divider(new Divider(false, this)),
    m_startMenuButton(new StartMenuButton(plugin, this))
{
    translator();

    m_layout->setContentsMargins(0, 0, 0, 0);
    m_layout->setSpacing(0);
    m_layout->addWidget(m_startMenuButton);
    m_layout->addWidget(m_divider);
    m_layout->setAlignment(m_divider, Qt::AlignCenter);
    const QByteArray id(UKUI_PANEL_SETTINGS);
    if(QGSettings::isSchemaInstalled(id)) {
        m_gsettings = new QGSettings(id);
    }

    showTaskviewButton();
    connect(m_gsettings, &QGSettings::changed, this, [=] (const QString &key){
        if(key == SHOW_TASKVIEW)
            showTaskviewButton();
    });

    realign();
}

void UKUIStartBarWidget::translator()
{
    QTranslator *translator = new QTranslator(this);
    translator->load(QLocale(), "startbar", "_", STARTBAR_TRANSLATION_DIR);
    QCoreApplication::installTranslator(translator);
}

UKUIStartBarWidget::~UKUIStartBarWidget()
{
    m_startMenuButton->deleteLater();
    m_taskViewButton->deleteLater();
}

/*plugin-startmenu refresh function*/
void UKUIStartBarWidget::realign()
{
    if (m_plugin->panel()->isHorizontal()) {
        m_layout->setDirection(QBoxLayout::LeftToRight);

        m_divider->setFixedWidth(1);
        m_divider->setFixedHeight(m_plugin->panel()->panelSize()/3);
    } else {
        m_layout->setDirection(QBoxLayout::TopToBottom);

        m_divider->setFixedHeight(1);
        m_divider->setFixedWidth(m_plugin->panel()->panelSize()/3);
    }

    m_startMenuButton->realign();
    if (this->findChild<TaskViewButton *>("TaskViewButton")) {
        m_taskViewButton->realign();
    }
}


void UKUIStartBarWidget::showTaskviewButton()
{
    if(m_gsettings->get(SHOW_TASKVIEW).toBool()){
        if (!this->findChild<TaskViewButton *>("TaskViewButton")) {
            m_taskViewButton = new TaskViewButton(m_plugin,this);
            m_taskViewButton->setObjectName("TaskViewButton");
            m_layout->addWidget(m_taskViewButton);
        }
    } else {
        if (this->findChild<TaskViewButton *>("TaskViewButton")) {
            if (m_taskViewButton != nullptr) {
                m_layout->removeWidget(m_taskViewButton);
                m_taskViewButton->deleteLater();
            }
        }
    }
}