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

Subversion Repositories ezidebug

[/] [ezidebug/] [trunk/] [EziDebug_src/] [listwindow.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 <QtGui>
2
 
3
#include "toolwindow.h"
4
#include "treeview.h"
5
#include "treeitem.h"
6
//#include "ezidebugprj.h"
7
#include "ezidebugmodule.h"
8
#include "updatedetectthread.h"
9
#include "ezidebuginstancetreeitem.h"
10
#include "ezidebugtreemodel.h"
11
#include "ezidebugscanchain.h"
12
 
13
 
14
#include<QDebug>
15
 
16
ListWindow::ListWindow(QWidget *parent, Qt::WindowFlags f) :
17
    QWidget(parent, f)
18
{
19
    QStringList ifileList ;
20
    QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030"));
21
    setMouseTracking(true);
22
    getToolWindowPointer(parent);
23
 
24
    findDialog = 0;
25
    moduleTreeView = NULL ;
26
    m_peziDebugTreeModel = NULL ;
27
    eDirection = eNone ;
28
    isLeftButtonPress = false ;
29
 
30
    //创建菜单栏和按钮
31
    //createButtons();
32
//    createActions();
33
//    createMenus();
34
    //    QPalette palette;
35
    //    palette.setBrush(QColor(255,255,255));
36
    //    menuBar->setPalette(palette);
37
    //    menuBar->setWindowOpacity(0);
38
 
39
    //创建标题栏
40
    titleBar = new TitleBar(this);
41
 
42
    connect(titleBar->closeButton, SIGNAL(clicked()), this, SLOT(close()));
43
    //创建工具栏
44
    //QToolBar toolBar = new ToolBar(this);
45
    //创建内容区域
46
    //QPushButton *btn = new QPushButton(this);
47
    //btn->setText(tr("cancel"));
48
    //QWidget *contentWidget = new QWidget(this);
49
    //分栏
50
//    closeButton = new Button(tr(":/images/ListWindowExit.bmp"), this);
51
//    //closeButton = new Button ;
52
//    closeButton->setIconSize(QSize(11, 10));
53
//   // closeButton->setGeometry(QRect(this->geometry().left()-20, 7, 11, 10));
54
//    closeButton->setGeometry(QRect(this->geometry().width()-20, 7, 11, 10));
55
//    qDebug()<< this->geometry().width()<<geometry().height();
56
//    connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
57
//    button1 = new QPushButton(tr("hello"),this);
58
//    button1->setGeometry(QRect(10,7, 11, 10));
59
//    connect(button1, SIGNAL(clicked()), this, SLOT(close()));
60
    m_pmessageTreeView = new TreeView(this) ;
61
 
62
 
63
    m_iShowMessageModel = new QStandardItemModel(0,2,this);
64
 
65
 
66
    m_iShowMessageModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Type"));
67
    m_iShowMessageModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Message"));
68
 
69
 
70
    moduleTreeView = new TreeView(this);
71
 
72
    moduleTreeView->setWindowTitle(QObject::tr("Simple Tree Model"));
73
    m_pcontextMenu = new QMenu(moduleTreeView);
74
    m_paddChainAct = m_pcontextMenu->addAction(QIcon(":/images/insert.png"),tr("添加链"));
75
    m_pdeleteChainAct = m_pcontextMenu->addAction(QIcon(":/images/delete.png"),tr("删除链"));
76
    connect(m_paddChainAct,SIGNAL(triggered()), toolWindow, SLOT(addScanChain()));
77
    connect(m_pdeleteChainAct,SIGNAL(triggered()),toolWindow, SLOT(deleteScanChain()));
78
 
79
    moduleTreeView->setModel(NULL);
80
    m_pmessageTreeView->setModel(m_iShowMessageModel);
81
 
82
    mainSplitter = new Splitter(Qt::Horizontal, this);
83
 
84
 
85
    mainSplitter->addWidget(moduleTreeView);
86
    mainSplitter->addWidget(m_pmessageTreeView);
87
 
88
 
89
    moduleTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
90
    connect(moduleTreeView, SIGNAL(customContextMenuRequested(const QPoint&)),
91
            this, SLOT(show_contextmenu(const QPoint&)));
92
    moduleTreeView->show();
93
 
94
    addMessage("welcome","####Welcome to use EziDebug####");
95
 
96
    /* 根据工程 文件是否创建 来是否显示 树状结构图*/
97
    // 在 toolwindow 的 构造 时 检测是否存在 默认路径 ,如果存在有效的默认路径,则会根据该路径1个工程对象
98
    // 构造完 toolwindow 后 接着 构造 listwindow ,如果 listwidow 检查 toolwindow 下的
99
    // 工程对象指针来 判断 是否 需要 重现 树状结构 ,如果 工程对象指针 不为空的话 ,
100
 
101
    // 1 、根据工程对象指针 来判断 是否存在 log 文件、以及工程文件
102
    // 如果没有的话 不在窗口构造的时候 构造树形结构,在旁边的 文本栏 提示错误信息:默认路径 不存在有效数据
103
    // 2 、从log 文件恢复 所有数据,恢复时 检测 log 文件 是否 ok,如果有错误,则在 文本栏提示 错误信息 log 文件被破坏
104
    //
105
    // 当构造函数完成最后,开启 进程信息,并开启定时器,定时器定时 从工程文件中提取所有的 代码文件信息,与目前工程文件中保存的
106
    // 所有文件信息进行对比,检查 代码文件是否 被更新,如果更新 则将 部分更新按钮 有效
107
    //
108
    // 部分更新按钮初始化后不可用,待线程启用后,检测到文件可更新时,再可用
109
    ToolWindow * pparent = static_cast<ToolWindow*>(toolWindow) ;
110
    EziDebugPrj* prj ;
111
    if(prj = const_cast<EziDebugPrj*>(pparent->getCurrentProject()))
112
    {
113
        /*检查所需工程文件是否存在 0:存在 1:不存在*/
114
 
115
        if(!prj->isPrjFileExist())
116
        {
117
            addMessage("error",tr("EziDebug error: There is no Project file in the default path:%1").arg(prj->getCurrentDir().absolutePath()));
118
            delete prj ;
119
            pparent->setCurrentProject(NULL);
120
        }
121
        else
122
        {
123
            // 检测log文件是否存在
124
            if(prj->getCurrentDir().exists("config.ezi"))
125
            {
126
                prj->setLogFileExistFlag(true);
127
 
128
                prj->setLogFileName(prj->getCurrentDir().absoluteFilePath("config.ezi")) ;
129
 
130
                /*检查保存的log文件是否ok 并恢复log文件中的扫描链信息,用于检测要扫描的工程是否被修改导致扫描链被破坏,提取所有信息*/
131
                if(prj->detectLogFile(READ_MODULE_INFO|READ_FILE_INFO|READ_CHAIN_INFO))
132
                {
133
                   // do nothing until the toolwindow show!!
134
                   // listwindow will show infomation after toolwindow show!
135
                }
136
                else
137
                {
138
                    prj->clearupCheckedChainList();
139
                    prj->clearupDestroyedChainList();
140
                    //  对所有改动过的文件(文件时间不一致、文件增、删)进行扫描
141
                    if(EziDebugPrj::ToolQuartus == prj->getToolType())
142
                    {
143
                        prj->parseQuartusPrjFile(ifileList);
144
                    }
145
                    else if(EziDebugPrj::ToolIse == prj->getToolType())
146
                    {
147
                        prj->parseIsePrjFile(ifileList);
148
                    }
149
                    else
150
                    {
151
                        addMessage("error","EziDebug error: EziDebug is not support this kind project file parse!");
152
                        delete prj ;
153
                        pparent->setCurrentProject(NULL);
154
                    }
155
 
156
                    QStringList iaddFileList ;
157
                    QStringList idelFileList ;
158
                    QStringList ichgFileList ;
159
 
160
                    QList<EziDebugPrj::LOG_FILE_INFO*> iaddedinfoList ;
161
                    QList<EziDebugPrj::LOG_FILE_INFO*> ideletedinfoList ;
162
 
163
                    ifileList.sort();
164
 
165
                    prj->compareFileList(ifileList,iaddFileList,idelFileList,ichgFileList);
166
 
167
                    if(prj->updatePrjAllFile(iaddFileList,idelFileList,ichgFileList,iaddedinfoList,ideletedinfoList,false))
168
                    {
169
                        delete prj ;
170
                        pparent->setCurrentProject(NULL);
171
                        qDeleteAll(iaddedinfoList);
172
                        qDeleteAll(ideletedinfoList);
173
                    }
174
                    else
175
                    {
176
                        // store to macro
177
                        prj->addToMacroMap();
178
 
179
                        QString itopModule = prj->getTopModule() ;
180
 
181
                        QString itopModuleComboName = itopModule + QObject::tr(":")+ itopModule ;
182
                        EziDebugInstanceTreeItem* pnewHeadItem = new EziDebugInstanceTreeItem(itopModule,itopModule);
183
                        if(!pnewHeadItem)
184
                        {
185
                            addMessage("error","EziDebug error: There is no memory left!");
186
                            delete prj ;
187
                            pparent->setCurrentProject(NULL);
188
                        }
189
                        else
190
                        {
191
                            if(!itopModule.isEmpty())
192
                            {
193
                                if(prj->getScanChainInfo().count())
194
                                {
195
                                    // 通过备份 进行还原
196
                                    prj->backupChainMap();
197
                                    prj->cleanupBakChainTreeItemMap();
198
                                    prj->cleanupChainTreeItemMap();
199
                                }
200
                                // set the headitem
201
                                prj->setInstanceTreeHeadItem(pnewHeadItem) ;
202
                                if(prj->traverseModuleTree(itopModuleComboName,pnewHeadItem))
203
                                {
204
                                    qDebug() << tr("从log文件恢复失败") << __FILE__ << __LINE__ ;
205
                                    addMessage("error","EziDebug error: resume data failed from EziDebug config file!");
206
 
207
                                    prj->resumeChainMap();
208
                                    prj->updateOperation(EziDebugPrj::OperateTypeNone,NULL,NULL);
209
                                    delete pnewHeadItem ;
210
                                    delete prj ;
211
                                    pparent->setCurrentProject(NULL);
212
                                    qDeleteAll(iaddedinfoList);
213
                                    qDeleteAll(ideletedinfoList);
214
                                    //return ;
215
                                }
216
                                else
217
                                {
218
 
219
                                    if(prj->getBackupChainMap().count())
220
                                    {
221
                                        prj->resumeChainMap();
222
                                        prj->resumeChainTreeItemMap();
223
                                        // 用于清空 备份的 map
224
                                        prj->updateOperation(EziDebugPrj::OperateTypeNone,NULL,NULL);
225
                                    }
226
 
227
 
228
                                    EziDebugInstanceTreeItem::setProject(prj);
229
 
230
                                    if(prj->changedLogFile(iaddedinfoList,ideletedinfoList))
231
                                    {
232
                                        //提示 保存 log 文件出错
233
                                        addMessage("info","EziDebug info: changedLogFile encounter some problem!");
234
                                    }
235
 
236
                                    // 删除 新分配的  log_file_info 指针
237
                                    qDeleteAll(iaddedinfoList);
238
                                    qDeleteAll(ideletedinfoList);
239
 
240
                                    m_peziDebugTreeModel = new EziDebugTreeModel(pnewHeadItem,this);
241
                                    moduleTreeView->setModel(m_peziDebugTreeModel);
242
 
243
                                    // welcomeinfoinit(prj);
244
#if 0
245
                                    QStringList iunexistChainList = prj->checkChainExist();
246
                                    if(iunexistChainList.count())
247
                                    {
248
                                        addMessage("warning","EziDebug warning: Some chains lost partly or full  for some reasons!");
249
                                        for(int i = 0 ; i < iunexistChainList.count() ;i++)
250
                                        {
251
                                            addMessage("warning",tr("EziDebug chain:%1").arg(iunexistChainList.at(i)));
252
                                        }
253
                                    }
254
 
255
                                    if(prj->getDestroyedChainList().count())
256
                                    {
257
                                        // 把所有破坏掉的链打印出来
258
 
259
                                        QString ichain ;
260
                                        QStringList idestroyedChainList = prj->getDestroyedChainList() ;
261
 
262
                                        addMessage("warning","The destroyed chain are:");
263
                                        for(int i = 0 ; i < idestroyedChainList.count() ;i++)
264
                                        {
265
                                            QString ichainName = idestroyedChainList.at(i) ;
266
 
267
                                            EziDebugInstanceTreeItem *pitem = prj->getChainTreeItemMap().value(ichainName);
268
                                            if(pitem)
269
                                            {
270
                                                ichain.append(tr("EziDebug chain:   %1  topInstance:    %2:%3").arg(ichainName)\
271
                                                              .arg(pitem->getModuleName()).arg(pitem->getInstanceName())) ;
272
                                            }
273
                                            addMessage("warning",ichain);
274
                                        }
275
 
276
                                        // 扫描链被破坏 ,提示删除  部分扫描链被破坏  是否删除相关扫描链代码,否则相应扫描链不可用!
277
                                        QMessageBox::StandardButton rb = QMessageBox::question(this, tr("部分扫描链被破坏"), tr("相关扫描链不可用,是否删除相关扫描链代码?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
278
                                        if(rb == QMessageBox::Yes)
279
                                        {
280
                                            QStringList iunDelChainList = prj->deleteDestroyedChain() ;
281
                                            if(iunDelChainList.count())
282
                                            {
283
                                                addMessage("error","EziDebug error: Some chains do not be deleted for some reasons!");
284
                                                for(int i = 0 ; i < iunDelChainList.count() ;i++)
285
                                                {
286
                                                    addMessage("error",tr("EziDebug chain:%1").arg(iunDelChainList.at(i)));
287
                                                }
288
                                                addMessage("error","EziDebug error: Please check the code file is compiled successed!");
289
                                            }
290
 
291
                                            for(int i = 0 ; i < idestroyedChainList.count() ; i++)
292
                                            {
293
                                                QString idestroyedChain = idestroyedChainList.at(i) ;
294
                                                if(!iunDelChainList.contains(idestroyedChain))
295
                                                {
296
                                                    struct EziDebugPrj::LOG_FILE_INFO* pdelChainInfo = new EziDebugPrj::LOG_FILE_INFO ;
297
                                                    memcpy(pdelChainInfo->ainfoName,idestroyedChain.toAscii().data(),idestroyedChain.size()+1);
298
                                                    pdelChainInfo->pinfo = NULL ;
299
                                                    pdelChainInfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
300
                                                    ideletedinfoList << pdelChainInfo ;
301
                                                }
302
 
303
                                            }
304
 
305
                                        }
306
 
307
                                    }
308
 
309
 
310
#if 0
311
                                    if(prj->getScanChainInfo().count())
312
                                    {
313
                                        QMap<QString,EziDebugScanChain*>::const_iterator iaddedChainIter = prj->getScanChainInfo().constBegin() ;
314
                                        while(iaddedChainIter !=  prj->getScanChainInfo().constEnd())
315
                                        {
316
                                            QString ichainName = iaddedChainIter.key();
317
                                            struct EziDebugPrj::LOG_FILE_INFO* pinfo = new EziDebugPrj::LOG_FILE_INFO ;
318
                                            memcpy(pinfo->ainfoName ,ichainName.toAscii().data(),ichainName.size()+1);
319
                                            pinfo->pinfo = iaddedChainIter.value() ;
320
                                            pinfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
321
                                            iaddedinfoList << pinfo ;
322
                                            ++iaddedChainIter ;
323
                                        }
324
                                    }
325
#endif
326
 
327
                                    if(prj->changedLogFile(iaddedinfoList,ideletedinfoList))
328
                                    {
329
                                        //提示 保存 log 文件出错
330
                                        addMessage("info","EziDebug info: changedLogFile encounter some problem!");
331
                                    }
332
 
333
 
334
                                    // 删除 新分配的  log_file_info 指针
335
 
336
                                    qDeleteAll(iaddedinfoList);
337
                                    qDeleteAll(ideletedinfoList);
338
 
339
                                    QStandardItem * pitem = addMessage("info",tr("EziDebug info: The default project parameter:"));
340
                                    addMessage("process",tr("      Scanchain Max Reg Number: %1").arg(prj->getMaxRegNumPerChain()),pitem);
341
                                    addMessage("process",tr("      Project Path: %1").arg(prj->getCurrentDir().absolutePath()),pitem);
342
                                    addMessage("process",tr("      Compile Software: \"%1\"").arg((prj->getToolType() == EziDebugPrj::ToolQuartus) ? ("quartus") :("ise")),pitem);
343
 
344
                                    if(prj->getChainTreeItemMap().count())
345
                                    {
346
                                        QStandardItem * psecondItem = addMessage("info","      EziDebug info: The complete chain are:",pitem);
347
                                        QMap<QString,EziDebugInstanceTreeItem*> itreeItemMap = prj->getChainTreeItemMap() ;
348
                                        QMap<QString,EziDebugInstanceTreeItem*>::const_iterator i = itreeItemMap.constBegin() ;
349
                                        while( i!= itreeItemMap.constEnd())
350
                                        {
351
                                            EziDebugInstanceTreeItem* pitem = i.value();
352
                                            addMessage("process",tr("            EziDebug chain: %1\tInstance Node:%2").arg(i.key()).arg(pitem->getNameData()),psecondItem);
353
                                            EziDebugScanChain *pscanChain = pitem->getScanChainInfo();
354
                                            QString iclockNumStr ;
355
                                            QString itraversedInstStr ;
356
                                            QMap<QString,QVector<QStringList> > iregChain = pscanChain->getRegChain();
357
                                            QMap<QString,QVector<QStringList> >::const_iterator iregChainIter = iregChain.constBegin() ;
358
                                            while( iregChainIter != iregChain.constEnd())
359
                                            {
360
                                                iclockNumStr.append(tr("%1 (%2)     ").arg(pscanChain->getChainRegCount(iregChainIter.key())).arg(iregChainIter.key()));
361
                                                ++iregChainIter ;
362
                                            }
363
 
364
                                            addMessage("process" , tr("            The chain total reg number: %1").arg(iclockNumStr),psecondItem);
365
                                            addMessage("process" , tr("            The traversed NodeList:"),psecondItem);
366
 
367
                                            for(int j = 0 ; j < pscanChain->getInstanceItemList().count() ;j++)
368
                                            {
369
                                                itraversedInstStr.append(tr("  ->  ") + pscanChain->getInstanceItemList().at(j)) ;
370
                                                if((j+1)%3 == 0)
371
                                                {
372
                                                    addMessage("process" , tr("            ") + itraversedInstStr,psecondItem);
373
                                                    itraversedInstStr.clear();
374
                                                }
375
                                            }
376
                                            addMessage("process" , tr("            ") + itraversedInstStr,psecondItem);
377
 
378
                                            ++i ;
379
                                        }
380
                                    }
381
 
382
 
383
                                    UpdateDetectThread * pthread = prj->getThread() ;
384
                                    pthread->start();
385
#endif
386
                                }
387
                            }
388
                            else
389
                            {
390
                                addMessage("error","EziDebug error: There is no top module definition!");
391
                                delete pnewHeadItem ;
392
                                delete prj ;
393
                                pparent->setCurrentProject(NULL);
394
                            }
395
                        }
396
                    }
397
                }
398
 
399
            }
400
            else
401
            {
402
                /*向文本栏 传递错误信息 默认路径不存在log文件*/
403
                addMessage("warning","EziDebug warning: There is no EziDebug config File !");
404
                delete prj ;
405
                pparent->setCurrentProject(NULL);
406
            }
407
        }
408
    }
409
    else
410
    {
411
       addMessage("info",tr("EziDebug info: There is no default EziDebug project file!"));
412
       moduleTreeView->setModel(NULL);
413
    }
414
 
415
//    //创建状态栏
416
//    //m_pStatuBar = new StatuBar(this);
417
 
418
    //创建布局
419
    //QHBoxLayout *secondLayout = new QHBoxLayout(this);
420
    QVBoxLayout *mainLayout = new QVBoxLayout(this) ;
421
    //将部件加入到布局中
422
    mainLayout->addWidget(titleBar);
423
    //mainLayout->addWidget(closeButton);
424
    //secondLayout->addStretch(1);
425
    //secondLayout->addWidget(closeButton);
426
    //mainLayout->addLayout(secondLayout);
427
    mainLayout->addWidget(mainSplitter);
428
 
429
    //mainLayout->addWidget(m_pStatuBar);
430
 
431
 
432
//    mainSplitter->setStyleSheet("Splitter{margin-left:8px;margin-right:6px;margin-top:6px;margin-bottom:10px;}");
433
    mainSplitter->setStyleSheet("Splitter{margin-left:6px;margin-right:6px;margin-top:3px;margin-bottom:10px;}");
434
    //设置间距与边缘空白
435
    mainLayout->setSpacing(0);
436
    mainLayout->setContentsMargins(0,0,0,0);
437
//    mainLayout->setGeometry(QRect(this->geometry().left(),this->geometry().top(),100,100));
438
    setLayout(mainLayout);
439
 
440
 
441
 
442
    //设置列表窗口的背景
443
    setAutoFillBackground(true);
444
    //设置调色板
445
    listBackground.load(":/images/listBackground.bmp",//4.jpg",
446
                        0,Qt::AvoidDither|Qt::ThresholdDither|Qt::ThresholdAlphaDither);
447
    QPalette palette;
448
    palette.setBrush(QPalette::Background, QBrush(listBackground));//竖条纹背景对应这QBrush(listBackground.copy(0, 0, 850, 480))
449
//    palette.setBrush(QPalette::Window,
450
//                     QBrush(listBackground.scaled(size(), Qt::IgnoreAspectRatio,
451
//                                                  Qt::SmoothTransformation)));
452
    setPalette(palette);
453
//  setGeometry(QRect(toolWindow->frameGeometry().bottomLeft().rx(),
454
//                      toolWindow->frameGeometry().bottomLeft().ry(),
455
//                      290, 105));
456
    //setGeometry(QRect(100, 100, 290, 105));
457
    resize(listBackground.size());
458
 
459
    //isListWindowAdsorbedFlag = true;//初始状态下,ListWindow吸附在toolWindow下方
460
 
461
    //设置掩板
462
    //生成一张位图
463
    QBitmap objBitmap(size());
464
    //QPainter用于在位图上绘画
465
    QPainter painter(&objBitmap);
466
    //填充位图矩形框(用白色填充)
467
    painter.fillRect(rect(),Qt::white);
468
    painter.setBrush(QColor(0,0,0));
469
    //在位图上画圆角矩形(用黑色填充)
470
    painter.drawRoundedRect(this->rect(),4,4);
471
    //使用setmask过滤即可
472
    setMask(objBitmap);
473
 
474
 
475
    //设置为无边框
476
    //setWindowFlags(Qt::FramelessWindowHint);
477
    //设置窗口的最大尺寸(桌面)和最小尺寸(图片的尺寸)
478
    setMinimumSize(listBackground.size());
479
    setMaximumSize(qApp->desktop()->size());
480
    //setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
481
    isMaxWin = false;   //初始状态下不是最大化的窗口
482
    //isDrag = true ;
483
    isDrag = false ;
484
    isStick = false ;
485
 
486
 
487
    //放大,方便调试
488
//    resize(291,106);
489
 
490
 
491
    //设置普通模式下的按键
492
    //exitButton->setGeometry(QRect(273, 4, 11, 10));
493
    //menuBar->setGeometry(1, 18, 273, 18);//1, 18, 274, 34
494
    //titleBar->setGeometry(0,0,290,17);
495
    qDebug()<< this->hasMouseTracking();
496
}
497
 
498
ListWindow::~ListWindow()
499
{
500
    qDebug() << "Attention: Begin destruct listwindow object!";
501
    if(m_peziDebugTreeModel)
502
        delete m_peziDebugTreeModel ;
503
 
504
}
505
 
506
QStandardItem *ListWindow::addMessage(const QString &type ,const QString &message ,QStandardItem *parentitem)
507
{
508
    if(!m_iShowMessageModel)
509
    {
510
        return NULL ;
511
    }
512
    QStandardItem* pparentItem ;
513
    QStandardItem* piconItem ;
514
    QStandardItem* pstrItem ;
515
    QList<QStandardItem*> iitemList ;
516
 
517
    if(!parentitem)
518
    {
519
        pparentItem = m_iShowMessageModel->invisibleRootItem() ;
520
    }
521
    else
522
    {
523
        pparentItem = parentitem ;
524
    }
525
 
526
    if(type.toLower() == "warning")
527
    {
528
        QIcon iwarning(":/images/warning");
529
        piconItem = new QStandardItem(iwarning,"");
530
        pstrItem = new QStandardItem(message);
531
        //pstrItem->setForeground(QBrush(QColor(22,130,54)));
532
        pstrItem->setForeground(QBrush(QColor(21,255,21)));
533
        pstrItem->setFont(QFont("Times", 10 , QFont::Bold));
534
    }
535
    else if(type.toLower() == "info")
536
    {
537
        QIcon iinfo(":/images/info");
538
        piconItem = new QStandardItem(iinfo,"");
539
        pstrItem = new QStandardItem(message);
540
        pstrItem->setFont(QFont("Times", 10 , QFont::Black));
541
    }
542
    else if(type.toLower() == "error")
543
    {
544
        QIcon ierror(":/images/error");
545
        piconItem = new QStandardItem(ierror,"");
546
        pstrItem = new QStandardItem(message);
547
        pstrItem->setForeground(QBrush(QColor(255,0,0)));
548
        pstrItem->setFont(QFont("Times", 10 , QFont::Normal));
549
    }
550
    else if(type.toLower() == "process")
551
    {
552
        QIcon iok(":/images/ok");
553
        piconItem = new QStandardItem(iok,"");
554
        pstrItem = new QStandardItem(message);
555
        pstrItem->setForeground(QBrush(QColor(0,0,255)));
556
        pstrItem->setFont(QFont("Times", 10 , QFont::Normal));
557
    }
558
    else if(type.toLower() == "welcome")
559
    {
560
        QIcon iok1(":/images/ok_1");
561
        piconItem = new QStandardItem(iok1,"");
562
        pstrItem = new QStandardItem(message);
563
        pstrItem->setFont(QFont("Times", 10 , QFont::Bold));
564
    }
565
    else
566
    {
567
        QIcon iinfo(":/images/info");
568
        piconItem = new QStandardItem(iinfo,"");
569
        pstrItem = new QStandardItem(message);
570
        pstrItem->setFont(QFont("Times", 10 , QFont::Black));
571
    }
572
 
573
    iitemList << piconItem << pstrItem ;
574
    pparentItem->appendRow(iitemList);
575
 
576
 
577
    return  pparentItem->child((pparentItem->rowCount()-1),0) ;
578
}
579
 
580
 
581
//获取ToolWindow的指针,以获取其位置等信息
582
void ListWindow::getToolWindowPointer(QWidget *toolWin)
583
{
584
    toolWindow = toolWin;
585
}
586
 
587
void ListWindow::createButtons()
588
{
589
 
590
//    exitButton = createToolButton(tr("退出"),
591
//                                  QIcon(":/images/ListWindowExit.bmp"),
592
//                                  QSize(11, 10),
593
//                                  SLOT(close()));
594
 
595
}
596
 
597
void ListWindow::createActions()
598
{
599
    proSettingWizardAct = new QAction(tr("工程设置向导"), this);
600
    //normalAct->setShortcuts(QKeySequence::Quit);
601
    //normalAct->setStatusTip(tr("Exit the application"));
602
    connect(proSettingWizardAct, SIGNAL(triggered()), this, SLOT(proSetting()));
603
 
604
    setProPathAct = new QAction(tr("工程目录"), this);
605
    connect(setProPathAct, SIGNAL(triggered()), this, SLOT(proUpdate()));
606
 
607
    setRegNumACt = new QAction(tr("设置寄存器个数"), this);
608
    connect(setRegNumACt, SIGNAL(triggered()), this, SLOT(proUpdate()));
609
 
610
    useVerilogAct = new QAction(tr("使用verilog语言"), this);
611
    useVerilogAct->setCheckable(true);
612
    //useVerilogAct->setChecked(spreadsheet->showGrid());
613
    connect(useVerilogAct, SIGNAL(triggered()), this, SLOT(proUpdate()));
614
 
615
    useVHDLAct = new QAction(tr("使用VHDL语言"), this);
616
    useVHDLAct->setCheckable(true);
617
    //useVerilogAct->setChecked(spreadsheet->showGrid());
618
    connect(useVHDLAct, SIGNAL(triggered()), this, SLOT(proUpdate()));
619
 
620
    useMixeLanguagedAct = new QAction(tr("使用verilong和VHDL语言"), this);
621
    useMixeLanguagedAct->setCheckable(true);
622
    //useVerilogAct->setChecked(spreadsheet->showGrid());
623
    connect(useMixeLanguagedAct, SIGNAL(triggered()), this, SLOT(proUpdate()));
624
 
625
    setSlotAct = new QAction(tr("设置计时器的时钟"), this);
626
    connect(setSlotAct, SIGNAL(triggered()), this, SLOT(proUpdate()));
627
 
628
    useAlteraAct = new QAction(tr("使用Altera"), this);
629
    useAlteraAct->setCheckable(true);
630
    //useVerilogAct->setChecked(spreadsheet->showGrid());
631
    connect(useAlteraAct, SIGNAL(triggered()), this, SLOT(proUpdate()));
632
 
633
    useXilinxAct = new QAction(tr("使用Xilinx"), this);
634
    useXilinxAct->setCheckable(true);
635
    //useVerilogAct->setChecked(spreadsheet->showGrid());
636
    connect(useXilinxAct, SIGNAL(triggered()), this, SLOT(proUpdate()));
637
 
638
    exitAct = new QAction(tr("退出"), this);
639
    exitAct->setShortcuts(QKeySequence::Quit);
640
    //exitAct->setStatusTip(tr("退出"));
641
    connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
642
 
643
 
644
    rankAfterFileNameAct = new QAction(tr("按文件名"), this);
645
    connect(rankAfterFileNameAct, SIGNAL(triggered()), this, SLOT(proUpdate()));
646
 
647
    rankAfterPathNameAct = new QAction(tr("按路径名"), this);
648
    connect(rankAfterPathNameAct, SIGNAL(triggered()), this, SLOT(proUpdate()));
649
 
650
 
651
    fastOrientAct = new QAction(tr("快速定位"), this);
652
    connect(fastOrientAct, SIGNAL(triggered()), this, SLOT(proUpdate()));
653
 
654
    findAct = new QAction(tr("查找"), this);
655
    //connect(findAct, SIGNAL(triggered()), this, SLOT());
656
    connect(findAct, SIGNAL(triggered()), this, SLOT(find()));
657
 
658
    findNextAct = new QAction(tr("查找下一个"), this);
659
    connect(findNextAct, SIGNAL(triggered()), this, SLOT(proUpdate()));
660
 
661
 
662
    aboutEziDebugAct = new QAction(tr("关于..."), this);
663
    connect(aboutEziDebugAct, SIGNAL(triggered()), this, SLOT(about()));
664
 
665
    helpFileAct = new QAction(tr("帮助"), this);
666
    connect(helpFileAct, SIGNAL(triggered()), this, SLOT(proUpdate()));
667
}
668
 
669
void ListWindow::createMenus()
670
{
671
    menuBar = new MenuBar(this);
672
 
673
    addMenu = menuBar->addMenu(tr("添加"));
674
    addMenu->addAction(proSettingWizardAct);
675
    addMenu->addAction(setProPathAct);
676
    addMenu->addAction(setRegNumACt);
677
    addMenu->addSeparator();
678
    addMenu->addAction(useVerilogAct);
679
    addMenu->addAction(useVHDLAct);
680
    addMenu->addAction(useMixeLanguagedAct);
681
    addMenu->addSeparator();
682
    addMenu->addAction(setSlotAct);
683
    addMenu->addSeparator();
684
    addMenu->addAction(useAlteraAct);
685
    addMenu->addAction(useXilinxAct);
686
    addMenu->addSeparator();
687
    addMenu->addAction(exitAct);
688
 
689
    checkMenu = menuBar->addMenu(tr("查看"));
690
 
691
    sortMenu = menuBar->addMenu(tr("排序"));
692
    sortMenu->addAction(rankAfterFileNameAct);
693
    sortMenu->addAction(rankAfterPathNameAct);
694
 
695
    findMenu = menuBar->addMenu(tr("查找"));
696
    findMenu->addAction(fastOrientAct);
697
    findMenu->addSeparator();
698
    findMenu->addAction(findAct);
699
    findMenu->addAction(findNextAct);
700
 
701
    helpMenu = menuBar->addMenu(tr("帮助"));
702
    helpMenu->addAction(aboutEziDebugAct);
703
    helpMenu->addAction(helpFileAct);
704
 
705
//    //获取图像
706
//    QPixmap objPixmap(tr(":/images/listWindowMenubar.bmp"));
707
//    //得到图像宽和高
708
//    int nPixWidth = objPixmap.width() / 5;
709
//    int nPixHeight = objPixmap.height();
710
//    addMenu->setIcon(QIcon(objPixmap.copy(nPixWidth*0,0,nPixWidth,nPixHeight)));
711
//    checkMenu->setIcon(QIcon(objPixmap.copy(nPixWidth*1,0,nPixWidth,nPixHeight)));
712
//    sortMenu->setIcon(QIcon(objPixmap.copy(nPixWidth*2,0,nPixWidth,nPixHeight)));
713
//    findMenu->setIcon(QIcon(objPixmap.copy(nPixWidth*3,0,nPixWidth,nPixHeight)));
714
//    helpMenu->setIcon(QIcon(objPixmap.copy(nPixWidth*4,0,nPixWidth,nPixHeight)));
715
 
716
//    addMenu->setContentsMargins(0,0,0,0);
717
//    //addMenu->setBaseSize(QSize(nPixWidth,nPixHeight));
718
//    //addMenu->setSizeIncrement(nPixWidth,nPixHeight);
719
//    addMenu->setFixedSize(nPixWidth,nPixHeight);
720
 
721
 
722
}
723
 
724
//void ListWindow::contextMenuEvent(QContextMenuEvent *event)
725
//{
726
//    QMenu menu(this);
727
//    menu.addAction(ListWindowmizeAct);
728
//    menu.addAction(normalAct);
729
//    menu.addAction(exitAct);
730
//    menu.exec(event->globalPos());
731
//}
732
 
733
 
734
 
735
 
736
 
737
 
738
//void ListWindow::mousePressEvent(QMouseEvent * event)
739
//{
740
//    if (event->button() == Qt::LeftButton) //点击左边鼠标
741
//    {
742
//        //globalPos()获取根窗口的相对路径,frameGeometry().topLeft()获取主窗口左上角的位置
743
//        dragPosition = event->globalPos() - frameGeometry().topLeft();
744
//        event->accept();   //鼠标事件被系统接收
745
//    }
746
//    //    if (event->button() == Qt::RightButton)
747
//    //    {
748
//    //         close();
749
//    //    }
750
//}
751
 
752
//void ListWindow::mouseMoveEvent(QMouseEvent * event)
753
//{
754
//    if (event->buttons() == Qt::LeftButton) //当满足鼠标左键被点击时。
755
//    {
756
//        move(event->globalPos() - dragPosition);//移动窗口
757
////        //如果ListWindow的上边沿和ToolWindow的下边沿靠近,则移至紧紧贴合的位置
758
////        int disY = toolWindow->geometry().bottom() - this->geometry().top();
759
////        if(disY < 5 || disY > -5){
760
////            move(this->geometry().left(), this->geometry().top() + disY);
761
////        }
762
//        event->accept();
763
//    }
764
//}
765
 
766
//void ListWindow::mouseReleaseEvent(QMouseEvent *event)
767
//{
768
////    if (event->buttons() == Qt::LeftButton) //当满足鼠标左键被点击时。
769
////    {
770
 
771
//        //如果ListWindow的上边沿和ToolWindow的下边沿靠近,则移至紧紧贴合的位置
772
//        int disY = toolWindow->geometry().bottom() - this->geometry().top();
773
//        if((disY < 15) && (disY > -15)){
774
//            move(this->geometry().left(), this->geometry().top() + disY);//移动窗口
775
//            toolWindow->setListWindowAdsorbedFlag(true);
776
//        }
777
//        else{
778
//            toolWindow->setListWindowAdsorbedFlag(false);
779
//        }
780
 
781
//        event->accept();
782
////    }
783
//}
784
 
785
 
786
 
787
 
788
//当鼠标移动到主界面内部周围5像素时,改变鼠标形状;当进行伸缩拖动时,根据拖动方向进行主界面的位置和大小设置即可。
789
//鼠标按下事件
790
void ListWindow::mousePressEvent(QMouseEvent *event)
791
{
792
//    static int i = 0 ;
793
//    qDebug()<<"mouse Press Event"<<i++ ;
794
    if (event->button() == Qt::LeftButton)
795
    {
796
        oldPointGlobal = pointPressGlobal = event->globalPos();
797
        isLeftButtonPress = true;
798
 
799
        oldWindowPoint = this->geometry().topLeft();
800
 
801
        mousePressPoint = event->pos();
802
        parentRect = parentWidget()->geometry();
803
        //isDrag = true ;
804
    }
805
    event->accept();
806
}
807
 
808
// 窗体拖动事件
809
void ListWindow::moveEvent(QMoveEvent *event)
810
{
811
//    static int i = 0 ;
812
//    qDebug()<<"moveEvent"<<i++ ;
813
//    QWidget * parent = this->parentWidget();
814
//    const int disMax = 30;
815
//    ToolWindow* parent_tool = static_cast<ToolWindow*>(parent);
816
//    parent_tool->setListWindowAdsorbedFlag(false);
817
 
818
//    int dis = parent_tool->geometry().bottom() - this->geometry().top();
819
//    if((dis < disMax) && (dis > -disMax)){
820
////        move(this->geometry().left(), parent->geometry().bottom());//移动窗口
821
////        move(200,300);
822
//        qDebug()<< parent_tool->geometry().left()<< parent_tool->geometry().right() \
823
//                   << parent_tool->geometry().top()<< parent_tool->geometry().bottom ();
824
 
825
//        qDebug()<< this->geometry().left()<< this->geometry().right() \
826
//                   << this->geometry().top()<< this->geometry().bottom ();
827
 
828
//        move(300,400);
829
//        qDebug()<<"move the widget to bottom of parent !";
830
//        parent_tool->setListWindowAdsorbedFlag(true);
831
//    }
832
//    dis = parent->geometry().top() - this->geometry().bottom();
833
//    if((dis < disMax) && (dis > -disMax)){
834
//        move(this->geometry().left(), this->geometry().top() + dis);//移动窗口
835
//        parent_tool->setListWindowAdsorbedFlag(true);
836
//    }
837
//    dis = parent->geometry().right() - this->geometry().left();
838
//    if((dis < disMax) && (dis > -disMax)){
839
//        move(parent->geometry().right(), this->geometry().top());//移动窗口
840
//        parent_tool->setListWindowAdsorbedFlag(true);
841
//    }
842
//    dis = parent->geometry().left() - this->geometry().right();
843
//    if((dis < disMax) && (dis > -disMax)){
844
//        move(this->geometry().left() + dis, this->geometry().top());//移动窗口
845
//        parent_tool->setListWindowAdsorbedFlag(true);
846
//    }
847
//    event->accept();
848
      event->ignore();
849
 
850
    //  event->accept();
851
     // QWidget::moveEvent(event);
852
      //event->accept();
853
}
854
 
855
//鼠标移动事件
856
void ListWindow::mouseMoveEvent(QMouseEvent *event)
857
{
858
    //qDebug()<<"ListWindow::mouseMoveEvent" ;
859
    // qDebug()<<"ListWindow::mouseMoveEvent"<<this->geometry().width()<<this->geometry().height()<<"mouse track!"<<event->x()<<event->y();
860
    if(!isLeftButtonPress)
861
    {
862
        eDirection = (enum_Direction)PointValid(event->x(),event->y());
863
 
864
        SetCursorStyle(eDirection);
865
 
866
    }
867
    else
868
    {
869
        int nXGlobal = event->globalX();
870
        int nYGlobal = event->globalY();
871
        NewPointGlobal = event->globalPos();
872
        SetDrayMove(nXGlobal,nYGlobal,eDirection);
873
        pointPressGlobal =QPoint(nXGlobal,nYGlobal);
874
        if(cursor().shape() == Qt::ArrowCursor)
875
        {
876
            mouseMovePoint = event->pos() ;
877
            diffPos = event->pos() - mousePressPoint;
878
            magneticMove(parentRect,geometry());
879
        }
880
 
881
    }
882
    event->accept();
883
}
884
//鼠标释放事件
885
void ListWindow::mouseReleaseEvent(QMouseEvent *event)
886
{
887
    if (event->button() == Qt::LeftButton)
888
    {
889
        isLeftButtonPress = false;
890
        eDirection = eNone;
891
        //isDrag = false ;
892
    }
893
    event->accept();
894
}
895
 
896
//鼠标双击事件
897
void ListWindow::mouseDoubleClickEvent(QMouseEvent *event)
898
{
899
    //Null
900
//    qDebug()<< "list window"<<this->frameGeometry().left() << this->frameGeometry().top();
901
    if ((event->button() == Qt::LeftButton) && (event->y()<= 10))
902
        //if ((event->button() == Qt::LeftButton) && (event->y()<= titleBar->height()))
903
     {
904
        if(!isMaxWin)
905
        {
906
            rectRestoreWindow = geometry();
907
            setGeometry(qApp->desktop()->availableGeometry());
908
        }
909
        else
910
        {
911
            setGeometry(rectRestoreWindow);
912
        }
913
        isMaxWin = !isMaxWin;
914
    }
915
    event->accept();
916
}
917
 
918
void ListWindow::magneticMove(const QRect &bechmarkRect, const QRect &targetRect)
919
{
920
    int bechmarkLeft = bechmarkRect.left();
921
    int bechmarkRight = bechmarkRect.right();
922
    int bechmarkTop = bechmarkRect.top();
923
    int bechmarkBottom = bechmarkRect.bottom();
924
    int targetLeft = targetRect.left();
925
    int targetRight = targetRect.right();
926
    int targetTop = targetRect.top();
927
    int targetBottom = targetRect.bottom();
928
    QPoint finalPosition;
929
    const int magneticOffset = 12 ;
930
 
931
    isStick = false;
932
//    qDebug()<< "move widget"<<tr("上") <<targetTop <<tr("下") << targetBottom \
933
//            <<tr("左")<< targetLeft <<tr("右")<< targetRight ;
934
 
935
//    qDebug()<< "static widget"<<tr("上") <<bechmarkTop <<tr("下") << bechmarkBottom \
936
//            <<tr("左")<< bechmarkLeft <<tr("右")<< bechmarkRight ;
937
 
938
//    qDebug()<< "magneticMove" << mousePressPoint.x() << mousePressPoint.y() \
939
//            << mouseMovePoint.x()<< mouseMovePoint.y()<< this->parentWidget()->geometry().bottom()\
940
//               << this->parentWidget()->geometry().right();
941
    /*
942
    qDebug() << "bechmarkLeft - targetLeft:" << qAbs(bechmarkLeft - targetLeft);
943
    qDebug() << "pos().y():" << pos().y();
944
    qDebug() << "geometry().top():" << geometry().top();
945
    qDebug() << "bechmarkBottom:" << bechmarkBottom;
946
    qDebug() << "bechmarkTop - targetRect.height()):" << bechmarkTop - targetRect.height();
947
    */
948
 
949
    //if (qAbs(bechmarkLeft - targetLeft) < qAbs(bechmarkRight - targetLeft))
950
    //move(pos() + diffPos);
951
    // 移动窗口 的 pos()
952
    //horizontal-1:left to left
953
     //&& (pos().y() <= bechmarkBottom && pos().y() >= (bechmarkTop - targetRect.height()))
954
    if(qAbs(diffPos.x()) < magneticOffset \
955
       &&qAbs(bechmarkLeft - targetLeft) < magneticOffset
956
       && bechmarkRect.intersects(geometry()))
957
    {
958
        qDebug() << "Left To Left" << endl;
959
        //move(geometry().topLeft() + diffPos);
960
        //move(bechmarkLeft, pos().y() + diffPos.y());
961
        finalPosition.setX(bechmarkLeft);
962
        finalPosition.setY(pos().y() + diffPos.y());
963
        isStick |= true;
964
    }
965
 
966
    //horizontal-2:left to right
967
    if (qAbs(diffPos.x()) < magneticOffset
968
        && qAbs(bechmarkRight - targetLeft) < magneticOffset
969
        && bechmarkRect.intersects(QRect(pos().x() - magneticOffset, pos().y(),
970
                                     targetRect.width(), targetRect.height())))
971
    {
972
        qDebug() << "Left To Right" << endl;
973
        //move(bechmarkRight, pos().y() + diffPos.y());
974
        finalPosition.setX(bechmarkRight);
975
        finalPosition.setY(pos().y() + diffPos.y());
976
        isStick |= true;
977
    }
978
 
979
    //horizontal-3:right to left
980
    if (qAbs(diffPos.x()) < magneticOffset
981
    && qAbs(bechmarkLeft - targetRight) < magneticOffset
982
    && bechmarkRect.intersects(QRect(pos().x(), pos().y(),
983
                                     targetRect.width() + magneticOffset, targetRect.height())))
984
    {
985
        qDebug() << "Right TO Left" << endl;
986
        //move(pos().x() + (bechmarkLeft - targetRight),
987
        //    pos().y() + diffPos.y());
988
        finalPosition.setX(pos().x() + bechmarkLeft - targetRight);
989
        finalPosition.setY(pos().y() + diffPos.y());
990
        qDebug() << "finalPosition.x():" << finalPosition.x() << endl;
991
        qDebug() << "bechmarkLeft - targetRect.width():" << bechmarkLeft - targetRect.width();
992
        isStick |= true;
993
    }
994
 
995
    //horizontal-4:right to right
996
    if (qAbs(diffPos.x()) < magneticOffset
997
        && qAbs(bechmarkRight - targetRight) < magneticOffset
998
        //&& bechmarkRect.intersects(geometry())
999
        )
1000
    {
1001
        qDebug() << "Right TO Right" << endl;
1002
        //move(pos().x() + (bechmarkRight - targetRight), pos().y() + diffPos.y());
1003
        finalPosition.setX(pos().x() + (bechmarkRight - targetRight));
1004
        //finalPosition.setX(targetLeft + (bechmarkRight - targetRight));
1005
        finalPosition.setY(pos().y() + diffPos.y());
1006
        isStick |= true;
1007
    }
1008
 
1009
    //veritcal-1:top to top
1010
    if (qAbs(diffPos.y()) < magneticOffset
1011
        && qAbs(bechmarkTop - targetTop) < magneticOffset \
1012
            && bechmarkRect.intersects(geometry())
1013
        //&& (isStick || bechmarkRect.intersects(geometry()))
1014
        )
1015
    {
1016
        qDebug() << "Top TO Top" << endl;
1017
 
1018
        if (isStick)
1019
        finalPosition.setY(bechmarkTop);
1020
        else
1021
        {
1022
            finalPosition.setX(pos().x() + diffPos.x());
1023
            finalPosition.setY(bechmarkTop);
1024
        }
1025
 
1026
        //move(pos().x() + diffPos.x(), bechmarkTop);
1027
        isStick |= true;
1028
    }
1029
 
1030
    //veritcal-2:top to bottom
1031
    if (qAbs(diffPos.y()) < magneticOffset
1032
        && qAbs(bechmarkBottom - targetTop) < magneticOffset
1033
        && bechmarkRect.intersects(QRect(pos().x(), pos().y()- magneticOffset,
1034
                                         targetRect.width(), targetRect.height())))
1035
    {
1036
        qDebug() << "Top To Bottom" << endl;
1037
        //move(pos().x() + diffPos.x(), bechmarkBottom);
1038
        if (isStick)
1039
        {
1040
            qDebug() << "case 1" ;
1041
            finalPosition.setY(bechmarkBottom);
1042
        }
1043
        else
1044
        {
1045
//            finalPosition.setX(pos().x() + diffPos.x());
1046
            finalPosition.setX(pos().x()+diffPos.x());
1047
            finalPosition.setY(bechmarkBottom);
1048
        }
1049
        isStick |= true;
1050
    }
1051
 
1052
    //veritcal-3:bottom to top
1053
    if (qAbs(diffPos.y()) < magneticOffset
1054
        && qAbs(bechmarkTop - targetBottom) < magneticOffset
1055
        && bechmarkRect.intersects(QRect(pos().x(), pos().y(),
1056
        targetRect.width(), targetRect.height() + magneticOffset)))
1057
    {
1058
        qDebug() << "Bottom TO Top" << endl;
1059
        if (isStick)
1060
        {
1061
            qDebug() << "case 2";
1062
            finalPosition.setY(pos().y() + (bechmarkTop - targetBottom));
1063
        }
1064
        else
1065
        {
1066
            finalPosition.setX(pos().x() + diffPos.x());
1067
            finalPosition.setY(pos().y() + (bechmarkTop - targetBottom));
1068
        }
1069
        //move(pos().x() + diffPos.x(), pos().y() + (bechmarkTop - targetBottom));
1070
        isStick |= true;
1071
    }
1072
 
1073
    //veritcal-4:bottom to bottom
1074
    if (qAbs(diffPos.y()) < magneticOffset
1075
        && qAbs(bechmarkBottom - targetBottom) < magneticOffset
1076
        && bechmarkRect.intersects(geometry()))
1077
    {
1078
        qDebug() << "Bottom TO Bottom" << endl;
1079
 
1080
        if (isStick)
1081
            finalPosition.setY(pos().y() + (bechmarkBottom - targetBottom));
1082
        else
1083
        {
1084
            finalPosition.setX(pos().x() + diffPos.x());
1085
            finalPosition.setY(pos().y() + (bechmarkBottom - targetBottom));
1086
        }
1087
        //move(pos().x() + diffPos.x(), pos().y() + (bechmarkBottom - targetBottom));
1088
 
1089
        isStick |= true;
1090
    }
1091
 
1092
    if (isStick)
1093
    {
1094
        qDebug()<< "finalPosition" << finalPosition.x()<< finalPosition.y() << isStick ;
1095
        move(finalPosition);
1096
    }
1097
    else
1098
    {
1099
 
1100
        qDebug()<<"!!!move the widget!!!" << diffPos.x()<< diffPos.y()\
1101
               << (pos() + diffPos).x()<<(pos() + diffPos).y() << isStick;
1102
 
1103
        move(pos() + diffPos);
1104
    }
1105
//        move(oldWindowPoint+NewPointGlobal-oldPointGlobal);
1106
//        i++ ;
1107
////        move(700,10+i*10);
1108
//        move(700+diffPos.x(),i*5+diffPos.y());
1109
}
1110
 
1111
//判断鼠标所在位置在当前窗口的什么位置,上下左右 边界上,或者都不是
1112
int ListWindow::PointValid(int x, int y)
1113
{
1114
    enum_Direction direction = eNone;
1115
 
1116
//    int top = geometry().top();
1117
//    int bottom = geometry().bottom();
1118
//    int left = geometry().left();
1119
//    int right = geometry().right();
1120
//    int width = this->width();
1121
//    int height = this->height();
1122
 
1123
//    int ra = this->x();
1124
//    int rb = this->y();
1125
 
1126
//    QRect rr = rect();
1127
//    QRect rg = geometry();
1128
//    QPoint q1 = geometry().topLeft();
1129
//    QPoint q2 = geometry().bottomRight();
1130
 
1131
//    QSize rsize = this->size();
1132
 
1133
 
1134
//    if ((x >= left) && (x < left + 5))
1135
//    {
1136
//        if((y >= top) && (y < top + 5))
1137
//            direction = eLeftTop;
1138
//        else if((y > bottom - 5) && (y <= bottom))
1139
//            direction = eBottomLeft;
1140
//        else
1141
//            direction = eLeft;
1142
//    }
1143
//    else if((x > right - 5) && (x <= right))
1144
//    {
1145
//        if((y >= top) && (y < top + 5))
1146
//            direction = eTopRight;
1147
//        else if((y > bottom - 5) && (y <= bottom))
1148
//            direction = eRightBottom;
1149
//        else
1150
//            direction = eLeft;
1151
//    }
1152
    // this is listwindow
1153
    if ((x >= 0) && (x < 5))
1154
    {
1155
        if((y >= 0) && (y < 5))
1156
            direction = eLeftTop;
1157
        else if((y > this->height() - 5) && (y <= this->height()))
1158
            direction = eBottomLeft;
1159
        else
1160
            direction = eLeft;
1161
    }
1162
    else if((x > this->width() - 5) && (x <= this->width()))
1163
    {
1164
        if((y >= 0) && (y < 5))
1165
            direction = eTopRight;
1166
        else if((y > this->height() - 5) && (y <= this->height()))
1167
            direction = eRightBottom;
1168
        else
1169
            direction = eRight;
1170
    }
1171
    else if((y >= 0) && (y < 5))
1172
    {
1173
        direction = eTop;
1174
    }
1175
    else if((y > this->height() - 5) && (y <= this->height()))
1176
    {
1177
        direction = eBottom;
1178
    }
1179
 
1180
    //qDebug() << "judget direction" << x << y << direction ;
1181
    return (int)direction;
1182
}
1183
 
1184
//设置鼠标样式
1185
void ListWindow::SetCursorStyle(enum_Direction direction)
1186
{
1187
    //设置上下左右以及右上、右下、左上、坐下的鼠标形状
1188
    //isDrag = false ;
1189
    switch(direction)
1190
    {
1191
    case eTop:
1192
    case eBottom:
1193
        setCursor(Qt::SizeVerCursor);
1194
        break;
1195
    case eRight:
1196
    case eLeft:
1197
        setCursor(Qt::SizeHorCursor);
1198
        break;
1199
    case eTopRight:
1200
    case eBottomLeft:
1201
        setCursor(Qt::SizeBDiagCursor);
1202
        break;
1203
    case eRightBottom:
1204
    case eLeftTop:
1205
        setCursor(Qt::SizeFDiagCursor);
1206
        break;
1207
    default:
1208
        {
1209
            setCursor(Qt::ArrowCursor);
1210
            //isDrag = true ;
1211
        }
1212
        break;
1213
    }
1214
}
1215
 
1216
//设置鼠标拖动的窗口位置信息
1217
void ListWindow::SetDrayMove(int nXGlobal,int nYGlobal,enum_Direction direction)
1218
{
1219
//    //计算偏差
1220
//    int ndX = nXGlobal - pointPressGlobal.x();
1221
//    int ndY = nYGlobal - pointPressGlobal.y();
1222
    //获得主窗口位置信息
1223
 
1224
    QRect rectWindow = geometry();
1225
    qDebug()<< "direction" << direction << geometry().bottom()<<geometry().right();
1226
    //判别方向
1227
    switch(direction)
1228
    {
1229
    case eTop:
1230
        rectWindow.setTop(nYGlobal);
1231
        break;
1232
    case eBottom:
1233
        rectWindow.setBottom(nYGlobal);
1234
        break;
1235
    case eRight:
1236
        rectWindow.setRight(nXGlobal);
1237
        //titleBar->lineLabel->
1238
                //resize(titleBar->lineLabel->size().width() + ndX,
1239
                //                    titleBar->lineLabel->size().height());
1240
        break;
1241
    case eLeft:
1242
        rectWindow.setLeft(nXGlobal);
1243
        break;
1244
    case eTopRight:
1245
        rectWindow.setTop(nYGlobal);
1246
        rectWindow.setRight(nXGlobal);
1247
        break;
1248
    case eBottomLeft:
1249
        rectWindow.setBottom(nYGlobal);
1250
        rectWindow.setLeft(nXGlobal);
1251
        break;
1252
    case eRightBottom:
1253
        rectWindow.setBottom(nYGlobal);
1254
        rectWindow.setRight(nXGlobal);
1255
        break;
1256
    case eLeftTop:
1257
        rectWindow.setTop(nYGlobal);
1258
        rectWindow.setLeft(nXGlobal);
1259
         break;
1260
    default:
1261
        break;
1262
    }
1263
 
1264
    qDebug()<< "new pos" << rectWindow.top()<< rectWindow.left()<<rectWindow.width()<< rectWindow.height() \
1265
               <<nXGlobal << nYGlobal;
1266
    if(rectWindow.width()< minimumWidth() || rectWindow.height()<minimumHeight())
1267
    {
1268
        qDebug()<< "the window size less than miniumWidth ";
1269
 
1270
 
1271
        return;
1272
    }
1273
 
1274
//  qDebug()<< "new pos" << rectWindow.top()<< rectWindow.left()<<rectWindow.width()<< rectWindow.height();
1275
    qDebug()<< "move positon";
1276
    //重新设置窗口位置为新位置信息
1277
    setGeometry(rectWindow);
1278
//    move(100,200);
1279
}
1280
 
1281
 
1282
 
1283
 
1284
 
1285
 
1286
 
1287
 
1288
 
1289
 
1290
 
1291
 
1292
 
1293
 
1294
//bool ListWindow::isAdsorbed()
1295
//{
1296
//    return isNormalListWindowAdsorbed;
1297
//}
1298
 
1299
//void ListWindow::paintEvent(QPaintEvent *)
1300
//{
1301
//    QPainter painter(this);//创建一个QPainter对象
1302
//    painter.drawPixmap(0,0,QPixmap(":/images/Watermelon.png"));//绘制图片到窗口
1303
//    /*
1304
//      QPixmap(":/images/Watermelon.png")如果改为QPixmap(),则只能看到绘制出的框架,看不到图片颜色,也就是看不到图片。
1305
//    */
1306
//}
1307
 
1308
// 随着窗体变化而设置背景
1309
void ListWindow::resizeEvent(QResizeEvent *event)
1310
{
1311
//    QWidget::resizeEvent(event);
1312
//    QPalette pal(palette());
1313
//    pal.setBrush(QPalette::Window,
1314
//                 QBrush(listBackground.scaled(event->size(),
1315
//                                                 Qt::IgnoreAspectRatio,
1316
//                                                 Qt::SmoothTransformation)));
1317
////    pal.setBrush(QPalette::Window,
1318
////                QBrush(_image.scaled(event->size(), Qt::IgnoreAspectRatio,
1319
////                        Qt::SmoothTransformation)));
1320
//    setPalette(pal);
1321
 
1322
    QWidget::resizeEvent(event);
1323
 
1324
 
1325
 
1326
    //背景图片缩放,九宫格,四个角不变,其他缩放
1327
    int dx = event->size().width() - listBackground.width();
1328
    int dy = event->size().height() - listBackground.height();
1329
/*暂时去掉  最小窗口时  无法扩大 */
1330
//    if(dx < 1 || dy <1)
1331
//    {
1332
//        qDebug()<< "no zoom !";
1333
//        return;
1334
//    }
1335
    qDebug()<< "begin zoom !";
1336
 
1337
    //创建一个size为变化后size的新画布
1338
    QImage img(event->size(), QImage::Format_ARGB32);
1339
    QPainter *paint = new QPainter(&img);
1340
    //在新区域画图
1341
    //左上-fixed,中上-x方向scaled,右上-fixed
1342
    paint->drawPixmap(0, 0, listBackground.copy(0, 0, 5, 27));
1343
    paint->drawPixmap(5, 0, listBackground.copy(5, 0, 321, 27).scaled(QSize(321 + dx, 27),
1344
                                                                         Qt::IgnoreAspectRatio,
1345
                                                                         Qt::SmoothTransformation));
1346
    paint->drawPixmap(326 + dx, 0, listBackground.copy(326, 0, 42, 27));
1347
    //左下-fixed,中下-x方向scaled,右下-fixed
1348
    paint->drawPixmap(0, 359 + dy, listBackground.copy(0, 359, 4, 10));
1349
    paint->drawPixmap(4, 359 + dy, listBackground.copy(4, 359, 363, 10).scaled(QSize(363 + dx, 10),
1350
                                                                         Qt::IgnoreAspectRatio,
1351
                                                                         Qt::SmoothTransformation));
1352
    paint->drawPixmap(363 + dx, 359 + dy, listBackground.copy(363, 359, 5, 10));
1353
    //左中-y方向scaled,中中-xy方向scaled,右中-y方向scaled
1354
    paint->drawPixmap(0, 27, listBackground.copy(0, 27, 4, 333).scaled(QSize(4, 333 + dy),
1355
                                                                       Qt::IgnoreAspectRatio,
1356
                                                                       Qt::SmoothTransformation));
1357
    paint->drawPixmap(4, 27, listBackground.copy(4, 27, 358, 333).scaled(QSize(358 + dx, 333 + dy),
1358
                                                                         Qt::IgnoreAspectRatio,
1359
                                                                         Qt::SmoothTransformation));
1360
    paint->drawPixmap(363 + dx, 27, listBackground.copy(363, 27, 5, 333).scaled(QSize(5, 333 + dy),
1361
                                                                            Qt::IgnoreAspectRatio,
1362
                                                                            Qt::SmoothTransformation));
1363
 
1364
 
1365
//保留原背景图片对应的resize参数,以供参考和查错
1366
//    //左上-fixed,中上-x方向scaled,右上-fixed
1367
//    paint->drawPixmap(0, 0, listBackground.copy(0, 0, 24, 40));
1368
//    paint->drawPixmap(24, 0, listBackground.copy(24, 0, 240, 40).scaled(QSize(240 + dx, 40),
1369
//                                                                         Qt::IgnoreAspectRatio,
1370
//                                                                         Qt::SmoothTransformation));
1371
//    paint->drawPixmap(264 + dx, 0, listBackground.copy(264, 0, 25, 40));
1372
//    //左下-fixed,中下-x方向scaled,右下-fixed
1373
//    paint->drawPixmap(0, 52 + dy, listBackground.copy(0, 52, 24, 53));
1374
//    paint->drawPixmap(24, 52 + dy, listBackground.copy(24, 52, 240, 53).scaled(QSize(240 + dx, 53),
1375
//                                                                         Qt::IgnoreAspectRatio,
1376
//                                                                         Qt::SmoothTransformation));
1377
//    paint->drawPixmap(264 + dx, 52 + dy, listBackground.copy(264, 52, 25, 53));
1378
//    //左中-y方向scaled,中中-xy方向scaled,右中-y方向scaled
1379
//    paint->drawPixmap(0, 40, listBackground.copy(0, 40, 24, 12).scaled(QSize(24, 12 + dy),
1380
//                                                                       Qt::IgnoreAspectRatio,
1381
//                                                                       Qt::SmoothTransformation));
1382
//    paint->drawPixmap(24, 40, listBackground.copy(24, 40, 240, 12).scaled(QSize(240 + dx, 12 + dy),
1383
//                                                                         Qt::IgnoreAspectRatio,
1384
//                                                                         Qt::SmoothTransformation));
1385
//    paint->drawPixmap(264 + dx, 40, listBackground.copy(264, 40, 25, 12).scaled(QSize(25, 12 + dy),
1386
//                                                                            Qt::IgnoreAspectRatio,
1387
//                                                                            Qt::SmoothTransformation));
1388
    paint->end();
1389
 
1390
//    QLabel *l = new QLabel;
1391
//    l->setPixmap(QPixmap::fromImage(img));
1392
//    l->show();
1393
 
1394
    QPalette pal(palette());
1395
    pal.setBrush(QPalette::Window,QBrush(img));
1396
    //    pal.setBrush(QPalette::Window,
1397
    //                 QBrush(backgroundPix.scaled(event->size(),
1398
    //                                              Qt::IgnoreAspectRatio,
1399
    //                                              Qt::SmoothTransformation)));
1400
    setPalette(pal);
1401
 
1402
    //设置掩板
1403
    //生成一张位图
1404
    QBitmap objBitmap(size());
1405
    //QPainter用于在位图上绘画
1406
    QPainter painter(&objBitmap);
1407
    //填充位图矩形框(用白色填充)
1408
    painter.fillRect(rect(),Qt::white);
1409
    painter.setBrush(QColor(0,0,0));
1410
    //在位图上画圆角矩形(用黑色填充)
1411
    painter.drawRoundedRect(this->rect(),4,4);
1412
    //使用setmask过滤即可
1413
    setMask(objBitmap);
1414
//    closeButton->setGeometry(QRect(this->geometry().width()-18, 5, 11, 10));
1415
}
1416
 
1417
 
1418
 
1419
//点击右上角标题栏按钮时,仅隐藏列表窗口
1420
void ListWindow::close()
1421
{
1422
    setListWindowHidden(true);
1423
}
1424
 
1425
 
1426
 
1427
//void ListWindow::moveListWindow(const QPoint &p, QPoint bottomLeft, QPoint bottomRight)
1428
//{
1429
//    QPoint listWtopLeft = this->geometry().topLeft();
1430
//    if((listWtopLeft.ry() == bottomLeft.ry())
1431
//            &&((listWtopLeft.rx() <= bottomRight.rx())
1432
//               || (geometry().topRight().rx() >= bottomLeft.rx()))){
1433
//        move(p + geometry().topLeft());
1434
//    }
1435
//}
1436
 
1437
//void ListWindow::toMiniMode()
1438
//{
1439
//    toolWindow->hide();
1440
//    this->hide();
1441
//    miniWindow->show();
1442
//    if(!miniWindow->statusWidgetHidden())
1443
//        miniWindow->setStatusWidgetHidden(false);
1444
//}
1445
 
1446
//void ListWindow::deleteChain()
1447
//{
1448
 
1449
//}
1450
 
1451
void ListWindow::testbenchGeneration()
1452
{
1453
 
1454
}
1455
 
1456
void ListWindow::about()
1457
{
1458
    QMessageBox::about(this, tr("About EziDebug"),
1459
            tr("<h2>EziDebug 0.1</h2>"
1460
               "<p>Copyright &copy; 2012 Software Inc."
1461
               "<p>EziDebug is a application that... "
1462
               ""
1463
               ));
1464
}
1465
 
1466
 
1467
void ListWindow::show_contextmenu(const QPoint& pos)
1468
{
1469
    QModelIndex  index = moduleTreeView->indexAt(pos) ;
1470
    EziDebugPrj * pcurrentPrj = NULL ;
1471
    pcurrentPrj = const_cast<EziDebugPrj *>(EziDebugInstanceTreeItem::getProject());
1472
    if(index.isValid())
1473
    {
1474
       m_ptreeItem = static_cast<EziDebugInstanceTreeItem *>(index.internalPointer());
1475
 
1476
       if(m_ptreeItem)
1477
       {
1478
           if(!m_ptreeItem->getScanChainInfo())
1479
           {
1480
                /*可以添加链 不能删除链*/
1481
               m_paddChainAct->setEnabled(true); ;
1482
               m_pdeleteChainAct->setEnabled(false);
1483
           }
1484
           else
1485
           {
1486
               /*可以删除链 不能添加链*/
1487
               m_paddChainAct->setEnabled(false);
1488
               m_pdeleteChainAct->setEnabled(true);
1489
           }
1490
       }
1491
 
1492
       if(m_ptreeItem->getModuleName() == pcurrentPrj->getTopModule())
1493
       {
1494
           m_paddChainAct->setEnabled(false);
1495
           m_pdeleteChainAct->setEnabled(false);
1496
       }
1497
 
1498
       if(pcurrentPrj->getPrjModuleMap().value(m_ptreeItem->getModuleName())->isLibaryCore())
1499
       {
1500
           m_paddChainAct->setEnabled(false);
1501
           m_pdeleteChainAct->setEnabled(false);
1502
       }
1503
    }
1504
    else
1505
    {
1506
        m_paddChainAct->setEnabled(false);
1507
        m_pdeleteChainAct->setEnabled(false);
1508
    }
1509
 
1510
    QPoint mm = QCursor::pos();
1511
    if(m_pcontextMenu)
1512
       m_pcontextMenu->exec(mm) ;
1513
 
1514
 
1515
//        m_pcontextMenu->exec(pos) ;
1516
}
1517
 
1518
void ListWindow::generateTreeView(EziDebugInstanceTreeItem* item)
1519
{
1520
    // item 是 要显示的节点的头节点
1521
//    QString itopModuleComboName  ;
1522
//    QString itopModule ;
1523
//    EziDebugPrj *pcurrentPrj = NULL ;
1524
    if(!m_peziDebugTreeModel)
1525
    {
1526
        qDebug() << "Generate Tree View!!!" << item->getNameData();
1527
        m_peziDebugTreeModel = new EziDebugTreeModel(item,this);
1528
        moduleTreeView->setModel(m_peziDebugTreeModel);
1529
    }
1530
    else
1531
    {
1532
        qDebug() << "Generate Tree View!!!"  ;
1533
 
1534
        // 插入链 删除链
1535
        moduleTreeView->setModel(NULL);
1536
        // 更新 图标
1537
        if(!item)
1538
        {
1539
        }
1540
        else
1541
        {
1542
#if 0
1543
            EziDebugInstanceTreeItem* poldTreeRootItem = m_peziDebugTreeModel->getInstanceTreeRootItem() ;
1544
            qDebug() << "top item "<< item ;
1545
            // 替换为新的头节点
1546
            m_peziDebugTreeModel->setInstanceTreeRootItem(item);
1547
 
1548
            /*成功则 删除 上次更新的所有节点 ,插入链的节点咱不能删除  */
1549
            delete poldTreeRootItem ;
1550
 
1551
            moduleTreeView->setModel(m_peziDebugTreeModel);
1552
#else
1553
            // EziDebugInstanceTreeItem* poldTreeRootItem = m_peziDebugTreeModel->getInstanceTreeRootItem() ;
1554
 
1555
            delete m_peziDebugTreeModel ;
1556
            // 替换为新的头节点
1557
            m_peziDebugTreeModel = new EziDebugTreeModel(item,this);
1558
 
1559
            /*成功则 删除 上次更新的所有节点 ,插入链的节点咱不能删除  */
1560
            //delete poldTreeRootItem ;
1561
 
1562
            moduleTreeView->setModel(m_peziDebugTreeModel);
1563
 
1564
#endif
1565
        }
1566
 
1567
    }
1568
}
1569
 
1570
void ListWindow::clearTreeView(void)
1571
{
1572
    if(moduleTreeView)
1573
    {
1574
        moduleTreeView->setModel(NULL);
1575
        if(m_peziDebugTreeModel)
1576
        {
1577
            delete m_peziDebugTreeModel ;
1578
            m_peziDebugTreeModel = NULL ;
1579
        }
1580
    }
1581
}
1582
 
1583
void ListWindow::welcomeinfoinit(EziDebugPrj *prj)
1584
{
1585
 #if 0
1586
    // (代码中的扫描链 在 log文件中不存在  说明log文件曾经被破坏过!)
1587
    if(prj->getLogFileExistFlag()&&prj->getLogfileDestroyedFlag())
1588
    {
1589
        // 提示删除所有链   部分扫描链信息丢失  是否删除所有扫描链代码
1590
        QMessageBox::StandardButton rb = QMessageBox::question(this, tr("部分扫描链信息丢失"), tr("是否删除所有扫描链代码?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
1591
        if(rb == QMessageBox::Yes)
1592
        {
1593
            // 删除所有链代码
1594
            currentPrj->deleteAllEziDebugCode(ivlgFileMap,ivhdlFileMap);
1595
            // 删除所有链相关的信息
1596
            QMap<QString,EziDebugScanChain*> ichainMap = currentPrj->getScanChainInfo();
1597
            QMap<QString,EziDebugScanChain*>::const_iterator k = ichainMap.constBegin() ;
1598
            while(k != ichainMap.constEnd())
1599
            {
1600
                EziDebugScanChain* pchain = k.value() ;
1601
                if(pchain)
1602
                {
1603
                    delete pchain ;
1604
                    pchain = NULL ;
1605
                }
1606
                ++k ;
1607
            }
1608
            currentPrj->cleanupChainMap();
1609
            currentPrj->cleanupChainTreeItemMap();
1610
            currentPrj->cleanupChainQueryTreeItemMap();
1611
 
1612
            // 删除log所有链信息 (新的log文件所以不用添加信息,此步可跳过)
1613
 
1614
            // 清空 被破坏的扫描链list
1615
            currentPrj->clearupDestroyedChainList();
1616
 
1617
        }
1618
        else
1619
        {
1620
            // 不处理
1621
        }
1622
 
1623
    }
1624
 #endif
1625
    if(prj)
1626
    {
1627
        if(!m_peziDebugTreeModel)
1628
        {
1629
            ToolWindow * pparent = static_cast<ToolWindow*>(toolWindow) ;
1630
 
1631
            /*向文本栏 传递错误信息 待窗体显示的时候,显示给用户看*/
1632
            addMessage("error","EziDebug error: The EziDebug config file has been destroyed!");
1633
 
1634
            // log 文件被破坏, 可能还没有扫描到扫描链
1635
            //if(prj->getScanChainInfo().count())
1636
            //{
1637
                // 配置文件被破坏  是否删除工程代码中所有的扫描链代码?
1638
                QMessageBox::StandardButton rb = QMessageBox::question(this, tr("配置文件被破坏"), tr("是否删除工程代码中所有扫描链代码?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
1639
 
1640
                if(rb == QMessageBox::Yes)
1641
                {
1642
                    QMap<QString,EziDebugVlgFile*> ivlgFileMap ;
1643
                    QMap<QString,EziDebugVhdlFile*> ivhdlFileMap ;
1644
                    if(EziDebugPrj::ToolQuartus == prj->getToolType())
1645
                    {
1646
                        prj->parseQuartusPrjFile(ivlgFileMap,ivhdlFileMap);
1647
                    }
1648
                    else if(EziDebugPrj::ToolIse == prj->getToolType())
1649
                    {
1650
                        prj->parseIsePrjFile(ivlgFileMap,ivhdlFileMap);
1651
                    }
1652
                    else
1653
                    {
1654
                        addMessage("error","EziDebug error: EziDebug is not support this kind project file parse!");
1655
                        delete prj ;
1656
                        pparent->setCurrentProject(NULL);
1657
                    }
1658
 
1659
                    // delete all ezidebug code
1660
                    prj->deleteAllEziDebugCode(ivlgFileMap,ivhdlFileMap) ;
1661
 
1662
                    // delete all log file
1663
                    addMessage("warning","EziDebug warning: The EziDebug config file has been deleted!");
1664
                    QFile ilogFile(prj->getCurrentDir().absoluteFilePath("config.ezi"));
1665
                    ilogFile.remove();
1666
 
1667
                    // set exist flag false
1668
                    //prj->setLogFileExistFlag(false);
1669
 
1670
                    delete prj ;
1671
                    pparent->setCurrentProject(NULL);
1672
 
1673
                }
1674
                else
1675
                {
1676
                    // 如果不删除代码,不进行恢复
1677
                    delete prj ;
1678
                    pparent->setCurrentProject(NULL);
1679
                }
1680
            //}
1681
        }
1682
        else
1683
        {
1684
            QList<EziDebugPrj::LOG_FILE_INFO*> iaddedinfoList ;
1685
            QList<EziDebugPrj::LOG_FILE_INFO*> ideletedinfoList ;
1686
            QStringList iunDelChainList ;
1687
            QStringList ideletedChainList ;
1688
 
1689
            // (代码中的扫描链 在 log文件中不存在  说明log文件曾经被破坏过!)
1690
            if(prj->getLogFileExistFlag()&&prj->getLogfileDestroyedFlag())
1691
            {
1692
                // 提示删除所有链
1693
                // 部分扫描链信息丢失  是否删除所有扫描链代码
1694
                QMessageBox::StandardButton rb = QMessageBox::question(this, tr("部分扫描链信息丢失"), tr("是否删除所有扫描链代码?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
1695
                if(rb == QMessageBox::Yes)
1696
                {
1697
                    // 删除所有链代码
1698
 
1699
                    prj->deleteAllEziDebugCode(prj->getPrjVlgFileMap(),prj->getPrjVhdlFileMap());
1700
 
1701
                    QMap<QString,EziDebugVlgFile*>::const_iterator ivlgFileIter = prj->getPrjVlgFileMap().constBegin() ;
1702
                    while(ivlgFileIter != prj->getPrjVlgFileMap().constEnd())
1703
                    {
1704
                        QString irelativeFileName = ivlgFileIter.key() ;
1705
                        EziDebugVlgFile* pfile = ivlgFileIter.value() ;
1706
 
1707
                        EziDebugPrj::LOG_FILE_INFO* pdelFileInfo = new EziDebugPrj::LOG_FILE_INFO ;
1708
                        pdelFileInfo->etype = EziDebugPrj::infoTypeFileInfo ;
1709
                        pdelFileInfo->pinfo = NULL ;
1710
                        memcpy(pdelFileInfo->ainfoName , irelativeFileName.toAscii().data() , irelativeFileName.size()+1);
1711
                        ideletedinfoList.append(pdelFileInfo);
1712
 
1713
                        struct EziDebugPrj::LOG_FILE_INFO* paddFileInfo = new EziDebugPrj::LOG_FILE_INFO ;
1714
                        paddFileInfo->etype = EziDebugPrj::infoTypeFileInfo ;
1715
                        paddFileInfo->pinfo = pfile ;
1716
                        memcpy(paddFileInfo->ainfoName , irelativeFileName.toAscii().data(), irelativeFileName.size()+1);
1717
                        iaddedinfoList.append(paddFileInfo);
1718
 
1719
                        ++ivlgFileIter ;
1720
                    }
1721
 
1722
 
1723
                    QMap<QString,EziDebugVhdlFile*>::const_iterator ivhdlFileIter = prj->getPrjVhdlFileMap().constBegin() ;
1724
                    while(ivhdlFileIter != prj->getPrjVhdlFileMap().constEnd())
1725
                    {
1726
                        QString irelativeFileName = ivhdlFileIter.key() ;
1727
                        EziDebugVhdlFile* pfile = ivhdlFileIter.value() ;
1728
                        EziDebugPrj::LOG_FILE_INFO* pdelFileInfo = new EziDebugPrj::LOG_FILE_INFO ;
1729
                        pdelFileInfo->etype = EziDebugPrj::infoTypeFileInfo ;
1730
                        pdelFileInfo->pinfo = NULL ;
1731
                        memcpy(pdelFileInfo->ainfoName , irelativeFileName.toAscii().data() , irelativeFileName.size()+1);
1732
                        ideletedinfoList.append(pdelFileInfo);
1733
 
1734
                        struct EziDebugPrj::LOG_FILE_INFO* paddFileInfo = new EziDebugPrj::LOG_FILE_INFO ;
1735
                        paddFileInfo->etype = EziDebugPrj::infoTypeFileInfo ;
1736
                        paddFileInfo->pinfo = pfile ;
1737
                        memcpy(paddFileInfo->ainfoName , irelativeFileName.toAscii().data(), irelativeFileName.size()+1);
1738
                        iaddedinfoList.append(paddFileInfo);
1739
                        ++ivhdlFileIter ;
1740
                    }
1741
 
1742
 
1743
                    // 删除所有链相关的信息
1744
                    QMap<QString,EziDebugScanChain*> ichainMap = prj->getScanChainInfo();
1745
                    QMap<QString,EziDebugScanChain*>::const_iterator k = ichainMap.constBegin() ;
1746
                    while(k != ichainMap.constEnd())
1747
                    {
1748
                        QString ichainName = k.key() ;
1749
                        EziDebugScanChain* pchain = k.value() ;
1750
 
1751
                        // 从log文件中删除相关信息
1752
                        struct EziDebugPrj::LOG_FILE_INFO* pdelChainInfo = new EziDebugPrj::LOG_FILE_INFO ;
1753
                        memcpy(pdelChainInfo->ainfoName,ichainName.toAscii().data(),ichainName.size()+1);
1754
                        pdelChainInfo->pinfo = NULL ;
1755
                        pdelChainInfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
1756
                        ideletedinfoList << pdelChainInfo ;
1757
 
1758
                        if(pchain)
1759
                        {
1760
                            delete pchain ;
1761
                            pchain = NULL ;
1762
                        }
1763
                        ++k ;
1764
                    }
1765
                    prj->cleanupChainMap();
1766
                    prj->cleanupChainTreeItemMap();
1767
                    prj->cleanupChainQueryTreeItemMap();
1768
 
1769
                    // 删除log所有链信息 (新的log文件所以不用添加信息,此步可跳过)
1770
 
1771
                    // 清空 被破坏的扫描链list
1772
                    prj->clearupDestroyedChainList();
1773
 
1774
                }
1775
                else
1776
                {
1777
                    // 不处理
1778
                }
1779
 
1780
            }
1781
 
1782
 
1783
            if(prj->getDestroyedChainList().count())
1784
            {
1785
                // 把所有破坏掉的链打印出来
1786
 
1787
                QString ichain ;
1788
                QStringList idestroyedChainList = prj->getDestroyedChainList() ;
1789
 
1790
                addMessage("error","The destroyed chain are:");
1791
                for(int i = 0 ; i < idestroyedChainList.count() ;i++)
1792
                {
1793
                    QString ichainName = idestroyedChainList.at(i) ;
1794
 
1795
                    EziDebugInstanceTreeItem *pitem = prj->getChainTreeItemMap().value(ichainName);
1796
                    if(pitem)
1797
                    {
1798
                        ichain.append(tr("EziDebug chain:   %1  topInstance:    %2:%3").arg(ichainName)\
1799
                                      .arg(pitem->getModuleName()).arg(pitem->getInstanceName())) ;
1800
                    }
1801
                    addMessage("error",ichain);
1802
                }
1803
 
1804
                // 是否删除相关扫描链代码,否则相应扫描链不可用!
1805
                QMessageBox::StandardButton rb = QMessageBox::question(this, tr("部分扫描链被破坏"), tr("相关扫描链不可用,是否删除相关扫描链代码?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
1806
                if(rb == QMessageBox::Yes)
1807
                {
1808
                    iunDelChainList = prj->deleteDestroyedChain(iaddedinfoList,ideletedinfoList) ;
1809
                    if(iunDelChainList.count())
1810
                    {
1811
                        addMessage("error","EziDebug error: Some chains do not be deleted for some reasons!");
1812
                        for(int i = 0 ; i < iunDelChainList.count() ;i++)
1813
                        {
1814
                            addMessage("error",tr("EziDebug chain:%1").arg(iunDelChainList.at(i)));
1815
                        }
1816
                        addMessage("error","EziDebug error: Please check the code file is compiled successed!");
1817
                    }
1818
 
1819
                    for(int i = 0 ; i < idestroyedChainList.count() ; i++)
1820
                    {
1821
                        QString idestroyedChain = idestroyedChainList.at(i) ;
1822
                        if(!iunDelChainList.contains(idestroyedChain))
1823
                        {
1824
                            ideletedChainList.append(idestroyedChain);
1825
                            struct EziDebugPrj::LOG_FILE_INFO* pdelChainInfo = new EziDebugPrj::LOG_FILE_INFO ;
1826
                            memcpy(pdelChainInfo->ainfoName,idestroyedChain.toAscii().data(),idestroyedChain.size()+1);
1827
                            pdelChainInfo->pinfo = NULL ;
1828
                            pdelChainInfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
1829
                            ideletedinfoList << pdelChainInfo ;
1830
                        }
1831
                    }
1832
 
1833
                }
1834
            }
1835
 
1836
            QStringList icheckChainList = prj->checkChainExist();
1837
 
1838
            for(int i = 0 ; i < icheckChainList.count() ;i++)
1839
            {
1840
                QString iupdatedChain = icheckChainList.at(i) ;
1841
                if(!ideletedChainList.contains(iupdatedChain))
1842
                {
1843
                    struct EziDebugPrj::LOG_FILE_INFO* pdelChainInfo = new EziDebugPrj::LOG_FILE_INFO ;
1844
                    memcpy(pdelChainInfo->ainfoName,iupdatedChain.toAscii().data(),iupdatedChain.size()+1);
1845
                    pdelChainInfo->pinfo = NULL ;
1846
                    pdelChainInfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
1847
                    ideletedinfoList << pdelChainInfo ;
1848
 
1849
                    struct EziDebugPrj::LOG_FILE_INFO* paddChainInfo = new EziDebugPrj::LOG_FILE_INFO ;
1850
                    memcpy(paddChainInfo->ainfoName,iupdatedChain.toAscii().data(),iupdatedChain.size()+1);
1851
                    paddChainInfo->pinfo = paddChainInfo ;
1852
                    paddChainInfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
1853
                    iaddedinfoList << paddChainInfo ;
1854
                }
1855
            }
1856
 
1857
#if 0
1858
            if(prj->getScanChainInfo().count())
1859
            {
1860
                QMap<QString,EziDebugScanChain*>::const_iterator iaddedChainIter = prj->getScanChainInfo().constBegin() ;
1861
                while(iaddedChainIter !=  prj->getScanChainInfo().constEnd())
1862
                {
1863
                    QString ichainName = iaddedChainIter.key();
1864
                    struct EziDebugPrj::LOG_FILE_INFO* pinfo = new EziDebugPrj::LOG_FILE_INFO ;
1865
                    memcpy(pinfo->ainfoName ,ichainName.toAscii().data(),ichainName.size()+1);
1866
                    pinfo->pinfo = iaddedChainIter.value() ;
1867
                    pinfo->etype = EziDebugPrj::infoTypeScanChainStructure ;
1868
                    iaddedinfoList << pinfo ;
1869
                    ++iaddedChainIter ;
1870
                }
1871
            }
1872
#endif
1873
 
1874
            if(prj->changedLogFile(iaddedinfoList,ideletedinfoList))
1875
            {
1876
                //提示 保存 log 文件出错
1877
                addMessage("info","EziDebug info: changedLogFile encounter some problem!");
1878
            }
1879
 
1880
 
1881
            // 删除 新分配的  log_file_info 指针
1882
 
1883
            qDeleteAll(iaddedinfoList);
1884
            qDeleteAll(ideletedinfoList);
1885
 
1886
            QStandardItem * pitem = addMessage("info",tr("EziDebug info: The default project parameter:"));
1887
            addMessage("process",tr("      Scanchain Max Reg Number: %1").arg(prj->getMaxRegNumPerChain()),pitem);
1888
            addMessage("process",tr("      Project Path: %1").arg(prj->getCurrentDir().absolutePath()),pitem);
1889
            addMessage("process",tr("      Compile Software: \"%1\"").arg((prj->getToolType() == EziDebugPrj::ToolQuartus) ? ("quartus") :("ise")),pitem);
1890
 
1891
            if(prj->getChainTreeItemMap().count())
1892
            {
1893
                QStandardItem * psecondItem = addMessage("info","      EziDebug info: The existed chains are:",pitem);
1894
                QMap<QString,EziDebugInstanceTreeItem*> itreeItemMap = prj->getChainTreeItemMap() ;
1895
                QMap<QString,EziDebugInstanceTreeItem*>::const_iterator i = itreeItemMap.constBegin() ;
1896
                while( i!= itreeItemMap.constEnd())
1897
                {
1898
                    EziDebugInstanceTreeItem* pitem = i.value();
1899
                    addMessage("process",tr("            EziDebug chain: %1\tInstance Node:%2").arg(i.key()).arg(pitem->getNameData()),psecondItem);
1900
                    EziDebugScanChain *pscanChain = pitem->getScanChainInfo();
1901
                    QString iclockNumStr ;
1902
                    QString itraversedInstStr ;
1903
                    QMap<QString,QVector<QStringList> > iregChain = pscanChain->getRegChain();
1904
                    QMap<QString,QVector<QStringList> >::const_iterator iregChainIter = iregChain.constBegin() ;
1905
                    while( iregChainIter != iregChain.constEnd())
1906
                    {
1907
                        iclockNumStr.append(tr("%1 (%2)     ").arg(pscanChain->getChainRegCount(iregChainIter.key())).arg(iregChainIter.key()));
1908
                        ++iregChainIter ;
1909
                    }
1910
 
1911
                    addMessage("process" , tr("            The chain total reg number: %1").arg(iclockNumStr),psecondItem);
1912
                    addMessage("process" , tr("            The traversed NodeList:"),psecondItem);
1913
 
1914
                    for(int j = 0 ; j < pscanChain->getInstanceItemList().count() ;j++)
1915
                    {
1916
                        itraversedInstStr.append(tr("  ->  ") + pscanChain->getInstanceItemList().at(j)) ;
1917
                        if((j+1)%3 == 0)
1918
                        {
1919
                            addMessage("process" , tr("            ") + itraversedInstStr,psecondItem);
1920
                            itraversedInstStr.clear();
1921
                        }
1922
                    }
1923
                    addMessage("process" , tr("            ") + itraversedInstStr,psecondItem);
1924
 
1925
                    ++i ;
1926
                }
1927
            }
1928
 
1929
 
1930
            UpdateDetectThread * pthread = prj->getThread() ;
1931
            pthread->start();
1932
        }
1933
    }
1934
}
1935
 
1936
 
1937
QPushButton *ListWindow::createToolButton(const QString &toolTip, const QIcon &icon,
1938
                                    const QSize &size, const char *member)
1939
{
1940
    QPushButton *button = new QPushButton(this);
1941
    button->setToolTip(toolTip);
1942
    button->setIcon(icon);
1943
    button->setIconSize(size);//(QSize(10, 10));
1944
    // button->setSizeIncrement(size);
1945
    //button->setSizePolicy(size.width(), size.height());
1946
    button->setFlat(true);
1947
    connect(button, SIGNAL(clicked()), this, member);
1948
 
1949
    return button;
1950
}
1951
 
1952
void ListWindow::find()
1953
{
1954
    if (!findDialog) {
1955
        findDialog = new FindDialog;
1956
//        connect(findDialog, SIGNAL(findNext(const QString &,
1957
//                                            Qt::CaseSensitivity)),
1958
//                spreadsheet, SLOT(findNext(const QString &,
1959
//                                           Qt::CaseSensitivity)));
1960
//        connect(findDialog, SIGNAL(findPrevious(const QString &,
1961
//                                                Qt::CaseSensitivity)),
1962
//                spreadsheet, SLOT(findPrevious(const QString &,
1963
//                                               Qt::CaseSensitivity)));
1964
    }
1965
 
1966
    findDialog->show();
1967
    findDialog->raise();
1968
    findDialog->activateWindow();
1969
}
1970
 
1971
 
1972
//控制列表窗口是否隐藏
1973
void ListWindow::setListWindowHidden(bool flag)
1974
{
1975
    isListWindowHiddenFlag = flag;
1976
    if(isListWindowHiddenFlag)
1977
        this->hide();
1978
    else
1979
        this->showNormal();
1980
}
1981
 
1982
//获取普通模式下,ToolWindow不隐藏时,列表窗口是否隐藏
1983
bool ListWindow::isListWindowHidden()
1984
{
1985
    return isListWindowHiddenFlag;
1986
}
1987
 
1988
void ListWindow::enterEvent(QEvent * event)
1989
{
1990
//    QMouseEvent * mouseEvent = (QMouseEvent *) event ;
1991
//    qDebug()<<"enter  Event" << mouseEvent->x()<< mouseEvent->y()<< this->frameGeometry().right();
1992
//    eDirection = (enum_Direction)PointValid(mouseEvent->x(),mouseEvent->y());
1993
//    SetCursorStyle(eDirection);
1994
}
1995
 
1996
void ListWindow::leaveEvent(QEvent * event)
1997
{
1998
//    QMouseEvent * mouseEvent = (QMouseEvent *) event ;
1999
//    qDebug()<<"leave  Event" << mouseEvent->x()<< mouseEvent->y()<< this->frameGeometry().right();
2000
//    eDirection = (enum_Direction)PointValid(mouseEvent->x(),mouseEvent->y());
2001
//    SetCursorStyle(eDirection);
2002
}
2003
 
2004
void ListWindow::setChainActEnable(bool addenable,bool delenable)
2005
{
2006
//    m_paddChainAct->setEnabled(addenable) ;
2007
//    m_pdeleteChainAct->setEnabled(delenable) ;
2008
}
2009
 
2010
////工具栏窗口只需要获取isListWindowAdsorbed,而不需要更改之
2011
//bool ListWindow::isListWindowAdsorbed()
2012
//{
2013
//    return isListWindowAdsorbedFlag;
2014
//}
2015
 
2016
EziDebugInstanceTreeItem * ListWindow::getCurrentTreeItem(void)
2017
{
2018
    return m_ptreeItem ;
2019
}
2020
 
2021
void ListWindow::setCurrentTreeItem(EziDebugInstanceTreeItem * item)
2022
{
2023
    m_ptreeItem = item ;
2024
}

powered by: WebSVN 2.1.0

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