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

Subversion Repositories ezidebug

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

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 4 EziDebug
    //工具栏按钮  tr("工程设置")
152
    proSettingButton = createToolButton(tr("Set Project Parameter"),
153 2 EziDebug
                                        tr(":/images/projectSetting.bmp"),
154
                                        QSize(26, 25));//(42, 41)
155
 
156 4 EziDebug
        // tr("更新")
157
    proUpdateButton = createToolButton(tr("Update"),
158 2 EziDebug
                                       tr(":/images/projectUpdate.bmp"),
159
                                       QSize(26, 25));
160 4 EziDebug
    // tr("部分更新")
161
    proPartlyUpdateButton = createToolButton(tr("Update fast"),
162 2 EziDebug
                                       tr(":/images/projectPartlyUpdate.bmp"),
163
                                       QSize(26, 25));
164
 
165 4 EziDebug
        // tr("删除")
166
    deleteChainButton = createToolButton(tr("Delete all scan chain"),
167 2 EziDebug
                                         tr(":/images/deleteChain.bmp"),
168
                                         QSize(26, 25));
169
 
170 4 EziDebug
        // tr("testbench生成")
171
    testbenchGenerationButton = createToolButton(tr("Gnerate testbench"),
172 2 EziDebug
                                                 tr(":/images/testbenchGeneration.bmp"),
173
                                                 QSize(26, 25));
174 4 EziDebug
    // tr("撤消")
175
    proUndoButton = createToolButton(tr("Undo"),
176 2 EziDebug
                                                     tr(":/images/undo.bmp"),
177
                                                     QSize(26, 25));
178
 
179
 
180
 
181
    //右上角标题栏按钮
182 4 EziDebug
    // tr("最小化")
183
    minimizeButton = createToolButton(tr("Minimize"),
184 2 EziDebug
                                          tr(":/images/ToolWindowminimize.bmp"),
185
                                          QSize(20, 14));//QSize(27, 19)
186
 
187 4 EziDebug
        // tr("普通模式")
188
    normalModeButton = createToolButton(tr("Normal mode"),
189 2 EziDebug
                                        tr(":/images/ToolWindowNormal.bmp"),
190
                                        QSize(20, 14));
191 4 EziDebug
    // tr("退出")
192
    exitButton = createToolButton(tr("Quit"),
193 2 EziDebug
                                      tr(":/images/ToolWindowExit.bmp"),
194
                                      QSize(24, 14));//QSize(33, 19)
195
 
196
 
197
 
198
//原代码,留connect对象供参考
199
//    minimizeButton = createToolButton(tr("最小化"),
200
//                                          QIcon(":/images/miniMinimize.bmp"),
201
//                                          QSize(11, 10),
202
//                                           SLOT(minimize()));
203
 
204
//    showStatusButton = createToolButton(tr("运行状态"),
205
//                                            QIcon(":/images/miniShowStatus.bmp"),
206
//                                            QSize(11, 10),
207
//                                            SLOT(showStatusWedgit()));
208
 
209
//    normalModeButton = createToolButton(tr("普通模式"),
210
//                                        QIcon(":/images/miniNormal.bmp"),
211
//                                        QSize(11, 10),
212
//                                        SIGNAL(toNormalMode()));
213
 
214
//    exitButton = createToolButton(tr("退出"),
215
//                                      QIcon(":/images/miniExit.bmp"),
216
//                                      QSize(11, 10),
217
//                                      SLOT(close()));
218
    //connect(minimizeButton, SIGNAL(clicked()), this, SLOT(minimize()));//在toolwindow中connect
219
    connect(normalModeButton, SIGNAL(clicked()), this, SIGNAL(toNormalMode()));
220
    connect(exitButton, SIGNAL(clicked()), this, SLOT(close()));
221
 
222
}
223
 
