Add editing/renaming and delete key to live connection window

This commit is contained in:
baldurk
2017-06-12 17:46:49 +01:00
parent b59f03c198
commit c1fb2bb020
3 changed files with 65 additions and 10 deletions
+55 -5
View File
@@ -24,10 +24,12 @@
#include "LiveCapture.h"
#include <QMenu>
#include <QMetaProperty>
#include <QMouseEvent>
#include <QPainter>
#include <QProcess>
#include <QScrollBar>
#include <QStyledItemDelegate>
#include <QToolBar>
#include <QToolButton>
#include "3rdparty/toolwindowmanager/ToolWindowManager.h"
@@ -41,6 +43,41 @@ static const int PIDRole = Qt::UserRole + 1;
static const int IdentRole = Qt::UserRole + 2;
static const int LogPtrRole = Qt::UserRole + 3;
class NameEditOnlyDelegate : public QStyledItemDelegate
{
public:
LiveCapture *live;
NameEditOnlyDelegate(LiveCapture *l) : live(l) {}
void setEditorData(QWidget *editor, const QModelIndex &index) const override
{
QByteArray n = editor->metaObject()->userProperty().name();
QListWidgetItem *item = live->ui->captures->item(index.row());
if(!n.isEmpty() && item)
{
LiveCapture::CaptureLog *log = live->GetLog(item);
if(log)
editor->setProperty(n, log->name);
}
}
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
{
QByteArray n = editor->metaObject()->userProperty().name();
QListWidgetItem *item = live->ui->captures->item(index.row());
if(!n.isEmpty() && item)
{
LiveCapture::CaptureLog *log = live->GetLog(item);
if(log)
{
log->name = editor->property(n).toString();
item->setText(live->MakeText(log));
}
}
}
};
LiveCapture::LiveCapture(ICaptureContext &ctx, const QString &hostname, uint32_t ident,
MainWindow *main, QWidget *parent)
: QFrame(parent),
@@ -77,6 +114,8 @@ LiveCapture::LiveCapture(ICaptureContext &ctx, const QString &hostname, uint32_t
ui->connectionStatus->setText(tr("Connecting.."));
ui->connectionIcon->setPixmap(Pixmaps::hourglass());
ui->captures->setItemDelegate(new NameEditOnlyDelegate(this));
{
QToolBar *bottomTools = new QToolBar(this);
@@ -116,6 +155,8 @@ LiveCapture::LiveCapture(ICaptureContext &ctx, const QString &hostname, uint32_t
QObject::connect(saveAction, &QAction::triggered, this, &LiveCapture::saveCapture_triggered);
QObject::connect(deleteAction, &QAction::triggered, this, &LiveCapture::deleteCapture_triggered);
QObject::connect(ui->captures, &RDListWidget::keyPress, this, &LiveCapture::captures_keyPress);
ui->mainLayout->addWidget(bottomTools);
bottomTools->setStyleSheet(
@@ -253,7 +294,7 @@ void LiveCapture::openNewWindow_triggered()
{
CaptureLog *log = GetLog(ui->captures->selectedItems()[0]);
QString temppath = m_Ctx.TempLogFilename(log->exe);
QString temppath = m_Ctx.TempLogFilename(lit("newwindow"));
if(!log->local)
{
@@ -523,7 +564,7 @@ bool LiveCapture::checkAllowDelete()
QString LiveCapture::MakeText(CaptureLog *log)
{
QString text = log->exe;
QString text = log->name;
if(!log->local)
text += tr(" (Remote)");
@@ -557,8 +598,8 @@ bool LiveCapture::checkAllowClose()
if(!suppressRemoteWarning)
{
res = RDDialog::question(this, tr("Unsaved log"),
tr("Save this logfile from %1 at %2?")
.arg(log->exe)
tr("Save this logfile '%1' at %2?")
.arg(log->name)
.arg(log->timestamp.toString(lit("HH:mm:ss"))),
RDDialog::YesNoCancel);
}
@@ -762,6 +803,14 @@ void LiveCapture::on_previewSplit_splitterMoved(int pos, int index)
m_IgnorePreviewToggle = false;
}
void LiveCapture::captures_keyPress(QKeyEvent *e)
{
if(e->key() == Qt::Key_Delete)
{
deleteCapture_triggered();
}
}
void LiveCapture::preview_mouseClick(QMouseEvent *e)
{
QPoint mouse = QCursor::pos();
@@ -847,7 +896,7 @@ void LiveCapture::captureAdded(uint32_t ID, const QString &executable, const QSt
{
CaptureLog *log = new CaptureLog();
log->remoteID = ID;
log->exe = executable;
log->name = executable;
log->api = api;
log->timestamp = timestamp;
log->thumb = QImage(thumbnail.elems, thumbWidth, thumbHeight, QImage::Format_RGB888)
@@ -857,6 +906,7 @@ void LiveCapture::captureAdded(uint32_t ID, const QString &executable, const QSt
log->local = local;
QListWidgetItem *item = new QListWidgetItem();
item->setFlags(item->flags() | Qt::ItemIsEditable);
item->setText(MakeText(log));
item->setIcon(QIcon(QPixmap::fromImage(MakeThumb(log->thumb))));
if(!local)
+9 -4
View File
@@ -41,6 +41,8 @@ class QToolButton;
class QListWidgetItem;
class RDLabel;
class MainWindow;
class QKeyEvent;
class NameEditOnlyDelegate;
class LiveCapture : public QFrame
{
@@ -56,6 +58,9 @@ public:
const QString &hostname() { return m_Hostname; }
void cleanItems();
public slots:
bool checkAllowClose();
private slots:
void on_captures_itemSelectionChanged();
void on_captures_mouseClicked(QMouseEvent *e);
@@ -66,10 +71,8 @@ private slots:
void on_previewSplit_splitterMoved(int pos, int index);
// manual slots
public slots:
bool checkAllowClose();
void captures_keyPress(QKeyEvent *e);
private slots:
void childUpdate();
void captureCountdownTick();
@@ -85,10 +88,12 @@ private slots:
private:
void showEvent(QShowEvent *event) override;
friend class NameEditOnlyDelegate;
struct CaptureLog
{
uint32_t remoteID;
QString exe;
QString name;
QString api;
QDateTime timestamp;
+1 -1
View File
@@ -321,7 +321,7 @@
<item>
<widget class="RDListWidget" name="captures">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
<set>QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>