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

« back to all changes in this revision

Viewing changes to mainui/homepage.cpp

  • Committer: kobe
  • Date: 2015-02-13 07:37:10 UTC
  • Revision ID: xiangli@ubuntukylin.com-20150213073710-0jyp02ilyi5njj10
Qt Version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "homepage.h"
 
2
//#include "../component/commontoolbutton.h"
 
3
#include <QSignalMapper>
 
4
#include <QDebug>
 
5
#include "mainwindow.h"
 
6
 
 
7
HomePage::HomePage(QWidget *parent) :
 
8
    QWidget(parent)
 
9
{
 
10
    this->setFixedSize(900, 326);
 
11
 
 
12
    //set white background color
 
13
    this->setAutoFillBackground(true);
 
14
    QPalette palette;
 
15
    palette.setBrush(QPalette::Window, QBrush(Qt::white));
 
16
    this->setPalette(palette);
 
17
 
 
18
////    QPixmap label_pixmap("");
 
19
////    movie_label->setPixmap(label_pixmap);
 
20
////    movie_label->setFixedSize(label_pixmap.size());
 
21
 
 
22
//    scan_button->setFocusPolicy(Qt::NoFocus);
 
23
//    QPixmap pixmap("://res/scan.png");
 
24
//    scan_button->setIcon(pixmap);
 
25
//    scan_button->setIconSize(pixmap.size());
 
26
 
 
27
    version_logo = new QLabel();
 
28
    version_title = new QLabel();
 
29
    version_tip = new QLabel();
 
30
    check_btn = new QPushButton();
 
31
    box_logo = new QLabel();
 
32
    box_title = new QLabel();
 
33
    box_tip = new QLabel();
 
34
    more_text_btn = new QPushButton();
 
35
    more_btn = new QPushButton();
 
36
 
 
37
    auto_start = NULL;
 
38
    camera_manager = NULL;
 
39
 
 
40
//    software_btn = new CommonToolButton();
 
41
//    boot_btn = new CommonToolButton();
 
42
//    camera_btn = new CommonToolButton();
 
43
//    more_text_btn->setAlignment(Qt::AlignCenter);
 
44
    more_text_btn->setObjectName("checkButton");
 
45
    more_text_btn->setCursor(Qt::PointingHandCursor);
 
46
    more_text_btn->setFocusPolicy(Qt::NoFocus);
 
47
    check_btn->setObjectName("checkButton");
 
48
    check_btn->setCursor(Qt::PointingHandCursor);
 
49
    check_btn->setFocusPolicy(Qt::NoFocus);
 
50
    version_title->setObjectName("bigblackLabel");
 
51
    box_title->setObjectName("bigblackLabel");
 
52
    version_tip->setAlignment(Qt::AlignLeft);
 
53
    version_tip->setObjectName("smallgrayLabel");
 
54
    box_tip->setAlignment(Qt::AlignLeft);
 
55
    box_tip->setObjectName("smallgrayLabel");
 
56
    version_tip->setWordWrap(true);//QLabel自动换行
 
57
    box_tip->setWordWrap(true);//QLabel自动换行
 
58
    more_btn->setObjectName("transparentButton");
 
59
    more_btn->setCursor(Qt::PointingHandCursor);
 
60
 
 
61
    version_logo->setFixedSize(65, 65);
 
62
    version_logo->setPixmap(QPixmap("://res/version.png"));
 
63
    box_logo->setFixedSize(65, 65);
 
64
    box_logo->setPixmap(QPixmap("://res/box.png"));
 
65
 
 
66
 
 
67
 
 
68
    this->setLanguage();
 
69
}
 
70
 
 
71
HomePage::~HomePage()
 
72
{
 
73
    if(auto_start != NULL)
 
74
    {
 
75
        delete auto_start;
 
76
        auto_start = NULL;
 
77
    }
 
78
    if(camera_manager != NULL)
 
79
    {
 
80
        delete camera_manager;
 
81
        camera_manager = NULL;
 
82
    }
 
83
}
 
84
 
 
85
void HomePage::initUI()
 
