OpenCores
URL https://opencores.org/ocsvn/ezidebug/ezidebug/trunk

Subversion Repositories ezidebug

[/] [ezidebug/] [trunk/] [EziDebug_src/] [titlebar.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 EziDebug
#include "titlebar.h"
2
#include "listwindow.h"
3
 
4
#include <QtGui>
5
TitleBar::TitleBar(QWidget *parent) :
6
    QWidget(parent)
7
{
8
    //test
9
//    setAutoFillBackground(true);
10
//    QPixmap backgroundPix;
11
//    QPalette palette;
12
//    backgroundPix.load(":/images/mainBackground.bmp",0,Qt::AvoidDither|Qt::ThresholdDither|Qt::ThresholdAlphaDither);
13
//    palette.setBrush(QPalette::Background, QBrush(backgroundPix.copy(0,0,290,17)));
14
//    this->setPalette(palette);
15
 
16
 
17
    QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030"));
18
    setMouseTracking (true);
19
    //setCursor(Qt::ArrowCursor);
20
    isLeftButtonPress = false;
21
 
22
    CreateWidget();//创建子部件
23
    //SetWidgetStyle();//设置子部件样式(qss)
24
    //CreateLayout();//创建设置布局
25
}
26
 
27
 
28
 
29
 
30
 
31
 
32
//创建子部件
33
void TitleBar::CreateWidget()
34
{
35
//    background.load(":/images/listBackground.bmp",
36
//                        0,Qt::AvoidDither|Qt::ThresholdDither|Qt::ThresholdAlphaDither);
37
//    //background = background.copy(0, 0, background.width(), 17);
38
//    background = background.copy(0, 4, background.width(), 13);
39
 
40
 
41
 
42
 
43
//    QPixmap objPixmap(background);
44
 
45
//    iconLabel = new QLabel(this);//最左侧的小图标
46
//    iconLabel->setPixmap(objPixmap.copy(5, 0, 20, 13));
47
 
48
//    lineLabel = new QLabel(this);//中间的长直线
49
//    lineLabel->setPixmap(objPixmap.copy(25, 0, 235, 13));
50
 
51
//    closeButtonLabel = new QLabel(this);//最右侧关闭按键的图标
52
//    closeButtonLabel->setPixmap(objPixmap.copy(260, 0, background.width() - 259-5, 13));
53
//    closeButtonLabel->setCursor(Qt::PointingHandCursor);
54
 
55
 
56
    //setGeometry(QRect(0, 0, 290, 17));
57
    setMinimumSize(423, 26);
58
    setFixedHeight(26);
59
    closeButton = new Button(tr(":/images/ListWindowExit.bmp"), this);
60
    closeButton->setIconSize(QSize(33, 19));
61
    closeButton->setGeometry(QRect(385, 0, 33, 19));
62
    setContentsMargins(0,0,0,0);
63
 
64
 
65
//    //图像标签--logo
66
//    m_pLabelIcon = new QLabel(this);
67
//    QPixmap objPixmap(":/image/360AboutLogo.png");
68
//    m_pLabelIcon->setPixmap(objPixmap.scaled(TITLE_H,TITLE_H));
69
//    //文本标签--标题
70
//    m_pLabelTitle = new QLabel(this);
71
//    m_pLabelTitle->setText(QString("360 Safe Guard V8.5"));
72
//    //文本标签--样式版本
73
//    m_pLabelVersion = new QLabel(this);
74
//    m_pLabelVersion->setText(QString("Use Class Style"));
75
//    //设置鼠标形状
76
//    m_pLabelVersion->setCursor(Qt::PointingHandCursor);
77
//    //按钮--更换皮肤
78
//    m_pBtnSkin = new QToolButton(this);
79
//    //设置初始图片
80
//    SetBtnIcon(m_pBtnSkin,eBtnStateDefault,true);
81
//    //按钮--菜单
82
//    m_pBtnMenu = new QToolButton(this);
83
//    SetBtnIcon(m_pBtnMenu,eBtnStateDefault,true);
84
//    //按钮--最小化
85
//    m_pBtnMin = new QToolButton(this);
86
//    SetBtnIcon(m_pBtnMin,eBtnStateDefault,true);
87
//    //按钮--最大化/还原
88
//    m_pBtnMax = new QToolButton(this);
89
//    SetBtnIcon(m_pBtnMax,eBtnStateDefault,true);
90
//    //按钮--关闭
91
//    m_pBtnClose = new QToolButton(this);
92
//    SetBtnIcon(m_pBtnClose,eBtnStateDefault,true);
93
    //获得子部件
94
    const QObjectList &objList = children();
95
    for(int nIndex=0; nIndex < objList.count(); ++nIndex)
96
    {
97
        //设置子部件的MouseTracking属性
98
        ((QWidget*)(objList.at(nIndex)))->setMouseTracking(true);
99
//        //如果是QToolButton部件
100
//        if(0==qstrcmp(objList.at(nIndex)->metaObject()->className(),"QToolButton"))
101
//        {
102
//            //连接pressed信号为slot_btnpress
103
//            connect(((QToolButton*)(objList.at(nIndex))),SIGNAL(pressed()),this,SLOT(slot_btnpress()));
104
//            //连接clicked信号为slot_btnclick
105
//            connect(((QToolButton*)(objList.at(nIndex))),SIGNAL(clicked()),this,SLOT(slot_btnclick()));
106
//            //设置顶部间距
107
//            ((QToolButton*)(objList.at(nIndex)))->setContentsMargins(0,VALUE_DIS,0,0);
108
//        }
109
    }
110
}
111
 
112
//设置子部件样式(qss)
113
void TitleBar::SetWidgetStyle()
114
{
115
    //设置标签的文本颜色,大小等以及按钮的边框
116
    setStyleSheet("QLabel{color:#CCCCCC;font-size:12px;font-weight:bold;}Button{border:0px;}");
117
    //设置左边距
118
   // m_pLabelTitle->setStyleSheet("margin-left:6px;");
119
    //设置右边距以及鼠标移上去时的文本颜色
120
    //m_pLabelVersion->setStyleSheet("QLabel{margin-right:10px;}QLabel:hover{color:#00AA00;}");
121
}
122
 
123
//创建设置布局
124
void TitleBar::CreateLayout()
125
{
126
    //水平布局
127
//    layout = new QHBoxLayout(this);
128
//    //添加部件
129
////    layout->addWidget(iconLabel);
130
////    layout->addWidget(lineLabel);
131
//    //添加伸缩项
132
//    layout->addStretch(1);
133
//    //添加部件
134
//    layout->addWidget(closeButton);
135
////    layout->addWidget(m_pBtnSkin);
136
////    layout->addWidget(m_pBtnMenu);
137
////    layout->addWidget(m_pBtnMin);
138
////    layout->addWidget(m_pBtnMax);
139
////    layout->addWidget(m_pBtnClose);
140
//    //设置Margin
141
//    layout->setContentsMargins(0,0,0,0);
142
////    layout->setContentsMargins(0,0,VALUE_DIS,0);
143
 
144
//    //设置部件之间的space
145
//    layout->setSpacing(0);
146
//    setLayout(layout);
147
}
148
 
149
 
150
 
151
//设置按钮不同状态下的图标
152
//void TitleBar::SetBtnIcon(QToolButton *pBtn,eBtnMoustState state,bool bInit/*=false*/)
153
//{
154
//    //获得图片路径
155
//    QString strImagePath = GetBtnImagePath(pBtn,bInit);
156
//    //创建QPixmap对象
157
//    QPixmap objPixmap(strImagePath);
158
//    //得到图像宽和高
159
//    int nPixWidth = objPixmap.width();
160
//    int nPixHeight = objPixmap.height();
161
//    //如果状态不是无效值
162
//    if(state!=eBtnStateNone)
163
//    {
164
//        /*设置按钮图片
165
//按钮的图片是连续在一起的,如前1/4部分表示默认状态下的图片部分,接后的1/4部分表示鼠标移到按钮状态下的图片部分
166
//*/
167
//        pBtn->setIcon(objPixmap.copy((nPixWidth/4)*(state-1),0,nPixWidth/4,nPixHeight));
168
//        //设置按钮图片大小
169
//        pBtn->setIconSize(QSize(nPixWidth/4,nPixHeight));
170
//    }
171
//}
172
 
173
////获得图片路径(固定值)
174
//const QString TitleBar::GetBtnImagePath(QToolButton *pBtn,bool bInit/*=false*/)
175
//{
176
//    QString strImagePath;
177
//    //皮肤按钮
178
//    if(m_pBtnSkin==pBtn)
179
//    {
180
//        strImagePath = ":/image/SkinButtom.png";
181
//    }
182
//    //菜单按钮
183
//    if(m_pBtnMenu==pBtn)
184
//    {
185
//        strImagePath = ":/image/title_bar_menu.png";
186
//    }
187
//    //最小化
188
//    if(m_pBtnMin==pBtn)
189
//    {
190
//        strImagePath = ":/image/sys_button_min.png";
191
//    }
192
//    //最大化/还原按钮,所以包括最大化和还原两张图片
193
//    if(m_pBtnMax==pBtn)
194
//    {
195
//        //如果是初始设置或者主界面的最大化标志不为真(其中MainWindow::Instance()使用单例设计模式)
196
//        if(bInit==true || MainWindow::Instance()->GetMaxWin()==false)
197
//        {
198
//            //最大化按钮图片路径
199
//            strImagePath = ":/image/sys_button_max.png";
200
//        }
201
//        else
202
//        {
203
//            //还原按钮图片路径
204
//            strImagePath = ":/image/sys_button_restore.png";
205
//        }
206
//    }
207
//    //关闭按钮
208
//    if(m_pBtnClose==pBtn)
209
//    {
210
//        strImagePath = ":/image/sys_button_close.png";
211
//    }
212
//    return strImagePath;
213
//}
214
 
215
////创建事件过滤器
216
//void TitleBar::CreateEventFiter()
217
//{
218
//    m_pBtnSkin->installEventFilter(this);
219
//    m_pBtnMenu->installEventFilter(this);
220
//    m_pBtnMin->installEventFilter(this);
221
//    m_pBtnMax->installEventFilter(this);
222
//    m_pBtnClose->installEventFilter(this);
223
//}
224
////事件过滤
225
//bool TitleBar::eventFilter(QObject *obj, QEvent *event)
226
//{
227
//    //按钮状态
228
//    eBtnMoustState eState = eBtnStateNone;
229
//    //判断事件类型--QEvent::Enter
230
//    if (event->type() == QEvent::Enter)
231
//    {
232
//        eState = eBtnStateHover;
233
//    }
234
//    //判断事件类型--QEvent::Leave
235
//    if (event->type() == QEvent::Leave)
236
//    {
237
//        eState = eBtnStateDefault;
238
//    }
239
//    //判断事件类型--QEvent::MouseButtonPress
240
//    if (event->type() == QEvent::MouseButtonPress && ((QMouseEvent*)(event))->button()== Qt::LeftButton)
241
//    {
242
//        eState = eBtnStatePress;
243
//    }
244
//    //判断目标
245
//    if(m_pBtnSkin==obj || m_pBtnMenu==obj || m_pBtnMin==obj || m_pBtnMax==obj || m_pBtnClose==obj)
246
//    {
247
//        //如果状态有效
248
//        if(eState != eBtnStateNone)
249
//        {
250
//            //根据状态设置按钮图标
251
//            SetBtnIcon((QToolButton *)obj,eState);
252
//            return false;
253
//        }
254
//    }
255
//    return QWidget::eventFilter(obj,event);
256
//}
257
 
258
////槽函数--slot_btnclick
259
//void TitleBar::slot_btnclick()
260
//{
261
//    QToolButton *pBtn = (QToolButton*)(sender());
262
//    if(pBtn==m_pBtnMin)
263
//    {
264
//        emit signal_min();
265
//    }
266
//    if(pBtn==m_pBtnMax)
267
//    {
268
//        emit signal_maxrestore();
269
//    }
270
//    if(pBtn==m_pBtnClose)
271
//    {
272
//        emit signal_close();
273
//    }
274
//}
275
 
276
 
277
 
278
 
279
 
280
 
281
 
282
 
283
 
284
 
285
 
286
 
287
 
288
//鼠标按下事件
289
void TitleBar::mousePressEvent(QMouseEvent *event)
290
{
291
//    qDebug()<< "TitleBar mousePress Event" << "the relative coordination"<< event->x()<< event->y();
292
//    if (event->button() == Qt::LeftButton)
293
//    {
294
//        if(event->y()<VALUE_DIS||event->x()<VALUE_DIS||rect().width()-event->x()<5)
295
//        {
296
//            event->ignore();
297
//            return;
298
//        }
299
//        else
300
//        {
301
//            pointPress = event->globalPos();
302
//            isLeftButtonPress = true;
303
//            //test
304
//            event->accept();
305
//            return;
306
//        }
307
//    }
308
 
309
    event->ignore();
310
}
311
 
312
 
313
 
314
//鼠标移动事件
315
void TitleBar::mouseMoveEvent(QMouseEvent *event)
316
{
317
//    qDebug()<< "TitleBar mouseMove Event" << "the relative coordination"<< event->x()<< event->y();
318
//    if(isLeftButtonPress)//已经按下左键拖拽窗口
319
//    {
320
//        pointMove = event->globalPos();
321
//        //移动主窗口
322
//        ListWindow *pMainWindow = (qobject_cast<ListWindow *>(parent()));
323
//        pMainWindow->move(pMainWindow->pos() + pointMove - pointPress);
324
//        //重新设置pointPress;
325
//        pointPress = pointMove;
326
 
327
//        //test
328
//        event->accept();
329
////        event->ignore();
330
//        return;//
331
//    }
332
    event->ignore();
333
}
334
//鼠标释放事件
335
void TitleBar::mouseReleaseEvent(QMouseEvent *event)
336
{
337
//    qDebug() << "TitleBar::mouseReleaseEvent";
338
    if (event->button() == Qt::LeftButton)
339
    {
340
        isLeftButtonPress = false;
341
 
342
//        //获取父窗口指针
343
//        ListWindow *pMainWindow = (qobject_cast<ListWindow *>(parent()));
344
//                //如果ListWindow的上边沿和ToolWindow的下边沿靠近,则移至紧紧贴合的位置
345
//                int disY = pMainWindow->toolWindow->geometry().bottom() - pMainWindow->geometry().top();
346
//                if((disY < 15) && (disY > -15)){
347
//                    move(pMainWindow->geometry().left(), pMainWindow->geometry().top() + disY);//移动窗口
348
//                    pMainWindow->toolWindow->setListWindowAdsorbedFlag(true);
349
//                }
350
//                else{
351
//                    pMainWindow->toolWindow->setListWindowAdsorbedFlag(false);
352
//                }
353
 
354
    }
355
    event->ignore();
356
}
357
 
358
//缩放时调用该函数
359
void TitleBar::resizeEvent(QResizeEvent *event)
360
{
361
    QWidget::resizeEvent(event);
362
    closeButton->move(size().width() - 38, 0);
363
 
364
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.