|
| 1 | +#include "captureareapage.h" |
| 2 | + |
| 3 | +#include <QFileDialog> |
| 4 | +#include <QLabel> |
| 5 | +#include <QLineEdit> |
| 6 | +#include <QPushButton> |
| 7 | +#include <QVBoxLayout> |
| 8 | +#include <appconfig.h> |
| 9 | + |
| 10 | +#include "hotkeymanager.h" |
| 11 | +#include "components/custom_keyseq_edit/singlestrokekeysequenceedit.h" |
| 12 | + |
| 13 | +bool CaptureAreaPage::validatePage() |
| 14 | +{ |
| 15 | + if(!field("command.area").isValid()) |
| 16 | + return false; |
| 17 | + AppConfig::setValue(CONFIG::COMMAND_SCREENSHOT, field("command.area").toString()); |
| 18 | + |
| 19 | + if(!field("keySequence.area").isValid()) |
| 20 | + return false; |
| 21 | + auto keyCombo = QKeySequence::fromString(field("keySequence.area").toString(), QKeySequence::NativeText); |
| 22 | + AppConfig::setValue(CONFIG::SHORTCUT_SCREENSHOT, keyCombo.toString(QKeySequence::PortableText)); |
| 23 | + HotkeyManager::updateHotkeys(); |
| 24 | + return true; |
| 25 | +} |
| 26 | + |
| 27 | +void CaptureAreaPage::initializePage() |
| 28 | +{ |
| 29 | + HotkeyManager::unregisterKey(HotkeyManager::ACTION_CAPTURE_AREA); |
| 30 | + QString captureAreaCommand = AppConfig::value(CONFIG::COMMAND_SCREENSHOT); |
| 31 | + if(!captureAreaCommand.isEmpty()) { |
| 32 | + setField("command.area", captureAreaCommand); |
| 33 | + captureAreaLine->setText(captureAreaCommand); |
| 34 | + } |
| 35 | + |
| 36 | + QString sequence = AppConfig::value(CONFIG::SHORTCUT_SCREENSHOT); |
| 37 | + if(!sequence.isEmpty()) { |
| 38 | + setField("keySequence.area", sequence); |
| 39 | + captureAreaKeySequenceEdit->setKeySequence(QKeySequence::fromString(sequence)); |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +void CaptureAreaPage::cleanupPage() |
| 44 | +{ |
| 45 | + HotkeyManager::updateHotkeys(); |
| 46 | +} |
| 47 | + |
| 48 | +CaptureAreaPage::CaptureAreaPage(QWidget *parent) |
| 49 | + : WizardPage{Page_CaptureArea, parent} |
| 50 | +{ |
| 51 | + auto f = font(); |
| 52 | + auto _lblTitleLabel = new QLabel(this); |
| 53 | + f.setPointSize(titleFont.first); |
| 54 | + f.setWeight(titleFont.second); |
| 55 | + _lblTitleLabel->setFont(f); |
| 56 | + _lblTitleLabel->setText(tr("Capture Area")); |
| 57 | + |
| 58 | + auto _lblSubtitle = new QLabel(this); |
| 59 | + f.setPointSize(subTitleFont.first); |
| 60 | + f.setWeight(subTitleFont.second); |
| 61 | + _lblSubtitle->setFont(f); |
| 62 | + _lblSubtitle->setWordWrap(true); |
| 63 | + _lblSubtitle->setText(tr("Set the capture area command and shortcut.")); |
| 64 | + |
| 65 | + auto _lblB1 = new QLabel(this); |
| 66 | + f.setPointSize(bodyFont.first); |
| 67 | + f.setWeight(bodyFont.second); |
| 68 | + _lblB1->setFont(f); |
| 69 | + _lblB1->setText(tr("<html><br><br>• Enter the command ashirt will use to capture area screenshots<br><br>• Enter a key combination that will trigger the capture area command<html>")); |
| 70 | + |
| 71 | + auto hLayout = new QHBoxLayout(); |
| 72 | + hLayout->addWidget(_lblB1, 0, Qt::AlignHCenter); |
| 73 | + |
| 74 | + auto _lblAKey = new QLabel(this); |
| 75 | + f.setPointSize(smallFont.first); |
| 76 | + f.setWeight(smallFont.second); |
| 77 | + _lblAKey->setFont(f); |
| 78 | + _lblAKey->setText(tr("Capture Area Command")); |
| 79 | + |
| 80 | + captureAreaLine = new QLineEdit(this); |
| 81 | + captureAreaLine->setTextMargins(3,0,3,0); |
| 82 | + registerField("command.area*", captureAreaLine); |
| 83 | + |
| 84 | + auto t1 = new QVBoxLayout(); |
| 85 | + t1->setSpacing(1); |
| 86 | + t1->addWidget(_lblAKey); |
| 87 | + t1->addWidget(captureAreaLine); |
| 88 | + |
| 89 | + auto _lblBKey = new QLabel(this); |
| 90 | + f.setPointSize(smallFont.first); |
| 91 | + f.setWeight(smallFont.second); |
| 92 | + _lblBKey->setFont(f); |
| 93 | + _lblBKey->setText(tr("Shortcut")); |
| 94 | + |
| 95 | + captureAreaKeySequenceEdit = new SingleStrokeKeySequenceEdit(this); |
| 96 | + registerField("keySequence.area*", captureAreaKeySequenceEdit, "keySequence", SIGNAL(keySequenceChanged(const QKeySequence &))); |
| 97 | + |
| 98 | + auto t2 = new QVBoxLayout(); |
| 99 | + t2->setSpacing(1); |
| 100 | + t2->addWidget(_lblBKey); |
| 101 | + t2->addWidget(captureAreaKeySequenceEdit); |
| 102 | + |
| 103 | + auto tLayout = new QHBoxLayout(); |
| 104 | + tLayout->addLayout(t1, 8); |
| 105 | + tLayout->addLayout(t2, 2); |
| 106 | + |
| 107 | + auto layout = new QVBoxLayout(); |
| 108 | + layout->addWidget(_lblTitleLabel); |
| 109 | + layout->addWidget(_lblSubtitle); |
| 110 | + layout->addLayout(hLayout); |
| 111 | + layout->addSpacerItem(new QSpacerItem(0,60,QSizePolicy::Minimum, QSizePolicy::Fixed)); |
| 112 | + layout->addLayout(tLayout); |
| 113 | + layout->addSpacerItem(new QSpacerItem(0,0,QSizePolicy::Minimum, QSizePolicy::Expanding)); |
| 114 | + setLayout(layout); |
| 115 | +} |
0 commit comments