224
void MiniWindow::createActions()
225 4 EziDebug
{
226
    // tr("退出")
227
    exitAct = new QAction(tr("Quit"), this);
228 2 EziDebug
    exitAct->setShortcuts(QKeySequence::Quit);
229
    //exitAct->setStatusTip(tr("退出"));
230
    connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
231
 
232 4 EziDebug
        // tr("最小化")
233
    minimizeAct = new QAction(tr("Minimize"), this);
234 2 EziDebug
    //minimizeAct->setShortcuts(QKeySequence::);
235
    //minimizeAct->setStatusTip(tr("Exit the application"));
236
    connect(minimizeAct, SIGNAL(triggered()), this, SLOT(minimize()));
237
 
238 4 EziDebug
        // tr("普通模式")
239
    toNormalModeAct = new QAction(tr("Normal mode"), this);
240 2 EziDebug
    //normalAct->setShortcuts(QKeySequence::Quit);
241
    //normalAct->setStatusTip(tr("Exit the application"));
242
    connect(toNormalModeAct, SIGNAL(triggered()), this, SIGNAL(toNormalMode()));
243
 
244
}
245
 
246
Button *MiniWindow::createToolButton(const QString &toolTip,
247
                                          const QString &iconstr,const QSize &size)
248
{
249
    Button *button = new Button(iconstr, this);
250
    button->setToolTip(toolTip);
251
    //button->setIcon(icon);
252
    button->setIconSize(size);//(QSize(10, 10));
253
    // button->setSizeIncrement(size);
254
    //button->setSizePolicy(size.width(), size.height());
255
    button->setFlat(true);
256
    //connect(button, SIGNAL(clicked()), this, member);
257
 
258
    return button;
259
}
260
 
261
void MiniWindow::contextMenuEvent(QContextMenuEvent *event)
262
{
263
    QMenu menu(this);
264
    menu.addAction(minimizeAct);
265
    menu.addAction(toNormalModeAct);
266
    menu.addAction(exitAct);
267
    menu.exec(event->globalPos());
268
}
269
 
270
void MiniWindow::mousePressEvent(QMouseEvent * event)
271
{
272
    if (event->button() == Qt::LeftButton) //点击左边鼠标
273
    {
274
        //globalPos()获取根窗口的相对路径,frameGeometry().topLeft()获取主窗口左上角的位置
275
            dragPosition = event->globalPos() - frameGeometry().topLeft();
276
 
277
        event->accept();   //鼠标事件被系统接收
278
    }
279
    //    if (event->button() == Qt::RightButton)
280
    //    {
281
    //         close();
282
    //    }
283
}
284
 
285
void MiniWindow::mouseMoveEvent(QMouseEvent * event)
286
{
287
    if (event->buttons() == Qt::LeftButton) //当满足鼠标左键被点击时。
288
    {
289
 
290
            QPoint p = event->globalPos() - dragPosition;
291
            move(p);//移动窗口
292
            p.setX(p.rx() + width());
293
            statusWidget->move(p);
294
 
295
        event->accept();
296
    }
297
}
298
 
299
 
300
//以下代码(直到"exitButton->move(size().width() - 17, 4);"一句)
301
//均为mini窗口可放大缩小的前提下设置的,现注释掉,以后调整需求后或许有用
302
////当鼠标移动到主界面内部周围5像素时,改变鼠标形状;当进行伸缩拖动时,根据拖动方向进行主界面的位置和大小设置即可。
303
////鼠标按下事件
304
//void MiniWindow::mousePressEvent(QMouseEvent *event)
305
//{
306
//    if (event->button() == Qt::LeftButton)
307
//    {
308
//        isLeftButtonPress = true;
309
 
310
//        //判读是窗口移动还是缩放
311
//        eDirection = (enum_Direction)PointValid(event->x());
312
//        if(eDirection == eNone)//是窗口移动
313
//        {
314
//            isWindowMovement = true;
315
//            //globalPos()获取根窗口的相对路径,frameGeometry().topLeft()获取主窗口左上角的位置
316
//            dragPosition = event->globalPos() - frameGeometry().topLeft();
317
//        }
318
//        else//是窗口缩放
319
//        {
320
//            isWindowMovement = false;
321
//            pointPressGlobal = event->globalPos();
322
//        }
323
 
