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

Subversion Repositories ezidebug

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 EziDebug
#include "miniwindow.h"
2
//#include "button.h"//移至"miniwindow.h"中
3
 
4
#include <QtGui>
5
 
6
MiniWindow::MiniWindow(QWidget *parent) :
7
    QWidget(parent)
8
{
9
    QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030"));
10
    setMouseTracking (true);
11
    setWindowTitle(tr("EziDebug"));
12
 
13
    statusLabel = new QLabel(tr("         Status"));
14
 
15
 
16
    createActions();   //创建右键菜单的选项0
17
    createButtons();   //创建按钮
18
 
19
    //设置系统图标,状态栏图标
20
 
21
    QPixmap objPixmap(tr(":/images/EziDebugIcon.bmp"));
22
    QPixmap iconPix;
23
    objPixmap.setMask(QPixmap(tr(":/images/EziDebugIconMask.bmp")));
24
    iconPix = objPixmap.copy(0, 0, 127, 104).scaled(32, 31);
25
    setWindowIcon(iconPix);
26
 
27
 
28
    //设置背景
29
    //QPixmap maskPix;
30
    QPalette palette;
31
    backgroundPix.load(":/images/miniBackground.bmp",0,Qt::AvoidDither|Qt::ThresholdDither|Qt::ThresholdAlphaDither);
32
    //maskPix.load(":/images/miniMask.bmp");
33
    palette.setBrush(QPalette::Background, QBrush(backgroundPix));
34
    //setMask(maskPix);
35
    setPalette(palette);
36
    //setMask(backgroundPix.mask());   //通过QPixmap的方法获得图片的过滤掉透明的部分得到的图片,作为Widget的不规则边框
37
    //setWindowOpacity(1.0);  //设置图片透明度
38
 
39
    //设置对话框的位置和大小
40
    setGeometry(QRect(250,100,298,34));
41
    //setMinimumSize(480,42);
42
    setFixedSize(backgroundPix.size());//设置窗口的尺寸为图片的尺寸
43
    setContentsMargins(0,0,0,0);
44
    Qt::WindowFlags flags = Qt::Widget;
45
    flags |= Qt::WindowStaysOnTopHint;//最前端显示
46
    flags |= Qt::FramelessWindowHint;//设置为无边框
47
    setWindowFlags(flags);
48
 
49
    //设置掩板
50
    QPixmap maskPix;
51
    maskPix.load(":/images/miniMask.bmp");
52
    setMask(maskPix);
53
//    //生成一张位图
54
//    QBitmap objBitmap(size());
55
//    //QPainter用于在位图上绘画
56
//    QPainter painter(&objBitmap);
57
//    //填充位图矩形框(用白色填充)
58
//    painter.fillRect(rect(),Qt::white);
59
//    painter.setBrush(QColor(0,0,0));
60
//    //在位图上画圆角矩形(用黑色填充)
61
//    painter.drawRoundedRect(this->rect(),8,8);
62
//    //使用setmask过滤即可
63
//    setMask(objBitmap);
64
 
65
 
66
    //设置迷你模式下的按键
67
    //大版的位置
68
//    proSettingButton->setGeometry(QRect(60, 1, 42, 41));//工程设置
69
//    proUpdateButton->setGeometry(QRect(102, 1, 42, 41));//更新
70
//    proPartlyUpdateButton->setGeometry(QRect(144, 1, 42, 41));//部分更新
71
//    deleteChainButton->setGeometry(QRect(186, 1, 42, 41));//删除
72
//    testbenchGenerationButton->setGeometry(QRect(228, 1, 42, 41));//testbench生成
73
//    proUndoButton->setGeometry(QRect(270, 1, 42, 41));//撤销(undo)
74
 
75
//    minimizeButton->setGeometry(QRect(390, 0, 27, 19));
76
//    normalModeButton->setGeometry(QRect(416, 0, 27, 19));
77
//    exitButton->setGeometry(QRect(442, 0, 33, 19));
78
 
79
    //设置迷你模式下的按键
80
     //中版的位置
81
     proSettingButton->setGeometry(QRect(40, 4, 26, 25));
82
     proUpdateButton->setGeometry(QRect(65, 4, 26, 25));
83
     proPartlyUpdateButton->setGeometry(QRect(90, 4, 26, 25));
84
     deleteChainButton->setGeometry(QRect(115, 4, 26, 25));
85
     testbenchGenerationButton->setGeometry(QRect(140, 4, 26, 25));
86
     proUndoButton->setGeometry(QRect(165, 4, 26, 25));
87
 
88
     minimizeButton->setGeometry(QRect(240, 0, 16, 11));
89
     normalModeButton->setGeometry(QRect(257, 0, 16, 11));
90
     exitButton->setGeometry(QRect(274, 0, 20, 11));
91
 
92
     //    //小版的位置
93
//    proSettingButton->setGeometry(QRect(30, 2, 21, 20));//工程设置
94
//    proUpdateButton->setGeometry(QRect(50, 2, 21, 20));//更新
95
//    proPartlyUpdateButton->setGeometry(QRect(70, 2, 21, 20));//部分更新
96
//    deleteChainButton->setGeometry(QRect(90, 2, 21, 20));//删除
97
//    testbenchGenerationButton->setGeometry(QRect(110, 2, 21, 20));//testbench生成
98
//    proUndoButton->setGeometry(QRect(130, 2, 21, 20));//撤销(undo)
99
 
100
//    minimizeButton->setGeometry(QRect(255, 0, 14, 10));
101
//    normalModeButton->setGeometry(QRect(268, 0, 14, 10));
102
//    exitButton->setGeometry(QRect(281, 0, 17, 10));
103
 
104
//    //miniIconLabel->setGeometry(QRect(100, 1, 105, 20));
105
//    minimizeButton->setGeometry(QRect(317, 4, 11, 10));
106
//    //showStatusButton->hide();
107
//    //minimizeButton->setGeometry(QRect(305, 4, 11, 10));
108
//    //showStatusButton->setGeometry(QRect(317, 4, 11, 10));
109
//    normalModeButton->setGeometry(QRect(329, 4, 11, 10));
110
//    exitButton->setGeometry(QRect(341, 4, 11, 10));
111
 
112
 
113
    //状态显示
114
//    statusRoll = new RollCaption(this);
115
//    statusRoll->setGeometry(QRect(118, 2, 162, 21));
116
//    statusRoll->setText(tr("status of EziDebug, this is a demo, just for test. "));
117
////    statusRoll->setSpeed(50);
118
////    statusRoll->setcolor(QColor(0, 0, 0));
119
 
120
////    QLabel *statusLabel1 = new QLabel(tr("Status"));
121
////    //statusLabel1->setTextFormat();
122
////    statusLabel1->setGeometry(QRect(118, 2, 170, 21));
123
 
124
//    //迷你模式下的状态栏
125
    statusWidget = new QWidget;
126
//    QHBoxLayout *StatusLayout = new QHBoxLayout;
127
//    StatusLayout->addWidget(statusLabel);
128
//    StatusLayout->setMargin(0);
129
//    statusWidget->setLayout(StatusLayout);
130
//    flags =  Qt::Widget;
131
//    flags |= Qt::WindowStaysOnTopHint;//最前端显示
132
//    flags |= Qt::FramelessWindowHint;//设置为无边框
133
//    statusWidget->setWindowFlags(flags);
134
 
135
//    palette.setColor(QPalette::Background, QColor(27,61,125));
136
//    statusWidget->setPalette(palette);
137
//    //statusWidget->setFont();
138
 
139
//    statusWidget->resize(size());
140
//    QPoint p = frameGeometry().topLeft();
141
//    p.setX(p.rx() + width());
142
//    statusWidget->move(p);
143
 
144
    statusWidget->setHidden(true);
145
    isMiniStatusLabelHidden = true;
146
 
147
}
148
 
