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

« back to all changes in this revision

Viewing changes to setting/switchmenu.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 "switchmenu.h"
 
2
 
 
3
#include <QPainter>
 
4
#include <QMouseEvent>
 
5
#include <QDebug>
 
6
 
 
7
SwitchMenu::SwitchMenu(QWidget *parent) :
 
8
    QWidget(parent)
 
9
{
 
10
//    setWindowFlags(Qt::FramelessWindowHint);
 
11
 
 
12
    m_bOn = false;
 
13
 
 
14
    m_bLBtnDown = false;
 
15
 
 
16
    m_pixmapBk.load(":/background/res/on.png");
 
17
    m_pixmapFore.load(":/background/res/off.png");
 
18
 
 
19
    setGeometry(0, 0, m_pixmapBk.width(), m_pixmapBk.height());
 
20
}
 
21
 
 
22
void SwitchMenu::paintEvent(QPaintEvent *)
 
23
{
 
24
    qDebug() << "1111111111";
 
25
    QPainter painter(this);
 
26
 
 
27
    painter.drawPixmap(QPoint(0,0), m_pixmapBk);
 
28
 
 
29
    QPoint ptFore;
 
30
    if (m_bOn) {
 
31
        ptFore = rect().topLeft();
 
32
    } else {
 
33
        ptFore = QPoint(this->width() - m_pixmapFore.width(),
 
34
                        this->rect().top());
 
35
    }
 
36
    painter.drawPixmap(ptFore, m_pixmapFore);
 
37
 
 
38
    QRect rcOn;
 
39
    rcOn.setTopLeft(rect().topLeft());
 
40
    rcOn.setBottomRight(QPoint(m_pixmapFore.width(), m_pixmapFore.height()));
 
41
    painter.drawText(rcOn, Qt::AlignCenter, "ON");
 
42
 
 
43
    QRect rcOff;
 
44
    rcOff.setTopLeft(QPoint(rect().width() - m_pixmapFore.width(), rect().top()));
 
45
    rcOff.setBottomRight(rect().bottomRight());
 
46
    painter.drawText(rcOff, Qt::AlignCenter, "Off");
 
47
}
 
48
 
 
49
void SwitchMenu::mousePressEvent(QMouseEvent *)
 
50
{
 
51
    qDebug() << "333333333";
 
52
    m_bLBtnDown = true;
 
53
}
 
54
 
 
55
void SwitchMenu::mouseReleaseEvent(QMouseEvent *e)
 
56
{
 
57
    qDebug() << "222222222";
 
58
    if (m_bLBtnDown) {
 
59
        m_bOn = !m_bOn;
 
60
 
 
61
        m_bLBtnDown = false;
 
62
    }
 
63
 
 
64
    update();
 
65
}
 
66
 
 
67
void SwitchMenu::leaveEvent(QEvent *)
 
68
{
 
69
//    status = NORMAL;
 
70
    update();
 
71
}
 
72
 
 
73
void SwitchMenu::enterEvent(QEvent *)
 
74
{
 
75
//    status = ENTER;
 
76
    update();
 
77
}
 
78
 
 
79
 
 
80
 
 
81
 
 
82
 
 
83
 
 
84
 
 
85
 
 
86
//void SystemButton::paintEvent(QPaintEvent *)
 
87
//{
 
88
//    QPainter painter;
 
89
//    painter.begin(this);
 
90
//    painter.drawPixmap(this->rect(), pixmap.copy(btn_width * status, 0, btn_width, btn_height));
 
91
//    painter.end();
 
92
//}