86
{
 
87
    QHBoxLayout *layout1 = new QHBoxLayout();
 
88
    layout1->addWidget(version_title);
 
89
    layout1->addWidget(check_btn);
 
90
    layout1->addStretch();
 
91
    layout1->setMargin(0);
 
92
    layout1->setSpacing(5);
 
93
    layout1->setContentsMargins(0,0,0,0);
 
94
    QVBoxLayout *layout2 = new QVBoxLayout();
 
95
    layout2->addStretch();
 
96
    layout2->addLayout(layout1);
 
97
    layout2->addWidget(version_tip);
 
98
    layout2->addStretch();
 
99
    layout2->setMargin(0);
 
100
    layout2->setSpacing(5);
 
101
    layout2->setContentsMargins(0,0,0,0);
 
102
    QHBoxLayout *layout3 = new QHBoxLayout();
 
103
    layout3->addWidget(version_logo/* ,0, Qt::AlignVCenter*/);
 
104
    layout3->addLayout(layout2);
 
105
    layout3->addStretch();
 
106
    layout3->setMargin(0);
 
107
    layout3->setSpacing(5);
 
108
    layout3->setContentsMargins(0,0,0,0);
 
109
 
 
110
    QVBoxLayout *layout4 = new QVBoxLayout();
 
111
    layout4->addStretch();
 
112
    layout4->addWidget(box_title);
 
113
    layout4->addWidget(box_tip);
 
114
    layout4->addStretch();
 
115
    layout4->setMargin(0);
 
116
    layout4->setSpacing(5);
 
117
    layout4->setContentsMargins(0,0,0,0);
 
118
 
 
119
 
 
120
 
 
121
 
 
122
    QStringList icon_list;
 
123
//    icon_list<<"://res/ubuntukylin-software-center"<<"://res/boot"<<"://res/camera";
 
124
    icon_list<<"://res/boot"<<"://res/camera";
 
125
    QStringList text_list;
 
126
//    text_list<< tr("Youker Softeware Center") << tr("Boot Manager") << tr("Camera");
 
127
    text_list << tr("Boot Manager") << tr("Camera");
 
128
    QHBoxLayout *button_layout = new QHBoxLayout();
 
129
    QSignalMapper *signal_mapper = new QSignalMapper(this);
 
130
    for(int i=0; i<icon_list.size(); i++)
 
131
    {
 
132
        QToolButton *tool_button = new QToolButton();
 
133
        tool_button->setFocusPolicy(Qt::NoFocus);
 
134
        tool_button->setText(text_list.at(i));
 
135
        tool_button->setIcon(QIcon(icon_list.at(i)));
 
136
        tool_button->setIconSize(QPixmap(icon_list.at(i)).size());
 
137
        tool_button->setAutoRaise(true);
 
138
        tool_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
 
139
        tool_button->setObjectName("commonToolButton");
 
140
        tool_button->setFixedSize(110, 110);
 
141
//        tool_button->setContentsMargins(0, 20, 0, 30);
 
142
 
 
143
        button_list.append(tool_button);
 
144
        connect(tool_button, SIGNAL(clicked()), signal_mapper, SLOT(map()));
 
145
        signal_mapper->setMapping(tool_button, QString::number(i, 10));
 
146
        button_layout->addWidget(tool_button, 0, Qt::AlignBottom);
 
147
    }
 
148
    connect(signal_mapper, SIGNAL(mapped(QString)), this, SLOT(switchPageIndex(QString)));
 
149
 
 
150
 
 
151
    more_btn->setFocusPolicy(Qt::NoFocus);
 
152
    QPixmap pixmap("://res/more.png");
 
153
    more_btn->setIcon(pixmap);
 
154
    more_btn->setIconSize(pixmap.size());
 
155
 
 
156
    QVBoxLayout *more_layout = new QVBoxLayout();
 
157
    more_layout->addStretch();
 
158
    more_layout->addWidget(more_btn);
 
159
    more_layout->addWidget(more_text_btn);
 
160
    more_layout->addStretch();
 
161
    more_layout->setSpacing(0);
 
162
    more_layout->setMargin(0);
 
163
    more_layout->setContentsMargins(0, 0, 0, 0);
 
164
 
 
165
    button_layout->addStretch();
 
166
    button_layout->addLayout(more_layout);
 
167
//    button_layout->addWidget(more_btn, 0, Qt::AlignTop);
 
168
    button_layout->setSpacing(20);
 
169
    button_layout->setMargin(0);
 
170
    button_layout->setContentsMargins(0, 0, 0, 0);
 
171
 
 
172
    QHBoxLayout *layout5 = new QHBoxLayout();
 
173
    layout5->addWidget(box_logo);
 
174
    layout5->addLayout(layout4);
 
175
    layout5->addStretch();
 
176
    layout5->addLayout(button_layout);
 
177
    layout5->setMargin(0);
 
178
    layout5->setSpacing(5);
 
179
    layout5->setContentsMargins(0,0,0,0);
 
180
 
 
181
 
 
182
 
 
183
    QVBoxLayout *main_layout = new QVBoxLayout();
 
184
    main_layout->addLayout(layout3);
 
185
    main_layout->addLayout(layout5);
 
186
    main_layout->setMargin(0);
 
187
    main_layout->setSpacing(50);
 
188
    main_layout->setContentsMargins(60,50,60,80);
 
189
 
 
190
    this->setLayout(main_layout);
 
191
}
 
