"Fossies" - the Fresh Open Source Software Archive

Member "cutter-1.10.3/src/dialogs/CommentsDialog.cpp" (8 May 2020, 1992 Bytes) of package /linux/privat/cutter-1.10.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "CommentsDialog.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.10.2_vs_1.10.3.

    1 #include "CommentsDialog.h"
    2 #include "ui_CommentsDialog.h"
    3 
    4 #include "core/Cutter.h"
    5 
    6 CommentsDialog::CommentsDialog(QWidget *parent) :
    7     QDialog(parent),
    8     ui(new Ui::CommentsDialog)
    9 {
   10     ui->setupUi(this);
   11     setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
   12 
   13     // Event filter for capturing Ctrl/Cmd+Return
   14     ui->textEdit->installEventFilter(this);
   15 }
   16 
   17 CommentsDialog::~CommentsDialog() {}
   18 
   19 void CommentsDialog::on_buttonBox_accepted()
   20 {
   21 }
   22 
   23 void CommentsDialog::on_buttonBox_rejected()
   24 {
   25     close();
   26 }
   27 
   28 QString CommentsDialog::getComment()
   29 {
   30     QString ret = ui->textEdit->document()->toPlainText();
   31     return ret;
   32 }
   33 
   34 void CommentsDialog::setComment(const QString &comment)
   35 {
   36     ui->textEdit->document()->setPlainText(comment);
   37 }
   38 
   39 void CommentsDialog::addOrEditComment(RVA offset, QWidget *parent)
   40 {
   41     QString oldComment = Core()->cmdRawAt("CC.", offset);
   42     // Remove newline at the end added by cmd
   43     oldComment.remove(oldComment.length() - 1, 1);
   44     CommentsDialog c(parent);
   45 
   46     if (oldComment.isNull() || oldComment.isEmpty()) {
   47         c.setWindowTitle(tr("Add Comment at %1").arg(RAddressString(offset)));
   48     } else {
   49         c.setWindowTitle(tr("Edit Comment at %1").arg(RAddressString(offset)));
   50     }
   51 
   52     c.setComment(oldComment);
   53     if (c.exec()) {
   54         QString comment = c.getComment();
   55         if (comment.isEmpty()) {
   56             Core()->delComment(offset);
   57         } else {
   58             Core()->setComment(offset, comment);
   59         }
   60     }
   61 }
   62 
   63 bool CommentsDialog::eventFilter(QObject */*obj*/, QEvent *event)
   64 {
   65     if (event -> type() == QEvent::KeyPress) {
   66         QKeyEvent *keyEvent = static_cast <QKeyEvent *> (event);
   67 
   68         // Confirm comment by pressing Ctrl/Cmd+Return
   69         if ((keyEvent -> modifiers() & Qt::ControlModifier) &&
   70                 ((keyEvent -> key() == Qt::Key_Enter) || (keyEvent -> key() == Qt::Key_Return))) {
   71             this->accept();
   72             return true;
   73         }
   74     }
   75 
   76     return false;
   77 }