149
void MiniWindow::createButtons()
150
{
151
    //工具栏按钮
152
    proSettingButton = createToolButton(tr("工程设置"),
153
                                        tr(":/images/projectSetting.bmp"),
154
                                        QSize(26, 25));//(42, 41)
155
 
156
    proUpdateButton = createToolButton(tr("更新"),
157
                                       tr(":/images/projectUpdate.bmp"),
158
                                       QSize(26, 25));
159
 
160
    proPartlyUpdateButton = createToolButton(tr("部分更新"),
161
                                       tr(":/images/projectPartlyUpdate.bmp"),
162
                                       QSize(26, 25));
163
 
164
    deleteChainButton = createToolButton(tr("删除"),
165
                                         tr(":/images/deleteChain.bmp"),
166
                                         QSize(26, 25));
167
 
168
    testbenchGenerationButton = createToolButton(tr("testbench生成"),
169
                                                 tr(":/images/testbenchGeneration.bmp"),
170
                                                 QSize(26, 25));
171
 
172
    proUndoButton = createToolButton(tr("撤消"),
173
                                                     tr(":/images/undo.bmp"),
174
                                                     QSize(26, 25));
175
 
176
 
177
 
178
    //右上角标题栏按钮
179
    minimizeButton = createToolButton(tr("最小化"),
180
                                          tr(":/images/ToolWindowminimize.bmp"),
181
                                          QSize(20, 14));//QSize(27, 19)
182
 
183
    normalModeButton = createToolButton(tr("普通模式"),
184
                                        tr(":/images/ToolWindowNormal.bmp"),
185
                                        QSize(20, 14));
186
 
187
    exitButton = createToolButton(tr("退出"),
188
                                      tr(":/images/ToolWindowExit.bmp"),
189
                                      QSize(24, 14));//QSize(33, 19)
190
 
191
 
192
 
193
//原代码,留connect对象供参考
194
//    minimizeButton = createToolButton(tr("最小化"),
195
//                                          QIcon(":/images/miniMinimize.bmp"),
196
//                                          QSize(11, 10),
197
//                                           SLOT(minimize()));
198
 
199
//    showStatusButton = createToolButton(tr("运行状态"),
200
//                                            QIcon(":/images/miniShowStatus.bmp"),
201
//                                            QSize(11, 10),
202
//                                            SLOT(showStatusWedgit()));
203
 
204
//    normalModeButton = createToolButton(tr("普通模式"),
205
//                                        QIcon(":/images/miniNormal.bmp"),
206
//                                        QSize(11, 10),
207
//                                        SIGNAL(toNormalMode()));
208
 
209
//    exitButton = createToolButton(tr("退出"),
210
//                                      QIcon(":/images/miniExit.bmp"),
211
//                                      QSize(11, 10),
212
//                                      SLOT(close()));
213
    //connect(minimizeButton, SIGNAL(clicked()), this, SLOT(minimize()));//在toolwindow中connect
214
    connect(normalModeButton, SIGNAL(clicked()), this, SIGNAL(toNormalMode()));
215
    connect(exitButton, SIGNAL(clicked()), this, SLOT(close()));
216
 
217
}
218
 
