File: mainwindow.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 (1113 lines) | stat: -rw-r--r-- 42,861 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
/*
 * 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 "mainwindow.h"
#include "ui_mainwindow.h"
#include "interface/ukcccommon.h"
using namespace ukcc;
#include "imageutil.h"
#include "ukccabout.h"

#include <QLabel>
#include <QLocale>
#include <QPushButton>
#include <QButtonGroup>
#include <QHBoxLayout>
#include <QPluginLoader>
#include <QPainter>
#include <QPainterPath>
#include <QProcess>
#include <QDebug>
#include <QMessageBox>
#include <QGSettings>
#include <QMenu>
#include <QShortcut>
#include <QMouseEvent>
#include <QScrollBar>
#include <KWindowSystem>
#include "component/leftwidgetitem.h"
#include "iconbutton.h"
#include "lightlabel.h"
#include "../../shell/customstyle.h"
#include "utils/modulefactory.h"
#include "utils/functionselect.h"

#define THEME_QT_SCHEMA "org.ukui.style"

#ifdef WITHKYSEC
#include <kysec/libkysec.h>
#include <kysec/status.h>
#endif

const QByteArray kVinoSchemas    = "org.gnome.Vino";

#define KYLIN_USER_GUIDE_PATH              "/"
#define KYLIN_USER_GUIDE_SERVICE           "com.kylinUserGuide.hotel"
#define KYLIN_USER_GUIDE_INTERFACE         "com.guide.hotel"

/* qt会将glib里的signals成员识别为宏,所以取消该宏
 * 后面如果用到signals时,使用Q_SIGNALS代替即可
 **/
#ifdef signals
#undef signals
#endif

extern "C" {
#include <glib.h>
#include <gio/gio.h>
}

const int dbWitdth = 50;
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    m_searchWidget(nullptr)
{
    qApp->installEventFilter(this);
    qApp->setStyle(new InternalStyle("ukui"));
    is_ExitPower = isExitsPower();
    pluginPathList = FunctionSelect::listExistsCustomNoticePath(PLUGINS_PATH);
    if (UkccCommon::isOpenkylin()) {
        connect(WindowManager::self(),&WindowManager::windowAdded,this,[=](const WindowId& windowId){
            if (getpid() == WindowManager::getPid(windowId)) {
                m_listWinIds.append(windowId);
            }
        });
        connect(WindowManager::self(),&WindowManager::windowRemoved,this,[=](const WindowId& windowId){
            if (m_listWinIds.contains(windowId)) {
                m_listWinIds.removeOne(windowId);
            }
        });
    }
    isLoad = false;
    loadWidget = false;
    preInit();
}

MainWindow::~MainWindow()
{
    //执行插件的析构函数
    ModulesFactory::pluginDelete();
    qInfo()<<"~exit ukui-control-center";
    delete ui;
    ui = nullptr;
}

void MainWindow::preInit() {
    m_searchWidget = new SearchWidget(this);
    m_searchWidget->setContextMenuPolicy(Qt::NoContextMenu);
    connect(m_searchWidget, &SearchWidget::notifyModuleSearch, this, &MainWindow::switchPage);
    m_searchWidget->setFixedWidth(240);
    m_ModuleMap = UkccCommon::getModuleHideStatus();
}

void MainWindow::bootOptionsFilter(QString opt, bool firstIn) {
    PluginInfo* pluginInfo = ModulesFactory::getPluginInfoByName(opt);
    if (pluginInfo == nullptr) {
        //避免无限循环的风险
        if (UkccCommon::isTablet()) {
            if (firstIn) {
                bootOptionsFilter("userinfointel", false);
            }
            backBtn->hide();
        }
        return ;
    }
    QString pluginName = pluginInfo->nameString;
    QString moduleName = ModulesFactory::getModuleNamebyName(pluginName);
    QObject* pluginObj = ModulesFactory::getPluginObjectByName(pluginInfo->namei18nString);
    if (pluginObj != nullptr) {
        if (m_ModuleMap.isEmpty()) {
            //开始跳转
            functionBtnClicked(pluginObj);
            return ;
        } else {
            qDebug() << "module:" << pluginName.toLower() << ";superordinate:" << moduleName;
            // 若跳转节点或跳转节点父节点不存在直接跳转,不受管控文件控制,若存在,则根据管控文件判断是否被禁用
            if (!m_ModuleMap.contains(pluginName.toLower()) || !m_ModuleMap.contains(moduleName)
                 || (m_ModuleMap[pluginName.toLower()].toBool() && m_ModuleMap[moduleName].toBool())) {
                //开始跳转
                functionBtnClicked(pluginObj);
                return ;
            }
        }

        QMessageBox::information(this, tr("Warnning"), tr("This function has been controlled"));
    }
}

