File: modulepagewidget.cpp

package info (click to toggle)
ukui-control-center 3.22.1.29-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 42,420 kB
  • sloc: cpp: 77,963; xml: 2,408; sh: 30; makefile: 4
file content (142 lines) | stat: -rw-r--r-- 4,629 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
136
137
138
139
140
141
142
/*
 * Copyright (C) 2023, KylinSoft Co., Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, 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/>.
 *
**/
#include "modulepagewidget.h"
#include "ui_modulepagewidget.h"

#include <QListWidgetItem>
#include <QDebug>

#include "mainwindow.h"
#include "interface.h"
#include "utils/functionselect.h"
#include "interface/ukcccommon.h"
using namespace ukcc;
#include "component/leftwidgetitem.h"
#include "component/leftmenulist.h"
#include <QScrollBar>

ModulePageWidget::ModulePageWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ModulePageWidget)
{
    ui->setupUi(this);
    initUI();
}

ModulePageWidget::~ModulePageWidget()
{
    delete ui;
    ui = nullptr;
}

void ModulePageWidget::initUI() {
    //设置伸缩策略

    QSizePolicy rightSizePolicy = ui->widget->sizePolicy();

    rightSizePolicy.setHorizontalStretch(5);

    ui->widget->setSizePolicy(rightSizePolicy);
    ui->widget->setObjectName("widget");
    ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    ui->scrollArea->verticalScrollBar()->setHidden(true);
    connect(ui->scrollArea->verticalScrollBar(),&QScrollBar::rangeChanged,this, [=](){
        if (ui->scrollArea->verticalScrollBar()->maximum() == 0) {
            ui->scrollArea->verticalScrollBar()->setHidden(true);
        } else {
            ui->scrollArea->verticalScrollBar()->setHidden(false);
        }
    });
    connect(ui->scrollArea->horizontalScrollBar(), &QScrollBar::rangeChanged, this, [=](){
        if (ui->scrollArea->horizontalScrollBar()->maximum() == 0) {
            emit hScrollBarHide();
        } else {
            emit hScrollBarShow();
        }
    });

    //设置qss之后,点击屏保再主页进入插件会卡死,原因未知
//    ui->scrollArea->setStyleSheet("QScrollArea{background-color: palette(window);}");
    ui->scrollArea->verticalScrollBar()->setProperty("drawScrollBarGroove", false);
}

void ModulePageWidget::switchPage(QObject *plugin, bool recorded, QString jumpText){
    Q_UNUSED(recorded);
    CommonInterface * pluginInstance = qobject_cast<CommonInterface *>(plugin);
    refreshPluginWidget(pluginInstance);
    if (jumpText.isEmpty() || !pluginwidget) {
        return;
    }
    for (QLabel *o : pluginwidget->findChildren<QLabel*>()) {
        if (o->text() == jumpText) {
            QPoint pos = o->mapTo(ui->scrollArea->widget(), o->pos());
            int widgetHeight = ui->scrollArea->widget()->height();
            int areaHeight   = ui->scrollArea->height();
            if (pluginInstance->name() == "Theme") {
               pos.setY(pos.y()/2);
            }
            int maxNum = widgetHeight - areaHeight;
            int value = pos.y() + o->height() - areaHeight;
            value = value + areaHeight/2; //尽量让选中的显示在中间位置
            if (value <= 0) {
               ui->scrollArea->verticalScrollBar()->setValue(0);
            } else if (value > maxNum){
                ui->scrollArea->verticalScrollBar()->setValue(maxNum);
            } else {
               ui->scrollArea->verticalScrollBar()->setValue(value);
            }
            return;
       }
    }
}

void ModulePageWidget::refreshPluginWidget(CommonInterface *plu){
    if (plu->pluginBtn) {
        plu->pluginBtn->setCheckState(Qt::Checked);
    }
    prePlugin = currentPlugin;
    if (prePlugin) {
        qInfo()<<"plugin_leave(): "<<prePlugin->name();
        prePlugin->plugin_leave();
    }
    currentPlugin = plu;
    ui->scrollArea->takeWidget();
    delete(ui->scrollArea->widget());

    pluginwidget =  plu->pluginUi();
    qInfo()<<"pluginUi(): "<<currentPlugin->name();
    pluginwidget->setContentsMargins(24,0,4,40);
    ui->scrollArea->setWidget(pluginwidget);
    mCurrentPluName = plu->name();

    //记录打开历史
    if (flagBit){
        FunctionSelect::pushRecordValue(plu->pluginTypes(), plu->plugini18nName());
    }

    //恢复标志位
    flagBit = true;
}

void ModulePageWidget::pluginLeave()
{
    if (currentPlugin) {
        currentPlugin->plugin_leave();
    }
}