219
void MiniWindow::createActions()
220
{
221
    exitAct = new QAction(tr("退出"), this);
222
    exitAct->setShortcuts(QKeySequence::Quit);
223
    //exitAct->setStatusTip(tr("退出"));
224
    connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
225
 
226
    minimizeAct = new QAction(tr("最小化"), this);
227
    //minimizeAct->setShortcuts(QKeySequence::);
228
    //minimizeAct->setStatusTip(tr("Exit the application"));
229
    connect(minimizeAct, SIGNAL(triggered()), this, SLOT(minimize()));
230
 
231
    toNormalModeAct = new QAction(tr("普通模式"), this);
232
    //normalAct->setShortcuts(QKeySequence::Quit);
233
    //normalAct->setStatusTip(tr("Exit the application"));
234
    connect(toNormalModeAct, SIGNAL(triggered()), this, SIGNAL(toNormalMode()));
235
 
236
}
237
 
238
Button *MiniWindow::createToolButton(const QString &toolTip,
239
                                          const QString &iconstr,const QSize &size)
240
{
241
    Button *button = new Button(iconstr, this);
242
    button->setToolTip(toolTip);
243
    //button->setIcon(icon);
244
    button->setIconSize(size);//(QSize(10, 10));
245
    // button->setSizeIncrement(size);
246
    //button->setSizePolicy(size.width(), size.height());
247
    button->setFlat(true);
248
    //connect(button, SIGNAL(clicked()), this, member);
249
 
250
    return button;
251
}
252
 
253
void MiniWindow::contextMenuEvent(QContextMenuEvent *event)
254
{
255
    QMenu menu(this);
256
    menu.addAction(minimizeAct);
257
    menu.addAction(toNormalModeAct);
258
    menu.addAction(exitAct);
259
    menu.exec(event->globalPos());
260
}
261
 
262
void MiniWindow::mousePressEvent(QMouseEvent * event)
263
{
264
    if (event->button() == Qt::LeftButton) //点击左边鼠标
265
    {
266
        //globalPos()获取根窗口的相对路径,frameGeometry().topLeft()获取主窗口左上角的位置
267
            dragPosition = event->globalPos() - frameGeometry().topLeft();
268
 
269
        event->accept();   //鼠标事件被系统接收
270
    }
271
    //    if (event->button() == Qt::RightButton)
272
    //    {
273
    //         close();
274
    //    }
275
}
276
 
