2 * Copyright Johannes Sixt
3 * This file is licensed under the GNU General Public License Version 2.
4 * See the file COPYING in the toplevel directory of the source directory.
12 #include <QContextMenuEvent>
15 #include <kxmlguiwindow.h>
16 #include <kxmlguifactory.h>
17 #include <klocale.h> /* i18n */
22 WinStack::WinStack(QWidget
* parent
) :
27 connect(&m_findDlg
.m_buttonForward
,
28 SIGNAL(clicked()), SLOT(slotFindForward()));
29 connect(&m_findDlg
.m_buttonBackward
,
30 SIGNAL(clicked()), SLOT(slotFindBackward()));
32 connect(this, SIGNAL(setTabWidth(int)), this, SLOT(slotSetTabWidth(int)));
39 void WinStack::contextMenuEvent(QContextMenuEvent
* e
)
41 // get the context menu from the GUI factory
44 top
= top
->parentWidget();
45 while (!top
->isTopLevel());
46 KXmlGuiWindow
* mw
= static_cast<KXmlGuiWindow
*>(top
);
48 static_cast<QMenu
*>(mw
->factory()->container("popup_files_empty", mw
));
49 m
->exec(e
->globalPos());
53 void WinStack::reloadAllFiles()
55 for (int i
= count()-1; i
>= 0; i
--) {
56 windowAt(i
)->reloadFile();
60 QSize
WinStack::sizeHint() const
62 return QSize(640, 480);
65 void WinStack::activate(const QString
& fileName
, int lineNo
, const DbgAddr
& address
)
67 QFileInfo
fi(fileName
);
71 * We didn't find that file. Now check if it is a relative path and
72 * try m_lastOpenDir as prefix.
74 TRACE(fi
.filePath() + (" not found, looking in " + m_lastOpenDir
));
75 if (!fi
.isRelative() || m_lastOpenDir
.isEmpty()) {
78 fi
.setFile(m_lastOpenDir
+ "/" + fi
.filePath());
83 // if this is not an absolute path name, make it one
84 activatePath(fi
.absoluteFilePath(), lineNo
, address
);
87 void WinStack::activateFile(const QString
& fileName
)
89 activatePath(fileName
, 0, DbgAddr());
92 bool WinStack::activatePath(QString pathName
, int lineNo
, const DbgAddr
& address
)
94 // check whether the file is already open
96 for (int i
= count()-1; i
>= 0; i
--) {
97 if (windowAt(i
)->fileName() == pathName
) {
103 // not found, load it
104 fw
= new SourceWindow(pathName
, this);
107 if (!fw
->loadFile()) {
113 int idx
= addTab(fw
, QFileInfo(pathName
).fileName());
114 setTabToolTip(idx
, pathName
);
116 connect(fw
, SIGNAL(clickedLeft(const QString
&,int,const DbgAddr
&,bool)),
117 SIGNAL(toggleBreak(const QString
&,int,const DbgAddr
&,bool)));
118 connect(fw
, SIGNAL(clickedMid(const QString
&,int,const DbgAddr
&)),
119 SIGNAL(enadisBreak(const QString
&,int,const DbgAddr
&)));
122 connect(fw
, SIGNAL(disassemble(const QString
&, int)),
123 SIGNAL(disassemble(const QString
&, int)));
124 connect(fw
, SIGNAL(expanded(int)), SLOT(slotExpandCollapse(int)));
125 connect(fw
, SIGNAL(collapsed(int)), SLOT(slotExpandCollapse(int)));
128 connect(this, SIGNAL(setTabWidth(int)), fw
, SLOT(setTabWidth(int)));
129 fw
->setTabWidth(m_tabWidth
);
130 fw
->setFocusPolicy(Qt::WheelFocus
);
132 // set PC if there is one
133 emit
newFileLoaded();
135 setPC(true, m_pcFile
, m_pcLine
, DbgAddr(m_pcAddress
), m_pcFrame
);
138 return activateWindow(fw
, lineNo
, address
);
141 bool WinStack::activateWindow(SourceWindow
* fw
, int lineNo
, const DbgAddr
& address
)
143 // make the line visible
145 fw
->scrollTo(lineNo
, address
);
148 setCurrentWidget(fw
);
154 bool WinStack::activeLine(QString
& fileName
, int& lineNo
)
157 return activeLine(fileName
, lineNo
, dummy
);
160 bool WinStack::activeLine(QString
& fileName
, int& lineNo
, DbgAddr
& address
)
162 if (activeWindow() == 0) {
166 fileName
= activeFileName();
167 activeWindow()->activeLine(lineNo
, address
);
171 void WinStack::updateLineItems(const KDebugger
* dbg
)
173 for (int i
= count()-1; i
>= 0; i
--) {
174 windowAt(i
)->updateLineItems(dbg
);
178 void WinStack::updatePC(const QString
& fileName
, int lineNo
, const DbgAddr
& address
, int frameNo
)
181 setPC(false, m_pcFile
, m_pcLine
, DbgAddr(m_pcAddress
), m_pcFrame
);
185 m_pcAddress
= address
.asString();
188 setPC(true, fileName
, lineNo
, address
, frameNo
);
192 SourceWindow
* WinStack::findByFileName(const QString
& fileName
) const
194 for (int i
= count()-1; i
>= 0; i
--) {
195 if (windowAt(i
)->fileNameMatches(fileName
)) {
202 void WinStack::setPC(bool set
, const QString
& fileName
, int lineNo
,
203 const DbgAddr
& address
, int frameNo
)
205 TRACE((set
? "set PC: " : "clear PC: ") + fileName
+
206 QString().sprintf(":%d#%d ", lineNo
, frameNo
) + address
.asString());
207 SourceWindow
* fw
= findByFileName(fileName
);
209 fw
->setPC(set
, lineNo
, address
, frameNo
);
212 SourceWindow
* WinStack::windowAt(int i
) const
214 return static_cast<SourceWindow
*>(widget(i
));
217 SourceWindow
* WinStack::activeWindow() const
219 return static_cast<SourceWindow
*>(currentWidget());
222 QString
WinStack::activeFileName() const
225 if (activeWindow() != 0)
226 f
= activeWindow()->fileName();
230 void WinStack::slotFindForward()
232 if (activeWindow() != 0)
233 activeWindow()->find(m_findDlg
.searchText(), m_findDlg
.caseSensitive(),
234 SourceWindow::findForward
);
237 void WinStack::slotFindBackward()
239 if (activeWindow() != 0)
240 activeWindow()->find(m_findDlg
.searchText(), m_findDlg
.caseSensitive(),
241 SourceWindow::findBackward
);
244 bool WinStack::event(QEvent
* evt
)
246 if (evt
->type() != QEvent::ToolTip
)
247 return KTabWidget::event(evt
);
249 SourceWindow
* w
= activeWindow();
253 QPoint p
= static_cast<QHelpEvent
*>(evt
)->globalPos();
254 // get the word at the point
257 if (!w
->wordAtPoint(w
->mapFromGlobal(p
), word
, r
)) {
258 QToolTip::hideText();
263 assert(!word
.isEmpty());
266 // remember the location
268 m_tipRegion
= QRect(w
->mapTo(this, r
.topLeft()), r
.size());
270 emit
initiateValuePopup(word
);
274 void WinStack::slotShowValueTip(const QString
& tipText
)
276 QToolTip::showText(m_tipLocation
, tipText
, this, m_tipRegion
);
279 void WinStack::slotDisassembled(const QString
& fileName
, int lineNo
,
280 const std::list
<DisassembledCode
>& disass
)
282 SourceWindow
* fw
= findByFileName(fileName
);
288 fw
->disassembled(lineNo
, disass
);
291 void WinStack::slotExpandCollapse(int)
293 // update line items after expanding or collapsing disassembled code
295 // HACK: we know that this will result in updateLineItems
296 // should be done more cleanly with a separate signal
297 emit
newFileLoaded();
300 setPC(true, m_pcFile
, m_pcLine
, DbgAddr(m_pcAddress
), m_pcFrame
);
305 void WinStack::slotSetTabWidth(int numChars
)
307 m_tabWidth
= numChars
;
310 void WinStack::slotFileReload()
312 if (activeWindow() != 0) {
313 TRACE("reloading one file");
314 activeWindow()->reloadFile();
318 void WinStack::slotViewFind()
320 if (m_findDlg
.isVisible()) {
327 void WinStack::slotBrkptSet()
332 if (activeLine(file
, lineNo
, address
))
333 emit
toggleBreak(file
, lineNo
, address
, false);
336 void WinStack::slotBrkptSetTemp()
341 if (activeLine(file
, lineNo
, address
))
342 emit
toggleBreak(file
, lineNo
, address
, true);
345 void WinStack::slotBrkptEnable()
350 if (activeLine(file
, lineNo
, address
))
351 emit
enadisBreak(file
, lineNo
, address
);
354 void WinStack::slotMoveProgramCounter()
359 if (activeLine(file
, lineNo
, address
))
360 emit
moveProgramCounter(file
, lineNo
, address
);
363 void WinStack::slotClose()
365 QWidget
* w
= activeWindow();
374 FindDialog::FindDialog() :
378 m_buttonForward(this),
379 m_buttonBackward(this),
382 setWindowTitle(KGlobal::caption() + i18n(": Search"));
384 m_searchText
.setMinimumSize(330, 24);
385 m_searchText
.setMaxLength(10000);
386 m_searchText
.setFrame(true);
387 m_searchText
.setFocus();
389 m_caseCheck
.setText(i18n("&Case sensitive"));
390 m_caseCheck
.setChecked(true);
391 m_buttonForward
.setText(i18n("&Forward"));
392 m_buttonForward
.setDefault(true);
393 m_buttonBackward
.setText(i18n("&Backward"));
394 m_buttonClose
.setText(i18n("Close"));
396 connect(&m_buttonClose
, SIGNAL(clicked()), SLOT(reject()));
398 m_layout
.addWidget(&m_searchText
);
399 m_layout
.addWidget(&m_caseCheck
);
400 m_layout
.addLayout(&m_buttons
);
402 m_buttons
.addWidget(&m_buttonForward
);
403 m_buttons
.addWidget(&m_buttonBackward
);
404 m_buttons
.addWidget(&m_buttonClose
);
406 setLayout(&m_layout
);
409 FindDialog::~FindDialog()
413 void FindDialog::closeEvent(QCloseEvent
* ev
)
415 QDialog::closeEvent(ev
);
419 void FindDialog::done(int result
)
421 QDialog::done(result
);
425 #include "winstack.moc"