324
//        event->accept();   //鼠标事件被系统接收
325
//    }
326
//}
327
////鼠标移动事件
328
//void MiniWindow::mouseMoveEvent(QMouseEvent *event)
329
//{
330
//    if(!isLeftButtonPress)
331
//    {
332
//        eDirection = (enum_Direction)PointValid(event->x());
333
//        SetCursorStyle(eDirection);
334
//    }
335
//    else
336
//    {
337
//        if(eDirection == eNone)//是窗口移动
338
//        {
339
//            QPoint p = event->globalPos() - dragPosition;
340
//            move(p);//移动窗口
341
//            //                        p.setX(p.rx() + width());
342
//            //                        statusWidget->move(p);
343
 
344
//        }
345
//        else//是窗口缩放
346
//        {
347
//            int nXGlobal = event->globalX();
348
//            int nYGlobal = event->globalY();
349
//            SetDrayMove(nXGlobal, eDirection);
350
//            pointPressGlobal =QPoint(nXGlobal,nYGlobal);
351
//        }
352
//    }
353
 
354
//    event->accept();
355
 
356
//}
357
 
358
////鼠标释放事件
359
//void MiniWindow::mouseReleaseEvent(QMouseEvent *event)
360
//{
361
//    if (event->button() == Qt::LeftButton)
362
//    {
363
//        isLeftButtonPress = false;
364
//        eDirection = eNone;
365
//    }
366
//}
367
 
368
////判断鼠标所在位置在当前窗口的什么位置,左右 边界上,或者都不是
369
//int MiniWindow::PointValid(int x)
370
//{
371
//    enum_Direction direction = eNone;
372
//    if ((x >= 0) && (x < 6))
373
//    {
374
 
375
//            direction = eLeft;
376
//    }
377
//    else if((x > this->width() - 6) && (x <= this->width()))
378
//    {
379
 
380
//            direction = eRight;
381
//    }
382
 
383
//   return (int)direction;
384
//}
385
 
386
////设置鼠标样式
387
//void MiniWindow::SetCursorStyle(enum_Direction direction)
388
//{
389
//    //设置左右的鼠标形状
390
//    switch(direction)
391
//    {
392
//    case eRight:
393
//    case eLeft:
394
//        setCursor(Qt::SizeHorCursor);
395
//        break;
396
//    default:
397
//        setCursor(Qt::ArrowCursor);
398
//        break;
399
//    }
400
//}
401
 
402
////设置鼠标拖动的窗口位置信息
403
//void MiniWindow::SetDrayMove(int nXGlobal, enum_Direction direction)
404
//{
405
//    //获得主窗口位置信息
406
//    QRect rectWindow = geometry();
407
//    //判别方向
408
//    switch(direction)
409
//    {
410
 
411
//    case eRight:
412
//        rectWindow.setRight(nXGlobal);
413
//        break;
414
//    case eLeft:
415
//        rectWindow.setLeft(nXGlobal);
416
//        break;
417
//    default:
418
//        break;
419
//    }
420
 
421
//    if(rectWindow.width()< minimumWidth())
422
//    {
423
//        return;
424
//    }
425
//    //重新设置窗口位置为新位置信息
426
//    setGeometry(rectWindow);
427
//}
428
 
429
//// 随着窗体变化而设置背景
430
//void MiniWindow::resizeEvent(QResizeEvent *event)
431
//{
432
//    QWidget::resizeEvent(event);
433
 
