2
* Copyright (C) 2013 ~ 2014 National University of Defense Technology(NUDT) & Kylin Ltd.
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; version 3.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#include "slidershow.h"
20
#include <QDesktopWidget>
23
SliderShow::SliderShow(QWidget *parent)
30
this->setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint);
31
this->setAttribute(Qt::WA_TranslucentBackground);
32
this->resize(QSize(680, 372));
35
background_label = new QLabel(this);
36
background_label->setPixmap(QPixmap(":/pixmap/image/bg_bottom"));
37
background_label->setGeometry(QRect(0, 0, this->width(), this->height()));
39
//把所有要显示的图片设置到一个大的label中
40
QPixmap pixmap(QSize(this->width()*page_count, 372));
41
QPainter painter(&pixmap);
42
for(int i = 0; i < page_count; i++) {
43
painter.drawImage(QRect(680*i, 0, 680, 372), QImage(QString(":/pixmap/image/desktop_%1").arg(i)));
45
master_label = new QLabel(this);
46
master_label->resize(pixmap.size());
47
master_label->setPixmap(pixmap);
48
master_label->move(0, 0);
51
for(int i = 0; i < window_btn_count; i++)
54
label = new IconText(i, this);
55
label->resize(QSize(14, 14));
56
label->setIcon(QPixmap(QString(":/pixmap/image/dot_normal")));
57
label->move(300+i*14, 319);
58
connect(label, SIGNAL(ukclicked(int)), this, SLOT(changeCurrentPage(int)));
62
pic_array[0]->setMousePressFlag(true);
63
pic_array[0]->installEventFilter(this);
64
pic_array[1]->installEventFilter(this);
65
pic_array[2]->installEventFilter(this);
66
pic_array[3]->installEventFilter(this);
67
pic_array[4]->installEventFilter(this);
69
close_button = new KButton(this);
70
close_button->setPicName(":/pixmap/image/closeBtn");
71
close_button->resize(QSize(26, 20));
72
close_button->move(1, 1);
73
close_button->raise();
74
close_button->installEventFilter(this);
75
connect(close_button, SIGNAL(clicked()), this, SLOT(accept()));
78
hLayout = new QHBoxLayout(this);
79
start_button = new KButton(this);
81
locale_Lan = this->get_locale_version();
82
if(locale_Lan == "zh_CN") {
83
start_button->setPicName(":/pixmap/image/start");
86
start_button->setPicName(":/pixmap/image/start_en");
88
start_button->resize(QSize(180, 57));
89
start_button->raise();
91
hLayout->addWidget(start_button);
92
hLayout->setAlignment(Qt::AlignBottom | Qt::AlignHCenter);
93
start_button->installEventFilter(this);
94
connect(start_button, SIGNAL(clicked()), this, SLOT(start_run_program()));
96
timer=new QTimer(this);
97
connect(timer,SIGNAL(timeout()),this,SLOT(timerChangePosition()));
100
int windowWidth = QApplication::desktop()->width();
101
int windowHeight = QApplication::desktop()->height();
102
this->move((windowWidth - this->width()) / 2,(windowHeight - this->height()) / 2);
105
SliderShow::~SliderShow()
107
for (int i = 0; i < page_count; i++) {
112
delete background_label;
115
disconnect(timer,SIGNAL(timeout()),this,SLOT(timerChangePosition()));
116
if(timer->isActive()) {
124
QString SliderShow::get_locale_version() {
125
QString locale = QLocale::system().name();
129
bool SliderShow::eventFilter(QObject *obj, QEvent *event) {
130
if(obj == start_button || obj == close_button || obj == pic_array[0] || obj == pic_array[1] || obj == pic_array[2] || obj == pic_array[3] || obj == pic_array[4])
132
if (((QMouseEvent *)event)->button() == Qt::LeftButton) {
133
if (event->type() == QEvent::MouseButtonPress) {
138
return QObject::eventFilter(obj, event);
141
void SliderShow::mousePressEvent(QMouseEvent *event) {
142
if (event->button() == Qt::LeftButton) {
143
dragPos = event->globalPos() - frameGeometry().topLeft();
149
void SliderShow::mouseMoveEvent(QMouseEvent *event) {
150
if (event->buttons() & Qt::LeftButton ) {
152
move(event->globalPos() - dragPos);
153
setWindowOpacity(0.7);
159
void SliderShow::mouseReleaseEvent(QMouseEvent *event) {
160
if (event->button() == Qt::LeftButton) {
167
void SliderShow::changeCurrentPage(int index/*IconText *iconText*/)
171
for(int i = 0; i < window_btn_count; i++)
174
pic_array[i]->setMousePressFlag(true);
177
pic_array[i]->setMousePressFlag(false);
181
start_button->show();
184
start_button->hide();
187
int current_pos_x = master_label->x();
188
int dest_pos_x = -680 * index;
189
if(current_pos_x > dest_pos_x) {
190
while(current_pos_x > dest_pos_x)
192
master_label->move(current_pos_x-20, 0);
193
current_pos_x = master_label->x();
194
qApp->processEvents(QEventLoop::AllEvents);//防止界面冻结
197
else if(current_pos_x < dest_pos_x) {
198
while(current_pos_x < dest_pos_x)
200
master_label->move(current_pos_x+20, 0);
201
current_pos_x = master_label->x();
202
qApp->processEvents(QEventLoop::AllEvents);//防止界面冻结
205
master_label->move(dest_pos_x, 0);
206
current_index = index;
210
void SliderShow::timerChangePosition() {
211
if(current_index == page_count-1) {
213
pic_array[0]->setMousePressFlag(true);
214
this->changeCurrentPage(current_index);
218
this->changeCurrentPage(current_index);
222
void SliderShow::start_run_program() {