192
 
 
193
void HomePage::initConnect()
 
194
{
 
195
    connect(more_btn, SIGNAL(clicked()), p_mainwindow, SLOT(showBoxWidget()));
 
196
    connect(more_btn, SIGNAL(clicked()), p_mainwindow, SIGNAL(chanegBoxToolStatus()));
 
197
    connect(more_text_btn, SIGNAL(clicked()), p_mainwindow, SLOT(showBoxWidget()));
 
198
    connect(more_text_btn, SIGNAL(clicked()), p_mainwindow, SIGNAL(chanegBoxToolStatus()));
 
199
}
 
200
 
 
201
void HomePage::setLanguage()
 
202
{
 
203
    version_title->setText(tr("Current Version Number") + "    " + "V2.0.0");
 
204
    version_tip->setText(tr("Update to the lastest version, make it work better"));
 
205
    check_btn->setText(tr("Check new version"));
 
206
    box_title->setText(tr("Common toolbox"));
 
207
    box_tip->setText(tr("Fast and practical, making the system more personalized"));
 
208
    more_text_btn->setText(tr("More"));
 
209
    more_btn->setToolTip(tr("More"));
 
210
}
 
211
 
 
212
void HomePage::initBoxTool()
 
213
{
 
214
 
 
215
}
 
216
 
 
217
void HomePage::switchPageIndex(QString index)
 
218
{
 
219
//    bool ok;
 
220
//    int current_index = index.toInt(&ok, 10);
 
221
//    qDebug() << index;
 
222
 
 
223
    if(index == "0")
 
224
    {
 
225
        if(auto_start == NULL) {
 
226
            auto_start = new AutoStartWidget(0, sessionProxy);
 
227
            connect(sessionProxy, SIGNAL(tellAutoModel(QStringList)), auto_start, SLOT(readyReciveData(QStringList)));
 
228
            connect(sessionProxy, SIGNAL(showAutoModel()), auto_start, SLOT(readyShowUI()));
 
229
            auto_start->initData();
 
230
            int w_x = p_mainwindow->frameGeometry().topLeft().x() + (900 / 2) - (560  / 2);
 
231
            int w_y = p_mainwindow->frameGeometry().topLeft().y() + (600 /2) - (398  / 2);
 
232
            auto_start->move(w_x, w_y);
 
233
            auto_start->show();
 
234
            auto_start->raise();
 
235
        }
 
236
        else {
 
237
            int w_x = p_mainwindow->frameGeometry().topLeft().x() + (900 / 2) - (560  / 2);
 
238
            int w_y = p_mainwindow->frameGeometry().topLeft().y() + (600 /2) - (398  / 2);
 
239
            auto_start->move(w_x, w_y);
 
240
            auto_start->show();
 
241
            auto_start->raise();
 
242
        }
 
243
    }
 
244
 
 
245
    else if(index == "1")
 
246
    {
 
247
        if(camera_manager == NULL) {
 
248
            camera_manager = new CameraManager(0, sessionProxy);
 
249
            if(sessionProxy->judge_camera_qt())
 
250
            {
 
251
                camera_manager->setOKButtonEnable(true);
 
252
            }
 
253
            else{
 
254
                camera_manager->setOKButtonEnable(false);
 
255
            }
 
256
            int w_x = p_mainwindow->frameGeometry().topLeft().x() + (900 / 2) - (524  / 2);
 
257
            int w_y = p_mainwindow->frameGeometry().topLeft().y() + (600 /2) - (277  / 2);
 
258
            camera_manager->move(w_x, w_y);
 
259
            camera_manager->show();
 
260
            camera_manager->raise();
 
261
        }
 
262
        else {
 
263
            int w_x = p_mainwindow->frameGeometry().topLeft().x() + (900 / 2) - (524  / 2);
 
264
            int w_y = p_mainwindow->frameGeometry().topLeft().y() + (600 /2) - (277  / 2);
 
265
            camera_manager->move(w_x, w_y);
 
266
            camera_manager->show();
 
267
            camera_manager->raise();
 
268
        }
 
269
    }
 
270
//    for(int i=0; i<button_list.count(); i++)
 
271
//    {
 
272
////        CommonToolButton *tool_button = button_list.at(i);
 
273
//        QToolButton *tool_button = button_list.at(i);
 
274
//        if(current_index == i)
 
275
//        {
 
276
//            tool_button->setMousePress(true);
 
277
//        }
 
278
//        else
 
279
//        {
 
280
//            tool_button->setMousePress(false);
 
281
//        }
 
282
//    }
 
283
}