bool MainWindow::eventFilter(QObject *watched, QEvent *event)
{
    if (watched == scrollArea) {
        if (!UkccCommon::isTablet()) {
            if (event->type() == QEvent::Enter) {
                scrollArea->verticalScrollBar()->setVisible(true);
            } else if (event->type() == QEvent::Leave) {
                scrollArea->verticalScrollBar()->setVisible(false);
            }
        }
    } else if (watched == this) {
        if (event->type() == QEvent::WindowStateChange) {
            if (this->windowState() == Qt::WindowMaximized) {
                maxBtn->setIcon(QIcon::fromTheme("window-restore-symbolic"));
                maxBtn->setToolTip(tr("Restore"));
            } else {
                maxBtn->setIcon(QIcon::fromTheme("window-maximize-symbolic"));
                maxBtn->setToolTip(tr("Maximize"));
            }
        } else if (event->type() == QEvent::MouseButtonDblClick) {
            QMouseEvent * mouseEvent = static_cast<QMouseEvent *>(event);
            if (mouseEvent->button() == Qt::LeftButton ){
                bool res = dblOnEdge(dynamic_cast<QMouseEvent*>(event));
                if (res) {
                    if (this->windowState() == Qt::WindowMaximized) {
                        this->showNormal();
                    } else {
                        this->showMaximized();
                    }
                }
            }
        }
    } else if (watched == homepageWidget) {
        if (event->type() == QEvent::Paint) {
            QTimer::singleShot(1, this, [=]() {
                if (!UkccCommon::isTablet()) {
                    m_searchWidget->setFixedWidth(240 > mOptionBtn->x() - titleLabel->x() - titleLabel->width() ? (mOptionBtn->x() - m_searchWidget->x() - 16) : 240);
                }
            });
        }
    }
    return QObject::eventFilter(watched, event);
}

void MainWindow::keyReleaseEvent(QKeyEvent *event)
{
    mFirstKey = 0;
}

void MainWindow::keyPressEvent(QKeyEvent *event)
{
    if (event->key() == Qt::Key_F1) {
        if (!event->isAutoRepeat()) //避免重复触发该事件
            onF1ButtonClicked();
    }

    if (mFirstKey == 0 && event->key() == Qt::Key_Control) {
        mFirstKey = Qt::Key_Control;
    } else if (mFirstKey == Qt::Key_Control && event->key() == Qt::Key_E) {
#ifdef Nile
        m_searchWidget->setFocus();
#endif
    } else {
        mFirstKey = 0;
    }
}

void MainWindow::loadAllModules() {
    // 一级菜单配置加载
    QtConcurrent::run([=]{
        ModulesFactory::loadConfig();
    });

    //加载插件
    loadPlugins();
}

void MainWindow::initPageWidget() {
    if (loadWidget) {
        return;
    }
    loadWidget = true;
    initUI();
    hideComponent();

    //加载首页Widget
    homepageWidget = new HomePageWidget(this, vecGsettins);
    homepageWidget->installEventFilter(this);
    ui->stackedWidget->addWidget(homepageWidget);
    ui->stackedWidget->setFocusPolicy(Qt::ClickFocus);

    //加载左侧边栏一级菜单
    initLeftsideBar();

    //加载功能页Widget
    modulepageWidget = new ModulePageWidget(this);
    ui->stackedWidget->addWidget(modulepageWidget);

    connect(ui->stackedWidget, &QStackedWidget::currentChanged, this, [=] (int id){
        if (id == 0) {
            modulepageWidget->mCurrentPluName =  "";
        }
    });
    connect(modulepageWidget, &ModulePageWidget::hScrollBarHide, this, [=]() {
        m_searchWidget->setFixedWidth(240);
    });
    connect(modulepageWidget, &ModulePageWidget::hScrollBarShow, this, [=]() {
        QTimer::singleShot(1, this, [=]() {
            if (!UkccCommon::isTablet()) {
                if (m_searchWidget->width() > backBtn->x() - mOptionBtn->x()) {
                    m_searchWidget->setFixedWidth(mOptionBtn->x() - backBtn->x() - mOptionBtn->width() - 16);
                }
            }
        });
    });
}

