HAL
comment_dialog.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4 // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 
24 #pragma once
25 
26 #include <QDialog>
27 #include <QVBoxLayout>
28 #include <QHBoxLayout>
29 
30 class QLineEdit;
31 class QTextEdit;
32 class QLabel;
33 class QToolBar;
34 class QAction;
35 class QTextCharFormat;
36 
37 namespace hal
38 {
39  class CommentEntry;
40  class CommentDialog : public QDialog
41  {
42  Q_OBJECT
47  public:
48  // Perhaps remove the title-parameter and determine "New comment" and "Modify comment"
49  // through the item parameter (or perhaps 2 constructors?)
58  CommentDialog(const QString windowTitle, CommentEntry* entry = nullptr, QWidget* parent = nullptr);
60 
61  // Getter for the header and textfield if the dialog returns accapted?
62  // (Or direct interaction with the manager?)
63 
71 
78  QString getText();
79 
80  //property tests
81  QString redColor(){return mRedColor;}
82  void setRedColor(const QString& str){mRedColor = str;}
83  QString yellowColor(){return mYellowColor;}
84  void setYellowColor(const QString & str){mYellowColor = str;}
85  QString greenColor(){return mGreenColor;}
86  void setGreenColor(const QString& str){mGreenColor = str;}
87  QString defaultColor(){return mDefaultColor;}
88  void setDefaultColor(const QString& str){mDefaultColor = str;}
89 
90  private:
91  QVBoxLayout* mLayout;
92  CommentEntry* mCommentEntry;
93  QFont mDefaultFont;
94 
95  QString mRedColor;
96  QString mYellowColor;
97  QString mGreenColor;
98  QString mDefaultColor;
99 
100  // header part
101  QWidget* mHeaderContainer; // for custom margins/spacing on top as well as colored background
102  QHBoxLayout* mHeaderContainerLayout;
103  QLineEdit* mHeaderEdit;
104  QLabel* mLastModifiedLabel;
105 
106  // toolbar (Or container widget for Toolbuttons?)
107  QToolBar* mToolBar;
108  QAction* mBoldAction;
109  QAction* mItalicsAction;
110  QAction* mUnderscoreAction;
111  QAction* mColorAction; // additional widget/indicatior to show current color?
112  QAction* mListAction;
113  QAction* mCodeAction;
114 
115  // textfield
116  QTextEdit* mTextEdit;
117 
118  // helper functions
119  void init();
120  void mergeFormatOnWordOrSelection(const QTextCharFormat &format); // taken from richtext example
121  void updateColorActionPixmap(const QColor &c);
122  void handleColorSelected();
123  void handleCurrentCharFormatChanged(const QTextCharFormat &format); // for the color
124  void handleCursorPositionChanged(); // for the color (mTextEdit->textColor is the current color the curser is at)
125 
126  void boldTriggered();
127  void italicsTriggered();
128  void underscoreTriggered();
129  void colorTriggered();
130  void bulletListTriggered();
131  void codeTriggered();
132 
133  void handleOkClicked();
134  void handleCancelClicked();
135 
136  };
137 }
CommentDialog(const QString windowTitle, CommentEntry *entry=nullptr, QWidget *parent=nullptr)
void setYellowColor(const QString &str)
void setGreenColor(const QString &str)
QString defaultColor()
void setDefaultColor(const QString &str)
void setRedColor(const QString &str)
The CommentEntry class encapsulated information related to a comment.
Definition: comment_entry.h:43
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
QObject * parent() const const