HAL
expanding_list_button.cpp
Go to the documentation of this file.
2 
4 
5 #include <QHBoxLayout>
6 #include <QLabel>
7 #include <QMouseEvent>
8 #include <QStyle>
9 
10 namespace hal
11 {
12  QHash<QString,QString> ExpandingListButton::sIconMap = ExpandingListButton::defaultIconMap();
13 
15  : QFrame(parent),
16  mLayout(new QHBoxLayout(this)),
17  mLeftBorder(new QFrame(this)),
18  mIconLabel(new QLabel(this)),
19  mTextLabel(new QLabel(this)),
20  mRightBorder(new QFrame(this)),
21  mLevel(levl), mHover(false), mSelected(false)
22  {
23  mLayout->setContentsMargins(0, 0, 0, 0);
24  mLayout->setSpacing(0);
25 
26  mLeftBorder->setObjectName("left-border");
27  mLeftBorder->setFrameStyle(QFrame::NoFrame);
28  mLayout->addWidget(mLeftBorder);
29 
30  mIconLabel->setObjectName("icon-label");
32  mLayout->addWidget(mIconLabel);
33 
34  mTextLabel->setObjectName("text-label");
35  mLayout->addWidget(mTextLabel);
36 
37  mRightBorder->setObjectName("right-border");
38  mRightBorder->setFrameStyle(QFrame::NoFrame);
39  mLayout->addWidget(mRightBorder);
40  }
41 
42  QHash<QString,QString> ExpandingListButton::defaultIconMap()
43  {
44  const char* iconList[] = {"style", "eye",
45  "graph", "graph",
46  "navig", "graph",
47  "pytho", "python",
48  "selec", "gen-window",
49  "appea", "preferences",
50  "exper", "preferences",
51  "keybi", "keyboard",
52  "autos", "save",
53  "debug", "bug",
54  nullptr, nullptr};
56  int i = 0;
57  const char* key;
58  while ( (key=iconList[i++]) )
59  retval[key] = QString(":/icons/%1").arg(iconList[i++]);
60  return retval;
61  }
62 
64  {
65  Q_UNUSED(event)
66 
67  mHover = true;
68  repolish();
69  }
70 
72  {
73  Q_UNUSED(event)
74 
75  mHover = false;
76  repolish();
77  }
78 
80  {
81  Q_UNUSED(event)
82 
83  Q_EMIT clicked();
84  event->accept();
85  }
86 
88  {
89  return mTextLabel->text();
90  }
91 
93  {
94  return mLevel;
95  }
96 
98  {
99  return mHover;
100  }
101 
103  {
104  return mSelected;
105  }
106 
107  /*
108  QString ExpandingListButton::type()
109  {
110  return mType;
111  }
112 */
113 
115  {
116  return mIconStyle;
117  }
118 
120  {
121  if (mSelected == selected)
122  return;
123 
124  mSelected = selected;
125  repolish();
126  }
127 
128  /*
129  void ExpandingListButton::set_type(const QString& type)
130  {
131  if (mType == type)
132  return;
133 
134  mType = type;
135  repolish();
136  }
137 */
138 
140  {
141  if (mIconStyle == style)
142  return;
143 
144  mIconStyle = style;
145  repolish();
146  }
147 
149  {
150  if (mIconPath == path)
151  return;
152 
153  mIconPath = path;
154  repolish();
155  }
156 
158  {
159  QString iconPath = sIconMap.value(text.left(5).toLower());
160  if (iconPath.isEmpty()) iconPath = ":/icons/python";
161  setIconPath(iconPath);
162  }
163 
165  {
166  mTextLabel->setText(text);
167  }
168 
170  {
171  QStyle* s = style();
172 
173  s->unpolish(this);
174  s->polish(this);
175 
176  s->unpolish(mLeftBorder);
177  s->polish(mLeftBorder);
178 
179  s->unpolish(mIconLabel);
180  s->polish(mIconLabel);
181 
182  s->unpolish(mTextLabel);
183  s->polish(mTextLabel);
184 
185  s->unpolish(mRightBorder);
186  s->polish(mRightBorder);
187 
188  if (!mIconPath.isEmpty())
189  mIconLabel->setPixmap(gui_utility::getStyledSvgIcon(mIconStyle, mIconPath).pixmap(QSize(20, 20)));
190  }
191 }
void setIconStyle(const QString &style)
void setDefaultIcon(const QString &text)
void setIconPath(const QString &path)
void mousePressEvent(QMouseEvent *event) override
void setText(const QString &text)
ExpandingListButton(int levl, QWidget *parent=0)
void enterEvent(QEvent *event) override
void leaveEvent(QEvent *event) override
QIcon getStyledSvgIcon(const QString &from_to_colors_enabled, const QString &svg_path, QString from_to_colors_disabled=QString())
Definition: graphics.cpp:60
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void setSpacing(int spacing)
virtual bool event(QEvent *e) override
void setFrameStyle(int style)
const T value(const Key &key) const const
void setPixmap(const QPixmap &)
void setContentsMargins(int left, int top, int right, int bottom)
Q_EMITQ_EMIT
void setObjectName(const QString &name)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool isEmpty() const const
QString left(int n) const const
QString toLower() const const
virtual void polish(QWidget *widget)
virtual void unpolish(QWidget *widget)
void setSizePolicy(QSizePolicy)
QStyle * style() const const