void MainWindow::initUI() {
    ui->setupUi(this);
    QRect screenSize = UkccCommon::sizeOnCursor();
    this->setMinimumSize(978, 630);
    if (screenSize.width() > 1440)
        this->resize(1160,720);

    const QByteArray id("org.ukui.style");
    m_fontSetting = new QGSettings(id, QByteArray(), this);
    connect(m_fontSetting, &QGSettings::changed, this, [=](QString key) {
        if ("systemFont" == key || "systemFontSize" == key) {
            QFont font = this->font();
            int width = font.pointSize();
            for (auto widget : qApp->allWidgets()) {
                QString className(widget->metaObject()->className());
                if (widget->objectName() == "timeClockLable") {
                    QFont fontTime;
                    fontTime.setWeight(QFont::Medium);
                    fontTime.setBold(true);
                    if (QLocale::system().amText() == "སྔ་དྲོ་") {
                        fontTime.setPixelSize(m_fontSetting->get("systemFontSize").toInt() * 20 / 11);
                    } else {
                        fontTime.setPixelSize(font.pointSize() * 28 / 11);
                    }
                    widget->setFont(fontTime);
                } else if(widget->objectName() == "DateTime_Info") {
                    QFont fontTitle;
                    fontTitle.setPixelSize(font.pointSize() * 18 / 11);
                    fontTitle.setWeight(QFont::Medium);
                    widget->setFont(fontTitle);
                } else {
                    font.setWeight(QFont::Normal);
                    widget->setFont(font);
                }
            }
        }
    });

    initTileBar();
    initStyleSheet();

    connect(minBtn, SIGNAL(clicked()), this, SLOT(showMinimized()));
    connect(maxBtn, &QPushButton::clicked, this, [=] {
        if (isMaximized()) {
            showNormal();
            maxBtn->setIcon(QIcon::fromTheme("window-maximize-symbolic"));
        } else {
            showMaximized();
            maxBtn->setIcon(QIcon::fromTheme("window-restore-symbolic"));
        }
    });
    connect(closeBtn, &QPushButton::clicked, this, [=] {
        qApp->quit();
    });

    connect(ui->stackedWidget, &QStackedWidget::currentChanged, this, [=](int index){
        ui->centralWidget->setVisible(false);    //避免出现明显的卡顿现象,在选择进入屏保界面之后这个问题比较明显,这种做法只是优化
        if (index){ //次页部分组件样式
            titleLabel->setHidden(true);
            mTitleIcon->setHidden(true);
              ui->leftsidebarWidget->setVisible(true);
            //左上角显示字符/返回按钮
            if (!is_tabletmode) {
                backBtn->setVisible(true);
            }
            ui->stackedWidget->status = false;
            ui->titleWidget->status = false;
        } else { //首页部分组件样式
            //左侧边栏显示/不显示
            ui->leftsidebarWidget->setHidden(true);
            titleLabel->setVisible(true);
            mTitleIcon->setVisible(true);
            //左上角显示字符/返回按钮
            backBtn->setHidden(true);
            if (modulepageWidget) {
                modulepageWidget->pluginLeave();
            }
            ui->stackedWidget->status = true;
            ui->titleWidget->status = true;
        }
        ui->centralWidget->setVisible(true);
    });

    //top left return button
    connect(backBtn, &QPushButton::clicked, this, [=]{
        ui->stackedWidget->setCurrentIndex(0);
        UkccCommon::buriedSettings(backBtn->objectName(), nullptr, QString("clicked"));
    });

    // 快捷参数
    if (QApplication::arguments().length() > 2) {
        if (QApplication::arguments().at(1) == "-p") {
            QString fileFullName = "";
            QString fileName = QApplication::arguments().at(2);
            if (!fileName.startsWith("/")) { //非绝对路径
                char *path = get_current_dir_name();
                QString currentPath = QString(path);
                if (!currentPath.endsWith("/")) {
                    currentPath = currentPath + "/";
                }
                fileFullName = currentPath + fileName;
                g_free(path);
            } else {
                fileFullName = fileName;
            }
            loadSpecifiedPlugin(fileFullName);
        } else if (QApplication::arguments().at(1) == "-m") {
            QTimer::singleShot(2, this, [=](){  //延时保证菜单栏选中插件居中,控件未画出来,无法准确居中
                bootOptionsFilter(QApplication::arguments().at(2));
            });
        }
    }

    //监听平板模式切换
    m_statusSessionDbus = new QDBusInterface("com.kylin.statusmanager.interface",
                                              "/",
                                              "com.kylin.statusmanager.interface",
                                              QDBusConnection::sessionBus(),this);
    if (m_statusSessionDbus->isValid()) {
        QDBusReply<bool> tabletmode = m_statusSessionDbus->call("get_current_tabletmode");
        is_tabletmode = tabletmode;
        mainWindow_statusDbusSlot(is_tabletmode);
        connect(m_statusSessionDbus, SIGNAL(mode_change_signal(bool)), this, SLOT(mainWindow_statusDbusSlot(bool)));

    } else {
        qDebug() << "Create statusmanager Interface Failed When : " << QDBusConnection::systemBus().lastError();
    }
}

void MainWindow::initTileBar() {

    mLogoSetLabel  = new QLabel(this);
    QLabel  *textSetLable  = new QLabel(this);
    ui->leftTopWidget->layout()->addWidget(mLogoSetLabel);
    ui->leftTopWidget->layout()->addWidget(textSetLable);
    mLogoSetLabel->setFixedSize(24,24);
    mLogoSetLabel->setPixmap(QPixmap::fromImage(QIcon::fromTheme("ukui-control-center").pixmap(24,24).toImage()));
    const QByteArray id(THEME_QT_SCHEMA);
    QGSettings *mQtSettings = new QGSettings(id, QByteArray(), this);

    textSetLable->setText(tr("Settings"));
    textSetLable->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);

    titleLayout = new QHBoxLayout(ui->titleWidget);
    ui->titleWidget->setLayout(titleLayout);
    ui->titleWidget->setObjectName("titleWidget");
    titleLayout->setContentsMargins(8, 2, 4, 2);
    titleLayout->setSpacing(0);
    titleLayout->addWidget(m_searchWidget,Qt::AlignCenter);

    backBtn     = new QPushButton(this);
    backBtn->setObjectName("go-home");
    backBtn->setToolTip(tr("Back home"));
    mOptionBtn  = new QToolButton(this);
    minBtn      = new QPushButton(this);
    maxBtn      = new QPushButton(this);
    closeBtn    = new QPushButton(this);
    mTitleIcon  = new QLabel(this);
    titleLabel  = new QLabel(tr("Settings"), this);

    backBtn->setFixedSize(36, 36);
    mOptionBtn->setFixedSize(30, 30);
    if (UkccCommon::isTablet()) {
        minBtn->setFixedSize(48, 48);
        maxBtn->setFixedSize(48, 48);
        closeBtn->setFixedSize(48, 48);
        ui->titleWidget->setFixedHeight(48);
        titleLayout->setContentsMargins(8, 0, 0, 0);
        mOptionBtn->hide();
    } else {
        minBtn->setFixedSize(30, 30);
        maxBtn->setFixedSize(30, 30);
        closeBtn->setFixedSize(30, 30);
        mOptionBtn->show();
    }

    mTitleIcon->setFixedSize(24, 24);

    mOptionBtn->setToolTip(tr("Option"));
    minBtn->setToolTip(tr("Minimize"));
    maxBtn->setToolTip(tr("Maximize"));
    closeBtn->setToolTip(tr("Close"));
    m_titleIcon = QIcon::fromTheme("ukui-control-center");
    mTitleIcon->setPixmap(m_titleIcon.pixmap(m_titleIcon.actualSize(QSize(24, 24))));

    connect(mQtSettings, &QGSettings::changed, this, [=](QString key) {
        if (key == "iconThemeName") {
            mLogoSetLabel->setPixmap(QPixmap::fromImage(QIcon::fromTheme("ukui-control-center").pixmap(24,24).toImage()));
            mTitleIcon->setPixmap(QPixmap::fromImage(QIcon::fromTheme("ukui-control-center").pixmap(24,24).toImage()));
        }
        if (key == "styleName") {
            qApp->setStyle(new InternalStyle("ukui"));
        }
    });

    titleLayout->addWidget(mTitleIcon);
    titleLayout->addSpacing(8);
    titleLayout->addWidget(titleLabel);
    titleLayout->addWidget(backBtn);
    titleLayout->addStretch();
    titleLayout->addWidget(m_searchWidget);
    titleLayout->addStretch();
    titleLayout->addWidget(mOptionBtn);
    titleLayout->addSpacing(4);
    titleLayout->addWidget(minBtn);
    titleLayout->addSpacing(4);
    titleLayout->addWidget(maxBtn);
    titleLayout->addSpacing(4);
    titleLayout->addWidget(closeBtn);

    initUkccAbout();
}

