Cppcheck
codeeditstylecontrols.cpp
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2023 Cppcheck team.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "codeeditstylecontrols.h"
20 
21 #include <QColorDialog>
22 #include <QDialog>
23 #include <QVariant>
24 
25 class QWidget;
26 
28  QPushButton(parent),
29  mColor(QColor(255, 255, 255))
30 {
31  updateColor();
32  connect(this, SIGNAL(clicked()), this, SLOT(changeColor()));
33 }
34 
36 {
37  QString btnColorStyle = QString(
38  "background-color:rgb(%1,%2,%3);"
39  "border-style:outset;"
40  "border-width: 1px;")
41  .arg(mColor.red())
42  .arg(mColor.green())
43  .arg(mColor.blue());
44  setObjectName("SelectColorButton");
45  setStyleSheet(btnColorStyle);
46 }
47 
49 {
50  QColorDialog pDlg(mColor);
51  pDlg.setModal(true);
52  const int nResult = pDlg.exec();
53  if (nResult == QDialog::Accepted) {
54  setColor(pDlg.selectedColor());
55  emit colorChanged(mColor);
56  }
57 }
58 
59 void SelectColorButton::setColor(const QColor& color)
60 {
61  mColor = color;
62  updateColor();
63 }
64 
65 // cppcheck-suppress unusedFunction
67 {
68  return mColor;
69 }
70 
72  QComboBox(parent)
73 {
74  addItem(QObject::tr("Thin"),
75  QVariant(static_cast<int>(QFont::Thin)));
76  addItem(QObject::tr("ExtraLight"),
77  QVariant(static_cast<int>(QFont::ExtraLight)));
78  addItem(QObject::tr("Light"),
79  QVariant(static_cast<int>(QFont::Light)));
80  addItem(QObject::tr("Normal"),
81  QVariant(static_cast<int>(QFont::Normal)));
82  addItem(QObject::tr("Medium"),
83  QVariant(static_cast<int>(QFont::Medium)));
84  addItem(QObject::tr("DemiBold"),
85  QVariant(static_cast<int>(QFont::DemiBold)));
86  addItem(QObject::tr("Bold"),
87  QVariant(static_cast<int>(QFont::Bold)));
88  addItem(QObject::tr("ExtraBold"),
89  QVariant(static_cast<int>(QFont::ExtraBold)));
90  addItem(QObject::tr("Black"),
91  QVariant(static_cast<int>(QFont::Black)));
92  updateWeight();
93  connect(this, SIGNAL(currentIndexChanged(int)),
94  this, SLOT(changeWeight(int)));
95 }
96 
98 {
99  const int nResult = findData(QVariant(static_cast<int>(mWeight)));
100 
101  if (nResult != -1) {
102  setCurrentIndex(nResult);
103  } else {
104  setCurrentIndex(findData(static_cast<int>(QFont::Normal)));
105  }
106 }
107 
109 {
110  if (index != -1) {
111  setWeight(static_cast<QFont::Weight>(itemData(index).toInt()));
112  emit weightChanged(mWeight);
113  }
114 }
115 
116 void SelectFontWeightCombo::setWeight(QFont::Weight weight)
117 {
118  mWeight = weight;
119  updateWeight();
120 }
121 
122 // cppcheck-suppress unusedFunction
123 const QFont::Weight& SelectFontWeightCombo::getWeight()
124 {
125  return mWeight;
126 }
static void addItem(QMap< QString, unsigned > &m, const QString &key)
const QColor & getColor()
SelectColorButton(QWidget *parent)
void setColor(const QColor &color)
void colorChanged(const QColor &newColor)
void setWeight(QFont::Weight weight)
void weightChanged(QFont::Weight newWeight)
SelectFontWeightCombo(QWidget *parent)
const QFont::Weight & getWeight()