277
void MiniWindow::mouseMoveEvent(QMouseEvent * event)
278
{
279
    if (event->buttons() == Qt::LeftButton) //当满足鼠标左键被点击时。
280
    {
281
 
282
            QPoint p = event->globalPos() - dragPosition;
283
            move(p);//移动窗口
284
            p.setX(p.rx() + width());
285
            statusWidget->move(p);
286
 
287
        event->accept();
288
    }
289
}
290
 
291
 
292
//以下代码(直到"exitButton->move(size().width() - 17, 4);"一句)
293
//均为mini窗口可放大缩小的前提下设置的,现注释掉,以后调整需求后或许有用
294
////当鼠标移动到主界面内部周围5像素时,改变鼠标形状;当进行伸缩拖动时,根据拖动方向进行主界面的位置和大小设置即可。
295
////鼠标按下事件
296
//void MiniWindow::mousePressEvent(QMouseEvent *event)
297
//{
298
//    if (event->button() == Qt::LeftButton)
299
//    {
300
//        isLeftButtonPress = true;
301
 
302
//        //判读是窗口移动还是缩放
303
//        eDirection = (enum_Direction)PointValid(event->x());
304
//        if(eDirection == eNone)//是窗口移动
305
//        {
306
//            isWindowMovement = true;
307
//            //globalPos()获取根窗口的相对路径,frameGeometry().topLeft()获取主窗口左上角的位置
308
//            dragPosition = event->globalPos() - frameGeometry().topLeft();
309
//        }
310
//        else//是窗口缩放
311
//        {
312
//            isWindowMovement = false;
313
//            pointPressGlobal = event->globalPos();
314
//        }
315
 
316
//        event->accept();   //鼠标事件被系统接收
317
//    }
318
//}
319
////鼠标移动事件
320
//void MiniWindow::mouseMoveEvent(QMouseEvent *event)
321
//{
322
//    if(!isLeftButtonPress)
323
//    {
324
//        eDirection = (enum_Direction)PointValid(event->x());
325
//        SetCursorStyle(eDirection);
326
//    }
327
//    else
328
//    {
329
//        if(eDirection == eNone)//是窗口移动
330
//        {
331
//            QPoint p = event->globalPos() - dragPosition;
332
//            move(p);//移动窗口
333
//            //                        p.setX(p.rx() + width());
334
//            //                        statusWidget->move(p);
335
 
336
//        }
337
//        else//是窗口缩放
338
//        {
339
//            int nXGlobal = event->globalX();
340
//            int nYGlobal = event->globalY();
341
//            SetDrayMove(nXGlobal, eDirection);
342
//            pointPressGlobal =QPoint(nXGlobal,nYGlobal);
343
//        }
344
//    }
345
 
346
//    event->accept();
347
 
348
//}
349
 
350
////鼠标释放事件
351
//void MiniWindow::mouseReleaseEvent(QMouseEvent *event)
352
//{
353
//    if (event->button() == Qt::LeftButton)
354
//    {
355
//        isLeftButtonPress = false;
356
//        eDirection = eNone;
357
//    }
358
//}
359
 
360
////判断鼠标所在位置在当前窗口的什么位置,左右 边界上,或者都不是
361
//int MiniWindow::PointValid(int x)
362
//{
363
//    enum_Direction direction = eNone;
364
//    if ((x >= 0) && (x < 6))
365
//    {
366
 
367
//            direction = eLeft;
368
//    }
369
//    else if((x > this->width() - 6) && (x <= this->width()))
370
//    {
371
 
372
//            direction = eRight;
373
//    }
374
 
375
//   return (int)direction;
376
//}
377
 
378
////设置鼠标样式
379
//void MiniWindow::SetCursorStyle(enum_Direction direction)
380
//{
381
//    //设置左右的鼠标形状
382
//    switch(direction)
383
//    {
384
//    case eRight:
385
//    case eLeft:
386
//        setCursor(Qt::SizeHorCursor);
387
//        break;
388
//    default:
389
//        setCursor(Qt::ArrowCursor);
390
//        break;
391
//    }
392
//}
393
 
394
////设置鼠标拖动的窗口位置信息
395
//void MiniWindow::SetDrayMove(int nXGlobal, enum_Direction direction)
396
//{
397
//    //获得主窗口位置信息
398
//    QRect rectWindow = geometry();
399
//    //判别方向
400
//    switch(direction)
401
//    {
402
 
403
//    case eRight:
404
//        rectWindow.setRight(nXGlobal);
405
//        break;
406
//    case eLeft:
407
//        rectWindow.setLeft(nXGlobal);
408
//        break;
409
//    default:
410
//        break;
411
//    }
412
 