void MainWindow::mainWindow_statusDbusSlot(bool tablet_mode)
{
    is_tabletmode =  tablet_mode;
    if (tablet_mode) {

        ui->leftTopWidget->layout()->setContentsMargins(16, 0, 0, 0);
        ui->leftTopWidget->setFixedHeight(64);
        ui->titleWidget->setFixedHeight(64);
        mLogoSetLabel->setFixedSize(32,32);
        mLogoSetLabel->setPixmap(QPixmap::fromImage(QIcon::fromTheme("ukui-control-center").pixmap(32,32).toImage()));

        mTitleIcon->setFixedSize(32, 32);
        mTitleIcon->setPixmap(m_titleIcon.pixmap(m_titleIcon.actualSize(QSize(32, 32))));

        titleLayout->setContentsMargins(16, 0, 8, 0);

        if (ui->stackedWidget->currentIndex() == -1 || ui->stackedWidget->currentIndex() == 0) {
            this->bootOptionsFilter("userinfo", true);
        }
        backBtn->hide();

        mOptionBtn->setFixedSize(48, 48);
        minBtn->setFixedSize(48, 48);
        maxBtn->hide();
        closeBtn->setFixedSize(48, 48);

        m_searchWidget->setFixedHeight(40);
    } else {
        ui->leftTopWidget->layout()->setContentsMargins(8, 0, 0, 0);
        ui->leftTopWidget->setFixedHeight(40);
        ui->titleWidget->setFixedHeight(40);
        mLogoSetLabel->setFixedSize(24,24);
        mLogoSetLabel->setPixmap(QPixmap::fromImage(QIcon::fromTheme("ukui-control-center").pixmap(24,24).toImage()));

        mTitleIcon->setFixedSize(24, 24);
        mTitleIcon->setPixmap(m_titleIcon.pixmap(m_titleIcon.actualSize(QSize(24, 24))));

        titleLayout->setContentsMargins(8, 2, 5, 2);
        if (ui->stackedWidget->currentIndex() == 1) {
            backBtn->show();
        }

        mOptionBtn->setFixedSize(30, 30);
        minBtn->setFixedSize(30, 30);
        maxBtn->show();
        closeBtn->setFixedSize(30, 30);

        m_searchWidget->setFixedHeight(36);
    }
    emit tabletModeChanged(tablet_mode);
    qApp->setStyle(new InternalStyle("ukui"));
}

void MainWindow::onF1ButtonClicked() {
    QString pluName = "ukui-control-center";
    if (!modulepageWidget->mCurrentPluName.isEmpty()) {
        pluName = QString("%1%2%3").arg(pluName).arg("/").arg(modulepageWidget->mCurrentPluName);
    }
    qDebug()<<pluName;
    showGuide(pluName);
}

void MainWindow::initUkccAbout() {
    mOptionBtn->setPopupMode(QToolButton::InstantPopup);
    QMenu* ukccMain = new QMenu(this);
    ukccMain->setObjectName("mainMenu");
    mOptionBtn->setMenu(ukccMain);

    QAction* ukccHelp = new QAction(tr("Help"),this);
    ukccMain->addAction(ukccHelp);
    QAction* ukccAbout = new QAction(tr("About"),this);
    ukccMain->addAction(ukccAbout);
    QAction* ukccExit = new QAction(tr("Exit"),this);
    ukccMain->addAction(ukccExit);

    connect(ukccExit, SIGNAL(triggered()), this, SLOT(close()));

    connect(ukccAbout, &QAction::triggered, this, [=] {
        KAboutDialog *ukcc = new KAboutDialog(this);
        ukcc->setAppIcon(QIcon::fromTheme("ukui-control-center"));
        ukcc->setAppName(tr("Settings"));
        ukcc->setAppVersion(tr("Version: ") + UkccCommon::getUkccVersion());
        ukcc->setAppSupport(UkccCommon::isOpenkylin() ? "" : ukcc->appSupport());
        ukcc->exec();
    });

     connect(ukccHelp, &QAction::triggered, this, &MainWindow::onF1ButtonClicked);
}
void MainWindow::setBtnLayout(QPushButton * &pBtn) {
    QLabel * imgLabel = new QLabel(pBtn);
    QSizePolicy imgLabelPolicy = imgLabel->sizePolicy();
    imgLabelPolicy.setHorizontalPolicy(QSizePolicy::Fixed);
    imgLabelPolicy.setVerticalPolicy(QSizePolicy::Fixed);
    imgLabel->setSizePolicy(imgLabelPolicy);
    imgLabel->setScaledContents(true);

    QVBoxLayout * baseVerLayout = new QVBoxLayout(pBtn);

    QHBoxLayout * contentHorLayout = new QHBoxLayout();
    contentHorLayout->addStretch();
    contentHorLayout->addWidget(imgLabel);
    contentHorLayout->addStretch();

    baseVerLayout->addStretch();
    baseVerLayout->addLayout(contentHorLayout);
    baseVerLayout->addStretch();

    pBtn->setLayout(baseVerLayout);
}

