4 #include <QDialogButtonBox>
10 #include <QColorDialog>
15 #include <QTextBlockFormat>
16 #include <QTextCharFormat>
18 #include <QFontDatabase>
30 mDefaultFont =
QFont(
"Iosevka");
37 mLastModifiedLabel->
show();
40 updateColorActionPixmap(mDefaultColor);
51 return mHeaderEdit->
text();
56 return mTextEdit->
toHtml();
59 void CommentDialog::init()
84 mLastModifiedLabel =
new QLabel;
85 mHeaderContainerLayout->
addWidget(mHeaderEdit);
86 mHeaderContainerLayout->
addWidget(mLastModifiedLabel);
87 mLastModifiedLabel->
hide();
91 mBoldAction = mToolBar->
addAction(
"Bold",
this, &CommentDialog::boldTriggered);
95 mItalicsAction = mToolBar->
addAction(
"Italics",
this, &CommentDialog::italicsTriggered);
99 mUnderscoreAction = mToolBar->
addAction(
"Underscore",
this, &CommentDialog::underscoreTriggered);
104 pix.fill(
QColor(mDefaultColor));
105 mColorAction = mToolBar->
addAction(pix,
"Colors",
this, &CommentDialog::colorTriggered);
107 mListAction = mToolBar->
addAction(
"List",
this, &CommentDialog::bulletListTriggered);
110 mCodeAction = mToolBar->
addAction(
"Code",
this, &CommentDialog::codeTriggered);
125 mLayout->
addLayout(mHeaderContainerLayout);
141 void CommentDialog::mergeFormatOnWordOrSelection(
const QTextCharFormat &format)
144 if(!
cursor.hasSelection())
146 cursor.mergeCharFormat(format);
150 void CommentDialog::updateColorActionPixmap(
const QColor &c)
157 void CommentDialog::handleColorSelected()
163 if(!color.isValid())
return;
167 mergeFormatOnWordOrSelection(fmt);
168 updateColorActionPixmap(color);
171 void CommentDialog::handleCurrentCharFormatChanged(
const QTextCharFormat &format)
179 updateColorActionPixmap(color);
182 void CommentDialog::handleCursorPositionChanged()
188 void CommentDialog::boldTriggered()
192 mergeFormatOnWordOrSelection(fmt);
195 void CommentDialog::italicsTriggered()
199 mergeFormatOnWordOrSelection(fmt);
202 void CommentDialog::underscoreTriggered()
206 mergeFormatOnWordOrSelection(fmt);
209 void CommentDialog::colorTriggered()
216 auto act = men->
addAction(map,
"Red",
this, &CommentDialog::handleColorSelected);
219 color =
QColor(mGreenColor);
221 act = men->
addAction(map,
"Green",
this, &CommentDialog::handleColorSelected);
224 color =
QColor(mYellowColor);
226 act = men->
addAction(map,
"Yellow",
this, &CommentDialog::handleColorSelected);
229 color =
QColor(mDefaultColor);
231 act = men->
addAction(map,
"Default",
this, &CommentDialog::handleColorSelected);
234 QRect geo = mToolBar->actionGeometry(mColorAction);
240 void CommentDialog::bulletListTriggered()
246 cursor.currentList()->remove(block);
249 cursor.setBlockFormat(blockFmt);
262 cursor.setBlockFormat(blockFmt);
265 listFmt =
cursor.currentList()->format();
270 cursor.setBlockFormat(blockFmt);
273 cursor.createList(listFmt);
278 void CommentDialog::codeTriggered()
285 mergeFormatOnWordOrSelection(fmt);
288 void CommentDialog::handleOkClicked()
293 void CommentDialog::handleCancelClicked()
QVariant data() const const
void setIcon(const QIcon &icon)
void setData(const QVariant &userData)
void setShortcut(const QKeySequence &shortcut)
void addLayout(QLayout *layout, int stretch)
const QColor & color() const const
QString toString(Qt::DateFormat format) const const
bool italic() const const
void setPixelSize(int pixelSize)
bool underline() const const
QFont systemFont(QFontDatabase::SystemFont type)
void setText(const QString &)
void setText(const QString &)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * sender() const const
virtual void polish(QWidget *widget)
virtual void unpolish(QWidget *widget)
void setIndent(int indentation)
void setFont(const QFont &font, QTextCharFormat::FontPropertiesInheritanceBehavior behavior)
void setFontItalic(bool italic)
void setFontUnderline(bool underline)
void setFontWeight(int weight)
QTextList * currentList() const const
void currentCharFormatChanged(const QTextCharFormat &f)
void cursorPositionChanged()
void setHtml(const QString &text)
void mergeCurrentCharFormat(const QTextCharFormat &modifier)
QTextCursor textCursor() const const
QBrush background() const const
QBrush foreground() const const
void setBackground(const QBrush &brush)
void setForeground(const QBrush &brush)
void setIndent(int indentation)
void setStyle(QTextListFormat::Style style)