434
//    //背景图片缩放
435
//    //创建一个size为变化后size的新画布
436
//    QImage img(event->size(), QImage::Format_ARGB32);
437
//    QPainter *paint = new QPainter(&img);
438
//    //在新区域画图,左-fixed,中-scaled,右-fixed
439
//    paint->drawPixmap(0, 0, backgroundPix.copy(0, 0, 120, 25));
440
//    paint->drawPixmap(120, 0, backgroundPix.copy(120, 0, 156, 25).scaled(QSize(event->size().width() - 202, 25),
441
//                                                                         Qt::IgnoreAspectRatio,
442
//                                                                         Qt::SmoothTransformation));
443
//    paint->drawPixmap(event->size().width() - 82, 0, backgroundPix.copy(276, 0, 82, 25));
444
//    paint->end();
445
//    //setPixmap(QPixmap::fromImage(displayImg));
446
//    QPalette pal(palette());
447
//    pal.setBrush(QPalette::Window,QBrush(img));
448
//    //    pal.setBrush(QPalette::Window,
449
//    //                 QBrush(backgroundPix.scaled(event->size(),
450
//    //                                              Qt::IgnoreAspectRatio,
451
//    //                                              Qt::SmoothTransformation)));
452
//    setPalette(pal);
453
 
454
 
455
 
456
//    //设置掩板
457
//    //生成一张位图
458
//    QBitmap objBitmap(size());
459
//    //QPainter用于在位图上绘画
460
//    QPainter painter(&objBitmap);
461
//    //填充位图矩形框(用白色填充)
462
//    painter.fillRect(rect(),Qt::white);
463
//    painter.setBrush(QColor(0,0,0));
464
//    //在位图上画圆角矩形(用黑色填充)
465
//    painter.drawRoundedRect(this->rect(),8,8);
466
//    //使用setmask过滤即可
467
//    setMask(objBitmap);
468
 
469
//    //移动右侧按钮的位置
470
//    minimizeButton->move(size().width() - 41, 4);
471
//    normalModeButton->move(size().width() - 29, 4);
472
//    exitButton->move(size().width() - 17, 4);
473
 
474
 
475
//}
476
 
477
 
478
 
479
 
480
 
481
 
482
//void MiniWindow::paintEvent(QPaintEvent *)
483
//{
484
//    QPainter painter(this);//创建一个QPainter对象
485
//    painter.drawPixmap(0,0,QPixmap(":/images/Watermelon.png"));//绘制图片到窗口
486
//    /*
487
//      QPixmap(":/images/Watermelon.png")如果改为QPixmap(),则只能看到绘制出的框架,看不到图片颜色,也就是看不到图片。
488
//    */
489
//}
490
 
491
void MiniWindow::minimize()
492
{
493
    this->hide();
494
    if(isMiniStatusLabelHidden == false)
495
        statusWidget->hide();
496
}
497
 
498
void MiniWindow::showStatusWedgit()
499
{
500
 
501
    if(isMiniStatusLabelHidden == true){
502
        isMiniStatusLabelHidden = false;
503
        statusWidget->setHidden(false);
504
 
505
    }
506
    else{
507
        isMiniStatusLabelHidden = true;
508
        statusWidget->setHidden(true);
509
    }
510
 
511
}
512
 
513
//void MiniWindow::toNormalMode()
514
//{
515
////    mainWindow->show();
516
////    if(isNormalListWindowHidden == false)
517
////        listWindow->show();
518
//    statusWidget->hide();
519
//    this->hide();
520
//}
521
 
522
void MiniWindow::close()
523
{
524
//    listWindow->close();
525
//    mainWindow->close();
526
    statusWidget->close();
527
    QWidget::close();
528
}
529
 
530
bool MiniWindow::statusWidgetHidden()
531
{
532
    return isMiniStatusLabelHidden;
533
}
534
 
535
void MiniWindow::setStatusWidgetHidden(bool flag)
536
{
537
    if(flag == true)
538
        statusWidget->hide();
539
    else
540
        statusWidget->show();
541
}
542
 
543
 

powered by: WebSVN 2.1.0

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