void MainWindow::loadPlugins()
{
    if (isLoad) {
        return;
    }
    isLoad = true;
    bool installed = (QCoreApplication::applicationDirPath() == QDir(("/usr/bin")).canonicalPath());
    if (installed) {
        pluginsDir = QDir(PLUGIN_INSTALL_DIRS);
    } else {
        pluginsDir = QDir(qApp->applicationDirPath() + "/plugins");
    }
    loadUpdatePlugins();

    foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
        if (!m_updatePlugins.contains(fileName)) {
            determinePlugin(fileName, pluginsDir);
        }
    }
    m_searchWidget->setLanguage(QLocale::system().name());
}

void MainWindow::loadUpdatePlugins()
{
    updatePluginDir = QDir(PLUGIN_INSTALL_UPDATE);
    foreach (QString fileName, updatePluginDir.entryList(QDir::Files)) {
        m_updatePlugins.append(fileName);
        determinePlugin(fileName, updatePluginDir);
    }
}

void MainWindow::determinePlugin(const QString &fileName, const QDir &dir)
{
    QString pluginPath = dir.absoluteFilePath(fileName);
    //三权分立开启
#ifdef WITHKYSEC
    if (!kysec_is_disabled() && kysec_get_3adm_status() && (getuid() || geteuid())){
        //时间和日期 | 用户帐户 | 电源管理 |网络连接 |网络代理
        if (fileName.contains("datetime") || fileName.contains("userinfo") || fileName.contains("power") || \
                fileName.contains("netconnect") || fileName.contains("proxy") || fileName.contains("update") || \
                fileName.contains("upgrade") || fileName.contains("backup") || fileName.contains("vino") ||
                fileName.contains("printer") || fileName.contains("bluetooth", Qt::CaseInsensitive) || fileName.contains("mobilehotspot", Qt::CaseInsensitive) ||
                fileName.contains("vpn") || fileName.contains("autoboot") || fileName.contains("wlanconnect") ||
                fileName.contains("projection") || fileName.contains("area"))
            return;
    }
#endif
    qDebug() << "Scan Plugin: " << fileName;
    if (!fileName.endsWith(".so") ||
            ("libpower.so" == fileName && !is_ExitPower)) {
        return;
    }

    QPluginLoader loader(pluginPath);
    QObject * plugin = loader.instance();
    if (plugin) {
        QtConcurrent::run([=]{
        CommonInterface * pluginInstance = qobject_cast<CommonInterface *>(plugin);
        // 插件是否启用
        if (!pluginInstance || !pluginInstance->isEnable() || !fileName.endsWith("so")) {
            return;
        }

        qDebug() << "Load Plugin :" << pluginInstance->plugini18nName();
        QGSettings *pluginSettings = setGsettingsPath(pluginPathList, pluginInstance->name());
        vecGsettins.insert(pluginInstance->name(), pluginSettings);

        ModulesFactory::loadPluginInfo(plugin);
        if (pluginInstance->isEnable() && pluginSettings->get(SHOW_KEY).toBool() &&
                (!m_ModuleMap.contains(pluginInstance->name().toLower()) ||
                 m_ModuleMap[pluginInstance->name().toLower()].toBool())) {
            m_searchWidget->addModulesName(pluginInstance->name(), pluginInstance->plugini18nName(), pluginInstance->translationPath());
        }
        connect(pluginSettings, &QGSettings::changed,[=](QString key){
            if (key == SHOW_KEY) {
                m_searchWidget->hiddenSearchItem(QLocale::system().name() == "zh_CN" ? pluginInstance->plugini18nName() : pluginInstance->name(), pluginSettings->get(SHOW_KEY).toBool());
            } else {
                m_searchWidget->hiddenSearchItem(QLocale::system().name() == "zh_CN" ? pluginInstance->plugini18nName() : pluginInstance->name(), pluginSettings->get(SHOW_KEY).toBool());
            }
        });
        });
    } else {
        //如果加载错误且文件后缀为so,输出错误
        if (fileName.endsWith(".so"))
            qDebug() << fileName << "Load Failed: " << loader.errorString() << "\n";
    }
}

void MainWindow::loadSpecifiedPlugin(QString pluginFullName)
{
    QPluginLoader loader(pluginFullName);
    QObject *plugin = loader.instance();
    if (plugin) {
        CommonInterface * pluginInstance = qobject_cast<CommonInterface *>(plugin);
        // 插件是否启用
        if (!pluginInstance || !pluginInstance->isEnable() || !pluginFullName.endsWith("so")) {
            qDebug()<<"plugin " <<pluginFullName<<" unavailable.";
            plugin->deleteLater();
            return;
        }
        Q_EMIT specifiedPluginLoaded(pluginInstance);
    } else {
        //如果加载错误且文件后缀为so,输出错误
        if (pluginFullName.endsWith(".so"))
            qDebug() << pluginFullName << "Load Failed: " << loader.errorString();
    }
}