413
//    if(rectWindow.width()< minimumWidth())
414
//    {
415
//        return;
416
//    }
417
//    //重新设置窗口位置为新位置信息
418
//    setGeometry(rectWindow);
419
//}
420
 
421
//// 随着窗体变化而设置背景
422
//void MiniWindow::resizeEvent(QResizeEvent *event)
423
//{
424
//    QWidget::resizeEvent(event);
425
 
426
//    //背景图片缩放
427
//    //创建一个size为变化后size的新画布
428
//    QImage img(event->size(), QImage::Format_ARGB32);
429
//    QPainter *paint = new QPainter(&img);
430
//    //在新区域画图,左-fixed,中-scaled,右-fixed
431
//    paint->drawPixmap(0, 0, backgroundPix.copy(0, 0, 120, 25));
432
//    paint->drawPixmap(120, 0, backgroundPix.copy(120, 0, 156, 25).scaled(QSize(event->size().width() - 202, 25),
433
//                                                                         Qt::IgnoreAspectRatio,
434
//                                                                         Qt::SmoothTransformation));
435
//    paint->drawPixmap(event->size().width() - 82, 0, backgroundPix.copy(276, 0, 82, 25));
436
//    paint->end();
437
//    //setPixmap(QPixmap::fromImage(displayImg));
438
//    QPalette pal(palette());
439
//    pal.setBrush(QPalette::Window,QBrush(img));
440
//    //    pal.setBrush(QPalette::Window,
441
//    //                 QBrush(backgroundPix.scaled(event->size(),
442
//    //                                              Qt::IgnoreAspectRatio,
443
//    //                                              Qt::SmoothTransformation)));
444
//    setPalette(pal);
445
 
446
 
447
 
448
//    //设置掩板
449
//    //生成一张位图
450
//    QBitmap objBitmap(size());
451
//    //QPainter用于在位图上绘画
452
//    QPainter painter(&objBitmap);
453
//    //填充位图矩形框(用白色填充)
454
//    painter.fillRect(rect(),Qt::white);
455
//    painter.setBrush(QColor(0,0,0));
456
//    //在位图上画圆角矩形(用黑色填充)
457
//    painter.drawRoundedRect(this->rect(),8,8);
458
//    //使用setmask过滤即可
459
//    setMask(objBitmap);
460
 
461
//    //移动右侧按钮的位置
462
//    minimizeButton->move(size().width() - 41, 4);
463
//    normalModeButton->move(size().width() - 29, 4);
464
//    exitButton->move(size().width() - 17, 4);
465
 
466
 
467
//}
468
 
469
 
470
 
471
 
472
 
473
 
474
//void MiniWindow::paintEvent(QPaintEvent *)
475
//{
476
//    QPainter painter(this);//创建一个QPainter对象
477
//    painter.drawPixmap(0,0,QPixmap(":/images/Watermelon.png"));//绘制图片到窗口
478
//    /*
479
//      QPixmap(":/images/Watermelon.png")如果改为QPixmap(),则只能看到绘制出的框架,看不到图片颜色,也就是看不到图片。
480
//    */
481
//}
482
 
483
void MiniWindow::minimize()
484
{
485
    this->hide();
486
    if(isMiniStatusLabelHidden == false)
487
        statusWidget->hide();
488
}
489
 
490
void MiniWindow::showStatusWedgit()
491
{
492
 
493
    if(isMiniStatusLabelHidden == true){
494
        isMiniStatusLabelHidden = false;
495
        statusWidget->setHidden(false);
496
 
497
    }
498
    else{
499
        isMiniStatusLabelHidden = true;
500
        statusWidget->setHidden(true);
501
    }
502
 
503
}
504
 
505
//void MiniWindow::toNormalMode()
506
//{
507
////    mainWindow->show();
508
////    if(isNormalListWindowHidden == false)
509
////        listWindow->show();
510
//    statusWidget->hide();
511
//    this->hide();
512
//}
513
 
514
void MiniWindow::close()
515
{
516
//    listWindow->close();
517
//    mainWindow->close();
518
    statusWidget->close();
519
    QWidget::close();
520
}
521
 
522
bool MiniWindow::statusWidgetHidden()
523
{
524
    return isMiniStatusLabelHidden;
525
}
526
 
527
void MiniWindow::setStatusWidgetHidden(bool flag)
528
{
529
    if(flag == true)
530
        statusWidget->hide();
531
    else
532
        statusWidget->show();
533
}
534
 
535
 

powered by: WebSVN 2.1.0

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