OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / debugger / sourcefileswindow.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "sourcefileswindow.h"
34
35 #include "debuggeractions.h"
36 #include "debuggerconstants.h"
37 #include "debuggercore.h"
38 #include "debuggerengine.h"
39
40 #include <utils/qtcassert.h>
41 #include <utils/savedaction.h>
42
43 #include <QtCore/QDebug>
44 #include <QtCore/QFileInfo>
45
46 #include <QtGui/QHeaderView>
47 #include <QtGui/QMenu>
48 #include <QtGui/QResizeEvent>
49
50
51 //////////////////////////////////////////////////////////////////
52 //
53 // SourceFilesWindow
54 //
55 //////////////////////////////////////////////////////////////////
56
57 namespace Debugger {
58 namespace Internal {
59
60 static DebuggerEngine *currentEngine()
61 {
62     return debuggerCore()->currentEngine();
63 }
64
65 SourceFilesWindow::SourceFilesWindow(QWidget *parent)
66     : QTreeView(parent)
67 {
68     QAction *act = debuggerCore()->action(UseAlternatingRowColors);
69
70     setAttribute(Qt::WA_MacShowFocusRect, false);
71     setFrameStyle(QFrame::NoFrame);
72     setWindowTitle(tr("Source Files"));
73     setSortingEnabled(true);
74     setAlternatingRowColors(act->isChecked());
75     setRootIsDecorated(false);
76     setIconSize(QSize(10, 10));
77     //header()->setDefaultAlignment(Qt::AlignLeft);
78
79     connect(this, SIGNAL(activated(QModelIndex)),
80         SLOT(sourceFileActivated(QModelIndex)));
81     connect(act, SIGNAL(toggled(bool)),
82         SLOT(setAlternatingRowColorsHelper(bool)));
83 }
84
85 void SourceFilesWindow::sourceFileActivated(const QModelIndex &index)
86 {
87     DebuggerEngine *engine = currentEngine();
88     QTC_ASSERT(engine, return);
89     engine->gotoLocation(index.data().toString());
90 }
91
92 void SourceFilesWindow::contextMenuEvent(QContextMenuEvent *ev)
93 {
94     DebuggerEngine *engine = currentEngine();
95     QTC_ASSERT(engine, return);
96     QModelIndex index = indexAt(ev->pos());
97     index = index.sibling(index.row(), 0);
98     QString name = index.data().toString();
99     bool engineActionsEnabled = engine->debuggerActionsEnabled();
100
101     QMenu menu;
102     QAction *act1 = new QAction(tr("Reload Data"), &menu);
103
104     act1->setEnabled(engineActionsEnabled);
105     //act1->setCheckable(true);
106     QAction *act2 = 0;
107     if (name.isEmpty()) {
108         act2 = new QAction(tr("Open File"), &menu);
109         act2->setEnabled(false);
110     } else {
111         act2 = new QAction(tr("Open File \"%1\"'").arg(name), &menu);
112         act2->setEnabled(true);
113     }
114
115     menu.addAction(act1);
116     menu.addAction(act2);
117     menu.addSeparator();
118     menu.addAction(debuggerCore()->action(SettingsDialog));
119
120     QAction *act = menu.exec(ev->globalPos());
121
122     if (act == act1)
123         engine->reloadSourceFiles();
124     else if (act == act2)
125         engine->gotoLocation(name);
126 }
127
128 } // namespace Internal
129 } // namespace Debugger
130