diff --git a/trunk/registrykeytable.cpp b/trunk/registrykeytable.cpp index d8c3886..d028496 100644 --- a/trunk/registrykeytable.cpp +++ b/trunk/registrykeytable.cpp @@ -1,149 +1,146 @@ /******************************************************************************* * fred Copyright (c) 2011-2013 by Gillen Daniel * * * * Forensic Registry EDitor (fred) is a cross-platform M$ registry hive editor * * with special feautures useful during forensic analysis. * * * * This program is free software: you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the Free * * Software Foundation, either version 3 of the License, or (at your option) * * any later version. * * * * This program is distributed in the hope that it will be useful, but WITHOUT * * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * * more details. * * * * You should have received a copy of the GNU General Public License along with * * this program. If not, see . * *******************************************************************************/ #include "registrykeytable.h" #include #include #include RegistryKeyTable::RegistryKeyTable(QWidget *p_parent) : QTableView(p_parent) { // Configure widget this->setSelectionMode(QAbstractItemView::SingleSelection); this->setSelectionBehavior(QAbstractItemView::SelectRows); this->setAutoScroll(false); this->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); this->verticalHeader()->setHidden(true); this->setTextElideMode(Qt::ElideNone); // Create context menu this->p_menu_copy=new QMenu(tr("Copy"),this); this->p_action_copy_key_name=new QAction(tr("Key name"), this->p_menu_copy); this->p_menu_copy->addAction(this->p_action_copy_key_name); this->connect(this->p_action_copy_key_name, SIGNAL(triggered()), this, SLOT(SlotCopyKeyName())); this->p_action_copy_key_value=new QAction(tr("Key value"), this->p_menu_copy); this->p_menu_copy->addAction(this->p_action_copy_key_value); this->connect(this->p_action_copy_key_value, SIGNAL(triggered()), this, SLOT(SlotCopyKeyValue())); } RegistryKeyTable::~RegistryKeyTable() { // Delete context menu delete this->p_action_copy_key_name; delete this->p_action_copy_key_value; delete this->p_menu_copy; } void RegistryKeyTable::setModel(QAbstractItemModel *p_model) { QTableView::setModel(p_model); // Resize table rows / columns to fit data this->resizeColumnsToContents(); this->resizeRowsToContents(); this->horizontalHeader()->stretchLastSection(); if(p_model!=NULL && p_model->rowCount()>0) { // Select first table item this->selectRow(0); } } /* void RegistryKeyTable::selectRow(QString key_name) { int i; this->clearSelection(); for(i=0;imodel()->rowCount();i++) { if(this->model()) } } */ int RegistryKeyTable::sizeHintForColumn(int column) const { int size_hint=-1; int i=0; int item_width=0; QFontMetrics fm(this->fontMetrics()); QModelIndex idx; if(this->model()==NULL) return -1; // Find string that needs the most amount of space idx=this->model()->index(i,column); while(idx.isValid()) { item_width=fm.width(this->model()->data(idx).toString())+10; if(item_width>size_hint) size_hint=item_width; idx=this->model()->index(++i,column); } - // Qt seems to be very unhappy with size hints bigger then 30000. - if(size_hint>30000) size_hint=30000; - return size_hint; } void RegistryKeyTable::contextMenuEvent(QContextMenuEvent *p_event) { // Only show context menu when a row is selected if(this->selectedIndexes().count()!=4) return; // Only show context menu when user clicked on selected row if(!(this->indexAt(p_event->pos())==this->selectedIndexes().at(0) || this->indexAt(p_event->pos())==this->selectedIndexes().at(1) || this->indexAt(p_event->pos())==this->selectedIndexes().at(2) || this->indexAt(p_event->pos())==this->selectedIndexes().at(3))) { return; } // Emit a click signal emit(this->clicked(this->indexAt(p_event->pos()))); // Create context menu and add actions QMenu context_menu(this); context_menu.addMenu(this->p_menu_copy); context_menu.exec(p_event->globalPos()); } void RegistryKeyTable::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) { // Call parent class's currentChanged first QTableView::currentChanged(current,previous); // Now emit our signal QModelIndex current_item=QModelIndex(current); emit(RegistryKeyTable::CurrentItemChanged(current_item)); } void RegistryKeyTable::SlotCopyKeyName() { QApplication::clipboard()-> setText(this->selectedIndexes().at(0).data().toString(), QClipboard::Clipboard); } void RegistryKeyTable::SlotCopyKeyValue() { QApplication::clipboard()-> setText(this->selectedIndexes().at(2).data().toString(), QClipboard::Clipboard); } diff --git a/trunk/registrynodetree.cpp b/trunk/registrynodetree.cpp index bb3c138..8d0e8b3 100644 --- a/trunk/registrynodetree.cpp +++ b/trunk/registrynodetree.cpp @@ -1,146 +1,132 @@ /******************************************************************************* * fred Copyright (c) 2011-2013 by Gillen Daniel * * * * Forensic Registry EDitor (fred) is a cross-platform M$ registry hive editor * * with special feautures useful during forensic analysis. * * * * This program is free software: you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the Free * * Software Foundation, either version 3 of the License, or (at your option) * * any later version. * * * * This program is distributed in the hope that it will be useful, but WITHOUT * * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * * more details. * * * * You should have received a copy of the GNU General Public License along with * * this program. If not, see . * *******************************************************************************/ #include "registrynodetree.h" #include "registrynodetreemodel.h" #include #include #include RegistryNodeTree::RegistryNodeTree(QWidget *p_parent) : QTreeView(p_parent) { // Configure widget this->setTextElideMode(Qt::ElideNone); this->sortByColumn(0,Qt::AscendingOrder); this->setSortingEnabled(true); - // Create proxy model -// this->p_model_proxy=new RegistryNodeTreeModelProxy(this); -// this->p_model_proxy->setDynamicSortFilter(true); - // Create context menu this->p_menu_copy=new QMenu(tr("Copy"),this); this->p_action_copy_node_name=new QAction(tr("Node name"), this->p_menu_copy); this->p_menu_copy->addAction(this->p_action_copy_node_name); this->connect(this->p_action_copy_node_name, SIGNAL(triggered()), this, SLOT(SlotCopyNodeName())); this->p_action_copy_node_path=new QAction(tr("Node path"), this->p_menu_copy); this->p_menu_copy->addAction(this->p_action_copy_node_path); this->connect(this->p_action_copy_node_path, SIGNAL(triggered()), this, SLOT(SlotCopyNodePath())); } RegistryNodeTree::~RegistryNodeTree() { - // Delete our proxy model -// delete this->p_model_proxy; // Delete context menu delete this->p_action_copy_node_name; delete this->p_action_copy_node_path; delete this->p_menu_copy; } void RegistryNodeTree::setModel(QAbstractItemModel *p_model) { - // Assign model to our proxy model -// this->p_model_proxy->setSourceModel(p_model); - // Then assign proxy as our own model -// QTreeView::setModel(this->p_model_proxy); + // Assign model to view QTreeView::setModel(p_model); this->header()->setResizeMode(0,QHeaderView::ResizeToContents); this->header()->setStretchLastSection(false); if(p_model!=NULL && p_model->index(0,0).isValid()) { // Select first tree item this->setCurrentIndex(p_model->index(0,0)); } } -/* -QModelIndex RegistryNodeTree::MapIndexToModel(const QModelIndex &index) { - if(this->p_model_proxy==NULL) return QModelIndex(); - else return this->p_model_proxy->mapToSource(index); -} -*/ + void RegistryNodeTree::contextMenuEvent(QContextMenuEvent *p_event) { // Only show context menu when a node is selected if(this->selectedIndexes().count()!=1) return; // Only show context menu when user clicked on selected row if(this->indexAt(p_event->pos())!=this->selectedIndexes().at(0)) return; // Emit a click signal emit(this->clicked(this->indexAt(p_event->pos()))); // Create context menu and add actions QMenu context_menu(this); context_menu.addMenu(this->p_menu_copy); context_menu.exec(p_event->globalPos()); } void RegistryNodeTree::keyPressEvent(QKeyEvent *p_event) { // Only react if a node is selected and user pressed Key_Left if(this->selectedIndexes().count()==1 && p_event->key()==Qt::Key_Left) { QModelIndex cur_index=this->selectedIndexes().at(0); if(this->model()->hasChildren(cur_index) && this->isExpanded(cur_index)) { // Current node is expanded. Only collapse this one this->collapse(cur_index); return; } if(!cur_index.parent().isValid()) { // Do no try to collapse anything above root node return; } this->collapse(cur_index.parent()); this->setCurrentIndex(cur_index.parent()); return; } // If we didn't handle the key event, let our parent handle it QTreeView::keyPressEvent(p_event); } void RegistryNodeTree::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) { // Call parent class's currentChanged first QTreeView::currentChanged(current,previous); // Now emit our signal QModelIndex current_item=QModelIndex(current); emit(RegistryNodeTree::CurrentItemChanged(current_item)); } void RegistryNodeTree::SlotCopyNodeName() { QApplication::clipboard()-> setText(this->selectedIndexes().at(0).data().toString(), QClipboard::Clipboard); } void RegistryNodeTree::SlotCopyNodePath() { QString path=((RegistryNodeTreeModel*)(this->model()))-> GetNodePath(this->selectedIndexes().at(0)); QApplication::clipboard()->setText(path,QClipboard::Clipboard); } diff --git a/trunk/registrynodetree.h b/trunk/registrynodetree.h index cd85fb3..216f016 100644 --- a/trunk/registrynodetree.h +++ b/trunk/registrynodetree.h @@ -1,63 +1,59 @@ /******************************************************************************* * fred Copyright (c) 2011-2013 by Gillen Daniel * * * * Forensic Registry EDitor (fred) is a cross-platform M$ registry hive editor * * with special feautures useful during forensic analysis. * * * * This program is free software: you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the Free * * Software Foundation, either version 3 of the License, or (at your option) * * any later version. * * * * This program is distributed in the hope that it will be useful, but WITHOUT * * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * * more details. * * * * You should have received a copy of the GNU General Public License along with * * this program. If not, see . * *******************************************************************************/ #ifndef REGISTRYNODETREE_H #define REGISTRYNODETREE_H #include #include #include #include #include -#include "registrynodetreemodelproxy.h" - class RegistryNodeTree : public QTreeView { Q_OBJECT public: RegistryNodeTree(QWidget *p_parent=0); ~RegistryNodeTree(); void setModel(QAbstractItemModel *p_model); - QModelIndex MapIndexToModel(const QModelIndex &index); Q_SIGNALS: void CurrentItemChanged(QModelIndex current); protected: // int sizeHintForColumn(int column) const; void contextMenuEvent(QContextMenuEvent *p_event); void keyPressEvent(QKeyEvent *p_event); private: - RegistryNodeTreeModelProxy *p_model_proxy; QMenu *p_menu_copy; QAction *p_action_copy_node_name; QAction *p_action_copy_node_path; void currentChanged(const QModelIndex ¤t, const QModelIndex &previous); private slots: void SlotCopyNodeName(); void SlotCopyNodePath(); }; #endif // REGISTRYNODETREE_H diff --git a/trunk/searchresultwidget.cpp b/trunk/searchresultwidget.cpp index 45ddbcc..0607165 100644 --- a/trunk/searchresultwidget.cpp +++ b/trunk/searchresultwidget.cpp @@ -1,133 +1,124 @@ /******************************************************************************* * fred Copyright (c) 2011-2013 by Gillen Daniel * * * * Forensic Registry EDitor (fred) is a cross-platform M$ registry hive editor * * with special feautures useful during forensic analysis. * * * * This program is free software: you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the Free * * Software Foundation, either version 3 of the License, or (at your option) * * any later version. * * * * This program is distributed in the hope that it will be useful, but WITHOUT * * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * * more details. * * * * You should have received a copy of the GNU General Public License along with * * this program. If not, see . * *******************************************************************************/ #include "searchresultwidget.h" #include #include #include #include #include //#include SearchResultWidget::SearchResultWidget(QWidget *p_parent) : QTableWidget(p_parent) { // Create our delegate instance this->p_delegate=new SearchResultTableDelegate(); this->setItemDelegate(this->p_delegate); this->setColumnCount(3); this->setRowCount(0); this->setTextElideMode(Qt::ElideNone); this->verticalHeader()->setHidden(true); this->setSelectionBehavior(QAbstractItemView::SelectRows); this->setSelectionMode(QAbstractItemView::SingleSelection); this->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); this->setHorizontalHeaderLabels(QStringList()<p_delegate; } void SearchResultWidget::SlotFoundMatch(ThreadSearch::eMatchType match_type, QString path, QString key, QString value) { QTableWidgetItem *p_item; // QTextEdit* p_te; QString full_path; QString type; QString match; switch(match_type) { case ThreadSearch::eMatchType_NodeName: type=tr("Node name"); full_path=path; match=key; break; case ThreadSearch::eMatchType_KeyName: type=tr("Key name"); full_path=path; match=key; break; case ThreadSearch::eMatchType_KeyValue: type=tr("Key value"); full_path=path+"\\"+key; //if(value.length()<6934) match=value; //else //match=value.left(5610); //match=QString(value); match=value; break; } int rows=this->rowCount(); this->setRowCount(rows+1); // TODO: Use setCellWidget to add QTextEdit and then use insertText and // insertHtml to format match p_item=new QTableWidgetItem(full_path=="" ? "\\" : full_path); p_item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); this->setItem(rows,0,p_item); p_item=new QTableWidgetItem(type); p_item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); this->setItem(rows,1,p_item); p_item=new QTableWidgetItem(match); p_item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); this->setItem(rows,2,p_item); // p_te=new QTextEdit(match); // p_te->setReadOnly(true); // this->setCellWidget(rows,2,p_te); } int SearchResultWidget::sizeHintForColumn(int column) const { int size_hint=0; int i=0; int item_width=0; QFontMetrics fm(this->fontMetrics()); // if(column<0 || column>=this->columnCount()) return -1; // Find string that needs the most amount of space for(i=0;irowCount();i++) { -// if(column!=2) { item_width=fm.width(this->item(i,column)->text())+10; - //item_width=this->item(i,column)->sizeHint().width(); -// } else { -// // Column 2 has special cell widgets -// item_width=fm.width(((QTextEdit*)(this->cellWidget(i,column)))->toPlainText())+10; -// } if(item_width>size_hint) size_hint=item_width; } - // Qt seems to be very unhappy with size hints bigger then 30000. -// if(size_hint>30000) size_hint=30000; - return size_hint; } void SearchResultWidget::SlotSearchFinished() { this->resizeColumnsToContents(); this->resizeRowsToContents(); }