HAL  v4.5.0-136-gbce33ee73
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
comment_item.cpp
Go to the documentation of this file.
5 #include "gui/gui_globals.h"
7 
8 #include <QToolBar>
9 #include <QVBoxLayout>
10 #include <QHBoxLayout>
11 #include <QLabel>
12 #include <QAction>
13 #include <QToolButton>
14 #include <QDebug>
15 #include "gui/gui_utils/graphics.h"
16 #if QT_VERSION >= QT_VERSION_CHECK(5,13,0)
17  #include <QRegularExpression>
18 #else
19  #include <QRegExp>
20 #endif
21 
22 namespace hal
23 {
25  {
26  init();
27  }
28 
30  {
31  init();
32  mEntry = entry;
34  }
35 
37  {
38  }
39 
41  {
42  mEntry = entry;
44  }
45 
47  {
48  if(!mEntry) return;
49  mHeader->setText(mEntry->getHeader());
50  mCreationDate->setText(" " + mEntry->getLastModifiedTime().toLocalTime().toString(mEntry->getDateFormatString()));
51  mTextEdit->setHtml(mEntry->getText());
52  //setFixedHeight(mTopWidget->height()+mText->height());
53  }
54 
55  bool CommentItem::search(const QString &string, SearchOptions searchOpts)
56  {
57  mHeader->handleSearchChanged(string,searchOpts.toInt());
58  if (string.isEmpty())
59  {
61  // reset find marker
62  mTextEdit->moveCursor(QTextCursor::Start);
63  return false;
64  }
65  bool found = mHeader->hasMatch();
66  QList<QTextEdit::ExtraSelection> extraSelections;
67 
68  mTextEdit->moveCursor(QTextCursor::Start);
69  QColor color = QColor(12, 15, 19);
70  QColor mBackgroundColor = QColor(255, 255, 0);
71 
73  options.setFlag(QTextDocument::FindCaseSensitively, searchOpts.isCaseSensitive());
74  options.setFlag(QTextDocument::FindWholeWords, searchOpts.isExactMatch());
75  qInfo() << "search in commets";
76  if(searchOpts.isRegularExpression())
77  {
78  qInfo() << "is regex";
79 #if QT_VERSION >= QT_VERSION_CHECK(5,13,0)
81 #else
82  QRegExp regExp(string, searchOpts.isCaseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive);
83 #endif
84 
85  while (mTextEdit->find(regExp, options))
86  {
87  found = true; // just return if something is found, position doesnt matter
88  QTextCursor cur = mTextEdit->textCursor();
89  if (cur.anchor() == cur.position()) // zero-length match
90  {
92  break; // end of document reached
93  mTextEdit->setTextCursor(cur);
94  continue;
95  }
96 
98  extra.format.setForeground(QBrush(color));
99  extra.format.setBackground(mBackgroundColor);
100  extra.cursor = cur;
101  extraSelections.append(extra);
102  }
103  }
104  else
105  {
106  while (mTextEdit->find(string, options))
107  {
108 
109  qInfo() << "found";
110  found = true; // just return if something is found, position doesnt matter
112  extra.format.setForeground(QBrush(color));
113  extra.format.setBackground(mBackgroundColor);
114  extra.cursor = mTextEdit->textCursor();
115  extraSelections.append(extra);
116  }
117  }
118  mTextEdit->setExtraSelections(extraSelections);
119  return found;
120  }
121 
123  {
124  return mEntry;
125  }
126 
127  void CommentItem::init()
128  {
129  // extract property information
130  style()->unpolish(this);
131  style()->polish(this);
132  QSize iconSize(20, 20);
133 
134  mEntry = nullptr;
135  // TODO: replace fixed sizes (put them in stylesheet / compute them?)
136  mLayout = new QVBoxLayout(this);
137  mLayout->setSpacing(0);
138  QtCompat::setMarginWidth(mLayout,0);
139 
140  // top part
141  mTopWidget = new QWidget(this);
142  mTopWidget->setFixedHeight(iconSize.height()+5); // just some spacing
143  mTopLayout = new QHBoxLayout(mTopWidget);
144  mTopLayout->setSpacing(0);
145  QtCompat::setMarginWidth(mTopLayout,0);
146 
147  mHeader = new SearchableLabel(this);
148  mHeader->setStyleSheet("font-weight: bold;");
149  mCreationDate = new QLabel(this);
150  mCreationDate->setStyleSheet("font-size: 12px;");
151  mModifyButton = new QToolButton(this);
152  mModifyButton->setIcon(gui_utility::getStyledSvgIcon(mModifyCommentIconStyle, mModifyCommentIconPath));
153  mModifyButton->setIconSize(iconSize);
154  mModifyButton->setAutoRaise(true);
155  mDeleteButton = new QToolButton(this);
156  mDeleteButton->setIcon(gui_utility::getStyledSvgIcon(mDeleteCommentIconStyle, mDeleteCommentIconPath));
157  mDeleteButton->setIconSize(iconSize);
158  mDeleteButton->setAutoRaise(true);
159 
160  //perhaps with alignments (header left, date normal, small spacer, fixed buttons without stretch)?
161  mTopLayout->addWidget(mHeader);
162  mTopLayout->addWidget(mCreationDate);
163  mTopLayout->addWidget(mModifyButton);
164  mTopLayout->addWidget(mDeleteButton);
166 
167  // actual comment
168  mTextEdit = new QTextEdit(this);
169  mTextEdit->setReadOnly(true);
170 
171  mLayout->addWidget(mTopWidget);
172  //mLayout->addWidget(mText);
173  mLayout->addWidget(mTextEdit);
174  mLayout->addStretch();
175 
176  // connections / logic
177  connect(mDeleteButton, &QAbstractButton::clicked, this, &CommentItem::handleDeleteButtonTriggered);
178  connect(mModifyButton, &QAbstractButton::clicked, this, &CommentItem::handleModifyButtonTriggered);
179  }
180 
181  void CommentItem::handleDeleteButtonTriggered()
182  {
183  Q_EMIT delete_requested(this);
184  }
185 
186  void CommentItem::handleModifyButtonTriggered()
187  {
188  CommentDialog dialog("Modify Comment", mEntry);
189  if(dialog.exec() == QDialog::Accepted)
190  {
191  mEntry->setHeader(dialog.getHeader());
192  mEntry->setText(dialog.getText());
193  // relay modification through manager, let comment-widget call this function
194  // updateCurrentEntry();
196  }
197 
198  dialog.close();
199  }
200 }
The CommentEntry class encapsulated information related to a comment.
Definition: comment_entry.h:43
QDateTime getLastModifiedTime() const
QString getHeader() const
QString getText() const
void setText(QString newText)
QString getDateFormatString() const
void setHeader(QString newHeader)
void setComment(CommentEntry *entry)
void delete_requested(CommentItem *item)
bool search(const QString &string, SearchOptions searchOpts)
CommentItem(QWidget *parent=nullptr)
CommentEntry * getEntry()
void updateCurrentEntry()
void relayEntryModified(CommentEntry *entry)
bool isExactMatch() const
bool isCaseSensitive() const
bool isRegularExpression() const
void handleSearchChanged(const QString &string, int option)
void setMarginWidth(QLayout *layout, int marginWidth)
QIcon getStyledSvgIcon(const QString &from_to_colors_enabled, const QString &svg_path, QString from_to_colors_disabled=QString())
Definition: graphics.cpp:60
Definition: defines.h:45
CommentManager * gCommentManager
Definition: plugin_gui.cpp:88
void clicked(bool checked)
void setIcon(const QIcon &icon)
void setIconSize(const QSize &size)
void addStretch(int stretch)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void setSpacing(int spacing)
QDateTime toLocalTime() const const
QString toString(Qt::DateFormat format) const const
void setText(const QString &)
void append(const T &value)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
virtual void polish(QWidget *widget)
virtual void unpolish(QWidget *widget)
CaseSensitive
int anchor() const const
bool movePosition(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode, int n)
int position() const const
typedef FindFlags
bool find(const QString &exp, QTextDocument::FindFlags options)
void setHtml(const QString &text)
void moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode)
void setReadOnly(bool ro)
void setExtraSelections(const QList< QTextEdit::ExtraSelection > &selections)
void setTextCursor(const QTextCursor &cursor)
QTextCursor textCursor() const const
void setAutoRaise(bool enable)
QWidget(QWidget *parent, Qt::WindowFlags f)
void setFixedHeight(int h)
void setSizePolicy(QSizePolicy)
QStyle * style() const const
void setStyleSheet(const QString &styleSheet)