Textractor_test/GUI/attachprocessdialog.cpp

40 lines
1.4 KiB
C++
Raw Normal View History

2021-06-05 16:29:51 -06:00
#include "attachprocessdialog.h"
#include <QtWinExtras/QtWin>
extern const char* SELECT_PROCESS;
extern const char* ATTACH_INFO;
2022-01-29 12:49:48 -07:00
AttachProcessDialog::AttachProcessDialog(QWidget* parent, std::vector<std::pair<QString, HICON>> processIcons) :
2021-06-05 16:29:51 -06:00
QDialog(parent, Qt::WindowCloseButtonHint),
model(this)
{
ui.setupUi(this);
setWindowTitle(SELECT_PROCESS);
ui.label->setText(ATTACH_INFO);
ui.processList->setModel(&model);
QPixmap transparent(100, 100);
transparent.fill(QColor::fromRgba(0));
for (const auto& [process, icon] : processIcons)
{
auto item = new QStandardItem(icon ? QIcon(QtWin::fromHICON(icon)) : transparent, process);
item->setEditable(false);
model.appendRow(item);
}
connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
2022-01-29 12:49:48 -07:00
connect(ui.processList, &QListView::clicked, [this](QModelIndex index) { ui.processEdit->setText(model.item(index.row())->text()); });
connect(ui.processList, &QListView::doubleClicked, this, &QDialog::accept);
connect(ui.processEdit, &QLineEdit::textEdited, [this](QString process)
2021-06-05 16:29:51 -06:00
{
2022-01-29 12:49:48 -07:00
for (int i = 0; i < model.rowCount(); ++i) ui.processList->setRowHidden(i, !model.item(i)->text().contains(process, Qt::CaseInsensitive));
2021-06-05 16:29:51 -06:00
});
2022-01-29 12:49:48 -07:00
connect(ui.processEdit, &QLineEdit::returnPressed, this, &QDialog::accept);
2021-06-05 16:29:51 -06:00
}
QString AttachProcessDialog::SelectedProcess()
{
2022-01-29 12:49:48 -07:00
return ui.processEdit->text();
2021-06-05 16:29:51 -06:00
}