void MainWindow::initLeftsideBar()
{
    scrollArea = new KNavigationBar(ui->leftBotWidget);

    connect(this,&MainWindow::specifiedPluginLoaded,this,[=](CommonInterface * pluginInstance){
        int type = ModulesFactory::size();
        QString typeName = tr("Specified");

        QStandardItem *specifiedPlugin = new QStandardItem(pluginInstance->icon(), pluginInstance->plugini18nName());
        QList<QStandardItem *> secondList;
        secondList << specifiedPlugin;
        specifiedPlugin->setData(type, Qt::UserRole+1);
        specifiedPlugin->setData(pluginInstance->plugini18nName(), Qt::UserRole+2);
        scrollArea->addGroupItems(secondList, typeName);

        pluginInstance->pluginBtn = specifiedPlugin;
    });

    int totalModule = ModulesFactory::size();
    for(int index = 0; index < totalModule; index++) {
        //循环构建左侧边栏一级菜单按钮
        ModuleInfo *curModuleInfo = ModulesFactory::getModuleInfoByIndex(index);
        if (curModuleInfo == nullptr) {
            continue;
        }
        int type = curModuleInfo->moduleType;
        if (ModulesFactory::checkModuleType(type)){   // 一级菜单不会有多个
            QString mnameString = curModuleInfo->moduleName;
            const QString locale = QLocale::system().name();
            QString mnamei18nString = curModuleInfo->getModuleNameLocale(locale);
            if (m_ModuleMap.keys().contains(mnameString)) {
                if (!m_ModuleMap[mnameString].toBool()) {
                    continue;
                }
            }

            QList<QStandardItem *> secondList;
            QList<PluginInfo> functionStructList = curModuleInfo->pluginInfoList;
            if (functionStructList.size() <= 0) { // 下属无插件,不显示
                continue;
            }
            int showModuleCount = 0;
            for (int funcIndex = 0; funcIndex < functionStructList.size(); funcIndex++) {
                PluginInfo single = functionStructList.at(funcIndex);

                //跳过插件不存在的功能项
                if (!ModulesFactory::checkPluginExist(single.namei18nString) || !single.isEnable) {
                    continue;
                }

                bool plgIsVisiable = false;
                if (m_ModuleMap.keys().contains(single.nameString.toLower())) {
                    if (!m_ModuleMap[single.nameString.toLower()].toBool()) {
                        m_searchWidget->hiddenSearchItem(single.namei18nString, false);
                        continue;
                    }
                    else plgIsVisiable = true;
                } else {
                    plgIsVisiable = true;
                }

                // intel与sp1做区分
                if ((UkccCommon::isTablet() && single.nameString == "Userinfo")
                    || (!UkccCommon::isTablet() && single.nameString == "Userinfointel")) {
                    continue;
                }

                //填充左侧菜单
                QObject* pluginObj = ModulesFactory::getPluginObjectByName(single.namei18nString);
                if (pluginObj == nullptr) {
                    continue;
                }
                CommonInterface * pluginInstance = qobject_cast<CommonInterface *>(pluginObj);
                QStandardItem *pluginItem = new QStandardItem(pluginInstance->icon(), single.namei18nString);
                secondList << pluginItem;
                pluginItem->setData(type, Qt::UserRole+1);
                pluginItem->setData(single.namei18nString, Qt::UserRole+2);
                pluginInstance->pluginBtn = pluginItem;
                // 初始化插件状态
                QGSettings *msettings = nullptr;
                int row = scrollArea->model()->rowCount() + secondList.count();
                if (vecGsettins.contains(single.oriNameString)) {
                    msettings = vecGsettins[single.oriNameString];
                    if (msettings && plgIsVisiable) {
                        connect(msettings, &QGSettings::changed,[=](QString key){
                            bool visible = !pluginInstance->isEnable() ? false : msettings->get(SHOW_KEY).toBool();
                            qDebug() << "isEnable = " << pluginInstance->isEnable();
                            if (key == SHOW_KEY) {
                                if (!msettings->get(SHOW_KEY).toBool() && scrollArea->listview()->currentIndex().row() == row) {
                                    ui->stackedWidget->setCurrentIndex(0);
                                }
                                scrollArea->listview()->setRowHidden(row, !visible);
                                m_searchWidget->hiddenSearchItem(QLocale::system().name() == "zh_CN" ? single.namei18nString : single.oriNameString, visible);
                            }
                        });
                    }
                }
                ++showModuleCount;
            }
            // 下属无插件,不显示
            if (curModuleInfo->pluginInfoList.size() == 0 || showModuleCount == 0 || secondList.size() == 0) {
                continue;
            }
            scrollArea->addGroupItems(secondList, mnamei18nString);
            for (int funcIndex = 0; funcIndex < functionStructList.size(); funcIndex++) {
                PluginInfo single = functionStructList.at(funcIndex);
                if (!single.isEnable) {
                    QList<QStandardItem *> itemList = scrollArea->model()->findItems(single.namei18nString);
                    if (!itemList.isEmpty()) {
                        qDebug() << "row = " << scrollArea->model()->indexFromItem(itemList.at(0)).row() << ";" <<single.namei18nString;
                        scrollArea->listview()->setRowHidden(scrollArea->model()->indexFromItem(itemList.at(0)).row(), true);
                        m_searchWidget->hiddenSearchItem(QLocale::system().name() == "zh_CN" ? single.namei18nString : single.oriNameString, true);
                    }
                }
            }
        }
    }

    connect(scrollArea->listview(), &QListView::clicked, this, [=](const QModelIndex &index){
        qDebug() << "index = " << index.data(Qt::UserRole+2).toString();
        QString pluginil8Name =  index.data(Qt::UserRole+2).toString();
        QObject* pluginObj = ModulesFactory::getPluginObjectByName(pluginil8Name);
        if (pluginObj != nullptr) {
            CommonInterface * pluginInstance = qobject_cast<CommonInterface *>(pluginObj);
            if (pluginInstance) {
                modulepageWidget->refreshPluginWidget(pluginInstance);

                // 埋点点击左侧导航插件
                UkccCommon::buriedSettings(pluginInstance->name(), nullptr, QString("left clicked"));
            }
        }
    });
    ui->leftBotLayout->addWidget(scrollArea);
}

