Warning, file /pim/mailcommon/src/tag/tagwidget.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "tagwidget.h" 0008 0009 #include <KLineEditEventHandler> 0010 0011 #include <KActionCollection> 0012 #include <KColorCombo> 0013 #include <KIconButton> 0014 #include <KKeySequenceWidget> 0015 #include <KLocalizedString> 0016 #include <QCheckBox> 0017 #include <QGridLayout> 0018 #include <QIcon> 0019 #include <QLabel> 0020 #include <QLineEdit> 0021 #include <QVBoxLayout> 0022 using namespace MailCommon; 0023 class MailCommon::TagWidgetPrivate 0024 { 0025 public: 0026 TagWidgetPrivate() = default; 0027 0028 QLineEdit *mTagNameLineEdit = nullptr; 0029 0030 QCheckBox *mTextColorCheck = nullptr; 0031 QCheckBox *mBackgroundColorCheck = nullptr; 0032 QCheckBox *mTextFontCheck = nullptr; 0033 QCheckBox *mInToolbarCheck = nullptr; 0034 0035 KColorCombo *mTextColorCombo = nullptr; 0036 KColorCombo *mBackgroundColorCombo = nullptr; 0037 0038 QCheckBox *mBoldCheckBox = nullptr; 0039 QCheckBox *mItalicCheckBox = nullptr; 0040 0041 KIconButton *mIconButton = nullptr; 0042 0043 KKeySequenceWidget *mKeySequenceWidget = nullptr; 0044 }; 0045 0046 TagWidget::TagWidget(const QList<KActionCollection *> &actionCollections, QWidget *parent) 0047 : QWidget(parent) 0048 , d(new MailCommon::TagWidgetPrivate) 0049 { 0050 auto settings = new QGridLayout(this); 0051 settings->setContentsMargins({}); 0052 0053 // Stretcher layout for adding some space after the label 0054 auto spacer = new QVBoxLayout(); 0055 settings->addLayout(spacer, 0, 0, 1, 2); 0056 0057 // First row for renaming 0058 d->mTagNameLineEdit = new QLineEdit(this); 0059 d->mTagNameLineEdit->setClearButtonEnabled(true); 0060 KLineEditEventHandler::catchReturnKey(d->mTagNameLineEdit); 0061 settings->addWidget(d->mTagNameLineEdit, 1, 1); 0062 0063 auto namelabel = new QLabel(i18nc("@label:listbox Name of the tag", "Name:"), this); 0064 namelabel->setBuddy(d->mTagNameLineEdit); 0065 settings->addWidget(namelabel, 1, 0); 0066 0067 connect(d->mTagNameLineEdit, &QLineEdit::textChanged, this, &TagWidget::slotEmitChangeCheck); 0068 0069 // Second row for text color 0070 d->mTextColorCheck = new QCheckBox(i18n("Change te&xt color:"), this); 0071 settings->addWidget(d->mTextColorCheck, 2, 0); 0072 0073 d->mTextColorCombo = new KColorCombo(this); 0074 settings->addWidget(d->mTextColorCombo, 2, 1); 0075 d->mTextColorCombo->setEnabled(false); 0076 0077 connect(d->mTextColorCheck, &QCheckBox::toggled, d->mTextColorCombo, &KColorCombo::setEnabled); 0078 connect(d->mTextColorCheck, &QCheckBox::stateChanged, this, &TagWidget::slotEmitChangeCheck); 0079 connect(d->mTextColorCombo, &KColorCombo::activated, this, &TagWidget::slotEmitChangeCheck); 0080 0081 // Third row for text background color 0082 d->mBackgroundColorCheck = new QCheckBox(i18n("Change &background color:"), this); 0083 settings->addWidget(d->mBackgroundColorCheck, 3, 0); 0084 0085 d->mBackgroundColorCombo = new KColorCombo(this); 0086 settings->addWidget(d->mBackgroundColorCombo, 3, 1); 0087 d->mBackgroundColorCombo->setEnabled(false); 0088 0089 connect(d->mBackgroundColorCheck, &QAbstractButton::toggled, d->mBackgroundColorCombo, &QWidget::setEnabled); 0090 connect(d->mBackgroundColorCheck, &QCheckBox::stateChanged, this, &TagWidget::slotEmitChangeCheck); 0091 connect(d->mBackgroundColorCombo, &KColorCombo::activated, this, &TagWidget::slotEmitChangeCheck); 0092 0093 // Fourth for font selection 0094 d->mTextFontCheck = new QCheckBox(i18n("Change fo&nt:"), this); 0095 settings->addWidget(d->mTextFontCheck, 4, 0); 0096 0097 auto fontLayout = new QVBoxLayout; 0098 settings->addLayout(fontLayout, 4, 1); 0099 0100 d->mBoldCheckBox = new QCheckBox(i18n("&Bold")); 0101 d->mBoldCheckBox->setEnabled(false); 0102 fontLayout->addWidget(d->mBoldCheckBox); 0103 0104 d->mItalicCheckBox = new QCheckBox(i18n("&Italics")); 0105 d->mItalicCheckBox->setEnabled(false); 0106 fontLayout->addWidget(d->mItalicCheckBox); 0107 0108 connect(d->mTextFontCheck, &QAbstractButton::toggled, d->mBoldCheckBox, &QWidget::setEnabled); 0109 connect(d->mTextFontCheck, &QAbstractButton::toggled, d->mItalicCheckBox, &QWidget::setEnabled); 0110 connect(d->mTextFontCheck, &QCheckBox::stateChanged, this, &TagWidget::slotEmitChangeCheck); 0111 connect(d->mBoldCheckBox, &QAbstractButton::toggled, this, &TagWidget::slotEmitChangeCheck); 0112 connect(d->mItalicCheckBox, &QAbstractButton::toggled, this, &TagWidget::slotEmitChangeCheck); 0113 0114 // Fifth for toolbar icon 0115 d->mIconButton = new KIconButton(this); 0116 d->mIconButton->setIconSize(16); 0117 d->mIconButton->setIconType(KIconLoader::NoGroup, KIconLoader::Action); 0118 d->mIconButton->setIcon(QIcon::fromTheme(QStringLiteral("mail-tagged"))); 0119 settings->addWidget(d->mIconButton, 5, 1); 0120 connect(d->mIconButton, &KIconButton::iconChanged, this, &TagWidget::iconNameChanged); 0121 0122 auto iconlabel = new QLabel(i18n("Message tag &icon:"), this); 0123 iconlabel->setBuddy(d->mIconButton); 0124 settings->addWidget(iconlabel, 5, 0); 0125 0126 // We do not connect the checkbox to icon selector since icons are used in the 0127 // menus as well 0128 connect(d->mIconButton, &KIconButton::iconChanged, this, &TagWidget::slotEmitChangeCheck); 0129 0130 // Sixth for shortcut 0131 d->mKeySequenceWidget = new KKeySequenceWidget(this); 0132 settings->addWidget(d->mKeySequenceWidget, 6, 1); 0133 auto sclabel = new QLabel(i18n("Shortc&ut:"), this); 0134 sclabel->setBuddy(d->mKeySequenceWidget); 0135 settings->addWidget(sclabel, 6, 0); 0136 if (!actionCollections.isEmpty()) { 0137 d->mKeySequenceWidget->setCheckActionCollections(actionCollections); 0138 connect(d->mKeySequenceWidget, &KKeySequenceWidget::keySequenceChanged, this, &TagWidget::slotEmitChangeCheck); 0139 } else { 0140 d->mKeySequenceWidget->setEnabled(false); 0141 } 0142 0143 // Seventh for Toolbar checkbox 0144 d->mInToolbarCheck = new QCheckBox(i18n("Enable &toolbar button"), this); 0145 settings->addWidget(d->mInToolbarCheck, 7, 0); 0146 connect(d->mInToolbarCheck, &QCheckBox::stateChanged, this, &TagWidget::slotEmitChangeCheck); 0147 } 0148 0149 TagWidget::~TagWidget() = default; 0150 0151 void TagWidget::slotEmitChangeCheck() 0152 { 0153 Q_EMIT changed(); 0154 } 0155 0156 void TagWidget::setTagTextColor(const QColor &color) 0157 { 0158 d->mTextColorCheck->setEnabled(true); 0159 if (color.isValid()) { 0160 d->mTextColorCheck->setChecked(true); 0161 d->mTextColorCombo->setColor(color); 0162 } else { 0163 d->mTextColorCheck->setChecked(false); 0164 d->mTextColorCombo->setColor(Qt::white); 0165 } 0166 d->mTextColorCombo->setEnabled(d->mTextColorCheck->isChecked()); 0167 } 0168 0169 void TagWidget::setTagBackgroundColor(const QColor &color) 0170 { 0171 d->mBackgroundColorCheck->setEnabled(true); 0172 if (color.isValid()) { 0173 d->mBackgroundColorCheck->setChecked(true); 0174 d->mBackgroundColorCombo->setColor(color); 0175 } else { 0176 d->mBackgroundColorCheck->setChecked(false); 0177 d->mBackgroundColorCombo->setColor(Qt::white); 0178 } 0179 d->mBackgroundColorCombo->setEnabled(d->mBackgroundColorCheck->isChecked()); 0180 } 0181 0182 void TagWidget::setTagTextFormat(bool isBold, bool isItalic) 0183 { 0184 d->mTextFontCheck->setEnabled(true); 0185 d->mTextFontCheck->setChecked(isBold || isItalic); 0186 d->mBoldCheckBox->setChecked(isBold); 0187 d->mItalicCheckBox->setChecked(isItalic); 0188 } 0189 0190 void TagWidget::recordTagSettings(MailCommon::Tag::Ptr tag) 0191 { 0192 tag->textColor = d->mTextColorCheck->isChecked() ? d->mTextColorCombo->color() : QColor(); 0193 0194 tag->backgroundColor = d->mBackgroundColorCheck->isChecked() ? d->mBackgroundColorCombo->color() : QColor(); 0195 0196 tag->isBold = d->mTextFontCheck->isChecked() ? d->mBoldCheckBox->isChecked() : false; 0197 tag->isItalic = d->mTextFontCheck->isChecked() ? d->mItalicCheckBox->isChecked() : false; 0198 0199 tag->iconName = iconButton()->icon(); 0200 if (d->mKeySequenceWidget->isEnabled()) { 0201 d->mKeySequenceWidget->applyStealShortcut(); 0202 tag->shortcut = QKeySequence(d->mKeySequenceWidget->keySequence()); 0203 } 0204 0205 tag->inToolbar = d->mInToolbarCheck->isChecked(); 0206 } 0207 0208 QLineEdit *TagWidget::tagNameLineEdit() const 0209 { 0210 return d->mTagNameLineEdit; 0211 } 0212 0213 QCheckBox *TagWidget::textColorCheck() const 0214 { 0215 return d->mTextColorCheck; 0216 } 0217 0218 QCheckBox *TagWidget::textFontCheck() const 0219 { 0220 return d->mTextFontCheck; 0221 } 0222 0223 QCheckBox *TagWidget::backgroundColorCheck() const 0224 { 0225 return d->mBackgroundColorCheck; 0226 } 0227 0228 QCheckBox *TagWidget::inToolBarCheck() const 0229 { 0230 return d->mInToolbarCheck; 0231 } 0232 0233 KColorCombo *TagWidget::textColorCombo() const 0234 { 0235 return d->mTextColorCombo; 0236 } 0237 0238 KColorCombo *TagWidget::backgroundColorCombo() const 0239 { 0240 return d->mBackgroundColorCombo; 0241 } 0242 0243 QCheckBox *TagWidget::textBoldCheck() const 0244 { 0245 return d->mBoldCheckBox; 0246 } 0247 0248 QCheckBox *TagWidget::textItalicCheck() const 0249 { 0250 return d->mItalicCheckBox; 0251 } 0252 0253 KIconButton *TagWidget::iconButton() const 0254 { 0255 return d->mIconButton; 0256 } 0257 0258 KKeySequenceWidget *TagWidget::keySequenceWidget() const 0259 { 0260 return d->mKeySequenceWidget; 0261 } 0262 0263 #include "moc_tagwidget.cpp"