~ubuntu-branches/ubuntu/vivid/youker-assistant/vivid

« back to all changes in this revision

Viewing changes to src/updatedialog.cpp

  • Committer: Package Import Robot
  • Author(s): Kobe Lee (kylinkobe)
  • Date: 2013-09-18 16:22:14 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130918162214-6nqyjyf3cd3ynqky
Tags: 0.2.1-0ubuntu1
* Modify the mouse events of MonitorBall.
* Add reset button for clear pages.
* Add policykit for apt clear in sudodbus.
* Fixed the bug about software status and add masklayer.
* Rewrite the code of system information.
* Add some signals and slots.
* Fixed the bug about Software signals(LP: #1226389).
* Modify KThread and add base.py.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 National University of Defense Technology(NUDT) & Kylin Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
#include "updatedialog.h"
 
17
#include "ui_updatedialog.h"
 
18
#include <QMouseEvent>
 
19
#include <QDebug>
 
20
UpdateDialog::UpdateDialog(QWidget *parent) :
 
21
    QDialog(parent),
 
22
    ui(new Ui::UpdateDialog)
 
23
{
 
24
    ui->setupUi(this);
 
25
    this->setAttribute(Qt::WA_DeleteOnClose);//防止内存泄漏
 
26
    this->setWindowFlags(Qt::FramelessWindowHint);
 
27
    this->setAttribute(Qt::WA_TranslucentBackground);
 
28
    ui->btn_close->installEventFilter(this);
 
29
    ui->btn_close->setStyleSheet("border-image:url(:/pixmap/image/closeBtn.png)");
 
30
    ui->okButton->setStyleSheet("QPushButton {border-image:url(:/pixmap/image/ok.png);}"
 
31
                "QPushButton:hover{border-image:url(:/pixmap/image/ok-hover.png);}");
 
32
    //QLabel自动换行
 
33
    ui->displaylabel->setWordWrap(true);
 
34
    ui->displaylabel->setText("没有找到该软件,请尝试更新软件源。");
 
35
    QObject::connect(ui->okButton,SIGNAL(clicked()),this,SLOT(update_software_source()));
 
36
    QObject::connect(ui->closeButton,SIGNAL(clicked()),this,SLOT(hide()));
 
37
}
 
38
 
 
39
UpdateDialog::~UpdateDialog() {
 
40
    delete ui;
 
41
}
 
42
 
 
43
void UpdateDialog::update_software_source() {
 
44
    emit call_update();
 
45
    this->hide();
 
46
}
 
47
 
 
48
bool UpdateDialog::eventFilter(QObject *obj, QEvent *event) {
 
49
    if(obj == ui->btn_close){
 
50
            if(event->type() == QEvent::Enter){
 
51
                ui->btn_close->setPixmap(QPixmap(":/pixmap/image/closeBtn-hover.png"));
 
52
            }else if(event->type() == QEvent::Leave){
 
53
                ui->btn_close->setPixmap(QPixmap(":/pixmap/image/closeBtn.png"));
 
54
            }else if(event->type() == QEvent::MouseButtonPress){
 
55
                ui->btn_close->setPixmap(QPixmap(":/pixmap/image/closeBtn-hover.png"));
 
56
            }else if(event->type() == QEvent::MouseButtonRelease){
 
57
                QMouseEvent *me = (QMouseEvent *)event;
 
58
                QLabel *lb = (QLabel *)obj;
 
59
                if(me->x() > 0 && me->x() < lb->width() && me->y() > 0 && me->y() < lb->height()){
 
60
//                    this->close();
 
61
                    this->hide();
 
62
                }else{
 
63
                    ui->btn_close->setPixmap(QPixmap(":/pixmap/image/closeBtn.png"));
 
64
                }
 
65
            } else {
 
66
                return QObject::eventFilter(obj, event);
 
67
            }
 
68
        }
 
69
    return QObject::eventFilter(obj, event);
 
70
 
 
71
 
 
72
}
 
73
 
 
74
void UpdateDialog::mousePressEvent(QMouseEvent *event) {
 
75
    if (event->button() == Qt::LeftButton) {
 
76
        dragPos = event->globalPos() - frameGeometry().topLeft();
 
77
        event->accept();
 
78
    }
 
79
}
 
80
 
 
81
void UpdateDialog::mouseMoveEvent(QMouseEvent *event) {
 
82
    if (event->buttons() & Qt::LeftButton ) {
 
83
        move(event->globalPos() - dragPos);
 
84
        setWindowOpacity(0.5);
 
85
    }
 
86
    event->accept();
 
87
}
 
88
 
 
89
void UpdateDialog::mouseReleaseEvent(QMouseEvent *event) {
 
90
    if (event->button() == Qt::LeftButton) {
 
91
        setWindowOpacity(1);
 
92
    }
 
93
    event->accept();
 
94
}