QGSettings *MainWindow::setGsettingsPath(QList<char *> list, QString name)
{
    // 为每个插件创建动态QGSettings对象,用于监听插件是否隐藏
    QByteArray ba;
    char *path;
    ba = (QString("%1%2").arg(name).arg("/")).toUtf8();
    path = ba.data();
    const QByteArray id(PLUGINS_SCHEMA);
    if (!QGSettings::isSchemaInstalled(id)) {
        return nullptr;
    }
    QGSettings *settings = nullptr;
    QString plugin = QString("%1%2%3").arg(PLUGINS_PATH).arg(name).arg("/");
    settings = new QGSettings(id, plugin.toUtf8().data(), this);

    //判断是否已存在该路径,不存在则赋初值
    for (int j = 0; j < list.count(); j++) {
        if (!qstrcmp(path, list.at(j))){
            return settings;
        }
    }
    settings->set(PLUGIN_NAME, name);
    settings->set(SHOW_KEY, true);
    return settings;
}

bool MainWindow::isExitsCloudAccount() {
    QProcess *wifiPro = new QProcess();
    QString shellOutput = "";
    wifiPro->start("dpkg -l  | grep kylin-sso-client");
    wifiPro->waitForFinished();
    QString output = wifiPro->readAll();
    shellOutput += output;
    QStringList slist = shellOutput.split("\n");

    for (QString res : slist) {
        if (res.contains("kylin-sso-client")) {
            return true;
        }
    }
    return false;
}

bool MainWindow::isExitsPower()
{
    QProcess *process = new QProcess;
    process->start("dpkg -l ukui-power-manager");
    process->waitForFinished();

    QByteArray ba = process->readAllStandardOutput();
    delete process;
    QString mOutput = QString(ba.data());

    return mOutput.contains("ii", Qt::CaseSensitive) ? true : false;
}

bool MainWindow::isExitWirelessDevice()
{
    QDBusInterface *interface = new QDBusInterface("com.kylin.network", "/com/kylin/network",
                                     "com.kylin.network",
                                     QDBusConnection::sessionBus());
    if (!interface->isValid()) {
        qDebug() << "/com/kylin/network is invalid";
        return false;
    }

    QDBusMessage result = interface->call(QStringLiteral("getDeviceListAndEnabled"),1);
    if(result.type() == QDBusMessage::ErrorMessage) {
        qWarning() << "getWirelessDeviceList error:" << result.errorMessage();
        return false;
    }

    auto dbusArg =  result.arguments().at(0).value<QDBusArgument>();
    QMap<QString, bool> deviceListMap;
    dbusArg >> deviceListMap;


    if (deviceListMap.isEmpty()) {
        qDebug() << "no wireless device";
        return false;
    }
    return true;
}

bool MainWindow::dblOnEdge(QMouseEvent *event) {
    QPoint pos = event->globalPos();
    int globalMouseY = pos.y();

    int frameY = this->y();

    bool onTopEdges = (globalMouseY >= frameY &&
                       globalMouseY <= frameY + dbWitdth);
    return onTopEdges;
}

void MainWindow::initStyleSheet() {
    // 设置panel图标
    QIcon panelicon;
    if (QIcon::hasThemeIcon("ukui-control-center"))
        panelicon = QIcon::fromTheme("ukui-control-center");

    qApp->setWindowIcon(panelicon);
    this->setWindowTitle(tr("Settings"));
    ui->stackedWidget->setAutoFillBackground(true);

    // 左上角返回按钮
    backBtn->setProperty("useIconHighlightEffect", true);
    backBtn->setProperty("iconHighlightEffectMode", 1);
    backBtn->setFlat(true);

    mOptionBtn->setProperty("useIconHighlightEffect", 0x2);
    mOptionBtn->setProperty("isWindowButton", 0x01);
    mOptionBtn->setAutoRaise(true);

    minBtn->setProperty("useIconHighlightEffect", 0x2);
    minBtn->setProperty("isWindowButton", 0x01);
    minBtn->setFlat(true);

    maxBtn->setProperty("useIconHighlightEffect", 0x2);
    maxBtn->setProperty("isWindowButton", 0x1);
    maxBtn->setFlat(true);

    closeBtn->setProperty("isWindowButton", 0x02);
    closeBtn->setProperty("useIconHighlightEffect", 0x08);
    closeBtn->setFlat(true);

    ui->centralWidget->setAttribute(Qt::WA_TranslucentBackground);
    ui->leftsidebarWidget->setFixedWidth(260); //一级菜单宽度

    // 设置左上角按钮图标
    backBtn->setIcon(QIcon::fromTheme("go-home-symbolic"));
    backBtn->setIconSize(QSize(16, 16));

    // 设置右上角按钮图标
    mOptionBtn->setIcon(QIcon::fromTheme("open-menu-symbolic"));
    minBtn->setIcon(QIcon::fromTheme("window-minimize-symbolic"));
    maxBtn->setIcon(QIcon::fromTheme("window-maximize-symbolic"));
    closeBtn->setIcon(QIcon::fromTheme("window-close-symbolic"));
}

