~feng-kylin/youker-assistant/youker-assistant

« back to all changes in this revision

Viewing changes to src/middlewidget.cpp

  • Committer: lixiang
  • Date: 2018-03-06 03:13:06 UTC
  • Revision ID: lixiang@kylinos.cn-20180306031306-fd7qnru3vm4a1xjd
Rewrite with Qt5, and add system monitor

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 ~ 2015 National University of Defense Technology(NUDT) & Kylin Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *  Kobe Lee    xiangli@ubuntukylin.com/kobe24_lixiang@126.com
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; version 3.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include "middlewidget.h"
 
21
#include "../component/kylintoolbutton.h"
 
22
#include "mainwindow.h"
 
23
#include <QDebug>
 
24
 
 
25
MiddleWidget::MiddleWidget(QWidget *parent, QString arch, QString os)
 
26
    : QWidget(parent), cur_arch(arch), osname(os)
 
27
{
 
28
    this->setFixedSize(900, 47);
 
29
    this->setAutoFillBackground(true);
 
30
    QPalette palette;
 
31
    palette.setColor(QPalette::Background, QColor(233,238,241));//#e9eef1
 
32
    this->setPalette(palette);
 
33
 
 
34
    QStringList icon_list;
 
35
    QStringList text_list;
 
36
//    if(this->cur_arch == "aarch64" || this->osname == "Kylin" || this->osname == "YHKylin")
 
37
//    {
 
38
//        icon_list<<":/tool/res/menu/home"<<":/tool/res/menu/cleanup"<<":/tool/res/menu/sysinfo"<<":/tool/res/menu/toolkits";
 
39
//        text_list<< tr("KylinHome") << tr("Cleanup") << tr("Sysinfo") << tr("Toolkits");
 
40
//    }
 
41
//    else {
 
42
        icon_list<<":/tool/res/menu/home"<<":/tool/res/menu/cleanup"<<":/tool/res/menu/sysinfo"<<":/tool/res/menu/feature"<<":/tool/res/menu/toolkits";
 
43
        text_list<< tr("Home") << tr("Cleanup") << tr("Sysinfo") << tr("Feature") << tr("Toolkits");
 
44
//    }
 
45
 
 
46
    QHBoxLayout *button_layout = new QHBoxLayout();
 
47
 
 
48
    QSignalMapper *signal_mapper = new QSignalMapper(this);
 
49
    for(int i=0; i<icon_list.size(); i++)
 
50
    {
 
51
        KylinToolButton *tool_button = new KylinToolButton(icon_list.at(i), text_list.at(i));
 
52
        tool_button->setFixedSize(180, 47);
 
53
        button_list.append(tool_button);
 
54
        connect(tool_button, SIGNAL(clicked()), signal_mapper, SLOT(map()));
 
55
        signal_mapper->setMapping(tool_button, QString::number(i, 10));
 
56
        button_layout->addWidget(tool_button, 0, Qt::AlignBottom);
 
57
    }
 
58
    this->switchSelectedPageIndex("0");
 
59
    connect(signal_mapper, SIGNAL(mapped(QString)), this, SLOT(switchSelectedPageIndex(QString)));
 
60
 
 
61
    button_layout->addStretch();
 
62
    button_layout->setSpacing(8);
 
63
    button_layout->setMargin(0);
 
64
    button_layout->setContentsMargins(15, 0, 15, 0);
 
65
 
 
66
    setLayout(button_layout);
 
67
    is_move = false;
 
68
}
 
69
 
 
70
MiddleWidget::~MiddleWidget()
 
71
{
 
72
    for(int i=0; i<button_list.count(); i++)
 
73
    {
 
74
        KylinToolButton *btn = button_list.at(i);
 
75
        delete btn;
 
76
        btn = NULL;
 
77
    }
 
78
    button_list.clear();
 
79
}
 
80
 
 
81
void MiddleWidget::switchSelectedPageIndex(QString index)
 
82
{
 
83
    bool ok;
 
84
    int current_index = index.toInt(&ok, 10);
 
85
 
 
86
    for(int i=0; i<button_list.count(); i++)
 
87
    {
 
88
        KylinToolButton *tool_button = button_list.at(i);
 
89
        if(current_index == i)
 
90
        {
 
91
            tool_button->setMousePress(true);
 
92
        }
 
93
        else
 
94
        {
 
95
            tool_button->setMousePress(false);
 
96
        }
 
97
    }
 
98
    emit turnCurrentPage(current_index);
 
99
}
 
100
 
 
101
void MiddleWidget::showBoxTool()
 
102
{
 
103
//    if(this->cur_arch == "aarch64" || this->osname == "Kylin" || this->osname == "YHKylin") {
 
104
//        this->switchSelectedPageIndex("3");
 
105
//    }
 
106
//    else {
 
107
    this->switchSelectedPageIndex("4");
 
108
//    }
 
109
}