void MainWindow::showGuide(QString pluName)
{
    QString service_name = "com.kylinUserGuide.hotel_" + QString::number(getuid());
    QDBusInterface *interface = new QDBusInterface(service_name,
                                                   KYLIN_USER_GUIDE_PATH,
                                                   KYLIN_USER_GUIDE_INTERFACE,
                                                   QDBusConnection::sessionBus(),
                                                   this);
    QDBusMessage msg = interface->call("showGuide" , pluName);
}

void MainWindow::hideComponent()
{
    QTimer::singleShot(100, this, [=]() {
        if(UkccCommon::isTablet()) {
            if (QApplication::arguments().length() < 2) {
                initPageWidget();
                bootOptionsFilter("userinfointel");
            }
            backBtn->hide();
        }
    });
}

void MainWindow::setModuleBtnHightLight(int id) {
    leftBtnGroup->button(id)->setChecked(true);
    leftMicBtnGroup->button(id)->setChecked(true);
}

void MainWindow::pluginBtnClicked(QObject *plugin) {

    CommonInterface * pluginInstance = qobject_cast<CommonInterface *>(plugin);
    UkccCommon::buriedSettings(pluginInstance->name(), nullptr, "home clicked");

    functionBtnClicked(plugin);
}

void MainWindow::functionBtnClicked(QObject *plugin, QString jumpText) {
    if (!scrollArea)
        return;

    ui->stackedWidget->setCurrentIndex(1);
    modulepageWidget->switchPage(plugin, true, jumpText);

    CommonInterface * pluginInstance = qobject_cast<CommonInterface *>(plugin);
    scrollArea->listview()->setCurrentIndex(pluginInstance->pluginBtn->index());
    QRect size = scrollArea->listview()->visualRect(scrollArea->listview()->currentIndex());
    qDebug() << "size.y() = " <<size.y() << "size.height() = " << size.height() << "step = " << scrollArea->height() << "scrollArea->height()/2" << scrollArea->height()/2;
    int value = size.y() + size.height() - scrollArea->height();
    value = value + scrollArea->height()/2; //尽量让选中的显示在中间位置
    if (value <= 0) {
        scrollArea->verticalScrollBar()->setValue(0);
    } else if (value > scrollArea->verticalScrollBar()->maximum()){
        scrollArea->verticalScrollBar()->setValue(scrollArea->verticalScrollBar()->maximum());
    } else {
        scrollArea->verticalScrollBar()->setValue(value);
    }
}

void MainWindow::sltMessageReceived(const QString &msg) {
    QString platform = QGuiApplication::platformName();
    if(platform.startsWith(QLatin1String("wayland"),Qt::CaseInsensitive)) {
        if (!m_listWinIds.isEmpty()) {
            WindowManager::activateWindow(m_listWinIds.back());
        }
    } else {
        KWindowSystem::forceActiveWindow(this->winId());
    }
    this->initPageWidget();
    this->show();
    bootOptionsFilter(msg, false);
}

QVariantMap MainWindow::getSearchItems() {
    return m_searchWidget->getSearchItems();
}

void MainWindow::switchPage(QString moduleName, QString jumpMoudle, QString jumpText) {
    //开始跳转
    QObject* pluginObj = ModulesFactory::getPluginObjectByName(moduleName);
    if (pluginObj != nullptr) {
        if (m_ModuleMap.isEmpty()) {
            functionBtnClicked(pluginObj);
            return;
        } else {
            QString superordinate = ModulesFactory::getModuleNamebyName(jumpMoudle);
            // 若跳转节点或跳转节点父节点不存在直接跳转,不受管控文件控制,若存在,则根据管控文件判断是否被禁用
            if (!m_ModuleMap.contains(jumpMoudle.toLower()) || !m_ModuleMap.contains(superordinate.toLower())
                    || (m_ModuleMap[jumpMoudle.toLower()].toBool() && m_ModuleMap[superordinate.toLower()].toBool())) {
                functionBtnClicked(pluginObj);
                return;
            }
        }
    }
    QMessageBox::information(this, tr("Warning"), tr("This function has been controlled"));
    return;
}

void MainWindow::moveEvent(QMoveEvent *event)
{
    Q_UNUSED(event);
    Q_EMIT posChanged();
}

void MainWindow::resizeEvent(QResizeEvent *event)
{
    QMainWindow::resizeEvent(event);
    Q_EMIT posChanged();
}

QString MainWindow::pluginBtnHoverColor(QString styleName, bool hoverFlag)
{
    QColor color1 = palette().color(QPalette::Active, QPalette::Button);
    QColor color2 = palette().color(QPalette::Active, QPalette::BrightText);
    QColor color;
    qreal r,g,b,a;
    QString hoverColor;
    if (((styleName.contains("dark") || styleName.contains("black")) && hoverFlag) ||
        ((!styleName.contains("dark") && !styleName.contains("black")) && !hoverFlag)) {
        r = color1.redF() * 0.8 + color2.redF() * 0.2;
        g = color1.greenF() * 0.8 + color2.greenF() * 0.2;
        b = color1.blueF() * 0.8 + color2.blueF() * 0.2;
        a = color1.alphaF() * 0.8 + color2.alphaF() * 0.2;
    } else {
        r = color1.redF() * 0.95 + color2.redF() * 0.05;
        g = color1.greenF() * 0.95 + color2.greenF() * 0.05;
        b = color1.blueF() * 0.95 + color2.blueF() * 0.05;
        a = color1.alphaF() * 0.95 + color2.alphaF() * 0.05;
    }
    color = QColor::fromRgbF(r, g, b, a);
    hoverColor = QString("rgba(%1, %2, %3, %4)").arg(color.red())
                                                .arg(color.green())
                                                .arg(color.blue())
                                                .arg(color.alpha());
    return hoverColor;
}